ATEST-81:

- fixing serialisation
- adding tests
This commit is contained in:
Zellweger Christof Ralf
2015-06-23 11:49:08 +02:00
parent c51db19001
commit 1276e20399
12 changed files with 413 additions and 144 deletions

View File

@ -53,7 +53,7 @@ public class DaqRestController {
* @throws IOException
*/
@RequestMapping(value = "/timerange")
public void pulseRange(@RequestBody TimeRangeQuery query, HttpServletResponse res) throws IOException {
public void timeRange(@RequestBody TimeRangeQuery query, HttpServletResponse res) throws IOException {
logger.debug("TimeRangeQuery received: {}", query);

View File

@ -5,13 +5,17 @@ import java.util.LinkedHashSet;
import java.util.List;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
import ch.psi.daq.cassandra.reader.Ordering;
import ch.psi.daq.hazelcast.query.Aggregation;
import ch.psi.daq.hazelcast.query.AggregationType;
import ch.psi.daq.hazelcast.query.Query;
import ch.psi.daq.hazelcast.query.bin.BinIntervalCalculator;
import ch.psi.daq.hazelcast.query.bin.BinningStrategy;
import ch.psi.daq.hazelcast.query.bin.BinningStrategyFactory;
import ch.psi.daq.hazelcast.query.range.QueryRange;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -35,6 +39,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
})
public abstract class AbstractQuery implements Query {
private static Logger logger = LoggerFactory.getLogger(AbstractQuery.class);
private List<String> channels;
private LinkedHashSet<String> fields;
@ -47,37 +53,65 @@ public abstract class AbstractQuery implements Query {
private Ordering ordering;
private BinningStrategy binningStrategy;
private BinningStrategyEnum binningStrategyEnum;
private QueryRange queryRange;
/**
*
* @param isOrderDescending whether to add a 'orderBy' clause into the database query
* @param channelIds all the channelIds (channel names) we want to query
* @param ordering whether to add a 'orderBy' clause into the database query
* @param channels all the channelIds (channel names) we want to query
* @param fields the fields (who map to fields in the DB) we are interested in returning to the
* client, needs to be in insertion order (hence the {@link LinkedHashSet} type)
* @param queryRange TODO
*/
@JsonCreator
public AbstractQuery(
// note that those annotations are needed for the polymorphic
// mapping to work correctly
@JsonProperty(value = "ordering") Ordering ordering,
@JsonProperty(value = "channels") List<String> channelIds,
@JsonProperty(value = "channels") List<String> channels,
@JsonProperty(value = "fields") LinkedHashSet<String> fields,
@JsonProperty(value = "binningStrategy") BinningStrategyEnum binningStrategyEnum,
@JsonProperty(value = "binDuration") long binDurationOrBinCount,
@JsonProperty(value = "aggregateChannels") boolean aggregateChannels,
@JsonProperty(value = "aggregationType") AggregationType aggregationType,
@JsonProperty(value = "aggregations") List<Aggregation> aggregations) {
@JsonProperty(value = "aggregations") List<Aggregation> aggregations,
@JsonProperty(value = "queryRange") QueryRange queryRange) {
this.ordering = ordering;
this.aggregateChannels = aggregateChannels;
this.aggregationType = aggregationType;
this.aggregations = aggregations;
this.queryRange = queryRange;
if (channelIds == null || fields == null) {
throw new IllegalArgumentException("sourceIds and/or fields cannot be null.");
}
Assert.notNull(channelIds, "channel name must not be null.");
Assert.notNull(channels, "channel name must not be null.");
Assert.notNull(fields, "field, i.e. property, names must not be null.");
this.channels = channelIds;
this.channels = channels;
this.fields = fields;
this.aggregations = aggregations;
this.binningStrategyEnum = binningStrategyEnum; // can be null: default then will be BinCountBinningStrategy
if (binningStrategyEnum != null) {
switch (binningStrategyEnum) {
case bincount:
this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), (int) binDurationOrBinCount);
break;
case lengthpulse:
case lengthtime:
this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), binDurationOrBinCount);
break;
default:
logger.warn("No binning strategy has been set. Selecting BinningStrategyBinCount.");
this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), (int) binDurationOrBinCount);
}
} else {
this.binningStrategy = BinningStrategyFactory.getBinningStrategy(getQueryRange(), (int) binDurationOrBinCount);
}
}
/**
@ -104,16 +138,19 @@ public abstract class AbstractQuery implements Query {
return aggregationType;
}
@Override
public BinIntervalCalculator getBinIntervalCalculator() {
// TODO
return null;
}
public boolean isAggregateChannels() {
return aggregateChannels;
}
public BinningStrategyEnum getBinningStrategyEnum() {
return binningStrategyEnum;
}
@Override
public BinningStrategy getBinningStrategy() {
return binningStrategy;
}
public LinkedHashSet<String> getFields() {
return fields;
@ -123,6 +160,18 @@ public abstract class AbstractQuery implements Query {
return aggregations;
}
/**
* {@inheritDoc}
*/
@Override
public QueryRange getQueryRange() {
return queryRange;
}
public void setQueryRange(QueryRange queryRange) {
this.queryRange = queryRange;
}
@Override
public String toString() {
return ReflectionToStringBuilder.reflectionToString(this);

View File

@ -0,0 +1,13 @@
package ch.psi.daq.rest.queries;
import ch.psi.daq.hazelcast.query.bin.BinningStrategy;
/**
* Defines the strategies that map to the similarly named {@link BinningStrategy} implementations.
* <p>
* This enum is used for type-safety and simplicity for the rest interface.
*
*/
public enum BinningStrategyEnum {
lengthpulse, lengthtime, bincount
}

View File

@ -18,9 +18,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
*/
public class PulseRangeQuery extends AbstractQuery {
private long startPulseId;
private long endPulseId;
@JsonCreator
public PulseRangeQuery(
// note that those annotations are needed for the polymorphic
@ -28,33 +25,16 @@ public class PulseRangeQuery extends AbstractQuery {
@JsonProperty(value = "ordering") Ordering ordering,
@JsonProperty(value = "channels") List<String> channels,
@JsonProperty(value = "fields") LinkedHashSet<String> fields,
@JsonProperty(value = "binningStrategy") BinningStrategyEnum binningStrategyEnum,
@JsonProperty(value = "binDuration") long binDurationOrBinCount,
@JsonProperty(value = "aggregateChannels") boolean aggregateChannels,
@JsonProperty(value = "aggregationType") AggregationType aggregationType,
@JsonProperty(value = "aggregations") List<Aggregation> aggregations,
@JsonProperty(value = "startPulseId") long startPulseId,
@JsonProperty(value = "endPulseId") long endPulseId)
{
@JsonProperty(value = "queryRange") QueryRange queryRange) {
super(ordering, channels, fields, aggregateChannels, aggregationType, aggregations);
super(ordering, channels, fields, binningStrategyEnum, binDurationOrBinCount, aggregateChannels, aggregationType,
aggregations, queryRange);
this.startPulseId = startPulseId;
this.endPulseId = endPulseId;
}
public long getStartPulseId() {
return startPulseId;
}
public void setStartPulseId(long startPulseId) {
this.startPulseId = startPulseId;
}
public long getEndPulseId() {
return endPulseId;
}
public void setEndPulseId(long endPulseId) {
this.endPulseId = endPulseId;
}
/**
@ -65,10 +45,4 @@ public class PulseRangeQuery extends AbstractQuery {
return ToStringBuilder.reflectionToString(this);
}
@Override
public QueryRange getQueryRange() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -6,8 +6,6 @@ import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -23,31 +21,24 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class TimeRangeQuery extends AbstractQuery {
private static final String DATE_FORMAT_STRING = "yyyy/MM/dd hh:mm:ss.SSS";
public static final String DATE_FORMAT_STRING = "yyyy/MM/dd hh:mm:ss.SSS";
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(DATE_FORMAT_STRING);
private static Logger logger = LoggerFactory.getLogger(TimeRangeQuery.class);
@NotNull
private long start;
@NotNull
private long startNanoOffset;
@NotNull
private long end;
@NotNull
private long endNanoOffset;
/**
*
* @param ordering
* @param ordering whether to add a 'orderBy' clause into the database query
* @param channelIds all the sourceIds (channel names) we want to query
* @param fields the fields (who map to fields in the DB) we are interested in returning to the
* client, needs to be in insertion order (hence the {@link LinkedHashSet} type)
* @param startMillis
* @param startNanoOffset
* @param endMillis
* @param endNanoOffset
* @param binningStrategyEnum
* @param binDurationOrBinCount
* @param aggregateChannels
* @param aggregationType
* @param aggregations
* @param queryRange
* @param startDateTime
* @param endDateTime
*/
@JsonCreator
public TimeRangeQuery(
@ -56,23 +47,16 @@ public class TimeRangeQuery extends AbstractQuery {
@JsonProperty(value = "ordering") Ordering ordering,
@JsonProperty(value = "channels") List<String> channels,
@JsonProperty(value = "fields") LinkedHashSet<String> fields,
@JsonProperty(value = "binningStrategy") BinningStrategyEnum binningStrategyEnum,
@JsonProperty(value = "binDuration") long binDurationOrBinCount,
@JsonProperty(value = "aggregateChannels") boolean aggregateChannels,
@JsonProperty(value = "aggregationType") AggregationType aggregationType,
@JsonProperty(value = "aggregations") List<Aggregation> aggregations,
@JsonProperty(value = "start") long startMillis,
@JsonProperty(value = "startNanoOffset") long startNanoOffset,
@JsonProperty(value = "queryRange") QueryRange queryRange,
@JsonProperty(value = "startDateTime") String startDateTime,
@JsonProperty(value = "end") long endMillis,
@JsonProperty(value = "endNanoOffset") long endNanoOffset,
@JsonProperty(value = "endDateTime") String endDateTime) {
super(ordering, channels, fields, aggregateChannels, aggregationType, aggregations);
this.start = startMillis;
this.startNanoOffset = startNanoOffset;
this.end = endMillis;
this.endNanoOffset = endNanoOffset;
super(ordering, channels, fields, binningStrategyEnum, binDurationOrBinCount, aggregateChannels, aggregationType, aggregations, queryRange);
if (startDateTime != null && endDateTime != null) {
logger.info("startDateTime and endDateTime specified. This takes precedence over the start / end fields.");
@ -80,8 +64,7 @@ public class TimeRangeQuery extends AbstractQuery {
Date startDate = DATE_FORMAT.parse(startDateTime);
Date endDate = DATE_FORMAT.parse(endDateTime);
this.start = startDate.getTime();
this.end = endDate.getTime();
getQueryRange().setTimeRange(startDate.getTime(), queryRange.getStartNanos(), endDate.getTime(), queryRange.getEndNanos());
} catch (ParseException e) {
logger.error("Parsing the start- and/or endDate was unsuccessful. "
+ "The format must be '" + DATE_FORMAT_STRING + "'", e);
@ -90,38 +73,6 @@ public class TimeRangeQuery extends AbstractQuery {
}
public long getStart() {
return start;
}
public void setStart(long start) {
this.start = start;
}
public long getStartNanoOffset() {
return startNanoOffset;
}
public void setStartNanoOffset(long startNanoOffset) {
this.startNanoOffset = startNanoOffset;
}
public long getEnd() {
return end;
}
public void setEnd(long end) {
this.end = end;
}
public long getEndNanoOffset() {
return endNanoOffset;
}
public void setEndNanoOffset(long endNanoOffset) {
this.endNanoOffset = endNanoOffset;
}
/**
* {@inheritDoc}
*/
@ -130,11 +81,4 @@ public class TimeRangeQuery extends AbstractQuery {
return ToStringBuilder.reflectionToString(this);
}
@Override
public QueryRange getQueryRange() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -37,7 +37,8 @@ public abstract class AbstractDaqRestTest {
protected MockMvc mockMvc;
protected ObjectMapper mapper = new ObjectMapper();
@Autowired
protected ObjectMapper mapper;
@Before
public void setup() {

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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