From 5c067fa5525191cd68d85c1f4cab8c29a72196ba Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 28 Jan 2025 10:30:08 +0100 Subject: [PATCH 1/9] send multiple MQTT measures in a batch update to CB --- lib/commonBindings.js | 66 ++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/lib/commonBindings.js b/lib/commonBindings.js index 4f4166f8..293417a6 100644 --- a/lib/commonBindings.js +++ b/lib/commonBindings.js @@ -283,50 +283,46 @@ function singleMeasure(apiKey, deviceId, attribute, device, parsedMessage) { */ function multipleMeasures(apiKey, deviceId, device, messageObj) { let measure; + let values; const ctxt = fillService(context, device); config.getLogger().debug(context, 'Processing multiple measures for device %s with apiKey %s', deviceId, apiKey); + let attributesArray = []; for (let j = 0; j < messageObj.length; j++) { measure = messageObj[j]; - let attributesArray = []; - const values = extractAttributes(device, measure, device.payloadType); + values = extractAttributes(device, measure, device.payloadType); if (values && values[0] && values[0][0]) { - // multi measure is extracted due to payloadType is ngsi - attributesArray = values; + // Check multimeasure from a ngsiv2/ngsild entities array + attributesArray = attributesArray.concat(values); } else { - attributesArray = [values]; + attributesArray.push(values); } - config - .getLogger() - .debug( - context, - 'Processing multiple measures for device %s with apiKey %s values %j', - deviceId, - apiKey, - attributesArray - ); - iotAgentLib.update(device.name, device.type, '', attributesArray, device, function (error) { - if (error) { - config.getLogger().error( - ctxt, - /*jshint quotmark: double */ - "MEASURES-002: Couldn't send the updated values to the Context Broker due to an error: %j", - /*jshint quotmark: single */ - error - ); - } else { - config - .getLogger() - .info( - ctxt, - 'Multiple measures for device %s with apiKey %s successfully updated', - deviceId, - apiKey - ); - } - finishSouthBoundTransaction(null); - }); } + config + .getLogger() + .debug( + context, + 'Processing multiple measures for device %s with apiKey %s values %j', + deviceId, + apiKey, + attributesArray + ); + iotAgentLib.update(device.name, device.type, '', attributesArray, device, function (error) { + if (error) { + config.getLogger().error( + ctxt, + /*jshint quotmark: double */ + "MEASURES-002: Couldn't send the updated values to the Context Broker due to an error: %j", + /*jshint quotmark: single */ + error + ); + } else { + config + .getLogger() + .info(ctxt, 'Multiple measures for device %s with apiKey %s successfully updated', deviceId, apiKey); + } + finishSouthBoundTransaction(null); + }); } /** From 13ac697b51d39e3d2e955a62f0c86a322aafd46f Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 28 Jan 2025 11:13:56 +0100 Subject: [PATCH 2/9] fix mqtt test --- .../ngsiv2/MQTT_receive_measures-test2.js | 53 +++---------------- 1 file changed, 8 insertions(+), 45 deletions(-) diff --git a/test/unit/ngsiv2/MQTT_receive_measures-test2.js b/test/unit/ngsiv2/MQTT_receive_measures-test2.js index d362646c..bfdaaf25 100644 --- a/test/unit/ngsiv2/MQTT_receive_measures-test2.js +++ b/test/unit/ngsiv2/MQTT_receive_measures-test2.js @@ -110,17 +110,8 @@ describe('MQTT: Measure reception ', function () { .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes.json') - ) - .reply(204); - - contextBrokerMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes2.json') + '/v2/op/update', + utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes4.json') ) .reply(204); }); @@ -207,20 +198,10 @@ describe('MQTT: Measure reception ', function () { .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice.json') + '/v2/op/update', + utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice4.json') ) .reply(204); - - contextBrokerUnprovMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice2.json') - ) - .reply(204); - request(groupCreation, function (error, response, body) { done(); }); @@ -278,17 +259,8 @@ describe('MQTT: Measure reception ', function () { .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unknownMeasures.json') - ) - .reply(204); - - contextBrokerMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unknownMeasures2.json') + '/v2/op/update', + utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unknownMeasures3.json') ) .reply(204); }); @@ -338,17 +310,8 @@ describe('MQTT: Measure reception ', function () { .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timestampMeasure.json') - ) - .reply(204); - - contextBrokerMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timestampMeasure2.json') + '/v2/op/update', + utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timestampMeasure3.json') ) .reply(204); }); From c9f9dfcc9dddbc3f47cd8381a29c4418e2553156 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 28 Jan 2025 11:20:11 +0100 Subject: [PATCH 3/9] add mocks values --- .../multipleMeasuresJsonTypes4.json | 85 +++++++++++++++++++ .../contextRequests/timestampMeasure3.json | 37 ++++++++ .../contextRequests/unknownMeasures3.json | 29 +++++++ .../contextRequests/unprovisionedDevice4.json | 29 +++++++ 4 files changed, 180 insertions(+) create mode 100644 test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes4.json create mode 100644 test/unit/ngsiv2/contextRequests/timestampMeasure3.json create mode 100644 test/unit/ngsiv2/contextRequests/unknownMeasures3.json create mode 100644 test/unit/ngsiv2/contextRequests/unprovisionedDevice4.json diff --git a/test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes4.json b/test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes4.json new file mode 100644 index 00000000..bc7bd8e1 --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes4.json @@ -0,0 +1,85 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "temperature": { + "type": "celsius", + "value": "87" + }, + "humidity": { + "type": "degrees", + "value": "32" + }, + "luminosity": { + "type": "Integer", + "value": 10 + }, + "pollution": { + "type": "Float", + "value": 43.4 + }, + "configuration": { + "type": "Object", + "value": { + "firmware": { + "version": "1.1.0", + "hash": "cf23df2207d99a74fbe169e3eba035e633b65d94" + } + } + }, + "tags": { + "type": "Array", + "value": [ + "iot", + "device" + ] + }, + "enabled": { + "type": "Boolean", + "value": true + } + }, + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "temperature": { + "type": "celsius", + "value": "89" + }, + "humidity": { + "type": "degrees", + "value": "33" + }, + "luminosity": { + "type": "Integer", + "value": 10 + }, + "pollution": { + "type": "Float", + "value": 43.4 + }, + "configuration": { + "type": "Object", + "value": { + "firmware": { + "version": "1.1.0", + "hash": "cf23df2207d99a74fbe169e3eba035e633b65d94" + } + } + }, + "tags": { + "type": "Array", + "value": [ + "iot", + "device" + ] + }, + "enabled": { + "type": "Boolean", + "value": true + } + } + ] +} diff --git a/test/unit/ngsiv2/contextRequests/timestampMeasure3.json b/test/unit/ngsiv2/contextRequests/timestampMeasure3.json new file mode 100644 index 00000000..da11a952 --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/timestampMeasure3.json @@ -0,0 +1,37 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "temperature": { + "type": "celsius", + "value": "87" + }, + "humidity": { + "type": "degrees", + "value": "32" + }, + "TimeInstant": { + "type": "DateTime", + "value": "2007-11-03T13:18:05Z" + } + }, + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "temperature": { + "type": "celsius", + "value": "89" + }, + "humidity": { + "type": "degrees", + "value": "33" + }, + "TimeInstant": { + "type": "DateTime", + "value": "2007-11-03T13:18:06Z" + } + } + ] + } diff --git a/test/unit/ngsiv2/contextRequests/unknownMeasures3.json b/test/unit/ngsiv2/contextRequests/unknownMeasures3.json new file mode 100644 index 00000000..07b17932 --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/unknownMeasures3.json @@ -0,0 +1,29 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "humidity": { + "type": "degrees", + "value": "32" + }, + "weight": { + "type": "Text", + "value": "87" + } + }, + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "humidity": { + "type": "degrees", + "value": "33" + }, + "weight": { + "type": "Text", + "value": "89" + } + } + ] + } diff --git a/test/unit/ngsiv2/contextRequests/unprovisionedDevice4.json b/test/unit/ngsiv2/contextRequests/unprovisionedDevice4.json new file mode 100644 index 00000000..f8eabedb --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/unprovisionedDevice4.json @@ -0,0 +1,29 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "TheLightType:JSON_UNPROVISIONED", + "type": "TheLightType", + "humidity": { + "type": "Text", + "value": "32" + }, + "temperature": { + "type": "Text", + "value": "87" + } + }, + { + "id": "TheLightType:JSON_UNPROVISIONED", + "type": "TheLightType", + "humidity": { + "type": "Text", + "value": "33" + }, + "temperature": { + "type": "Text", + "value": "89" + } + } + ] + } From 867f08044e34dda29a3b7efe8d2510f31721c418 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 28 Jan 2025 11:38:34 +0100 Subject: [PATCH 4/9] update tests --- .../MQTT_receive_ngsild_measures-test.js | 21 ++- .../MQTT_receive_ngsiv2_measures-test.js | 20 +-- .../ngsildPayloadMeasure3.json | 109 +++++++++++++++ .../ngsiv2PayloadMeasure3.json | 129 ++++++++++++++++++ 4 files changed, 258 insertions(+), 21 deletions(-) create mode 100644 test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure3.json create mode 100644 test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure3.json diff --git a/test/unit/ngsiv2/MQTT_receive_ngsild_measures-test.js b/test/unit/ngsiv2/MQTT_receive_ngsild_measures-test.js index db17d197..90b8f469 100644 --- a/test/unit/ngsiv2/MQTT_receive_ngsild_measures-test.js +++ b/test/unit/ngsiv2/MQTT_receive_ngsild_measures-test.js @@ -77,7 +77,6 @@ describe('MQTT: NGSILD Measure reception ', function () { async.series([iotAgentLib.clearAll, iotaJson.stop], done); }); - describe('When a publish single NGSILD entity measure with NGSILD format arrives for the HTTP binding and NGSILD is the expected payload type', function () { const measure = { id: 'urn:ngsi-ld:ParkingSpot:santander:daoiz_velarde_1_5:3', @@ -206,18 +205,18 @@ describe('MQTT: NGSILD Measure reception ', function () { .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure.json') - ) - .reply(204); - contextBrokerMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure2.json') + '/v2/op/update', + utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure3.json') ) .reply(204); + // contextBrokerMock + // .matchHeader('fiware-service', 'smartgondor') + // .matchHeader('fiware-servicepath', '/gardens') + // .post( + // '/v2/entities?options=upsert', + // utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure2.json') + // ) + // .reply(204); }); it('should send its value to the Context Broker', function (done) { diff --git a/test/unit/ngsiv2/MQTT_receive_ngsiv2_measures-test.js b/test/unit/ngsiv2/MQTT_receive_ngsiv2_measures-test.js index 9ee5ce95..65a3aa7e 100644 --- a/test/unit/ngsiv2/MQTT_receive_ngsiv2_measures-test.js +++ b/test/unit/ngsiv2/MQTT_receive_ngsiv2_measures-test.js @@ -464,18 +464,18 @@ describe('MQTT: NGSIv2 Measure reception ', function () { .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure.json') - ) - .reply(204); - contextBrokerMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure2.json') + '/v2/op/update', + utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure3.json') ) .reply(204); + // contextBrokerMock + // .matchHeader('fiware-service', 'smartgondor') + // .matchHeader('fiware-servicepath', '/gardens') + // .post( + // '/v2/entities?options=upsert', + // utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure2.json') + // ) + // .reply(204); }); it('should send its value to the Context Broker', function (done) { mqttClient.publish('json/1234/MQTT_2/attrs', JSON.stringify(measure), null, function (error) { diff --git a/test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure3.json b/test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure3.json new file mode 100644 index 00000000..1ec520d3 --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure3.json @@ -0,0 +1,109 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "measure_id": { + "type": "Text", + "value": "urn:ngsi-ld:ParkingSpot:santander:daoiz_velarde_1_5:3" + }, + "measure_type": { + "type": "Text", + "value": "ParkingSpot" + }, + "status": { + "type": "Property", + "value": "free", + "metadata": { + "observedAt": { + "value": "2018-09-21T12:00:00Z" + } + } + }, + "category": { + "type": "Property", + "value": [ + "onstreet" + ] + }, + "refParkingSite": { + "type": "Relationship", + "value": "urn:ngsi-ld:ParkingSite:santander:daoiz_velarde_1_5" + }, + "name": { + "type": "Property", + "value": "A-13" + }, + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ + -3.80356167695194, + 43.46296641666926 + ] + } + }, + "@context": { + "type": "@context", + "value": [ + "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld", + "https://schema.lab.fiware.org/ld/context" + ] + } + }, + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "measure_id": { + "type": "Text", + "value": "urn:ngsi-ld:ParkingSpot:santander:reyes_magos_1_1:1" + }, + "measure_type": { + "type": "Text", + "value": "ParkingSpot" + }, + "status": { + "type": "Property", + "value": "free", + "metadata": { + "observedAt": { + "value": "2012-09-21T12:00:00Z" + } + } + }, + "category": { + "type": "Property", + "value": [ + "onstreet" + ] + }, + "refParkingSite": { + "type": "Relationship", + "value": "urn:ngsi-ld:ParkingSite:santander:reyes_magos_1_1" + }, + "name": { + "type": "Property", + "value": "A-12" + }, + "location": { + "type": "GeoProperty", + "value": { + "type": "Point", + "coordinates": [ + -3.90356167695194, + 42.46296641666926 + ] + } + }, + "@context": { + "type": "@context", + "value": [ + "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld", + "https://schema.lab.fiware.org/ld/context" + ] + } + } + ] + } diff --git a/test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure3.json b/test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure3.json new file mode 100644 index 00000000..ceb4c439 --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure3.json @@ -0,0 +1,129 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "measure_id": { + "type": "Text", + "value": "urn:ngsiv2:Streetlight:Streetlight-Mylightpoint-2" + }, + "measure_type": { + "type": "Text", + "value": "Streetlight" + }, + "name": { + "type": "Text", + "value": "MyLightPoint-test1" + }, + "description": { + "type": "Text", + "value": "testdescription" + }, + "status": { + "type": "Text", + "value": "connected", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2023-11-17T11:59:22.661Z" + } + } + }, + "dateServiceStarted": { + "type": "DateTime", + "value": "2020-06-04T09: 55: 02" + }, + "locationComment": { + "type": "Text", + "value": "Test1" + }, + "location": { + "type": "geo:json", + "value": { + "coordinates": [ + -87.88429, + 41.99499 + ], + "type": "Point" + } + }, + "address": { + "type": "Text", + "value": { + "streetAddress": "MyStreet" + } + }, + "isRemotelyManaged": { + "type": "Integer", + "value": 1 + }, + "installationDate": { + "type": "DateTime", + "value": "2022-04-17T02: 30: 04" + } + }, + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "measure_id": { + "type": "Text", + "value": "urn:ngsiv2:Streetlight:Streetlight-Mylightpoint-3" + }, + "measure_type": { + "type": "Text", + "value": "Streetlight" + }, + "name": { + "type": "Text", + "value": "MyLightPoint-test2" + }, + "description": { + "type": "Text", + "value": "testdescription" + }, + "status": { + "type": "Text", + "value": "connected", + "metadata": { + "TimeInstant": { + "type": "DateTime", + "value": "2023-11-17T11:59:22.661Z" + } + } + }, + "dateServiceStarted": { + "type": "DateTime", + "value": "2022-06-04T09: 55: 02" + }, + "locationComment": { + "type": "Text", + "value": "Test3" + }, + "location": { + "type": "geo:json", + "value": { + "coordinates": [ + -84.88429, + 42.99499 + ], + "type": "Point" + } + }, + "address": { + "type": "Text", + "value": { + "streetAddress": "MyFarStreet" + } + }, + "isRemotelyManaged": { + "type": "Integer", + "value": 3 + }, + "installationDate": { + "type": "DateTime", + "value": "2023-04-17T02: 30: 04" + } + } + ] + } From 294d47148950a7184648896568038226e7807a5f Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 28 Jan 2025 11:50:46 +0100 Subject: [PATCH 5/9] update amqp tests --- test/unit/ngsiv2/amqpBinding-test2.js | 43 ++++++++++--------- .../contextRequests/multipleMeasure3.json | 29 +++++++++++++ .../contextRequests/multipleMeasureAMQP4.json | 21 +++++++++ 3 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 test/unit/ngsiv2/contextRequests/multipleMeasure3.json create mode 100644 test/unit/ngsiv2/contextRequests/multipleMeasureAMQP4.json diff --git a/test/unit/ngsiv2/amqpBinding-test2.js b/test/unit/ngsiv2/amqpBinding-test2.js index 5bbdec12..63470920 100644 --- a/test/unit/ngsiv2/amqpBinding-test2.js +++ b/test/unit/ngsiv2/amqpBinding-test2.js @@ -100,19 +100,20 @@ describe('AMQP Transport binding: multiple measures', function () { .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP3.json') + '/v2/op/update', + utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasureAMQP4.json') ) - .reply(200, utils.readExampleFile('./test/contextResponses/singleMeasureSuccess.json')); + //.reply(200, utils.readExampleFile('./test/contextResponses/singleMeasureSuccess.json')); + .reply(204); - contextBrokerMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP2.json') - ) - .reply(200, utils.readExampleFile('./test/contextResponses/singleMeasureSuccess.json')); + // contextBrokerMock + // .matchHeader('fiware-service', 'smartgondor') + // .matchHeader('fiware-servicepath', '/gardens') + // .post( + // '/v2/entities?options=upsert', + // utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP2.json') + // ) + // .reply(200, utils.readExampleFile('./test/contextResponses/singleMeasureSuccess.json')); }); it('should send a single update context request with all the attributes', function (done) { @@ -135,19 +136,19 @@ describe('AMQP Transport binding: multiple measures', function () { .matchHeader('fiware-service', 'smartgondor') .matchHeader('fiware-servicepath', '/gardens') .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure.json') + '/v2/op/update', + utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure3.json') ) .reply(204); - contextBrokerMock - .matchHeader('fiware-service', 'smartgondor') - .matchHeader('fiware-servicepath', '/gardens') - .post( - '/v2/entities?options=upsert', - utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure2.json') - ) - .reply(204); + // contextBrokerMock + // .matchHeader('fiware-service', 'smartgondor') + // .matchHeader('fiware-servicepath', '/gardens') + // .post( + // '/v2/entities?options=upsert', + // utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure2.json') + // ) + // .reply(204); }); it('should send one update context per measure group to the Contet Broker', function (done) { diff --git a/test/unit/ngsiv2/contextRequests/multipleMeasure3.json b/test/unit/ngsiv2/contextRequests/multipleMeasure3.json new file mode 100644 index 00000000..07a543c4 --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/multipleMeasure3.json @@ -0,0 +1,29 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "a": { + "type": "celsius", + "value": "23" + }, + "b": { + "type": "degrees", + "value": "98" + } + }, + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "a": { + "type": "celsius", + "value": "25" + }, + "b": { + "type": "degrees", + "value": "100" + } + } + ] + } diff --git a/test/unit/ngsiv2/contextRequests/multipleMeasureAMQP4.json b/test/unit/ngsiv2/contextRequests/multipleMeasureAMQP4.json new file mode 100644 index 00000000..bd18ba2a --- /dev/null +++ b/test/unit/ngsiv2/contextRequests/multipleMeasureAMQP4.json @@ -0,0 +1,21 @@ +{ + "actionType": "append", + "entities": [ + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "a": { + "type": "celsius", + "value": "23" + } + }, + { + "id": "Second MQTT Device", + "type": "AnMQTTDevice", + "a": { + "type": "celsius", + "value": "25" + } + } + ] + } From e4d9040c35dc9846f7e2e266a56b32fcd0c11644 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 28 Jan 2025 12:10:31 +0100 Subject: [PATCH 6/9] clean code --- .../MQTT_receive_ngsild_measures-test.js | 8 -------- test/unit/ngsiv2/amqpBinding-test2.js | 19 ------------------- 2 files changed, 27 deletions(-) diff --git a/test/unit/ngsiv2/MQTT_receive_ngsild_measures-test.js b/test/unit/ngsiv2/MQTT_receive_ngsild_measures-test.js index 90b8f469..4b841e9b 100644 --- a/test/unit/ngsiv2/MQTT_receive_ngsild_measures-test.js +++ b/test/unit/ngsiv2/MQTT_receive_ngsild_measures-test.js @@ -209,14 +209,6 @@ describe('MQTT: NGSILD Measure reception ', function () { utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure3.json') ) .reply(204); - // contextBrokerMock - // .matchHeader('fiware-service', 'smartgondor') - // .matchHeader('fiware-servicepath', '/gardens') - // .post( - // '/v2/entities?options=upsert', - // utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure2.json') - // ) - // .reply(204); }); it('should send its value to the Context Broker', function (done) { diff --git a/test/unit/ngsiv2/amqpBinding-test2.js b/test/unit/ngsiv2/amqpBinding-test2.js index 63470920..683f0985 100644 --- a/test/unit/ngsiv2/amqpBinding-test2.js +++ b/test/unit/ngsiv2/amqpBinding-test2.js @@ -103,17 +103,7 @@ describe('AMQP Transport binding: multiple measures', function () { '/v2/op/update', utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasureAMQP4.json') ) - //.reply(200, utils.readExampleFile('./test/contextResponses/singleMeasureSuccess.json')); .reply(204); - - // contextBrokerMock - // .matchHeader('fiware-service', 'smartgondor') - // .matchHeader('fiware-servicepath', '/gardens') - // .post( - // '/v2/entities?options=upsert', - // utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP2.json') - // ) - // .reply(200, utils.readExampleFile('./test/contextResponses/singleMeasureSuccess.json')); }); it('should send a single update context request with all the attributes', function (done) { @@ -140,15 +130,6 @@ describe('AMQP Transport binding: multiple measures', function () { utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure3.json') ) .reply(204); - - // contextBrokerMock - // .matchHeader('fiware-service', 'smartgondor') - // .matchHeader('fiware-servicepath', '/gardens') - // .post( - // '/v2/entities?options=upsert', - // utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure2.json') - // ) - // .reply(204); }); it('should send one update context per measure group to the Contet Broker', function (done) { From 11402ab036747032c4e3835991d3fae97fc591a0 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 28 Jan 2025 14:34:12 +0100 Subject: [PATCH 7/9] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 7c7547b4..17da4161 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,3 +1,4 @@ +- Fix: allow send multiple measures in MQTT to CB in a batch (POST /v2/op/update) and sorted by TimeInstant when possible, instead of using multiples single request (#825, iotagent-node-lib#1612) - Fix: check endpoint expression when execute http command - Fix: use config.defaultTransport (from config.js or IOTA_DEFAULT_TRANSPORT env var) instead of magic 'HTTP' at provision device - Add: X-Processing-Time response header with processing time (in milliseconds) expended by current HTTP measure (iotagent-node-lib#1650) From 8e4a280526e8ef46e9f7fd30c23135dafa754ca0 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 28 Jan 2025 15:43:53 +0100 Subject: [PATCH 8/9] Update MQTT_receive_ngsiv2_measures-test.js --- test/unit/ngsiv2/MQTT_receive_ngsiv2_measures-test.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/unit/ngsiv2/MQTT_receive_ngsiv2_measures-test.js b/test/unit/ngsiv2/MQTT_receive_ngsiv2_measures-test.js index 65a3aa7e..af49ff4d 100644 --- a/test/unit/ngsiv2/MQTT_receive_ngsiv2_measures-test.js +++ b/test/unit/ngsiv2/MQTT_receive_ngsiv2_measures-test.js @@ -468,14 +468,6 @@ describe('MQTT: NGSIv2 Measure reception ', function () { utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure3.json') ) .reply(204); - // contextBrokerMock - // .matchHeader('fiware-service', 'smartgondor') - // .matchHeader('fiware-servicepath', '/gardens') - // .post( - // '/v2/entities?options=upsert', - // utils.readExampleFile('./test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure2.json') - // ) - // .reply(204); }); it('should send its value to the Context Broker', function (done) { mqttClient.publish('json/1234/MQTT_2/attrs', JSON.stringify(measure), null, function (error) { From 5f6313f3a5e83f19ef2daec3904602cf953aec6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Tue, 28 Jan 2025 16:28:36 +0100 Subject: [PATCH 9/9] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 17da4161..41456e4f 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,4 +1,4 @@ -- Fix: allow send multiple measures in MQTT to CB in a batch (POST /v2/op/update) and sorted by TimeInstant when possible, instead of using multiples single request (#825, iotagent-node-lib#1612) +- Fix: allow send multiple measures in MQTT to CB in a batch (POST /v2/op/update) and sorted by TimeInstant when possible, instead of using multiples single request (#825, iotagent-node-lib#1612) (reopened) - Fix: check endpoint expression when execute http command - Fix: use config.defaultTransport (from config.js or IOTA_DEFAULT_TRANSPORT env var) instead of magic 'HTTP' at provision device - Add: X-Processing-Time response header with processing time (in milliseconds) expended by current HTTP measure (iotagent-node-lib#1650)