You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2018/01/07 06:15:36 UTC
[bookkeeper] branch master updated: ISSUE #935 ISSUE #915: Part 3 -
Make circe-checksum module work for both java 8 and java 9
This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 1e2c24b ISSUE #935 ISSUE #915: Part 3 - Make circe-checksum module work for both java 8 and java 9
1e2c24b is described below
commit 1e2c24b82648aa27974d1a0b91fe80d97c30fef0
Author: Sijie Guo <si...@apache.org>
AuthorDate: Sat Jan 6 22:15:29 2018 -0800
ISSUE #935 ISSUE #915: Part 3 - Make circe-checksum module work for both java 8 and java 9
Descriptions of the changes in this PR:
- switch from jmockit to mockito, and from testng to junit. make testing and mocking framework consistent across modules.
- skip `-Werror` check in circe-checksum since `finalize` is deprecated at java 9
- change CRC32CDigestManager to use `circe-checksum` module
- fix shading to include `circe-checksum`
This change is based #917 . Gitsha 73049f8 contains the changes to make circe-checksum module work for both java8 and java9.
Author: Sijie Guo <si...@apache.org>
Reviewers: Enrico Olivelli <eo...@gmail.com>, Matteo Merli <mm...@apache.org>
This closes #937 from sijie/fix_pulsar_checksum, closes #935, closes #915
---
bookkeeper-server/pom.xml | 90 ++++++++-----
.../bookkeeper/client/CRC32CDigestManager.java | 6 +-
circe-checksum/pom.xml | 30 +++--
.../com/scurrilous/circe/CommonHashesTest.java | 5 +-
.../scurrilous/circe/checksum/ChecksumTest.java | 4 +-
.../com/scurrilous/circe/crc/CRCProvidersTest.java | 9 +-
.../java/com/scurrilous/circe/crc/CRCTest.java | 8 +-
.../circe/impl/AbstractIncrementalIntHashTest.java | 117 ++++++++--------
.../impl/AbstractIncrementalLongHashTest.java | 120 ++++++++---------
.../circe/impl/AbstractStatefulHashTest.java | 149 ++++++++++-----------
.../circe/impl/AbstractStatelessIntHashTest.java | 56 ++++----
.../circe/impl/AbstractStatelessLongHashTest.java | 58 ++++----
.../scurrilous/circe/utils/NativeUtilsTests.java | 4 +-
shaded/bookkeeper-server-shaded/pom.xml | 1 +
.../bookkeeper-server-shaded-artifact-test/pom.xml | 4 +
.../shaded/BookKeeperServerShadedArtifactTest.java | 6 +
.../shaded/BookKeeperServerShadedJarTest.java | 6 +
17 files changed, 347 insertions(+), 326 deletions(-)
diff --git a/bookkeeper-server/pom.xml b/bookkeeper-server/pom.xml
index 5b82066..7b62fb7 100644
--- a/bookkeeper-server/pom.xml
+++ b/bookkeeper-server/pom.xml
@@ -33,6 +33,13 @@
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-common</artifactId>
<version>${project.parent.version}</version>
+ <exclusions>
+ <!-- exclude "netty-common" since "netty-all" already introduces it -->
+ <exclusion>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-common</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper</groupId>
@@ -70,7 +77,7 @@
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
- </exclusion>
+ </exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
@@ -78,27 +85,29 @@
</exclusions>
</dependency>
<dependency>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- <version>${zookeeper.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
+ <version>${netty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-tcnative-boringssl-static</artifactId>
+ <version>${netty-boringssl.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.bookkeeper.http</groupId>
+ <artifactId>http-server</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.bookkeeper</groupId>
+ <artifactId>circe-checksum</artifactId>
+ <version>${project.version}</version>
<exclusions>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </exclusion>
+ <!-- exclude "netty-buffer" since "netty-all" already introduces it -->
<exclusion>
<groupId>io.netty</groupId>
- <artifactId>netty</artifactId>
+ <artifactId>netty-buffer</artifactId>
</exclusion>
</exclusions>
</dependency>
@@ -161,11 +170,7 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-all</artifactId>
- <version>${netty.version}</version>
- </dependency>
+ <!-- testing dependencies -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minikdc</artifactId>
@@ -173,19 +178,29 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-tcnative-boringssl-static</artifactId>
- <version>${netty-boringssl.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.bookkeeper.http</groupId>
- <artifactId>http-server</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.pulsar</groupId>
- <artifactId>pulsar-checksum</artifactId>
- <version>1.20.0-incubating</version>
+ <groupId>org.apache.zookeeper</groupId>
+ <artifactId>zookeeper</artifactId>
+ <version>${zookeeper.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>io.netty</groupId>
+ <artifactId>netty</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
</dependencies>
<build>
@@ -224,6 +239,7 @@
<include>com.google.protobuf:protobuf-java</include>
<include>org.apache.bookkeeper:bookkeeper-common</include>
<include>org.apache.bookkeeper:bookkeeper-proto</include>
+ <include>org.apache.bookkeeper:circe-checksum</include>
<include>org.apache.bookkeeper.stats:bookkeeper-stats-api</include>
</includes>
</artifactSet>
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/CRC32CDigestManager.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/CRC32CDigestManager.java
index 1923220..86394cc 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/CRC32CDigestManager.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/CRC32CDigestManager.java
@@ -18,11 +18,11 @@ package org.apache.bookkeeper.client;
* limitations under the License.
*/
+import com.scurrilous.circe.checksum.Crc32cIntChecksum;
import com.scurrilous.circe.crc.Sse42Crc32C;
import io.netty.buffer.ByteBuf;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.mutable.MutableInt;
-import org.apache.pulsar.checksum.utils.Crc32cChecksum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,10 +56,10 @@ class CRC32CDigestManager extends DigestManager {
void update(ByteBuf data) {
if (isNewCrc.get().isTrue()) {
isNewCrc.get().setFalse();
- currentCrc.get().setValue(Crc32cChecksum.computeChecksum(data));
+ currentCrc.get().setValue(Crc32cIntChecksum.computeChecksum(data));
} else {
final int lastCrc = currentCrc.get().intValue();
- currentCrc.get().setValue(Crc32cChecksum.resumeChecksum(lastCrc, data));
+ currentCrc.get().setValue(Crc32cIntChecksum.resumeChecksum(lastCrc, data));
}
}
}
diff --git a/circe-checksum/pom.xml b/circe-checksum/pom.xml
index ddcd0f2..9b4f084 100644
--- a/circe-checksum/pom.xml
+++ b/circe-checksum/pom.xml
@@ -54,19 +54,6 @@
<version>${netty.version}</version>
</dependency>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <version>6.8.5</version>
- </dependency>
-
- <dependency>
- <groupId>com.googlecode.jmockit</groupId>
- <artifactId>jmockit</artifactId>
- <version>1.7</version>
- <scope>test</scope>
- </dependency>
-
</dependencies>
<build>
@@ -105,7 +92,22 @@
</execution>
</executions>
</plugin>
-
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ <compilerArgs>
+ <!-- Object.finalize() is deprecated at java 9 -->
+ <!-- <compilerArg>-Werror</compilerArg> -->
+ <compilerArg>-Xlint:deprecation</compilerArg>
+ <compilerArg>-Xlint:unchecked</compilerArg>
+ <!-- https://issues.apache.org/jira/browse/MCOMPILER-205 -->
+ <compilerArg>-Xpkginfo:always</compilerArg>
+ </compilerArgs>
+ </configuration>
+ </plugin>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/CommonHashesTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/CommonHashesTest.java
index a42de85..f69e599 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/CommonHashesTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/CommonHashesTest.java
@@ -15,11 +15,10 @@
******************************************************************************/
package com.scurrilous.circe;
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
import java.nio.charset.Charset;
-
-import org.testng.annotations.Test;
+import org.junit.Test;
@SuppressWarnings("javadoc")
public class CommonHashesTest {
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/checksum/ChecksumTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/checksum/ChecksumTest.java
index f6b0b9b..67fee3c 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/checksum/ChecksumTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/checksum/ChecksumTest.java
@@ -19,14 +19,14 @@
package com.scurrilous.circe.checksum;
import static com.scurrilous.circe.params.CrcParameters.CRC32C;
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
import com.scurrilous.circe.IncrementalIntHash;
import com.scurrilous.circe.IncrementalLongHash;
import com.scurrilous.circe.crc.StandardCrcProvider;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-import org.testng.annotations.Test;
+import org.junit.Test;
/**
* Verify circe checksum.
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCProvidersTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCProvidersTest.java
index b3ac059..81ff710 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCProvidersTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCProvidersTest.java
@@ -24,21 +24,20 @@ import static com.scurrilous.circe.HashSupport.STATEFUL;
import static com.scurrilous.circe.HashSupport.STATELESS_INCREMENTAL;
import static com.scurrilous.circe.params.CrcParameters.CRC32;
import static com.scurrilous.circe.params.CrcParameters.CRC64;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.SortedMap;
-import org.testng.annotations.Test;
-
import com.scurrilous.circe.HashProvider;
import com.scurrilous.circe.HashProviders;
import com.scurrilous.circe.HashSupport;
import com.scurrilous.circe.IncrementalLongHash;
+import org.junit.Test;
@SuppressWarnings("javadoc")
public class CRCProvidersTest {
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCTest.java
index e5eb77d..287026c 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCTest.java
@@ -24,16 +24,14 @@ import static com.scurrilous.circe.params.CrcParameters.CRC32_BZIP2;
import static com.scurrilous.circe.params.CrcParameters.CRC32_POSIX;
import static com.scurrilous.circe.params.CrcParameters.CRC64;
import static com.scurrilous.circe.params.CrcParameters.CRC64_XZ;
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
import com.scurrilous.circe.IncrementalLongHash;
-import java.nio.charset.Charset;
-
-import org.testng.annotations.Test;
-
import com.scurrilous.circe.HashProvider;
import com.scurrilous.circe.IncrementalIntHash;
import com.scurrilous.circe.params.CrcParameters;
+import java.nio.charset.Charset;
+import org.junit.Test;
/**
* Tests the {@link StandardCrcProvider} with various CRC algorithms. See the <a
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalIntHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalIntHashTest.java
index 0f947c9..7b75a03 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalIntHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalIntHashTest.java
@@ -15,101 +15,106 @@
******************************************************************************/
package com.scurrilous.circe.impl;
-import static org.testng.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import com.scurrilous.circe.StatefulHash;
import java.nio.ByteBuffer;
-import mockit.Expectations;
-import mockit.Mocked;
-import org.testng.annotations.Test;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
@SuppressWarnings("javadoc")
public class AbstractIncrementalIntHashTest {
- @Mocked
private AbstractIncrementalIntHash hash;
+ @Before
+ public void setup() {
+ this.hash = mock(AbstractIncrementalIntHash.class, Mockito.CALLS_REAL_METHODS);
+ }
+
@Test
public void testAsStateful() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.algorithm();
- hash.length();
- hash.initial();
- result = 42;
- hash.resumeUnchecked(42, input, 2, 4);
- result = 99;
- }
- };
+
+ when(hash.initial()).thenReturn(42);
+ when(hash.resumeUnchecked(eq(42), eq(input), eq(2), eq(4))).thenReturn(99);
+
StatefulHash stateful = hash.createStateful();
stateful.algorithm();
stateful.length();
- assertNotEquals(stateful, stateful.createNew());
+ assertNotSame(stateful, stateful.createNew());
stateful.reset();
stateful.update(input, 2, 4);
assertEquals(99, stateful.getInt());
+
+ // verification
+ verify(hash, times(1)).algorithm();
+ verify(hash, times(1)).length();
+ verify(hash, times(1)).initial();
+ verify(hash, times(1)).resumeUnchecked(
+ eq(42), eq(input), eq(2), eq(4));
}
@Test
public void testCalculateByteArray() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.initial();
- result = 42;
- hash.resume(42, input);
- }
- };
+
+ when(hash.initial()).thenReturn(42);
+
hash.calculate(input);
+
+ verify(hash, times(1)).initial();
+ verify(hash, times(1)).resume(eq(42), eq(input));
}
@Test
public void testCalculateByteArrayIntInt() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.initial();
- result = 42;
- hash.resume(42, input, 2, 4);
- }
- };
+
+ when(hash.initial()).thenReturn(42);
+
hash.calculate(input, 2, 4);
+
+ verify(hash, times(1)).initial();
+ verify(hash, times(1)).resume(eq(42), eq(input), eq(2), eq(4));
}
@Test
public void testCalculateByteBuffer() {
final ByteBuffer input = ByteBuffer.allocate(10);
- new Expectations(hash) {
- {
- hash.initial();
- result = 42;
- hash.resume(42, input);
- }
- };
+
+ when(hash.initial()).thenReturn(42);
+
hash.calculate(input);
+
+ verify(hash, times(1)).initial();
+ verify(hash, times(1)).resume(eq(42), eq(input));
}
@Test
public void testResumeIntByteArray() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.resumeUnchecked(42, input, 0, input.length);
- }
- };
+
hash.resume(42, input);
+
+ verify(hash, times(1)).resumeUnchecked(eq(42), eq(input), eq(0), eq(input.length));
}
@Test
public void testResumeIntByteArrayIntInt() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.resumeUnchecked(42, input, 2, 4);
- }
- };
+
hash.resume(42, input, 2, 4);
+
+ verify(hash, times(1)).resumeUnchecked(eq(42), eq(input), eq(2), eq(4));
}
@Test
@@ -117,13 +122,12 @@ public class AbstractIncrementalIntHashTest {
final ByteBuffer input = ByteBuffer.allocate(20);
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.resumeUnchecked(42, input.array(), input.arrayOffset() + 5, 10);
- }
- };
+
hash.resume(42, input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .resumeUnchecked(eq(42), eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
}
@Test
@@ -131,12 +135,11 @@ public class AbstractIncrementalIntHashTest {
final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.resumeUnchecked(42, withInstanceOf(byte[].class), 0, 10);
- }
- };
+
hash.resume(42, input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .resumeUnchecked(eq(42), any(byte[].class), eq(0), eq(10));
}
}
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalLongHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalLongHashTest.java
index 0468da8..81f8f72 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalLongHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalLongHashTest.java
@@ -15,37 +15,39 @@
******************************************************************************/
package com.scurrilous.circe.impl;
-import static org.testng.Assert.*;
-
-import java.nio.ByteBuffer;
-
-import mockit.Expectations;
-import mockit.Mocked;
-
-import org.testng.annotations.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import com.scurrilous.circe.StatefulHash;
-import com.scurrilous.circe.impl.AbstractIncrementalLongHash;
+import java.nio.ByteBuffer;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
@SuppressWarnings("javadoc")
public class AbstractIncrementalLongHashTest {
- @Mocked
private AbstractIncrementalLongHash hash;
+ @Before
+ public void setup() {
+ this.hash = mock(AbstractIncrementalLongHash.class, Mockito.CALLS_REAL_METHODS);
+ }
+
@Test
public void testAsStateful() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.algorithm();
- hash.length();
- hash.initial();
- result = 0x4200000000L;
- hash.resumeUnchecked(0x4200000000L, input, 2, 4);
- result = 0x990000000000L;
- }
- };
+
+ when(hash.initial()).thenReturn(0x4200000000L);
+ when(hash.resumeUnchecked(eq(0x4200000000L), eq(input), eq(2), eq(4)))
+ .thenReturn(0x990000000000L);
+
StatefulHash stateful = hash.createStateful();
stateful.algorithm();
stateful.length();
@@ -54,67 +56,65 @@ public class AbstractIncrementalLongHashTest {
stateful.update(input, 2, 4);
assertEquals(0, stateful.getInt());
assertEquals(0x990000000000L, stateful.getLong());
+
+ verify(hash, times(1)).algorithm();
+ verify(hash, times(1)).length();
+ verify(hash, times(1)).initial();
+ verify(hash, times(1)).resumeUnchecked(
+ eq(0x4200000000L), eq(input), eq(2), eq(4));
}
@Test
public void testCalculateByteArray() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.initial();
- result = 0x4200000000L;
- hash.resume(0x4200000000L, input);
- }
- };
+
+ when(hash.initial()).thenReturn(0x4200000000L);
+
hash.calculate(input);
+
+ verify(hash, times(1)).resume(eq(0x4200000000L), eq(input));
}
@Test
public void testCalculateByteArrayIntInt() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.initial();
- result = 0x4200000000L;
- hash.resume(0x4200000000L, input, 2, 4);
- }
- };
+
+ when(hash.initial()).thenReturn(0x4200000000L);
+
hash.calculate(input, 2, 4);
+
+ verify(hash, times(1)).resume(eq(0x4200000000L), eq(input), eq(2), eq(4));
}
@Test
public void testCalculateByteBuffer() {
final ByteBuffer input = ByteBuffer.allocate(10);
- new Expectations(hash) {
- {
- hash.initial();
- result = 0x4200000000L;
- hash.resume(0x4200000000L, input);
- }
- };
+
+ when(hash.initial()).thenReturn(0x4200000000L);
+
hash.calculate(input);
+
+ verify(hash, times(1)).resume(eq(0x4200000000L), eq(input));
}
@Test
public void testResumeLongByteArray() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.resumeUnchecked(0x4200000000L, input, 0, input.length);
- }
- };
+
hash.resume(0x4200000000L, input);
+
+ verify(hash, times(1))
+ .resumeUnchecked(eq(0x4200000000L), eq(input), eq(0), eq(input.length));
}
@Test
public void testResumeLongByteArrayIntInt() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.resumeUnchecked(0x4200000000L, input, 2, 4);
- }
- };
+
hash.resume(0x4200000000L, input, 2, 4);
+
+ verify(hash, times(1))
+ .resumeUnchecked(eq(0x4200000000L), eq(input), eq(2), eq(4));
}
@Test
@@ -122,13 +122,12 @@ public class AbstractIncrementalLongHashTest {
final ByteBuffer input = ByteBuffer.allocate(20);
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.resumeUnchecked(0x4200000000L, input.array(), input.arrayOffset() + 5, 10);
- }
- };
+
hash.resume(0x4200000000L, input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .resumeUnchecked(eq(0x4200000000L), eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
}
@Test
@@ -136,12 +135,11 @@ public class AbstractIncrementalLongHashTest {
final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.resumeUnchecked(0x4200000000L, withInstanceOf(byte[].class), 0, 10);
- }
- };
+
hash.resume(0x4200000000L, input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .resumeUnchecked(eq(0x4200000000L), any(byte[].class), eq(0), eq(10));
}
}
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatefulHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatefulHashTest.java
index 8cad8b1..968e18b 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatefulHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatefulHashTest.java
@@ -15,67 +15,71 @@
******************************************************************************/
package com.scurrilous.circe.impl;
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
-import mockit.Expectations;
-import mockit.Mocked;
-import mockit.NonStrictExpectations;
-
-import org.testng.annotations.Test;
+import org.junit.Test;
+import org.mockito.Mockito;
@SuppressWarnings("javadoc")
public class AbstractStatefulHashTest {
- @Mocked
private AbstractStatefulHash hash;
+ public AbstractStatefulHashTest() {
+ this.hash = mock(AbstractStatefulHash.class, Mockito.CALLS_REAL_METHODS);
+ }
+
@Test
public void testUpdateByteArray() {
final byte[] input = new byte[42];
- new Expectations(hash) {
- {
- hash.updateUnchecked(input, 0, input.length);
- }
- };
+
hash.update(input);
+
+ verify(hash, times(1))
+ .updateUnchecked(eq(input), eq(0), eq(input.length));
}
@Test
public void testUpdateByteArrayIntInt() {
final byte[] input = new byte[42];
- new Expectations(hash) {
- {
- hash.updateUnchecked(input, 5, 10);
- }
- };
+
hash.update(input, 5, 10);
+
+ verify(hash, times(1))
+ .updateUnchecked(eq(input), eq(5), eq(10));
}
- @Test(expectedExceptions = IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testUpdateByteArrayIntNegInt() {
final byte[] input = new byte[42];
- new Expectations(hash) {
- };
+
hash.update(input, 1, -1);
}
- @Test(expectedExceptions = IndexOutOfBoundsException.class)
+ @Test(expected = IndexOutOfBoundsException.class)
public void testUpdateByteArrayNegIntInt() {
final byte[] input = new byte[42];
- new Expectations(hash) {
- };
+
hash.update(input, -1, 10);
}
- @Test(expectedExceptions = IndexOutOfBoundsException.class)
+ @Test(expected = IndexOutOfBoundsException.class)
public void testUpdateByteArrayIntIntOverflow() {
final byte[] input = new byte[42];
- new Expectations(hash) {
- };
+
hash.update(input, 40, 3);
}
@@ -84,13 +88,12 @@ public class AbstractStatefulHashTest {
final ByteBuffer input = ByteBuffer.allocate(20);
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.updateUnchecked(input.array(), input.arrayOffset() + 5, 10);
- }
- };
+
hash.update(input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .updateUnchecked(eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
}
@Test
@@ -98,25 +101,25 @@ public class AbstractStatefulHashTest {
final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.updateUnchecked(withInstanceOf(byte[].class), 0, 10);
- }
- };
+
hash.update(input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .updateUnchecked(any(byte[].class), eq(0), eq(10));
}
@Test
public void testGetBytes() {
final List<byte[]> captures = new ArrayList<>();
- new Expectations(hash) {
- {
- hash.length();
- result = 5;
- hash.writeBytes(withCapture(captures), 0, 5);
- }
- };
+
+ when(hash.length()).thenReturn(5);
+
+ doAnswer(invocationOnMock -> {
+ captures.add(invocationOnMock.getArgument(0));
+ return invocationOnMock.callRealMethod();
+ }).when(hash).writeBytes(any(byte[].class), eq(0), eq(5));
+
hash.getBytes();
assertEquals(5, captures.get(0).length);
}
@@ -124,70 +127,54 @@ public class AbstractStatefulHashTest {
@Test
public void testGetBytesByteArrayInt() {
final byte[] output = new byte[5];
- new Expectations(hash) {
- {
- hash.length();
- result = output.length;
- hash.getLong();
- result = 0x1234567890L;
- }
- };
+
+ when(hash.length()).thenReturn(output.length);
+ when(hash.getLong()).thenReturn(0x1234567890L);
+
hash.getBytes(output, 0, output.length);
- assertEquals(new byte[] { (byte) 0x90, 0x78, 0x56, 0x34, 0x12 }, output);
+ assertArrayEquals(new byte[] { (byte) 0x90, 0x78, 0x56, 0x34, 0x12 }, output);
}
- @Test(expectedExceptions = IndexOutOfBoundsException.class)
+ @Test(expected = IndexOutOfBoundsException.class)
public void testGetBytesByteArrayNegInt() {
final byte[] output = new byte[5];
- new NonStrictExpectations(hash) {
- {
- hash.length();
- result = output.length;
- }
- };
+
+ when(hash.length()).thenReturn(output.length);
+
hash.getBytes(output, -1, output.length);
+
+ verify(hash, atLeast(0)).length();
}
- @Test(expectedExceptions = IndexOutOfBoundsException.class)
+ @Test(expected = IndexOutOfBoundsException.class)
public void testGetBytesByteArrayIntOverflow() {
final byte[] output = new byte[5];
- new Expectations(hash) {
- };
+
hash.getBytes(output, 0, output.length + 1);
}
@Test
public void testGetBytesByteArrayIntPartial() {
final byte[] output = new byte[5];
- new Expectations(hash) {
- {
- hash.length();
- result = output.length + 1;
- hash.writeBytes(output, 0, output.length);
- }
- };
+
+ when(hash.length()).thenReturn(output.length + 1);
+
hash.getBytes(output, 0, output.length);
+
+ verify(hash, times(1)).writeBytes(eq(output), eq(0), eq(output.length));
}
@Test
public void testGetByte() {
- new Expectations(hash) {
- {
- hash.getInt();
- result = 0x12345678;
- }
- };
+ when(hash.getInt()).thenReturn(0x12345678);
+
assertEquals(0x78, hash.getByte());
}
@Test
public void testGetShort() {
- new Expectations(hash) {
- {
- hash.getInt();
- result = 0x12345678;
- }
- };
+ when(hash.getInt()).thenReturn(0x12345678);
+
assertEquals(0x5678, hash.getShort());
}
}
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessIntHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessIntHashTest.java
index 184b546..1aa3d55 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessIntHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessIntHashTest.java
@@ -15,43 +15,45 @@
******************************************************************************/
package com.scurrilous.circe.impl;
-import static org.testng.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import java.nio.ByteBuffer;
-import mockit.Expectations;
-import mockit.Mocked;
-
-import org.testng.annotations.Test;
-
-import com.scurrilous.circe.impl.AbstractStatelessIntHash;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
@SuppressWarnings("javadoc")
public class AbstractStatelessIntHashTest {
- @Mocked
private AbstractStatelessIntHash hash;
+ @Before
+ public void setup() {
+ hash = mock(AbstractStatelessIntHash.class, Mockito.CALLS_REAL_METHODS);
+ }
+
@Test
public void testCalculateByteArray() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.calculateUnchecked(input, 0, input.length);
- }
- };
+
hash.calculate(input);
+
+ verify(hash, times(1)).calculateUnchecked(eq(input), eq(0), eq(input.length));
}
@Test
public void testCalculateByteArrayIntInt() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.calculateUnchecked(input, 2, 4);
- }
- };
+
hash.calculate(input, 2, 4);
+
+ verify(hash, times(1)).calculateUnchecked(eq(input), eq(2), eq(4));
}
@Test
@@ -59,13 +61,12 @@ public class AbstractStatelessIntHashTest {
final ByteBuffer input = ByteBuffer.allocate(20);
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.calculateUnchecked(input.array(), input.arrayOffset() + 5, 10);
- }
- };
+
hash.calculate(input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .calculateUnchecked(eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
}
@Test
@@ -73,12 +74,11 @@ public class AbstractStatelessIntHashTest {
final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.calculateUnchecked(withInstanceOf(byte[].class), 0, 10);
- }
- };
+
hash.calculate(input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .calculateUnchecked(any(byte[].class), eq(0), eq(10));
}
}
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessLongHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessLongHashTest.java
index a4a607f..d0aabd5 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessLongHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessLongHashTest.java
@@ -15,43 +15,47 @@
******************************************************************************/
package com.scurrilous.circe.impl;
-import static org.testng.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import java.nio.ByteBuffer;
-import mockit.Expectations;
-import mockit.Mocked;
-
-import org.testng.annotations.Test;
-
-import com.scurrilous.circe.impl.AbstractStatelessLongHash;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
@SuppressWarnings("javadoc")
public class AbstractStatelessLongHashTest {
- @Mocked
private AbstractStatelessLongHash hash;
+ @Before
+ public void setup() {
+ this.hash = mock(AbstractStatelessLongHash.class, Mockito.CALLS_REAL_METHODS);
+ }
+
@Test
public void testCalculateByteArray() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.calculateUnchecked(input, 0, input.length);
- }
- };
+
hash.calculate(input);
+
+ verify(hash, times(1))
+ .calculateUnchecked(eq(input), eq(0), eq(input.length));
}
@Test
public void testCalculateByteArrayIntInt() {
final byte[] input = new byte[10];
- new Expectations(hash) {
- {
- hash.calculateUnchecked(input, 2, 4);
- }
- };
+
hash.calculate(input, 2, 4);
+
+ verify(hash, times(1))
+ .calculateUnchecked(eq(input), eq(2), eq(4));
}
@Test
@@ -59,13 +63,12 @@ public class AbstractStatelessLongHashTest {
final ByteBuffer input = ByteBuffer.allocate(20);
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.calculateUnchecked(input.array(), input.arrayOffset() + 5, 10);
- }
- };
+
hash.calculate(input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .calculateUnchecked(eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
}
@Test
@@ -73,12 +76,11 @@ public class AbstractStatelessLongHashTest {
final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
input.position(5);
input.limit(15);
- new Expectations(hash) {
- {
- hash.calculateUnchecked(withInstanceOf(byte[].class), 0, 10);
- }
- };
+
hash.calculate(input);
assertEquals(input.limit(), input.position());
+
+ verify(hash, times(1))
+ .calculateUnchecked(any(byte[].class), eq(0), eq(10));
}
}
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/utils/NativeUtilsTests.java b/circe-checksum/src/test/java/com/scurrilous/circe/utils/NativeUtilsTests.java
index f1d4928..adaf771 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/utils/NativeUtilsTests.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/utils/NativeUtilsTests.java
@@ -19,8 +19,8 @@
package com.scurrilous.circe.utils;
import java.io.FileNotFoundException;
-import org.testng.Assert;
-import org.testng.annotations.Test;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Unit test of {@link NativeUtils}.
diff --git a/shaded/bookkeeper-server-shaded/pom.xml b/shaded/bookkeeper-server-shaded/pom.xml
index d09b274..c2be721 100644
--- a/shaded/bookkeeper-server-shaded/pom.xml
+++ b/shaded/bookkeeper-server-shaded/pom.xml
@@ -69,6 +69,7 @@
<include>org.apache.bookkeeper:bookkeeper-common</include>
<include>org.apache.bookkeeper:bookkeeper-proto</include>
<include>org.apache.bookkeeper:bookkeeper-server</include>
+ <include>org.apache.bookkeeper:circe-checksum</include>
<include>org.apache.bookkeeper.stats:bookkeeper-stats-api</include>
</includes>
</artifactSet>
diff --git a/tests/bookkeeper-server-shaded-artifact-test/pom.xml b/tests/bookkeeper-server-shaded-artifact-test/pom.xml
index 5832854..aa40a12 100644
--- a/tests/bookkeeper-server-shaded-artifact-test/pom.xml
+++ b/tests/bookkeeper-server-shaded-artifact-test/pom.xml
@@ -42,6 +42,10 @@
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-proto</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.apache.bookkeeper</groupId>
+ <artifactId>circe-checksum</artifactId>
+ </exclusion>
</exclusions>
</dependency>
</dependencies>
diff --git a/tests/bookkeeper-server-shaded-artifact-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedArtifactTest.java b/tests/bookkeeper-server-shaded-artifact-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedArtifactTest.java
index 9b97cc6..80e2d0c 100644
--- a/tests/bookkeeper-server-shaded-artifact-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedArtifactTest.java
+++ b/tests/bookkeeper-server-shaded-artifact-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedArtifactTest.java
@@ -59,4 +59,10 @@ public class BookKeeperServerShadedArtifactTest {
Class.forName("org.apache.bookkeeper.proto.BookkeeperProtocol");
assertTrue(true);
}
+
+ @Test
+ public void testCirceChecksum() throws Exception {
+ Class.forName("com.scurrilous.circe.checksum.Crc32cIntChecksum");
+ assertTrue(true);
+ }
}
diff --git a/tests/bookkeeper-server-shaded-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedJarTest.java b/tests/bookkeeper-server-shaded-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedJarTest.java
index 083935f..e462d33 100644
--- a/tests/bookkeeper-server-shaded-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedJarTest.java
+++ b/tests/bookkeeper-server-shaded-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedJarTest.java
@@ -59,4 +59,10 @@ public class BookKeeperServerShadedJarTest {
Class.forName("org.apache.bookkeeper.proto.BookkeeperProtocol");
assertTrue(true);
}
+
+ @Test
+ public void testCirceChecksum() throws Exception {
+ Class.forName("com.scurrilous.circe.checksum.Crc32cIntChecksum");
+ assertTrue(true);
+ }
}
--
To stop receiving notification emails like this one, please contact
['"commits@bookkeeper.apache.org" <co...@bookkeeper.apache.org>'].