|
|
|
@ -68,11 +68,13 @@ import org.thingsboard.server.service.ws.telemetry.cmd.v2.AlarmStatusUpdate; |
|
|
|
import org.thingsboard.server.service.ws.telemetry.cmd.v2.EntityCountCmd; |
|
|
|
import org.thingsboard.server.service.ws.telemetry.cmd.v2.EntityCountUpdate; |
|
|
|
import org.thingsboard.server.service.ws.telemetry.cmd.v2.EntityDataUpdate; |
|
|
|
import org.thingsboard.server.service.ws.telemetry.sub.TelemetrySubscriptionUpdate; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
@ -584,6 +586,33 @@ public class WebsocketApiTest extends AbstractControllerTest { |
|
|
|
Assert.assertNull(msg); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testTimeseriesSubscriptionCmd() throws Exception { |
|
|
|
long now = System.currentTimeMillis() - 100; |
|
|
|
|
|
|
|
long lastTs = now - TimeUnit.MINUTES.toMillis(1); |
|
|
|
TsKvEntry dataPoint1 = new BasicTsKvEntry(lastTs, new LongDataEntry("temperature", 42L)); |
|
|
|
sendTelemetry(device, List.of(dataPoint1)); |
|
|
|
|
|
|
|
JsonNode update = getWsClient().sendTimeseriesCmd(device.getId(), "LATEST_TELEMETRY"); |
|
|
|
JsonNode data = update.get("data"); |
|
|
|
Assert.assertEquals(1, data.size()); |
|
|
|
Assert.assertEquals(JacksonUtil.newArrayNode().add(lastTs).add("42"), data.get("temperature").get(0)); |
|
|
|
|
|
|
|
//Sending update from the past, while latest value has new timestamp;
|
|
|
|
TsKvEntry dataPoint4 = new BasicTsKvEntry(now - TimeUnit.MINUTES.toMillis(5), new LongDataEntry("temperature", 45L)); |
|
|
|
getWsClient().registerWaitForUpdate(); |
|
|
|
sendTelemetry(device, List.of(dataPoint4)); |
|
|
|
String msg = getWsClient().waitForUpdate(TimeUnit.SECONDS.toMillis(1)); |
|
|
|
Assert.assertNull(msg); |
|
|
|
|
|
|
|
//Sending duplicate update again
|
|
|
|
getWsClient().registerWaitForUpdate(); |
|
|
|
sendTelemetry(device, List.of(dataPoint4)); |
|
|
|
msg = getWsClient().waitForUpdate(TimeUnit.SECONDS.toMillis(1)); |
|
|
|
Assert.assertNull(msg); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testEntityDataLatestTsWsCmd() throws Exception { |
|
|
|
long now = System.currentTimeMillis(); |
|
|
|
|