Skip to content

Commit

Permalink
getLongArray() should copy the current long also
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Mar 14, 2018
1 parent be48230 commit 32807f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fi.iki.yak.ts.compression.gorilla;

import java.util.Arrays;

/**
* An implementation of BitOutput interface that uses on-heap long array.
*
Expand Down Expand Up @@ -136,10 +138,9 @@ public void flush() {
flipWord();
}

/**
* Changed in 2.1, returns a reference to the underlying array (no copy anymore)
*/
public long[] getLongArray() {
return this.longArray;
long[] copy = Arrays.copyOf(longArray, position + 1);
copy[copy.length - 1] = lB;
return copy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,25 @@ void testEmptyBlock() throws Exception {
assertNull(d.readPair());
}

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

LongArrayOutput output = new LongArrayOutput();

GorillaCompressor c = new GorillaCompressor(now, output);

c.addValue(now + 1, 1.0);
c.addValue(now + 2, 1.0);

LongArrayInput input = new LongArrayInput(output.getLongArray());
GorillaDecompressor d = new GorillaDecompressor(input);

assertEquals(now + 1, d.readPair().getTimestamp());
assertEquals(now + 2, d.readPair().getTimestamp());
}

/**
* Long values should be compressable and decompressable in the stream
*/
Expand Down
10 changes: 3 additions & 7 deletions src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package fi.iki.yak.ts.compression.gorilla;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.nio.ByteBuffer;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.concurrent.ThreadLocalRandom;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

/**
* These are generic tests to test that input matches the output after compression + decompression cycle, using
Expand Down

0 comments on commit 32807f2

Please sign in to comment.