Polishing.
Make sure nested LettuceConnectionUnitTests are actually run by junit. Original Pull Request: #2990
This commit is contained in:
@@ -15,10 +15,29 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.redis.connection.lettuce;
|
package org.springframework.data.redis.connection.lettuce;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
import static org.mockito.Mockito.any;
|
||||||
|
import static org.mockito.Mockito.anyMap;
|
||||||
|
import static org.mockito.Mockito.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 io.lettuce.core.*;
|
import io.lettuce.core.KeyScanCursor;
|
||||||
|
import io.lettuce.core.MapScanCursor;
|
||||||
|
import io.lettuce.core.RedisClient;
|
||||||
|
import io.lettuce.core.RedisFuture;
|
||||||
|
import io.lettuce.core.ScanArgs;
|
||||||
|
import io.lettuce.core.ScanCursor;
|
||||||
|
import io.lettuce.core.ScoredValue;
|
||||||
|
import io.lettuce.core.ScoredValueScanCursor;
|
||||||
|
import io.lettuce.core.ValueScanCursor;
|
||||||
|
import io.lettuce.core.XAddArgs;
|
||||||
|
import io.lettuce.core.XClaimArgs;
|
||||||
import io.lettuce.core.api.StatefulRedisConnection;
|
import io.lettuce.core.api.StatefulRedisConnection;
|
||||||
import io.lettuce.core.api.async.RedisAsyncCommands;
|
import io.lettuce.core.api.async.RedisAsyncCommands;
|
||||||
import io.lettuce.core.api.sync.RedisCommands;
|
import io.lettuce.core.api.sync.RedisCommands;
|
||||||
@@ -42,6 +61,7 @@ import java.util.Map.Entry;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@@ -60,43 +80,44 @@ import org.springframework.test.util.ReflectionTestUtils;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class LettuceConnectionUnitTests {
|
class LettuceConnectionUnitTests {
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
protected LettuceConnection connection;
|
||||||
public static class BasicUnitTests extends AbstractConnectionUnitTestBase<RedisAsyncCommands> {
|
private RedisClient clientMock;
|
||||||
|
StatefulRedisConnection<byte[], byte[]> statefulConnectionMock;
|
||||||
|
RedisAsyncCommands<byte[], byte[]> asyncCommandsMock;
|
||||||
|
RedisCommands<byte[], byte[]> commandsMock;
|
||||||
|
|
||||||
protected LettuceConnection connection;
|
@BeforeEach
|
||||||
private RedisClient clientMock;
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
StatefulRedisConnection<byte[], byte[]> statefulConnectionMock;
|
public void setUp() throws InvocationTargetException, IllegalAccessException {
|
||||||
RedisAsyncCommands<byte[], byte[]> asyncCommandsMock;
|
|
||||||
RedisCommands<byte[], byte[]> commandsMock;
|
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked" })
|
clientMock = mock(RedisClient.class);
|
||||||
@BeforeEach
|
statefulConnectionMock = mock(StatefulRedisConnection.class);
|
||||||
public void setUp() throws InvocationTargetException, IllegalAccessException {
|
when(clientMock.connect((RedisCodec) any())).thenReturn(statefulConnectionMock);
|
||||||
|
|
||||||
clientMock = mock(RedisClient.class);
|
asyncCommandsMock = Mockito.mock(RedisAsyncCommands.class, invocation -> {
|
||||||
statefulConnectionMock = mock(StatefulRedisConnection.class);
|
|
||||||
when(clientMock.connect((RedisCodec) any())).thenReturn(statefulConnectionMock);
|
|
||||||
|
|
||||||
asyncCommandsMock = Mockito.mock(RedisAsyncCommands.class, invocation -> {
|
if (invocation.getMethod().getReturnType().equals(RedisFuture.class)) {
|
||||||
|
|
||||||
if (invocation.getMethod().getReturnType().equals(RedisFuture.class)) {
|
Command<?, ?, ?> cmd = new Command<>(CommandType.PING, new StatusOutput<>(StringCodec.UTF8));
|
||||||
|
AsyncCommand<?, ?, ?> async = new AsyncCommand<>(cmd);
|
||||||
|
async.complete();
|
||||||
|
|
||||||
Command<?, ?, ?> cmd = new Command<>(CommandType.PING, new StatusOutput<>(StringCodec.UTF8));
|
return async;
|
||||||
AsyncCommand<?, ?, ?> async = new AsyncCommand<>(cmd);
|
}
|
||||||
async.complete();
|
return null;
|
||||||
|
});
|
||||||
|
commandsMock = Mockito.mock(RedisCommands.class);
|
||||||
|
|
||||||
return async;
|
when(statefulConnectionMock.async()).thenReturn(asyncCommandsMock);
|
||||||
}
|
when(statefulConnectionMock.sync()).thenReturn(commandsMock);
|
||||||
return null;
|
connection = new LettuceConnection(0, clientMock);
|
||||||
});
|
}
|
||||||
commandsMock = Mockito.mock(RedisCommands.class);
|
|
||||||
|
|
||||||
when(statefulConnectionMock.async()).thenReturn(asyncCommandsMock);
|
@Nested
|
||||||
when(statefulConnectionMock.sync()).thenReturn(commandsMock);
|
@SuppressWarnings({ "rawtypes", "deprecation" })
|
||||||
connection = new LettuceConnection(0, clientMock);
|
class BasicUnitTests extends AbstractConnectionUnitTestBase<RedisAsyncCommands> {
|
||||||
}
|
|
||||||
|
|
||||||
@Test // DATAREDIS-184
|
@Test // DATAREDIS-184
|
||||||
public void shutdownWithNullOptionsIsCalledCorrectly() {
|
public void shutdownWithNullOptionsIsCalledCorrectly() {
|
||||||
@@ -178,8 +199,7 @@ public class LettuceConnectionUnitTests {
|
|||||||
when(asyncCommandsMock.set(any(), any())).thenThrow(exception);
|
when(asyncCommandsMock.set(any(), any())).thenThrow(exception);
|
||||||
connection = new LettuceConnection(null, 0, clientMock, 1);
|
connection = new LettuceConnection(null, 0, clientMock, 1);
|
||||||
|
|
||||||
assertThatThrownBy(() -> connection.set("foo".getBytes(), "bar".getBytes()))
|
assertThatThrownBy(() -> connection.set("foo".getBytes(), "bar".getBytes())).hasRootCause(exception);
|
||||||
.hasRootCause(exception);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREDIS-603
|
@Test // DATAREDIS-603
|
||||||
@@ -270,8 +290,8 @@ public class LettuceConnectionUnitTests {
|
|||||||
sc.setCursor(cursorId);
|
sc.setCursor(cursorId);
|
||||||
sc.setFinished(false);
|
sc.setFinished(false);
|
||||||
|
|
||||||
Command<byte[], byte[], KeyScanCursor<byte[]>> command = new Command<>(new LettuceConnection.CustomCommandType("SCAN"),
|
Command<byte[], byte[], KeyScanCursor<byte[]>> command = new Command<>(
|
||||||
new ScanOutput<>(ByteArrayCodec.INSTANCE, sc) {
|
new LettuceConnection.CustomCommandType("SCAN"), new ScanOutput<>(ByteArrayCodec.INSTANCE, sc) {
|
||||||
@Override
|
@Override
|
||||||
protected void setOutput(ByteBuffer bytes) {
|
protected void setOutput(ByteBuffer bytes) {
|
||||||
|
|
||||||
@@ -280,10 +300,10 @@ public class LettuceConnectionUnitTests {
|
|||||||
AsyncCommand<byte[], byte[], KeyScanCursor<byte[]>> future = new AsyncCommand<>(command);
|
AsyncCommand<byte[], byte[], KeyScanCursor<byte[]>> future = new AsyncCommand<>(command);
|
||||||
future.complete();
|
future.complete();
|
||||||
|
|
||||||
when(asyncCommandsMock.scan(any(ScanCursor.class),any(ScanArgs.class))).thenReturn(future, future);
|
when(asyncCommandsMock.scan(any(ScanCursor.class), any(ScanArgs.class))).thenReturn(future, future);
|
||||||
|
|
||||||
Cursor<byte[]> cursor = connection.scan(KeyScanOptions.NONE);
|
Cursor<byte[]> cursor = connection.scan(KeyScanOptions.NONE);
|
||||||
cursor.next(); //initial
|
cursor.next(); // initial
|
||||||
assertThat(cursor.getCursorId()).isEqualTo(Long.parseUnsignedLong(cursorId));
|
assertThat(cursor.getCursorId()).isEqualTo(Long.parseUnsignedLong(cursorId));
|
||||||
|
|
||||||
cursor.next(); // fetch next
|
cursor.next(); // fetch next
|
||||||
@@ -305,8 +325,8 @@ public class LettuceConnectionUnitTests {
|
|||||||
sc.setCursor(cursorId);
|
sc.setCursor(cursorId);
|
||||||
sc.setFinished(false);
|
sc.setFinished(false);
|
||||||
|
|
||||||
Command<byte[], byte[], ValueScanCursor<byte[]>> command = new Command<>(new LettuceConnection.CustomCommandType("SSCAN"),
|
Command<byte[], byte[], ValueScanCursor<byte[]>> command = new Command<>(
|
||||||
new ScanOutput<>(ByteArrayCodec.INSTANCE, sc) {
|
new LettuceConnection.CustomCommandType("SSCAN"), new ScanOutput<>(ByteArrayCodec.INSTANCE, sc) {
|
||||||
@Override
|
@Override
|
||||||
protected void setOutput(ByteBuffer bytes) {
|
protected void setOutput(ByteBuffer bytes) {
|
||||||
|
|
||||||
@@ -315,10 +335,11 @@ public class LettuceConnectionUnitTests {
|
|||||||
AsyncCommand<byte[], byte[], ValueScanCursor<byte[]>> future = new AsyncCommand<>(command);
|
AsyncCommand<byte[], byte[], ValueScanCursor<byte[]>> future = new AsyncCommand<>(command);
|
||||||
future.complete();
|
future.complete();
|
||||||
|
|
||||||
when(asyncCommandsMock.sscan(any(byte[].class), any(ScanCursor.class),any(ScanArgs.class))).thenReturn(future, future);
|
when(asyncCommandsMock.sscan(any(byte[].class), any(ScanCursor.class), any(ScanArgs.class))).thenReturn(future,
|
||||||
|
future);
|
||||||
|
|
||||||
Cursor<byte[]> cursor = connection.setCommands().sScan("key".getBytes(), KeyScanOptions.NONE);
|
Cursor<byte[]> cursor = connection.setCommands().sScan("key".getBytes(), KeyScanOptions.NONE);
|
||||||
cursor.next(); //initial
|
cursor.next(); // initial
|
||||||
assertThat(cursor.getCursorId()).isEqualTo(Long.parseUnsignedLong(cursorId));
|
assertThat(cursor.getCursorId()).isEqualTo(Long.parseUnsignedLong(cursorId));
|
||||||
|
|
||||||
cursor.next(); // fetch next
|
cursor.next(); // fetch next
|
||||||
@@ -340,8 +361,8 @@ public class LettuceConnectionUnitTests {
|
|||||||
sc.setCursor(cursorId);
|
sc.setCursor(cursorId);
|
||||||
sc.setFinished(false);
|
sc.setFinished(false);
|
||||||
|
|
||||||
Command<byte[], byte[], ScoredValueScanCursor<byte[]>> command = new Command<>(new LettuceConnection.CustomCommandType("ZSCAN"),
|
Command<byte[], byte[], ScoredValueScanCursor<byte[]>> command = new Command<>(
|
||||||
new ScanOutput<>(ByteArrayCodec.INSTANCE, sc) {
|
new LettuceConnection.CustomCommandType("ZSCAN"), new ScanOutput<>(ByteArrayCodec.INSTANCE, sc) {
|
||||||
@Override
|
@Override
|
||||||
protected void setOutput(ByteBuffer bytes) {
|
protected void setOutput(ByteBuffer bytes) {
|
||||||
|
|
||||||
@@ -350,10 +371,11 @@ public class LettuceConnectionUnitTests {
|
|||||||
AsyncCommand<byte[], byte[], ScoredValueScanCursor<byte[]>> future = new AsyncCommand<>(command);
|
AsyncCommand<byte[], byte[], ScoredValueScanCursor<byte[]>> future = new AsyncCommand<>(command);
|
||||||
future.complete();
|
future.complete();
|
||||||
|
|
||||||
when(asyncCommandsMock.zscan(any(byte[].class), any(ScanCursor.class),any(ScanArgs.class))).thenReturn(future, future);
|
when(asyncCommandsMock.zscan(any(byte[].class), any(ScanCursor.class), any(ScanArgs.class))).thenReturn(future,
|
||||||
|
future);
|
||||||
|
|
||||||
Cursor<Tuple> cursor = connection.zSetCommands().zScan("key".getBytes(), KeyScanOptions.NONE);
|
Cursor<Tuple> cursor = connection.zSetCommands().zScan("key".getBytes(), KeyScanOptions.NONE);
|
||||||
cursor.next(); //initial
|
cursor.next(); // initial
|
||||||
assertThat(cursor.getCursorId()).isEqualTo(Long.parseUnsignedLong(cursorId));
|
assertThat(cursor.getCursorId()).isEqualTo(Long.parseUnsignedLong(cursorId));
|
||||||
|
|
||||||
cursor.next(); // fetch next
|
cursor.next(); // fetch next
|
||||||
@@ -375,8 +397,8 @@ public class LettuceConnectionUnitTests {
|
|||||||
sc.setCursor(cursorId);
|
sc.setCursor(cursorId);
|
||||||
sc.setFinished(false);
|
sc.setFinished(false);
|
||||||
|
|
||||||
Command<byte[], byte[], MapScanCursor<byte[], byte[]>> command = new Command<>(new LettuceConnection.CustomCommandType("HSCAN"),
|
Command<byte[], byte[], MapScanCursor<byte[], byte[]>> command = new Command<>(
|
||||||
new ScanOutput<>(ByteArrayCodec.INSTANCE, sc) {
|
new LettuceConnection.CustomCommandType("HSCAN"), new ScanOutput<>(ByteArrayCodec.INSTANCE, sc) {
|
||||||
@Override
|
@Override
|
||||||
protected void setOutput(ByteBuffer bytes) {
|
protected void setOutput(ByteBuffer bytes) {
|
||||||
|
|
||||||
@@ -385,10 +407,11 @@ public class LettuceConnectionUnitTests {
|
|||||||
AsyncCommand<byte[], byte[], MapScanCursor<byte[], byte[]>> future = new AsyncCommand<>(command);
|
AsyncCommand<byte[], byte[], MapScanCursor<byte[], byte[]>> future = new AsyncCommand<>(command);
|
||||||
future.complete();
|
future.complete();
|
||||||
|
|
||||||
when(asyncCommandsMock.hscan(any(byte[].class), any(ScanCursor.class),any(ScanArgs.class))).thenReturn(future, future);
|
when(asyncCommandsMock.hscan(any(byte[].class), any(ScanCursor.class), any(ScanArgs.class))).thenReturn(future,
|
||||||
|
future);
|
||||||
|
|
||||||
Cursor<Entry<byte[], byte[]>> cursor = connection.hashCommands().hScan("key".getBytes(), KeyScanOptions.NONE);
|
Cursor<Entry<byte[], byte[]>> cursor = connection.hashCommands().hScan("key".getBytes(), KeyScanOptions.NONE);
|
||||||
cursor.next(); //initial
|
cursor.next(); // initial
|
||||||
assertThat(cursor.getCursorId()).isEqualTo(Long.parseUnsignedLong(cursorId));
|
assertThat(cursor.getCursorId()).isEqualTo(Long.parseUnsignedLong(cursorId));
|
||||||
|
|
||||||
cursor.next(); // fetch next
|
cursor.next(); // fetch next
|
||||||
@@ -399,13 +422,12 @@ public class LettuceConnectionUnitTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LettucePipelineConnectionUnitTests extends BasicUnitTests {
|
@Nested
|
||||||
|
class LettucePipelineConnectionUnitTests extends BasicUnitTests {
|
||||||
|
|
||||||
@Override
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws InvocationTargetException, IllegalAccessException {
|
public void setUp() throws InvocationTargetException, IllegalAccessException {
|
||||||
super.setUp();
|
connection.openPipeline();
|
||||||
this.connection.openPipeline();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAREDIS-528
|
@Test // DATAREDIS-528
|
||||||
|
|||||||
Reference in New Issue
Block a user