This is an automated email from the ASF dual-hosted git repository.
gian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new abf0e0a159 CompressionStrategyTest: Fix thread-unsafe Closer usage.
(#12605)
abf0e0a159 is described below
commit abf0e0a1596e8c87796e10a90dc1bc9f7b314013
Author: Gian Merlino <[email protected]>
AuthorDate: Sat Jun 4 10:57:13 2022 -0700
CompressionStrategyTest: Fix thread-unsafe Closer usage. (#12605)
Closer is not thread-safe, so we need one per thread in the
concurrency tests.
---
.../segment/data/CompressionStrategyTest.java | 67 +++++++++-------------
1 file changed, 28 insertions(+), 39 deletions(-)
diff --git
a/processing/src/test/java/org/apache/druid/segment/data/CompressionStrategyTest.java
b/processing/src/test/java/org/apache/druid/segment/data/CompressionStrategyTest.java
index 7188f9373f..da6b781e33 100644
---
a/processing/src/test/java/org/apache/druid/segment/data/CompressionStrategyTest.java
+++
b/processing/src/test/java/org/apache/druid/segment/data/CompressionStrategyTest.java
@@ -23,9 +23,7 @@ import com.google.common.collect.Iterables;
import org.apache.druid.collections.ResourceHolder;
import org.apache.druid.java.util.common.ByteBufferUtils;
import org.apache.druid.java.util.common.io.Closer;
-import org.junit.After;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,7 +44,7 @@ import java.util.concurrent.TimeUnit;
@RunWith(Parameterized.class)
public class CompressionStrategyTest
{
- @Parameterized.Parameters
+ @Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> compressionStrategies()
{
return Iterables.transform(
@@ -64,44 +62,32 @@ public class CompressionStrategyTest
// MUST be smaller than CompressedPools.BUFFER_SIZE
private static final int DATA_SIZER = 0xFFFF;
- private static byte[] originalData;
+ private static byte[] ORIGINAL_DATA;
@BeforeClass
public static void setupClass()
{
- originalData = new byte[DATA_SIZER];
+ ORIGINAL_DATA = new byte[DATA_SIZER];
Random random = new Random(54671457);
- random.nextBytes(originalData);
- }
-
- private Closer closer;
-
- @Before
- public void createCloser()
- {
- closer = Closer.create();
- }
-
- @After
- public void closeCloser() throws IOException
- {
- closer.close();
+ random.nextBytes(ORIGINAL_DATA);
}
@Test
- public void testBasicOperations()
+ public void testBasicOperations() throws IOException
{
- ByteBuffer compressionOut =
compressionStrategy.getCompressor().allocateOutBuffer(originalData.length,
closer);
- ByteBuffer compressionIn =
compressionStrategy.getCompressor().allocateInBuffer(originalData.length,
closer);
- try (final ResourceHolder<ByteBuffer> holder =
ByteBufferUtils.allocateDirect(originalData.length)) {
+ try (final Closer closer = Closer.create();
+ final ResourceHolder<ByteBuffer> holder =
ByteBufferUtils.allocateDirect(ORIGINAL_DATA.length)) {
+ ByteBuffer compressionOut =
compressionStrategy.getCompressor().allocateOutBuffer(ORIGINAL_DATA.length,
closer);
+ ByteBuffer compressionIn =
compressionStrategy.getCompressor().allocateInBuffer(ORIGINAL_DATA.length,
closer);
+
final ByteBuffer output = holder.get();
- compressionIn.put(originalData);
+ compressionIn.put(ORIGINAL_DATA);
compressionIn.rewind();
ByteBuffer compressed =
compressionStrategy.getCompressor().compress(compressionIn, compressionOut);
compressionStrategy.getDecompressor().decompress(compressed,
compressed.remaining(), output);
byte[] checkArray = new byte[DATA_SIZER];
output.get(checkArray);
- Assert.assertArrayEquals("Uncompressed data does not match",
originalData, checkArray);
+ Assert.assertArrayEquals("Uncompressed data does not match",
ORIGINAL_DATA, checkArray);
}
}
@@ -122,19 +108,22 @@ public class CompressionStrategyTest
results.add(
threadPoolExecutor.submit(
() -> {
- ByteBuffer compressionOut = compressionStrategy.getCompressor()
-
.allocateOutBuffer(originalData.length, closer);
- ByteBuffer compressionIn = compressionStrategy.getCompressor()
-
.allocateInBuffer(originalData.length, closer);
- compressionIn.put(originalData);
- compressionIn.position(0);
- ByteBuffer compressed =
compressionStrategy.getCompressor().compress(compressionIn, compressionOut);
- ByteBuffer output =
compressionStrategy.getCompressor().allocateOutBuffer(originalData.length,
closer);
- compressionStrategy.getDecompressor().decompress(compressed,
compressed.remaining(), output);
- byte[] checkArray = new byte[DATA_SIZER];
- output.get(checkArray);
- Assert.assertArrayEquals("Uncompressed data does not match",
originalData, checkArray);
- return true;
+ try (final Closer closer = Closer.create()) {
+ ByteBuffer compressionOut =
compressionStrategy.getCompressor()
+
.allocateOutBuffer(ORIGINAL_DATA.length, closer);
+ ByteBuffer compressionIn =
compressionStrategy.getCompressor()
+
.allocateInBuffer(ORIGINAL_DATA.length, closer);
+ compressionIn.put(ORIGINAL_DATA);
+ compressionIn.position(0);
+ ByteBuffer compressed =
compressionStrategy.getCompressor().compress(compressionIn, compressionOut);
+ ByteBuffer output = compressionStrategy.getCompressor()
+
.allocateOutBuffer(ORIGINAL_DATA.length, closer);
+ compressionStrategy.getDecompressor().decompress(compressed,
compressed.remaining(), output);
+ byte[] checkArray = new byte[DATA_SIZER];
+ output.get(checkArray);
+ Assert.assertArrayEquals("Uncompressed data does not match",
ORIGINAL_DATA, checkArray);
+ return true;
+ }
}
)
);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]