Copy queryId when updating query
This commit is contained in:
parent
3a3771db64
commit
28d6e4c736
@ -47,4 +47,12 @@ public class BaseReadTsKvQuery extends BaseTsKvQuery implements ReadTsKvQuery {
|
|||||||
this(key, startTs, endTs, endTs - startTs, limit, Aggregation.NONE, order);
|
this(key, startTs, endTs, endTs - startTs, limit, Aggregation.NONE, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BaseReadTsKvQuery(ReadTsKvQuery query, long startTs, long endTs) {
|
||||||
|
super(query.getId(), query.getKey(), startTs, endTs);
|
||||||
|
this.interval = query.getInterval();
|
||||||
|
this.limit = query.getLimit();
|
||||||
|
this.aggregation = query.getAggregation();
|
||||||
|
this.order = query.getOrder();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,8 +28,12 @@ public class BaseTsKvQuery implements TsKvQuery {
|
|||||||
private final long endTs;
|
private final long endTs;
|
||||||
|
|
||||||
public BaseTsKvQuery(String key, long startTs, long endTs) {
|
public BaseTsKvQuery(String key, long startTs, long endTs) {
|
||||||
this.id = idSeq.get();
|
this(idSeq.get(), key, startTs, endTs);
|
||||||
idSeq.set(id + 1);
|
idSeq.set(id + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BaseTsKvQuery(int id, String key, long startTs, long endTs) {
|
||||||
|
this.id = id;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.startTs = startTs;
|
this.startTs = startTs;
|
||||||
this.endTs = endTs;
|
this.endTs = endTs;
|
||||||
|
|||||||
@ -234,7 +234,7 @@ public class BaseTimeseriesService implements TimeseriesService {
|
|||||||
} else {
|
} else {
|
||||||
endTs = query.getEndTs();
|
endTs = query.getEndTs();
|
||||||
}
|
}
|
||||||
return new BaseReadTsKvQuery(query.getKey(), startTs, endTs, query.getInterval(), query.getLimit(), query.getAggregation(), query.getOrder());
|
return new BaseReadTsKvQuery(query, startTs, endTs);
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import org.thingsboard.server.common.data.kv.DoubleDataEntry;
|
|||||||
import org.thingsboard.server.common.data.kv.KvEntry;
|
import org.thingsboard.server.common.data.kv.KvEntry;
|
||||||
import org.thingsboard.server.common.data.kv.LongDataEntry;
|
import org.thingsboard.server.common.data.kv.LongDataEntry;
|
||||||
import org.thingsboard.server.common.data.kv.ReadTsKvQuery;
|
import org.thingsboard.server.common.data.kv.ReadTsKvQuery;
|
||||||
|
import org.thingsboard.server.common.data.kv.ReadTsKvQueryResult;
|
||||||
import org.thingsboard.server.common.data.kv.StringDataEntry;
|
import org.thingsboard.server.common.data.kv.StringDataEntry;
|
||||||
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
||||||
import org.thingsboard.server.common.data.objects.TelemetryEntityView;
|
import org.thingsboard.server.common.data.objects.TelemetryEntityView;
|
||||||
@ -48,6 +49,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@ -344,6 +346,36 @@ public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
|
|||||||
Assert.assertEquals(toTsEntry(TS - 3, stringKvEntry), entries.get(2));
|
Assert.assertEquals(toTsEntry(TS - 3, stringKvEntry), entries.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAllByQueries_verifyQueryId() throws Exception {
|
||||||
|
DeviceId deviceId = new DeviceId(Uuids.timeBased());
|
||||||
|
saveEntries(deviceId, TS);
|
||||||
|
saveEntries(deviceId, TS - 2);
|
||||||
|
saveEntries(deviceId, TS - 10);
|
||||||
|
|
||||||
|
BaseReadTsKvQuery query = new BaseReadTsKvQuery(STRING_KEY, TS - 10, TS + 1, 0, 1000, Aggregation.NONE, "DESC");
|
||||||
|
findAndVerifyQueryId(deviceId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindAllByQueries_verifyQueryId_forEntityView() throws Exception {
|
||||||
|
DeviceId deviceId = new DeviceId(Uuids.timeBased());
|
||||||
|
saveEntries(deviceId, TS);
|
||||||
|
saveEntries(deviceId, TS - 2);
|
||||||
|
saveEntries(deviceId, TS - 12);
|
||||||
|
|
||||||
|
EntityView entityView = saveAndCreateEntityView(deviceId, List.of(LONG_KEY));
|
||||||
|
|
||||||
|
BaseReadTsKvQuery query = new BaseReadTsKvQuery(LONG_KEY, TS - 10, TS + 1, 0, 1000, Aggregation.NONE, "DESC");
|
||||||
|
findAndVerifyQueryId(entityView.getId(), query);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void findAndVerifyQueryId(EntityId entityId, ReadTsKvQuery query) throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
List<ReadTsKvQueryResult> results = tsService.findAllByQueries(tenantId, entityId, List.of(query)).get(MAX_TIMEOUT, TimeUnit.SECONDS);
|
||||||
|
assertThat(results).isNotEmpty();
|
||||||
|
assertThat(results).extracting(ReadTsKvQueryResult::getQueryId).containsOnly(query.getId());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteDeviceTsDataWithOverwritingLatest() throws Exception {
|
public void testDeleteDeviceTsDataWithOverwritingLatest() throws Exception {
|
||||||
DeviceId deviceId = new DeviceId(Uuids.timeBased());
|
DeviceId deviceId = new DeviceId(Uuids.timeBased());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user