use of io.lettuce.core.ConnectionFuture in project LinkAgent by shulieTech.
the class LettuceDefaultConnectionMediator method getPreformanceClient.
public ConnectionFuture getPreformanceClient() {
if (isUpdate.compareAndSet(true, false)) {
ConnectionFuture dynamic = (ConnectionFuture) LettuceFactory.getFactory().dynamic(businessRedisClient);
performanceRedisClient = dynamic;
}
return performanceRedisClient;
}
use of io.lettuce.core.ConnectionFuture in project easeagent by megaease.
the class CommonRedisClientInterceptorTest method processRedisClient.
@Test
public void processRedisClient() throws SocketException {
CommonRedisClientInterceptor commonRedisClientInterceptor = new CommonRedisClientInterceptor();
RedisClient redisClient = RedisClient.create(RedisURI.create("127.0.0.1", 111));
DatagramSocket s = new DatagramSocket(0);
ConnectionFuture connectionFuture = ConnectionFuture.completed(new InetSocketAddress(s.getLocalPort()), "test");
MethodInfo methodInfo = MethodInfo.builder().invoker(redisClient).retValue(connectionFuture).build();
commonRedisClientInterceptor.processRedisClient(methodInfo, EaseAgent.getContext());
assertTrue(methodInfo.getRetValue() instanceof ConnectionFutureWrapper);
redisClient.shutdown();
}
use of io.lettuce.core.ConnectionFuture in project lettuce-core by lettuce-io.
the class PooledClusterConnectionProvider method getWriteConnection.
private CompletableFuture<StatefulRedisConnection<K, V>> getWriteConnection(int slot) {
// avoid races when reconfiguring partitions.
CompletableFuture<StatefulRedisConnection<K, V>> writer;
synchronized (stateLock) {
writer = writers[slot];
}
if (writer == null) {
RedisClusterNode partition = partitions.getPartitionBySlot(slot);
if (partition == null) {
clusterEventListener.onUncoveredSlot(slot);
return Futures.failed(new PartitionSelectorException("Cannot determine a partition for slot " + slot + ".", partitions.clone()));
}
// Use always host and port for slot-oriented operations. We don't want to get reconnected on a different
// host because the nodeId can be handled by a different host.
RedisURI uri = partition.getUri();
ConnectionKey key = new ConnectionKey(Intent.WRITE, uri.getHost(), uri.getPort());
ConnectionFuture<StatefulRedisConnection<K, V>> future = getConnectionAsync(key);
return future.thenApply(connection -> {
synchronized (stateLock) {
if (writers[slot] == null) {
writers[slot] = CompletableFuture.completedFuture(connection);
}
}
return connection;
}).toCompletableFuture();
}
return writer;
}
use of io.lettuce.core.ConnectionFuture in project easeagent by megaease.
the class ConnectionFutureWrapperTest method thenRunAsync.
@Test
public void thenRunAsync() throws ExecutionException, InterruptedException {
ConnectionFutureWrapper<DynamicFieldAccessorObj> connectionFutureWrapper = createOne();
AtomicBoolean ran = new AtomicBoolean(false);
ConnectionFuture connectionFuture = connectionFutureWrapper.thenRunAsync(() -> ran.set(true));
connectionFuture.get();
assertTrue(ran.get());
}
use of io.lettuce.core.ConnectionFuture in project easeagent by megaease.
the class CommonRedisClientInterceptorTest method doAfter.
@Test
public void doAfter() throws SocketException {
CommonRedisClientInterceptor commonRedisClientInterceptor = new CommonRedisClientInterceptor();
RedisClusterClient redisClusterClient = RedisClusterClient.create(RedisURI.create("127.0.0.1", 111));
MethodInfo methodInfo = MethodInfo.builder().invoker(redisClusterClient).retValue(null).throwable(new RuntimeException()).build();
commonRedisClientInterceptor.doAfter(methodInfo, EaseAgent.getContext());
assertNull(methodInfo.getRetValue());
CompletableFuture completableFuture = CompletableFuture.completedFuture("testCompletableFuture");
methodInfo = MethodInfo.builder().invoker(redisClusterClient).retValue(completableFuture).build();
commonRedisClientInterceptor.doAfter(methodInfo, EaseAgent.getContext());
assertTrue(methodInfo.getRetValue() instanceof CompletableFutureWrapper);
RedisClient redisClient = RedisClient.create(RedisURI.create("127.0.0.1", 111));
DatagramSocket s = new DatagramSocket(0);
ConnectionFuture connectionFuture = ConnectionFuture.completed(new InetSocketAddress(s.getLocalPort()), "test");
methodInfo = MethodInfo.builder().invoker(redisClient).retValue(connectionFuture).build();
commonRedisClientInterceptor.doAfter(methodInfo, EaseAgent.getContext());
assertTrue(methodInfo.getRetValue() instanceof ConnectionFutureWrapper);
redisClient.shutdown();
redisClusterClient.shutdown();
}
Aggregations