Skip to content

Commit

Permalink
refactor: Updated some of the dependencies according the dependabot m…
Browse files Browse the repository at this point in the history
…essages, also renamed the IOTDBLZ4Compressor to TsFileLZ4Compressor and refactored the one test using Powermock to work without it.
  • Loading branch information
chrisdutz committed Jan 5, 2024
1 parent 74bed58 commit 1896aad
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
10 changes: 2 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
<version>2.15.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -91,13 +91,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<!-- It seems that powermock is having issues with the newest mockito versions -->
<version>2.23.4</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.9</version>
<version>5.8.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
5 changes: 0 additions & 5 deletions tsfile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -209,7 +209,7 @@ public static LZ4Factory getFactory() {
return factory;
}

public IOTDBLZ4Compressor() {
public TsFileLZ4Compressor() {
super();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tsfile/src/test/java/org/apache/tsfile/compress/LZ4Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ValuePageReader> 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 =
Expand All @@ -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<ValuePageReader> 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 =
Expand All @@ -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<ValuePageReader> 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 =
Expand All @@ -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<ValuePageReader> 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);

Expand All @@ -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<ValuePageReader> 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));

Expand Down

0 comments on commit 1896aad

Please sign in to comment.