Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* @author Yordan Tsintsov
* @author Tihomir Mateev
* @author Tiefang Hu
* @author Dongliang Xie
* @since 2.0
*/
@NullUnmarked
Expand Down Expand Up @@ -411,16 +412,12 @@ public void restore(byte @NonNull [] key, long ttlInMillis, byte @NonNull [] ser
if (replace) {

connection.invokeStatus().just(KeyBinaryCommands::restore, KeyPipelineBinaryCommands::restore, key,
(int) ttlInMillis, serializedValue, RestoreParams.restoreParams().replace());
ttlInMillis, serializedValue, RestoreParams.restoreParams().replace());
return;
}

if (ttlInMillis > Integer.MAX_VALUE) {
throw new IllegalArgumentException("TtlInMillis must be less than Integer.MAX_VALUE for restore in Jedis");
}

connection.invokeStatus().just(KeyBinaryCommands::restore, KeyPipelineBinaryCommands::restore, key,
(int) ttlInMillis, serializedValue);
ttlInMillis, serializedValue);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.ArgumentCaptor;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
Expand All @@ -47,6 +49,7 @@
* @author Christoph Strobl
* @author Tihomir Mateev
* @author Tiefang Hu
* @author Dongliang Xie
*/
class JedisConnectionUnitTests {

Expand All @@ -70,6 +73,23 @@ void pSubscribeShouldBeRejectedBetweenWatchAndMulti() {
.isThrownBy(() -> connection.pSubscribe(listener, "channel-*".getBytes()));
}

@ParameterizedTest // GH-3386
@ValueSource(booleans = { false, true })
@SuppressWarnings("unchecked")
void restoreShouldPassLongTtlToJedis(boolean replace) {

Connection nativeConnection = mock(Connection.class);
JedisConnection connection = new JedisConnection(new Jedis(nativeConnection));
long ttlInMillis = (long) Integer.MAX_VALUE + 1L;

connection.restore("foo".getBytes(), ttlInMillis, "bar".getBytes(), replace);

ArgumentCaptor<CommandObject<?>> captor = ArgumentCaptor.forClass(CommandObject.class);
verify(nativeConnection).executeCommand(captor.capture());
assertThat(captor.getValue().getArguments())
.anyMatch(it -> new String(it.getRaw()).equals(Long.toString(ttlInMillis)));
}

private static JedisConnection watchOnlyConnection() {

UnifiedJedis jedis = mock(UnifiedJedis.class);
Expand Down Expand Up @@ -201,12 +221,6 @@ void shouldThrowExceptionWhenAccessingRedisSentinelsCommandsWhenNoSentinelsConfi
.isThrownBy(() -> connection.getSentinelConnection());
}

@Test // DATAREDIS-472
void restoreShouldThrowExceptionWhenTtlInMillisExceedsIntegerRange() {
assertThatIllegalArgumentException()
.isThrownBy(() -> connection.restore("foo".getBytes(), (long) Integer.MAX_VALUE + 1L, "bar".getBytes()));
}

@Test // DATAREDIS-472
void setExShouldThrowExceptionWhenTimeExceedsIntegerRange() {
assertThatIllegalArgumentException()
Expand Down
Loading