ATEST-81:
- fixing serialisation - adding tests
This commit is contained in:
@@ -37,7 +37,8 @@ public abstract class AbstractDaqRestTest {
|
||||
|
||||
protected MockMvc mockMvc;
|
||||
|
||||
protected ObjectMapper mapper = new ObjectMapper();
|
||||
@Autowired
|
||||
protected ObjectMapper mapper;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
|
||||
import ch.psi.daq.rest.DaqRestConfiguration;
|
||||
import ch.psi.daq.test.cassandra.LocalCassandraTestConfig;
|
||||
|
||||
@Configuration
|
||||
@@ -15,7 +16,7 @@ import ch.psi.daq.test.cassandra.LocalCassandraTestConfig;
|
||||
// "ch.psi.daq.cassandra.reader",
|
||||
// "ch.psi.daq.cassandra.writer"
|
||||
//})
|
||||
@Import(value = {LocalCassandraTestConfig.class})
|
||||
@Import(value = {LocalCassandraTestConfig.class, DaqRestConfiguration.class})
|
||||
@EnableWebMvc
|
||||
public class DaqRestApplicationConfiguration extends WebMvcConfigurationSupport {
|
||||
|
||||
|
||||
@@ -12,10 +12,14 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
|
||||
import ch.psi.daq.cassandra.reader.Ordering;
|
||||
import ch.psi.daq.hazelcast.query.AggregationType;
|
||||
import ch.psi.daq.hazelcast.query.range.QueryRange;
|
||||
import ch.psi.daq.hazelcast.query.range.QueryRangeImpl;
|
||||
import ch.psi.daq.rest.queries.BinningStrategyEnum;
|
||||
import ch.psi.daq.rest.queries.PulseRangeQuery;
|
||||
import ch.psi.daq.rest.queries.TimeRangeQuery;
|
||||
import ch.psi.daq.test.rest.AbstractDaqRestTest;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@@ -28,16 +32,17 @@ public class DaqControllerTest extends AbstractDaqRestTest {
|
||||
|
||||
@Test
|
||||
public void testPulseRangeQuery() throws Exception {
|
||||
QueryRange range = new QueryRangeImpl(100l, 101l);
|
||||
PulseRangeQuery request = new PulseRangeQuery(
|
||||
Ordering.DESC,
|
||||
Lists.newArrayList(), // DummyQueryProcessor simply returns a fixed list
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
Ordering.DESC, //ordering
|
||||
Lists.newArrayList(), // channels, DummyQueryProcessor simply returns a fixed list
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES), // fields
|
||||
BinningStrategyEnum.bincount,
|
||||
100,
|
||||
false,
|
||||
AggregationType.index,
|
||||
null,
|
||||
100l,
|
||||
101l
|
||||
);
|
||||
range);
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
|
||||
@@ -59,18 +64,18 @@ public class DaqControllerTest extends AbstractDaqRestTest {
|
||||
|
||||
long startTime = new Date().getTime();
|
||||
long endTime = startTime + TimeUnit.SECONDS.toMillis(1);
|
||||
QueryRange range = new QueryRangeImpl(startTime, 0, endTime, 0);
|
||||
TimeRangeQuery request = new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
Lists.newArrayList(), // DummyQueryProcessor simply returns a fixed list
|
||||
Lists.newArrayList("test"),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.bincount,
|
||||
100,
|
||||
false,
|
||||
AggregationType.index,
|
||||
null, // aggregations
|
||||
startTime, // startMillis
|
||||
0,
|
||||
null,
|
||||
endTime,
|
||||
0,
|
||||
range,
|
||||
null, // startMillis
|
||||
null);
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
@@ -87,4 +92,26 @@ public class DaqControllerTest extends AbstractDaqRestTest {
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$[0].channel").value("testChannel1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapper() throws JsonProcessingException {
|
||||
long startTime = new Date().getTime();
|
||||
long endTime = startTime + TimeUnit.SECONDS.toMillis(1);
|
||||
QueryRange range = new QueryRangeImpl(startTime, 0, endTime, 0);
|
||||
TimeRangeQuery request = new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
Lists.newArrayList("test"),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.bincount,
|
||||
100,
|
||||
false,
|
||||
AggregationType.index,
|
||||
null, // aggregations
|
||||
range,
|
||||
null, // startMillis
|
||||
null);
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
System.out.println(content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package ch.psi.daq.test.rest.queries;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class AbstractQueryTest {
|
||||
|
||||
protected static final List<String> DEFAULT_PROPERTIES = Lists.newArrayList("channel", "pulseId");
|
||||
|
||||
protected long startMillis = new Date().getTime();
|
||||
protected long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package ch.psi.daq.test.rest.queries;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
|
||||
import ch.psi.daq.cassandra.reader.Ordering;
|
||||
import ch.psi.daq.hazelcast.query.AggregationType;
|
||||
import ch.psi.daq.hazelcast.query.bin.BinningStrategyBinCount;
|
||||
import ch.psi.daq.hazelcast.query.bin.BinningStrategyLengthPulse;
|
||||
import ch.psi.daq.hazelcast.query.bin.BinningStrategyLengthTime;
|
||||
import ch.psi.daq.hazelcast.query.range.QueryRange;
|
||||
import ch.psi.daq.hazelcast.query.range.QueryRangeImpl;
|
||||
import ch.psi.daq.rest.queries.BinningStrategyEnum;
|
||||
import ch.psi.daq.rest.queries.TimeRangeQuery;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@RunWith(BlockJUnit4ClassRunner.class)
|
||||
public class AbstractQueryTestTest extends AbstractQueryTest {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void test_NoChannels_exception() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
|
||||
new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
null, // should throw exception
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.bincount,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void test_NoFields_exception() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
|
||||
new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
Lists.newArrayList(),
|
||||
null,
|
||||
BinningStrategyEnum.bincount,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_nullBinningStrategyEnum_exception() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
Lists.newArrayList(),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
null,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
Assert.assertTrue(query.getBinningStrategy() != null);
|
||||
Assert.assertEquals(BinningStrategyBinCount.class, query.getBinningStrategy().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_LengthBinningTimeStrategy() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
Lists.newArrayList(),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.lengthpulse,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
Assert.assertTrue(query.getBinningStrategy() != null);
|
||||
Assert.assertEquals(BinningStrategyLengthTime.class, query.getBinningStrategy().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_LengthBinningPulseStrategy() {
|
||||
|
||||
long startPulse = 100l;
|
||||
long endPulse = 105l;
|
||||
QueryRange range = new QueryRangeImpl(startPulse, endPulse);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
Lists.newArrayList(),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.lengthpulse,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
Assert.assertTrue(query.getBinningStrategy() != null);
|
||||
Assert.assertEquals(BinningStrategyLengthPulse.class, query.getBinningStrategy().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_BinCountBinningStrategy() {
|
||||
|
||||
long startMillis = new Date().getTime();
|
||||
long endMillis = new Date().getTime() + TimeUnit.SECONDS.toMillis(10);
|
||||
QueryRange range = new QueryRangeImpl(startMillis, 0, endMillis, 0);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
Lists.newArrayList(),
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.bincount,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
null, // startDateTime : String
|
||||
null); // endDateTime : String
|
||||
|
||||
Assert.assertTrue(query.getBinningStrategy() != null);
|
||||
Assert.assertEquals(BinningStrategyBinCount.class, query.getBinningStrategy().getClass());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package ch.psi.daq.test.rest.queries;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
|
||||
import ch.psi.daq.cassandra.reader.Ordering;
|
||||
import ch.psi.daq.hazelcast.query.AggregationType;
|
||||
import ch.psi.daq.hazelcast.query.range.QueryRange;
|
||||
import ch.psi.daq.hazelcast.query.range.QueryRangeImpl;
|
||||
import ch.psi.daq.rest.queries.BinningStrategyEnum;
|
||||
import ch.psi.daq.rest.queries.TimeRangeQuery;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@RunWith(BlockJUnit4ClassRunner.class)
|
||||
public class TimeRangeQueryTest extends AbstractQueryTest {
|
||||
|
||||
@Test
|
||||
public void test_startAndEndDateTime_asString() throws ParseException {
|
||||
|
||||
// allowed format: yyyy/MM/dd hh:mm:ss.SSS
|
||||
String startDateTime = "2014/01/01 12:00:00.000";
|
||||
String endDateTime = "2014/01/01 18:00:00.000";
|
||||
|
||||
QueryRange range = new QueryRangeImpl(-1, 0, -1, 0);
|
||||
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
Lists.newArrayList(), // DummyQueryProcessor simply returns a fixed list
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.bincount,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null, // list of aggregations
|
||||
range,
|
||||
startDateTime, // startDateTime : String
|
||||
endDateTime); // endDateTime : String
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat(TimeRangeQuery.DATE_FORMAT_STRING);
|
||||
|
||||
Assert.assertEquals(format.parse(startDateTime).getTime(), query.getQueryRange().getStartMillis());
|
||||
Assert.assertEquals(format.parse(endDateTime).getTime(), query.getQueryRange().getEndMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_wrongFormat_exception() {
|
||||
String startDateTime = "2014-01-01 12:00:00.000";
|
||||
String endDateTime = "2014/01/01 18:00:00.000";
|
||||
QueryRange range = new QueryRangeImpl(-1, 0, -1, 0);
|
||||
TimeRangeQuery query = new TimeRangeQuery(
|
||||
Ordering.ASC,
|
||||
Lists.newArrayList(), // DummyQueryProcessor simply returns a fixed list
|
||||
Sets.newLinkedHashSet(DEFAULT_PROPERTIES),
|
||||
BinningStrategyEnum.bincount,
|
||||
100, // binDurationOrBincount : long
|
||||
false, // isAggregateChannels
|
||||
AggregationType.index,
|
||||
null,
|
||||
range,
|
||||
startDateTime, // startDateTime : String
|
||||
endDateTime); // endDateTime : String
|
||||
|
||||
Assert.assertEquals(-1, query.getQueryRange().getStartMillis());
|
||||
Assert.assertEquals(-1, query.getQueryRange().getStartMillis());
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,10 @@
|
||||
"test2"
|
||||
],
|
||||
"fields": [
|
||||
"channel", pulseId", "globalMillis", "globalNanos", "dbValueBytes"
|
||||
"channel", "pulseId", "globalMillis", "globalNanos", "dbValueBytes"
|
||||
],
|
||||
"binningStrategy" : "bincount",
|
||||
"binDuration" : 100,
|
||||
"aggregateChannels":"false",
|
||||
"aggregationType": "index",
|
||||
"aggregations": [
|
||||
@@ -25,7 +27,7 @@
|
||||
"endPulseId" : 200
|
||||
}
|
||||
|
||||
curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"pulserange","ordering":"ASC","channels":["test1","test2"],"fields":["channel","pulseId"],"aggregateChannels":"false","aggregationType":"index","aggregations":[{"fieldRef":"e_val","type":"max","resultFieldName":"maximum"},{"fieldRef":"e_val","type":"min","resultFieldName":"minimum"}],"startPulseId":100,"endPulseId":200}' http://localhost:8080/pulserange
|
||||
curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"pulserange","ordering":"ASC","channels":["test1","test2"],"fields":["channel","pulseId","globalMillis","globalNanos","dbValueBytes"],"binningStrategy":"bincount","binDuration":100,"aggregateChannels":"false","aggregationType":"index","aggregations":[{"fieldRef":"e_val","type":"max","resultFieldName":"maximum"},{"fieldRef":"e_val","type":"min","resultFieldName":"minimum"}],"startPulseId":100,"endPulseId":200}' http://localhost:8080/pulserange
|
||||
|
||||
|
||||
===============================================================================================================================================
|
||||
@@ -40,15 +42,21 @@ curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"pulserange
|
||||
"channel",
|
||||
"pulseId"
|
||||
],
|
||||
"binningStrategy" : "duration",
|
||||
"binDuration" : 100,
|
||||
"aggregateChannels":false,
|
||||
"aggregationType": "index",
|
||||
"aggregations":null,
|
||||
"start":1434717654177,
|
||||
"startNanoOffset":0,
|
||||
"end":1434717655177,
|
||||
"endNanoOffset":0,
|
||||
"valueAggregation":"index",
|
||||
"binIntervalCalculator":null,
|
||||
"ordering":"DESC"
|
||||
}
|
||||
|
||||
curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"timerange","channels":["test1","test2"],"fields":["channel","pulseId"],"aggregateChannels":false,"aggregations":null,"start":1434717654177,"startNanoOffset":0,"end":1434717655177,"endNanoOffset":0,"valueAggregation":"index","ordering":"ASC"}' http://localhost:8080/timerange
|
||||
curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"timerange","channels":["test1","test2"],"fields":["channel","pulseId"],"binningStrategy":"duration","binDuration":100,"aggregateChannels":false,"aggregations":null,"start":1434717654177,"startNanoOffset":0,"end":1434717655177,"endNanoOffset":0,"aggregationType":"index","ordering":"DESC"}' http://localhost:8080/timerange
|
||||
|
||||
curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"timerange","ordering":"ASC","channels":["test"],"fields":["channel","pulseId"],"binningStrategy":{"combinedMarkerCalculator":{}},"aggregateChannels":false,"aggregationType":"index","queryRange":{"startMillis":1435048390294,"startNanos":0,"endMillis":1435048391294,"endNanos":0,"startPulseId":9223372036854775807,"endPulseId":9223372036854775807},"binningStrategyEnum":"bincount"}' http://localhost:8080/timerange
|
||||
|
||||
curl -v -X POST -H 'Content-Type: application/json' -d '{"queryType":"timerange","ordering":"ASC","channels":["test"],"fields":["channel","pulseId"],"aggregateChannels":false,"aggregationType":"index","queryRange":{"startMillis":1435049709091,"startNanos":0,"endMillis":1435049710091,"endNanos":0,"startPulseId":9223372036854775807,"endPulseId":9223372036854775807},"binningStrategyEnum":"bincount"}' http://localhost:8080/timerange
|
||||
|
||||
|
||||
Reference in New Issue
Block a user