Skip to content

Commit

Permalink
Fix empty block case
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Sep 5, 2016
1 parent dac070a commit 43c0bce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public Pair readPair() {
if (storedTimestamp == 0) {
// First item to read
storedDelta = in.getLong(Compressor.FIRST_DELTA_BITS);

if(storedDelta == (1<<27) - 1) {
// Empty - no timestamp space left
return null;
}
storedVal = Double.longBitsToDouble(in.getLong(64));
storedTimestamp = blockTimestamp + storedDelta;
} else {
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,23 @@ void testEncodeLargeAmountOfData() throws Exception {
}
assertNull(d.readPair());
}

@Test
void testEmptyBlock() throws Exception {
long now = LocalDateTime.now().truncatedTo(ChronoUnit.HOURS)
.toInstant(ZoneOffset.UTC).toEpochMilli();

ByteBufferBitOutput output = new ByteBufferBitOutput();

Compressor c = new Compressor(now, output);
c.close();

ByteBuffer byteBuffer = output.getByteBuffer();
byteBuffer.flip();

ByteBufferBitInput input = new ByteBufferBitInput(byteBuffer);
Decompressor d = new Decompressor(input);

assertNull(d.readPair());
}
}

0 comments on commit 43c0bce

Please sign in to comment.