@Test(groups = "fast") public void testTimeCursorThatShowedError() throws Exception { // 39 bytes are: ff4f90f67afd03ce1e1ffe1a1e1d01fe771e1d01fd01df1e1d1ffe761e1d01fe771e1d01fe571e // 1944 samples; error at 1934 final int sampleCount = 1944; //final byte[] times = Hex.decodeHex("ff4f90f67afd03ce1e1ffe1a1e1d01fe771e1d01fd01df1e1d1ffe761e1d01fe771e1d01fe571e".toCharArray()); final byte[] times = Hex.decodeHex("00000018FF4F8FE521FD023D1E1FFEF01E1D01FE771E1D01FD03E21EFE07980F".toCharArray()); Assert.assertEquals(times.length, 32); final DefaultTimelineCursor cursor = new DefaultTimelineCursor(times, sampleCount); for (int i = 0; i < sampleCount; i++) { final DateTime nextTime = cursor.getNextTime(); Assert.assertNotNull(nextTime); cursor.skipToSampleNumber(i + 1); } try { final DateTime lastTime = cursor.getNextTime(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(true); } }
@Override public DateTime getNextTime() { final int nextTime = getNextTimeInternal(); if (nextTime == -1) { throw new IllegalStateException(String.format("In DecodedSampleOutputProcessor.getNextTime(), got -1 from timeCursor.getNextTimeInternal()")); } else { return DateTimeUtils.dateTimeFromUnixSeconds(nextTime); } } }
@Test(groups = "fast") public void testTimeCursorWithZeroDeltaWithNext() throws Exception { // This caused a TimeCursor problem // FF 4F 91 D5 BC FE 02 1E 00 FE 02 1E FF 79 0B 44 22 // FF 4F 91 D5 BC FE 02 1E 00 FE 02 1E // FF 4F 91 D5 BC Absolute time // FE 02 1E Repeated delta time: count 2, delta: 30 // 00 Delta 0. Why did this happen? // FE 02 1E Repeated delta time: count 2, delta: 30 // FF 79 0B 44 22 Absolute time // Total samples: 6 final int sampleCount = 7; final byte[] times = Hex.decodeHex("FF4F91D5BCFE021E00FE021EFF790B4422".toCharArray()); final DefaultTimelineCursor cursor = new DefaultTimelineCursor(times, sampleCount); for (int i = 0; i < sampleCount; i++) { final DateTime nextTime = cursor.getNextTime(); Assert.assertNotNull(nextTime); } try { final DateTime lastTime = cursor.getNextTime(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(true); } }
final ByteArrayInputStream byteStream = new ByteArrayInputStream(samples); final DataInputStream inputStream = new DataInputStream(byteStream); final TimelineCursor timeCursor = new DefaultTimelineCursor(times, sampleCount); int sampleNumber = 0; while (true) {
private void checkCombinedTimelines(final String... timelines) throws Exception { final List<byte[]> timeParts = new ArrayList<byte[]>(); for (final String timeline : timelines) { timeParts.add(Hex.decodeHex(timeline.toCharArray())); } int sampleCount = 0; int byteCount = 0; for (final byte[] timePart : timeParts) { byteCount += timePart.length; sampleCount += timelineCoder.countTimeBytesSamples(timePart); } final byte[] concatedTimes = new byte[byteCount]; int offset = 0; for (final byte[] timePart : timeParts) { final int length = timePart.length; System.arraycopy(timePart, 0, concatedTimes, offset, length); offset += length; } final byte[] newCombined = timelineCoder.combineTimelines(timeParts, null); final int newCombinedLength = timelineCoder.countTimeBytesSamples(newCombined); final DefaultTimelineCursor concatedCursor = new DefaultTimelineCursor(concatedTimes, sampleCount); final DefaultTimelineCursor combinedCursor = new DefaultTimelineCursor(newCombined, sampleCount); for (int i = 0; i < sampleCount; i++) { final DateTime concatedTime = concatedCursor.getNextTime(); final DateTime combinedTime = combinedCursor.getNextTime(); Assert.assertEquals(combinedTime, concatedTime); } Assert.assertEquals(newCombinedLength, sampleCount); } }
@Test(groups = "fast") public void testTimeRangeSampleProcessor() throws Exception { final DateTime startTime = new DateTime(dateFormatter.parseDateTime("2012-03-23T17:35:11.000Z")); final DateTime endTime = new DateTime(dateFormatter.parseDateTime("2012-03-23T17:35:17.000Z")); final int sampleCount = 2; final List<DateTime> dateTimes = ImmutableList.<DateTime>of(startTime, endTime); final byte[] compressedTimes = timelineCoder.compressDateTimes(dateTimes); final TimelineCursor cursor = new DefaultTimelineCursor(compressedTimes, sampleCount); Assert.assertEquals(cursor.getNextTime(), startTime); Assert.assertEquals(cursor.getNextTime(), endTime); // 2 x the value 12: REPEAT_BYTE, SHORT, 2, SHORT, 12 (2 bytes) final byte[] samples = new byte[]{(byte) 0xff, 2, 2, 0, 12}; final AtomicInteger samplesCount = new AtomicInteger(0); sampleCoder.scan(samples, compressedTimes, sampleCount, new TimeRangeSampleProcessor(startTime, endTime) { @Override public void processOneSample(final DateTime time, final SampleOpcode opcode, final Object value) { if (samplesCount.get() == 0) { Assert.assertEquals(DateTimeUtils.unixSeconds(time), DateTimeUtils.unixSeconds(startTime)); } else { Assert.assertEquals(DateTimeUtils.unixSeconds(time), DateTimeUtils.unixSeconds(endTime)); } samplesCount.incrementAndGet(); } }); Assert.assertEquals(samplesCount.get(), sampleCount); }
@Test(groups = "fast") public void testTimeCursorWithZeroDeltaWithSampleSkip() throws Exception { // This caused a TimeCursor problem // FF 4F 91 D5 BC FE 02 1E 00 FE 02 1E FF 79 0B 44 22 // FF 4F 91 D5 BC FE 02 1E 00 FE 02 1E // FF 4F 91 D5 BC Absolute time // FE 02 1E Repeated delta time: count 2, delta: 30 // 00 Delta 0. Why did this happen? // FE 02 1E Repeated delta time: count 2, delta: 30 // FF 79 0B 44 22 Absolute time // Total samples: 6 final int sampleCount = 7; final byte[] times = Hex.decodeHex("FF4F91D5BCFE021E00FE021EFF790B4422".toCharArray()); final DefaultTimelineCursor cursor = new DefaultTimelineCursor(times, sampleCount); for (int i = 0; i < sampleCount; i++) { final DateTime nextTime = cursor.getNextTime(); Assert.assertNotNull(nextTime); cursor.skipToSampleNumber(i + 1); } try { final DateTime lastTime = cursor.getNextTime(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(true); } }