@Test(groups = "fast") public void testByteRepeater() throws Exception { final int hostId = 123; final int sampleKindId = 456; final DateTime startTime = new DateTime(); final List<DateTime> dateTimes = new ArrayList<DateTime>(); final int byteRepeaterCount = 255; final TimelineChunkAccumulator accum = new TimelineChunkAccumulator(hostId, sampleKindId, sampleCoder); for (int i=0; i<byteRepeaterCount; i++) { dateTimes.add(startTime.plusSeconds(i * 5)); accum.addSample(sampleCoder.compressSample(new ScalarSample<Double>(SampleOpcode.DOUBLE, 2.0))); } final DateTime endTime = startTime.plusSeconds(5 * byteRepeaterCount); byte[] compressedTimes = timelineCoder.compressDateTimes(dateTimes); final TimelineChunk chunk = accum.extractTimelineChunkAndReset(startTime, endTime, compressedTimes); final byte[] samples = chunk.getSamples(); Assert.assertEquals(samples.length, 4); Assert.assertEquals(((int)samples[0]) & 0xff, SampleOpcode.REPEAT_BYTE.getOpcodeIndex()); Assert.assertEquals(((int)samples[1]) & 0xff, byteRepeaterCount); Assert.assertEquals(((int)samples[2]) & 0xff, SampleOpcode.BYTE_FOR_DOUBLE.getOpcodeIndex()); Assert.assertEquals(((int)samples[3]) & 0xff, 0x02); Assert.assertEquals(chunk.getSampleCount(), byteRepeaterCount); sampleCoder.scan(chunk.getSamples(), compressedTimes, dateTimes.size(), new SampleProcessor() { @Override public void processSamples(TimelineCursor timeCursor, int sampleCount, SampleOpcode opcode, Object value) { Assert.assertEquals(sampleCount, byteRepeaterCount); Assert.assertEquals(value, 2.0); } }); }
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();  }