From 933614dba859f7449a9bb97639ac64db545160ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Tue, 16 Jan 2024 17:01:57 +0100 Subject: [PATCH 1/2] FIX onlyChagnedAttrs true with alterationType for entityDelete case --- src/lib/mongoBackend/MongoCommonUpdate.cpp | 4 +- src/lib/mongoBackend/MongoGlobal.cpp | 20 ++- ...with_alteration_type_on_entity_delete.test | 167 ++++++++++++++++++ 3 files changed, 183 insertions(+), 8 deletions(-) create mode 100644 test/functionalTest/cases/3190_notify_only_attributes_that_change/notify_only_attributes_that_change_with_alteration_type_on_entity_delete.test diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index 2c1ad6c507..eca3ed90b0 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -3533,7 +3533,7 @@ static unsigned int updateEntity attrNames.push_back(eP->attributeVector[ix]->name); } - // Note we cannot usse eP->type for the type, as it may be blank in the request + // Note we cannot use eP->type for the type, as it may be blank in the request // (that would break the cases/1494_subscription_alteration_types/sub_alteration_type_entity_delete2.test case) if (!addTriggeredSubscriptions(notifyCerP->entity.id, notifyCerP->entity.type, @@ -3557,7 +3557,7 @@ static unsigned int updateEntity addBuiltins(notifyCerP, subAltType2string(ngsiv2::SubAltType::EntityDelete)); unsigned int notifSent = processSubscriptions(subsToNotify, notifyCerP, - tenant, + tenant, xauthToken, fiwareCorrelator, notifStartCounter); diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index b582615eb7..c21c65f6a3 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -2292,14 +2292,22 @@ static void getCommonAttributes std::vector& resultVector ) { - for (unsigned int cavOc = 0; cavOc < fVector.size(); ++cavOc) + for (unsigned int avOc = 0; avOc < sVector.size(); ++avOc) { - for (unsigned int avOc = 0; avOc < sVector.size(); ++avOc) + // some builtin attributes are always include (even when onlyChangedAttrs is true) + if ((sVector[avOc] == ALTERATION_TYPE) || (sVector[avOc] == DATE_CREATED) || (sVector[avOc] == DATE_MODIFIED)) { - // some builtin attributes are always include (even when onlyChangedAttrs is true) - if ((sVector[avOc] == ALTERATION_TYPE) || (sVector[avOc] == DATE_CREATED) || (sVector[avOc] == DATE_MODIFIED) || (fVector[cavOc] == sVector[avOc])) - { - resultVector.push_back(sVector[avOc]); + resultVector.push_back(sVector[avOc]); + } + else + { + for (unsigned int cavOc = 0; cavOc < fVector.size(); ++cavOc) + { + if (fVector[cavOc] == sVector[avOc]) + { + resultVector.push_back(sVector[avOc]); + break; + } } } } diff --git a/test/functionalTest/cases/3190_notify_only_attributes_that_change/notify_only_attributes_that_change_with_alteration_type_on_entity_delete.test b/test/functionalTest/cases/3190_notify_only_attributes_that_change/notify_only_attributes_that_change_with_alteration_type_on_entity_delete.test new file mode 100644 index 0000000000..5617ed8fcf --- /dev/null +++ b/test/functionalTest/cases/3190_notify_only_attributes_that_change/notify_only_attributes_that_change_with_alteration_type_on_entity_delete.test @@ -0,0 +1,167 @@ +# Copyright 2019 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +Notify only attributes that change get with alterationType on entityDelete + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + + +--SHELL-- + +# +# 01. Create entity E-A,B,C +# 02. Create a subscription with onlyChangedAttrs: true, alterationsTypes: entityDelete and notify alterationType +# 03. Delete E +# 04. Dump notification get E with alterationType entityDelete +# + + +echo '01. Create entity E-A,B,C' +echo '=========================' +payload='{ + "id": "E", + "type": "T", + "A": { + "value": 1, + "type": "Number" + }, + "B": { + "value": 1, + "type": "Number" + }, + "C": { + "value": 1, + "type": "Number" + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo '02. Create a subscription with onlyChangedAttrs: true, alterationsTypes: entityDelete and notify alterationType' +echo '===============================================================================================================' +payload='{ + "subject": { + "entities": [ + { + "id": "E", + "type": "T" + } + ], + "condition": { + "alterationTypes": [ "entityDelete" ] + } + }, + "notification": { + "http": { + "url": "http://localhost:'$LISTENER_PORT'/notify" + }, + "attrs": [ "alterationType" ], + "onlyChangedAttrs": true + } +}' +orionCurl --url /v2/subscriptions --payload "$payload" +echo +echo + + +echo '03. Delete E' +echo '============' +orionCurl --url /v2/entities/E -X DELETE +echo +echo + + +echo '04. Dump notification get E with alterationType entityDelete' +echo '============================================================' +accumulatorDump +echo +echo + + +--REGEXPECT-- +01. Create entity E-A,B,C +========================= +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/E?type=T +Content-Length: 0 + + + +02. Create a subscription with onlyChangedAttrs: true, alterationsTypes: entityDelete and notify alterationType +=============================================================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/subscriptions/REGEX([0-9a-f]{24}) +Content-Length: 0 + + + +03. Delete E +============ +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +04. Dump notification get E with alterationType entityDelete +============================================================ +POST http://localhost:REGEX(\d+)/notify +Fiware-Servicepath: / +Content-Length: 146 +User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) +Ngsiv2-Attrsformat: normalized +Host: localhost:REGEX(\d+) +Accept: application/json +Content-Type: application/json; charset=utf-8 +Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 + +{ + "data": [ + { + "alterationType": { + "metadata": {}, + "type": "Text", + "value": "entityDelete" + }, + "id": "E", + "type": "T" + } + ], + "subscriptionId": "REGEX([0-9a-f]{24})" +} +======================================= + + +--TEARDOWN-- +brokerStop CB +dbDrop CB +accumulatorStop From f4e5eb253d0ab87d55cd0a100660ee6dce3de2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Tue, 16 Jan 2024 17:03:12 +0100 Subject: [PATCH 2/2] REMOVE trailing whitespace --- src/lib/mongoBackend/MongoCommonUpdate.cpp | 2 +- src/lib/mongoBackend/MongoGlobal.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index eca3ed90b0..1a3e667084 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -3557,7 +3557,7 @@ static unsigned int updateEntity addBuiltins(notifyCerP, subAltType2string(ngsiv2::SubAltType::EntityDelete)); unsigned int notifSent = processSubscriptions(subsToNotify, notifyCerP, - tenant, + tenant, xauthToken, fiwareCorrelator, notifStartCounter); diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index c21c65f6a3..9b0cca0054 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -2292,7 +2292,7 @@ static void getCommonAttributes std::vector& resultVector ) { - for (unsigned int avOc = 0; avOc < sVector.size(); ++avOc) + for (unsigned int avOc = 0; avOc < sVector.size(); ++avOc) { // some builtin attributes are always include (even when onlyChangedAttrs is true) if ((sVector[avOc] == ALTERATION_TYPE) || (sVector[avOc] == DATE_CREATED) || (sVector[avOc] == DATE_MODIFIED))