@Test(groups = "fast") public void testWriteJsonForInMemoryChunks() throws Exception { final DateTime startTime = new DateTime(DateTimeZone.UTC).minusHours(2); final ByteArrayOutputStream output = new ByteArrayOutputStream(); final JsonGenerator generator = mapper.getJsonFactory().createJsonGenerator(output); resource.writeJsonForInMemoryChunks(generator, mapper.writer(), null, ImmutableList.<Integer>of(hostId3), ImmutableList.<Integer>of(sampleKindId1, sampleKindId2), startTime, null, false); Assert.assertEquals(output.size(), 0); handler.handle(new MapEvent(System.currentTimeMillis(), EVENT_TYPE, UUID.randomUUID(), ImmutableMap.<String, Object>of("hostName", HOST_NAME_3, SAMPLE_KIND_1, 12, SAMPLE_KIND_2, 42))); final Map<Integer, Map<Integer, DecimatingSampleFilter>> filters = resource.createDecimatingSampleFilters(ImmutableList.<Integer>of(hostId3), ImmutableList.<Integer>of(sampleKindId1, sampleKindId2), DecimationMode.PEAK_PICK, startTime, null, null); resource.writeJsonForInMemoryChunks(generator, mapper.writer(), filters, ImmutableList.<Integer>of(hostId3), ImmutableList.<Integer>of(sampleKindId1, sampleKindId2), startTime, null, false); Assert.assertTrue(output.size() > 0); final Set<CategoryIdAndSampleKind> categoryIdsAndSampleKinds = resource.findCategoryIdsAndSampleKindsForHosts(ImmutableList.<String>of(HOST_NAME_3)); Assert.assertEquals(categoryIdsAndSampleKinds.size(), 3); final List<String> sampleKinds = CategoryIdAndSampleKind.extractSampleKinds(categoryIdsAndSampleKinds); Assert.assertTrue(sampleKinds.contains(SAMPLE_KIND_1)); Assert.assertTrue(sampleKinds.contains(SAMPLE_KIND_2)); Assert.assertTrue(sampleKinds.contains("hostName")); }
@VisibleForTesting void writeJsonForInMemoryChunks(final JsonGenerator generator, final ObjectWriter writer, final Map<Integer, Map<Integer, DecimatingSampleFilter>> filters, final List<Integer> hostIdsList, final List<Integer> sampleKindIdsList, @Nullable final DateTime startTime, @Nullable final DateTime endTime, final boolean decodeSamples) throws IOException, ExecutionException { for (final Integer hostId : hostIdsList) { final Collection<? extends TimelineChunk> inMemorySamples = processor.getInMemoryTimelineChunks(hostId, sampleKindIdsList, startTime, endTime); writeJsonForChunks(generator, writer, filters, inMemorySamples, decodeSamples); } }
HostDataResource { @VisibleForTesting void writeJsonForInMemoryChunks(final JsonGenerator generator, final ObjectWriter writer, final Map<Integer, Map<Integer, DecimatingSampleFilter>> filters, final List<Integer> hostIdsList, final List<Integer> sampleKindIdsList, @Nullable final DateTime startTime, @Nullable final DateTime endTime, final boolean decodeSamples) throws IOException, ExecutionException { for (final Integer hostId : hostIdsList) { final Collection<? extends TimelineChunk> inMemorySamples = processor.getInMemoryTimelineChunks(hostId, sampleKindIdsList, startTime, endTime); writeJsonForChunks(generator, writer, filters, inMemorySamples, decodeSamples); } } }
HostDataResource { @VisibleForTesting void writeJsonForInMemoryChunks(final JsonGenerator generator, final ObjectWriter writer, final Map<Integer, Map<Integer, DecimatingSampleFilter>> filters, final List<Integer> hostIdsList, final List<Integer> sampleKindIdsList, @Nullable final DateTime startTime, @Nullable final DateTime endTime, final boolean decodeSamples) throws IOException, ExecutionException { for (final Integer hostId : hostIdsList) { final Collection<? extends TimelineChunk> inMemorySamples = processor.getInMemoryTimelineChunks(hostId, sampleKindIdsList, startTime, endTime); writeJsonForChunks(generator, writer, filters, inMemorySamples, decodeSamples); } } @Inject  HostDataResource(final TimelineDAO dao, final SampleCoder sampleCoder, final CollectorConfig config, final TimelineEventHandler processor); }
HostDataResource { @VisibleForTesting void writeJsonForInMemoryChunks(final JsonGenerator generator, final ObjectWriter writer, final Map<Integer, Map<Integer, DecimatingSampleFilter>> filters, final List<Integer> hostIdsList, final List<Integer> sampleKindIdsList, @Nullable final DateTime startTime, @Nullable final DateTime endTime, final boolean decodeSamples) throws IOException, ExecutionException { for (final Integer hostId : hostIdsList) { final Collection<? extends TimelineChunk> inMemorySamples = processor.getInMemoryTimelineChunks(hostId, sampleKindIdsList, startTime, endTime); writeJsonForChunks(generator, writer, filters, inMemorySamples, decodeSamples); } } @Inject  HostDataResource(final TimelineDAO dao, final SampleCoder sampleCoder, final CollectorConfig config, final TimelineEventHandler processor); @GET @Path("/hosts") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getHosts(@QueryParam("pretty") @DefaultValue("false") final boolean pretty); @GET @Path("/sample_kinds") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getSampleKinds(@QueryParam("pretty") @DefaultValue("false") final boolean pretty); @GET @Path("/{host}") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getSamplesByHostName(@QueryParam("from") @DefaultValue("") final DateTimeParameter startTimeParameter,
                                                @QueryParam("to") @DefaultValue("") final DateTimeParameter endTimeParameter,
                                                @QueryParam("pretty") @DefaultValue("false") final boolean pretty,
                                                @QueryParam("decode_samples") @DefaultValue("false") final boolean decodeSamples,
                                                @QueryParam("compact") @DefaultValue("false") final boolean compact,
                                                @QueryParam("decimation_mode") @DefaultValue("peak_pick") final String decimationModeStringString,
                                                @QueryParam("output_count") final Integer outputCount,
                                                @PathParam("host") final String hostName); @GET @Path("/{host}/{category_and_sample_kind}") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getSamplesByHostNameAndSampleKind(@QueryParam("from") @DefaultValue("") final DateTimeParameter startTimeParameter,
                                                             @QueryParam("to") @DefaultValue("") final DateTimeParameter endTimeParameter,
                                                             @QueryParam("pretty") @DefaultValue("false") final boolean pretty,
                                                             @QueryParam("decode_samples") @DefaultValue("false") final boolean decodeSamples,
                                                             @QueryParam("compact") @DefaultValue("false") final boolean compact,
                                                             @QueryParam("decimation_mode") @DefaultValue("peak_pick") final String decimationModeStringString,
                                                             @QueryParam("output_count") final Integer outputCount,
                                                             @PathParam("host") final String hostName,
                                                             @PathParam("category_and_sample_kind") final String categoryAndSampleKind); @GET @Path("/host_samples") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getHostSamples(@QueryParam("from") @DefaultValue("") final DateTimeParameter startTimeParameter,
                                          @QueryParam("to") @DefaultValue("") final DateTimeParameter endTimeParameter,
                                          @QueryParam("pretty") @DefaultValue("false") final boolean pretty,
                                          @QueryParam("decode_samples") @DefaultValue("false") final boolean decodeSamples,
                                          @QueryParam("compact") @DefaultValue("false") final boolean compact,
                                          @QueryParam("decimation_mode") @DefaultValue("peak_pick") final String decimationModeString,
                                          @QueryParam("output_count") final Integer outputCount,
                                          @QueryParam("host") final List<String> hostNames,
                                          @QueryParam("category_and_sample_kind") final List<String> categoriesAndSampleKinds); @GET @Path("/host_samples_using_ids") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getHostSamplesUsingIds(@QueryParam("from") @DefaultValue("") final DateTimeParameter startTimeParameter,
                                                  @QueryParam("to") @DefaultValue("") final DateTimeParameter endTimeParameter,
                                                  @QueryParam("pretty") @DefaultValue("false") final boolean pretty,
                                                  @QueryParam("decode_samples") @DefaultValue("false") final boolean decodeSamples,
                                                  @QueryParam("compact") @DefaultValue("false") final boolean compact,
                                                  @QueryParam("decimation_mode") @DefaultValue("peak_pick") final String decimationModeString,
                                                  @QueryParam("output_count") final Integer outputCount,
                                                  @QueryParam("host_id") final List<Integer> hostIds,
                                                  @QueryParam("sample_kind_id") final List<Integer> sampleKindIds); }
HostDataResource { @VisibleForTesting void writeJsonForInMemoryChunks(final JsonGenerator generator, final ObjectWriter writer, final Map<Integer, Map<Integer, DecimatingSampleFilter>> filters, final List<Integer> hostIdsList, final List<Integer> sampleKindIdsList, @Nullable final DateTime startTime, @Nullable final DateTime endTime, final boolean decodeSamples) throws IOException, ExecutionException { for (final Integer hostId : hostIdsList) { final Collection<? extends TimelineChunk> inMemorySamples = processor.getInMemoryTimelineChunks(hostId, sampleKindIdsList, startTime, endTime); writeJsonForChunks(generator, writer, filters, inMemorySamples, decodeSamples); } } @Inject  HostDataResource(final TimelineDAO dao, final SampleCoder sampleCoder, final CollectorConfig config, final TimelineEventHandler processor); @GET @Path("/hosts") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getHosts(@QueryParam("pretty") @DefaultValue("false") final boolean pretty); @GET @Path("/sample_kinds") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getSampleKinds(@QueryParam("pretty") @DefaultValue("false") final boolean pretty); @GET @Path("/{host}") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getSamplesByHostName(@QueryParam("from") @DefaultValue("") final DateTimeParameter startTimeParameter,
                                                @QueryParam("to") @DefaultValue("") final DateTimeParameter endTimeParameter,
                                                @QueryParam("pretty") @DefaultValue("false") final boolean pretty,
                                                @QueryParam("decode_samples") @DefaultValue("false") final boolean decodeSamples,
                                                @QueryParam("compact") @DefaultValue("false") final boolean compact,
                                                @QueryParam("decimation_mode") @DefaultValue("peak_pick") final String decimationModeStringString,
                                                @QueryParam("output_count") final Integer outputCount,
                                                @PathParam("host") final String hostName); @GET @Path("/{host}/{category_and_sample_kind}") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getSamplesByHostNameAndSampleKind(@QueryParam("from") @DefaultValue("") final DateTimeParameter startTimeParameter,
                                                             @QueryParam("to") @DefaultValue("") final DateTimeParameter endTimeParameter,
                                                             @QueryParam("pretty") @DefaultValue("false") final boolean pretty,
                                                             @QueryParam("decode_samples") @DefaultValue("false") final boolean decodeSamples,
                                                             @QueryParam("compact") @DefaultValue("false") final boolean compact,
                                                             @QueryParam("decimation_mode") @DefaultValue("peak_pick") final String decimationModeStringString,
                                                             @QueryParam("output_count") final Integer outputCount,
                                                             @PathParam("host") final String hostName,
                                                             @PathParam("category_and_sample_kind") final String categoryAndSampleKind); @GET @Path("/host_samples") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getHostSamples(@QueryParam("from") @DefaultValue("") final DateTimeParameter startTimeParameter,
                                          @QueryParam("to") @DefaultValue("") final DateTimeParameter endTimeParameter,
                                          @QueryParam("pretty") @DefaultValue("false") final boolean pretty,
                                          @QueryParam("decode_samples") @DefaultValue("false") final boolean decodeSamples,
                                          @QueryParam("compact") @DefaultValue("false") final boolean compact,
                                          @QueryParam("decimation_mode") @DefaultValue("peak_pick") final String decimationModeString,
                                          @QueryParam("output_count") final Integer outputCount,
                                          @QueryParam("host") final List<String> hostNames,
                                          @QueryParam("category_and_sample_kind") final List<String> categoriesAndSampleKinds); @GET @Path("/host_samples_using_ids") @Produces(MediaType.APPLICATION_JSON) @TimedResource StreamingOutput getHostSamplesUsingIds(@QueryParam("from") @DefaultValue("") final DateTimeParameter startTimeParameter,
                                                  @QueryParam("to") @DefaultValue("") final DateTimeParameter endTimeParameter,
                                                  @QueryParam("pretty") @DefaultValue("false") final boolean pretty,
                                                  @QueryParam("decode_samples") @DefaultValue("false") final boolean decodeSamples,
                                                  @QueryParam("compact") @DefaultValue("false") final boolean compact,
                                                  @QueryParam("decimation_mode") @DefaultValue("peak_pick") final String decimationModeString,
                                                  @QueryParam("output_count") final Integer outputCount,
                                                  @QueryParam("host_id") final List<Integer> hostIds,
                                                  @QueryParam("sample_kind_id") final List<Integer> sampleKindIds);  }