ATEST-633

This commit is contained in:
Fabian Märki
2016-12-08 16:26:29 +01:00
parent 101af582d2
commit 161fa9d38f
2 changed files with 91 additions and 10 deletions

View File

@ -81,6 +81,8 @@ public class JSONTableResponseStreamWriter implements ResponseStreamWriter {
@Resource(name = QueryRestConfig.BEAN_NAME_DEFAULT_RESPONSE_AGGREGATIONS)
private Set<Aggregation> defaultResponseAggregations;
// In case ArchiverAppliance had several events within the 10ms mapping interval, return these
// aggregations
private Set<String> defaultResponseAggregationsStr;
@PostConstruct
@ -116,7 +118,9 @@ public class JSONTableResponseStreamWriter implements ResponseStreamWriter {
/* make sure identifiers are available */
includedFields.add(QueryField.channel.name());
includedFields.add(QueryField.backend.name());
if (!containsAggregation(includedFields)) {
includedFields.addAll(defaultResponseAggregationsStr);
}
ObjectWriter writer = JSONResponseStreamWriter.configureWriter(includedFields, mapper);
@ -211,4 +215,13 @@ public class JSONTableResponseStreamWriter implements ResponseStreamWriter {
throw exception.get();
}
}
private static boolean containsAggregation(Set<String> includedFields) {
for (Aggregation aggregation : Aggregation.values()) {
if (includedFields.contains(aggregation.name())) {
return true;
}
}
return false;
}
}

View File

@ -145,6 +145,72 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].iocMillis").value(1010));
}
@Test
public void testPulseRangeQuery_NrOfBins() 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);
request.addField(QueryField.value);
AggregationDescriptor aggregation = new AggregationDescriptor(AggregationType.value);
aggregation.setNrOfBins(1);
aggregation.setAggregations(Arrays.asList(Aggregation.mean));
request.setAggregation(aggregation);
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("$.data").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0]").isArray())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0]").isMap())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].channel").value(TEST_CHANNEL_01))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].backend").value(Backend.SF_DATABUFFER.getKey()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].pulseId").value(100))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].globalMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].iocMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].value.mean").value(100.5))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].value.min").doesNotExist())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].value.max").doesNotExist())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1]").isMap())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].channel").value(TEST_CHANNEL_02))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].backend").value(Backend.SF_DATABUFFER.getKey()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].pulseId").value(100))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].globalMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].iocSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].iocMillis").value(1000))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].value.mean").value(100.5))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].value.min").doesNotExist())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].value.max").doesNotExist());
}
@Test
public void testPulseRangeQuery_ChannelOrder() throws Exception {
DAQQuery request = new DAQQuery(
@ -369,7 +435,8 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1]").isMap())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].channel").value(TEST_CHANNEL_02))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
.andExpect(
MockMvcResultMatchers.jsonPath("$.data[0][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].pulseId").value(100))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 0)))
@ -385,7 +452,8 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1]").exists())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1]").isMap())
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].channel").value(TEST_CHANNEL_02))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
.andExpect(
MockMvcResultMatchers.jsonPath("$.data[1][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].pulseId").value(101))
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].globalSeconds").value(
TestTimeUtils.getTimeStr(1, 10000000)));