...
|
...
|
@@ -28,6 +28,8 @@ import org.thingsboard.server.common.data.Device; |
28
|
28
|
import org.thingsboard.server.common.data.Tenant;
|
29
|
29
|
import org.thingsboard.server.common.data.User;
|
30
|
30
|
import org.thingsboard.server.common.data.kv.Aggregation;
|
|
31
|
+import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
|
32
|
+import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry;
|
31
|
33
|
import org.thingsboard.server.common.data.kv.BasicTsKvEntry;
|
32
|
34
|
import org.thingsboard.server.common.data.kv.LongDataEntry;
|
33
|
35
|
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
...
|
...
|
@@ -41,6 +43,7 @@ import org.thingsboard.server.common.data.query.EntityKeyType; |
41
|
43
|
import org.thingsboard.server.common.data.query.TsValue;
|
42
|
44
|
import org.thingsboard.server.common.data.security.Authority;
|
43
|
45
|
import org.thingsboard.server.dao.timeseries.TimeseriesService;
|
|
46
|
+import org.thingsboard.server.service.subscription.TbAttributeSubscriptionScope;
|
44
|
47
|
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
|
45
|
48
|
import org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper;
|
46
|
49
|
import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd;
|
...
|
...
|
@@ -48,6 +51,7 @@ import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUpdate; |
48
|
51
|
import org.thingsboard.server.service.telemetry.cmd.v2.EntityHistoryCmd;
|
49
|
52
|
import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd;
|
50
|
53
|
|
|
54
|
+import java.util.ArrayList;
|
51
|
55
|
import java.util.Arrays;
|
52
|
56
|
import java.util.Collections;
|
53
|
57
|
import java.util.List;
|
...
|
...
|
@@ -139,7 +143,7 @@ public class BaseWebsocketApiTest extends AbstractWebsocketTest { |
139
|
143
|
List<TsKvEntry> tsData = Arrays.asList(dataPoint1, dataPoint2, dataPoint3);
|
140
|
144
|
|
141
|
145
|
sendTelemetry(device, tsData);
|
142
|
|
- Thread.sleep(1000);
|
|
146
|
+ Thread.sleep(100);
|
143
|
147
|
|
144
|
148
|
wsClient.send(mapper.writeValueAsString(wrapper));
|
145
|
149
|
msg = wsClient.waitForReply();
|
...
|
...
|
@@ -156,25 +160,8 @@ public class BaseWebsocketApiTest extends AbstractWebsocketTest { |
156
|
160
|
Assert.assertEquals(new TsValue(dataPoint3.getTs(), dataPoint3.getValueAsString()), tsArray[2]);
|
157
|
161
|
}
|
158
|
162
|
|
159
|
|
- private void sendTelemetry(Device device, List<TsKvEntry> tsData) throws InterruptedException {
|
160
|
|
- CountDownLatch latch = new CountDownLatch(1);
|
161
|
|
- tsService.saveAndNotify(device.getTenantId(), device.getId(), tsData, 0, new FutureCallback<Void>() {
|
162
|
|
- @Override
|
163
|
|
- public void onSuccess(@Nullable Void result) {
|
164
|
|
- latch.countDown();
|
165
|
|
- }
|
166
|
|
-
|
167
|
|
- @Override
|
168
|
|
- public void onFailure(Throwable t) {
|
169
|
|
- latch.countDown();
|
170
|
|
- }
|
171
|
|
- });
|
172
|
|
- latch.await(3, TimeUnit.SECONDS);
|
173
|
|
- }
|
174
|
|
-
|
175
|
163
|
@Test
|
176
|
|
- @Ignore
|
177
|
|
- public void testEntityDataLatestWsCmd() throws Exception {
|
|
164
|
+ public void testEntityDataLatestTsWsCmd() throws Exception {
|
178
|
165
|
Device device = new Device();
|
179
|
166
|
device.setName("Device");
|
180
|
167
|
device.setType("default");
|
...
|
...
|
@@ -211,9 +198,9 @@ public class BaseWebsocketApiTest extends AbstractWebsocketTest { |
211
|
198
|
List<TsKvEntry> tsData = Arrays.asList(dataPoint1);
|
212
|
199
|
sendTelemetry(device, tsData);
|
213
|
200
|
|
214
|
|
- cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
|
215
|
|
-
|
|
201
|
+ Thread.sleep(100);
|
216
|
202
|
|
|
203
|
+ cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
|
217
|
204
|
wrapper = new TelemetryPluginCmdsWrapper();
|
218
|
205
|
wrapper.setEntityDataCmds(Collections.singletonList(cmd));
|
219
|
206
|
|
...
|
...
|
@@ -231,11 +218,12 @@ public class BaseWebsocketApiTest extends AbstractWebsocketTest { |
231
|
218
|
TsValue tsValue = pageData.getData().get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("temperature");
|
232
|
219
|
Assert.assertEquals(new TsValue(dataPoint1.getTs(), dataPoint1.getValueAsString()), tsValue);
|
233
|
220
|
|
234
|
|
- log.error("GOING TO LISTEN FOR UPDATES");
|
235
|
|
- msg = wsClient.waitForUpdate();
|
236
|
221
|
now = System.currentTimeMillis();
|
237
|
222
|
TsKvEntry dataPoint2 = new BasicTsKvEntry(now, new LongDataEntry("temperature", 52L));
|
|
223
|
+
|
|
224
|
+ wsClient.registerWaitForUpdate();
|
238
|
225
|
sendTelemetry(device, Arrays.asList(dataPoint2));
|
|
226
|
+ msg = wsClient.waitForUpdate();
|
239
|
227
|
|
240
|
228
|
update = mapper.readValue(msg, EntityDataUpdate.class);
|
241
|
229
|
Assert.assertEquals(1, update.getCmdId());
|
...
|
...
|
@@ -247,6 +235,280 @@ public class BaseWebsocketApiTest extends AbstractWebsocketTest { |
247
|
235
|
tsValue = eData.get(0).getLatest().get(EntityKeyType.TIME_SERIES).get("temperature");
|
248
|
236
|
Assert.assertEquals(new TsValue(dataPoint2.getTs(), dataPoint2.getValueAsString()), tsValue);
|
249
|
237
|
|
|
238
|
+ //Sending update from the past, while latest value has new timestamp;
|
|
239
|
+ wsClient.registerWaitForUpdate();
|
|
240
|
+ sendTelemetry(device, Arrays.asList(dataPoint1));
|
|
241
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
242
|
+ Assert.assertNull(msg);
|
|
243
|
+
|
|
244
|
+ //Sending duplicate update again
|
|
245
|
+ wsClient.registerWaitForUpdate();
|
|
246
|
+ sendTelemetry(device, Arrays.asList(dataPoint2));
|
|
247
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
248
|
+ Assert.assertNull(msg);
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+ @Test
|
|
252
|
+ public void testEntityDataLatestAttrWsCmd() throws Exception {
|
|
253
|
+ Device device = new Device();
|
|
254
|
+ device.setName("Device");
|
|
255
|
+ device.setType("default");
|
|
256
|
+ device.setLabel("testLabel" + (int) (Math.random() * 1000));
|
|
257
|
+ device = doPost("/api/device", device, Device.class);
|
|
258
|
+
|
|
259
|
+ long now = System.currentTimeMillis();
|
|
260
|
+
|
|
261
|
+ DeviceTypeFilter dtf = new DeviceTypeFilter();
|
|
262
|
+ dtf.setDeviceNameFilter("D");
|
|
263
|
+ dtf.setDeviceType("default");
|
|
264
|
+ EntityDataQuery edq = new EntityDataQuery(dtf, new EntityDataPageLink(1, 0, null, null),
|
|
265
|
+ Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
|
266
|
+
|
|
267
|
+ LatestValueCmd latestCmd = new LatestValueCmd();
|
|
268
|
+ latestCmd.setKeys(Collections.singletonList(new EntityKey(EntityKeyType.SERVER_ATTRIBUTE, "serverAttributeKey")));
|
|
269
|
+ EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
|
|
270
|
+
|
|
271
|
+ TelemetryPluginCmdsWrapper wrapper = new TelemetryPluginCmdsWrapper();
|
|
272
|
+ wrapper.setEntityDataCmds(Collections.singletonList(cmd));
|
|
273
|
+
|
|
274
|
+ wsClient.send(mapper.writeValueAsString(wrapper));
|
|
275
|
+ String msg = wsClient.waitForReply();
|
|
276
|
+ EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
277
|
+ Assert.assertEquals(1, update.getCmdId());
|
|
278
|
+ PageData<EntityData> pageData = update.getData();
|
|
279
|
+ Assert.assertNotNull(pageData);
|
|
280
|
+ Assert.assertEquals(1, pageData.getData().size());
|
|
281
|
+ Assert.assertEquals(device.getId(), pageData.getData().get(0).getEntityId());
|
|
282
|
+ Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey"));
|
|
283
|
+ Assert.assertEquals(0, pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey").getTs());
|
|
284
|
+ Assert.assertEquals("", pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey").getValue());
|
|
285
|
+
|
|
286
|
+ AttributeKvEntry dataPoint1 = new BaseAttributeKvEntry(now - TimeUnit.MINUTES.toMillis(1), new LongDataEntry("serverAttributeKey", 42L));
|
|
287
|
+ List<AttributeKvEntry> tsData = Arrays.asList(dataPoint1);
|
|
288
|
+ sendAttributes(device, TbAttributeSubscriptionScope.SERVER_SCOPE, tsData);
|
|
289
|
+
|
|
290
|
+ Thread.sleep(100);
|
|
291
|
+
|
|
292
|
+ cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
|
|
293
|
+ wrapper = new TelemetryPluginCmdsWrapper();
|
|
294
|
+ wrapper.setEntityDataCmds(Collections.singletonList(cmd));
|
|
295
|
+
|
|
296
|
+ wsClient.send(mapper.writeValueAsString(wrapper));
|
|
297
|
+ msg = wsClient.waitForReply();
|
|
298
|
+ update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
299
|
+
|
|
300
|
+ Assert.assertEquals(1, update.getCmdId());
|
|
301
|
+
|
|
302
|
+ pageData = update.getData();
|
|
303
|
+ Assert.assertNotNull(pageData);
|
|
304
|
+ Assert.assertEquals(1, pageData.getData().size());
|
|
305
|
+ Assert.assertEquals(device.getId(), pageData.getData().get(0).getEntityId());
|
|
306
|
+ Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE));
|
|
307
|
+ TsValue tsValue = pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey");
|
|
308
|
+ Assert.assertEquals(new TsValue(dataPoint1.getLastUpdateTs(), dataPoint1.getValueAsString()), tsValue);
|
|
309
|
+
|
|
310
|
+ now = System.currentTimeMillis();
|
|
311
|
+ AttributeKvEntry dataPoint2 = new BaseAttributeKvEntry(now, new LongDataEntry("serverAttributeKey", 52L));
|
|
312
|
+
|
|
313
|
+ wsClient.registerWaitForUpdate();
|
|
314
|
+ sendAttributes(device, TbAttributeSubscriptionScope.SERVER_SCOPE, Arrays.asList(dataPoint2));
|
|
315
|
+ msg = wsClient.waitForUpdate();
|
|
316
|
+
|
|
317
|
+ update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
318
|
+ Assert.assertEquals(1, update.getCmdId());
|
|
319
|
+ List<EntityData> eData = update.getUpdate();
|
|
320
|
+ Assert.assertNotNull(eData);
|
|
321
|
+ Assert.assertEquals(1, eData.size());
|
|
322
|
+ Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
|
|
323
|
+ Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE));
|
|
324
|
+ tsValue = eData.get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey");
|
|
325
|
+ Assert.assertEquals(new TsValue(dataPoint2.getLastUpdateTs(), dataPoint2.getValueAsString()), tsValue);
|
|
326
|
+
|
|
327
|
+ //Sending update from the past, while latest value has new timestamp;
|
|
328
|
+ wsClient.registerWaitForUpdate();
|
|
329
|
+ sendAttributes(device, TbAttributeSubscriptionScope.SERVER_SCOPE, Arrays.asList(dataPoint1));
|
|
330
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
331
|
+ Assert.assertNull(msg);
|
|
332
|
+
|
|
333
|
+ //Sending duplicate update again
|
|
334
|
+ wsClient.registerWaitForUpdate();
|
|
335
|
+ sendAttributes(device, TbAttributeSubscriptionScope.SERVER_SCOPE, Arrays.asList(dataPoint2));
|
|
336
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
337
|
+ Assert.assertNull(msg);
|
|
338
|
+ }
|
|
339
|
+
|
|
340
|
+ @Test
|
|
341
|
+ public void testEntityDataLatestAttrTypesWsCmd() throws Exception {
|
|
342
|
+ Device device = new Device();
|
|
343
|
+ device.setName("Device");
|
|
344
|
+ device.setType("default");
|
|
345
|
+ device.setLabel("testLabel" + (int) (Math.random() * 1000));
|
|
346
|
+ device = doPost("/api/device", device, Device.class);
|
|
347
|
+
|
|
348
|
+ long now = System.currentTimeMillis();
|
|
349
|
+
|
|
350
|
+ DeviceTypeFilter dtf = new DeviceTypeFilter();
|
|
351
|
+ dtf.setDeviceNameFilter("D");
|
|
352
|
+ dtf.setDeviceType("default");
|
|
353
|
+ EntityDataQuery edq = new EntityDataQuery(dtf, new EntityDataPageLink(1, 0, null, null),
|
|
354
|
+ Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
|
355
|
+
|
|
356
|
+ LatestValueCmd latestCmd = new LatestValueCmd();
|
|
357
|
+ List<EntityKey> keys = new ArrayList<>();
|
|
358
|
+ keys.add(new EntityKey(EntityKeyType.SERVER_ATTRIBUTE, "serverAttributeKey"));
|
|
359
|
+ keys.add(new EntityKey(EntityKeyType.CLIENT_ATTRIBUTE, "clientAttributeKey"));
|
|
360
|
+ keys.add(new EntityKey(EntityKeyType.SHARED_ATTRIBUTE, "sharedAttributeKey"));
|
|
361
|
+ keys.add(new EntityKey(EntityKeyType.ATTRIBUTE, "anyAttributeKey"));
|
|
362
|
+ latestCmd.setKeys(keys);
|
|
363
|
+ EntityDataCmd cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
|
|
364
|
+
|
|
365
|
+ TelemetryPluginCmdsWrapper wrapper = new TelemetryPluginCmdsWrapper();
|
|
366
|
+ wrapper.setEntityDataCmds(Collections.singletonList(cmd));
|
|
367
|
+
|
|
368
|
+ wsClient.send(mapper.writeValueAsString(wrapper));
|
|
369
|
+ String msg = wsClient.waitForReply();
|
|
370
|
+ EntityDataUpdate update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
371
|
+ Assert.assertEquals(1, update.getCmdId());
|
|
372
|
+ PageData<EntityData> pageData = update.getData();
|
|
373
|
+ Assert.assertNotNull(pageData);
|
|
374
|
+ Assert.assertEquals(1, pageData.getData().size());
|
|
375
|
+ Assert.assertEquals(device.getId(), pageData.getData().get(0).getEntityId());
|
|
376
|
+ Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey"));
|
|
377
|
+ Assert.assertEquals(0, pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey").getTs());
|
|
378
|
+ Assert.assertEquals("", pageData.getData().get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey").getValue());
|
|
379
|
+ Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE).get("clientAttributeKey"));
|
|
380
|
+ Assert.assertEquals(0, pageData.getData().get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE).get("clientAttributeKey").getTs());
|
|
381
|
+ Assert.assertEquals("", pageData.getData().get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE).get("clientAttributeKey").getValue());
|
|
382
|
+ Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE).get("sharedAttributeKey"));
|
|
383
|
+ Assert.assertEquals(0, pageData.getData().get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE).get("sharedAttributeKey").getTs());
|
|
384
|
+ Assert.assertEquals("", pageData.getData().get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE).get("sharedAttributeKey").getValue());
|
|
385
|
+ Assert.assertNotNull(pageData.getData().get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey"));
|
|
386
|
+ Assert.assertEquals(0, pageData.getData().get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey").getTs());
|
|
387
|
+ Assert.assertEquals("", pageData.getData().get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey").getValue());
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+ wsClient.registerWaitForUpdate();
|
|
391
|
+ AttributeKvEntry dataPoint1 = new BaseAttributeKvEntry(now - TimeUnit.MINUTES.toMillis(1), new LongDataEntry("serverAttributeKey", 42L));
|
|
392
|
+ List<AttributeKvEntry> tsData = Arrays.asList(dataPoint1);
|
|
393
|
+ sendAttributes(device, TbAttributeSubscriptionScope.SERVER_SCOPE, tsData);
|
|
394
|
+
|
|
395
|
+ Thread.sleep(100);
|
|
396
|
+
|
|
397
|
+ cmd = new EntityDataCmd(1, edq, null, latestCmd, null);
|
|
398
|
+ wrapper = new TelemetryPluginCmdsWrapper();
|
|
399
|
+ wrapper.setEntityDataCmds(Collections.singletonList(cmd));
|
|
400
|
+
|
|
401
|
+ msg = wsClient.waitForUpdate();
|
|
402
|
+
|
|
403
|
+ update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
404
|
+ Assert.assertEquals(1, update.getCmdId());
|
|
405
|
+ List<EntityData> eData = update.getUpdate();
|
|
406
|
+ Assert.assertNotNull(eData);
|
|
407
|
+ Assert.assertEquals(1, eData.size());
|
|
408
|
+ Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
|
|
409
|
+ Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE));
|
|
410
|
+ TsValue attrValue = eData.get(0).getLatest().get(EntityKeyType.SERVER_ATTRIBUTE).get("serverAttributeKey");
|
|
411
|
+ Assert.assertEquals(new TsValue(dataPoint1.getLastUpdateTs(), dataPoint1.getValueAsString()), attrValue);
|
|
412
|
+
|
|
413
|
+ //Sending update from the past, while latest value has new timestamp;
|
|
414
|
+ wsClient.registerWaitForUpdate();
|
|
415
|
+ sendAttributes(device, TbAttributeSubscriptionScope.SHARED_SCOPE, Arrays.asList(dataPoint1));
|
|
416
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
417
|
+ Assert.assertNull(msg);
|
|
418
|
+
|
|
419
|
+ //Sending duplicate update again
|
|
420
|
+ wsClient.registerWaitForUpdate();
|
|
421
|
+ sendAttributes(device, TbAttributeSubscriptionScope.CLIENT_SCOPE, Arrays.asList(dataPoint1));
|
|
422
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
423
|
+ Assert.assertNull(msg);
|
|
424
|
+
|
|
425
|
+ //Sending update from the past, while latest value has new timestamp;
|
|
426
|
+ wsClient.registerWaitForUpdate();
|
|
427
|
+ AttributeKvEntry dataPoint2 = new BaseAttributeKvEntry(now, new LongDataEntry("sharedAttributeKey", 42L));
|
|
428
|
+ sendAttributes(device, TbAttributeSubscriptionScope.SHARED_SCOPE, Arrays.asList(dataPoint2));
|
|
429
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
430
|
+ update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
431
|
+ Assert.assertEquals(1, update.getCmdId());
|
|
432
|
+ eData = update.getUpdate();
|
|
433
|
+ Assert.assertNotNull(eData);
|
|
434
|
+ Assert.assertEquals(1, eData.size());
|
|
435
|
+ Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
|
|
436
|
+ Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE));
|
|
437
|
+ attrValue = eData.get(0).getLatest().get(EntityKeyType.SHARED_ATTRIBUTE).get("sharedAttributeKey");
|
|
438
|
+ Assert.assertEquals(new TsValue(dataPoint2.getLastUpdateTs(), dataPoint2.getValueAsString()), attrValue);
|
|
439
|
+
|
|
440
|
+ wsClient.registerWaitForUpdate();
|
|
441
|
+ AttributeKvEntry dataPoint3 = new BaseAttributeKvEntry(now, new LongDataEntry("clientAttributeKey", 42L));
|
|
442
|
+ sendAttributes(device, TbAttributeSubscriptionScope.CLIENT_SCOPE, Arrays.asList(dataPoint3));
|
|
443
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
444
|
+ update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
445
|
+ Assert.assertEquals(1, update.getCmdId());
|
|
446
|
+ eData = update.getUpdate();
|
|
447
|
+ Assert.assertNotNull(eData);
|
|
448
|
+ Assert.assertEquals(1, eData.size());
|
|
449
|
+ Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
|
|
450
|
+ Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE));
|
|
451
|
+ attrValue = eData.get(0).getLatest().get(EntityKeyType.CLIENT_ATTRIBUTE).get("clientAttributeKey");
|
|
452
|
+ Assert.assertEquals(new TsValue(dataPoint3.getLastUpdateTs(), dataPoint3.getValueAsString()), attrValue);
|
|
453
|
+
|
|
454
|
+ wsClient.registerWaitForUpdate();
|
|
455
|
+ AttributeKvEntry dataPoint4 = new BaseAttributeKvEntry(now, new LongDataEntry("anyAttributeKey", 42L));
|
|
456
|
+ sendAttributes(device, TbAttributeSubscriptionScope.CLIENT_SCOPE, Arrays.asList(dataPoint4));
|
|
457
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
458
|
+ update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
459
|
+ Assert.assertEquals(1, update.getCmdId());
|
|
460
|
+ eData = update.getUpdate();
|
|
461
|
+ Assert.assertNotNull(eData);
|
|
462
|
+ Assert.assertEquals(1, eData.size());
|
|
463
|
+ Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
|
|
464
|
+ Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.ATTRIBUTE));
|
|
465
|
+ attrValue = eData.get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey");
|
|
466
|
+ Assert.assertEquals(new TsValue(dataPoint4.getLastUpdateTs(), dataPoint4.getValueAsString()), attrValue);
|
|
467
|
+
|
|
468
|
+ wsClient.registerWaitForUpdate();
|
|
469
|
+ AttributeKvEntry dataPoint5 = new BaseAttributeKvEntry(now, new LongDataEntry("anyAttributeKey", 43L));
|
|
470
|
+ sendAttributes(device, TbAttributeSubscriptionScope.SERVER_SCOPE, Arrays.asList(dataPoint5));
|
|
471
|
+ msg = wsClient.waitForUpdate(TimeUnit.SECONDS.toMillis(1));
|
|
472
|
+ update = mapper.readValue(msg, EntityDataUpdate.class);
|
|
473
|
+ Assert.assertEquals(1, update.getCmdId());
|
|
474
|
+ eData = update.getUpdate();
|
|
475
|
+ Assert.assertNotNull(eData);
|
|
476
|
+ Assert.assertEquals(1, eData.size());
|
|
477
|
+ Assert.assertEquals(device.getId(), eData.get(0).getEntityId());
|
|
478
|
+ Assert.assertNotNull(eData.get(0).getLatest().get(EntityKeyType.ATTRIBUTE));
|
|
479
|
+ attrValue = eData.get(0).getLatest().get(EntityKeyType.ATTRIBUTE).get("anyAttributeKey");
|
|
480
|
+ Assert.assertEquals(new TsValue(dataPoint5.getLastUpdateTs(), dataPoint5.getValueAsString()), attrValue);
|
|
481
|
+ }
|
|
482
|
+
|
|
483
|
+ private void sendTelemetry(Device device, List<TsKvEntry> tsData) throws InterruptedException {
|
|
484
|
+ CountDownLatch latch = new CountDownLatch(1);
|
|
485
|
+ tsService.saveAndNotify(device.getTenantId(), device.getId(), tsData, 0, new FutureCallback<Void>() {
|
|
486
|
+ @Override
|
|
487
|
+ public void onSuccess(@Nullable Void result) {
|
|
488
|
+ latch.countDown();
|
|
489
|
+ }
|
|
490
|
+
|
|
491
|
+ @Override
|
|
492
|
+ public void onFailure(Throwable t) {
|
|
493
|
+ latch.countDown();
|
|
494
|
+ }
|
|
495
|
+ });
|
|
496
|
+ latch.await(3, TimeUnit.SECONDS);
|
250
|
497
|
}
|
251
|
498
|
|
|
499
|
+ private void sendAttributes(Device device, TbAttributeSubscriptionScope scope, List<AttributeKvEntry> attrData) throws InterruptedException {
|
|
500
|
+ CountDownLatch latch = new CountDownLatch(1);
|
|
501
|
+ tsService.saveAndNotify(device.getTenantId(), device.getId(), scope.name(), attrData, new FutureCallback<Void>() {
|
|
502
|
+ @Override
|
|
503
|
+ public void onSuccess(@Nullable Void result) {
|
|
504
|
+ latch.countDown();
|
|
505
|
+ }
|
|
506
|
+
|
|
507
|
+ @Override
|
|
508
|
+ public void onFailure(Throwable t) {
|
|
509
|
+ latch.countDown();
|
|
510
|
+ }
|
|
511
|
+ });
|
|
512
|
+ latch.await(3, TimeUnit.SECONDS);
|
|
513
|
+ }
|
252
|
514
|
} |
...
|
...
|
|