Lambdas for Remaining Modules JPA -> ZK
Polishing - PR Comments and Closeable Warnings Eclipse emits bogus warnings with exceptions in lambdas. Even though the lambda might run on another thread, elipse thinks it could cause the context to not be closed. SPR-14854: MessageChannel is now a @FunctionalInterface * Additional Lambda polishing and some code style fixes
This commit is contained in:
committed by
Artem Bilan
parent
16be9fc47d
commit
67d6cd0c89
@@ -123,7 +123,6 @@ public class SubscribableRedisChannel extends AbstractMessageChannel
|
||||
return this.dispatcher.removeHandler(handler);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected boolean doSend(Message<?> message, long arg1) {
|
||||
this.redisTemplate.convertAndSend(this.topicName, this.messageConverter.fromMessage(message, Object.class));
|
||||
@@ -212,7 +211,11 @@ public class SubscribableRedisChannel extends AbstractMessageChannel
|
||||
|
||||
private class MessageListenerDelegate {
|
||||
|
||||
@SuppressWarnings({ "unused", "unchecked" })
|
||||
MessageListenerDelegate() {
|
||||
super();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unused" })
|
||||
public void handleMessage(Object payload) {
|
||||
Message<?> siMessage = SubscribableRedisChannel.this.messageConverter.toMessage(payload, null);
|
||||
try {
|
||||
|
||||
@@ -138,6 +138,10 @@ public class RedisInboundChannelAdapter extends MessageProducerSupport {
|
||||
|
||||
private class MessageListenerDelegate {
|
||||
|
||||
MessageListenerDelegate() {
|
||||
super();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void handleMessage(Object object) {
|
||||
sendMessage(convertMessage(object));
|
||||
|
||||
@@ -332,6 +332,10 @@ public class RedisQueueInboundGateway extends MessagingGatewaySupport implements
|
||||
|
||||
private class ListenerTask implements SchedulingAwareRunnable {
|
||||
|
||||
ListenerTask() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLongLived() {
|
||||
return true;
|
||||
|
||||
@@ -321,6 +321,10 @@ public class RedisQueueMessageDrivenEndpoint extends MessageProducerSupport impl
|
||||
|
||||
private class ListenerTask implements SchedulingAwareRunnable {
|
||||
|
||||
ListenerTask() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLongLived() {
|
||||
return true;
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.integration.redis.outbound;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -135,18 +133,16 @@ public class RedisOutboundGateway extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
final byte[][] actualArgs = args;
|
||||
|
||||
return this.redisTemplate.execute(new RedisCallback<Object>() {
|
||||
|
||||
@Override
|
||||
public Object doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.execute(command, actualArgs);
|
||||
}
|
||||
|
||||
});
|
||||
return this.redisTemplate.execute(
|
||||
(RedisCallback<Object>) connection -> connection.execute(command, actualArgs));
|
||||
}
|
||||
|
||||
private class PayloadArgumentsStrategy implements ArgumentsStrategy {
|
||||
|
||||
PayloadArgumentsStrategy() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] resolve(String command, Message<?> message) {
|
||||
Object payload = message.getPayload();
|
||||
|
||||
@@ -288,26 +288,20 @@ public class RedisStoreWritingMessageHandler extends AbstractMessageHandler {
|
||||
if (this.extractPayloadElements) {
|
||||
if ((payload instanceof Map<?, ?> && this.verifyAllMapValuesOfTypeNumber((Map<?, ?>) payload))) {
|
||||
final Map<Object, Number> payloadAsMap = (Map<Object, Number>) payload;
|
||||
this.processInPipeline(new PipelineCallback() {
|
||||
@Override
|
||||
public void process() {
|
||||
for (Entry<Object, Number> entry : payloadAsMap.entrySet()) {
|
||||
Number d = entry.getValue();
|
||||
incrementOrOverwrite(ops, entry.getKey(), d == null ?
|
||||
determineScore(message) :
|
||||
NumberUtils.convertNumberToTargetClass(d, Double.class),
|
||||
zsetIncrementHeader);
|
||||
}
|
||||
this.processInPipeline(() -> {
|
||||
for (Entry<Object, Number> entry : payloadAsMap.entrySet()) {
|
||||
Number d = entry.getValue();
|
||||
incrementOrOverwrite(ops, entry.getKey(), d == null ?
|
||||
determineScore(message) :
|
||||
NumberUtils.convertNumberToTargetClass(d, Double.class),
|
||||
zsetIncrementHeader);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (payload instanceof Collection<?>) {
|
||||
this.processInPipeline(new PipelineCallback() {
|
||||
@Override
|
||||
public void process() {
|
||||
for (Object object : ((Collection<?>) payload)) {
|
||||
incrementOrOverwrite(ops, object, determineScore(message), zsetIncrementHeader);
|
||||
}
|
||||
this.processInPipeline(() -> {
|
||||
for (Object object : ((Collection<?>) payload)) {
|
||||
incrementOrOverwrite(ops, object, determineScore(message), zsetIncrementHeader);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -350,12 +344,9 @@ public class RedisStoreWritingMessageHandler extends AbstractMessageHandler {
|
||||
final BoundSetOperations<String, Object> ops =
|
||||
(BoundSetOperations<String, Object>) this.redisTemplate.boundSetOps(set.getKey());
|
||||
|
||||
this.processInPipeline(new PipelineCallback() {
|
||||
@Override
|
||||
public void process() {
|
||||
for (Object object : ((Collection<?>) payload)) {
|
||||
ops.add(object);
|
||||
}
|
||||
this.processInPipeline(() -> {
|
||||
for (Object object : ((Collection<?>) payload)) {
|
||||
ops.add(object);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -368,12 +359,7 @@ public class RedisStoreWritingMessageHandler extends AbstractMessageHandler {
|
||||
private void writeToMap(final RedisMap<Object, Object> map, Message<?> message) {
|
||||
final Object payload = message.getPayload();
|
||||
if (this.extractPayloadElements && payload instanceof Map<?, ?>) {
|
||||
this.processInPipeline(new PipelineCallback() {
|
||||
@Override
|
||||
public void process() {
|
||||
map.putAll((Map<? extends Object, ? extends Object>) payload);
|
||||
}
|
||||
});
|
||||
this.processInPipeline(() -> map.putAll((Map<? extends Object, ? extends Object>) payload));
|
||||
}
|
||||
else {
|
||||
Object key = this.determineMapKey(message, false);
|
||||
@@ -384,12 +370,7 @@ public class RedisStoreWritingMessageHandler extends AbstractMessageHandler {
|
||||
private void writeToProperties(final RedisProperties properties, Message<?> message) {
|
||||
final Object payload = message.getPayload();
|
||||
if (this.extractPayloadElements && payload instanceof Properties) {
|
||||
this.processInPipeline(new PipelineCallback() {
|
||||
@Override
|
||||
public void process() {
|
||||
properties.putAll((Properties) payload);
|
||||
}
|
||||
});
|
||||
this.processInPipeline(() -> properties.putAll((Properties) payload));
|
||||
}
|
||||
else {
|
||||
Assert.isInstanceOf(String.class, payload, "For property, payload must be a String.");
|
||||
@@ -482,4 +463,5 @@ public class RedisStoreWritingMessageHandler extends AbstractMessageHandler {
|
||||
private interface PipelineCallback {
|
||||
void process();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,14 +47,7 @@ import org.springframework.util.Assert;
|
||||
public class RedisChannelPriorityMessageStore extends RedisChannelMessageStore
|
||||
implements PriorityCapableChannelMessageStore {
|
||||
|
||||
private final Comparator<String> keysComparator = new Comparator<String>() {
|
||||
|
||||
@Override
|
||||
public int compare(String s1, String s2) {
|
||||
return s2.compareTo(s1);
|
||||
}
|
||||
|
||||
};
|
||||
private final Comparator<String> keysComparator = (s1, s2) -> s2.compareTo(s1);
|
||||
|
||||
public RedisChannelPriorityMessageStore(RedisConnectionFactory connectionFactory) {
|
||||
super(connectionFactory);
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -32,13 +31,12 @@ import java.util.WeakHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.dao.CannotAcquireLockException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -153,7 +151,7 @@ public final class RedisLockRegistry implements LockRegistry {
|
||||
Assert.notNull(connectionFactory, "'connectionFactory' cannot be null");
|
||||
Assert.notNull(registryKey, "'registryKey' cannot be null");
|
||||
Assert.notNull(localRegistry, "'localRegistry' cannot be null");
|
||||
this.redisTemplate = new RedisTemplate<String, RedisLockRegistry.RedisLock>();
|
||||
this.redisTemplate = new RedisTemplate<>();
|
||||
this.redisTemplate.setConnectionFactory(connectionFactory);
|
||||
this.redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
this.redisTemplate.setValueSerializer(this.lockSerializer);
|
||||
@@ -198,7 +196,7 @@ public final class RedisLockRegistry implements LockRegistry {
|
||||
private Collection<RedisLock> getHardThreadLocks() {
|
||||
List<RedisLock> locks = this.hardThreadLocks.get();
|
||||
if (locks == null) {
|
||||
locks = new LinkedList<RedisLock>();
|
||||
locks = new LinkedList<>();
|
||||
this.hardThreadLocks.set(locks);
|
||||
}
|
||||
return locks;
|
||||
@@ -293,20 +291,15 @@ public final class RedisLockRegistry implements LockRegistry {
|
||||
}
|
||||
|
||||
public Collection<Lock> listLocks() {
|
||||
return this.redisTemplate.execute(new RedisCallback<Collection<Lock>>() {
|
||||
|
||||
@Override
|
||||
public Collection<Lock> doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
Set<byte[]> keys = connection.keys((RedisLockRegistry.this.registryKey + ":*").getBytes());
|
||||
ArrayList<Lock> list = new ArrayList<Lock>(keys.size());
|
||||
if (keys.size() > 0) {
|
||||
List<byte[]> locks = connection.mGet(keys.toArray(new byte[keys.size()][]));
|
||||
for (byte[] lock : locks) {
|
||||
list.add(RedisLockRegistry.this.lockSerializer.deserialize(lock));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return this.redisTemplate.execute((RedisCallback<Collection<Lock>>) connection -> {
|
||||
Set<byte[]> keys = connection.keys((RedisLockRegistry.this.registryKey + ":*").getBytes());
|
||||
if (keys.size() > 0) {
|
||||
List<byte[]> locks = connection.mGet(keys.toArray(new byte[keys.size()][]));
|
||||
return locks.stream()
|
||||
.map(RedisLockRegistry.this.lockSerializer::deserialize)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -324,7 +317,7 @@ public final class RedisLockRegistry implements LockRegistry {
|
||||
|
||||
private int reLock;
|
||||
|
||||
private RedisLock(String lockKey) {
|
||||
RedisLock(String lockKey) {
|
||||
this.lockKey = lockKey;
|
||||
this.lockHost = RedisLockRegistry.hostName;
|
||||
}
|
||||
@@ -420,30 +413,25 @@ public final class RedisLockRegistry implements LockRegistry {
|
||||
Boolean success = false;
|
||||
try {
|
||||
|
||||
success = RedisLockRegistry.this.redisTemplate.execute(new RedisCallback<Boolean>() {
|
||||
success = RedisLockRegistry.this.redisTemplate.execute((RedisCallback<Boolean>) connection -> {
|
||||
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
|
||||
/*
|
||||
Perform Redis command 'SET resource-name anystring NX EX max-lock-time' directly.
|
||||
As it is recommended by Redis: http://redis.io/commands/set.
|
||||
This command isn't supported directly by RedisTemplate.
|
||||
*/
|
||||
long expireAfter = TimeoutUtils.toSeconds(RedisLockRegistry.this.expireAfter,
|
||||
TimeUnit.MILLISECONDS);
|
||||
RedisSerializer<String> serializer = RedisLockRegistry.this.redisTemplate.getStringSerializer();
|
||||
byte[][] actualArgs = new byte[][] {
|
||||
serializer.serialize(constructLockKey()),
|
||||
RedisLockRegistry.this.lockSerializer.serialize(RedisLock.this),
|
||||
serializer.serialize("NX"),
|
||||
serializer.serialize("EX"),
|
||||
serializer.serialize(String.valueOf(expireAfter))
|
||||
};
|
||||
|
||||
return connection.execute("SET", actualArgs) != null;
|
||||
}
|
||||
/*
|
||||
Perform Redis command 'SET resource-name anystring NX EX max-lock-time' directly.
|
||||
As it is recommended by Redis: http://redis.io/commands/set.
|
||||
This command isn't supported directly by RedisTemplate.
|
||||
*/
|
||||
long expireAfter = TimeoutUtils.toSeconds(RedisLockRegistry.this.expireAfter,
|
||||
TimeUnit.MILLISECONDS);
|
||||
RedisSerializer<String> serializer = RedisLockRegistry.this.redisTemplate.getStringSerializer();
|
||||
byte[][] actualArgs = new byte[][] {
|
||||
serializer.serialize(constructLockKey()),
|
||||
RedisLockRegistry.this.lockSerializer.serialize(RedisLock.this),
|
||||
serializer.serialize("NX"),
|
||||
serializer.serialize("EX"),
|
||||
serializer.serialize(String.valueOf(expireAfter))
|
||||
};
|
||||
|
||||
return connection.execute("SET", actualArgs) != null;
|
||||
});
|
||||
}
|
||||
finally {
|
||||
@@ -603,6 +591,10 @@ public final class RedisLockRegistry implements LockRegistry {
|
||||
|
||||
private class LockSerializer implements RedisSerializer<RedisLock> {
|
||||
|
||||
LockSerializer() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize(RedisLock t) throws SerializationException {
|
||||
int hostLength = t.lockHost.length;
|
||||
|
||||
@@ -38,9 +38,7 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.integration.redis.rules.RedisAvailable;
|
||||
import org.springframework.integration.redis.rules.RedisAvailableTests;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
/**
|
||||
@@ -66,13 +64,7 @@ public class SubscribableRedisChannelTests extends RedisAvailableTests {
|
||||
RedisMessageListenerContainer.class));
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(3);
|
||||
MessageHandler handler = new MessageHandler() {
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
latch.countDown();
|
||||
}
|
||||
};
|
||||
MessageHandler handler = message -> latch.countDown();
|
||||
channel.subscribe(handler);
|
||||
|
||||
channel.send(new GenericMessage<String>("1"));
|
||||
|
||||
@@ -34,8 +34,6 @@ import org.springframework.integration.redis.rules.RedisAvailableTests;
|
||||
import org.springframework.integration.support.utils.IntegrationUtils;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
@@ -81,12 +79,9 @@ public class RedisChannelParserTests extends RedisAvailableTests {
|
||||
final Message<?> m = new GenericMessage<String>("Hello Redis");
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
redisChannel.subscribe(new MessageHandler() {
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
assertEquals(m.getPayload(), message.getPayload());
|
||||
latch.countDown();
|
||||
}
|
||||
redisChannel.subscribe(message -> {
|
||||
assertEquals(m.getPayload(), message.getPayload());
|
||||
latch.countDown();
|
||||
});
|
||||
redisChannel.send(m);
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
@@ -262,14 +261,7 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
|
||||
final CountDownLatch stopLatch = new CountDownLatch(1);
|
||||
|
||||
endpoint.stop(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
stopLatch.countDown();
|
||||
}
|
||||
|
||||
});
|
||||
endpoint.stop(() -> stopLatch.countDown());
|
||||
|
||||
executorService.shutdown();
|
||||
assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS));
|
||||
@@ -282,7 +274,6 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
@SuppressWarnings("unchecked")
|
||||
@Ignore("JedisConnectionFactory doesn't support proper 'destroy()' and allows to create new fresh Redis connection")
|
||||
public void testInt3196Recovery() throws Exception {
|
||||
String queueName = "test.si.Int3196Recovery";
|
||||
@@ -294,19 +285,9 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
|
||||
RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory);
|
||||
endpoint.setBeanFactory(Mockito.mock(BeanFactory.class));
|
||||
endpoint.setApplicationEventPublisher(new ApplicationEventPublisher() {
|
||||
|
||||
@Override
|
||||
public void publishEvent(ApplicationEvent event) {
|
||||
exceptionEvents.add(event);
|
||||
exceptionsLatch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishEvent(Object event) {
|
||||
|
||||
}
|
||||
|
||||
endpoint.setApplicationEventPublisher(event -> {
|
||||
exceptionEvents.add((ApplicationEvent) event);
|
||||
exceptionsLatch.countDown();
|
||||
});
|
||||
endpoint.setOutputChannel(channel);
|
||||
endpoint.setReceiveTimeout(100);
|
||||
|
||||
@@ -35,8 +35,6 @@ import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.redis.rules.RedisAvailable;
|
||||
import org.springframework.integration.redis.rules.RedisAvailableTests;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
|
||||
/**
|
||||
@@ -108,6 +106,7 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
context.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test
|
||||
@RedisAvailable
|
||||
// synchronization rollback renames the list
|
||||
@@ -120,14 +119,9 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
this.getClass());
|
||||
SubscribableChannel fail = context.getBean("redisFailChannel", SubscribableChannel.class);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
fail.subscribe(new MessageHandler() {
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
latch.countDown();
|
||||
throw new RuntimeException("Test Rollback");
|
||||
}
|
||||
|
||||
fail.subscribe(message -> {
|
||||
latch.countDown();
|
||||
throw new RuntimeException("Test Rollback");
|
||||
});
|
||||
SourcePollingChannelAdapter spca = context.getBean("listAdapterWithSynchronizationAndRollback",
|
||||
SourcePollingChannelAdapter.class);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class RedisPublishingMessageHandlerTests extends RedisAvailableTests {
|
||||
|
||||
private final CountDownLatch latch;
|
||||
|
||||
private Listener(CountDownLatch latch) {
|
||||
Listener(CountDownLatch latch) {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
|
||||
@@ -327,27 +327,19 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
executor = Executors.newCachedThreadPool();
|
||||
|
||||
executor.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
MessageGroup group = store1.addMessageToGroup(1, message);
|
||||
if (group.getMessages().size() != 1) {
|
||||
failures.add("ADD");
|
||||
throw new AssertionFailedError("Failed on ADD");
|
||||
}
|
||||
executor.execute(() -> {
|
||||
MessageGroup group = store1.addMessageToGroup(1, message);
|
||||
if (group.getMessages().size() != 1) {
|
||||
failures.add("ADD");
|
||||
throw new AssertionFailedError("Failed on ADD");
|
||||
}
|
||||
});
|
||||
executor.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
store2.removeMessagesFromGroup(1, message);
|
||||
MessageGroup group = store2.getMessageGroup(1);
|
||||
if (group.getMessages().size() != 0) {
|
||||
failures.add("REMOVE");
|
||||
throw new AssertionFailedError("Failed on Remove");
|
||||
}
|
||||
executor.execute(() -> {
|
||||
store2.removeMessagesFromGroup(1, message);
|
||||
MessageGroup group = store2.getMessageGroup(1);
|
||||
if (group.getMessages().size() != 0) {
|
||||
failures.add("REMOVE");
|
||||
throw new AssertionFailedError("Failed on Remove");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -131,17 +131,12 @@ public class AggregatorWithRedisLocksTests extends RedisAvailableTests {
|
||||
public void testDistributedAggregator() throws Exception {
|
||||
this.releaseStrategy.reset(1);
|
||||
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 1));
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
in2.send(new GenericMessage<String>("bar", stubHeaders(2, 2, 1)));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
exception = e;
|
||||
}
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
try {
|
||||
in2.send(new GenericMessage<String>("bar", stubHeaders(2, 2, 1)));
|
||||
}
|
||||
catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
});
|
||||
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
|
||||
@@ -162,17 +157,12 @@ public class AggregatorWithRedisLocksTests extends RedisAvailableTests {
|
||||
}
|
||||
|
||||
private Runnable asyncSend(final String payload, final int sequence, final int correlation) {
|
||||
return new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
in.send(new GenericMessage<String>(payload, stubHeaders(sequence, 2, correlation)));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
exception = e;
|
||||
}
|
||||
return () -> {
|
||||
try {
|
||||
in.send(new GenericMessage<String>(payload, stubHeaders(sequence, 2, correlation)));
|
||||
}
|
||||
catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -82,7 +81,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
}
|
||||
|
||||
private RedisTemplate<String, ?> createTemplate() {
|
||||
RedisTemplate<String, ?> template = new RedisTemplate<String, Object>();
|
||||
RedisTemplate<String, ?> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(this.getConnectionFactoryForTest());
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.afterPropertiesSet();
|
||||
@@ -206,21 +205,17 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
lock1.lockInterruptibly();
|
||||
final AtomicBoolean locked = new AtomicBoolean();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Future<Object> result = Executors.newSingleThreadExecutor().submit(new Callable<Object>() {
|
||||
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
locked.set(lock2.tryLock(200, TimeUnit.MILLISECONDS));
|
||||
latch.countDown();
|
||||
try {
|
||||
lock2.unlock();
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
return ise;
|
||||
}
|
||||
return null;
|
||||
Future<Object> result = Executors.newSingleThreadExecutor().submit(() -> {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
locked.set(lock2.tryLock(200, TimeUnit.MILLISECONDS));
|
||||
latch.countDown();
|
||||
try {
|
||||
lock2.unlock();
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
return ise;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertFalse(locked.get());
|
||||
@@ -242,25 +237,21 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
final CountDownLatch latch3 = new CountDownLatch(1);
|
||||
lock1.lockInterruptibly();
|
||||
assertNotNull(TestUtils.getPropertyValue(registry, "hardThreadLocks", ThreadLocal.class).get());
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
try {
|
||||
latch1.countDown();
|
||||
lock2.lockInterruptibly();
|
||||
assertNotNull(TestUtils.getPropertyValue(registry, "hardThreadLocks", ThreadLocal.class).get());
|
||||
latch2.await(10, TimeUnit.SECONDS);
|
||||
locked.set(true);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
finally {
|
||||
lock2.unlock();
|
||||
latch3.countDown();
|
||||
}
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
try {
|
||||
latch1.countDown();
|
||||
lock2.lockInterruptibly();
|
||||
assertNotNull(TestUtils.getPropertyValue(registry, "hardThreadLocks", ThreadLocal.class).get());
|
||||
latch2.await(10, TimeUnit.SECONDS);
|
||||
locked.set(true);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
finally {
|
||||
lock2.unlock();
|
||||
latch3.countDown();
|
||||
}
|
||||
});
|
||||
assertTrue(latch1.await(10, TimeUnit.SECONDS));
|
||||
@@ -284,31 +275,26 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
final CountDownLatch latch3 = new CountDownLatch(1);
|
||||
lock1.lockInterruptibly();
|
||||
assertNotNull(TestUtils.getPropertyValue(registry1, "hardThreadLocks", ThreadLocal.class).get());
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Lock lock2 = registry2.obtain("foo");
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
Lock lock2 = registry2.obtain("foo");
|
||||
try {
|
||||
latch1.countDown();
|
||||
lock2.lockInterruptibly();
|
||||
assertNotNull(TestUtils.getPropertyValue(registry2, "hardThreadLocks", ThreadLocal.class).get());
|
||||
latch2.await(10, TimeUnit.SECONDS);
|
||||
locked.set(true);
|
||||
}
|
||||
catch (InterruptedException e1) {
|
||||
Thread.currentThread().interrupt();
|
||||
logger.error("Interrupted while locking: " + lock2, e1);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
latch1.countDown();
|
||||
lock2.lockInterruptibly();
|
||||
assertNotNull(TestUtils.getPropertyValue(registry2, "hardThreadLocks", ThreadLocal.class).get());
|
||||
latch2.await(10, TimeUnit.SECONDS);
|
||||
locked.set(true);
|
||||
logger.debug("Locks in store: " + registry2.listLocks());
|
||||
lock2.unlock();
|
||||
latch3.countDown();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
logger.error("Interrupted while locking: " + lock2, e);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
lock2.unlock();
|
||||
latch3.countDown();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
logger.error("Failed to unlock: " + lock2, e);
|
||||
}
|
||||
catch (IllegalStateException e2) {
|
||||
logger.error("Failed to unlock: " + lock2, e2);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -330,19 +316,15 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
lock.lockInterruptibly();
|
||||
final AtomicBoolean locked = new AtomicBoolean();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Future<Object> result = Executors.newSingleThreadExecutor().submit(new Callable<Object>() {
|
||||
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
try {
|
||||
lock.unlock();
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
latch.countDown();
|
||||
return ise;
|
||||
}
|
||||
return null;
|
||||
Future<Object> result = Executors.newSingleThreadExecutor().submit(() -> {
|
||||
try {
|
||||
lock.unlock();
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
latch.countDown();
|
||||
return ise;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertFalse(locked.get());
|
||||
@@ -500,15 +482,10 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
|
||||
Long expire = getExpire(registry, "foo");
|
||||
|
||||
Future<Object> result = Executors.newSingleThreadExecutor().submit(new Callable<Object>() {
|
||||
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
assertFalse(lock2.tryLock());
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<Object> result = Executors.newSingleThreadExecutor().submit(() -> {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
assertFalse(lock2.tryLock());
|
||||
return null;
|
||||
});
|
||||
result.get();
|
||||
assertEquals(expire, getExpire(registry, "foo"));
|
||||
|
||||
Reference in New Issue
Block a user