poolConfig = new GenericObjectPoolConfig<>();
JedisClientConfig masterConfig = DefaultJedisClientConfig.builder()
- .connectionTimeoutMillis(1000).socketTimeoutMillis(1000).database(2)
- .user("acljedis").password("fizzbuzz").build();
+ .connectionTimeoutMillis(1000).socketTimeoutMillis(1000).database(2).user("acljedis")
+ .password("fizzbuzz").build();
JedisClientConfig sentinelConfig = DefaultJedisClientConfig.builder()
- .connectionTimeoutMillis(1000).socketTimeoutMillis(1000)
- .user("sentinel").password("foobared").build();
+ .connectionTimeoutMillis(1000).socketTimeoutMillis(1000).user("sentinel")
+ .password("foobared").build();
- JedisSentinelPool pool = new JedisSentinelPool("wrongMasterName", sentinels, poolConfig, masterConfig, sentinelConfig);
- pool.getResource().close();
- pool.destroy();
+ assertThrows(JedisException.class, () -> {
+ try (JedisSentinelPool ignored = new JedisSentinelPool("wrongMasterName", sentinels, poolConfig,
+ masterConfig, sentinelConfig)) {
+ // do nothing
+ }
+ });
}
@Test
diff --git a/src/test/java/redis/clients/jedis/ACLJedisTest.java b/src/test/java/redis/clients/jedis/ACLJedisTest.java
index b9b35326e1..86378e55ae 100644
--- a/src/test/java/redis/clients/jedis/ACLJedisTest.java
+++ b/src/test/java/redis/clients/jedis/ACLJedisTest.java
@@ -1,35 +1,37 @@
package redis.clients.jedis;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static redis.clients.jedis.util.RedisVersionUtil.getRedisVersion;
import io.redis.test.utils.RedisVersion;
import java.net.URISyntaxException;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import redis.clients.jedis.commands.jedis.JedisCommandsTestBase;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedClass;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import redis.clients.jedis.commands.jedis.JedisCommandsTestBase;
/**
* This test class is a copy of {@link JedisTest}.
*
* This test is only executed when the server/cluster is Redis 6. or more.
*/
-@RunWith(Parameterized.class)
+@ParameterizedClass
+@MethodSource("redis.clients.jedis.commands.CommandsTestsParameters#respVersions")
public class ACLJedisTest extends JedisCommandsTestBase {
protected static final EndpointConfig endpoint = HostAndPorts.getRedisEndpoint("standalone0-acl");
/**
* Use to check if the ACL test should be ran. ACL are available only in 6.0 and later
- * @throws Exception
*/
- @BeforeClass
- public static void prepare() throws Exception {
- org.junit.Assume.assumeTrue("Not running ACL test on this version of Redis",
- getRedisVersion(endpoint).isGreaterThanOrEqualTo(RedisVersion.of("6.0.0")));
+ @BeforeAll
+ public static void prepare() {
+ assumeTrue(getRedisVersion(endpoint).isGreaterThanOrEqualTo(RedisVersion.of("6.0.0")),
+ "Not running ACL test on this version of Redis");
}
public ACLJedisTest(RedisProtocol redisProtocol) {
diff --git a/src/test/java/redis/clients/jedis/BuilderTest.java b/src/test/java/redis/clients/jedis/BuilderTest.java
index 4efdca7102..8076a181a5 100644
--- a/src/test/java/redis/clients/jedis/BuilderTest.java
+++ b/src/test/java/redis/clients/jedis/BuilderTest.java
@@ -1,9 +1,9 @@
package redis.clients.jedis;
-import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class BuilderTest {
@@ -20,9 +20,9 @@ public void buildDouble() {
try {
BuilderFactory.DOUBLE.build("".getBytes());
- Assert.fail("Empty String should throw NumberFormatException.");
+ Assertions.fail("Empty String should throw NumberFormatException.");
} catch (NumberFormatException expected) {
- Assert.assertEquals("empty String", expected.getMessage());
+ assertEquals("empty String", expected.getMessage());
}
}
}
diff --git a/src/test/java/redis/clients/jedis/ClusterCommandExecutorTest.java b/src/test/java/redis/clients/jedis/ClusterCommandExecutorTest.java
index 4601bf0b6f..d6437e84ea 100644
--- a/src/test/java/redis/clients/jedis/ClusterCommandExecutorTest.java
+++ b/src/test/java/redis/clients/jedis/ClusterCommandExecutorTest.java
@@ -1,8 +1,9 @@
package redis.clients.jedis;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -13,7 +14,7 @@
import java.util.function.LongConsumer;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.InOrder;
import org.mockito.Mockito;
@@ -192,7 +193,7 @@ public void runMovedThenAllNodesFailing() {
final Connection failer = mock(Connection.class);
when(connectionHandler.getConnection(ArgumentMatchers.any(HostAndPort.class))).thenReturn(failer);
- Mockito.doAnswer((Answer) (InvocationOnMock invocation) -> {
+ Mockito.doAnswer((InvocationOnMock invocation) -> {
when(connectionHandler.getConnection(STR_COM_OBJECT.getArguments())).thenReturn(failer);
return null;
}).when(connectionHandler).renewSlotCache();
@@ -260,7 +261,7 @@ public void runMasterFailingReplicaRecovering() {
when(connectionHandler.getConnection(STR_COM_OBJECT.getArguments())).thenReturn(master);
- Mockito.doAnswer((Answer) (InvocationOnMock invocation) -> {
+ Mockito.doAnswer((InvocationOnMock invocation) -> {
when(connectionHandler.getConnection(STR_COM_OBJECT.getArguments())).thenReturn(replica);
return null;
}).when(connectionHandler).renewSlotCache();
@@ -297,13 +298,14 @@ protected void sleep(long sleepMillis) {
MatcherAssert.assertThat(totalSleepMs.get(), Matchers.greaterThan(0L));
}
- @Test(expected = JedisClusterOperationException.class)
+ @Test
public void runRethrowsJedisNoReachableClusterNodeException() {
ClusterConnectionProvider connectionHandler = mock(ClusterConnectionProvider.class);
when(connectionHandler.getConnection(STR_COM_OBJECT.getArguments())).thenThrow(
- JedisClusterOperationException.class);
+ JedisClusterOperationException.class);
- ClusterCommandExecutor testMe = new ClusterCommandExecutor(connectionHandler, 10, Duration.ZERO) {
+ ClusterCommandExecutor testMe = new ClusterCommandExecutor(connectionHandler, 10,
+ Duration.ZERO) {
@Override
public T execute(Connection connection, CommandObject commandObject) {
return null;
@@ -315,7 +317,7 @@ protected void sleep(long ignored) {
}
};
- testMe.executeCommand(STR_COM_OBJECT);
+ assertThrows(JedisClusterOperationException.class, () -> testMe.executeCommand(STR_COM_OBJECT));
}
@Test
diff --git a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java
index e186702e81..0c6667d2f9 100644
--- a/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java
+++ b/src/test/java/redis/clients/jedis/ClusterPipeliningTest.java
@@ -2,19 +2,27 @@
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static redis.clients.jedis.Protocol.CLUSTER_HASHSLOTS;
import java.util.*;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import redis.clients.jedis.args.*;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.params.*;
@@ -44,7 +52,7 @@ public class ClusterPipeliningTest {
private static HostAndPort nodeInfo3 = HostAndPorts.getClusterServers().get(2);
private Set nodes = new HashSet<>(Arrays.asList(nodeInfo1, nodeInfo2, nodeInfo3));
- @BeforeClass
+ @BeforeAll
public static void setUp() throws InterruptedException {
node1 = new Jedis(nodeInfo1);
node1.auth("cluster");
@@ -84,21 +92,21 @@ public static void setUp() throws InterruptedException {
JedisClusterTestUtil.waitForClusterReady(node1, node2, node3);
}
- @Before
+ @BeforeEach
public void prepare() {
node1.flushAll();
node2.flushAll();
node3.flushAll();
}
- @After
+ @AfterEach
public void cleanUp() {
node1.flushDB();
node2.flushDB();
node3.flushDB();
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws InterruptedException {
node1.flushDB();
node2.flushDB();
@@ -355,12 +363,12 @@ private void verifyHasBothValues(byte[] firstKey, byte[] secondKey, byte[] value
assertTrue(Arrays.equals(secondKey, value1) || Arrays.equals(secondKey, value2));
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void pipelineResponseWithinPipeline() {
try (ClusterConnectionProvider provider = new ClusterConnectionProvider(nodes, DEFAULT_CLIENT_CONFIG)) {
ClusterPipeline p = new ClusterPipeline(provider);
Response string = p.get("string");
- string.get();
+ assertThrows(IllegalStateException.class,string::get);
p.sync();
}
}
@@ -893,9 +901,11 @@ public void testEvalKeyAndArg() {
try (ClusterConnectionProvider provider = new ClusterConnectionProvider(nodes, DEFAULT_CLIENT_CONFIG)) {
ClusterPipeline p = new ClusterPipeline(provider);
p.set(key, "0");
- Response