@SuppressWarnings("unchecked") @Test(groups="fast") public void testBasicAccumulator() throws Exception { final int hostId = 123; final int sampleKindId = 456; final TimelineChunkAccumulator accum = new TimelineChunkAccumulator(hostId, sampleKindId, sampleCoder); final List<DateTime> dateTimes = new ArrayList<DateTime>(); final DateTime startTime = new DateTime(); final DateTime endTime = startTime.plus(1000); accum.addSample(new ScalarSample(SampleOpcode.INT, new Integer(25))); int timesCounter = 0; dateTimes.add(startTime.plusSeconds(30 * timesCounter++)); for (int i=0; i<5; i++) { accum.addSample(new ScalarSample(SampleOpcode.INT, new Integer(10))); dateTimes.add(startTime.plusSeconds(30 * timesCounter++)); } accum.addSample(new ScalarSample(SampleOpcode.DOUBLE, new Double(100.0))); dateTimes.add(startTime.plusSeconds(30 * timesCounter++)); accum.addSample(new ScalarSample(SampleOpcode.DOUBLE, new Double(100.0))); dateTimes.add(startTime.plusSeconds(30 * timesCounter++)); accum.addSample(new ScalarSample(SampleOpcode.STRING, new String("Hiya!"))); dateTimes.add(startTime.plusSeconds(30 * timesCounter++)); final byte[] compressedTimes = timelineCoder.compressDateTimes(dateTimes); final TimelineChunk chunk = accum.extractTimelineChunkAndReset(startTime, endTime, compressedTimes); Assert.assertEquals(chunk.getSampleCount(), 9); sampleCoder.scan(chunk.getSamples(), compressedTimes, dateTimes.size(), new SampleProcessor() { private int sampleNumber = 0; @Override public void processSamples(TimelineCursor timeCursor, int sampleCount, SampleOpcode opcode, Object value) { if (sampleNumber == 0) { Assert.assertEquals(opcode, SampleOpcode.INT); Assert.assertEquals(value, new Integer(25)); } else if (sampleNumber >= 1 && sampleNumber < 6) { Assert.assertEquals(opcode, SampleOpcode.INT); Assert.assertEquals(value, new Integer(10)); } else if (sampleNumber >= 6 && sampleNumber < 8) { Assert.assertEquals(opcode, SampleOpcode.DOUBLE); Assert.assertEquals(value, new Double(100.0)); } else if (sampleNumber == 8) { Assert.assertEquals(opcode, SampleOpcode.STRING); Assert.assertEquals(value, new String("Hiya!")); } else { Assert.assertTrue(false); } sampleNumber += sampleCount; } }); final TimelineChunkDecoded chunkDecoded = new TimelineChunkDecoded(chunk, sampleCoder); System.out.printf("%s\n", chunkDecoded.toString()); }
public synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes) { final byte[] sampleBytes = getEncodedSamples().getEncodedBytes(); log.debug("Creating TimelineChunk for sampleKindId %d, sampleCount %d", sampleKindId, getSampleCount()); final TimelineChunk chunk = new TimelineChunk(sampleCoder, 0, hostId, sampleKindId, startTime, endTime, timeBytes, sampleBytes, getSampleCount()); reset(); return chunk; }
TimelineChunkAccumulator extends SampleAccumulator { public synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes) { final byte[] sampleBytes = getEncodedSamples().getEncodedBytes(); log.debug("Creating TimelineChunk for sampleKindId %d, sampleCount %d", sampleKindId, getSampleCount()); final TimelineChunk chunk = new TimelineChunk(sampleCoder, 0, hostId, sampleKindId, startTime, endTime, timeBytes, sampleBytes, getSampleCount()); reset(); return chunk; } }
TimelineChunkAccumulator extends SampleAccumulator { public synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes) { final byte[] sampleBytes = getEncodedSamples().getEncodedBytes(); log.debug("Creating TimelineChunk for sampleKindId %d, sampleCount %d", sampleKindId, getSampleCount()); final TimelineChunk chunk = new TimelineChunk(sampleCoder, 0, hostId, sampleKindId, startTime, endTime, timeBytes, sampleBytes, getSampleCount()); reset(); return chunk; } TimelineChunkAccumulator(final int hostId, final int sampleKindId, final SampleCoder sampleCoder); private  TimelineChunkAccumulator(final int hostId, final int sampleKindId, final byte[] bytes, final SampleBase lastSample, final int sampleCount, final SampleCoder sampleCoder); }
TimelineChunkAccumulator extends SampleAccumulator { public synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes) { final byte[] sampleBytes = getEncodedSamples().getEncodedBytes(); log.debug("Creating TimelineChunk for sampleKindId %d, sampleCount %d", sampleKindId, getSampleCount()); final TimelineChunk chunk = new TimelineChunk(sampleCoder, 0, hostId, sampleKindId, startTime, endTime, timeBytes, sampleBytes, getSampleCount()); reset(); return chunk; } TimelineChunkAccumulator(final int hostId, final int sampleKindId, final SampleCoder sampleCoder); private  TimelineChunkAccumulator(final int hostId, final int sampleKindId, final byte[] bytes, final SampleBase lastSample, final int sampleCount, final SampleCoder sampleCoder); TimelineChunkAccumulator deepCopy(); synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes); int getHostId(); int getSampleKindId(); }
TimelineChunkAccumulator extends SampleAccumulator { public synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes) { final byte[] sampleBytes = getEncodedSamples().getEncodedBytes(); log.debug("Creating TimelineChunk for sampleKindId %d, sampleCount %d", sampleKindId, getSampleCount()); final TimelineChunk chunk = new TimelineChunk(sampleCoder, 0, hostId, sampleKindId, startTime, endTime, timeBytes, sampleBytes, getSampleCount()); reset(); return chunk; } TimelineChunkAccumulator(final int hostId, final int sampleKindId, final SampleCoder sampleCoder); private  TimelineChunkAccumulator(final int hostId, final int sampleKindId, final byte[] bytes, final SampleBase lastSample, final int sampleCount, final SampleCoder sampleCoder); TimelineChunkAccumulator deepCopy(); synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes); int getHostId(); int getSampleKindId();  }