Browse Source
Merge pull request #13565 from irynamatveieva/cf-old-telemetry-ts
Fixed updating CF state when old telemetry sent
pull/13575/head
Viacheslav Klimov
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
9 additions and
4 deletions
-
application/src/main/java/org/thingsboard/server/service/cf/ctx/state/SingleValueArgumentEntry.java
-
application/src/test/java/org/thingsboard/server/cf/CalculatedFieldIntegrationTest.java
-
application/src/test/java/org/thingsboard/server/service/cf/ctx/state/SingleValueArgumentEntryTest.java
|
|
|
@ -107,7 +107,7 @@ public class SingleValueArgumentEntry implements ArgumentEntry { |
|
|
|
@Override |
|
|
|
public boolean updateEntry(ArgumentEntry entry) { |
|
|
|
if (entry instanceof SingleValueArgumentEntry singleValueEntry) { |
|
|
|
if (singleValueEntry.getTs() == this.ts) { |
|
|
|
if (singleValueEntry.getTs() <= this.ts) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -555,7 +555,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
}); |
|
|
|
|
|
|
|
long tsABeforeTsB = tsB - 300L; |
|
|
|
doPost("/api/plugins/telemetry/DEVICE/" + testDevice.getUuidId() + "/timeseries/" + DataConstants.SERVER_SCOPE, JacksonUtil.toJsonNode(String.format("{\"ts\": %s, \"values\": {\"b\":10}}", tsABeforeTsB))); |
|
|
|
doPost("/api/plugins/telemetry/DEVICE/" + testDevice.getUuidId() + "/timeseries/" + DataConstants.SERVER_SCOPE, JacksonUtil.toJsonNode(String.format("{\"ts\": %s, \"values\": {\"a\":10}}", tsABeforeTsB))); |
|
|
|
|
|
|
|
await().alias("update telemetry with ts less than latest -> save result with latest ts").atMost(TIMEOUT, TimeUnit.SECONDS) |
|
|
|
.pollInterval(POLL_INTERVAL, TimeUnit.SECONDS) |
|
|
|
@ -563,7 +563,7 @@ public class CalculatedFieldIntegrationTest extends CalculatedFieldControllerTes |
|
|
|
ObjectNode c = getLatestTelemetry(testDevice.getId(), "c"); |
|
|
|
assertThat(c).isNotNull(); |
|
|
|
assertThat(c.get("c").get(0).get("ts").asText()).isEqualTo(Long.toString(tsB));// also tsB, since this is the latest timestamp
|
|
|
|
assertThat(c.get("c").get(0).get("value").asText()).isEqualTo("11.0"); |
|
|
|
assertThat(c.get("c").get(0).get("value").asText()).isEqualTo("15.0"); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -53,7 +53,7 @@ public class SingleValueArgumentEntryTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testUpdateEntryWithThaSameTs() { |
|
|
|
void testUpdateEntryWithTheSameTs() { |
|
|
|
assertThat(entry.updateEntry(new SingleValueArgumentEntry(ts, new LongDataEntry("key", 13L), 363L))).isFalse(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -81,6 +81,11 @@ public class SingleValueArgumentEntryTest { |
|
|
|
assertThat(entry.updateEntry(new SingleValueArgumentEntry(ts + 18, new LongDataEntry("key", 11L), 364L))).isTrue(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testUpdateEntryWithOldTs() { |
|
|
|
assertThat(entry.updateEntry(new SingleValueArgumentEntry(ts - 10, new LongDataEntry("key", 14L), 365L))).isFalse(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void testToTbelCfArgWhenJsonIsObject() { |
|
|
|
entry = new SingleValueArgumentEntry(ts, new JsonDataEntry("key", "{\"test\": 10}"), 370L); |
|
|
|
|