Remove deprecated LettucePool and deprecated methods.
See: #2273 Original Pull Request: #2276
This commit is contained in:
committed by
Christoph Strobl
parent
f1d528ffef
commit
91cfbf5470
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import io.lettuce.core.RedisClient;
|
||||
import io.lettuce.core.RedisException;
|
||||
import io.lettuce.core.api.StatefulRedisConnection;
|
||||
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.test.condition.EnabledOnRedisAvailable;
|
||||
|
||||
/**
|
||||
* Integration test of {@link AuthenticatingRedisClient}.
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@EnabledOnRedisAvailable(6382)
|
||||
class AuthenticatingRedisClientTests {
|
||||
|
||||
private RedisClient client;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
client = new AuthenticatingRedisClient("localhost", 6382, "foobared");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
if (client != null) {
|
||||
client.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void connect() {
|
||||
StatefulRedisConnection<String, String> conn = client.connect();
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void connectWithInvalidPassword() {
|
||||
|
||||
if (client != null) {
|
||||
client.shutdown();
|
||||
}
|
||||
|
||||
RedisClient badClient = new AuthenticatingRedisClient("localhost", 6382, "notthepassword");
|
||||
Assertions.assertThatExceptionOfType(RedisException.class).isThrownBy(badClient::connect);
|
||||
badClient.shutdown(0, 0, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void codecConnect() {
|
||||
StatefulRedisConnection<byte[], byte[]> conn = client.connect(LettuceConnection.CODEC);
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void connectAsync() {
|
||||
StatefulRedisConnection<String, String> conn = client.connect();
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void codecConnectAsync() {
|
||||
StatefulRedisConnection<byte[], byte[]> conn = client.connect(LettuceConnection.CODEC);
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void connectPubSub() {
|
||||
StatefulRedisPubSubConnection<String, String> conn = client.connectPubSub();
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void codecConnectPubSub() {
|
||||
StatefulRedisPubSubConnection<byte[], byte[]> conn = client.connectPubSub(LettuceConnection.CODEC);
|
||||
conn.sync().ping();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.test.util.ReflectionTestUtils.*;
|
||||
|
||||
import io.lettuce.core.RedisException;
|
||||
import io.lettuce.core.RedisURI;
|
||||
import io.lettuce.core.api.StatefulRedisConnection;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.PoolException;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
|
||||
|
||||
/**
|
||||
* Unit test of {@link DefaultLettucePool}
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class DefaultLettucePoolTests {
|
||||
|
||||
private DefaultLettucePool pool;
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
|
||||
if (pool != null) {
|
||||
|
||||
if (pool.getClient() != null) {
|
||||
pool.getClient().shutdown(0, 0, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
pool.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetResource() {
|
||||
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertThat(client).isNotNull();
|
||||
client.sync().ping();
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetResourcePoolExhausted() {
|
||||
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setMaxTotal(1);
|
||||
poolConfig.setMaxWaitMillis(1);
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertThat(client).isNotNull();
|
||||
try {
|
||||
pool.getResource();
|
||||
fail("PoolException should be thrown when pool exhausted");
|
||||
} catch (PoolException e) {} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetResourceValidate() {
|
||||
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setTestOnBorrow(true);
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertThat(client).isNotNull();
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetResourceCreationUnsuccessful() throws Exception {
|
||||
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), 3333);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
assertThatExceptionOfType(PoolException.class).isThrownBy(() -> pool.getResource());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReturnResource() {
|
||||
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setMaxTotal(1);
|
||||
poolConfig.setMaxWaitMillis(1);
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertThat(client).isNotNull();
|
||||
pool.returnResource(client);
|
||||
assertThat(pool.getResource()).isNotNull();
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReturnBrokenResource() {
|
||||
|
||||
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
|
||||
poolConfig.setMaxTotal(1);
|
||||
poolConfig.setMaxWaitMillis(1);
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort(), poolConfig);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertThat(client).isNotNull();
|
||||
pool.returnBrokenResource(client);
|
||||
StatefulRedisConnection<byte[], byte[]> client2 = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
|
||||
assertThat(client2).isNotSameAs(client);
|
||||
try {
|
||||
client.sync().ping();
|
||||
fail("Broken resouce connection should be closed");
|
||||
} catch (RedisException e) {} finally {
|
||||
client.close();
|
||||
client2.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateWithDbIndex() {
|
||||
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.setDatabase(1);
|
||||
pool.afterPropertiesSet();
|
||||
assertThat(pool.getResource()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateWithDbIndexInvalid() {
|
||||
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.setDatabase(17);
|
||||
pool.afterPropertiesSet();
|
||||
assertThatExceptionOfType(PoolException.class).isThrownBy(() -> pool.getResource());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-524
|
||||
void testCreateSentinelWithPassword() {
|
||||
|
||||
pool = new DefaultLettucePool(new RedisSentinelConfiguration("mymaster", Collections.singleton("host:1234")));
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.setPassword("foo");
|
||||
pool.afterPropertiesSet();
|
||||
|
||||
RedisURI redisUri = (RedisURI) getField(pool.getClient(), "redisURI");
|
||||
|
||||
assertThat(redisUri.getPassword()).isEqualTo(pool.getPassword().toCharArray());
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-462
|
||||
void poolWorksWithoutClientResources() {
|
||||
|
||||
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setDatabase(1);
|
||||
pool.afterPropertiesSet();
|
||||
assertThat(pool.getResource()).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -300,23 +300,6 @@ class LettuceConnectionFactoryTests {
|
||||
assertThat(factory.getSharedConnection()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateFactoryWithPool() {
|
||||
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
|
||||
factory2.setShutdownTimeout(0);
|
||||
factory2.afterPropertiesSet();
|
||||
|
||||
ConnectionFactoryTracker.add(factory2);
|
||||
|
||||
RedisConnection conn2 = factory2.getConnection();
|
||||
conn2.close();
|
||||
factory2.destroy();
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-431
|
||||
void dbIndexShouldBePropagatedCorrectly() {
|
||||
|
||||
|
||||
@@ -17,13 +17,10 @@ package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import io.lettuce.core.api.async.RedisAsyncCommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@@ -121,48 +118,6 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
|
||||
} catch (RedisSystemException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClosePooledConnectionWithShared() {
|
||||
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
|
||||
factory2.setShutdownTimeout(0);
|
||||
factory2.afterPropertiesSet();
|
||||
RedisConnection connection = factory2.getConnection();
|
||||
// Use the connection to make sure the channel is initialized, else nothing happens on close
|
||||
connection.ping();
|
||||
connection.close();
|
||||
// The shared connection should not be closed
|
||||
connection.ping();
|
||||
|
||||
// The dedicated connection should not be closed b/c it's part of a pool
|
||||
connection.multi();
|
||||
connection.close();
|
||||
factory2.destroy();
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClosePooledConnectionNotShared() {
|
||||
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
|
||||
factory2.setShareNativeConnection(false);
|
||||
factory2.afterPropertiesSet();
|
||||
RedisConnection connection = factory2.getConnection();
|
||||
// Use the connection to make sure the channel is initialized, else nothing happens on close
|
||||
connection.ping();
|
||||
connection.close();
|
||||
// The dedicated connection should not be closed
|
||||
connection.ping();
|
||||
|
||||
connection.close();
|
||||
factory2.destroy();
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCloseNonPooledConnectionNotShared() {
|
||||
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
@@ -182,60 +137,6 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
|
||||
factory2.destroy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
void testCloseReturnBrokenResourceToPool() {
|
||||
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
|
||||
factory2.setShutdownTimeout(0);
|
||||
factory2.setShareNativeConnection(false);
|
||||
factory2.afterPropertiesSet();
|
||||
RedisConnection connection = factory2.getConnection();
|
||||
// Use the connection to make sure the channel is initialized, else nothing happens on close
|
||||
connection.ping();
|
||||
((RedisAsyncCommands) connection.getNativeConnection()).getStatefulConnection().close();
|
||||
try {
|
||||
connection.ping();
|
||||
fail("Exception should be thrown trying to use a closed connection");
|
||||
} catch (RedisSystemException e) {}
|
||||
connection.close();
|
||||
factory2.destroy();
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-1062
|
||||
void testSelectNotShared() {
|
||||
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(1);
|
||||
config.setMaxIdle(1);
|
||||
pool.setPoolConfig(config);
|
||||
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
|
||||
pool.afterPropertiesSet();
|
||||
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
|
||||
factory2.setDatabase(0);
|
||||
factory2.setShutdownTimeout(0);
|
||||
factory2.setShareNativeConnection(false);
|
||||
factory2.afterPropertiesSet();
|
||||
RedisConnection connection = factory2.getConnection();
|
||||
|
||||
connection.select(2);
|
||||
connection.rPush("key".getBytes(), "value1".getBytes(), "value2".getBytes());
|
||||
List<byte[]> bytes = connection.bLPop(1, "key".getBytes());
|
||||
assertThat(bytes).hasSize(2);
|
||||
connection.close();
|
||||
|
||||
connection = factory2.getConnection();
|
||||
assertThat(connection.lLen("key".getBytes())).isEqualTo(0);
|
||||
connection.select(2);
|
||||
assertThat(connection.lLen("key".getBytes())).isEqualTo(1);
|
||||
|
||||
factory2.destroy();
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelect() {
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> super.testSelect());
|
||||
|
||||
@@ -143,7 +143,7 @@ public class LettuceConnectionUnitTests {
|
||||
@Test // DATAREDIS-431
|
||||
void dbIndexShouldBeSetWhenObtainingConnection() {
|
||||
|
||||
connection = new LettuceConnection(null, 0, clientMock, null, 0);
|
||||
connection = new LettuceConnection(null, 0, clientMock, 0);
|
||||
connection.select(1);
|
||||
connection.getNativeConnection();
|
||||
|
||||
@@ -156,7 +156,7 @@ public class LettuceConnectionUnitTests {
|
||||
IllegalArgumentException exception = new IllegalArgumentException("Aw, snap!");
|
||||
|
||||
when(syncCommandsMock.set(any(), any())).thenThrow(exception);
|
||||
connection = new LettuceConnection(null, 0, clientMock, null, 1);
|
||||
connection = new LettuceConnection(null, 0, clientMock, 1);
|
||||
|
||||
assertThatThrownBy(() -> connection.set("foo".getBytes(), "bar".getBytes()))
|
||||
.hasMessageContaining(exception.getMessage()).hasRootCause(exception);
|
||||
@@ -168,7 +168,7 @@ public class LettuceConnectionUnitTests {
|
||||
IllegalArgumentException exception = new IllegalArgumentException("Aw, snap!");
|
||||
|
||||
when(asyncCommandsMock.set(any(byte[].class), any(byte[].class))).thenThrow(exception);
|
||||
connection = new LettuceConnection(null, 0, clientMock, null, 1);
|
||||
connection = new LettuceConnection(null, 0, clientMock, 1);
|
||||
connection.openPipeline();
|
||||
|
||||
assertThatThrownBy(() -> connection.set("foo".getBytes(), "bar".getBytes()))
|
||||
|
||||
Reference in New Issue
Block a user