From 91cfbf5470452b943062e4e5b9cf7cc02f8d96f3 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 22 Feb 2022 15:02:49 +0100 Subject: [PATCH] Remove deprecated LettucePool and deprecated methods. See: #2273 Original Pull Request: #2276 --- .../lettuce/AuthenticatingRedisClient.java | 52 --- .../lettuce/DefaultLettucePool.java | 371 ------------------ .../lettuce/LettuceClusterConnection.java | 2 +- .../connection/lettuce/LettuceConnection.java | 88 +---- .../lettuce/LettuceConnectionFactory.java | 22 +- .../connection/lettuce/LettuceConverters.java | 197 +--------- .../lettuce/LettuceExceptionConverter.java | 2 + .../lettuce/LettuceFutureUtils.java | 2 +- .../redis/connection/lettuce/LettucePool.java | 41 -- .../LettuceReactiveRedisConnection.java | 2 +- .../lettuce/LettuceSentinelConnection.java | 2 +- .../AuthenticatingRedisClientTests.java | 110 ------ .../lettuce/DefaultLettucePoolTests.java | 195 --------- .../LettuceConnectionFactoryTests.java | 17 - .../LettuceConnectionIntegrationTests.java | 99 ----- .../lettuce/LettuceConnectionUnitTests.java | 6 +- 16 files changed, 18 insertions(+), 1190 deletions(-) delete mode 100644 src/main/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClient.java delete mode 100644 src/main/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePool.java delete mode 100644 src/main/java/org/springframework/data/redis/connection/lettuce/LettucePool.java delete mode 100644 src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java delete mode 100644 src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClient.java b/src/main/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClient.java deleted file mode 100644 index b52890493..000000000 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClient.java +++ /dev/null @@ -1,52 +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.RedisURI; -import io.lettuce.core.api.StatefulRedisConnection; -import io.lettuce.core.codec.RedisCodec; -import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; - -/** - * Extension of {@link RedisClient} that calls auth on all new connections using the supplied credentials - * - * @author Jennifer Hickey - * @author Mark Paluch - * @author Christoph Strobl - * @deprecated since 1.6 - Please use {@link RedisURI#setPassword(String)} - */ -@Deprecated -public class AuthenticatingRedisClient extends RedisClient { - - public AuthenticatingRedisClient(String host, int port, String password) { - super(null, RedisURI.builder().withHost(host).withPort(port).withPassword(password).build()); - } - - public AuthenticatingRedisClient(String host, String password) { - super(null, RedisURI.builder().withHost(host).withPassword(password).build()); - } - - @Override - public StatefulRedisConnection connect(RedisCodec codec) { - return super.connect(codec); - } - - @Override - public StatefulRedisPubSubConnection connectPubSub(RedisCodec codec) { - return super.connectPubSub(codec); - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePool.java b/src/main/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePool.java deleted file mode 100644 index 9b9dc3995..000000000 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePool.java +++ /dev/null @@ -1,371 +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.RedisURI; -import io.lettuce.core.api.StatefulConnection; -import io.lettuce.core.api.StatefulRedisConnection; -import io.lettuce.core.resource.ClientResources; - -import java.time.Duration; - -import org.apache.commons.pool2.BasePooledObjectFactory; -import org.apache.commons.pool2.PooledObject; -import org.apache.commons.pool2.impl.DefaultPooledObject; -import org.apache.commons.pool2.impl.GenericObjectPool; -import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.data.redis.connection.PoolException; -import org.springframework.data.redis.connection.RedisSentinelConfiguration; -import org.springframework.lang.Nullable; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * Default implementation of {@link LettucePool}. - * - * @author Jennifer Hickey - * @author Christoph Strobl - * @author Mark Paluch - * @deprecated since 2.0, use pooling via {@link LettucePoolingClientConfiguration}. - */ -@Deprecated -public class DefaultLettucePool implements LettucePool, InitializingBean { - - @SuppressWarnings("rawtypes") // - private @Nullable GenericObjectPool> internalPool; - private @Nullable RedisClient client; - private int dbIndex = 0; - private GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); - private String hostName = "localhost"; - private int port = 6379; - private @Nullable String password; - private long timeout = Duration.ofMinutes(1).toMillis(); - private @Nullable RedisSentinelConfiguration sentinelConfiguration; - private @Nullable ClientResources clientResources; - - /** - * Constructs a new DefaultLettucePool instance with default settings. - */ - public DefaultLettucePool() {} - - /** - * Uses the {@link GenericObjectPoolConfig} defaults for configuring the connection pool - * - * @param hostName The Redis host - * @param port The Redis port - */ - public DefaultLettucePool(String hostName, int port) { - this.hostName = hostName; - this.port = port; - } - - /** - * Uses the {@link RedisSentinelConfiguration} and {@link RedisClient} defaults for configuring the connection pool - * based on sentinels. - * - * @param sentinelConfiguration The Sentinel configuration - * @since 1.6 - */ - public DefaultLettucePool(RedisSentinelConfiguration sentinelConfiguration) { - this.sentinelConfiguration = sentinelConfiguration; - } - - /** - * Uses the {@link RedisClient} defaults for configuring the connection pool - * - * @param hostName The Redis host - * @param port The Redis port - * @param poolConfig The pool {@link GenericObjectPoolConfig} - */ - public DefaultLettucePool(String hostName, int port, GenericObjectPoolConfig poolConfig) { - this.hostName = hostName; - this.port = port; - this.poolConfig = poolConfig; - } - - /** - * @return true when {@link RedisSentinelConfiguration} is present. - * @since 1.6 - */ - public boolean isRedisSentinelAware() { - return sentinelConfiguration != null; - } - - @SuppressWarnings({ "rawtypes" }) - public void afterPropertiesSet() { - - if (clientResources != null) { - this.client = RedisClient.create(clientResources, getRedisURI()); - } else { - this.client = RedisClient.create(getRedisURI()); - } - - client.setDefaultTimeout(Duration.ofMillis(timeout)); - this.internalPool = new GenericObjectPool<>(new LettuceFactory(client, dbIndex), poolConfig); - } - - /** - * @return a RedisURI pointing either to a single Redis host or containing a set of sentinels. - */ - private RedisURI getRedisURI() { - - RedisURI redisUri = isRedisSentinelAware() - ? LettuceConverters.sentinelConfigurationToRedisURI(sentinelConfiguration) : createSimpleHostRedisURI(); - - if (StringUtils.hasText(password)) { - redisUri.setPassword(password); - } - - return redisUri; - } - - private RedisURI createSimpleHostRedisURI() { - return RedisURI.Builder.redis(hostName, port).withTimeout(Duration.ofMillis(timeout)).build(); - } - - @Override - @SuppressWarnings("unchecked") - public StatefulConnection getResource() { - try { - return internalPool.borrowObject(); - } catch (Exception e) { - throw new PoolException("Could not get a resource from the pool", e); - } - } - - @Override - public void returnBrokenResource(final StatefulConnection resource) { - - try { - internalPool.invalidateObject(resource); - } catch (Exception e) { - throw new PoolException("Could not invalidate the broken resource", e); - } - } - - @Override - public void returnResource(final StatefulConnection resource) { - - try { - internalPool.returnObject(resource); - } catch (Exception e) { - throw new PoolException("Could not return the resource to the pool", e); - } - } - - @Override - public void destroy() { - - try { - client.shutdown(); - internalPool.close(); - } catch (Exception e) { - throw new PoolException("Could not destroy the pool", e); - } - } - - /** - * @return The Redis client - */ - @Override - @Nullable - public RedisClient getClient() { - return client; - } - - /** - * @return The pool configuration - */ - public GenericObjectPoolConfig getPoolConfig() { - return poolConfig; - } - - /** - * @param poolConfig The pool configuration to use - */ - public void setPoolConfig(GenericObjectPoolConfig poolConfig) { - this.poolConfig = poolConfig; - } - - /** - * Returns the index of the database. - * - * @return Returns the database index - */ - public int getDatabase() { - return dbIndex; - } - - /** - * Sets the index of the database used by this connection pool. Default is 0. - * - * @param index database index - */ - public void setDatabase(int index) { - Assert.isTrue(index >= 0, "invalid DB index (a positive index required)"); - this.dbIndex = index; - } - - /** - * Returns the password used for authenticating with the Redis server. - * - * @return password for authentication - */ - @Nullable - public String getPassword() { - return password; - } - - /** - * Sets the password used for authenticating with the Redis server. - * - * @param password the password to set - */ - public void setPassword(String password) { - this.password = password; - } - - /** - * Returns the current host. - * - * @return the host - */ - public String getHostName() { - return hostName; - } - - /** - * Sets the host. - * - * @param host the host to set - */ - public void setHostName(String host) { - this.hostName = host; - } - - /** - * Returns the current port. - * - * @return the port - */ - public int getPort() { - return port; - } - - /** - * Sets the port. - * - * @param port the port to set - */ - public void setPort(int port) { - this.port = port; - } - - /** - * Returns the connection timeout (in milliseconds). - * - * @return connection timeout - */ - public long getTimeout() { - return timeout; - } - - /** - * Sets the connection timeout (in milliseconds). - * - * @param timeout connection timeout - */ - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - /** - * Get the {@link ClientResources} to reuse infrastructure. - * - * @return {@literal null} if not set. - * @since 1.7 - */ - @Nullable - public ClientResources getClientResources() { - return clientResources; - } - - /** - * Sets the {@link ClientResources} to reuse the client infrastructure.
- * Set to {@literal null} to not share resources. - * - * @param clientResources can be {@literal null}. - * @since 1.7 - */ - public void setClientResources(ClientResources clientResources) { - this.clientResources = clientResources; - } - - @SuppressWarnings("rawtypes") - private static class LettuceFactory extends BasePooledObjectFactory> { - - private final RedisClient client; - - private int dbIndex; - - public LettuceFactory(RedisClient client, int dbIndex) { - super(); - this.client = client; - this.dbIndex = dbIndex; - } - - @Override - public void activateObject(PooledObject> pooledObject) throws Exception { - - if (pooledObject.getObject() instanceof StatefulRedisConnection) { - ((StatefulRedisConnection) pooledObject.getObject()).sync().select(dbIndex); - } - } - - @Override - public void destroyObject(final PooledObject> obj) throws Exception { - try { - obj.getObject().close(); - } catch (Exception e) { - // Errors may happen if returning a broken resource - } - } - - @Override - public boolean validateObject(final PooledObject> obj) { - try { - if (obj.getObject() instanceof StatefulRedisConnection) { - ((StatefulRedisConnection) obj.getObject()).sync().ping(); - } - return true; - } catch (Exception e) { - return false; - } - } - - @Override - public StatefulConnection create() throws Exception { - return client.connect(LettuceConnection.CODEC); - } - - @Override - public PooledObject> wrap(StatefulConnection obj) { - return new DefaultPooledObject<>(obj); - } - } -} diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java index b4b4ffd71..eb858bd37 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java @@ -61,7 +61,7 @@ import org.springframework.util.ObjectUtils; public class LettuceClusterConnection extends LettuceConnection implements DefaultedRedisClusterConnection { static final ExceptionTranslationStrategy exceptionConverter = new PassThroughExceptionTranslationStrategy( - new LettuceExceptionConverter()); + LettuceExceptionConverter.INSTANCE); private final Log log = LogFactory.getLog(getClass()); diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index f40539b59..b34c95933 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -49,7 +49,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Queue; -import java.util.concurrent.CompletionStage; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -93,7 +92,7 @@ public class LettuceConnection extends AbstractRedisConnection { static final RedisCodec CODEC = ByteArrayCodec.INSTANCE; private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy( - LettuceConverters.exceptionConverter()); + LettuceExceptionConverter.INSTANCE); private static final TypeHints typeHints = new TypeHints(); private final int defaultDbIndex; @@ -161,20 +160,7 @@ public class LettuceConnection extends AbstractRedisConnection { * @param client The {@link RedisClient} to use when instantiating a native connection */ public LettuceConnection(long timeout, RedisClient client) { - this(null, timeout, client, null); - } - - /** - * Instantiates a new lettuce connection. - * - * @param timeout The connection timeout (in milliseconds) * @param client The {@link RedisClient} to use when - * instantiating a pub/sub connection - * @param pool The connection pool to use for all other native connections - * @deprecated since 2.0, use pooling via {@link LettucePoolingClientConfiguration}. - */ - @Deprecated - public LettuceConnection(long timeout, RedisClient client, LettucePool pool) { - this(null, timeout, client, pool); + this(null, timeout, client); } /** @@ -187,25 +173,7 @@ public class LettuceConnection extends AbstractRedisConnection { */ public LettuceConnection(@Nullable StatefulRedisConnection sharedConnection, long timeout, RedisClient client) { - this(sharedConnection, timeout, client, null); - } - - /** - * Instantiates a new lettuce connection. - * - * @param sharedConnection A native connection that is shared with other {@link LettuceConnection}s. Should not be - * used for transactions or blocking operations - * @param timeout The connection timeout (in milliseconds) - * @param client The {@link RedisClient} to use when making pub/sub connections - * @param pool The connection pool to use for blocking and tx operations - * @deprecated since 2.0, use - * {@link #LettuceConnection(StatefulRedisConnection, LettuceConnectionProvider, long, int)} - */ - @Deprecated - public LettuceConnection(@Nullable StatefulRedisConnection sharedConnection, long timeout, - RedisClient client, @Nullable LettucePool pool) { - - this(sharedConnection, timeout, client, pool, 0); + this(sharedConnection, timeout, client, 0); } /** @@ -213,22 +181,13 @@ public class LettuceConnection extends AbstractRedisConnection { * used for transactions or blocking operations. * @param timeout The connection timeout (in milliseconds) * @param client The {@link RedisClient} to use when making pub/sub connections. - * @param pool The connection pool to use for blocking and tx operations. * @param defaultDbIndex The db index to use along with {@link RedisClient} when establishing a dedicated connection. * @since 1.7 - * @deprecated since 2.0, use - * {@link #LettuceConnection(StatefulRedisConnection, LettuceConnectionProvider, long, int)} */ - @Deprecated public LettuceConnection(@Nullable StatefulRedisConnection sharedConnection, long timeout, - @Nullable AbstractRedisClient client, @Nullable LettucePool pool, int defaultDbIndex) { - - if (pool != null) { - this.connectionProvider = new LettucePoolConnectionProvider(pool); - } else { - this.connectionProvider = new StandaloneConnectionProvider((RedisClient) client, CODEC); - } + @Nullable AbstractRedisClient client, int defaultDbIndex) { + this.connectionProvider = new StandaloneConnectionProvider((RedisClient) client, CODEC); this.asyncSharedConn = sharedConnection; this.timeout = timeout; this.defaultDbIndex = defaultDbIndex; @@ -1248,43 +1207,6 @@ public class LettuceConnection extends AbstractRedisConnection { } } - static class LettucePoolConnectionProvider implements LettuceConnectionProvider { - - private final LettucePool pool; - - LettucePoolConnectionProvider(LettucePool pool) { - this.pool = pool; - } - - @Override - public > T getConnection(Class connectionType) { - return connectionType.cast(pool.getResource()); - } - - @Override - public > CompletionStage getConnectionAsync(Class connectionType) { - throw new UnsupportedOperationException("Async operations not supported!"); - } - - @Override - @SuppressWarnings("unchecked") - public void release(StatefulConnection connection) { - - if (connection.isOpen()) { - - if (connection instanceof StatefulRedisConnection) { - StatefulRedisConnection redisConnection = (StatefulRedisConnection) connection; - if (redisConnection.isMulti()) { - redisConnection.async().discard(); - } - } - pool.returnResource((StatefulConnection) connection); - } else { - pool.returnBrokenResource((StatefulConnection) connection); - } - } - } - /** * Strategy interface to control pipelining flush behavior. Lettuce writes (flushes) each command individually to the * Redis connection. Flushing behavior can be customized to optimize for performance. Flushing can be either stateless diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java index 796e63812..e84bcc244 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java @@ -104,7 +104,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory, ReactiveRedisConnectionFactory { private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new PassThroughExceptionTranslationStrategy( - LettuceConverters.exceptionConverter()); + LettuceExceptionConverter.INSTANCE); private final Log log = LogFactory.getLog(getClass()); private final LettuceClientConfiguration clientConfiguration; @@ -117,7 +117,6 @@ public class LettuceConnectionFactory private boolean eagerInitialization = false; private @Nullable SharedConnection connection; private @Nullable SharedConnection reactiveConnection; - private @Nullable LettucePool pool; /** Synchronization monitor for the shared Connection */ private final Object connectionMonitor = new Object(); private boolean convertPipelineAndTxResults = true; @@ -198,17 +197,6 @@ public class LettuceConnectionFactory this(clusterConfiguration, new MutableLettuceClientConfiguration()); } - /** - * @param pool - * @deprecated since 2.0, use pooling via {@link LettucePoolingClientConfiguration}. - */ - @Deprecated - public LettuceConnectionFactory(LettucePool pool) { - - this(new MutableLettuceClientConfiguration()); - this.pool = pool; - } - /** * Constructs a new {@link LettuceConnectionFactory} instance using the given {@link RedisStandaloneConfiguration} and * {@link LettuceClientConfiguration}. @@ -405,8 +393,8 @@ public class LettuceConnectionFactory return getClusterConnection(); } - LettuceConnection connection; - connection = doCreateLettuceConnection(getSharedConnection(), connectionProvider, getTimeout(), getDatabase()); + LettuceConnection connection = doCreateLettuceConnection(getSharedConnection(), connectionProvider, getTimeout(), + getDatabase()); connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults); return connection; } @@ -1095,10 +1083,6 @@ public class LettuceConnectionFactory private LettuceConnectionProvider createConnectionProvider(AbstractRedisClient client, RedisCodec codec) { - if (this.pool != null) { - return new LettucePoolConnectionProvider(this.pool); - } - LettuceConnectionProvider connectionProvider = doCreateConnectionProvider(client, codec); if (this.clientConfiguration instanceof LettucePoolingClientConfiguration) { diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java index 5b64dd096..633ca3ae7 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java @@ -22,14 +22,12 @@ import io.lettuce.core.*; import io.lettuce.core.cluster.models.partitions.Partitions; import io.lettuce.core.cluster.models.partitions.RedisClusterNode.NodeFlag; -import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.springframework.core.convert.converter.Converter; -import org.springframework.dao.DataAccessException; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResult; import org.springframework.data.geo.GeoResults; @@ -53,7 +51,6 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundar import org.springframework.data.redis.connection.RedisZSetCommands.Tuple; import org.springframework.data.redis.connection.SortParameters.Order; import org.springframework.data.redis.connection.convert.Converters; -import org.springframework.data.redis.connection.convert.ListConverter; import org.springframework.data.redis.connection.convert.LongToBooleanConverter; import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter; import org.springframework.data.redis.core.KeyScanOptions; @@ -65,7 +62,6 @@ import org.springframework.data.redis.domain.geo.BoxShape; import org.springframework.data.redis.domain.geo.GeoReference; import org.springframework.data.redis.domain.geo.GeoShape; import org.springframework.data.redis.domain.geo.RadiusShape; -import org.springframework.data.redis.util.ByteUtils; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -84,12 +80,9 @@ import org.springframework.util.StringUtils; * @author Chris Bono * @author Vikas Garg */ +@SuppressWarnings("ConstantConditions") public abstract class LettuceConverters extends Converters { - private static final Converter EXCEPTION_CONVERTER = new LettuceExceptionConverter(); - private static final ListConverter GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER; - private static final ListConverter, Object> KEY_VALUE_LIST_UNWRAPPER; - public static final byte[] PLUS_BYTES; public static final byte[] MINUS_BYTES; public static final byte[] POSITIVE_INFINITY_BYTES; @@ -104,31 +97,6 @@ public abstract class LettuceConverters extends Converters { MINUS_BYTES = toBytes("-"); POSITIVE_INFINITY_BYTES = toBytes("+inf"); NEGATIVE_INFINITY_BYTES = toBytes("-inf"); - - GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER = new ListConverter<>(LettuceConverters::geoCoordinatesToPoint); - - KEY_VALUE_LIST_UNWRAPPER = new ListConverter<>(source -> source.getValueOrElse(null)); - } - - @Deprecated - public static List toTuple(List source) { - - if (CollectionUtils.isEmpty(source)) { - return Collections.emptyList(); - } - - List tuples = new ArrayList<>(); - Iterator it = source.iterator(); - while (it.hasNext()) { - tuples.add(new DefaultTuple(it.next(), it.hasNext() ? Double.valueOf(toString(it.next())) : null)); - } - - return tuples; - } - - @Deprecated - public static Converter, List> bytesListToTupleListConverter() { - return LettuceConverters::toTuple; } public static Point geoCoordinatesToPoint(@Nullable GeoCoordinates geoCoordinate) { @@ -140,41 +108,6 @@ public abstract class LettuceConverters extends Converters { return LettuceConverters::toListOfRedisClientInformation; } - @Deprecated - public static Converter dateToLong() { - return LettuceConverters::toLong; - } - - @Deprecated - public static Converter, Set> bytesListToBytesSet() { - return LettuceConverters::toBytesSet; - } - - @Deprecated - public static Converter bytesToString() { - return LettuceConverters::toString; - } - - @Deprecated - public static Converter, List> keyValueToBytesList() { - return LettuceConverters::toBytesList; - } - - @Deprecated - public static Converter, List> bytesSetToBytesList() { - return LettuceConverters::toBytesList; - } - - @Deprecated - public static Converter, List> bytesCollectionToBytesList() { - return LettuceConverters::toBytesList; - } - - @Deprecated - public static Converter>, Set> scoredValuesToTupleSet() { - return LettuceConverters::toTupleSet; - } - public static Converter>, List> scoredValuesToTupleList() { return source -> { @@ -189,16 +122,6 @@ public abstract class LettuceConverters extends Converters { }; } - @Deprecated - public static Converter, Tuple> scoredValueToTuple() { - return LettuceConverters::toTuple; - } - - @Deprecated - public static Converter exceptionConverter() { - return EXCEPTION_CONVERTER; - } - /** * @return * @sice 1.3 @@ -234,18 +157,6 @@ public abstract class LettuceConverters extends Converters { return source != null ? new ArrayList<>(source) : null; } - @Deprecated - public static Set toTupleSet(@Nullable List> source) { - if (source == null) { - return null; - } - Set tuples = new LinkedHashSet<>(source.size()); - for (ScoredValue value : source) { - tuples.add(LettuceConverters.toTuple(value)); - } - return tuples; - } - public static Tuple toTuple(@Nullable ScoredValue source) { return source != null && source.hasValue() ? new DefaultTuple(source.getValue(), Double.valueOf(source.getScore())) : null; @@ -300,11 +211,6 @@ public abstract class LettuceConverters extends Converters { return target; } - @Deprecated - public static Converter, Map> bytesListToMapConverter() { - return LettuceConverters::toMap; - } - public static SortArgs toSortArgs(SortParameters params) { SortArgs args = new SortArgs(); @@ -346,28 +252,6 @@ public abstract class LettuceConverters extends Converters { return StringToRedisClientInfoConverter.INSTANCE.convert(clientList.split("\\r?\\n")); } - @Deprecated - public static byte[][] subarray(byte[][] input, int index) { - - if (input.length > index) { - byte[][] output = new byte[input.length - index][]; - System.arraycopy(input, index, output, 0, output.length); - return output; - } - - return null; - } - - @Deprecated - public static String boundaryToStringForZRange(Boundary boundary, String defaultValue) { - - if (boundary == null || boundary.getValue() == null) { - return defaultValue; - } - - return boundaryToString(boundary, "", "("); - } - private static String boundaryToString(Boundary boundary, String inclPrefix, String exclPrefix) { String prefix = boundary.isIncluding() ? inclPrefix : exclPrefix; @@ -639,66 +523,6 @@ public abstract class LettuceConverters extends Converters { return toBytes(String.valueOf(source)); } - /** - * Converts a given {@link Boundary} to its binary representation suitable for {@literal ZRANGEBY*} commands, despite - * {@literal ZRANGEBYLEX}. - * - * @param boundary - * @param defaultValue - * @return - * @since 1.6 - */ - @Deprecated - public static String boundaryToBytesForZRange(Boundary boundary, byte[] defaultValue) { - - if (boundary == null || boundary.getValue() == null) { - return toString(defaultValue); - } - - return boundaryToBytes(boundary, new byte[] {}, toBytes("(")); - } - - /** - * Converts a given {@link Boundary} to its binary representation suitable for ZRANGEBYLEX command. - * - * @param boundary - * @return - * @since 1.6 - */ - @Deprecated - public static String boundaryToBytesForZRangeByLex(Boundary boundary, byte[] defaultValue) { - - if (boundary == null || boundary.getValue() == null) { - return toString(defaultValue); - } - - return boundaryToBytes(boundary, toBytes("["), toBytes("(")); - } - - private static String boundaryToBytes(Boundary boundary, byte[] inclPrefix, byte[] exclPrefix) { - - byte[] prefix = boundary.isIncluding() ? inclPrefix : exclPrefix; - byte[] value = null; - if (boundary.getValue() instanceof byte[]) { - value = (byte[]) boundary.getValue(); - } else if (boundary.getValue() instanceof Double) { - value = toBytes((Double) boundary.getValue()); - } else if (boundary.getValue() instanceof Long) { - value = toBytes((Long) boundary.getValue()); - } else if (boundary.getValue() instanceof Integer) { - value = toBytes((Integer) boundary.getValue()); - } else if (boundary.getValue() instanceof String) { - value = toBytes((String) boundary.getValue()); - } else { - throw new IllegalArgumentException(String.format("Cannot convert %s to binary format", boundary.getValue())); - } - - ByteBuffer buffer = ByteBuffer.allocate(prefix.length + value.length); - buffer.put(prefix); - buffer.put(value); - return toString(ByteUtils.getBytes(buffer)); - } - public static List partitionsToClusterNodes(@Nullable Partitions source) { if (source == null) { @@ -1050,25 +874,6 @@ public abstract class LettuceConverters extends Converters { return GeoResultsConverterFactory.INSTANCE.forMetric(metric); } - /** - * @return - * @since 1.8 - */ - @Deprecated - public static ListConverter geoCoordinatesToPointConverter() { - return GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER; - } - - /** - * @return - * @since 2.0 - */ - @SuppressWarnings("unchecked") - @Deprecated - public static ListConverter, V> keyValueListUnwrapper() { - return (ListConverter) KEY_VALUE_LIST_UNWRAPPER; - } - public static Converter> transactionResultUnwrapper() { return transactionResult -> transactionResult.stream().collect(Collectors.toList()); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceExceptionConverter.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceExceptionConverter.java index 7d636a292..c4a9e4095 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceExceptionConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceExceptionConverter.java @@ -40,6 +40,8 @@ import org.springframework.data.redis.RedisSystemException; */ public class LettuceExceptionConverter implements Converter { + static final LettuceExceptionConverter INSTANCE = new LettuceExceptionConverter(); + public DataAccessException convert(Exception ex) { if (ex instanceof ExecutionException || ex instanceof RedisCommandExecutionException) { diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceFutureUtils.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceFutureUtils.java index 99cad3730..784fe6253 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceFutureUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceFutureUtils.java @@ -71,7 +71,7 @@ class LettuceFutureUtils { Throwable exceptionToUse = e; if (e instanceof CompletionException) { - exceptionToUse = new LettuceExceptionConverter().convert((Exception) e.getCause()); + exceptionToUse = LettuceExceptionConverter.INSTANCE.convert((Exception) e.getCause()); if (exceptionToUse == null) { exceptionToUse = e.getCause(); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePool.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePool.java deleted file mode 100644 index af41bfbac..000000000 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePool.java +++ /dev/null @@ -1,41 +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.AbstractRedisClient; -import io.lettuce.core.api.StatefulConnection; - -import org.springframework.data.redis.connection.Pool; -import org.springframework.lang.Nullable; - -/** - * Pool of Lettuce {@link StatefulConnection}s - * - * @author Jennifer Hickey - * @author Christoph Strobl - * @author Mark Paluch - * @deprecated since 2.0, use pooling via {@link LettucePoolingClientConfiguration}. - */ -@Deprecated -public interface LettucePool extends Pool> { - - /** - * @return The {@link AbstractRedisClient} used to create pooled connections - */ - @Nullable - AbstractRedisClient getClient(); - -} diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisConnection.java index 59073020f..c4bf04f07 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisConnection.java @@ -229,7 +229,7 @@ class LettuceReactiveRedisConnection implements ReactiveRedisConnection { if (throwable instanceof RuntimeException) { - DataAccessException convertedException = LettuceConverters.exceptionConverter() + DataAccessException convertedException = LettuceExceptionConverter.INSTANCE .convert((RuntimeException) throwable); return convertedException != null ? convertedException : throwable; } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java index 39a534ad8..85cdb59a9 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnection.java @@ -44,7 +44,7 @@ import org.springframework.util.Assert; public class LettuceSentinelConnection implements RedisSentinelConnection { private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy( - LettuceConverters.exceptionConverter()); + LettuceExceptionConverter.INSTANCE); private final LettuceConnectionProvider provider; private StatefulRedisSentinelConnection connection; // no that should not be null diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java deleted file mode 100644 index d61b278cb..000000000 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java +++ /dev/null @@ -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 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 conn = client.connect(LettuceConnection.CODEC); - conn.sync().ping(); - conn.close(); - } - - @Test - void connectAsync() { - StatefulRedisConnection conn = client.connect(); - conn.sync().ping(); - conn.close(); - } - - @Test - void codecConnectAsync() { - StatefulRedisConnection conn = client.connect(LettuceConnection.CODEC); - conn.sync().ping(); - conn.close(); - } - - @Test - void connectPubSub() { - StatefulRedisPubSubConnection conn = client.connectPubSub(); - conn.sync().ping(); - conn.close(); - } - - @Test - void codecConnectPubSub() { - StatefulRedisPubSubConnection conn = client.connectPubSub(LettuceConnection.CODEC); - conn.sync().ping(); - conn.close(); - } - -} diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java deleted file mode 100644 index 0b087aeb1..000000000 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java +++ /dev/null @@ -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 client = (StatefulRedisConnection) 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 client = (StatefulRedisConnection) 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 client = (StatefulRedisConnection) 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 client = (StatefulRedisConnection) 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 client = (StatefulRedisConnection) pool.getResource(); - assertThat(client).isNotNull(); - pool.returnBrokenResource(client); - StatefulRedisConnection client2 = (StatefulRedisConnection) 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(); - } -} diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java index 530aa4cec..77f328ffe 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java @@ -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() { diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java index d36536a7a..f1c90e671 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java @@ -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 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()); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionUnitTests.java index 41bd3fd2a..37940512e 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionUnitTests.java @@ -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()))