summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamas Penzes <tamaas@cloudera.com>2020-08-07 10:46:19 +0000
committerMate Szalay-Beko <symat@apache.org>2020-08-07 12:46:45 +0200
commit08ae49dee4d698fb8c926f3842acdcb0f5b3c58e (patch)
treef5c285030c41053a7e21673464453e366763cdc5
parent4df268b970f525d128219ec81007355d77f6417c (diff)
downloadzookeeper-08ae49dee4d698fb8c926f3842acdcb0f5b3c58e.tar.gz
ZOOKEEPER-3854: Upgrade jUnit in ZooKeeper-Recipes
Author: Tamas Penzes <tamaas@cloudera.com> Reviewers: Norbert Kalmar <nkalmar@apache.org>, Mate Szalay-Beko <symat@apache.org> Closes #1423 from tamaashu/ZOOKEEPER-3854
-rwxr-xr-xzookeeper-recipes/pom.xml4
-rw-r--r--zookeeper-recipes/zookeeper-recipes-election/src/test/java/org/apache/zookeeper/recipes/leader/LeaderElectionSupportTest.java27
-rw-r--r--zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/WriteLockTest.java17
-rw-r--r--zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/ZNodeNameTest.java120
-rw-r--r--zookeeper-recipes/zookeeper-recipes-queue/src/test/java/org/apache/zookeeper/recipes/queue/DistributedQueueTest.java32
5 files changed, 104 insertions, 96 deletions
diff --git a/zookeeper-recipes/pom.xml b/zookeeper-recipes/pom.xml
index 39a898ccd..2ab9d8eb6 100755
--- a/zookeeper-recipes/pom.xml
+++ b/zookeeper-recipes/pom.xml
@@ -80,8 +80,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/zookeeper-recipes/zookeeper-recipes-election/src/test/java/org/apache/zookeeper/recipes/leader/LeaderElectionSupportTest.java b/zookeeper-recipes/zookeeper-recipes-election/src/test/java/org/apache/zookeeper/recipes/leader/LeaderElectionSupportTest.java
index 2ea721e51..65df57d46 100644
--- a/zookeeper-recipes/zookeeper-recipes-election/src/test/java/org/apache/zookeeper/recipes/leader/LeaderElectionSupportTest.java
+++ b/zookeeper-recipes/zookeeper-recipes-election/src/test/java/org/apache/zookeeper/recipes/leader/LeaderElectionSupportTest.java
@@ -17,6 +17,8 @@
package org.apache.zookeeper.recipes.leader;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@@ -27,10 +29,9 @@ import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.recipes.leader.LeaderElectionSupport.EventType;
import org.apache.zookeeper.test.ClientBase;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,7 +45,7 @@ public class LeaderElectionSupportTest extends ClientBase {
private ZooKeeper zooKeeper;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
super.setUp();
@@ -57,7 +58,7 @@ public class LeaderElectionSupportTest extends ClientBase {
CreateMode.PERSISTENT);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
if (zooKeeper != null) {
zooKeeper.delete(TEST_ROOT_NODE + Thread.currentThread().getId(), -1);
@@ -85,7 +86,7 @@ public class LeaderElectionSupportTest extends ClientBase {
runElectionSupportThread(latch, failureCounter);
}
- Assert.assertEquals(0, failureCounter.get());
+ assertEquals(0, failureCounter.get());
if (!latch.await(10, TimeUnit.SECONDS)) {
LOGGER.info("Waited for all threads to start, but timed out. We had {} failures.", failureCounter);
@@ -102,7 +103,7 @@ public class LeaderElectionSupportTest extends ClientBase {
runElectionSupportThread(latch, failureCounter);
}
- Assert.assertEquals(0, failureCounter.get());
+ assertEquals(0, failureCounter.get());
if (!latch.await(10, TimeUnit.SECONDS)) {
LOGGER.info("Waited for all threads to start, but timed out. We had {} failures.", failureCounter);
@@ -119,7 +120,7 @@ public class LeaderElectionSupportTest extends ClientBase {
runElectionSupportThread(latch, failureCounter);
}
- Assert.assertEquals(0, failureCounter.get());
+ assertEquals(0, failureCounter.get());
if (!latch.await(10, TimeUnit.SECONDS)) {
LOGGER.info("Waited for all threads to start, but timed out. We had {} failures.", failureCounter);
@@ -136,7 +137,7 @@ public class LeaderElectionSupportTest extends ClientBase {
runElectionSupportThread(latch, failureCounter);
}
- Assert.assertEquals(0, failureCounter.get());
+ assertEquals(0, failureCounter.get());
if (!latch.await(20, TimeUnit.SECONDS)) {
LOGGER.info("Waited for all threads to start, but timed out. We had {} failures.", failureCounter);
@@ -170,8 +171,8 @@ public class LeaderElectionSupportTest extends ClientBase {
String leaderHostName = electionSupport.getLeaderHostName();
- Assert.assertNotNull(leaderHostName);
- Assert.assertEquals("foohost", leaderHostName);
+ assertNotNull(leaderHostName);
+ assertEquals("foohost", leaderHostName);
electionSupport.stop();
}
@@ -220,7 +221,7 @@ public class LeaderElectionSupportTest extends ClientBase {
expectedevents.add(EventType.ELECTED_START);
expectedevents.add(EventType.ELECTED_COMPLETE);
- Assert.assertEquals("Events has failed to executed in the order", expectedevents, events);
+ assertEquals(expectedevents, events, "Events has failed to executed in the order");
electionSupport2.stop();
}
diff --git a/zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/WriteLockTest.java b/zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/WriteLockTest.java
index 6809fadf5..e9082239a 100644
--- a/zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/WriteLockTest.java
+++ b/zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/WriteLockTest.java
@@ -18,13 +18,14 @@
package org.apache.zookeeper.recipes.lock;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.test.ClientBase;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
/**
* test for writelock.
@@ -74,11 +75,11 @@ public class WriteLockTest extends ClientBase {
dumpNodes(count);
// lets assert that the first election is the leader
- Assert.assertTrue("The first znode should be the leader " + first.getId(), first.isOwner());
+ assertTrue(first.isOwner(), "The first znode should be the leader " + first.getId());
for (int i = 1; i < count; i++) {
WriteLock node = nodes[i];
- Assert.assertFalse("Node should not be the leader " + node.getId(), node.isOwner());
+ assertFalse(node.isOwner(), "Node should not be the leader " + node.getId());
}
if (count > 1) {
@@ -92,11 +93,11 @@ public class WriteLockTest extends ClientBase {
WriteLock second = nodes[1];
dumpNodes(count);
// lets assert that the first election is the leader
- Assert.assertTrue("The second znode should be the leader " + second.getId(), second.isOwner());
+ assertTrue(second.isOwner(), "The second znode should be the leader " + second.getId());
for (int i = 2; i < count; i++) {
WriteLock node = nodes[i];
- Assert.assertFalse("Node should not be the leader " + node.getId(), node.isOwner());
+ assertFalse(node.isOwner(), "Node should not be the leader " + node.getId());
}
}
@@ -130,7 +131,7 @@ public class WriteLockTest extends ClientBase {
}
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
if (nodes != null) {
for (int i = 0; i < nodes.length; i++) {
diff --git a/zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/ZNodeNameTest.java b/zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/ZNodeNameTest.java
index 03dc2c29b..aac76cc62 100644
--- a/zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/ZNodeNameTest.java
+++ b/zookeeper-recipes/zookeeper-recipes-lock/src/test/java/org/apache/zookeeper/recipes/lock/ZNodeNameTest.java
@@ -18,12 +18,14 @@
package org.apache.zookeeper.recipes.lock;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.stream.Collectors;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test for znodenames.
@@ -41,24 +43,24 @@ public class ZNodeNameTest {
final Iterator<ZNodeName> it = nodeNames.iterator();
zname = it.next();
- Assert.assertEquals("x-1", zname.getName());
- Assert.assertEquals("x", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(1), zname.getSequence().get());
+ assertEquals("x-1", zname.getName());
+ assertEquals("x", zname.getPrefix());
+ assertEquals(Integer.valueOf(1), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("x-3", zname.getName());
- Assert.assertEquals("x", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(3), zname.getSequence().get());
+ assertEquals("x-3", zname.getName());
+ assertEquals("x", zname.getPrefix());
+ assertEquals(Integer.valueOf(3), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("x-5", zname.getName());
- Assert.assertEquals("x", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(5), zname.getSequence().get());
+ assertEquals("x-5", zname.getName());
+ assertEquals("x", zname.getPrefix());
+ assertEquals(Integer.valueOf(5), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("x-11", zname.getName());
- Assert.assertEquals("x", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(11), zname.getSequence().get());
+ assertEquals("x-11", zname.getName());
+ assertEquals("x", zname.getPrefix());
+ assertEquals(Integer.valueOf(11), zname.getSequence().get());
}
@Test
@@ -72,29 +74,29 @@ public class ZNodeNameTest {
final Iterator<ZNodeName> it = nodeNames.iterator();
zname = it.next();
- Assert.assertEquals("r-1", zname.getName());
- Assert.assertEquals("r", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(1), zname.getSequence().get());
+ assertEquals("r-1", zname.getName());
+ assertEquals("r", zname.getPrefix());
+ assertEquals(Integer.valueOf(1), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("w-1", zname.getName());
- Assert.assertEquals("w", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(1), zname.getSequence().get());
+ assertEquals("w-1", zname.getName());
+ assertEquals("w", zname.getPrefix());
+ assertEquals(Integer.valueOf(1), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("r-2", zname.getName());
- Assert.assertEquals("r", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(2), zname.getSequence().get());
+ assertEquals("r-2", zname.getName());
+ assertEquals("r", zname.getPrefix());
+ assertEquals(Integer.valueOf(2), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("w-2", zname.getName());
- Assert.assertEquals("w", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(2), zname.getSequence().get());
+ assertEquals("w-2", zname.getName());
+ assertEquals("w", zname.getPrefix());
+ assertEquals(Integer.valueOf(2), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("r-3", zname.getName());
- Assert.assertEquals("r", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(3), zname.getSequence().get());
+ assertEquals("r-3", zname.getName());
+ assertEquals("r", zname.getPrefix());
+ assertEquals(Integer.valueOf(3), zname.getSequence().get());
}
@Test
@@ -112,19 +114,19 @@ public class ZNodeNameTest {
final Iterator<ZNodeName> it = nodeNames.iterator();
zname = it.next();
- Assert.assertEquals("x-98566387950223723-0000000001", zname.getName());
- Assert.assertEquals("x-98566387950223723", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(1), zname.getSequence().get());
+ assertEquals("x-98566387950223723-0000000001", zname.getName());
+ assertEquals("x-98566387950223723", zname.getPrefix());
+ assertEquals(Integer.valueOf(1), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("x-242681582799028564-0000000002", zname.getName());
- Assert.assertEquals("x-242681582799028564", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(2), zname.getSequence().get());
+ assertEquals("x-242681582799028564-0000000002", zname.getName());
+ assertEquals("x-242681582799028564", zname.getPrefix());
+ assertEquals(Integer.valueOf(2), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("x-170623981976748329-0000000003", zname.getName());
- Assert.assertEquals("x-170623981976748329", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(3), zname.getSequence().get());
+ assertEquals("x-170623981976748329-0000000003", zname.getName());
+ assertEquals("x-170623981976748329", zname.getPrefix());
+ assertEquals(Integer.valueOf(3), zname.getSequence().get());
}
@Test
@@ -138,19 +140,19 @@ public class ZNodeNameTest {
final Iterator<ZNodeName> it = nodeNames.iterator();
zname = it.next();
- Assert.assertEquals("r-2-2-1", zname.getName());
- Assert.assertEquals("r-2-2", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(1), zname.getSequence().get());
+ assertEquals("r-2-2-1", zname.getName());
+ assertEquals("r-2-2", zname.getPrefix());
+ assertEquals(Integer.valueOf(1), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("r-1-3-2", zname.getName());
- Assert.assertEquals("r-1-3", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(2), zname.getSequence().get());
+ assertEquals("r-1-3-2", zname.getName());
+ assertEquals("r-1-3", zname.getPrefix());
+ assertEquals(Integer.valueOf(2), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("r-3-1-3", zname.getName());
- Assert.assertEquals("r-3-1", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(3), zname.getSequence().get());
+ assertEquals("r-3-1-3", zname.getName());
+ assertEquals("r-3-1", zname.getPrefix());
+ assertEquals(Integer.valueOf(3), zname.getSequence().get());
}
@Test
@@ -164,24 +166,26 @@ public class ZNodeNameTest {
final Iterator<ZNodeName> it = nodeNames.iterator();
zname = it.next();
- Assert.assertEquals("b-1", zname.getName());
- Assert.assertEquals("b", zname.getPrefix());
- Assert.assertEquals(Integer.valueOf(1), zname.getSequence().get());
+ assertEquals("b-1", zname.getName());
+ assertEquals("b", zname.getPrefix());
+ assertEquals(Integer.valueOf(1), zname.getSequence().get());
zname = it.next();
- Assert.assertEquals("a", zname.getName());
- Assert.assertEquals("a", zname.getPrefix());
- Assert.assertFalse(zname.getSequence().isPresent());
+ assertEquals("a", zname.getName());
+ assertEquals("a", zname.getPrefix());
+ assertFalse(zname.getSequence().isPresent());
zname = it.next();
- Assert.assertEquals("c", zname.getName());
- Assert.assertEquals("c", zname.getPrefix());
- Assert.assertFalse(zname.getSequence().isPresent());
+ assertEquals("c", zname.getName());
+ assertEquals("c", zname.getPrefix());
+ assertFalse(zname.getSequence().isPresent());
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testNullName() {
- new ZNodeName(null);
+ assertThrows(NullPointerException.class, () -> {
+ new ZNodeName(null);
+ });
}
}
diff --git a/zookeeper-recipes/zookeeper-recipes-queue/src/test/java/org/apache/zookeeper/recipes/queue/DistributedQueueTest.java b/zookeeper-recipes/zookeeper-recipes-queue/src/test/java/org/apache/zookeeper/recipes/queue/DistributedQueueTest.java
index 73829204a..0493d8792 100644
--- a/zookeeper-recipes/zookeeper-recipes-queue/src/test/java/org/apache/zookeeper/recipes/queue/DistributedQueueTest.java
+++ b/zookeeper-recipes/zookeeper-recipes-queue/src/test/java/org/apache/zookeeper/recipes/queue/DistributedQueueTest.java
@@ -18,20 +18,22 @@
package org.apache.zookeeper.recipes.queue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.NoSuchElementException;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.test.ClientBase;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link DistributedQueue}.
*/
public class DistributedQueueTest extends ClientBase {
- @After
+ @AfterEach
public void tearDown() throws Exception {
super.tearDown();
}
@@ -51,7 +53,7 @@ public class DistributedQueueTest extends ClientBase {
queueHandles[0].offer(testString.getBytes());
byte[] dequeuedBytes = queueHandles[0].remove();
- Assert.assertEquals(new String(dequeuedBytes), testString);
+ assertEquals(new String(dequeuedBytes), testString);
}
@Test
@@ -69,7 +71,7 @@ public class DistributedQueueTest extends ClientBase {
queueHandles[0].offer(testString.getBytes());
byte[] dequeuedBytes = queueHandles[1].remove();
- Assert.assertEquals(new String(dequeuedBytes), testString);
+ assertEquals(new String(dequeuedBytes), testString);
}
@Test
@@ -87,7 +89,7 @@ public class DistributedQueueTest extends ClientBase {
queueHandles[0].offer(testString.getBytes());
byte[] dequeuedBytes = queueHandles[0].take();
- Assert.assertEquals(new String(dequeuedBytes), testString);
+ assertEquals(new String(dequeuedBytes), testString);
}
@Test
@@ -107,7 +109,7 @@ public class DistributedQueueTest extends ClientBase {
return;
}
- Assert.fail();
+ fail();
}
public void createNremoveMtest(String dir, int n, int m) throws Exception {
@@ -130,8 +132,8 @@ public class DistributedQueueTest extends ClientBase {
data = queueHandles[1].remove();
}
- Assert.assertNotNull(data);
- Assert.assertEquals(new String(data), testString + (m - 1));
+ assertNotNull(data);
+ assertEquals(new String(data), testString + (m - 1));
}
@Test
@@ -161,7 +163,7 @@ public class DistributedQueueTest extends ClientBase {
for (int i = 0; i < m; i++) {
queueHandles[1].remove();
}
- Assert.assertEquals(new String(queueHandles[1].element()), testString + m);
+ assertEquals(new String(queueHandles[1].element()), testString + m);
}
@Test
@@ -219,8 +221,8 @@ public class DistributedQueueTest extends ClientBase {
takeThread.join();
- Assert.assertNotNull(takeResult[0]);
- Assert.assertEquals(new String(takeResult[0]), testString);
+ assertNotNull(takeResult[0]);
+ assertEquals(new String(takeResult[0]), testString);
}
@Test
@@ -260,8 +262,8 @@ public class DistributedQueueTest extends ClientBase {
takeThread.join();
- Assert.assertNotNull(takeResult[0]);
- Assert.assertEquals(new String(takeResult[0]), threadTestString);
+ assertNotNull(takeResult[0]);
+ assertEquals(new String(takeResult[0]), threadTestString);
}
}