DATAREDIS-1122 - Add support for MAXLEN attribute of XADD.
Original pull request: #523.
This commit is contained in:
committed by
Mark Paluch
parent
3568f300f6
commit
43ef4700c1
@@ -46,6 +46,7 @@ import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
|
||||
import org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
@@ -2054,10 +2055,10 @@ public class DefaultStringRedisConnectionTests {
|
||||
Assertions.assertThat(getResults()).containsExactly(1L);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-864
|
||||
@Test // DATAREDIS-864, DATAREDIS-1122
|
||||
public void xAddShouldAppendRecordCorrectly() {
|
||||
|
||||
doReturn(RecordId.of("1-1")).when(nativeConnection).xAdd(any());
|
||||
doReturn(RecordId.of("1-1")).when(nativeConnection).xAdd(any(), eq(XAddOptions.none()));
|
||||
actual.add(connection
|
||||
.xAdd(StreamRecords.newRecord().in("stream-1").ofStrings(Collections.singletonMap("field", "value"))));
|
||||
|
||||
|
||||
@@ -19,23 +19,28 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import io.lettuce.core.RedisClient;
|
||||
import io.lettuce.core.XAddArgs;
|
||||
import io.lettuce.core.api.StatefulRedisConnection;
|
||||
import io.lettuce.core.api.async.RedisAsyncCommands;
|
||||
import io.lettuce.core.api.sync.RedisCommands;
|
||||
import io.lettuce.core.codec.RedisCodec;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionUnitTestBase;
|
||||
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
|
||||
import org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionUnitTestSuite.LettuceConnectionUnitTests;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionUnitTestSuite.LettucePipelineConnectionUnitTests;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -164,6 +169,19 @@ public class LettuceConnectionUnitTestSuite {
|
||||
assertThatThrownBy(() -> connection.set("foo".getBytes(), "bar".getBytes()))
|
||||
.hasMessageContaining(exception.getMessage()).hasRootCause(exception);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1122
|
||||
public void xaddShouldHonorMaxlen() {
|
||||
|
||||
MapRecord<byte[], byte[], byte[]> record = MapRecord.create("key".getBytes(),
|
||||
Collections.emptyMap());
|
||||
|
||||
connection.streamCommands().xAdd(record, XAddOptions.maxlen(100));
|
||||
ArgumentCaptor<XAddArgs> args = ArgumentCaptor.forClass(XAddArgs.class);
|
||||
verify(syncCommandsMock, times(1)).xadd(any(), args.capture(), anyMap());
|
||||
|
||||
assertThat(args.getValue()).extracting("maxlen").isEqualTo(100L);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LettucePipelineConnectionUnitTests extends LettuceConnectionUnitTests {
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import io.lettuce.core.RedisConnectionException;
|
||||
import io.lettuce.core.XAddArgs;
|
||||
import io.lettuce.core.api.StatefulConnection;
|
||||
import io.lettuce.core.api.StatefulRedisConnection;
|
||||
import io.lettuce.core.api.reactive.RedisReactiveCommands;
|
||||
@@ -26,6 +27,8 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -33,9 +36,13 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.data.redis.connection.ReactiveStreamCommands.AddStreamRecord;
|
||||
import org.springframework.data.redis.connection.stream.ByteBufferRecord;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LettuceReactiveRedisConnection}.
|
||||
@@ -214,4 +221,22 @@ public class LettuceReactiveRedisConnectionUnitTests {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().bgSave()).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1122
|
||||
public void xaddShouldHonorMaxlen() {
|
||||
|
||||
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(connectionProvider);
|
||||
|
||||
ArgumentCaptor<XAddArgs> args = ArgumentCaptor.forClass(XAddArgs.class);
|
||||
when(reactiveCommands.xadd(any(ByteBuffer.class), args.capture(), anyMap())).thenReturn(Mono.just("1-1"));
|
||||
|
||||
|
||||
MapRecord<ByteBuffer, ByteBuffer, ByteBuffer> record = MapRecord.create(ByteBuffer.wrap("key".getBytes()),
|
||||
Collections.emptyMap());
|
||||
|
||||
connection.streamCommands().xAdd(Mono.just(AddStreamRecord.of(ByteBufferRecord.of(record)).maxlen(100)))
|
||||
.subscribe();
|
||||
|
||||
assertThat(args.getValue()).extracting("maxlen").isEqualTo(100L);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user