From 1896aad3a6d34ffd9fdecc7b194405c8abddca77 Mon Sep 17 00:00:00 2001 From: Christofer Dutz Date: Fri, 5 Jan 2024 13:53:23 +0100 Subject: [PATCH] refactor: Updated some of the dependencies according the dependabot messages, also renamed the IOTDBLZ4Compressor to TsFileLZ4Compressor and refactored the one test using Powermock to work without it. --- .github/workflows/greetings.yml | 2 +- .github/workflows/unit-test.yml | 2 +- pom.xml | 10 +--- tsfile/pom.xml | 5 -- .../apache/tsfile/compress/ICompressor.java | 6 +- .../apache/tsfile/compress/IUnCompressor.java | 2 +- .../apache/tsfile/compress/CompressTest.java | 4 +- .../org/apache/tsfile/compress/LZ4Test.java | 6 +- .../LazyLoadAlignedPagePointReaderTest.java | 57 +++++++++---------- 9 files changed, 41 insertions(+), 53 deletions(-) diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index 72179bba6..c833f27c4 100644 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -6,7 +6,7 @@ jobs: greeting: runs-on: ubuntu-latest steps: - - uses: actions/first-interaction@v1.1.1 + - uses: actions/first-interaction@v1.3.0 continue-on-error: true with: repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index d826c99cf..ec85b06d2 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -53,7 +53,7 @@ jobs: uses: actions/checkout@v4 - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: corretto java-version: ${{ matrix.java }} diff --git a/pom.xml b/pom.xml index e327c7813..cd114e30a 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ commons-io commons-io - 2.13.0 + 2.15.1 org.apache.commons @@ -91,13 +91,7 @@ org.mockito mockito-core - - 2.23.4 - - - org.powermock - powermock-api-mockito2 - 2.0.9 + 5.8.0 ch.qos.logback diff --git a/tsfile/pom.xml b/tsfile/pom.xml index 274b5e805..4c76fa893 100644 --- a/tsfile/pom.xml +++ b/tsfile/pom.xml @@ -82,11 +82,6 @@ mockito-core test - - org.powermock - powermock-api-mockito2 - test - ch.qos.logback logback-classic diff --git a/tsfile/src/main/java/org/apache/tsfile/compress/ICompressor.java b/tsfile/src/main/java/org/apache/tsfile/compress/ICompressor.java index ad8399199..390b2a136 100644 --- a/tsfile/src/main/java/org/apache/tsfile/compress/ICompressor.java +++ b/tsfile/src/main/java/org/apache/tsfile/compress/ICompressor.java @@ -67,7 +67,7 @@ static ICompressor getCompressor(CompressionType name) { case SNAPPY: return new SnappyCompressor(); case LZ4: - return new IOTDBLZ4Compressor(); + return new TsFileLZ4Compressor(); case GZIP: return new GZIPCompressor(); case ZSTD: @@ -196,7 +196,7 @@ public CompressionType getType() { } } - class IOTDBLZ4Compressor implements ICompressor { + class TsFileLZ4Compressor implements ICompressor { /** * This instance should be cached to avoid performance problem. See: * https://github.com/lz4/lz4-java/issues/152 and https://github.com/apache/spark/pull/24905 @@ -209,7 +209,7 @@ public static LZ4Factory getFactory() { return factory; } - public IOTDBLZ4Compressor() { + public TsFileLZ4Compressor() { super(); } diff --git a/tsfile/src/main/java/org/apache/tsfile/compress/IUnCompressor.java b/tsfile/src/main/java/org/apache/tsfile/compress/IUnCompressor.java index 773906bb4..f0f7c765c 100644 --- a/tsfile/src/main/java/org/apache/tsfile/compress/IUnCompressor.java +++ b/tsfile/src/main/java/org/apache/tsfile/compress/IUnCompressor.java @@ -200,7 +200,7 @@ class LZ4UnCompressor implements IUnCompressor { private static final int MAX_COMPRESS_RATIO = 255; private static final LZ4SafeDecompressor decompressor = - ICompressor.IOTDBLZ4Compressor.getFactory().safeDecompressor(); + ICompressor.TsFileLZ4Compressor.getFactory().safeDecompressor(); public LZ4UnCompressor() {} diff --git a/tsfile/src/test/java/org/apache/tsfile/compress/CompressTest.java b/tsfile/src/test/java/org/apache/tsfile/compress/CompressTest.java index f61bdf446..4d511a5e7 100644 --- a/tsfile/src/test/java/org/apache/tsfile/compress/CompressTest.java +++ b/tsfile/src/test/java/org/apache/tsfile/compress/CompressTest.java @@ -83,7 +83,7 @@ public void snappyTest() throws IOException { public void lz4CompressorTest1() throws IOException { PublicBAOS out = new PublicBAOS(); out.write(inputString.getBytes(StandardCharsets.UTF_8)); - ICompressor compressor = new ICompressor.IOTDBLZ4Compressor(); + ICompressor compressor = new ICompressor.TsFileLZ4Compressor(); IUnCompressor unCompressor = new IUnCompressor.LZ4UnCompressor(); byte[] compressed = compressor.compress(out.getBuf()); byte[] uncompressed = unCompressor.uncompress(compressed); @@ -95,7 +95,7 @@ public void lz4CompressorTest1() throws IOException { public void lz4CompressorTest2() throws IOException { PublicBAOS out = new PublicBAOS(); out.write(inputString.getBytes(StandardCharsets.UTF_8)); - ICompressor compressor = new ICompressor.IOTDBLZ4Compressor(); + ICompressor compressor = new ICompressor.TsFileLZ4Compressor(); IUnCompressor unCompressor = new IUnCompressor.LZ4UnCompressor(); byte[] compressed = new byte[compressor.getMaxBytesForCompression(out.size())]; int size = compressor.compress(out.getBuf(), 0, out.size(), compressed); diff --git a/tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java b/tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java index ad27402d8..91c5984d0 100644 --- a/tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java +++ b/tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java @@ -18,7 +18,7 @@ */ package org.apache.tsfile.compress; -import org.apache.tsfile.compress.ICompressor.IOTDBLZ4Compressor; +import org.apache.tsfile.compress.ICompressor.TsFileLZ4Compressor; import org.apache.tsfile.compress.IUnCompressor.LZ4UnCompressor; import org.junit.After; import org.junit.Assert; @@ -50,7 +50,7 @@ public void testBytes1() throws IOException { String input = randomString(2000000); byte[] uncom = input.getBytes(StandardCharsets.UTF_8); long time = System.currentTimeMillis(); - ICompressor compressor = new IOTDBLZ4Compressor(); + ICompressor compressor = new TsFileLZ4Compressor(); byte[] compressed = compressor.compress(uncom); System.out.println("compression time cost:" + (System.currentTimeMillis() - time)); @@ -67,7 +67,7 @@ public void testBytes1() throws IOException { @Test public void testBytes2() throws IOException { - ICompressor.IOTDBLZ4Compressor compressor = new ICompressor.IOTDBLZ4Compressor(); + TsFileLZ4Compressor compressor = new TsFileLZ4Compressor(); IUnCompressor.LZ4UnCompressor unCompressor = new IUnCompressor.LZ4UnCompressor(); int n = 500000; diff --git a/tsfile/src/test/java/org/apache/tsfile/read/reader/LazyLoadAlignedPagePointReaderTest.java b/tsfile/src/test/java/org/apache/tsfile/read/reader/LazyLoadAlignedPagePointReaderTest.java index 8cdb91dbf..e180f97a9 100644 --- a/tsfile/src/test/java/org/apache/tsfile/read/reader/LazyLoadAlignedPagePointReaderTest.java +++ b/tsfile/src/test/java/org/apache/tsfile/read/reader/LazyLoadAlignedPagePointReaderTest.java @@ -27,7 +27,6 @@ import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; import java.io.IOException; import java.util.LinkedList; @@ -38,16 +37,16 @@ public class LazyLoadAlignedPagePointReaderTest { @Test public void testTimeNoData() throws IOException { int columnCount = 2; - TimePageReader timePageReader = PowerMockito.mock(TimePageReader.class); + TimePageReader timePageReader = Mockito.mock(TimePageReader.class); List valuePageReaders = new LinkedList<>(); for (int i = 0; i < columnCount; i++) { - valuePageReaders.add(PowerMockito.mock(ValuePageReader.class)); + valuePageReaders.add(Mockito.mock(ValuePageReader.class)); } - PowerMockito.when(timePageReader.hasNextTime()).thenReturn(false); - PowerMockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(timePageReader.hasNextTime()).thenReturn(false); + Mockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(null); - PowerMockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(null); LazyLoadAlignedPagePointReader reader = @@ -59,16 +58,16 @@ public void testTimeNoData() throws IOException { @Test public void testValueNoData() throws IOException { int columnCount = 2; - TimePageReader timePageReader = PowerMockito.mock(TimePageReader.class); + TimePageReader timePageReader = Mockito.mock(TimePageReader.class); List valuePageReaders = new LinkedList<>(); for (int i = 0; i < columnCount; i++) { - valuePageReaders.add(PowerMockito.mock(ValuePageReader.class)); + valuePageReaders.add(Mockito.mock(ValuePageReader.class)); } - PowerMockito.when(timePageReader.hasNextTime()).thenReturn(true).thenReturn(false); - PowerMockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(timePageReader.hasNextTime()).thenReturn(true).thenReturn(false); + Mockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(null); - PowerMockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(null); LazyLoadAlignedPagePointReader reader = @@ -80,17 +79,17 @@ public void testValueNoData() throws IOException { @Test public void testOneRow() throws IOException { int columnCount = 2; - TimePageReader timePageReader = PowerMockito.mock(TimePageReader.class); + TimePageReader timePageReader = Mockito.mock(TimePageReader.class); List valuePageReaders = new LinkedList<>(); for (int i = 0; i < columnCount; i++) { - valuePageReaders.add(PowerMockito.mock(ValuePageReader.class)); + valuePageReaders.add(Mockito.mock(ValuePageReader.class)); } - PowerMockito.when(timePageReader.hasNextTime()).thenReturn(true).thenReturn(false); - PowerMockito.when(timePageReader.nextTime()).thenReturn(1L); - PowerMockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(timePageReader.hasNextTime()).thenReturn(true).thenReturn(false); + Mockito.when(timePageReader.nextTime()).thenReturn(1L); + Mockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(new TsPrimitiveType.TsInt(1)); - PowerMockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(new TsPrimitiveType.TsInt(2)); LazyLoadAlignedPagePointReader reader = @@ -111,21 +110,21 @@ public void testOneRow() throws IOException { @Test public void testSomeColumnNull() throws IOException { int columnCount = 2; - TimePageReader timePageReader = PowerMockito.mock(TimePageReader.class); + TimePageReader timePageReader = Mockito.mock(TimePageReader.class); List valuePageReaders = new LinkedList<>(); for (int i = 0; i < columnCount; i++) { - valuePageReaders.add(PowerMockito.mock(ValuePageReader.class)); + valuePageReaders.add(Mockito.mock(ValuePageReader.class)); } - PowerMockito.when(timePageReader.hasNextTime()) + Mockito.when(timePageReader.hasNextTime()) .thenReturn(true) .thenReturn(true) .thenReturn(false); - PowerMockito.when(timePageReader.nextTime()).thenReturn(1L).thenReturn(2L); - PowerMockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(timePageReader.nextTime()).thenReturn(1L).thenReturn(2L); + Mockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(new TsPrimitiveType.TsInt(1)) .thenReturn(null); - PowerMockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(null) .thenReturn(null); @@ -142,21 +141,21 @@ public void testSomeColumnNull() throws IOException { @Test public void testMultiRow() throws IOException { int columnCount = 2; - TimePageReader timePageReader = PowerMockito.mock(TimePageReader.class); + TimePageReader timePageReader = Mockito.mock(TimePageReader.class); List valuePageReaders = new LinkedList<>(); for (int i = 0; i < columnCount; i++) { - valuePageReaders.add(PowerMockito.mock(ValuePageReader.class)); + valuePageReaders.add(Mockito.mock(ValuePageReader.class)); } - PowerMockito.when(timePageReader.hasNextTime()) + Mockito.when(timePageReader.hasNextTime()) .thenReturn(true) .thenReturn(true) .thenReturn(false); - PowerMockito.when(timePageReader.nextTime()).thenReturn(1L).thenReturn(2L); - PowerMockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(timePageReader.nextTime()).thenReturn(1L).thenReturn(2L); + Mockito.when(valuePageReaders.get(0).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(new TsPrimitiveType.TsInt(1)) .thenReturn(new TsPrimitiveType.TsInt(1)); - PowerMockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) + Mockito.when(valuePageReaders.get(1).nextValue(Mockito.anyLong(), Mockito.anyInt())) .thenReturn(null) .thenReturn(new TsPrimitiveType.TsInt(2));