diff --git a/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java b/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java index e2c95f2..3c55e14 100644 --- a/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java +++ b/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java @@ -33,8 +33,8 @@ import ch.psi.daq.domain.query.backend.BackendQuery; import ch.psi.daq.domain.query.backend.analyzer.BackendQueryAnalyzer; import ch.psi.daq.domain.query.operation.Aggregation; import ch.psi.daq.domain.query.operation.QueryField; -import ch.psi.daq.domain.query.operation.Response; import ch.psi.daq.domain.query.operation.aggregation.extrema.AbstractExtremaMeta; +import ch.psi.daq.domain.query.response.Response; import ch.psi.daq.query.analyzer.BackendQueryAnalyzerImpl; import ch.psi.daq.query.config.QueryConfig; import ch.psi.daq.queryrest.controller.validator.QueryValidator; @@ -44,6 +44,7 @@ import ch.psi.daq.queryrest.query.QueryManagerImpl; import ch.psi.daq.queryrest.response.PolymorphicResponseMixIn; import ch.psi.daq.queryrest.response.csv.CSVResponseStreamWriter; import ch.psi.daq.queryrest.response.json.JSONResponseStreamWriter; +import ch.psi.daq.queryrest.response.json.JSONTableResponseStreamWriter; @Configuration @Import(value = QueryRestConfigCORS.class) @@ -128,6 +129,11 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter { public JSONResponseStreamWriter jsonResponseStreamWriter() { return new JSONResponseStreamWriter(); } + + @Bean + public JSONTableResponseStreamWriter jsonTableResponseStreamWriter() { + return new JSONTableResponseStreamWriter(); + } @Bean public CSVResponseStreamWriter csvResponseStreamWriter() { diff --git a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java index e0e780f..c053c06 100644 --- a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java +++ b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java @@ -39,8 +39,8 @@ import ch.psi.daq.domain.query.operation.Aggregation; import ch.psi.daq.domain.query.operation.AggregationType; import ch.psi.daq.domain.query.operation.Compression; import ch.psi.daq.domain.query.operation.QueryField; -import ch.psi.daq.domain.query.operation.Response; -import ch.psi.daq.domain.query.operation.ResponseFormat; +import ch.psi.daq.domain.query.response.Response; +import ch.psi.daq.domain.query.response.ResponseFormat; import ch.psi.daq.domain.request.validate.RequestProviderValidator; import ch.psi.daq.queryrest.query.QueryManager; import ch.psi.daq.queryrest.response.AbstractHTTPResponse; diff --git a/src/main/java/ch/psi/daq/queryrest/response/AbstractHTTPResponse.java b/src/main/java/ch/psi/daq/queryrest/response/AbstractHTTPResponse.java index 34f2021..26df204 100644 --- a/src/main/java/ch/psi/daq/queryrest/response/AbstractHTTPResponse.java +++ b/src/main/java/ch/psi/daq/queryrest/response/AbstractHTTPResponse.java @@ -10,8 +10,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.core.JsonEncoding; import ch.psi.daq.domain.query.DAQQueries; -import ch.psi.daq.domain.query.operation.ResponseFormat; -import ch.psi.daq.domain.query.operation.ResponseImpl; +import ch.psi.daq.domain.query.response.ResponseFormat; +import ch.psi.daq.domain.query.response.ResponseImpl; public abstract class AbstractHTTPResponse extends ResponseImpl { diff --git a/src/main/java/ch/psi/daq/queryrest/response/ResponseStreamWriter.java b/src/main/java/ch/psi/daq/queryrest/response/ResponseStreamWriter.java index 1eb72e0..9daceab 100644 --- a/src/main/java/ch/psi/daq/queryrest/response/ResponseStreamWriter.java +++ b/src/main/java/ch/psi/daq/queryrest/response/ResponseStreamWriter.java @@ -12,6 +12,7 @@ import org.apache.commons.lang3.tuple.Triple; import ch.psi.daq.domain.json.ChannelName; import ch.psi.daq.domain.query.DAQQueryElement; import ch.psi.daq.domain.query.backend.BackendQuery; +import ch.psi.daq.domain.query.response.Response; public interface ResponseStreamWriter { @@ -21,7 +22,8 @@ public interface ResponseStreamWriter { * * @param results The results results * @param out The OutputStream + * @param response The Response * @throws Exception thrown if writing to the output stream fails */ - public void respond(List>>> results, OutputStream out) throws Exception; + public void respond(List>>> results, OutputStream out, Response response) throws Exception; } diff --git a/src/main/java/ch/psi/daq/queryrest/response/csv/CSVHTTPResponse.java b/src/main/java/ch/psi/daq/queryrest/response/csv/CSVHTTPResponse.java index 11a6b50..80ad22c 100644 --- a/src/main/java/ch/psi/daq/queryrest/response/csv/CSVHTTPResponse.java +++ b/src/main/java/ch/psi/daq/queryrest/response/csv/CSVHTTPResponse.java @@ -19,11 +19,10 @@ import ch.psi.daq.domain.json.ChannelName; import ch.psi.daq.domain.query.DAQQueries; import ch.psi.daq.domain.query.DAQQueryElement; import ch.psi.daq.domain.query.backend.BackendQuery; -import ch.psi.daq.domain.query.backend.BackendQueryImpl; import ch.psi.daq.domain.query.operation.AggregationType; import ch.psi.daq.domain.query.operation.Compression; import ch.psi.daq.domain.query.operation.QueryField; -import ch.psi.daq.domain.query.operation.ResponseFormat; +import ch.psi.daq.domain.query.response.ResponseFormat; import ch.psi.daq.queryrest.query.QueryManager; import ch.psi.daq.queryrest.response.AbstractHTTPResponse; @@ -43,7 +42,8 @@ public class CSVHTTPResponse extends AbstractHTTPResponse { } @Override - public void respond(ApplicationContext context, DAQQueries queries, HttpServletResponse httpResponse) throws Exception { + public void respond(ApplicationContext context, DAQQueries queries, HttpServletResponse httpResponse) + throws Exception { OutputStream out = handleCompressionAndResponseHeaders(httpResponse, CONTENT_TYPE); // do csv specific validations @@ -59,7 +59,7 @@ public class CSVHTTPResponse extends AbstractHTTPResponse { List>>> result = queryManager.getEvents(queries); // write the response back to the client using java 8 streams - streamWriter.respond(result, out); + streamWriter.respond(result, out, this); } catch (Exception e) { LOGGER.error("Failed to execute query '{}'.", queries, e); throw e; @@ -68,7 +68,8 @@ public class CSVHTTPResponse extends AbstractHTTPResponse { protected void validateQueries(DAQQueries queries) { for (DAQQueryElement query : queries) { - if (!(query.getAggregation() == null || AggregationType.value.equals(query.getAggregation().getAggregationType()))) { + if (!(query.getAggregation() == null || AggregationType.value.equals(query.getAggregation() + .getAggregationType()))) { // We allow only no aggregation or value aggregation as // extrema: nested structure and not clear how to map it to one line // index: value is an array of Statistics whose size is not clear at initialization time diff --git a/src/main/java/ch/psi/daq/queryrest/response/csv/CSVResponseStreamWriter.java b/src/main/java/ch/psi/daq/queryrest/response/csv/CSVResponseStreamWriter.java index bc307b4..00f8189 100644 --- a/src/main/java/ch/psi/daq/queryrest/response/csv/CSVResponseStreamWriter.java +++ b/src/main/java/ch/psi/daq/queryrest/response/csv/CSVResponseStreamWriter.java @@ -28,18 +28,24 @@ import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; import ch.psi.daq.common.stream.StreamIterable; -import ch.psi.daq.common.stream.StreamMatcher; +import ch.psi.daq.common.stream.match.MapCreator; +import ch.psi.daq.common.stream.match.MapFiller; +import ch.psi.daq.common.stream.match.Padder; +import ch.psi.daq.common.stream.match.StreamMatcher; import ch.psi.daq.domain.DataEvent; import ch.psi.daq.domain.json.ChannelName; import ch.psi.daq.domain.query.DAQQueryElement; import ch.psi.daq.domain.query.backend.BackendQuery; -import ch.psi.daq.domain.query.backend.BackendQueryImpl; import ch.psi.daq.domain.query.backend.analyzer.BackendQueryAnalyzer; +import ch.psi.daq.domain.query.mapping.Mapping; +import ch.psi.daq.domain.query.mapping.IncompleteStrategy; import ch.psi.daq.domain.query.operation.Aggregation; import ch.psi.daq.domain.query.operation.Extrema; import ch.psi.daq.domain.query.operation.QueryField; +import ch.psi.daq.domain.query.response.Response; import ch.psi.daq.queryrest.response.ResponseStreamWriter; /** @@ -49,41 +55,52 @@ import ch.psi.daq.queryrest.response.ResponseStreamWriter; public class CSVResponseStreamWriter implements ResponseStreamWriter { private static final Logger LOGGER = LoggerFactory.getLogger(CSVResponseStreamWriter.class); + public static final Mapping DEFAULT_MAPPING = new Mapping(IncompleteStrategy.FILL_NULL); public static final char DELIMITER_CVS = ';'; public static final String DELIMITER_ARRAY = ","; public static final char DELIMITER_CHANNELNAME_FIELDNAME = '.'; public static final String EMPTY_VALUE = ""; public static final String FIELDNAME_EXTREMA = "extrema"; - private static final Function, ChannelName> KEY_PROVIDER = (pair) -> pair.getKey(); + private static final Function KEY_PROVIDER = (event) -> new ChannelName(event.getChannel(), event.getBackend()); // try to match sync data (bsread) with non sync data (epics) based on the time usin 10 millis // buckets. - private static final ToLongFunction> MATCHER_PROVIDER = (pair) -> pair.getValue() - .getGlobalMillis() / 10L; + private static final ToLongFunction MATCHER_PROVIDER = (event) -> event.getGlobalMillis() / 10L; + @Resource + private ApplicationContext context; + @Resource private Function queryAnalizerFactory; @Override public void respond(final List>>> results, - final OutputStream out) throws Exception { + final OutputStream out, final Response response) throws Exception { + if(results.size() > 1){ + throw new IllegalStateException("CSV format does not allow for multiple queries."); + } + AtomicReference exception = new AtomicReference<>(); - final Map>> streams = new LinkedHashMap<>(results.size()); + final Map> streams = new LinkedHashMap<>(results.size()); final List header = new ArrayList<>(); final Collection>> accessors = new ArrayList<>(); + final AtomicReference daqQueryRef = new AtomicReference<>(); + final AtomicReference backendQueryRef = new AtomicReference<>(); - // prepare the streams + /* get DataEvent stream of all sub-queries for later match */ results.forEach(entry -> { final DAQQueryElement query = entry.getKey(); + daqQueryRef.compareAndSet(null, query); entry.getValue() .sequential() .forEach(triple -> { + backendQueryRef.compareAndSet(null, triple.getLeft()); + if (triple.getRight() instanceof Stream) { setupChannelColumns(query, triple.getLeft(), triple.getMiddle(), header, accessors); - final Stream> eventStream = ((Stream) triple.getRight()) - .map(dataEvent -> Pair.of(triple.getMiddle(), dataEvent)); + final Stream eventStream = ((Stream) triple.getRight()); streams.put(triple.getMiddle(), eventStream); } else { final String message = String.format("Expect a DataEvent Stream for '%s'.", triple.getMiddle()); @@ -92,10 +109,20 @@ public class CSVResponseStreamWriter implements ResponseStreamWriter { }); }); + Mapping mapping = daqQueryRef.get().getMappingOrDefault(DEFAULT_MAPPING); + Padder padder = mapping.getIncomplete().getPadder(context, backendQueryRef.get()); + // online matching of the stream's content - StreamMatcher> streamMatcher = - new StreamMatcher<>(KEY_PROVIDER, MATCHER_PROVIDER, streams.values()); - Iterator>> streamsMatchIter = streamMatcher.iterator(); + StreamMatcher> streamMatcher = + new StreamMatcher<>( + KEY_PROVIDER, + MATCHER_PROVIDER, + new MapCreator<>(), + new MapFiller<>(), + null, + padder, + streams.values()); + Iterator> streamsMatchIter = streamMatcher.iterator(); // prepare csv output CSVFormat csvFormat = CSVFormat.EXCEL.withDelimiter(DELIMITER_CVS); @@ -111,14 +138,14 @@ public class CSVResponseStreamWriter implements ResponseStreamWriter { csvFilePrinter.printRecord(header); while (streamsMatchIter.hasNext()) { - final Map> match = streamsMatchIter.next(); + final Map match = streamsMatchIter.next(); // ensure correct order Stream rowStream = accessors.stream().sequential() .map(accessorPair -> { - Pair eventPair = match.get(accessorPair.getKey()); - if (eventPair != null) { - return accessorPair.getValue().apply(eventPair.getValue()); + DataEvent event = match.get(accessorPair.getKey()); + if (event != null) { + return accessorPair.getValue().apply(event); } else { return EMPTY_VALUE; } diff --git a/src/main/java/ch/psi/daq/queryrest/response/json/JSONHTTPResponse.java b/src/main/java/ch/psi/daq/queryrest/response/json/JSONHTTPResponse.java index 5e26b44..96280c0 100644 --- a/src/main/java/ch/psi/daq/queryrest/response/json/JSONHTTPResponse.java +++ b/src/main/java/ch/psi/daq/queryrest/response/json/JSONHTTPResponse.java @@ -1,6 +1,7 @@ package ch.psi.daq.queryrest.response.json; import java.io.OutputStream; +import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.stream.Stream; @@ -18,9 +19,10 @@ import ch.psi.daq.domain.query.DAQQueries; import ch.psi.daq.domain.query.DAQQueryElement; import ch.psi.daq.domain.query.backend.BackendQuery; import ch.psi.daq.domain.query.operation.Compression; -import ch.psi.daq.domain.query.operation.ResponseFormat; +import ch.psi.daq.domain.query.response.ResponseFormat; import ch.psi.daq.queryrest.query.QueryManager; import ch.psi.daq.queryrest.response.AbstractHTTPResponse; +import ch.psi.daq.queryrest.response.ResponseStreamWriter; public class JSONHTTPResponse extends AbstractHTTPResponse { private static final Logger LOGGER = LoggerFactory.getLogger(JSONHTTPResponse.class); @@ -31,7 +33,7 @@ public class JSONHTTPResponse extends AbstractHTTPResponse { public JSONHTTPResponse() { super(ResponseFormat.JSON); } - + public JSONHTTPResponse(Compression compression) { this(); setCompression(compression); @@ -41,16 +43,31 @@ public class JSONHTTPResponse extends AbstractHTTPResponse { public void respond(ApplicationContext context, DAQQueries queries, HttpServletResponse response) throws Exception { OutputStream out = handleCompressionAndResponseHeaders(response, CONTENT_TYPE); + boolean hasMapping = false; + Iterator iter = queries.getQueries().iterator(); + while (!hasMapping && iter.hasNext()) { + DAQQueryElement daqQueryElement = iter.next(); + if (daqQueryElement.getMapping() != null) { + hasMapping = true; + } + } + try { LOGGER.debug("Executing query '{}'", queries); QueryManager queryManager = context.getBean(QueryManager.class); - JSONResponseStreamWriter streamWriter = context.getBean(JSONResponseStreamWriter.class); + ResponseStreamWriter streamWriter; + if (hasMapping) { + streamWriter = context.getBean(JSONTableResponseStreamWriter.class); + } else { + streamWriter = context.getBean(JSONResponseStreamWriter.class); + } // execute query - List>>> result = queryManager.getEvents(queries); + List>>> result = + queryManager.getEvents(queries); // write the response back to the client using java 8 streams - streamWriter.respond(result, out); + streamWriter.respond(result, out, this); } catch (Exception e) { LOGGER.error("Failed to execute query '{}'.", queries, e); throw e; diff --git a/src/main/java/ch/psi/daq/queryrest/response/json/JSONResponseStreamWriter.java b/src/main/java/ch/psi/daq/queryrest/response/json/JSONResponseStreamWriter.java index c40dc24..3952e02 100644 --- a/src/main/java/ch/psi/daq/queryrest/response/json/JSONResponseStreamWriter.java +++ b/src/main/java/ch/psi/daq/queryrest/response/json/JSONResponseStreamWriter.java @@ -29,6 +29,7 @@ import ch.psi.daq.domain.query.backend.BackendQuery; import ch.psi.daq.domain.query.operation.Aggregation; import ch.psi.daq.domain.query.operation.Extrema; import ch.psi.daq.domain.query.operation.QueryField; +import ch.psi.daq.domain.query.response.Response; import ch.psi.daq.queryrest.response.ResponseStreamWriter; /** @@ -48,8 +49,8 @@ public class JSONResponseStreamWriter implements ResponseStreamWriter { private ObjectMapper mapper; @Override - public void respond(List>>> results, - OutputStream out) throws Exception { + public void respond(final List>>> results, + final OutputStream out, final Response response) throws Exception { AtomicReference exception = new AtomicReference<>(); JsonGenerator generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8); @@ -61,8 +62,8 @@ public class JSONResponseStreamWriter implements ResponseStreamWriter { results .forEach(entryy -> { DAQQueryElement daqQuery = entryy.getKey(); - Set includedFields = getFields(daqQuery); - ObjectWriter writer = configureWriter(includedFields); + Set includedFields = getFields(daqQuery, true); + ObjectWriter writer = configureWriter(includedFields, mapper); try { generator.writeStartArray(); @@ -106,7 +107,7 @@ public class JSONResponseStreamWriter implements ResponseStreamWriter { } } - protected Set getFields(DAQQueryElement query) { + public static Set getFields(DAQQueryElement query, boolean removeIdentifiers) { Set queryFields = query.getFields(); List aggregations = query.getAggregation() != null ? query.getAggregation().getAggregations() : null; List extrema = query.getAggregation() != null ? query.getAggregation().getExtrema() : null; @@ -129,8 +130,11 @@ public class JSONResponseStreamWriter implements ResponseStreamWriter { includedFields.add("extrema"); } - // do not write channel since it is already provided as key in mapping - includedFields.remove(QueryField.channel.name()); + if (removeIdentifiers) { + // do not write channel/backend since it is already provided as key in mapping + includedFields.remove(QueryField.channel.name()); + includedFields.remove(QueryField.backend.name()); + } return includedFields; } @@ -141,9 +145,10 @@ public class JSONResponseStreamWriter implements ResponseStreamWriter { * * @param includedFields set of strings which correspond to the getter method names of the * classes registered as a mixed-in + * @param mapper The ObjectMapper * @return the configured writer that includes the specified fields */ - private ObjectWriter configureWriter(Set includedFields) { + public static ObjectWriter configureWriter(Set includedFields, ObjectMapper mapper) { SimpleFilterProvider propertyFilter = new SimpleFilterProvider(); propertyFilter.addFilter("namedPropertyFilter", SimpleBeanPropertyFilter.filterOutAllExcept(includedFields)); // only write the properties not excluded in the filter diff --git a/src/main/java/ch/psi/daq/queryrest/response/json/JSONTableResponseStreamWriter.java b/src/main/java/ch/psi/daq/queryrest/response/json/JSONTableResponseStreamWriter.java new file mode 100644 index 0000000..686dfde --- /dev/null +++ b/src/main/java/ch/psi/daq/queryrest/response/json/JSONTableResponseStreamWriter.java @@ -0,0 +1,195 @@ +package ch.psi.daq.queryrest.response.json; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.function.ToLongFunction; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import javax.servlet.ServletResponse; + +import org.apache.commons.lang3.tuple.Triple; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; + +import com.fasterxml.jackson.core.JsonEncoding; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +import ch.psi.daq.common.stream.match.ListCreator; +import ch.psi.daq.common.stream.match.ListFiller; +import ch.psi.daq.common.stream.match.Padder; +import ch.psi.daq.common.stream.match.StreamMatcher; +import ch.psi.daq.common.time.TimeUtils; +import ch.psi.daq.domain.DataEvent; +import ch.psi.daq.domain.json.ChannelName; +import ch.psi.daq.domain.query.DAQQueryElement; +import ch.psi.daq.domain.query.backend.BackendQuery; +import ch.psi.daq.domain.query.bin.BinningStrategy; +import ch.psi.daq.domain.query.bin.strategy.BinningStrategyPerBinPulse; +import ch.psi.daq.domain.query.bin.strategy.BinningStrategyPerBinTime; +import ch.psi.daq.domain.query.mapping.Mapping; +import ch.psi.daq.domain.query.mapping.IncompleteStrategy; +import ch.psi.daq.domain.query.operation.Aggregation; +import ch.psi.daq.domain.query.operation.QueryField; +import ch.psi.daq.domain.query.response.Response; +import ch.psi.daq.domain.request.range.RequestRange; +import ch.psi.daq.query.bin.aggregate.BinnedValueCombiner; +import ch.psi.daq.queryrest.config.QueryRestConfig; +import ch.psi.daq.queryrest.response.ResponseStreamWriter; + +/** + * Takes a Java 8 stream and writes it to the output stream provided by the {@link ServletResponse} + * of the current request. + */ +public class JSONTableResponseStreamWriter implements ResponseStreamWriter { + + private static final Logger LOGGER = LoggerFactory.getLogger(JSONTableResponseStreamWriter.class); + + public static final Mapping DEFAULT_MAPPING = new Mapping(IncompleteStrategy.KEEP_AS_IS); + private static final long MILLIS_PER_PULSE = TimeUtils.MILLIS_PER_PULSE; + private static final Function KEY_PROVIDER = (event) -> new ChannelName(event.getChannel(), + event.getBackend()); + // try to match sync data (bsread) with non sync data (epics) based on the time usin 10 millis + // buckets. + private static final ToLongFunction MATCHER_PROVIDER = (event) -> event.getGlobalMillis() + / MILLIS_PER_PULSE; + + @Resource + private ApplicationContext context; + + @Resource + private JsonFactory jsonFactory; + + @Resource + private ObjectMapper mapper; + + @Resource(name = QueryRestConfig.BEAN_NAME_DEFAULT_RESPONSE_AGGREGATIONS) + private Set defaultResponseAggregations; + + private Set defaultResponseAggregationsStr; + + @PostConstruct + public void afterPropertiesSet() { + defaultResponseAggregationsStr = + defaultResponseAggregations.stream().map(Aggregation::name) + .collect(Collectors.toCollection(LinkedHashSet::new)); + } + + @Override + public void respond(final List>>> results, + final OutputStream out, final Response response) throws Exception { + AtomicReference exception = new AtomicReference<>(); + + JsonGenerator generator = jsonFactory.createGenerator(out, JsonEncoding.UTF8); + + try { + if (results.size() > 1) { + generator.writeStartArray(); + } + + results + .forEach(entryy -> { + DAQQueryElement daqQuery = entryy.getKey(); + Set includedFields = JSONResponseStreamWriter.getFields(daqQuery, false); + /* make sure identifiers are available */ + includedFields.add(QueryField.channel.name()); + includedFields.add(QueryField.backend.name()); + includedFields.addAll(defaultResponseAggregationsStr); + + ObjectWriter writer = JSONResponseStreamWriter.configureWriter(includedFields, mapper); + + /* get DataEvent stream of sub-queries for later match */ + final Map> streams = + new LinkedHashMap<>(results.size()); + final AtomicReference backendQueryRef = new AtomicReference<>(); + + entryy.getValue() + .sequential() + .forEach( + triple -> { + backendQueryRef.compareAndSet(null, triple.getLeft()); + + if (triple.getRight() instanceof Stream) { + streams.put(triple.getMiddle(), ((Stream) triple.getRight())); + } else { + final String message = + String.format("Expect a DataEvent Stream for '%s' but got '%s'.", + triple.getMiddle(), triple.getRight().getClass().getSimpleName()); + LOGGER.warn(message); + streams.put(triple.getMiddle(), Stream.empty()); + } + }); + + BackendQuery backendQuery = backendQueryRef.get(); + RequestRange requestRange = backendQuery.getRequest().getRequestRange(); + BinningStrategy binningStrategy = backendQuery.getBinningStrategy(); + + Mapping mapping = daqQuery.getMappingOrDefault(DEFAULT_MAPPING); + Padder padder = mapping.getIncomplete().getPadder(context, backendQuery); + + ToLongFunction matchProvider = binningStrategy; + if (binningStrategy == null) { + matchProvider = MATCHER_PROVIDER; + if (requestRange.isPulseIdRangeDefined()) { + binningStrategy = new BinningStrategyPerBinPulse(1); + } else if (requestRange.isTimeRangeDefined()) { + binningStrategy = new BinningStrategyPerBinTime(MILLIS_PER_PULSE); + } else { + String message = "Either time or pulseId range must be defined by the query!"; + LOGGER.error(message); + throw new IllegalStateException(message); + } + } + binningStrategy.setRequestRange(requestRange); + + /* online matching of the stream's content */ + StreamMatcher> streamMatcher = + new StreamMatcher<>( + KEY_PROVIDER, + matchProvider, + new ListCreator(), + new ListFiller(), + new BinnedValueCombiner(binningStrategy), + padder, + streams.values()); + Iterator> streamsMatchIter = streamMatcher.iterator(); + + try { + writer.writeValue(generator, streamsMatchIter); + } catch (Exception e) { + LOGGER.error("Exception while writing json for '{}'", daqQuery.getChannels(), e); + exception.compareAndSet(null, e); + } + }); + } catch (IOException e) { + LOGGER.error("Could not write JSON.", e); + exception.compareAndSet(null, e); + } finally { + if (results.size() > 1) { + generator.writeEndArray(); + } + + generator.flush(); + generator.close(); + } + + if (exception.get() != null) { + throw exception.get(); + } + } +} diff --git a/src/main/resources/queryrest.properties b/src/main/resources/queryrest.properties index 5fbaf69..f598b90 100644 --- a/src/main/resources/queryrest.properties +++ b/src/main/resources/queryrest.properties @@ -1,6 +1,6 @@ # defines the fields that are included in the response # if no fields have been specified by the user -queryrest.default.response.fields=channel,pulseId,globalSeconds,iocSeconds,shape,eventCount,value +queryrest.default.response.fields=channel,backend,pulseId,globalSeconds,iocSeconds,shape,eventCount,value # aggregation which are included in the response by default if aggregation is enabled for a given query queryrest.default.response.aggregations=min,mean,max diff --git a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerCsvTest.java b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerCsvTest.java index 467f0bc..ffe6992 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerCsvTest.java +++ b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerCsvTest.java @@ -26,9 +26,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import ch.psi.daq.common.ordering.Ordering; import ch.psi.daq.common.time.TimeUtils; import ch.psi.daq.domain.config.DomainConfig; -import ch.psi.daq.domain.query.DAQQueries; import ch.psi.daq.domain.query.DAQQuery; -import ch.psi.daq.domain.query.DAQQueryElement; import ch.psi.daq.domain.query.operation.Aggregation; import ch.psi.daq.domain.query.operation.AggregationDescriptor; import ch.psi.daq.domain.query.operation.AggregationType; @@ -323,98 +321,103 @@ public class QueryRestControllerCsvTest extends AbstractDaqRestTest { } } - @Test - public void testPulseRangeQueries() throws Exception { - List channels = Arrays.asList(TEST_CHANNEL_01, TEST_CHANNEL_02); - String testChannel3 = "testChannel3"; - DAQQueries request = new DAQQueries( - new DAQQueryElement( - new RequestRangePulseId( - 0, - 1), - channels), - new DAQQueryElement( - new RequestRangePulseId( - 0, - 1), - testChannel3)); - request.setResponse(new CSVHTTPResponse()); - channels = Arrays.asList(TEST_CHANNEL_01, TEST_CHANNEL_02, testChannel3); - - LinkedHashSet queryFields = new LinkedHashSet<>(); - queryFields.add(QueryField.channel); - queryFields.add(QueryField.pulseId); - queryFields.add(QueryField.iocSeconds); - queryFields.add(QueryField.iocMillis); - queryFields.add(QueryField.globalSeconds); - queryFields.add(QueryField.globalMillis); - queryFields.add(QueryField.shape); - queryFields.add(QueryField.eventCount); - queryFields.add(QueryField.value); - for (DAQQueryElement element : request) { - element.setFields(queryFields); - } - - String content = mapper.writeValueAsString(request); - System.out.println(content); - - MvcResult result = this.mockMvc - .perform(MockMvcRequestBuilders - .post(DomainConfig.PATH_QUERIES) - .contentType(MediaType.APPLICATION_JSON) - .content(content)) - .andDo(MockMvcResultHandlers.print()) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andReturn(); - - String response = result.getResponse().getContentAsString(); - System.out.println("Response: " + response); - - CSVFormat csvFormat = CSVFormat.EXCEL.withDelimiter(CSVResponseStreamWriter.DELIMITER_CVS); - StringReader reader = new StringReader(response); - CSVParser csvParser = new CSVParser(reader, csvFormat); - - try { - long pulse = 0; - int totalRows = 2; - - List records = csvParser.getRecords(); - assertEquals(totalRows + 1, records.size()); - // remove header - CSVRecord record = records.remove(0); - assertEquals(queryFields.size() * channels.size(), record.size()); - int column = 0; - for (String channel : channels) { - for (QueryField queryField : queryFields) { - assertEquals(channel + CSVResponseStreamWriter.DELIMITER_CHANNELNAME_FIELDNAME + queryField.name(), - record.get(column++)); - } - } - - for (int row = 0; row < totalRows; ++row) { - record = records.get(row); - - assertEquals(queryFields.size() * channels.size(), record.size()); - - column = 0; - for (String channel : channels) { - assertEquals(channel, record.get(column++)); - assertEquals("" + pulse, record.get(column++)); - assertEquals(TimeUtils.getTimeStr(TestTimeUtils.getTimeFromPulseId(pulse)), record.get(column++)); - assertEquals("" + TimeUtils.getMillis(TestTimeUtils.getTimeFromPulseId(pulse)), record.get(column++)); - assertEquals(TimeUtils.getTimeStr(TestTimeUtils.getTimeFromPulseId(pulse)), record.get(column++)); - assertEquals("" + TimeUtils.getMillis(TestTimeUtils.getTimeFromPulseId(pulse)), record.get(column++)); - assertEquals("[1]", record.get(column++)); - assertEquals("1", record.get(column++)); - assertEquals("" + pulse, record.get(column++)); - } - ++pulse; - } - } finally { - reader.close(); - csvParser.close(); - } - } + // @Test + // public void testPulseRangeQueries() throws Exception { + // List channels = Arrays.asList(TEST_CHANNEL_01, TEST_CHANNEL_02); + // String testChannel3 = "testChannel3"; + // DAQQueries request = new DAQQueries( + // new DAQQueryElement( + // new RequestRangePulseId( + // 0, + // 1), + // channels), + // new DAQQueryElement( + // new RequestRangePulseId( + // 0, + // 1), + // testChannel3)); + // request.setResponse(new CSVHTTPResponse()); + // channels = Arrays.asList(TEST_CHANNEL_01, TEST_CHANNEL_02, testChannel3); + // + // LinkedHashSet queryFields = new LinkedHashSet<>(); + // queryFields.add(QueryField.channel); + // queryFields.add(QueryField.pulseId); + // queryFields.add(QueryField.iocSeconds); + // queryFields.add(QueryField.iocMillis); + // queryFields.add(QueryField.globalSeconds); + // queryFields.add(QueryField.globalMillis); + // queryFields.add(QueryField.shape); + // queryFields.add(QueryField.eventCount); + // queryFields.add(QueryField.value); + // for (DAQQueryElement element : request) { + // element.setFields(queryFields); + // } + // + // String content = mapper.writeValueAsString(request); + // System.out.println(content); + // + // MvcResult result = this.mockMvc + // .perform(MockMvcRequestBuilders + // .post(DomainConfig.PATH_QUERIES) + // .contentType(MediaType.APPLICATION_JSON) + // .content(content)) + // .andDo(MockMvcResultHandlers.print()) + // .andExpect(MockMvcResultMatchers.status().isOk()) + // .andReturn(); + // + // String response = result.getResponse().getContentAsString(); + // System.out.println("Response: " + response); + // + // CSVFormat csvFormat = CSVFormat.EXCEL.withDelimiter(CSVResponseStreamWriter.DELIMITER_CVS); + // StringReader reader = new StringReader(response); + // CSVParser csvParser = new CSVParser(reader, csvFormat); + // + // try { + // long pulse = 0; + // int totalRows = 2; + // + // List records = csvParser.getRecords(); + // assertEquals(totalRows + 1, records.size()); + // // remove header + // CSVRecord record = records.remove(0); + // assertEquals(queryFields.size() * channels.size(), record.size()); + // int column = 0; + // for (String channel : channels) { + // for (QueryField queryField : queryFields) { + // assertEquals(channel + CSVResponseStreamWriter.DELIMITER_CHANNELNAME_FIELDNAME + + // queryField.name(), + // record.get(column++)); + // } + // } + // + // for (int row = 0; row < totalRows; ++row) { + // record = records.get(row); + // + // assertEquals(queryFields.size() * channels.size(), record.size()); + // + // column = 0; + // for (String channel : channels) { + // assertEquals(channel, record.get(column++)); + // assertEquals("" + pulse, record.get(column++)); + // assertEquals(TimeUtils.getTimeStr(TestTimeUtils.getTimeFromPulseId(pulse)), + // record.get(column++)); + // assertEquals("" + TimeUtils.getMillis(TestTimeUtils.getTimeFromPulseId(pulse)), + // record.get(column++)); + // assertEquals(TimeUtils.getTimeStr(TestTimeUtils.getTimeFromPulseId(pulse)), + // record.get(column++)); + // assertEquals("" + TimeUtils.getMillis(TestTimeUtils.getTimeFromPulseId(pulse)), + // record.get(column++)); + // assertEquals("[1]", record.get(column++)); + // assertEquals("1", record.get(column++)); + // assertEquals("" + pulse, record.get(column++)); + // } + // ++pulse; + // } + // } finally { + // reader.close(); + // csvParser.close(); + // } + // } @Test public void testPulseRangeQueryWaveform() throws Exception { diff --git a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTableTest.java b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTableTest.java new file mode 100644 index 0000000..d4fee11 --- /dev/null +++ b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTableTest.java @@ -0,0 +1,2139 @@ +package ch.psi.daq.test.queryrest.controller; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.annotation.Resource; + +import org.junit.After; +import org.junit.Test; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import ch.psi.daq.common.ordering.Ordering; +import ch.psi.daq.common.time.TimeUtils; +import ch.psi.daq.domain.backend.Backend; +import ch.psi.daq.domain.config.DomainConfig; +import ch.psi.daq.domain.json.ChannelName; +import ch.psi.daq.domain.query.DAQQueries; +import ch.psi.daq.domain.query.DAQQuery; +import ch.psi.daq.domain.query.DAQQueryElement; +import ch.psi.daq.domain.query.mapping.IncompleteStrategy; +import ch.psi.daq.domain.query.mapping.Mapping; +import ch.psi.daq.domain.query.operation.Aggregation; +import ch.psi.daq.domain.query.operation.AggregationDescriptor; +import ch.psi.daq.domain.query.operation.AggregationType; +import ch.psi.daq.domain.query.operation.Extrema; +import ch.psi.daq.domain.query.operation.QueryField; +import ch.psi.daq.domain.request.range.RequestRangeDate; +import ch.psi.daq.domain.request.range.RequestRangePulseId; +import ch.psi.daq.domain.request.range.RequestRangeTime; +import ch.psi.daq.domain.test.TestTimeUtils; +import ch.psi.daq.test.queryrest.AbstractDaqRestTest; + +/** + * Tests the {@link DaqController} implementation. + */ +public class QueryRestControllerJsonTableTest extends AbstractDaqRestTest { + + public static final String TEST_CHANNEL_01 = "testChannel1"; + public static final String TEST_CHANNEL_02 = "testChannel2"; + public static final String TEST_CHANNEL_WAVEFORM_01 = "testChannelWaveform1"; + public static final String TEST_CHANNEL_WAVEFORM_02 = "testChannelWaveform2"; + public static final String[] TEST_CHANNEL_NAMES = new String[] {TEST_CHANNEL_01, TEST_CHANNEL_02}; + + @Resource(name = DomainConfig.BEAN_NAME_BACKEND_DEFAULT) + private Backend backend; + + @After + public void tearDown() throws Exception {} + + @Test + public void testPulseRangeQuery() throws Exception { + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + 100, + 101), + TEST_CHANNEL_NAMES); + request.setMapping(new Mapping()); + request.addField(QueryField.pulseId); + request.addField(QueryField.globalSeconds); + request.addField(QueryField.globalMillis); + request.addField(QueryField.iocSeconds); + request.addField(QueryField.iocMillis); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalMillis").value(1000)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].iocMillis").value(1000)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalMillis").value(1000)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].iocMillis").value(1000)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalMillis").value(1010)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].iocMillis").value(1010)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalMillis").value(1010)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].iocMillis").value(1010)); + } + + @Test + public void testPulseRangeQuery_ChannelOrder() throws Exception { + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + 100, + 101), + TEST_CHANNEL_02, TEST_CHANNEL_01); + request.setMapping(new Mapping()); + request.addField(QueryField.pulseId); + request.addField(QueryField.globalSeconds); + request.addField(QueryField.globalMillis); + request.addField(QueryField.iocSeconds); + request.addField(QueryField.iocMillis); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalMillis").value(1000)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].iocMillis").value(1000)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalMillis").value(1000)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].iocMillis").value(1000)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalMillis").value(1010)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].iocMillis").value(1010)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalMillis").value(1010)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].iocMillis").value(1010)); + } + + @Test + public void testPulseRangeQuery_SingleChannel() throws Exception { + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + 100, + 101), + TEST_CHANNEL_01); + request.setMapping(new Mapping()); + request.addField(QueryField.pulseId); + request.addField(QueryField.globalSeconds); + request.addField(QueryField.globalMillis); + request.addField(QueryField.iocSeconds); + request.addField(QueryField.iocMillis); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalMillis").value(1000)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].iocMillis").value(1000)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalMillis").value(1010)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].iocMillis").value(1010)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").doesNotExist()); + } + + @Test + public void testPulseRangeQuery_Fields() throws Exception { + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + 100, + 199), + new AggregationDescriptor().setNrOfBins(2), + TEST_CHANNEL_NAMES); + request.setMapping(new Mapping()); + request.addField(QueryField.pulseId); + request.addField(QueryField.eventCount); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].eventCount").value(50)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].eventCount").value(50)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(150)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].eventCount").value(50)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(150)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].eventCount").value(50)); + } + + @Test + public void testPulseRangeQueryBackends() throws Exception { + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + 100, + 101), + new ChannelName(TEST_CHANNEL_01, backend), + new ChannelName(TEST_CHANNEL_02, Backend.SF_ARCHIVERAPPLIANCE)); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))); + } + + @Test + public void testPulseRangeQueries() throws Exception { + String testChannel3 = "testChannel3"; + DAQQueryElement daqQuery1 = new DAQQueryElement( + new RequestRangePulseId( + 100, + 101), + TEST_CHANNEL_NAMES); + daqQuery1.setMapping(new Mapping()); + DAQQueryElement daqQuery2 = new DAQQueryElement( + new RequestRangePulseId( + 100, + 101), + testChannel3); + daqQuery2.setMapping(new Mapping()); + DAQQueries request = new DAQQueries( + daqQuery1, daqQuery2); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERIES) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][0].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][1].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0][0].channel").value(testChannel3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1][0].channel").value(testChannel3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1][0].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))); + } + + @Test + public void testTimeRangeQuery_01() throws Exception { + DAQQuery request = new DAQQuery( + new RequestRangeTime( + TimeUtils.getTimeFromMillis(2000, 0), + TimeUtils.getTimeFromMillis(2010, 0)), + TEST_CHANNEL_NAMES); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + + this.mockMvc.perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(200)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(2, 0))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(200)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(2, 0))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(201)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(2, 10000000))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(201)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(2, 10000000))); + } + + @Test + public void testDateRangeQuery() throws Exception { + String startDate = TimeUtils.format(1000); + String endDate = TimeUtils.format(1010); + DAQQuery request = new DAQQuery( + new RequestRangeDate( + startDate, + endDate), + TEST_CHANNEL_NAMES); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform( + MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content) + ) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))); + } + + @Test + public void testExtremaAggregation() throws Exception { + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + 100, + 101), + Ordering.asc, + new AggregationDescriptor(AggregationType.extrema), + TEST_CHANNEL_NAMES[0]); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + + this.mockMvc + .perform(MockMvcRequestBuilders.post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + + .andExpect(MockMvcResultMatchers.jsonPath("$").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").doesNotExist()); + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].channel").isMap()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].channel.name").value(TEST_CHANNEL_NAMES[0])) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.value").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.value").value(Double.valueOf(100))) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.event").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.event.pulseId").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.minima.min.event.pulseId").value(100)) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.value").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.value").value(Double.valueOf(101))) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.event").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.event.pulseId").exists()) + // .andExpect(MockMvcResultMatchers.jsonPath("$[0].data.maxima.max.event.pulseId").value(101)); + } + + @Test + public void testDateRangeQueryNrOfBinsAggregate() throws Exception { + long startTime = 1000; + long endTime = 1099; + String startDate = TimeUtils.format(startTime); + String endDate = TimeUtils.format(endTime); + DAQQuery request = + new DAQQuery( + new RequestRangeDate( + startDate, + endDate), + new AggregationDescriptor().setNrOfBins(2).setAggregations( + Arrays.asList(Aggregation.min, Aggregation.mean, Aggregation.max)), + TEST_CHANNEL_NAMES); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform( + MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content) + ) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.max").value(104.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value.min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value.mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value.max").value(104.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value.min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value.mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value.max").value(109.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value.min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value.mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value.max").value(109.0)); + } + + @Test + public void testDateRangeQueryNrOfBinsAggregateExtrema() throws Exception { + long startTime = 1000; + long endTime = 1099; + String startDate = TimeUtils.format(startTime); + String endDate = TimeUtils.format(endTime); + DAQQuery request = + new DAQQuery( + new RequestRangeDate( + startDate, + endDate), + new AggregationDescriptor() + .setNrOfBins(2) + .setAggregations(Arrays.asList(Aggregation.min, Aggregation.mean, Aggregation.max)) + .setExtrema(Arrays.asList(Extrema.minValue, Extrema.maxValue)), + TEST_CHANNEL_NAMES); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform( + MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content) + ) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.max").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema.minValue.value").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema.minValue.pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema.minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema.minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema.maxValue.value").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema.maxValue.pulseId").value(104)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema.maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 40000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema.maxValue.eventCount").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value.min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value.mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value.max").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema.minValue.value").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema.minValue.pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema.minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema.minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema.maxValue.value").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema.maxValue.pulseId").value(104)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema.maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 40000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema.maxValue.eventCount").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value.min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value.mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value.max").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema.minValue.value").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema.minValue.pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema.minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema.minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema.maxValue.value").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema.maxValue.pulseId").value(109)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema.maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 90000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema.maxValue.eventCount").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value.min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value.mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value.max").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema.minValue.value").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema.minValue.pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema.minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema.minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema.maxValue.value").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema.maxValue.pulseId").value(109)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema.maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 90000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema.maxValue.eventCount").value(1)); + } + + @Test + public void testDateRangeQueryBinSizeAggregate() throws Exception { + long startTime = 10000; + long endTime = 10999; + String startDate = TimeUtils.format(startTime); + String endDate = TimeUtils.format(endTime); + DAQQuery request = new DAQQuery( + new RequestRangeDate( + startDate, + endDate), + new AggregationDescriptor().setDurationPerBin(100), + TEST_CHANNEL_NAMES); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform( + MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content) + ) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(1000)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.min").value(1000.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.mean").value(1004.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.max").value(1009.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(1000)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value.min").value(1000.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value.mean").value(1004.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value.max").value(1009.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(1010)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 100000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value.min").value(1010.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value.mean").value(1014.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value.max").value(1019.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(1010)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 100000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value.min").value(1010.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value.mean").value(1014.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value.max").value(1019.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].pulseId").value(1020)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 200000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].value.min").value(1020.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].value.mean").value(1024.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].value.max").value(1029.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].pulseId").value(1020)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 200000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].value.min").value(1020.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].value.mean").value(1024.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].value.max").value(1029.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].pulseId").value(1030)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 300000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].value.min").value(1030.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].value.mean").value(1034.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].value.max").value(1039.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].pulseId").value(1030)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 300000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].value.min").value(1030.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].value.mean").value(1034.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].value.max").value(1039.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].pulseId").value(1040)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 400000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].value.min").value(1040.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].value.mean").value(1044.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].value.max").value(1049.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].pulseId").value(1040)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 400000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].value.min").value(1040.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].value.mean").value(1044.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].value.max").value(1049.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].pulseId").value(1050)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 500000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].value.min").value(1050.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].value.mean").value(1054.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].value.max").value(1059.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].pulseId").value(1050)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 500000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value.min").value(1050.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value.mean").value(1054.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value.max").value(1059.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].pulseId").value(1060)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 600000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value.min").value(1060.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value.mean").value(1064.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value.max").value(1069.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].pulseId").value(1060)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 600000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].value.min").value(1060.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].value.mean").value(1064.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].value.max").value(1069.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[7]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[7]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0].pulseId").value(1070)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 700000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0].value.min").value(1070.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0].value.mean").value(1074.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][0].value.max").value(1079.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1].pulseId").value(1070)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 700000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1].value.min").value(1070.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1].value.mean").value(1074.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[7][1].value.max").value(1079.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[8]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[8]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0].pulseId").value(1080)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 800000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0].value.min").value(1080.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0].value.mean").value(1084.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][0].value.max").value(1089.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1].pulseId").value(1080)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 800000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1].value.min").value(1080.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1].value.mean").value(1084.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[8][1].value.max").value(1089.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[9]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[9]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0].pulseId").value(1090)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 900000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0].value.min").value(1090.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0].value.mean").value(1094.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][0].value.max").value(1099.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1].pulseId").value(1090)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1].globalSeconds").value( + TestTimeUtils.getTimeStr(10, 900000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1].eventCount").value(10)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1].value.min").value(1090.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1].value.mean").value(1094.5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[9][1].value.max").value(1099.0)); + } + + @Test + public void testDateRangeQueryIndexAggregate() throws Exception { + long startTime = 1000; + long endTime = 1099; + String startDate = TimeUtils.format(startTime); + String endDate = TimeUtils.format(endTime); + DAQQuery request = + new DAQQuery( + new RequestRangeDate( + startDate, + endDate), + new AggregationDescriptor() + .setAggregationType(AggregationType.index) + .setNrOfBins(2) + .setAggregations(Arrays.asList(Aggregation.min, Aggregation.mean, Aggregation.max)), + TEST_CHANNEL_WAVEFORM_01, TEST_CHANNEL_WAVEFORM_02); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform( + MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content) + ) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_WAVEFORM_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0].min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0].mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0].max").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1].min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1].mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1].max").value(104.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_WAVEFORM_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[0].min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[0].mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[0].max").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[1].min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[1].mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[1].max").value(104.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_WAVEFORM_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0].min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0].mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0].max").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1].min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1].mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1].max").value(109.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_WAVEFORM_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0].min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0].mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0].max").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1].min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1].mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1].max").value(109.0)); + } + + @Test + public void testDateRangeQueryIndexAggregateExtrema() throws Exception { + long startTime = 1000; + long endTime = 1099; + String startDate = TimeUtils.format(startTime); + String endDate = TimeUtils.format(endTime); + DAQQuery request = + new DAQQuery( + new RequestRangeDate( + startDate, + endDate), + new AggregationDescriptor() + .setAggregationType(AggregationType.index) + .setNrOfBins(2) + .setAggregations(Arrays.asList(Aggregation.min, Aggregation.mean, Aggregation.max)) + .setExtrema(Arrays.asList(Extrema.minValue, Extrema.maxValue)), + TEST_CHANNEL_WAVEFORM_01, TEST_CHANNEL_WAVEFORM_02); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform( + MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content) + ) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(TEST_CHANNEL_WAVEFORM_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0].min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0].mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0].max").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1].min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1].mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1].max").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[0].minValue.value").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[0].minValue.pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[0].minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[0].minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[0].maxValue.value").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[0].maxValue.pulseId").value(104)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[0].maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 40000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[0].maxValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[1].minValue.value").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[1].minValue.pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[1].minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[1].minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[1].maxValue.value").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[1].maxValue.pulseId").value(104)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[1].maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 40000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].extrema[1].maxValue.eventCount").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(TEST_CHANNEL_WAVEFORM_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[0].min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[0].mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[0].max").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[1].min").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[1].mean").value(102.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[1].max").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[0].minValue.value").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[0].minValue.pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[0].minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[0].minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[0].maxValue.value").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[0].maxValue.pulseId").value(104)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[0].maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 40000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[0].maxValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[1].minValue.value").value(100.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[1].minValue.pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[1].minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[1].minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[1].maxValue.value").value(104.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[1].maxValue.pulseId").value(104)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[1].maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 40000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].extrema[1].maxValue.eventCount").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(TEST_CHANNEL_WAVEFORM_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0].min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0].mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0].max").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1].min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1].mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1].max").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[0].minValue.value").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[0].minValue.pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[0].minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[0].minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[0].maxValue.value").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[0].maxValue.pulseId").value(109)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[0].maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 90000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[0].maxValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[1].minValue.value").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[1].minValue.pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[1].minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[1].minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[1].maxValue.value").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[1].maxValue.pulseId").value(109)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[1].maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 90000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].extrema[1].maxValue.eventCount").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(TEST_CHANNEL_WAVEFORM_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].eventCount").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value[0].min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value[0].mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value[0].max").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value[1].min").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value[1].mean").value(107.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value[1].max").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[0].minValue.value").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[0].minValue.pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[0].minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[0].minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[0].maxValue.value").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[0].maxValue.pulseId").value(109)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[0].maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 90000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[0].maxValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[1].minValue.value").value(105.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[1].minValue.pulseId").value(105)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[1].minValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 50000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[1].minValue.eventCount").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[1].maxValue.value").value(109.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[1].maxValue.pulseId").value(109)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[1].maxValue.globalSeconds").value( + TestTimeUtils.getTimeStr(1, 90000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].extrema[1].maxValue.eventCount").value(1)); + } + + @Test + public void testPulseRangeQuery_Match_Drop() throws Exception { + Map> channelSeq = new HashMap<>(); + Set channel_01_Seq = new LinkedHashSet<>(Arrays.asList(0L, 2L, 4L, 5L)); + String channel_01 = "TestChannel_Sequence_" + Arrays.toString(channel_01_Seq.toArray()); + channelSeq.put(channel_01, channel_01_Seq); + Set channel_02_Seq = new LinkedHashSet<>(Arrays.asList(1L, 3L, 5L, 6L)); + String channel_02 = "TestChannel_Sequence_" + Arrays.toString(channel_02_Seq.toArray()); + channelSeq.put(channel_02, channel_02_Seq); + Set channel_03_Seq = new LinkedHashSet<>(Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L)); + String channel_03 = "TestChannel_Sequence_" + Arrays.toString(channel_03_Seq.toArray()); + channelSeq.put(channel_03, channel_03_Seq); + List channels = Arrays.asList(channel_01, channel_02, channel_03); + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + // dummy range as range is defined by channel_Seq (see + // DummyCassandraReader.getDummyEventStream()) + 0, + 0), + channels); + request.setMapping(new Mapping(IncompleteStrategy.DROP)); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(5)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(5)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2].pulseId").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").doesNotExist()); + + } + + @Test + public void testPulseRangeQuery_Match_KeepAsIs() throws Exception { + Map> channelSeq = new HashMap<>(); + Set channel_01_Seq = new LinkedHashSet<>(Arrays.asList(0L, 2L, 4L, 5L)); + String channel_01 = "TestChannel_Sequence_" + Arrays.toString(channel_01_Seq.toArray()); + channelSeq.put(channel_01, channel_01_Seq); + Set channel_02_Seq = new LinkedHashSet<>(Arrays.asList(1L, 3L, 5L, 6L)); + String channel_02 = "TestChannel_Sequence_" + Arrays.toString(channel_02_Seq.toArray()); + channelSeq.put(channel_02, channel_02_Seq); + Set channel_03_Seq = new LinkedHashSet<>(Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L)); + String channel_03 = "TestChannel_Sequence_" + Arrays.toString(channel_03_Seq.toArray()); + channelSeq.put(channel_03, channel_03_Seq); + List channels = Arrays.asList(channel_01, channel_02, channel_03); + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + // dummy range as range is defined by channel_Seq (see + // DummyCassandraReader.getDummyEventStream()) + 0, + 0), + channels); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].pulseId").value(2)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].pulseId").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].pulseId").value(3)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].pulseId").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].pulseId").value(4)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].pulseId").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].pulseId").value(5)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].pulseId").value(5)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].pulseId").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].pulseId").value(6)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[7]").doesNotExist()); + + } + + @Test + public void testPulseRangeQuery_Match_FillNull() throws Exception { + Map> channelSeq = new HashMap<>(); + Set channel_01_Seq = new LinkedHashSet<>(Arrays.asList(0L, 2L, 4L, 5L)); + String channel_01 = "TestChannel_Sequence_" + Arrays.toString(channel_01_Seq.toArray()); + channelSeq.put(channel_01, channel_01_Seq); + Set channel_02_Seq = new LinkedHashSet<>(Arrays.asList(1L, 3L, 5L, 6L)); + String channel_02 = "TestChannel_Sequence_" + Arrays.toString(channel_02_Seq.toArray()); + channelSeq.put(channel_02, channel_02_Seq); + Set channel_03_Seq = new LinkedHashSet<>(Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L)); + String channel_03 = "TestChannel_Sequence_" + Arrays.toString(channel_03_Seq.toArray()); + channelSeq.put(channel_03, channel_03_Seq); + List channels = Arrays.asList(channel_01, channel_02, channel_03); + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + // dummy range as range is defined by channel_Seq (see + // DummyCassandraReader.getDummyEventStream()) + 0, + 0), + channels); + request.setMapping(new Mapping(IncompleteStrategy.FILL_NULL)); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2].pulseId").value(0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][2].pulseId").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].pulseId").value(2)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][2].pulseId").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].pulseId").value(3)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][2].pulseId").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].pulseId").value(4)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][2].pulseId").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].pulseId").value(5)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].pulseId").value(5)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].pulseId").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1].pulseId").value(6)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[6][2]").doesNotExist()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[7]").doesNotExist()); + + } + + @Test + public void testPulseRangeQuery_Match_KeepAsIs_Combine_Scalar() throws Exception { + Map> channelSeq = new HashMap<>(); + Set channel_01_Seq = new LinkedHashSet<>(Arrays.asList(0L, 5L, 20L, 40L, 50L)); + String channel_01 = + "TestChannel_Sequence_" + + channel_01_Seq.stream().map(val -> val.toString()).collect(Collectors.joining(",", "{", "}")); + channelSeq.put(channel_01, channel_01_Seq); + Set channel_02_Seq = new LinkedHashSet<>(Arrays.asList(10L, 30L, 50L, 55L, 60L, 65L)); + String channel_02 = + "TestChannel_Sequence_" + + channel_02_Seq.stream().map(val -> val.toString()).collect(Collectors.joining(",", "{", "}")); + channelSeq.put(channel_02, channel_02_Seq); + Set channel_03_Seq = new LinkedHashSet<>(Arrays.asList(0L, 10L, 20L, 30L, 40L, 50L)); + String channel_03 = + "TestChannel_Sequence_" + + channel_03_Seq.stream().map(val -> val.toString()).collect(Collectors.joining(",", "{", "}")); + channelSeq.put(channel_03, channel_03_Seq); + List channels = Arrays.asList(channel_01, channel_02, channel_03); + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + // dummy range as range is defined by channel_Seq (see + // DummyCassandraReader.getDummyEventStream()) + 0, + 0), + channels); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].eventCount").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.min").value(0.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.mean").value(0.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value.max").value(0.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value").value(0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].pulseId").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].value").value(2)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].pulseId").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].value").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].pulseId").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].value").value(3)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].pulseId").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].value").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].pulseId").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].value").value(4)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].pulseId").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].value").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].pulseId").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].value").value(5)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].pulseId").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].eventCount").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value.min").value(5.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value.mean").value(5.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value.max").value(5.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].pulseId").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].value").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].pulseId").value(6)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].eventCount").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value.min").value(6.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value.mean").value(6.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value.max").value(6.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[7]").doesNotExist()); + + } + + @Test + public void testPulseRangeQuery_Match_KeepAsIs_Combine_Waveform() throws Exception { + Map> channelSeq = new HashMap<>(); + Set channel_01_Seq = new LinkedHashSet<>(Arrays.asList(0L, 5L, 20L, 40L, 50L)); + String channel_01 = + "TestChannel_Waveform_Sequence_" + + channel_01_Seq.stream().map(val -> val.toString()).collect(Collectors.joining(",", "{", "}")); + channelSeq.put(channel_01, channel_01_Seq); + Set channel_02_Seq = new LinkedHashSet<>(Arrays.asList(10L, 30L, 50L, 55L, 60L, 65L)); + String channel_02 = + "TestChannel_Waveform_Sequence_" + + channel_02_Seq.stream().map(val -> val.toString()).collect(Collectors.joining(",", "{", "}")); + channelSeq.put(channel_02, channel_02_Seq); + Set channel_03_Seq = new LinkedHashSet<>(Arrays.asList(0L, 10L, 20L, 30L, 40L, 50L)); + String channel_03 = + "TestChannel_Waveform_Sequence_" + + channel_03_Seq.stream().map(val -> val.toString()).collect(Collectors.joining(",", "{", "}")); + channelSeq.put(channel_03, channel_03_Seq); + List channels = Arrays.asList(channel_01, channel_02, channel_03); + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + // dummy range as range is defined by channel_Seq (see + // DummyCassandraReader.getDummyEventStream()) + 0, + 0), + channels); + request.setMapping(new Mapping()); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].pulseId").value(0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].eventCount").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0].min").value(0.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0].mean").value(0.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[0].max").value(0.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1].min").value(0.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1].mean").value(0.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][0].value[1].max").value(0.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].pulseId").value(0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[0]").value(0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][1].value[1]").value(0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[0][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].pulseId").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[0]").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][0].value[1]").value(1)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].pulseId").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value[0]").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][1].value[1]").value(1)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].pulseId").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].value[0]").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][0].value[1]").value(2)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].pulseId").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].value[0]").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][1].value[1]").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[2][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].pulseId").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].value[0]").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][0].value[1]").value(3)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].pulseId").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].value[0]").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][1].value[1]").value(3)) + .andExpect(MockMvcResultMatchers.jsonPath("$[3][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].pulseId").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].value[0]").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][0].value[1]").value(4)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].pulseId").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].value[0]").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][1].value[1]").value(4)) + .andExpect(MockMvcResultMatchers.jsonPath("$[4][2]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].channel").value(channel_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].pulseId").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].value[0]").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][0].value[1]").value(5)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].pulseId").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].eventCount").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value[0].min").value(5.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value[0].mean").value(5.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value[0].max").value(5.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value[1].min").value(5.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value[1].mean").value(5.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][1].value[1].max").value(5.0)) + + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].channel").value(channel_03)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].pulseId").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].value[0]").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][2].value[1]").value(5)) + .andExpect(MockMvcResultMatchers.jsonPath("$[5][3]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].channel").value(channel_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].backend").value(Backend.SF_DATABUFFER.getKey())) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].pulseId").value(6)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].eventCount").value(2)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value[0].min").value(6.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value[0].mean").value(6.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value[0].max").value(6.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value[1].min").value(6.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value[1].mean").value(6.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][0].value[1].max").value(6.0)) + .andExpect(MockMvcResultMatchers.jsonPath("$[6][1]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$[7]").doesNotExist()); + + } + + // @Test + // public void testIncompleteMapping_01() throws Exception { + // asdfadsf + // + // - several events in same bin + // - missing events for bin (incomplete=true/false) + // } +} diff --git a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTest.java b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTest.java index 524ce83..3861149 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTest.java +++ b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerJsonTest.java @@ -373,15 +373,16 @@ public class QueryRestControllerJsonTest extends AbstractDaqRestTest { .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].pulseId").value(101)) .andExpect(MockMvcResultMatchers.jsonPath("$[0].data[1].globalSeconds").value( TestTimeUtils.getTimeStr(1, 10000000))) - // .andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists()) - // .andExpect(MockMvcResultMatchers.jsonPath("$[1].channel").isMap()) - // .andExpect(MockMvcResultMatchers.jsonPath("$[1].channel.name").value(TEST_CHANNEL_02)) - // .andExpect(MockMvcResultMatchers.jsonPath("$[1].data").isArray()) - // .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].pulseId").value(10)) - // .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].globalMillis").value(100)) - // .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].pulseId").value(11)) - // .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].globalMillis").value(110)) - ; + .andExpect(MockMvcResultMatchers.jsonPath("$[1]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].channel").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].channel.name").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].data").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))); } @Test diff --git a/src/test/java/ch/psi/daq/test/queryrest/query/AbstractStreamEventReader.java b/src/test/java/ch/psi/daq/test/queryrest/query/AbstractStreamEventReader.java index db98e9a..8249ea1 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/query/AbstractStreamEventReader.java +++ b/src/test/java/ch/psi/daq/test/queryrest/query/AbstractStreamEventReader.java @@ -84,8 +84,8 @@ public abstract class AbstractStreamEventReader implements StreamEventReader getEventStream(TimeRangeQuery query) { - return getDummyEventStream(query.getChannel(), query.getStartMillis() / 10, query.getEndMillis() / 10) + return getDummyEventStream(query.getChannel(), getBackend(), query.getStartMillis() / 10, + query.getEndMillis() / 10) .filter(query.getFilterOrDefault(EventQuery.NO_OP_FILTER)); } @@ -136,39 +137,50 @@ public abstract class AbstractStreamEventReader implements StreamEventReader getDummyEventStream(String channelParam, long startIndex, long endIndex, + public static Stream getDummyEventStream(String channelParam, Backend backend, long startIndex, + long endIndex, String... columns) { String channelLower = channelParam.toLowerCase(); String channel = (columns == null || columns.length == 0 || ArrayUtils.contains(columns, FieldNames.FIELD_CHANNEL)) ? channelParam : null; - Stream rangeStream; + LongStream millisRangeStream = null; if (channelParam.contains("[") && channelParam.contains("]")) { - rangeStream = + millisRangeStream = Arrays.stream( channelParam.substring( channelParam.indexOf("[") + 1, channelParam.indexOf("]")) .split(",") ) - .map(str -> str.trim()) - .map(Long::parseLong); + .mapToLong(str -> Long.parseLong(str.trim()) * 10); + } else if (channelParam.contains("{") && channelParam.contains("}")) { + millisRangeStream = + Arrays.stream( + channelParam.substring( + channelParam.indexOf("{") + 1, + channelParam.indexOf("}")) + .split(",") + ) + .mapToLong(str -> Long.parseLong(str)); } else { - rangeStream = LongStream.rangeClosed(startIndex, endIndex).boxed(); + millisRangeStream = LongStream.rangeClosed(startIndex * 10, endIndex * 10) + .filter(val -> val % 10 == 0); } Stream eventStream = - rangeStream.map( - i -> { + millisRangeStream.mapToObj( + millis -> { + long i = millis / 10; BigDecimal iocTime = (columns == null || columns.length == 0 || ArrayUtils.contains(columns, - FieldNames.FIELD_IOC_TIME)) ? TimeUtils.getTimeFromMillis(i * 10, 0) + FieldNames.FIELD_IOC_TIME)) ? TimeUtils.getTimeFromMillis(millis, 0) : PropertiesUtils.DEFAULT_VALUE_DECIMAL; BigDecimal globalTime = (columns == null || columns.length == 0 || ArrayUtils.contains(columns, - FieldNames.FIELD_GLOBAL_TIME)) ? TimeUtils.getTimeFromMillis(i * 10, 0) + FieldNames.FIELD_GLOBAL_TIME)) ? TimeUtils.getTimeFromMillis(millis, 0) : PropertiesUtils.DEFAULT_VALUE_DECIMAL; long pulseId = (columns == null || columns.length == 0 || ArrayUtils.contains(columns, @@ -180,6 +192,7 @@ public abstract class AbstractStreamEventReader implements StreamEventReader getDummyEvents(String channel, long startIndex, long endIndex, String... columns) { - return getDummyEventStream(channel, startIndex, endIndex, columns).collect(Collectors.toList()); + return getDummyEventStream(channel, getBackend(), startIndex, endIndex, columns).collect(Collectors.toList()); } /** @@ -293,6 +308,7 @@ public abstract class AbstractStreamEventReader implements StreamEventReader i * 10, i -> 0, i -> i, + getBackend(), query.getChannel()).stream(); } @@ -390,16 +406,18 @@ public abstract class AbstractStreamEventReader implements StreamEventReader getStartMetaPulseIdAsync(PulseIdRangeQuery query) { - return CompletableFuture.completedFuture(new MetaPulseIdImpl(query.getChannel(), query.getStartPulseId(), + return CompletableFuture.completedFuture(new MetaPulseIdImpl(query.getChannel(), getBackend(), query + .getStartPulseId(), TimeUtils.getTimeFromMillis(query.getStartPulseId() * 10, 0))); } @Override public CompletableFuture getEndMetaPulseIdAsync(PulseIdRangeQuery query) { - return CompletableFuture.completedFuture(new MetaPulseIdImpl(query.getChannel(), query.getEndPulseId(), + return CompletableFuture.completedFuture(new MetaPulseIdImpl(query.getChannel(), getBackend(), query + .getEndPulseId(), TimeUtils.getTimeFromMillis(query.getEndPulseId() * 10, 0))); } } diff --git a/src/test/java/ch/psi/daq/test/queryrest/query/DummyArchiverApplianceReader.java b/src/test/java/ch/psi/daq/test/queryrest/query/DummyArchiverApplianceReader.java index 334d316..d1eaa90 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/query/DummyArchiverApplianceReader.java +++ b/src/test/java/ch/psi/daq/test/queryrest/query/DummyArchiverApplianceReader.java @@ -53,7 +53,7 @@ public class DummyArchiverApplianceReader implements DataReader { @Override public Stream getEventStream(TimeRangeQuery query) { - return DummyCassandraReader.getDummyEventStream(query.getChannel(), query.getStartMillis() / 10, + return DummyCassandraReader.getDummyEventStream(query.getChannel(), getBackend(), query.getStartMillis() / 10, query.getEndMillis() / 10) .filter(query.getFilterOrDefault(EventQuery.NO_OP_FILTER)); } diff --git a/src/test/java/ch/psi/daq/test/queryrest/query/DummyCassandraReader.java b/src/test/java/ch/psi/daq/test/queryrest/query/DummyCassandraReader.java index 3649476..20c31ed 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/query/DummyCassandraReader.java +++ b/src/test/java/ch/psi/daq/test/queryrest/query/DummyCassandraReader.java @@ -64,13 +64,13 @@ public class DummyCassandraReader extends AbstractStreamEventReader implements C @Override public CompletableFuture getStartMetaPulseIdAsync(PulseIdRangeQuery query) { - return CompletableFuture.completedFuture(new MetaPulseIdImpl(query.getChannel(), query.getStartPulseId(), + return CompletableFuture.completedFuture(new MetaPulseIdImpl(query.getChannel(), getBackend(), query.getStartPulseId(), TimeUtils.getTimeFromMillis(query.getStartPulseId() * 10, 0))); } @Override public CompletableFuture getEndMetaPulseIdAsync(PulseIdRangeQuery query) { - return CompletableFuture.completedFuture(new MetaPulseIdImpl(query.getChannel(), query.getEndPulseId(), + return CompletableFuture.completedFuture(new MetaPulseIdImpl(query.getChannel(), getBackend(), query.getEndPulseId(), TimeUtils.getTimeFromMillis(query.getEndPulseId() * 10, 0))); } } diff --git a/src/test/java/ch/psi/daq/test/queryrest/response/ResponseQueryTest.java b/src/test/java/ch/psi/daq/test/queryrest/response/ResponseQueryTest.java index 1f62a40..3a84537 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/response/ResponseQueryTest.java +++ b/src/test/java/ch/psi/daq/test/queryrest/response/ResponseQueryTest.java @@ -17,7 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import ch.psi.daq.domain.query.DAQQuery; import ch.psi.daq.domain.query.operation.Compression; -import ch.psi.daq.domain.query.operation.Response; +import ch.psi.daq.domain.query.response.Response; import ch.psi.daq.domain.request.range.RequestRangePulseId; import ch.psi.daq.queryrest.response.csv.CSVHTTPResponse; import ch.psi.daq.queryrest.response.json.JSONHTTPResponse;