Skip to content

Commit 0830d34

Browse files
authored
[DB] Add "query by definition" datastore tests (#316)
1 parent e55721c commit 0830d34

File tree

3 files changed

+267
-155
lines changed

3 files changed

+267
-155
lines changed

sensorhub-core/src/testFixtures/java/org/sensorhub/impl/datastore/AbstractTestCommandStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public void testAddAndGetByKeyOneDataStream() throws Exception
308308
public void testGetWrongKey() throws Exception
309309
{
310310
testGetNumRecordsOneDataStream();
311-
assertNull(cmdStore.get(bigId(11)));
311+
assertNull(cmdStore.get(bigId(110)));
312312
}
313313

314314

sensorhub-core/src/testFixtures/java/org/sensorhub/impl/datastore/AbstractTestCommandStreamStore.java

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,28 @@ protected CommandStreamKey addSimpleCommandStream(FeatureId sysID, String output
126126

127127
return addCommandStream(sysID, dataStruct, validTime);
128128
}
129-
130-
129+
130+
protected CommandStreamKey addSimpleCommandStream(FeatureId sysID, String outputName, String description, TimeExtent validTime, String definition) throws DataStoreException
131+
{
132+
SWEHelper fac = new SWEHelper();
133+
var dataStruct = fac.createRecord()
134+
.name(outputName)
135+
.description(description)
136+
.addField("t1", fac.createTime().asSamplingTimeIsoUTC().build())
137+
.addField("q2", fac.createQuantity().build())
138+
.addField("c3", fac.createCount().build())
139+
.addField("b4", fac.createVector().definition(definition).build())
140+
.addField("txt5", fac.createText().build())
141+
.build();
142+
143+
return addCommandStream(sysID, dataStruct, validTime);
144+
}
145+
146+
protected CommandStreamKey addSimpleCommandStreamWithDefinition(BigId sysID, String outputName, TimeExtent validTime, String definition) throws DataStoreException
147+
{
148+
return addSimpleCommandStream(new FeatureId(sysID, PROC_UID_PREFIX+sysID), outputName, "command stream description", validTime, definition);
149+
}
150+
131151
protected CommandStreamKey addSimpleCommandStream(BigId sysID, String outputName, TimeExtent validTime) throws DataStoreException
132152
{
133153
return addSimpleCommandStream(new FeatureId(sysID, PROC_UID_PREFIX+sysID), outputName, "command stream description", validTime);
@@ -556,7 +576,42 @@ protected void testAddAndSelectByTimeRange_ExpectedResults(int testCaseIdx)
556576
case 3: addToExpectedResults(7); break;
557577
}
558578
}
559-
579+
580+
@Test
581+
@SuppressWarnings("unused")
582+
public void testAddAndSelectByTaskableProperty() throws Exception
583+
{
584+
Stream<Entry<CommandStreamKey, ICommandStreamInfo>> resultStream;
585+
586+
var now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
587+
var sysID1 = bigId(1);
588+
var sysID2 = bigId(2);
589+
var sysID3 = bigId(3);
590+
String def1 = "someDefinition1";
591+
String def2 = "someDefinition2";
592+
var ds1v0 = addSimpleCommandStreamWithDefinition(sysID1, "out1",
593+
TimeExtent.endNow(now.minus(365, ChronoUnit.DAYS)), def1);
594+
var ds2v0 = addSimpleCommandStream(sysID1, "out2", TimeExtent.endNow(now.minus(60, ChronoUnit.DAYS)));
595+
var ds4v0 = addSimpleCommandStreamWithDefinition(sysID3, "temp",
596+
TimeExtent.beginAt(now.plus(1, ChronoUnit.DAYS)), def2);
597+
var ds5v0 = addSimpleCommandStream(sysID3, "out3", TimeExtent.endNow(now.minus(60, ChronoUnit.DAYS)));
598+
var ds6v0 = addSimpleCommandStream(sysID3, "out4", TimeExtent.endNow(now.minus(60, ChronoUnit.DAYS)));
599+
cmdStreamStore.commit();
600+
601+
// select from t0 to now
602+
CommandStreamFilter filter = new CommandStreamFilter.Builder()
603+
.withTaskableProperties(def1, def2)
604+
.build();
605+
resultStream = cmdStreamStore.selectEntries(filter);
606+
607+
testAddAndSelectByTaskableProperty_ExpectedResults();
608+
checkSelectedEntries(resultStream, expectedResults, filter);
609+
}
610+
611+
protected void testAddAndSelectByTaskableProperty_ExpectedResults()
612+
{
613+
addToExpectedResults(0, 2);
614+
}
560615

561616
@Test
562617
@SuppressWarnings("unused")

0 commit comments

Comments
 (0)