Migrate tests to AssertJ
Mostly thanks to IDEA's plugin: https://plugins.jetbrains.com/plugin/10345-assertions2assertj There is still a lot of work to do when complex and composite matchers are used. * Add `awaitility` dependency and deprecate `EventuallyMatcher` in favor of `awaitility` * Remove Hamcrest from dependencies and disable JUnit & Hamcrest static imports to encourage to use only AssertJ * Migrate JUnit assumptions in rules to AssertJ's assumptions * Deprecate some custom matchers in favor of existing in Hamcrest after upgrading the last to version `2.1` * Replace `ExpectedException` rules with `assertThatThrownBy()` * Mention `MessagePredicate` in the `testing.adoc`
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -16,11 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.channel;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -41,6 +38,7 @@ import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
@@ -70,7 +68,7 @@ public class SubscribableRedisChannelTests extends RedisAvailableTests {
|
||||
channel.send(new GenericMessage<String>("1"));
|
||||
channel.send(new GenericMessage<String>("2"));
|
||||
channel.send(new GenericMessage<String>("3"));
|
||||
assertTrue(latch.await(20, TimeUnit.SECONDS));
|
||||
assertThat(latch.await(20, TimeUnit.SECONDS)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,10 +95,12 @@ public class SubscribableRedisChannelTests extends RedisAvailableTests {
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
Throwable cause = e.getCause();
|
||||
assertNotNull(cause);
|
||||
assertThat(cause.getMessage(),
|
||||
containsString("Dispatcher has no subscribers for redis-channel 'si.test.channel.no.subs' (dhnsChannel)."));
|
||||
assertThat(cause).isNotNull();
|
||||
assertThat(cause.getMessage())
|
||||
.contains("Dispatcher has no subscribers for redis-channel 'si.test.channel.no.subs' (dhnsChannel)" +
|
||||
".");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -79,16 +77,18 @@ public class RedisChannelParserTests extends RedisAvailableTests {
|
||||
RedisConnectionFactory connectionFactory =
|
||||
TestUtils.getPropertyValue(this.redisChannel, "connectionFactory", RedisConnectionFactory.class);
|
||||
RedisSerializer<?> redisSerializer = TestUtils.getPropertyValue(redisChannel, "serializer", RedisSerializer.class);
|
||||
assertEquals(connectionFactory, this.context.getBean("redisConnectionFactory"));
|
||||
assertEquals(redisSerializer, this.context.getBean("redisSerializer"));
|
||||
assertEquals("si.test.topic.parser", TestUtils.getPropertyValue(redisChannel, "topicName"));
|
||||
assertEquals(Integer.MAX_VALUE, TestUtils.getPropertyValue(
|
||||
TestUtils.getPropertyValue(this.redisChannel, "dispatcher"), "maxSubscribers", Integer.class).intValue());
|
||||
assertThat(this.context.getBean("redisConnectionFactory")).isEqualTo(connectionFactory);
|
||||
assertThat(this.context.getBean("redisSerializer")).isEqualTo(redisSerializer);
|
||||
assertThat(TestUtils.getPropertyValue(redisChannel, "topicName")).isEqualTo("si.test.topic.parser");
|
||||
assertThat(TestUtils.getPropertyValue(
|
||||
TestUtils.getPropertyValue(this.redisChannel, "dispatcher"), "maxSubscribers", Integer.class)
|
||||
.intValue()).isEqualTo(Integer.MAX_VALUE);
|
||||
|
||||
assertEquals(1,
|
||||
TestUtils.getPropertyValue(this.redisChannelWithSubLimit, "dispatcher.maxSubscribers", Integer.class).intValue());
|
||||
assertThat(TestUtils.getPropertyValue(this.redisChannelWithSubLimit, "dispatcher.maxSubscribers",
|
||||
Integer.class)
|
||||
.intValue()).isEqualTo(1);
|
||||
Object mbf = this.context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
|
||||
assertSame(mbf, TestUtils.getPropertyValue(this.redisChannelWithSubLimit, "messageBuilderFactory"));
|
||||
assertThat(TestUtils.getPropertyValue(this.redisChannelWithSubLimit, "messageBuilderFactory")).isSameAs(mbf);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,13 +101,13 @@ public class RedisChannelParserTests extends RedisAvailableTests {
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
this.redisChannel.subscribe(message -> {
|
||||
assertEquals(m.getPayload(), message.getPayload());
|
||||
assertThat(message.getPayload()).isEqualTo(m.getPayload());
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
this.redisChannel.send(m);
|
||||
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -16,15 +16,10 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -74,22 +69,22 @@ public class RedisInboundChannelAdapterParserTests extends RedisAvailableTests {
|
||||
@Test
|
||||
public void validateConfiguration() {
|
||||
RedisInboundChannelAdapter adapter = context.getBean("adapter", RedisInboundChannelAdapter.class);
|
||||
assertEquals("adapter", adapter.getComponentName());
|
||||
assertEquals("redis:inbound-channel-adapter", adapter.getComponentType());
|
||||
assertThat(adapter.getComponentName()).isEqualTo("adapter");
|
||||
assertThat(adapter.getComponentType()).isEqualTo("redis:inbound-channel-adapter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
|
||||
Object errorChannelBean = context.getBean("testErrorChannel");
|
||||
assertEquals(errorChannelBean, accessor.getPropertyValue("errorChannel"));
|
||||
assertThat(accessor.getPropertyValue("errorChannel")).isEqualTo(errorChannelBean);
|
||||
Object converterBean = context.getBean("testConverter");
|
||||
assertEquals(converterBean, accessor.getPropertyValue("messageConverter"));
|
||||
assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer"));
|
||||
assertThat(accessor.getPropertyValue("messageConverter")).isEqualTo(converterBean);
|
||||
assertThat(accessor.getPropertyValue("serializer")).isEqualTo(context.getBean("serializer"));
|
||||
|
||||
Object container = accessor.getPropertyValue("container");
|
||||
DirectFieldAccessor containerAccessor = new DirectFieldAccessor(container);
|
||||
assertSame(this.executor, containerAccessor.getPropertyValue("taskExecutor"));
|
||||
assertThat(containerAccessor.getPropertyValue("taskExecutor")).isSameAs(this.executor);
|
||||
|
||||
Object bean = context.getBean("withoutSerializer.adapter");
|
||||
assertNotNull(bean);
|
||||
assertNull(TestUtils.getPropertyValue(bean, "serializer"));
|
||||
assertThat(bean).isNotNull();
|
||||
assertThat(TestUtils.getPropertyValue(bean, "serializer")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,8 +102,8 @@ public class RedisInboundChannelAdapterParserTests extends RedisAvailableTests {
|
||||
QueueChannel receiveChannel = context.getBean("receiveChannel", QueueChannel.class);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Message<?> receive = receiveChannel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive.getPayload(), Matchers.<Object>isOneOf("Hello Redis from foo", "Hello Redis from bar"));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isIn("Hello Redis from foo", "Hello Redis from bar");
|
||||
}
|
||||
|
||||
adapter.stop();
|
||||
@@ -116,7 +111,7 @@ public class RedisInboundChannelAdapterParserTests extends RedisAvailableTests {
|
||||
|
||||
@Test
|
||||
public void testAutoChannel() {
|
||||
assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel"));
|
||||
assertThat(TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")).isSameAs(autoChannel);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -16,12 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -88,21 +84,21 @@ public class RedisOutboundChannelAdapterParserTests extends RedisAvailableTests
|
||||
EventDrivenConsumer adapter = context.getBean("outboundAdapter", EventDrivenConsumer.class);
|
||||
Object handler = context.getBean("outboundAdapter.handler");
|
||||
|
||||
assertEquals("outboundAdapter", adapter.getComponentName());
|
||||
assertThat(adapter.getComponentName()).isEqualTo("outboundAdapter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(handler);
|
||||
Object topicExpression = accessor.getPropertyValue("topicExpression");
|
||||
assertNotNull(topicExpression);
|
||||
assertEquals("headers['topic'] ?: 'foo'", ((Expression) topicExpression).getExpressionString());
|
||||
assertThat(topicExpression).isNotNull();
|
||||
assertThat(((Expression) topicExpression).getExpressionString()).isEqualTo("headers['topic'] ?: 'foo'");
|
||||
Object converterBean = context.getBean("testConverter");
|
||||
assertEquals(converterBean, accessor.getPropertyValue("messageConverter"));
|
||||
assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer"));
|
||||
assertThat(accessor.getPropertyValue("messageConverter")).isEqualTo(converterBean);
|
||||
assertThat(accessor.getPropertyValue("serializer")).isEqualTo(context.getBean("serializer"));
|
||||
|
||||
Object endpointHandler = TestUtils.getPropertyValue(adapter, "handler");
|
||||
|
||||
assertTrue(AopUtils.isAopProxy(endpointHandler));
|
||||
assertThat(AopUtils.isAopProxy(endpointHandler)).isTrue();
|
||||
|
||||
assertThat(TestUtils.getPropertyValue(endpointHandler, "h.advised.advisors[0].advice"),
|
||||
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
|
||||
assertThat(TestUtils.getPropertyValue(endpointHandler, "h.advised.advisors[0].advice"))
|
||||
.isInstanceOf(RequestHandlerRetryAdvice.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,15 +110,15 @@ public class RedisOutboundChannelAdapterParserTests extends RedisAvailableTests
|
||||
sendChannel.send(new GenericMessage<>("Hello Redis"));
|
||||
QueueChannel receiveChannel = context.getBean("receiveChannel", QueueChannel.class);
|
||||
Message<?> message = receiveChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals("Hello Redis", message.getPayload());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo("Hello Redis");
|
||||
|
||||
sendChannel = context.getBean("sendChannel", MessageChannel.class);
|
||||
sendChannel.send(MessageBuilder.withPayload("Hello Redis").setHeader("topic", "bar").build());
|
||||
receiveChannel = context.getBean("barChannel", QueueChannel.class);
|
||||
message = receiveChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals("Hello Redis", message.getPayload());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo("Hello Redis");
|
||||
}
|
||||
|
||||
@Test //INT-2275
|
||||
@@ -134,8 +130,8 @@ public class RedisOutboundChannelAdapterParserTests extends RedisAvailableTests
|
||||
sendChannel.send(new GenericMessage<>("Hello Redis from chain"));
|
||||
QueueChannel receiveChannel = context.getBean("receiveChannel", QueueChannel.class);
|
||||
Message<?> message = receiveChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals("Hello Redis from chain", message.getPayload());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo("Hello Redis from chain");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -87,8 +85,8 @@ public class RedisQueueGatewayIntegrationTests extends RedisAvailableTests {
|
||||
public void testRequestWithReply() {
|
||||
this.sendChannel.send(new GenericMessage<>(1));
|
||||
Message<?> receive = this.outputChannel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(2, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,7 +99,7 @@ public class RedisQueueGatewayIntegrationTests extends RedisAvailableTests {
|
||||
this.sendChannel.send(new GenericMessage<>("test1"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue(e.getMessage().contains("No reply produced"));
|
||||
assertThat(e.getMessage().contains("No reply produced")).isTrue();
|
||||
}
|
||||
finally {
|
||||
this.outboundGateway.setReceiveTimeout(receiveTimeout);
|
||||
@@ -118,7 +116,7 @@ public class RedisQueueGatewayIntegrationTests extends RedisAvailableTests {
|
||||
this.sendChannel.send(new GenericMessage<>("test1"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue(e.getMessage().contains("No reply produced"));
|
||||
assertThat(e.getMessage().contains("No reply produced")).isTrue();
|
||||
}
|
||||
finally {
|
||||
this.inboundGateway.setSerializer(new StringRedisSerializer());
|
||||
@@ -135,8 +133,8 @@ public class RedisQueueGatewayIntegrationTests extends RedisAvailableTests {
|
||||
this.outboundGateway.setExtractPayload(false);
|
||||
this.sendChannel.send(new GenericMessage<>(2));
|
||||
Message<?> receive = this.outputChannel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(3, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(3);
|
||||
this.inboundGateway.setSerializer(new StringRedisSerializer());
|
||||
this.inboundGateway.setExtractPayload(true);
|
||||
this.outboundGateway.setSerializer(new StringRedisSerializer());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -16,14 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -98,47 +92,50 @@ public class RedisQueueInboundChannelAdapterParserTests {
|
||||
|
||||
@Test
|
||||
public void testInt3017DefaultConfig() {
|
||||
assertSame(this.connectionFactory,
|
||||
TestUtils.getPropertyValue(this.defaultAdapter, "boundListOperations.ops.template.connectionFactory"));
|
||||
assertEquals("si.test.Int3017.Inbound1",
|
||||
TestUtils.getPropertyValue(this.defaultAdapter, "boundListOperations.key"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.defaultAdapter, "expectMessage", Boolean.class));
|
||||
assertEquals(1000L, TestUtils.getPropertyValue(this.defaultAdapter, "receiveTimeout"));
|
||||
assertEquals(5000L, TestUtils.getPropertyValue(this.defaultAdapter, "recoveryInterval"));
|
||||
assertNull(TestUtils.getPropertyValue(this.defaultAdapter, "errorChannel"));
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "taskExecutor"),
|
||||
Matchers.instanceOf(ErrorHandlingTaskExecutor.class));
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "serializer"),
|
||||
Matchers.instanceOf(JdkSerializationRedisSerializer.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.defaultAdapter, "autoStartup", Boolean.class));
|
||||
assertEquals(Integer.MAX_VALUE / 2, TestUtils.getPropertyValue(this.defaultAdapter, "phase"));
|
||||
assertSame(this.defaultAdapterChannel, TestUtils.getPropertyValue(this.defaultAdapter, "outputChannel"));
|
||||
assertTrue(TestUtils.getPropertyValue(this.defaultAdapter, "rightPop", Boolean.class));
|
||||
assertThat(TestUtils
|
||||
.getPropertyValue(this.defaultAdapter, "boundListOperations.ops.template.connectionFactory"))
|
||||
.isSameAs(this.connectionFactory);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "boundListOperations.key"))
|
||||
.isEqualTo("si.test.Int3017.Inbound1");
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "expectMessage", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "receiveTimeout")).isEqualTo(1000L);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "recoveryInterval")).isEqualTo(5000L);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "errorChannel")).isNull();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "taskExecutor"))
|
||||
.isInstanceOf(ErrorHandlingTaskExecutor.class);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "serializer"))
|
||||
.isInstanceOf(JdkSerializationRedisSerializer.class);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "autoStartup", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "phase")).isEqualTo(Integer.MAX_VALUE / 2);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "outputChannel"))
|
||||
.isSameAs(this.defaultAdapterChannel);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "rightPop", Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInt3017CustomConfig() {
|
||||
assertSame(this.customRedisConnectionFactory,
|
||||
TestUtils.getPropertyValue(this.customAdapter, "boundListOperations.ops.template.connectionFactory"));
|
||||
assertEquals("si.test.Int3017.Inbound2",
|
||||
TestUtils.getPropertyValue(this.customAdapter, "boundListOperations.key"));
|
||||
assertTrue(TestUtils.getPropertyValue(this.customAdapter, "expectMessage", Boolean.class));
|
||||
assertEquals(2000L, TestUtils.getPropertyValue(this.customAdapter, "receiveTimeout"));
|
||||
assertEquals(3000L, TestUtils.getPropertyValue(this.customAdapter, "recoveryInterval"));
|
||||
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.customAdapter, "errorChannel"));
|
||||
assertSame(this.taskExecutor, TestUtils.getPropertyValue(this.customAdapter, "taskExecutor"));
|
||||
assertSame(this.serializer, TestUtils.getPropertyValue(this.customAdapter, "serializer"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.customAdapter, "autoStartup", Boolean.class));
|
||||
assertEquals(100, TestUtils.getPropertyValue(this.customAdapter, "phase"));
|
||||
assertSame(this.sendChannel, TestUtils.getPropertyValue(this.customAdapter, "outputChannel"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.customAdapter, "rightPop", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "boundListOperations.ops.template" +
|
||||
".connectionFactory"))
|
||||
.isSameAs(this.customRedisConnectionFactory);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "boundListOperations.key"))
|
||||
.isEqualTo("si.test.Int3017.Inbound2");
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "expectMessage", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "receiveTimeout")).isEqualTo(2000L);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "recoveryInterval")).isEqualTo(3000L);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "errorChannel")).isSameAs(this.errorChannel);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "taskExecutor")).isSameAs(this.taskExecutor);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "serializer")).isSameAs(this.serializer);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "autoStartup", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "phase")).isEqualTo(100);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "outputChannel")).isSameAs(this.sendChannel);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "rightPop", Boolean.class)).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInt4341ZeroReceiveTimeoutConfig() {
|
||||
assertEquals(0L, TestUtils.getPropertyValue(this.zeroReceiveTimeoutAdapter, "receiveTimeout"));
|
||||
assertThat(TestUtils.getPropertyValue(this.zeroReceiveTimeoutAdapter, "receiveTimeout")).isEqualTo(0L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -16,11 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -70,20 +66,20 @@ public class RedisQueueInboundGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultConfig() throws Exception {
|
||||
assertFalse(TestUtils.getPropertyValue(this.defaultGateway, "extractPayload", Boolean.class));
|
||||
assertSame(this.serializer, TestUtils.getPropertyValue(this.defaultGateway, "serializer"));
|
||||
assertTrue(TestUtils.getPropertyValue(this.defaultGateway, "serializerExplicitlySet", Boolean.class));
|
||||
assertSame(this.receiveChannel, this.defaultGateway.getReplyChannel());
|
||||
assertSame(this.requestChannel, this.defaultGateway.getRequestChannel());
|
||||
assertEquals(2000L, TestUtils.getPropertyValue(this.defaultGateway, "replyTimeout"));
|
||||
assertNotNull(TestUtils.getPropertyValue(this.defaultGateway, "taskExecutor"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.defaultGateway, "autoStartup", Boolean.class));
|
||||
assertEquals(3, TestUtils.getPropertyValue(this.defaultGateway, "phase"));
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "extractPayload", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "serializer")).isSameAs(this.serializer);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "serializerExplicitlySet", Boolean.class)).isTrue();
|
||||
assertThat(this.defaultGateway.getReplyChannel()).isSameAs(this.receiveChannel);
|
||||
assertThat(this.defaultGateway.getRequestChannel()).isSameAs(this.requestChannel);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "replyTimeout")).isEqualTo(2000L);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "taskExecutor")).isNotNull();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "autoStartup", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "phase")).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroReceiveTimeoutConfig() throws Exception {
|
||||
assertEquals(0L, TestUtils.getPropertyValue(this.zeroReceiveTimeoutGateway, "receiveTimeout"));
|
||||
assertThat(TestUtils.getPropertyValue(this.zeroReceiveTimeoutGateway, "receiveTimeout")).isEqualTo(0L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -16,13 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -78,32 +73,34 @@ public class RedisQueueOutboundChannelAdapterParserTests {
|
||||
|
||||
@Test
|
||||
public void testInt3017DefaultConfig() throws Exception {
|
||||
assertSame(this.connectionFactory, TestUtils.getPropertyValue(this.defaultAdapter, "template.connectionFactory"));
|
||||
assertEquals("foo", TestUtils.getPropertyValue(this.defaultAdapter, "queueNameExpression", Expression.class).getExpressionString());
|
||||
assertTrue(TestUtils.getPropertyValue(this.defaultAdapter, "extractPayload", Boolean.class));
|
||||
assertFalse(TestUtils.getPropertyValue(this.defaultAdapter, "serializerExplicitlySet", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "template.connectionFactory"))
|
||||
.isSameAs(this.connectionFactory);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "queueNameExpression", Expression.class)
|
||||
.getExpressionString()).isEqualTo("foo");
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "extractPayload", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "serializerExplicitlySet", Boolean.class)).isFalse();
|
||||
|
||||
Object handler = TestUtils.getPropertyValue(this.defaultEndpoint, "handler");
|
||||
|
||||
assertTrue(AopUtils.isAopProxy(handler));
|
||||
assertThat(AopUtils.isAopProxy(handler)).isTrue();
|
||||
|
||||
assertSame(((Advised) handler).getTargetSource().getTarget(), this.defaultAdapter);
|
||||
assertThat(this.defaultAdapter).isSameAs(((Advised) handler).getTargetSource().getTarget());
|
||||
|
||||
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
|
||||
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.defaultAdapter, "leftPush", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"))
|
||||
.isInstanceOf(RequestHandlerRetryAdvice.class);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultAdapter, "leftPush", Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInt3017CustomConfig() {
|
||||
assertSame(this.customRedisConnectionFactory,
|
||||
TestUtils.getPropertyValue(this.customAdapter, "template.connectionFactory"));
|
||||
assertEquals("headers['redis_queue']",
|
||||
TestUtils.getPropertyValue(this.customAdapter, "queueNameExpression.expression"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.customAdapter, "extractPayload", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.customAdapter, "serializerExplicitlySet", Boolean.class));
|
||||
assertSame(this.serializer, TestUtils.getPropertyValue(this.customAdapter, "serializer"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.customAdapter, "leftPush", Boolean.class));
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "template.connectionFactory"))
|
||||
.isSameAs(this.customRedisConnectionFactory);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "queueNameExpression.expression"))
|
||||
.isEqualTo("headers['redis_queue']");
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "extractPayload", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "serializerExplicitlySet", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "serializer")).isSameAs(this.serializer);
|
||||
assertThat(TestUtils.getPropertyValue(this.customAdapter, "leftPush", Boolean.class)).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -66,16 +63,16 @@ public class RedisQueueOutboundGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultConfig() throws Exception {
|
||||
assertFalse(TestUtils.getPropertyValue(this.defaultGateway, "extractPayload", Boolean.class));
|
||||
assertSame(this.serializer, TestUtils.getPropertyValue(this.defaultGateway, "serializer"));
|
||||
assertTrue(TestUtils.getPropertyValue(this.defaultGateway, "serializerExplicitlySet", Boolean.class));
|
||||
assertEquals(2, TestUtils.getPropertyValue(this.defaultGateway, "order"));
|
||||
assertSame(this.receiveChannel, TestUtils.getPropertyValue(this.defaultGateway, "outputChannel"));
|
||||
assertSame(this.requestChannel, TestUtils.getPropertyValue(this.consumer, "inputChannel"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.defaultGateway, "requiresReply", Boolean.class));
|
||||
assertEquals(2000, TestUtils.getPropertyValue(this.defaultGateway, "receiveTimeout"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.consumer, "autoStartup", Boolean.class));
|
||||
assertEquals(3, TestUtils.getPropertyValue(this.consumer, "phase"));
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "extractPayload", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "serializer")).isSameAs(this.serializer);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "serializerExplicitlySet", Boolean.class)).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "order")).isEqualTo(2);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "outputChannel")).isSameAs(this.receiveChannel);
|
||||
assertThat(TestUtils.getPropertyValue(this.consumer, "inputChannel")).isSameAs(this.requestChannel);
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "requiresReply", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.defaultGateway, "receiveTimeout")).isEqualTo(2000);
|
||||
assertThat(TestUtils.getPropertyValue(this.consumer, "autoStartup", Boolean.class)).isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(this.consumer, "phase")).isEqualTo(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -57,18 +55,23 @@ public class RedisStoreInboundChannelAdapterParserTests {
|
||||
public void validateWithStringTemplate() {
|
||||
RedisStoreMessageSource withStringTemplate =
|
||||
TestUtils.getPropertyValue(context.getBean("withStringTemplate"), "source", RedisStoreMessageSource.class);
|
||||
assertEquals("'presidents'", ((SpelExpression) TestUtils.getPropertyValue(withStringTemplate, "keyExpression")).getExpressionString());
|
||||
assertEquals("LIST", ((CollectionType) TestUtils.getPropertyValue(withStringTemplate, "collectionType")).toString());
|
||||
assertTrue(TestUtils.getPropertyValue(withStringTemplate, "redisTemplate") instanceof StringRedisTemplate);
|
||||
assertThat(((SpelExpression) TestUtils.getPropertyValue(withStringTemplate, "keyExpression"))
|
||||
.getExpressionString()).isEqualTo("'presidents'");
|
||||
assertThat(((CollectionType) TestUtils.getPropertyValue(withStringTemplate, "collectionType")).toString())
|
||||
.isEqualTo("LIST");
|
||||
assertThat(TestUtils.getPropertyValue(withStringTemplate, "redisTemplate") instanceof StringRedisTemplate)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateWithExternalTemplate() {
|
||||
RedisStoreMessageSource withExternalTemplate =
|
||||
TestUtils.getPropertyValue(context.getBean("withExternalTemplate"), "source", RedisStoreMessageSource.class);
|
||||
assertEquals("'presidents'", ((SpelExpression) TestUtils.getPropertyValue(withExternalTemplate, "keyExpression")).getExpressionString());
|
||||
assertEquals("LIST", ((CollectionType) TestUtils.getPropertyValue(withExternalTemplate, "collectionType")).toString());
|
||||
assertSame(redisTemplate, TestUtils.getPropertyValue(withExternalTemplate, "redisTemplate"));
|
||||
assertThat(((SpelExpression) TestUtils.getPropertyValue(withExternalTemplate, "keyExpression"))
|
||||
.getExpressionString()).isEqualTo("'presidents'");
|
||||
assertThat(((CollectionType) TestUtils.getPropertyValue(withExternalTemplate, "collectionType")).toString())
|
||||
.isEqualTo("LIST");
|
||||
assertThat(TestUtils.getPropertyValue(withExternalTemplate, "redisTemplate")).isSameAs(redisTemplate);
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2018 the original author or authors.
|
||||
* Copyright 2007-2019 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.
|
||||
@@ -16,13 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -64,22 +59,24 @@ public class RedisStoreOutboundChannelAdapterParserTests {
|
||||
public void validateWithStringTemplate() throws Exception {
|
||||
RedisStoreWritingMessageHandler withStringTemplate = context.getBean("withStringTemplate.handler",
|
||||
RedisStoreWritingMessageHandler.class);
|
||||
assertEquals("pepboys", ((LiteralExpression) TestUtils.getPropertyValue(withStringTemplate,
|
||||
"keyExpression")).getExpressionString());
|
||||
assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withStringTemplate, "collectionType")).toString());
|
||||
assertTrue(TestUtils.getPropertyValue(withStringTemplate, "redisTemplate") instanceof StringRedisTemplate);
|
||||
assertThat(((LiteralExpression) TestUtils.getPropertyValue(withStringTemplate,
|
||||
"keyExpression")).getExpressionString()).isEqualTo("pepboys");
|
||||
assertThat((TestUtils.getPropertyValue(withStringTemplate, "collectionType")).toString())
|
||||
.isEqualTo("PROPERTIES");
|
||||
assertThat(TestUtils.getPropertyValue(withStringTemplate, "redisTemplate") instanceof StringRedisTemplate)
|
||||
.isTrue();
|
||||
|
||||
Object handler = TestUtils.getPropertyValue(context.getBean("withStringTemplate.adapter"), "handler");
|
||||
|
||||
assertTrue(AopUtils.isAopProxy(handler));
|
||||
assertThat(AopUtils.isAopProxy(handler)).isTrue();
|
||||
|
||||
assertSame(((Advised) handler).getTargetSource().getTarget(), withStringTemplate);
|
||||
assertThat(withStringTemplate).isSameAs(((Advised) handler).getTargetSource().getTarget());
|
||||
|
||||
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"),
|
||||
Matchers.instanceOf(RequestHandlerRetryAdvice.class));
|
||||
assertThat(TestUtils.getPropertyValue(handler, "h.advised.advisors[0].advice"))
|
||||
.isInstanceOf(RequestHandlerRetryAdvice.class);
|
||||
|
||||
assertEquals("true", TestUtils.getPropertyValue(withStringTemplate, "zsetIncrementScoreExpression",
|
||||
Expression.class).getExpressionString());
|
||||
assertThat(TestUtils.getPropertyValue(withStringTemplate, "zsetIncrementScoreExpression",
|
||||
Expression.class).getExpressionString()).isEqualTo("true");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,18 +84,20 @@ public class RedisStoreOutboundChannelAdapterParserTests {
|
||||
RedisStoreWritingMessageHandler withStringObjectTemplate =
|
||||
TestUtils.getPropertyValue(context.getBean("withStringObjectTemplate.adapter"), "handler",
|
||||
RedisStoreWritingMessageHandler.class);
|
||||
assertEquals("pepboys", ((LiteralExpression) TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"keyExpression")).getExpressionString());
|
||||
assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withStringObjectTemplate, "collectionType")).toString());
|
||||
assertFalse(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate") instanceof StringRedisTemplate);
|
||||
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"redisTemplate.keySerializer") instanceof StringRedisSerializer);
|
||||
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"redisTemplate.hashKeySerializer") instanceof StringRedisSerializer);
|
||||
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"redisTemplate.valueSerializer") instanceof JdkSerializationRedisSerializer);
|
||||
assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"redisTemplate.hashValueSerializer") instanceof JdkSerializationRedisSerializer);
|
||||
assertThat(((LiteralExpression) TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"keyExpression")).getExpressionString()).isEqualTo("pepboys");
|
||||
assertThat((TestUtils.getPropertyValue(withStringObjectTemplate, "collectionType")).toString())
|
||||
.isEqualTo("PROPERTIES");
|
||||
assertThat(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate") instanceof StringRedisTemplate)
|
||||
.isFalse();
|
||||
assertThat(TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"redisTemplate.keySerializer") instanceof StringRedisSerializer).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"redisTemplate.hashKeySerializer") instanceof StringRedisSerializer).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"redisTemplate.valueSerializer") instanceof JdkSerializationRedisSerializer).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(withStringObjectTemplate,
|
||||
"redisTemplate.hashValueSerializer") instanceof JdkSerializationRedisSerializer).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,10 +105,11 @@ public class RedisStoreOutboundChannelAdapterParserTests {
|
||||
RedisStoreWritingMessageHandler withExternalTemplate =
|
||||
TestUtils.getPropertyValue(context.getBean("withExternalTemplate.adapter"), "handler",
|
||||
RedisStoreWritingMessageHandler.class);
|
||||
assertEquals("pepboys", ((LiteralExpression) TestUtils.getPropertyValue(withExternalTemplate,
|
||||
"keyExpression")).getExpressionString());
|
||||
assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withExternalTemplate, "collectionType")).toString());
|
||||
assertSame(redisTemplate, TestUtils.getPropertyValue(withExternalTemplate, "redisTemplate"));
|
||||
assertThat(((LiteralExpression) TestUtils.getPropertyValue(withExternalTemplate,
|
||||
"keyExpression")).getExpressionString()).isEqualTo("pepboys");
|
||||
assertThat((TestUtils.getPropertyValue(withExternalTemplate, "collectionType")).toString())
|
||||
.isEqualTo("PROPERTIES");
|
||||
assertThat(TestUtils.getPropertyValue(withExternalTemplate, "redisTemplate")).isSameAs(redisTemplate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2017 the original author or authors.
|
||||
* Copyright 2007-2019 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.
|
||||
@@ -16,13 +16,9 @@
|
||||
|
||||
package org.springframework.integration.redis.inbound;
|
||||
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -84,12 +80,13 @@ public class RedisInboundChannelAdapterTests extends RedisAvailableTests {
|
||||
if (message == null) {
|
||||
throw new RuntimeException("Failed to receive message # " + i + " iteration " + iteration);
|
||||
}
|
||||
assertNotNull(message);
|
||||
assertThat(message.getPayload().toString(), startsWith("test-"));
|
||||
assertEquals("testRedisInboundChannelAdapterChannel", message.getHeaders().get(RedisHeaders.MESSAGE_SOURCE));
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().toString()).startsWith("test-");
|
||||
assertThat(message.getHeaders().get(RedisHeaders.MESSAGE_SOURCE))
|
||||
.isEqualTo("testRedisInboundChannelAdapterChannel");
|
||||
counter++;
|
||||
}
|
||||
assertEquals(numToTest, counter);
|
||||
assertThat(counter).isEqualTo(numToTest);
|
||||
adapter.stop();
|
||||
|
||||
redisChannelName = "testRedisBytesInboundChannelAdapterChannel";
|
||||
@@ -118,15 +115,15 @@ public class RedisInboundChannelAdapterTests extends RedisAvailableTests {
|
||||
if (message == null) {
|
||||
throw new RuntimeException("Failed to receive message # " + i + " iteration " + iteration);
|
||||
}
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
Object payload = message.getPayload();
|
||||
assertThat(payload, Matchers.instanceOf(byte[].class));
|
||||
assertThat(payload).isInstanceOf(byte[].class);
|
||||
|
||||
assertThat(new String((byte[]) payload), startsWith("test-"));
|
||||
assertThat(new String((byte[]) payload)).startsWith("test-");
|
||||
counter++;
|
||||
}
|
||||
|
||||
assertEquals(numToTest, counter);
|
||||
assertThat(counter).isEqualTo(numToTest);
|
||||
adapter.stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -16,17 +16,12 @@
|
||||
|
||||
package org.springframework.integration.redis.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -35,7 +30,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -130,12 +124,12 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
endpoint.start();
|
||||
|
||||
Message<Object> receive = (Message<Object>) channel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(payload, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(payload);
|
||||
|
||||
receive = (Message<Object>) channel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(payload2, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(payload2);
|
||||
|
||||
endpoint.stop();
|
||||
}
|
||||
@@ -175,19 +169,18 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
endpoint.start();
|
||||
|
||||
Message<Object> receive = (Message<Object>) channel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
assertEquals(message, receive);
|
||||
assertThat(receive).isEqualTo(message);
|
||||
|
||||
receive = (Message<Object>) errorChannel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive, Matchers.instanceOf(ErrorMessage.class));
|
||||
assertThat(receive.getPayload(), Matchers.instanceOf(MessagingException.class));
|
||||
assertThat(((Exception) receive.getPayload()).getMessage(),
|
||||
Matchers.containsString("Deserialization of Message failed."));
|
||||
assertThat(((Exception) receive.getPayload()).getCause(), Matchers.instanceOf(ClassCastException.class));
|
||||
assertThat(((Exception) receive.getPayload()).getCause().getMessage(),
|
||||
Matchers.containsString("java.lang.String cannot be cast to org.springframework.messaging.Message"));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive).isInstanceOf(ErrorMessage.class);
|
||||
assertThat(receive.getPayload()).isInstanceOf(MessagingException.class);
|
||||
assertThat(((Exception) receive.getPayload()).getMessage()).contains("Deserialization of Message failed.");
|
||||
assertThat(((Exception) receive.getPayload()).getCause()).isInstanceOf(ClassCastException.class);
|
||||
assertThat(((Exception) receive.getPayload()).getCause().getMessage())
|
||||
.contains("java.lang.String cannot be cast to org.springframework.messaging.Message");
|
||||
|
||||
endpoint.stop();
|
||||
}
|
||||
@@ -206,8 +199,8 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
.leftPush("{\"payload\":\"" + payload + "\",\"headers\":{}}");
|
||||
|
||||
Message<?> receive = this.fromChannel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(payload, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(payload);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -221,8 +214,8 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
this.symmetricalInputChannel.send(message);
|
||||
|
||||
Message<?> receive = this.symmetricalOutputChannel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(payload, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(payload);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -269,9 +262,9 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
endpoint.stop(() -> stopLatch.countDown());
|
||||
|
||||
executorService.shutdown();
|
||||
assertTrue(executorService.awaitTermination(20, TimeUnit.SECONDS));
|
||||
assertThat(executorService.awaitTermination(20, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
assertTrue(stopLatch.await(21, TimeUnit.SECONDS));
|
||||
assertThat(stopLatch.await(21, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
verify(boundListOperations, atLeastOnce()).rightPush(any(byte[].class));
|
||||
}
|
||||
@@ -288,7 +281,8 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
|
||||
final CountDownLatch exceptionsLatch = new CountDownLatch(2);
|
||||
|
||||
RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory);
|
||||
RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName,
|
||||
this.connectionFactory);
|
||||
endpoint.setBeanFactory(Mockito.mock(BeanFactory.class));
|
||||
endpoint.setApplicationEventPublisher(event -> {
|
||||
exceptionEvents.add((ApplicationEvent) event);
|
||||
@@ -304,13 +298,13 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
|
||||
((DisposableBean) this.connectionFactory).destroy();
|
||||
|
||||
assertTrue(exceptionsLatch.await(10, TimeUnit.SECONDS));
|
||||
assertThat(exceptionsLatch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
for (ApplicationEvent exceptionEvent : exceptionEvents) {
|
||||
assertThat(exceptionEvent, Matchers.instanceOf(RedisExceptionEvent.class));
|
||||
assertSame(endpoint, exceptionEvent.getSource());
|
||||
assertThat(((IntegrationEvent) exceptionEvent).getCause().getClass(),
|
||||
Matchers.isIn(Arrays.asList(RedisSystemException.class, RedisConnectionFailureException.class)));
|
||||
assertThat(exceptionEvent).isInstanceOf(RedisExceptionEvent.class);
|
||||
assertThat(exceptionEvent.getSource()).isSameAs(endpoint);
|
||||
assertThat(((IntegrationEvent) exceptionEvent).getCause().getClass())
|
||||
.isIn(RedisSystemException.class, RedisConnectionFailureException.class);
|
||||
}
|
||||
|
||||
((InitializingBean) this.connectionFactory).afterPropertiesSet();
|
||||
@@ -327,8 +321,8 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
redisTemplate.boundListOps(queueName).leftPush(payload);
|
||||
|
||||
Message<?> receive = channel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(payload, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(payload);
|
||||
|
||||
endpoint.stop();
|
||||
}
|
||||
@@ -367,12 +361,12 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
endpoint.start();
|
||||
|
||||
Message<Object> receive = (Message<Object>) channel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(payload, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(payload);
|
||||
|
||||
receive = (Message<Object>) channel.receive(10000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(payload2, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(payload2);
|
||||
|
||||
endpoint.stop();
|
||||
}
|
||||
@@ -388,7 +382,7 @@ public class RedisQueueMessageDrivenEndpointTests extends RedisAvailableTests {
|
||||
}
|
||||
while (!endpoint.isListening());
|
||||
|
||||
assertTrue(n < 100);
|
||||
assertThat(n < 100).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -58,13 +55,13 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
|
||||
|
||||
Message<Integer> message = (Message<Integer>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(Integer.valueOf(13), message.getPayload());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo(Integer.valueOf(13));
|
||||
|
||||
//poll again, should get the same stuff
|
||||
message = (Message<Integer>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(Integer.valueOf(13), message.getPayload());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo(Integer.valueOf(13));
|
||||
this.deletePresidents(jcf);
|
||||
context.close();
|
||||
}
|
||||
@@ -86,20 +83,20 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
|
||||
|
||||
Message<Integer> message = (Message<Integer>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(Integer.valueOf(13), message.getPayload());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo(Integer.valueOf(13));
|
||||
|
||||
//poll again, should get nothing since the collection was removed during synchronization
|
||||
message = (Message<Integer>) redisChannel.receive(100);
|
||||
assertNull(message);
|
||||
assertThat(message).isNull();
|
||||
|
||||
int n = 0;
|
||||
while (n++ < 100 && template.keys("bar").size() == 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertTrue("Rename didn't occur", n < 100);
|
||||
assertThat(n < 100).as("Rename didn't occur").isTrue();
|
||||
|
||||
assertEquals(Long.valueOf(13), template.boundListOps("bar").size());
|
||||
assertThat(template.boundListOps("bar").size()).isEqualTo(Long.valueOf(13));
|
||||
template.delete("bar");
|
||||
|
||||
spca.stop();
|
||||
@@ -126,13 +123,13 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
SourcePollingChannelAdapter spca = context.getBean("listAdapterWithSynchronizationAndRollback",
|
||||
SourcePollingChannelAdapter.class);
|
||||
spca.start();
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
int n = 0;
|
||||
while (n++ < 100 && template.keys("baz").size() == 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertTrue("Rename didn't occur", n < 100);
|
||||
assertEquals(Long.valueOf(13), template.boundListOps("baz").size());
|
||||
assertThat(n < 100).as("Rename didn't occur").isTrue();
|
||||
assertThat(template.boundListOps("baz").size()).isEqualTo(Long.valueOf(13));
|
||||
template.delete("baz");
|
||||
|
||||
spca.stop();
|
||||
@@ -156,20 +153,20 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
|
||||
|
||||
Message<Integer> message = (Message<Integer>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(Integer.valueOf(13), message.getPayload());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload()).isEqualTo(Integer.valueOf(13));
|
||||
|
||||
//poll again, should get nothing since the collection was removed during synchronization
|
||||
message = (Message<Integer>) redisChannel.receive(100);
|
||||
assertNull(message);
|
||||
assertThat(message).isNull();
|
||||
|
||||
int n = 0;
|
||||
while (n++ < 100 && template.keys("bar").size() == 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertTrue("Rename didn't occur", n < 100);
|
||||
assertThat(n < 100).as("Rename didn't occur").isTrue();
|
||||
|
||||
assertEquals(Long.valueOf(13), template.boundListOps("bar").size());
|
||||
assertThat(template.boundListOps("bar").size()).isEqualTo(Long.valueOf(13));
|
||||
template.delete("bar");
|
||||
|
||||
spca.stop();
|
||||
@@ -193,13 +190,13 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
|
||||
|
||||
Message<RedisZSet<Object>> message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(13, message.getPayload().size());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().size()).isEqualTo(13);
|
||||
|
||||
//poll again, should get the same stuff
|
||||
message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(13, message.getPayload().size());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().size()).isEqualTo(13);
|
||||
|
||||
zsetAdapterNoScore.stop();
|
||||
|
||||
@@ -210,13 +207,13 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
zsetAdapterWithScoreRange.start();
|
||||
|
||||
message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(11, message.getPayload().rangeByScore(18, 20).size());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().rangeByScore(18, 20).size()).isEqualTo(11);
|
||||
|
||||
//poll again, should get the same stuff
|
||||
message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(11, message.getPayload().rangeByScore(18, 20).size());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().rangeByScore(18, 20).size()).isEqualTo(11);
|
||||
|
||||
zsetAdapterWithScoreRange.stop();
|
||||
|
||||
@@ -227,13 +224,13 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
zsetAdapterWithSingleScore.start();
|
||||
|
||||
message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(2, message.getPayload().rangeByScore(18, 18).size());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().rangeByScore(18, 18).size()).isEqualTo(2);
|
||||
|
||||
//poll again, should get the same stuff
|
||||
message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(2, message.getPayload().rangeByScore(18, 18).size());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().rangeByScore(18, 18).size()).isEqualTo(2);
|
||||
|
||||
zsetAdapterWithSingleScore.stop();
|
||||
|
||||
@@ -247,26 +244,26 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila
|
||||
// get all 13 presidents
|
||||
zsetAdapterNoScore.start();
|
||||
message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertEquals(13, message.getPayload().size());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().size()).isEqualTo(13);
|
||||
zsetAdapterNoScore.stop();
|
||||
|
||||
// get only presidents for 18th century
|
||||
zsetAdapterWithSingleScoreAndSynchronization.start();
|
||||
Message<Integer> sizeMessage = (Message<Integer>) otherRedisChannel.receive(10000);
|
||||
assertNotNull(sizeMessage);
|
||||
assertEquals(Integer.valueOf(2), sizeMessage.getPayload());
|
||||
assertThat(sizeMessage).isNotNull();
|
||||
assertThat(sizeMessage.getPayload()).isEqualTo(Integer.valueOf(2));
|
||||
|
||||
// ... however other elements are still available 13-2=11
|
||||
zsetAdapterNoScore.start();
|
||||
message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
|
||||
int n = 0;
|
||||
while (n++ < 100 && message.getPayload().size() != 11) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertTrue(n < 100);
|
||||
assertThat(n < 100).isTrue();
|
||||
|
||||
zsetAdapterNoScore.stop();
|
||||
zsetAdapterWithSingleScoreAndSynchronization.stop();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2018 the original author or authors.
|
||||
* Copyright 2016-2019 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.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.leader;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -74,7 +72,7 @@ public class RedisLockRegistryLeaderInitiatorTests extends RedisAvailableTests {
|
||||
initiator.start();
|
||||
}
|
||||
|
||||
assertThat(granted.await(10, TimeUnit.SECONDS), is(true));
|
||||
assertThat(granted.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
LockRegistryLeaderInitiator initiator1 = countingPublisher.initiator;
|
||||
|
||||
@@ -87,10 +85,10 @@ public class RedisLockRegistryLeaderInitiatorTests extends RedisAvailableTests {
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(initiator2);
|
||||
assertThat(initiator2).isNotNull();
|
||||
|
||||
assertThat(initiator1.getContext().isLeader(), is(true));
|
||||
assertThat(initiator2.getContext().isLeader(), is(false));
|
||||
assertThat(initiator1.getContext().isLeader()).isTrue();
|
||||
assertThat(initiator2.getContext().isLeader()).isFalse();
|
||||
|
||||
final CountDownLatch granted1 = new CountDownLatch(1);
|
||||
final CountDownLatch granted2 = new CountDownLatch(1);
|
||||
@@ -108,22 +106,22 @@ public class RedisLockRegistryLeaderInitiatorTests extends RedisAvailableTests {
|
||||
|
||||
initiator1.getContext().yield();
|
||||
|
||||
assertThat(revoked1.await(20, TimeUnit.SECONDS), is(true));
|
||||
assertThat(granted2.await(20, TimeUnit.SECONDS), is(true));
|
||||
assertThat(revoked1.await(20, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(granted2.await(20, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
assertThat(initiator2.getContext().isLeader(), is(true));
|
||||
assertThat(initiator1.getContext().isLeader(), is(false));
|
||||
assertThat(initiator2.getContext().isLeader()).isTrue();
|
||||
assertThat(initiator1.getContext().isLeader()).isFalse();
|
||||
|
||||
initiator1.setBusyWaitMillis(LockRegistryLeaderInitiator.DEFAULT_BUSY_WAIT_TIME);
|
||||
initiator2.setBusyWaitMillis(1000);
|
||||
|
||||
initiator2.getContext().yield();
|
||||
|
||||
assertThat(revoked2.await(20, TimeUnit.SECONDS), is(true));
|
||||
assertThat(granted1.await(20, TimeUnit.SECONDS), is(true));
|
||||
assertThat(revoked2.await(20, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(granted1.await(20, TimeUnit.SECONDS)).isTrue();
|
||||
|
||||
assertThat(initiator1.getContext().isLeader(), is(true));
|
||||
assertThat(initiator2.getContext().isLeader(), is(false));
|
||||
assertThat(initiator1.getContext().isLeader()).isTrue();
|
||||
assertThat(initiator2.getContext().isLeader()).isFalse();
|
||||
|
||||
initiator2.stop();
|
||||
|
||||
@@ -133,8 +131,8 @@ public class RedisLockRegistryLeaderInitiatorTests extends RedisAvailableTests {
|
||||
|
||||
initiator1.getContext().yield();
|
||||
|
||||
assertThat(revoked11.await(10, TimeUnit.SECONDS), is(true));
|
||||
assertThat(initiator1.getContext().isLeader(), is(false));
|
||||
assertThat(revoked11.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(initiator1.getContext().isLeader()).isFalse();
|
||||
|
||||
initiator1.stop();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.metadata;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -51,7 +50,7 @@ public class RedisMetadataStoreTests extends RedisAvailableTests {
|
||||
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
|
||||
RedisMetadataStore metadataStore = new RedisMetadataStore(jcf);
|
||||
String retrievedValue = metadataStore.get("does-not-exist");
|
||||
assertNull(retrievedValue);
|
||||
assertThat(retrievedValue).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,7 +63,7 @@ public class RedisMetadataStoreTests extends RedisAvailableTests {
|
||||
StringRedisTemplate redisTemplate = new StringRedisTemplate(jcf);
|
||||
BoundHashOperations<String, Object, Object> ops = redisTemplate.boundHashOps("testMetadata");
|
||||
|
||||
assertEquals("Integration", ops.get("RedisMetadataStoreTests-Spring"));
|
||||
assertThat(ops.get("RedisMetadataStoreTests-Spring")).isEqualTo("Integration");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,7 +75,7 @@ public class RedisMetadataStoreTests extends RedisAvailableTests {
|
||||
metadataStore.put("RedisMetadataStoreTests-GetValue", "Hello Redis");
|
||||
|
||||
String retrievedValue = metadataStore.get("RedisMetadataStoreTests-GetValue");
|
||||
assertEquals("Hello Redis", retrievedValue);
|
||||
assertThat(retrievedValue).isEqualTo("Hello Redis");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +87,7 @@ public class RedisMetadataStoreTests extends RedisAvailableTests {
|
||||
metadataStore.put("RedisMetadataStoreTests-PersistEmpty", "");
|
||||
|
||||
String retrievedValue = metadataStore.get("RedisMetadataStoreTests-PersistEmpty");
|
||||
assertEquals("", retrievedValue);
|
||||
assertThat(retrievedValue).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,7 +101,7 @@ public class RedisMetadataStoreTests extends RedisAvailableTests {
|
||||
metadataStore.put("RedisMetadataStoreTests-PersistEmpty", null);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("'value' must not be null.", e.getMessage());
|
||||
assertThat(e.getMessage()).isEqualTo("'value' must not be null.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,7 +117,7 @@ public class RedisMetadataStoreTests extends RedisAvailableTests {
|
||||
metadataStore.put("", "PersistWithEmptyKey");
|
||||
|
||||
String retrievedValue = metadataStore.get("");
|
||||
assertEquals("PersistWithEmptyKey", retrievedValue);
|
||||
assertThat(retrievedValue).isEqualTo("PersistWithEmptyKey");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,7 +130,7 @@ public class RedisMetadataStoreTests extends RedisAvailableTests {
|
||||
metadataStore.put(null, "something");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("'key' must not be null.", e.getMessage());
|
||||
assertThat(e.getMessage()).isEqualTo("'key' must not be null.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -148,7 +147,7 @@ public class RedisMetadataStoreTests extends RedisAvailableTests {
|
||||
metadataStore.get(null);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertEquals("'key' must not be null.", e.getMessage());
|
||||
assertThat(e.getMessage()).isEqualTo("'key' must not be null.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,8 +165,8 @@ public class RedisMetadataStoreTests extends RedisAvailableTests {
|
||||
|
||||
metadataStore.put(testKey, testValue);
|
||||
|
||||
assertEquals(testValue, metadataStore.remove(testKey));
|
||||
assertNull(metadataStore.remove(testKey));
|
||||
assertThat(metadataStore.remove(testKey)).isEqualTo(testValue);
|
||||
assertThat(metadataStore.remove(testKey)).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -16,16 +16,12 @@
|
||||
|
||||
package org.springframework.integration.redis.outbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -84,8 +80,8 @@ public class RedisOutboundGatewayTests extends RedisAvailableTests {
|
||||
public void testPingPongCommand() {
|
||||
this.pingChannel.send(MessageBuilder.withPayload("foo").setHeader(RedisHeaders.COMMAND, "PING").build());
|
||||
Message<?> receive = this.replyChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertTrue(Arrays.equals("PONG".getBytes(), (byte[]) receive.getPayload()));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(Arrays.equals("PONG".getBytes(), (byte[]) receive.getPayload())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,15 +94,15 @@ public class RedisOutboundGatewayTests extends RedisAvailableTests {
|
||||
.setHeader("queue", queueName)
|
||||
.build());
|
||||
Message<?> receive = this.replyChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
this.leftPushRightPopChannel.send(MessageBuilder.withPayload(payload)
|
||||
.setHeader(RedisHeaders.COMMAND, "RPOP")
|
||||
.setHeader("queue", queueName)
|
||||
.build());
|
||||
receive = this.replyChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertTrue(Arrays.equals(payload.getBytes(), (byte[]) receive.getPayload()));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(Arrays.equals(payload.getBytes(), (byte[]) receive.getPayload())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,13 +113,13 @@ public class RedisOutboundGatewayTests extends RedisAvailableTests {
|
||||
this.beanFactory.getBean("atomicInteger");
|
||||
this.incrementAtomicIntegerChannel.send(MessageBuilder.withPayload("INCR").build());
|
||||
Message<?> receive = this.replyChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(11L, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(11L);
|
||||
|
||||
this.getCommandChannel.send(MessageBuilder.withPayload("si.test.RedisAtomicInteger").build());
|
||||
receive = this.replyChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertEquals("11", new String((byte[]) receive.getPayload()));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(new String((byte[]) receive.getPayload())).isEqualTo("11");
|
||||
this.createStringRedisTemplate(this.getConnectionFactoryForTest()).delete("si.test.RedisAtomicInteger");
|
||||
}
|
||||
|
||||
@@ -133,25 +129,25 @@ public class RedisOutboundGatewayTests extends RedisAvailableTests {
|
||||
this.setDelCommandChannel.send(MessageBuilder.withPayload(new String[] { "foo", "bar" })
|
||||
.setHeader(RedisHeaders.COMMAND, "SET").build());
|
||||
Message<?> receive = this.replyChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertEquals("OK", receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo("OK");
|
||||
|
||||
this.getCommandChannel.send(MessageBuilder.withPayload("foo").build());
|
||||
receive = this.replyChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertTrue(Arrays.equals("bar".getBytes(), (byte[]) receive.getPayload()));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(Arrays.equals("bar".getBytes(), (byte[]) receive.getPayload())).isTrue();
|
||||
|
||||
this.setDelCommandChannel.send(MessageBuilder.withPayload("foo").setHeader(RedisHeaders.COMMAND, "DEL").build());
|
||||
receive = this.replyChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertEquals(1L, receive.getPayload());
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo(1L);
|
||||
|
||||
try {
|
||||
this.getCommandChannel.send(MessageBuilder.withPayload("foo").build());
|
||||
fail("ReplyRequiredException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, Matchers.instanceOf(ReplyRequiredException.class));
|
||||
assertThat(e).isInstanceOf(ReplyRequiredException.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,8 +162,8 @@ public class RedisOutboundGatewayTests extends RedisAvailableTests {
|
||||
connection.set("foo2".getBytes(), value2);
|
||||
this.mgetCommandChannel.send(MessageBuilder.withPayload(new String[] { "foo1", "foo2" }).build());
|
||||
Message<?> receive = this.replyChannel.receive(1000);
|
||||
assertNotNull(receive);
|
||||
assertThat((List<byte[]>) receive.getPayload(), Matchers.contains(value1, value2));
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat((List<byte[]>) receive.getPayload()).containsExactly(value1, value2);
|
||||
connection.del("foo1".getBytes(), "foo2".getBytes());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2016 the original author or authors.
|
||||
* Copyright 2007-2019 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.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.outbound;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -74,7 +74,7 @@ public class RedisPublishingMessageHandlerTests extends RedisAvailableTests {
|
||||
for (int i = 0; i < numToTest; i++) {
|
||||
handler.handleMessage(MessageBuilder.withPayload(("test-" + i).getBytes()).build());
|
||||
}
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
container.stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.outbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
@@ -84,9 +83,9 @@ public class RedisQueueOutboundChannelAdapterTests extends RedisAvailableTests {
|
||||
redisTemplate.afterPropertiesSet();
|
||||
|
||||
Object result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
|
||||
assertNotNull(result);
|
||||
assertThat(result).isNotNull();
|
||||
|
||||
assertEquals(payload, result);
|
||||
assertThat(result).isEqualTo(payload);
|
||||
|
||||
Date payload2 = new Date();
|
||||
handler.handleMessage(MessageBuilder.withPayload(payload2).build());
|
||||
@@ -99,9 +98,9 @@ public class RedisQueueOutboundChannelAdapterTests extends RedisAvailableTests {
|
||||
redisTemplate2.afterPropertiesSet();
|
||||
|
||||
Object result2 = redisTemplate2.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
|
||||
assertNotNull(result2);
|
||||
assertThat(result2).isNotNull();
|
||||
|
||||
assertEquals(payload2, result2);
|
||||
assertThat(result2).isEqualTo(payload2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,9 +124,9 @@ public class RedisQueueOutboundChannelAdapterTests extends RedisAvailableTests {
|
||||
redisTemplate.afterPropertiesSet();
|
||||
|
||||
Object result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
|
||||
assertNotNull(result);
|
||||
assertThat(result).isNotNull();
|
||||
|
||||
assertEquals(message, result);
|
||||
assertThat(result).isEqualTo(message);
|
||||
|
||||
}
|
||||
|
||||
@@ -148,16 +147,16 @@ public class RedisQueueOutboundChannelAdapterTests extends RedisAvailableTests {
|
||||
handler.handleMessage(new GenericMessage<Object>(Arrays.asList("foo", "bar", "baz")));
|
||||
|
||||
Object result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
|
||||
assertNotNull(result);
|
||||
assertThat(result).isNotNull();
|
||||
|
||||
assertEquals("[\"foo\",\"bar\",\"baz\"]", result);
|
||||
assertThat(result).isEqualTo("[\"foo\",\"bar\",\"baz\"]");
|
||||
|
||||
handler.handleMessage(new GenericMessage<Object>("test"));
|
||||
|
||||
result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
|
||||
assertNotNull(result);
|
||||
assertThat(result).isNotNull();
|
||||
|
||||
assertEquals("\"test\"", result);
|
||||
assertThat(result).isEqualTo("\"test\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,11 +173,11 @@ public class RedisQueueOutboundChannelAdapterTests extends RedisAvailableTests {
|
||||
redisTemplate.afterPropertiesSet();
|
||||
|
||||
String result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
|
||||
assertNotNull(result);
|
||||
assertThat(result).isNotNull();
|
||||
InboundMessageMapper<String> mapper = new JsonInboundMessageMapper(String.class,
|
||||
new Jackson2JsonMessageParser());
|
||||
Message<?> resultMessage = mapper.toMessage(result);
|
||||
assertEquals(message.getPayload(), resultMessage.getPayload());
|
||||
assertThat(resultMessage.getPayload()).isEqualTo(message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,9 +201,9 @@ public class RedisQueueOutboundChannelAdapterTests extends RedisAvailableTests {
|
||||
redisTemplate.afterPropertiesSet();
|
||||
|
||||
Object result = redisTemplate.boundListOps(queueName).leftPop(5000, TimeUnit.MILLISECONDS);
|
||||
assertNotNull(result);
|
||||
assertThat(result).isNotNull();
|
||||
|
||||
assertEquals(payload, result);
|
||||
assertThat(result).isEqualTo(payload);
|
||||
|
||||
RedisTemplate<String, ?> redisTemplate2 = new RedisTemplate<String, Object>();
|
||||
redisTemplate2.setConnectionFactory(this.connectionFactory);
|
||||
@@ -214,9 +213,9 @@ public class RedisQueueOutboundChannelAdapterTests extends RedisAvailableTests {
|
||||
redisTemplate2.afterPropertiesSet();
|
||||
|
||||
Object result2 = redisTemplate2.boundListOps(queueName).leftPop(5000, TimeUnit.MILLISECONDS);
|
||||
assertNotNull(result2);
|
||||
assertThat(result2).isNotNull();
|
||||
|
||||
assertEquals(payload2, result2);
|
||||
assertThat(result2).isEqualTo(payload2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2017 the original author or authors.
|
||||
* Copyright 2007-2019 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.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.outbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -144,7 +144,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
@RedisAvailable
|
||||
public void testListWithKeyAsHeader() {
|
||||
RedisList<String> redisList = new DefaultRedisList<String>("pepboys", this.redisTemplate);
|
||||
assertEquals(0, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(0);
|
||||
|
||||
List<String> pepboys = new ArrayList<String>();
|
||||
pepboys.add("Manny");
|
||||
@@ -153,7 +153,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
Message<List<String>> message = MessageBuilder.withPayload(pepboys).setHeader(RedisHeaders.KEY, "pepboys").build();
|
||||
this.listWithKeyAsHeaderChannel.send(message);
|
||||
|
||||
assertEquals(3, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,19 +161,19 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
public void testListWithKeyAsHeaderSimple() {
|
||||
redisTemplate.delete("foo");
|
||||
RedisList<String> redisList = new DefaultRedisList<String>("foo", this.redisTemplate);
|
||||
assertEquals(0, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(0);
|
||||
|
||||
Message<String> message = MessageBuilder.withPayload("bar").setHeader("redis_key", "foo").build();
|
||||
this.listWithKeyAsHeaderChannel.send(message);
|
||||
|
||||
assertEquals(1, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testListWithProvidedKey() {
|
||||
RedisList<String> redisList = new DefaultRedisList<String>("pepboys", this.redisTemplate);
|
||||
assertEquals(0, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(0);
|
||||
|
||||
List<String> pepboys = new ArrayList<String>();
|
||||
pepboys.add("Manny");
|
||||
@@ -182,14 +182,14 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
Message<List<String>> message = MessageBuilder.withPayload(pepboys).build();
|
||||
this.listWithKeyProvidedChannel.send(message);
|
||||
|
||||
assertEquals(3, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testZsetSimplePayloadIncrement() {
|
||||
RedisZSet<String> redisZSet = new DefaultRedisZSet<String>("foo", this.redisTemplate);
|
||||
assertEquals(0, redisZSet.size());
|
||||
assertThat(redisZSet.size()).isEqualTo(0);
|
||||
|
||||
Message<String> message = MessageBuilder.withPayload("bar")
|
||||
.setHeader(RedisHeaders.KEY, "foo")
|
||||
@@ -197,40 +197,40 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
.build();
|
||||
this.zsetChannel.send(message);
|
||||
|
||||
assertEquals(1, redisZSet.size());
|
||||
assertEquals(Double.valueOf(1), redisZSet.score("bar"));
|
||||
assertThat(redisZSet.size()).isEqualTo(1);
|
||||
assertThat(redisZSet.score("bar")).isEqualTo(Double.valueOf(1));
|
||||
|
||||
this.zsetChannel.send(message);
|
||||
|
||||
assertEquals(1, redisZSet.size());
|
||||
assertEquals(Double.valueOf(2), redisZSet.score("bar"));
|
||||
assertThat(redisZSet.size()).isEqualTo(1);
|
||||
assertThat(redisZSet.score("bar")).isEqualTo(Double.valueOf(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testZsetSimplePayloadOverwrite() {
|
||||
RedisZSet<String> redisZSet = new DefaultRedisZSet<String>("foo", this.redisTemplate);
|
||||
assertEquals(0, redisZSet.size());
|
||||
assertThat(redisZSet.size()).isEqualTo(0);
|
||||
|
||||
Message<String> message = MessageBuilder.withPayload("bar")
|
||||
.setHeader(RedisHeaders.KEY, "foo")
|
||||
.build();
|
||||
this.zsetChannel.send(message);
|
||||
|
||||
assertEquals(1, redisZSet.size());
|
||||
assertEquals(Double.valueOf(1), redisZSet.score("bar"));
|
||||
assertThat(redisZSet.size()).isEqualTo(1);
|
||||
assertThat(redisZSet.score("bar")).isEqualTo(Double.valueOf(1));
|
||||
|
||||
this.zsetChannel.send(message);
|
||||
|
||||
assertEquals(1, redisZSet.size());
|
||||
assertEquals(Double.valueOf(1), redisZSet.score("bar"));
|
||||
assertThat(redisZSet.size()).isEqualTo(1);
|
||||
assertThat(redisZSet.score("bar")).isEqualTo(Double.valueOf(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testZsetSimplePayloadIncrementBy2() {
|
||||
RedisZSet<String> redisZSet = new DefaultRedisZSet<String>("foo", this.redisTemplate);
|
||||
assertEquals(0, redisZSet.size());
|
||||
assertThat(redisZSet.size()).isEqualTo(0);
|
||||
|
||||
Message<String> message = MessageBuilder.withPayload("bar")
|
||||
.setHeader(RedisHeaders.KEY, "foo")
|
||||
@@ -239,20 +239,20 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
.build();
|
||||
this.zsetChannel.send(message);
|
||||
|
||||
assertEquals(1, redisZSet.size());
|
||||
assertEquals(Double.valueOf(2), redisZSet.score("bar"));
|
||||
assertThat(redisZSet.size()).isEqualTo(1);
|
||||
assertThat(redisZSet.score("bar")).isEqualTo(Double.valueOf(2));
|
||||
|
||||
this.zsetChannel.send(message);
|
||||
|
||||
assertEquals(1, redisZSet.size());
|
||||
assertEquals(Double.valueOf(4), redisZSet.score("bar"));
|
||||
assertThat(redisZSet.size()).isEqualTo(1);
|
||||
assertThat(redisZSet.score("bar")).isEqualTo(Double.valueOf(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testZsetSimplePayloadOverwriteWithHeaderScore() {
|
||||
RedisZSet<String> redisZSet = new DefaultRedisZSet<String>("foo", this.redisTemplate);
|
||||
assertEquals(0, redisZSet.size());
|
||||
assertThat(redisZSet.size()).isEqualTo(0);
|
||||
|
||||
Message<String> message = MessageBuilder.withPayload("bar")
|
||||
.setHeader(RedisHeaders.KEY, "foo")
|
||||
@@ -261,20 +261,20 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
.build();
|
||||
this.zsetChannel.send(message);
|
||||
|
||||
assertEquals(1, redisZSet.size());
|
||||
assertEquals(Double.valueOf(2), redisZSet.score("bar"));
|
||||
assertThat(redisZSet.size()).isEqualTo(1);
|
||||
assertThat(redisZSet.score("bar")).isEqualTo(Double.valueOf(2));
|
||||
|
||||
this.zsetChannel.send(MessageBuilder.fromMessage(message).setHeader(RedisHeaders.ZSET_SCORE, 15).build());
|
||||
|
||||
assertEquals(1, redisZSet.size());
|
||||
assertEquals(Double.valueOf(15), redisZSet.score("bar"));
|
||||
assertThat(redisZSet.size()).isEqualTo(1);
|
||||
assertThat(redisZSet.score("bar")).isEqualTo(Double.valueOf(15));
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testMapToZsetWithProvidedKey() {
|
||||
RedisZSet<String> redisZset = new DefaultRedisZSet<String>("presidents", this.redisTemplate);
|
||||
assertEquals(0, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(0);
|
||||
|
||||
Map<String, Integer> presidents = new HashMap<String, Integer>();
|
||||
presidents.put("John Adams", 18);
|
||||
@@ -290,21 +290,21 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
|
||||
this.mapToZsetChannel.send(message);
|
||||
|
||||
assertEquals(5, redisZset.size());
|
||||
assertEquals(1, redisZset.rangeByScore(18, 18).size());
|
||||
assertEquals(4, redisZset.rangeByScore(18, 19).size());
|
||||
assertEquals(1, redisZset.rangeByScore(21, 21).size());
|
||||
assertThat(redisZset.size()).isEqualTo(5);
|
||||
assertThat(redisZset.rangeByScore(18, 18).size()).isEqualTo(1);
|
||||
assertThat(redisZset.rangeByScore(18, 19).size()).isEqualTo(4);
|
||||
assertThat(redisZset.rangeByScore(21, 21).size()).isEqualTo(1);
|
||||
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
this.beanFactory.getBean("mapToZset.handler", RedisStoreWritingMessageHandler.class);
|
||||
assertEquals("'presidents'", TestUtils.getPropertyValue(handler, "keyExpression.expression"));
|
||||
assertThat(TestUtils.getPropertyValue(handler, "keyExpression.expression")).isEqualTo("'presidents'");
|
||||
|
||||
this.mapToZsetChannel.send(message);
|
||||
|
||||
assertEquals(5, redisZset.size());
|
||||
assertEquals(1, redisZset.rangeByScore(36, 36).size());
|
||||
assertEquals(4, redisZset.rangeByScore(36, 38).size());
|
||||
assertEquals(1, redisZset.rangeByScore(42, 42).size());
|
||||
assertThat(redisZset.size()).isEqualTo(5);
|
||||
assertThat(redisZset.rangeByScore(36, 36).size()).isEqualTo(1);
|
||||
assertThat(redisZset.rangeByScore(36, 38).size()).isEqualTo(4);
|
||||
assertThat(redisZset.rangeByScore(42, 42).size()).isEqualTo(1);
|
||||
|
||||
// test overwrite score behavior
|
||||
presidents.put("Barack Obama", 31);
|
||||
@@ -313,10 +313,10 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
.setHeader(RedisHeaders.ZSET_INCREMENT_SCORE, false)
|
||||
.build());
|
||||
|
||||
assertEquals(5, redisZset.size());
|
||||
assertEquals(1, redisZset.rangeByScore(18, 18).size());
|
||||
assertEquals(4, redisZset.rangeByScore(18, 19).size());
|
||||
assertEquals(1, redisZset.rangeByScore(31, 31).size());
|
||||
assertThat(redisZset.size()).isEqualTo(5);
|
||||
assertThat(redisZset.rangeByScore(18, 18).size()).isEqualTo(1);
|
||||
assertThat(redisZset.rangeByScore(18, 19).size()).isEqualTo(4);
|
||||
assertThat(redisZset.rangeByScore(31, 31).size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -324,7 +324,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
public void testMapToMapWithProvidedKey() {
|
||||
RedisMap<String, String> redisMap = new DefaultRedisMap<String, String>("pepboys", this.redisTemplate);
|
||||
|
||||
assertEquals(0, redisMap.size());
|
||||
assertThat(redisMap.size()).isEqualTo(0);
|
||||
|
||||
Map<String, String> pepboys = new HashMap<String, String>();
|
||||
pepboys.put("1", "Manny");
|
||||
@@ -333,16 +333,16 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
|
||||
Message<Map<String, String>> message = MessageBuilder.withPayload(pepboys).build();
|
||||
this.mapToMapAChannel.send(message);
|
||||
assertEquals("Manny", redisMap.get("1"));
|
||||
assertEquals("Moe", redisMap.get("2"));
|
||||
assertEquals("Jack", redisMap.get("3"));
|
||||
assertThat(redisMap.get("1")).isEqualTo("Manny");
|
||||
assertThat(redisMap.get("2")).isEqualTo("Moe");
|
||||
assertThat(redisMap.get("3")).isEqualTo("Jack");
|
||||
|
||||
RedisStoreWritingMessageHandler handler = this.beanFactory.getBean("mapToMapA.handler",
|
||||
RedisStoreWritingMessageHandler.class);
|
||||
assertEquals("pepboys",
|
||||
TestUtils.getPropertyValue(handler, "keyExpression", LiteralExpression.class).getExpressionString());
|
||||
assertEquals("'foo'",
|
||||
TestUtils.getPropertyValue(handler, "mapKeyExpression", SpelExpression.class).getExpressionString());
|
||||
assertThat(TestUtils.getPropertyValue(handler, "keyExpression", LiteralExpression.class).getExpressionString())
|
||||
.isEqualTo("pepboys");
|
||||
assertThat(TestUtils.getPropertyValue(handler, "mapKeyExpression", SpelExpression.class).getExpressionString())
|
||||
.isEqualTo("'foo'");
|
||||
}
|
||||
|
||||
@Test(expected = MessageHandlingException.class) // map key is not provided
|
||||
@@ -351,7 +351,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
RedisMap<String, Map<String, String>> redisMap =
|
||||
new DefaultRedisMap<String, Map<String, String>>("pepboys", this.redisTemplate);
|
||||
|
||||
assertEquals(0, redisMap.size());
|
||||
assertThat(redisMap.size()).isEqualTo(0);
|
||||
|
||||
Map<String, String> pepboys = new HashMap<String, String>();
|
||||
pepboys.put("1", "Manny");
|
||||
@@ -376,7 +376,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
RedisMap<String, Map<String, String>> redisMap =
|
||||
new DefaultRedisMap<String, Map<String, String>>("pepboys", redisTemplate);
|
||||
|
||||
assertEquals(0, redisMap.size());
|
||||
assertThat(redisMap.size()).isEqualTo(0);
|
||||
|
||||
Map<String, String> pepboys = new HashMap<String, String>();
|
||||
pepboys.put("1", "Manny");
|
||||
@@ -399,7 +399,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
RedisMap<String, Map<String, String>> redisMap =
|
||||
new DefaultRedisMap<String, Map<String, String>>("pepboys", redisTemplate);
|
||||
|
||||
assertEquals(0, redisMap.size());
|
||||
assertThat(redisMap.size()).isEqualTo(0);
|
||||
|
||||
Map<String, String> pepboys = new HashMap<String, String>();
|
||||
pepboys.put("1", "Manny");
|
||||
@@ -411,9 +411,9 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
this.mapToMapBChannel.send(message);
|
||||
Map<String, String> pepboyz = redisMap.get("foo");
|
||||
|
||||
assertEquals("Manny", pepboyz.get("1"));
|
||||
assertEquals("Moe", pepboyz.get("2"));
|
||||
assertEquals("Jack", pepboyz.get("3"));
|
||||
assertThat(pepboyz.get("1")).isEqualTo("Manny");
|
||||
assertThat(pepboyz.get("2")).isEqualTo("Moe");
|
||||
assertThat(pepboyz.get("3")).isEqualTo("Jack");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -421,7 +421,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
public void testStoreSimpleStringInMap() {
|
||||
RedisMap<String, String> redisMap = new DefaultRedisMap<String, String>("bar", this.redisTemplate);
|
||||
|
||||
assertEquals(0, redisMap.size());
|
||||
assertThat(redisMap.size()).isEqualTo(0);
|
||||
|
||||
Message<String> message = MessageBuilder.withPayload("hello, world!").
|
||||
setHeader(RedisHeaders.KEY, "bar").setHeader(RedisHeaders.MAP_KEY, "foo").build();
|
||||
@@ -429,14 +429,14 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
this.simpleMapChannel.send(message);
|
||||
String hello = redisMap.get("foo");
|
||||
|
||||
assertEquals("hello, world!", hello);
|
||||
assertThat(hello).isEqualTo("hello, world!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testSetWithKeyAsHeader() {
|
||||
RedisSet<String> redisSet = new DefaultRedisSet<String>("pepboys", this.redisTemplate);
|
||||
assertEquals(0, redisSet.size());
|
||||
assertThat(redisSet.size()).isEqualTo(0);
|
||||
|
||||
Set<String> pepboys = new HashSet<String>();
|
||||
pepboys.add("Manny");
|
||||
@@ -445,27 +445,27 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
Message<Set<String>> message = MessageBuilder.withPayload(pepboys).setHeader("redis_key", "pepboys").build();
|
||||
this.setChannel.send(message);
|
||||
|
||||
assertEquals(3, redisSet.size());
|
||||
assertThat(redisSet.size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testSetWithKeyAsHeaderSimple() {
|
||||
RedisSet<String> redisSet = new DefaultRedisSet<String>("foo", this.redisTemplate);
|
||||
assertEquals(0, redisSet.size());
|
||||
assertThat(redisSet.size()).isEqualTo(0);
|
||||
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader(RedisHeaders.KEY, "foo").build();
|
||||
this.setChannel.send(message);
|
||||
|
||||
assertEquals(1, redisSet.size());
|
||||
assertThat(redisSet.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testSetWithKeyAsHeaderNotParsed() {
|
||||
RedisSet<String> redisSet = new DefaultRedisSet<String>("pepboys", this.redisTemplate);
|
||||
assertEquals(0, redisSet.size());
|
||||
assertThat(redisSet.size()).isEqualTo(0);
|
||||
|
||||
Set<String> pepboys = new HashSet<String>();
|
||||
pepboys.add("Manny");
|
||||
@@ -474,20 +474,20 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
Message<Set<String>> message = MessageBuilder.withPayload(pepboys).setHeader("redis_key", "pepboys").build();
|
||||
this.setNotParsedChannel.send(message);
|
||||
|
||||
assertEquals(1, redisSet.size());
|
||||
assertThat(redisSet.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testPojoIntoSet() {
|
||||
RedisSet<String> redisSet = new DefaultRedisSet<String>("pepboys", this.redisTemplate);
|
||||
assertEquals(0, redisSet.size());
|
||||
assertThat(redisSet.size()).isEqualTo(0);
|
||||
|
||||
String pepboy = "Manny";
|
||||
Message<String> message = MessageBuilder.withPayload(pepboy).setHeader("redis_key", "pepboys").build();
|
||||
this.pojoIntoSetChannel.send(message);
|
||||
|
||||
assertEquals(1, redisSet.size());
|
||||
assertThat(redisSet.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -495,7 +495,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
public void testProperties() {
|
||||
RedisProperties redisProperties = new RedisProperties("pepboys", this.redisTemplate);
|
||||
|
||||
assertEquals(0, redisProperties.size());
|
||||
assertThat(redisProperties.size()).isEqualTo(0);
|
||||
|
||||
Properties pepboys = new Properties();
|
||||
pepboys.put("1", "Manny");
|
||||
@@ -505,9 +505,9 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
Message<Properties> message = MessageBuilder.withPayload(pepboys).build();
|
||||
this.propertyChannel.send(message);
|
||||
|
||||
assertEquals("Manny", redisProperties.get("1"));
|
||||
assertEquals("Moe", redisProperties.get("2"));
|
||||
assertEquals("Jack", redisProperties.get("3"));
|
||||
assertThat(redisProperties.get("1")).isEqualTo("Manny");
|
||||
assertThat(redisProperties.get("2")).isEqualTo("Moe");
|
||||
assertThat(redisProperties.get("3")).isEqualTo("Jack");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -515,7 +515,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
public void testPropertiesSimple() {
|
||||
RedisProperties redisProperties = new RedisProperties("foo", this.redisTemplate);
|
||||
|
||||
assertEquals(0, redisProperties.size());
|
||||
assertThat(redisProperties.size()).isEqualTo(0);
|
||||
|
||||
Message<String> message = MessageBuilder.withPayload("bar")
|
||||
.setHeader(RedisHeaders.KEY, "foo")
|
||||
@@ -523,7 +523,7 @@ public class RedisStoreOutboundChannelAdapterIntegrationTests extends RedisAvail
|
||||
.build();
|
||||
this.simplePropertyChannel.send(message);
|
||||
|
||||
assertEquals("bar", redisProperties.get("qux"));
|
||||
assertThat(redisProperties.get("qux")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.outbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -68,7 +67,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisList<String> redisList =
|
||||
new DefaultRedisList<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
|
||||
|
||||
assertEquals(0, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(0);
|
||||
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
new RedisStoreWritingMessageHandler(jcf);
|
||||
@@ -83,10 +82,10 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
Message<List<String>> message = new GenericMessage<List<String>>(list);
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(3, redisList.size());
|
||||
assertEquals("Manny", redisList.get(0));
|
||||
assertEquals("Moe", redisList.get(1));
|
||||
assertEquals("Jack", redisList.get(2));
|
||||
assertThat(redisList.size()).isEqualTo(3);
|
||||
assertThat(redisList.get(0)).isEqualTo("Manny");
|
||||
assertThat(redisList.get(1)).isEqualTo("Moe");
|
||||
assertThat(redisList.get(2)).isEqualTo("Jack");
|
||||
this.deleteKey(jcf, "foo");
|
||||
}
|
||||
|
||||
@@ -99,7 +98,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisList<String> redisList =
|
||||
new DefaultRedisList<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
|
||||
|
||||
assertEquals(0, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(0);
|
||||
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
new RedisStoreWritingMessageHandler(jcf);
|
||||
@@ -114,10 +113,10 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
Message<List<String>> message = MessageBuilder.withPayload(list).setHeader("redis_key", key).build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(3, redisList.size());
|
||||
assertEquals("Manny", redisList.get(0));
|
||||
assertEquals("Moe", redisList.get(1));
|
||||
assertEquals("Jack", redisList.get(2));
|
||||
assertThat(redisList.size()).isEqualTo(3);
|
||||
assertThat(redisList.get(0)).isEqualTo("Manny");
|
||||
assertThat(redisList.get(1)).isEqualTo("Moe");
|
||||
assertThat(redisList.get(2)).isEqualTo("Jack");
|
||||
this.deleteKey(jcf, "foo");
|
||||
}
|
||||
|
||||
@@ -130,7 +129,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisList<String> redisList =
|
||||
new DefaultRedisList<String>(key, this.initTemplate(jcf, new RedisTemplate<String, String>()));
|
||||
|
||||
assertEquals(0, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(0);
|
||||
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
new RedisStoreWritingMessageHandler(jcf);
|
||||
@@ -155,7 +154,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisList<List<String>> redisList =
|
||||
new DefaultRedisList<List<String>>(key, this.initTemplate(jcf, new RedisTemplate<String, List<String>>()));
|
||||
|
||||
assertEquals(0, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(0);
|
||||
|
||||
RedisTemplate<String, List<String>> template = this.initTemplate(jcf, new RedisTemplate<String, List<String>>());
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
@@ -172,11 +171,11 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
Message<List<String>> message = new GenericMessage<List<String>>(list);
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(1, redisList.size());
|
||||
assertThat(redisList.size()).isEqualTo(1);
|
||||
List<String> resultList = redisList.get(0);
|
||||
assertEquals("Manny", resultList.get(0));
|
||||
assertEquals("Moe", resultList.get(1));
|
||||
assertEquals("Jack", resultList.get(2));
|
||||
assertThat(resultList.get(0)).isEqualTo("Manny");
|
||||
assertThat(resultList.get(1)).isEqualTo("Moe");
|
||||
assertThat(resultList.get(2)).isEqualTo("Jack");
|
||||
this.deleteKey(jcf, "foo");
|
||||
}
|
||||
|
||||
@@ -189,7 +188,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisZSet<String> redisZset =
|
||||
new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
|
||||
|
||||
assertEquals(0, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(0);
|
||||
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
new RedisStoreWritingMessageHandler(jcf);
|
||||
@@ -207,18 +206,18 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
.build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(3, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(3);
|
||||
Set<TypedTuple<String>> pepboys = redisZset.rangeByScoreWithScores(1, 1);
|
||||
for (TypedTuple<String> pepboy : pepboys) {
|
||||
assertTrue(pepboy.getScore() == 1);
|
||||
assertThat(pepboy.getScore() == 1).isTrue();
|
||||
}
|
||||
|
||||
handler.handleMessage(message);
|
||||
assertEquals(3, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(3);
|
||||
pepboys = redisZset.rangeByScoreWithScores(1, 2);
|
||||
// should have incremented by 1
|
||||
for (TypedTuple<String> pepboy : pepboys) {
|
||||
assertEquals(Double.valueOf(2), pepboy.getScore());
|
||||
assertThat(pepboy.getScore()).isEqualTo(Double.valueOf(2));
|
||||
}
|
||||
this.deleteKey(jcf, "foo");
|
||||
}
|
||||
@@ -232,7 +231,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisZSet<String> redisZset =
|
||||
new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
|
||||
|
||||
assertEquals(0, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(0);
|
||||
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
new RedisStoreWritingMessageHandler(jcf);
|
||||
@@ -251,18 +250,18 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(3, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(3);
|
||||
Set<TypedTuple<String>> pepboys = redisZset.rangeByScoreWithScores(1, 1);
|
||||
for (TypedTuple<String> pepboy : pepboys) {
|
||||
assertTrue(pepboy.getScore() == 1);
|
||||
assertThat(pepboy.getScore() == 1).isTrue();
|
||||
}
|
||||
|
||||
handler.handleMessage(message);
|
||||
assertEquals(3, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(3);
|
||||
pepboys = redisZset.rangeByScoreWithScores(1, 2);
|
||||
// should have incremented
|
||||
for (TypedTuple<String> pepboy : pepboys) {
|
||||
assertTrue(pepboy.getScore() == 2);
|
||||
assertThat(pepboy.getScore() == 2).isTrue();
|
||||
}
|
||||
this.deleteKey(jcf, "foo");
|
||||
}
|
||||
@@ -276,7 +275,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisZSet<String> redisZset =
|
||||
new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
|
||||
|
||||
assertEquals(0, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(0);
|
||||
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
new RedisStoreWritingMessageHandler(jcf);
|
||||
@@ -295,18 +294,18 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(3, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(3);
|
||||
Set<TypedTuple<String>> pepboys = redisZset.rangeByScoreWithScores(1, 1);
|
||||
for (TypedTuple<String> pepboy : pepboys) {
|
||||
assertTrue(pepboy.getScore() == 1);
|
||||
assertThat(pepboy.getScore() == 1).isTrue();
|
||||
}
|
||||
|
||||
handler.handleMessage(message);
|
||||
assertEquals(3, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(3);
|
||||
pepboys = redisZset.rangeByScoreWithScores(1, 2);
|
||||
// should have incremented
|
||||
for (TypedTuple<String> pepboy : pepboys) {
|
||||
assertTrue(pepboy.getScore() == 2);
|
||||
assertThat(pepboy.getScore() == 2).isTrue();
|
||||
}
|
||||
this.deleteKey(jcf, "foo");
|
||||
}
|
||||
@@ -320,7 +319,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisZSet<List<String>> redisZset =
|
||||
new DefaultRedisZSet<List<String>>(key, this.initTemplate(jcf, new RedisTemplate<String, List<String>>()));
|
||||
|
||||
assertEquals(0, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(0);
|
||||
|
||||
RedisTemplate<String, List<String>> template = this.initTemplate(jcf, new RedisTemplate<String, List<String>>());
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
@@ -339,10 +338,10 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
setHeader("redis_zsetScore", 4).build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(1, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(1);
|
||||
Set<TypedTuple<List<String>>> entries = redisZset.rangeByScoreWithScores(1, 4);
|
||||
for (TypedTuple<List<String>> pepboys : entries) {
|
||||
assertTrue(pepboys.getScore() == 4);
|
||||
assertThat(pepboys.getScore() == 4).isTrue();
|
||||
}
|
||||
this.deleteKey(jcf, "foo");
|
||||
}
|
||||
@@ -356,7 +355,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisZSet<String> redisZset =
|
||||
new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
|
||||
|
||||
assertEquals(0, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(0);
|
||||
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
new RedisStoreWritingMessageHandler(jcf);
|
||||
@@ -385,10 +384,10 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
Message<Map<String, Double>> message = MessageBuilder.withPayload(presidents).setHeader("redis_key", key).build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(13, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(13);
|
||||
|
||||
Set<TypedTuple<String>> entries = redisZset.rangeByScoreWithScores(18, 19);
|
||||
assertEquals(6, entries.size());
|
||||
assertThat(entries.size()).isEqualTo(6);
|
||||
this.deletePresidents(jcf);
|
||||
}
|
||||
|
||||
@@ -401,7 +400,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisZSet<President> redisZset =
|
||||
new DefaultRedisZSet<President>(key, this.initTemplate(jcf, new RedisTemplate<String, President>()));
|
||||
|
||||
assertEquals(0, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(0);
|
||||
|
||||
RedisTemplate<String, President> template = this.initTemplate(jcf, new RedisTemplate<String, President>());
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
@@ -431,10 +430,10 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
Message<Map<President, Double>> message = MessageBuilder.withPayload(presidents).setHeader("redis_key", key).build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(13, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(13);
|
||||
|
||||
Set<TypedTuple<President>> entries = redisZset.rangeByScoreWithScores(18, 19);
|
||||
assertEquals(6, entries.size());
|
||||
assertThat(entries.size()).isEqualTo(6);
|
||||
this.deletePresidents(jcf);
|
||||
}
|
||||
|
||||
@@ -447,7 +446,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
RedisZSet<Map<President, Double>> redisZset =
|
||||
new DefaultRedisZSet<Map<President, Double>>(key, this.initTemplate(jcf, new RedisTemplate<String, Map<President, Double>>()));
|
||||
|
||||
assertEquals(0, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(0);
|
||||
|
||||
RedisTemplate<String, Map<President, Double>> template = this.initTemplate(jcf, new RedisTemplate<String, Map<President, Double>>());
|
||||
RedisStoreWritingMessageHandler handler =
|
||||
@@ -467,7 +466,7 @@ public class RedisStoreWritingMessageHandlerTests extends RedisAvailableTests {
|
||||
Message<Map<President, Double>> message = MessageBuilder.withPayload(presidents).setHeader("redis_key", key).build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
assertEquals(1, redisZset.size());
|
||||
assertThat(redisZset.size()).isEqualTo(1);
|
||||
this.deletePresidents(jcf);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.rules;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -69,16 +68,18 @@ public abstract class RedisAvailableTests {
|
||||
int n = 0;
|
||||
while (n++ < 300 &&
|
||||
(connection =
|
||||
TestUtils.getPropertyValue(container, "subscriptionTask.connection", RedisConnection.class)) == null) {
|
||||
TestUtils.getPropertyValue(container, "subscriptionTask.connection", RedisConnection.class))
|
||||
== null) {
|
||||
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertNotNull("RedisMessageListenerContainer Failed to Connect", connection);
|
||||
assertThat(connection).as("RedisMessageListenerContainer Failed to Connect").isNotNull();
|
||||
|
||||
n = 0;
|
||||
while (n++ < 300 && !connection.isSubscribed()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertTrue("RedisMessageListenerContainer Failed to Subscribe", n < 300);
|
||||
assertThat(n < 300).as("RedisMessageListenerContainer Failed to Subscribe").isTrue();
|
||||
}
|
||||
|
||||
protected void awaitContainerSubscribedWithPatterns(RedisMessageListenerContainer container) throws Exception {
|
||||
@@ -90,7 +91,7 @@ public abstract class RedisAvailableTests {
|
||||
while (n++ < 300 && connection.getSubscription().getPatterns().size() == 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertTrue("RedisMessageListenerContainer Failed to Subscribe with patterns", n < 300);
|
||||
assertThat(n < 300).as("RedisMessageListenerContainer Failed to Subscribe with patterns").isTrue();
|
||||
// wait another second because of race condition
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
@@ -106,7 +107,7 @@ public abstract class RedisAvailableTests {
|
||||
received = channel.receive(1000);
|
||||
}
|
||||
drain(channel);
|
||||
assertNotNull("Container failed to fully start", received);
|
||||
assertThat(received).as("Container failed to fully start").isNotNull();
|
||||
}
|
||||
|
||||
private void drain(QueueChannel channel) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
* Copyright 2013-2019 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.
|
||||
@@ -16,11 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.store;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -86,42 +83,43 @@ public class DelayerHandlerRescheduleIntegrationTests extends RedisAvailableTest
|
||||
fail("IllegalStateException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue(e instanceof IllegalStateException);
|
||||
assertTrue(e.getMessage().contains("BeanFactory not initialized or already closed - call 'refresh'"));
|
||||
assertThat(e instanceof IllegalStateException).isTrue();
|
||||
assertThat(e.getMessage().contains("BeanFactory not initialized or already closed - call 'refresh'"))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
assertEquals(1, messageStore.getMessageGroupCount());
|
||||
assertEquals(delayerMessageGroupId, messageStore.iterator().next().getGroupId());
|
||||
assertEquals(2, messageStore.messageGroupSize(delayerMessageGroupId));
|
||||
assertEquals(2, messageStore.getMessageCountForAllMessageGroups());
|
||||
assertThat(messageStore.getMessageGroupCount()).isEqualTo(1);
|
||||
assertThat(messageStore.iterator().next().getGroupId()).isEqualTo(delayerMessageGroupId);
|
||||
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(2);
|
||||
assertThat(messageStore.getMessageCountForAllMessageGroups()).isEqualTo(2);
|
||||
MessageGroup messageGroup = messageStore.getMessageGroup(delayerMessageGroupId);
|
||||
Message<?> messageInStore = messageGroup.getMessages().iterator().next();
|
||||
Object payload = messageInStore.getPayload();
|
||||
|
||||
// INT-3049
|
||||
assertTrue(payload instanceof DelayHandler.DelayedMessageWrapper);
|
||||
assertEquals(message1, ((DelayHandler.DelayedMessageWrapper) payload).getOriginal());
|
||||
assertThat(payload instanceof DelayHandler.DelayedMessageWrapper).isTrue();
|
||||
assertThat(((DelayHandler.DelayedMessageWrapper) payload).getOriginal()).isEqualTo(message1);
|
||||
|
||||
context.refresh();
|
||||
|
||||
PollableChannel output = context.getBean("output", PollableChannel.class);
|
||||
|
||||
Message<?> message = output.receive(20000);
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
|
||||
Object payload1 = message.getPayload();
|
||||
|
||||
message = output.receive(20000);
|
||||
assertNotNull(message);
|
||||
assertThat(message).isNotNull();
|
||||
Object payload2 = message.getPayload();
|
||||
assertNotSame(payload1, payload2);
|
||||
assertThat(payload2).isNotSameAs(payload1);
|
||||
|
||||
assertEquals(1, messageStore.getMessageGroupCount());
|
||||
assertThat(messageStore.getMessageGroupCount()).isEqualTo(1);
|
||||
int n = 0;
|
||||
while (n++ < 300 && messageStore.messageGroupSize(delayerMessageGroupId) > 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
|
||||
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(0);
|
||||
|
||||
messageStore.removeMessageGroup(delayerMessageGroupId);
|
||||
context.close();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -16,12 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.store;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -85,38 +81,38 @@ public class RedisChannelMessageStoreTests extends RedisAvailableTests {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
this.testChannel1.send(new GenericMessage<Integer>(i));
|
||||
}
|
||||
assertEquals(1, this.cms.getMessageGroupCount());
|
||||
assertEquals(10, this.cms.messageGroupSize("cms:testChannel1"));
|
||||
assertEquals(10, this.cms.getMessageGroup("cms:testChannel1").size());
|
||||
assertThat(this.cms.getMessageGroupCount()).isEqualTo(1);
|
||||
assertThat(this.cms.messageGroupSize("cms:testChannel1")).isEqualTo(10);
|
||||
assertThat(this.cms.getMessageGroup("cms:testChannel1").size()).isEqualTo(10);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
this.testChannel2.send(MutableMessageBuilder.withPayload(i).build());
|
||||
}
|
||||
assertEquals(2, this.cms.getMessageGroupCount());
|
||||
assertEquals(10, this.cms.messageGroupSize("cms:testChannel2"));
|
||||
assertEquals(10, this.cms.getMessageGroup("cms:testChannel2").size());
|
||||
assertEquals(20, this.cms.getMessageCountForAllMessageGroups());
|
||||
assertThat(this.cms.getMessageGroupCount()).isEqualTo(2);
|
||||
assertThat(this.cms.messageGroupSize("cms:testChannel2")).isEqualTo(10);
|
||||
assertThat(this.cms.getMessageGroup("cms:testChannel2").size()).isEqualTo(10);
|
||||
assertThat(this.cms.getMessageCountForAllMessageGroups()).isEqualTo(20);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Message<?> out = this.testChannel1.receive(0);
|
||||
assertThat(out, Matchers.instanceOf(GenericMessage.class));
|
||||
assertEquals(i, out.getPayload());
|
||||
assertThat(out).isInstanceOf(GenericMessage.class);
|
||||
assertThat(out.getPayload()).isEqualTo(i);
|
||||
}
|
||||
assertNull(this.testChannel1.receive(0));
|
||||
assertThat(this.testChannel1.receive(0)).isNull();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Message<?> out = this.testChannel2.receive(0);
|
||||
assertEquals("org.springframework.integration.support.MutableMessage", out.getClass().getName());
|
||||
assertEquals(i, out.getPayload());
|
||||
assertThat(out.getClass().getName()).isEqualTo("org.springframework.integration.support.MutableMessage");
|
||||
assertThat(out.getPayload()).isEqualTo(i);
|
||||
}
|
||||
assertNull(this.testChannel2.receive(0));
|
||||
assertEquals(0, this.cms.getMessageGroupCount());
|
||||
assertThat(this.testChannel2.receive(0)).isNull();
|
||||
assertThat(this.cms.getMessageGroupCount()).isEqualTo(0);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
this.testChannel1.send(new GenericMessage<Integer>(i));
|
||||
}
|
||||
assertEquals(1, this.cms.getMessageGroupCount());
|
||||
assertEquals(10, this.cms.messageGroupSize("cms:testChannel1"));
|
||||
assertThat(this.cms.getMessageGroupCount()).isEqualTo(1);
|
||||
assertThat(this.cms.messageGroupSize("cms:testChannel1")).isEqualTo(10);
|
||||
this.cms.removeMessageGroup("cms:testChannel1");
|
||||
assertEquals(0, this.cms.getMessageGroupCount());
|
||||
assertEquals(0, this.cms.messageGroupSize("cms:testChannel1"));
|
||||
assertThat(this.cms.getMessageGroupCount()).isEqualTo(0);
|
||||
assertThat(this.cms.messageGroupSize("cms:testChannel1")).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,53 +125,53 @@ public class RedisChannelMessageStoreTests extends RedisAvailableTests {
|
||||
}
|
||||
this.testChannel3.send(MessageBuilder.withPayload(99).setPriority(199).build());
|
||||
this.testChannel3.send(MessageBuilder.withPayload(98).build());
|
||||
assertEquals(1, this.priorityCms.getMessageGroupCount());
|
||||
assertEquals(22, this.priorityCms.messageGroupSize("priorityCms:testChannel3"));
|
||||
assertEquals(22, this.priorityCms.getMessageCountForAllMessageGroups());
|
||||
assertEquals(22, this.priorityCms.getMessageGroup("priorityCms:testChannel3").size());
|
||||
assertThat(this.priorityCms.getMessageGroupCount()).isEqualTo(1);
|
||||
assertThat(this.priorityCms.messageGroupSize("priorityCms:testChannel3")).isEqualTo(22);
|
||||
assertThat(this.priorityCms.getMessageCountForAllMessageGroups()).isEqualTo(22);
|
||||
assertThat(this.priorityCms.getMessageGroup("priorityCms:testChannel3").size()).isEqualTo(22);
|
||||
this.testChannel4.send(MessageBuilder.withPayload(98).build());
|
||||
this.testChannel4.send(MessageBuilder.withPayload(99).setPriority(5).build());
|
||||
assertEquals(2, this.priorityCms.getMessageGroupCount());
|
||||
assertEquals(2, this.priorityCms.getMessageGroup("priorityCms:testChannel4").size());
|
||||
assertEquals(2, this.priorityCms.messageGroupSize("priorityCms:testChannel4"));
|
||||
assertEquals(24, this.priorityCms.getMessageCountForAllMessageGroups());
|
||||
assertThat(this.priorityCms.getMessageGroupCount()).isEqualTo(2);
|
||||
assertThat(this.priorityCms.getMessageGroup("priorityCms:testChannel4").size()).isEqualTo(2);
|
||||
assertThat(this.priorityCms.messageGroupSize("priorityCms:testChannel4")).isEqualTo(2);
|
||||
assertThat(this.priorityCms.getMessageCountForAllMessageGroups()).isEqualTo(24);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Message<?> m = this.testChannel3.receive(0);
|
||||
assertNotNull(m);
|
||||
assertEquals(Integer.valueOf(9 - i), new IntegrationMessageHeaderAccessor(m).getPriority());
|
||||
assertThat(m).isNotNull();
|
||||
assertThat(new IntegrationMessageHeaderAccessor(m).getPriority()).isEqualTo(Integer.valueOf(9 - i));
|
||||
m = this.testChannel3.receive(0);
|
||||
assertNotNull(m);
|
||||
assertEquals(Integer.valueOf(9 - i), new IntegrationMessageHeaderAccessor(m).getPriority());
|
||||
assertThat(m).isNotNull();
|
||||
assertThat(new IntegrationMessageHeaderAccessor(m).getPriority()).isEqualTo(Integer.valueOf(9 - i));
|
||||
}
|
||||
Message<?> m = this.testChannel3.receive(0);
|
||||
assertNotNull(m);
|
||||
assertEquals(Integer.valueOf(199), new IntegrationMessageHeaderAccessor(m).getPriority());
|
||||
assertEquals(99, m.getPayload());
|
||||
assertThat(m).isNotNull();
|
||||
assertThat(new IntegrationMessageHeaderAccessor(m).getPriority()).isEqualTo(Integer.valueOf(199));
|
||||
assertThat(m.getPayload()).isEqualTo(99);
|
||||
m = this.testChannel3.receive(0);
|
||||
assertNotNull(m);
|
||||
assertNull(new IntegrationMessageHeaderAccessor(m).getPriority());
|
||||
assertEquals(98, m.getPayload());
|
||||
assertEquals(0, this.priorityCms.messageGroupSize("priorityCms:testChannel3"));
|
||||
assertThat(m).isNotNull();
|
||||
assertThat(new IntegrationMessageHeaderAccessor(m).getPriority()).isNull();
|
||||
assertThat(m.getPayload()).isEqualTo(98);
|
||||
assertThat(this.priorityCms.messageGroupSize("priorityCms:testChannel3")).isEqualTo(0);
|
||||
|
||||
m = this.testChannel4.receive(0);
|
||||
assertNotNull(m);
|
||||
assertEquals(Integer.valueOf(5), new IntegrationMessageHeaderAccessor(m).getPriority());
|
||||
assertThat(m).isNotNull();
|
||||
assertThat(new IntegrationMessageHeaderAccessor(m).getPriority()).isEqualTo(Integer.valueOf(5));
|
||||
m = this.testChannel4.receive(0);
|
||||
assertNotNull(m);
|
||||
assertNull(new IntegrationMessageHeaderAccessor(m).getPriority());
|
||||
assertEquals(0, this.priorityCms.getMessageGroupCount());
|
||||
assertEquals(0, this.priorityCms.getMessageCountForAllMessageGroups());
|
||||
assertNull(this.testChannel3.receive(0));
|
||||
assertNull(this.testChannel4.receive(0));
|
||||
assertThat(m).isNotNull();
|
||||
assertThat(new IntegrationMessageHeaderAccessor(m).getPriority()).isNull();
|
||||
assertThat(this.priorityCms.getMessageGroupCount()).isEqualTo(0);
|
||||
assertThat(this.priorityCms.getMessageCountForAllMessageGroups()).isEqualTo(0);
|
||||
assertThat(this.testChannel3.receive(0)).isNull();
|
||||
assertThat(this.testChannel4.receive(0)).isNull();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
this.testChannel3.send(new GenericMessage<Integer>(i));
|
||||
}
|
||||
assertEquals(1, this.priorityCms.getMessageGroupCount());
|
||||
assertEquals(10, this.priorityCms.messageGroupSize("priorityCms:testChannel3"));
|
||||
assertThat(this.priorityCms.getMessageGroupCount()).isEqualTo(1);
|
||||
assertThat(this.priorityCms.messageGroupSize("priorityCms:testChannel3")).isEqualTo(10);
|
||||
this.priorityCms.removeMessageGroup("priorityCms:testChannel3");
|
||||
assertEquals(0, this.priorityCms.getMessageGroupCount());
|
||||
assertEquals(0, this.priorityCms.messageGroupSize("priorityCms:testChannel3"));
|
||||
assertThat(this.priorityCms.getMessageGroupCount()).isEqualTo(0);
|
||||
assertThat(this.priorityCms.messageGroupSize("priorityCms:testChannel3")).isEqualTo(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2018 the original author or authors.
|
||||
* Copyright 2007-2019 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.
|
||||
@@ -16,15 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.store;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -88,9 +81,9 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
RedisMessageStore store = new RedisMessageStore(jcf);
|
||||
|
||||
MessageGroup messageGroup = store.getMessageGroup(this.groupId);
|
||||
assertNotNull(messageGroup);
|
||||
assertTrue(messageGroup instanceof SimpleMessageGroup);
|
||||
assertEquals(0, messageGroup.size());
|
||||
assertThat(messageGroup).isNotNull();
|
||||
assertThat(messageGroup instanceof SimpleMessageGroup).isTrue();
|
||||
assertThat(messageGroup.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,22 +94,22 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
|
||||
Message<?> message = new GenericMessage<>("Hello");
|
||||
MessageGroup messageGroup = store.addMessageToGroup(this.groupId, message);
|
||||
assertEquals(1, messageGroup.size());
|
||||
assertThat(messageGroup.size()).isEqualTo(1);
|
||||
long createdTimestamp = messageGroup.getTimestamp();
|
||||
long updatedTimestamp = messageGroup.getLastModified();
|
||||
assertEquals(createdTimestamp, updatedTimestamp);
|
||||
assertThat(updatedTimestamp).isEqualTo(createdTimestamp);
|
||||
Thread.sleep(10);
|
||||
message = new GenericMessage<>("Hello");
|
||||
messageGroup = store.addMessageToGroup(this.groupId, message);
|
||||
createdTimestamp = messageGroup.getTimestamp();
|
||||
updatedTimestamp = messageGroup.getLastModified();
|
||||
assertTrue(updatedTimestamp > createdTimestamp);
|
||||
assertThat(updatedTimestamp > createdTimestamp).isTrue();
|
||||
|
||||
// make sure the store is properly rebuild from Redis
|
||||
store = new RedisMessageStore(jcf);
|
||||
|
||||
messageGroup = store.getMessageGroup(this.groupId);
|
||||
assertEquals(2, messageGroup.size());
|
||||
assertThat(messageGroup.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,13 +120,13 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
|
||||
Message<?> message = new GenericMessage<>("Hello");
|
||||
MessageGroup messageGroup = store.addMessageToGroup(this.groupId, message);
|
||||
assertEquals(1, messageGroup.size());
|
||||
assertThat(messageGroup.size()).isEqualTo(1);
|
||||
|
||||
// make sure the store is properly rebuild from Redis
|
||||
store = new RedisMessageStore(jcf);
|
||||
|
||||
messageGroup = store.getMessageGroup(this.groupId);
|
||||
assertEquals(1, messageGroup.size());
|
||||
assertThat(messageGroup.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,22 +138,22 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
MessageGroup messageGroup = store.getMessageGroup(this.groupId);
|
||||
Message<?> message = new GenericMessage<>("Hello");
|
||||
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
|
||||
assertEquals(1, messageGroup.size());
|
||||
assertThat(messageGroup.size()).isEqualTo(1);
|
||||
|
||||
store.removeMessageGroup(this.groupId);
|
||||
MessageGroup messageGroupA = store.getMessageGroup(this.groupId);
|
||||
assertNotSame(messageGroup, messageGroupA);
|
||||
assertThat(messageGroupA).isNotSameAs(messageGroup);
|
||||
// assertEquals(0, messageGroupA.getMarked().size());
|
||||
assertEquals(0, messageGroupA.getMessages().size());
|
||||
assertEquals(0, messageGroupA.size());
|
||||
assertThat(messageGroupA.getMessages().size()).isEqualTo(0);
|
||||
assertThat(messageGroupA.size()).isEqualTo(0);
|
||||
|
||||
// make sure the store is properly rebuild from Redis
|
||||
store = new RedisMessageStore(jcf);
|
||||
|
||||
messageGroup = store.getMessageGroup(this.groupId);
|
||||
|
||||
assertEquals(0, messageGroup.getMessages().size());
|
||||
assertEquals(0, messageGroup.size());
|
||||
assertThat(messageGroup.getMessages().size()).isEqualTo(0);
|
||||
assertThat(messageGroup.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,7 +167,7 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
|
||||
store.completeGroup(messageGroup.getGroupId());
|
||||
messageGroup = store.getMessageGroup(this.groupId);
|
||||
assertTrue(messageGroup.isComplete());
|
||||
assertThat(messageGroup.isComplete()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -188,7 +181,7 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
|
||||
store.setLastReleasedSequenceNumberForGroup(messageGroup.getGroupId(), 5);
|
||||
messageGroup = store.getMessageGroup(this.groupId);
|
||||
assertEquals(5, messageGroup.getLastReleasedMessageSequenceNumber());
|
||||
assertThat(messageGroup.getLastReleasedMessageSequenceNumber()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,17 +194,17 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
Message<?> message = new GenericMessage<>("2");
|
||||
store.addMessagesToGroup(messageGroup.getGroupId(), new GenericMessage<>("1"), message);
|
||||
messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), new GenericMessage<>("3"));
|
||||
assertEquals(3, messageGroup.size());
|
||||
assertThat(messageGroup.size()).isEqualTo(3);
|
||||
|
||||
store.removeMessagesFromGroup(this.groupId, message);
|
||||
messageGroup = store.getMessageGroup(this.groupId);
|
||||
assertEquals(2, messageGroup.size());
|
||||
assertThat(messageGroup.size()).isEqualTo(2);
|
||||
|
||||
// make sure the store is properly rebuild from Redis
|
||||
store = new RedisMessageStore(jcf);
|
||||
|
||||
messageGroup = store.getMessageGroup(this.groupId);
|
||||
assertEquals(2, messageGroup.size());
|
||||
assertThat(messageGroup.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -233,11 +226,11 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
message = store.getMessageGroup(this.groupId).getMessages().iterator().next();
|
||||
|
||||
MessageHistory messageHistory = MessageHistory.read(message);
|
||||
assertNotNull(messageHistory);
|
||||
assertEquals(2, messageHistory.size());
|
||||
assertThat(messageHistory).isNotNull();
|
||||
assertThat(messageHistory.size()).isEqualTo(2);
|
||||
Properties fooChannelHistory = messageHistory.get(0);
|
||||
assertEquals("fooChannel", fooChannelHistory.get("name"));
|
||||
assertEquals("channel", fooChannelHistory.get("type"));
|
||||
assertThat(fooChannelHistory.get("name")).isEqualTo("fooChannel");
|
||||
assertThat(fooChannelHistory.get("type")).isEqualTo("channel");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,14 +267,14 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
store1.addMessagesToGroup(this.groupId, message);
|
||||
MessageGroup messageGroup = store2.addMessageToGroup(this.groupId, new GenericMessage<>("2"));
|
||||
|
||||
assertEquals(2, messageGroup.getMessages().size());
|
||||
assertThat(messageGroup.getMessages().size()).isEqualTo(2);
|
||||
|
||||
RedisMessageStore store3 = new RedisMessageStore(jcf);
|
||||
|
||||
store3.removeMessagesFromGroup(this.groupId, message);
|
||||
messageGroup = store3.getMessageGroup(this.groupId);
|
||||
|
||||
assertEquals(1, messageGroup.getMessages().size());
|
||||
assertThat(messageGroup.getMessages().size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -307,17 +300,17 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
MessageGroup group = messageGroups.next();
|
||||
String groupId = (String) group.getGroupId();
|
||||
if (groupId.equals("1")) {
|
||||
assertEquals(1, group.getMessages().size());
|
||||
assertThat(group.getMessages().size()).isEqualTo(1);
|
||||
}
|
||||
else if (groupId.equals("2")) {
|
||||
assertEquals(1, group.getMessages().size());
|
||||
assertThat(group.getMessages().size()).isEqualTo(1);
|
||||
}
|
||||
else if (groupId.equals("3")) {
|
||||
assertEquals(2, group.getMessages().size());
|
||||
assertThat(group.getMessages().size()).isEqualTo(2);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
assertEquals(3, counter);
|
||||
assertThat(counter).isEqualTo(3);
|
||||
|
||||
store2.removeMessageGroup(group3);
|
||||
|
||||
@@ -327,7 +320,7 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
messageGroups.next();
|
||||
counter++;
|
||||
}
|
||||
assertEquals(2, counter);
|
||||
assertThat(counter).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -369,7 +362,7 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
executor.awaitTermination(10, TimeUnit.SECONDS);
|
||||
store2.removeMessagesFromGroup(1, message); // ensures that if ADD thread executed after REMOVE, the store is empty for the next cycle
|
||||
}
|
||||
assertTrue(failures.size() == 0);
|
||||
assertThat(failures.size() == 0).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -393,9 +386,9 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
.build();
|
||||
|
||||
input.send(m1);
|
||||
assertNull(output.receive(10));
|
||||
assertThat(output.receive(10)).isNull();
|
||||
input.send(m2);
|
||||
assertNull(output.receive(10));
|
||||
assertThat(output.receive(10)).isNull();
|
||||
|
||||
context.close();
|
||||
|
||||
@@ -410,7 +403,7 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
.build();
|
||||
|
||||
input.send(m3);
|
||||
assertNotNull(output.receive(10000));
|
||||
assertThat(output.receive(10000)).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -426,10 +419,10 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
messages.add(message);
|
||||
}
|
||||
MessageGroup group = messageStore.getMessageGroup(this.groupId);
|
||||
assertEquals(25, group.size());
|
||||
assertThat(group.size()).isEqualTo(25);
|
||||
messageStore.removeMessagesFromGroup(this.groupId, messages);
|
||||
group = messageStore.getMessageGroup(this.groupId);
|
||||
assertEquals(0, group.size());
|
||||
assertThat(group.size()).isEqualTo(0);
|
||||
messageStore.removeMessageGroup(this.groupId);
|
||||
}
|
||||
|
||||
@@ -452,17 +445,18 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
store.addMessagesToGroup(this.groupId, genericMessage, mutableMessage, adviceMessage, errorMessage);
|
||||
|
||||
MessageGroup messageGroup = store.getMessageGroup(this.groupId);
|
||||
assertEquals(4, messageGroup.size());
|
||||
assertThat(messageGroup.size()).isEqualTo(4);
|
||||
List<Message<?>> messages = new ArrayList<>(messageGroup.getMessages());
|
||||
assertEquals(genericMessage, messages.get(0));
|
||||
assertEquals(mutableMessage, messages.get(1));
|
||||
assertEquals(adviceMessage, messages.get(2));
|
||||
assertThat(messages.get(0)).isEqualTo(genericMessage);
|
||||
assertThat(messages.get(1)).isEqualTo(mutableMessage);
|
||||
assertThat(messages.get(2)).isEqualTo(adviceMessage);
|
||||
Message<?> errorMessageResult = messages.get(3);
|
||||
assertEquals(errorMessage.getHeaders(), errorMessageResult.getHeaders());
|
||||
assertThat(errorMessageResult, instanceOf(ErrorMessage.class));
|
||||
assertEquals(errorMessage.getOriginalMessage(), ((ErrorMessage) errorMessageResult).getOriginalMessage());
|
||||
assertEquals(errorMessage.getPayload().getMessage(),
|
||||
((ErrorMessage) errorMessageResult).getPayload().getMessage());
|
||||
assertThat(errorMessageResult.getHeaders()).isEqualTo(errorMessage.getHeaders());
|
||||
assertThat(errorMessageResult).isInstanceOf(ErrorMessage.class);
|
||||
assertThat(((ErrorMessage) errorMessageResult).getOriginalMessage())
|
||||
.isEqualTo(errorMessage.getOriginalMessage());
|
||||
assertThat(((ErrorMessage) errorMessageResult).getPayload().getMessage())
|
||||
.isEqualTo(errorMessage.getPayload().getMessage());
|
||||
|
||||
Message<Foo> fooMessage = new GenericMessage<>(new Foo("foo"));
|
||||
try {
|
||||
@@ -473,12 +467,11 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
fail("SerializationException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
|
||||
assertThat(e.getMessage(),
|
||||
containsString("The class with " +
|
||||
"org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo and name of " +
|
||||
"org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo " +
|
||||
"is not in the trusted packages:"));
|
||||
assertThat(e.getCause().getCause()).isInstanceOf(IllegalArgumentException.class);
|
||||
assertThat(e.getMessage()).contains("The class with " +
|
||||
"org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo and name of " +
|
||||
"org.springframework.integration.redis.store.RedisMessageGroupStoreTests$Foo " +
|
||||
"is not in the trusted packages:");
|
||||
}
|
||||
|
||||
mapper = JacksonJsonUtils.messagingAwareMapper(getClass().getPackage().getName());
|
||||
@@ -488,8 +481,8 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
|
||||
store.removeMessageGroup(this.groupId);
|
||||
messageGroup = store.addMessageToGroup(this.groupId, fooMessage);
|
||||
assertEquals(1, messageGroup.size());
|
||||
assertEquals(fooMessage, messageGroup.getMessages().iterator().next());
|
||||
assertThat(messageGroup.size()).isEqualTo(1);
|
||||
assertThat(messageGroup.getMessages().iterator().next()).isEqualTo(fooMessage);
|
||||
|
||||
mapper = JacksonJsonUtils.messagingAwareMapper("*");
|
||||
|
||||
@@ -498,8 +491,8 @@ public class RedisMessageGroupStoreTests extends RedisAvailableTests {
|
||||
|
||||
store.removeMessageGroup(this.groupId);
|
||||
messageGroup = store.addMessageToGroup(this.groupId, fooMessage);
|
||||
assertEquals(1, messageGroup.size());
|
||||
assertEquals(fooMessage, messageGroup.getMessages().iterator().next());
|
||||
assertThat(messageGroup.size()).isEqualTo(1);
|
||||
assertThat(messageGroup.getMessages().iterator().next()).isEqualTo(fooMessage);
|
||||
}
|
||||
|
||||
private static class Foo {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2016 the original author or authors.
|
||||
* Copyright 2007-2019 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.
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.store;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -63,7 +60,7 @@ public class RedisMessageStoreTests extends RedisAvailableTests {
|
||||
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
|
||||
RedisMessageStore store = new RedisMessageStore(jcf);
|
||||
Message<?> message = store.getMessage(UUID.randomUUID());
|
||||
assertNull(message);
|
||||
assertThat(message).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,7 +68,7 @@ public class RedisMessageStoreTests extends RedisAvailableTests {
|
||||
public void testGetMessageCountWhenEmpty() {
|
||||
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
|
||||
RedisMessageStore store = new RedisMessageStore(jcf);
|
||||
assertEquals(0, store.getMessageCount());
|
||||
assertThat(store.getMessageCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,8 +78,8 @@ public class RedisMessageStoreTests extends RedisAvailableTests {
|
||||
RedisMessageStore store = new RedisMessageStore(jcf);
|
||||
Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
|
||||
Message<String> storedMessage = store.addMessage(stringMessage);
|
||||
assertNotSame(stringMessage, storedMessage);
|
||||
assertEquals("Hello Redis", storedMessage.getPayload());
|
||||
assertThat(storedMessage).isNotSameAs(stringMessage);
|
||||
assertThat(storedMessage.getPayload()).isEqualTo("Hello Redis");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,8 +93,8 @@ public class RedisMessageStoreTests extends RedisAvailableTests {
|
||||
|
||||
Message<Person> objectMessage = new GenericMessage<Person>(person);
|
||||
Message<Person> storedMessage = store.addMessage(objectMessage);
|
||||
assertNotSame(objectMessage, storedMessage);
|
||||
assertEquals("Barak Obama", storedMessage.getPayload().getName());
|
||||
assertThat(storedMessage).isNotSameAs(objectMessage);
|
||||
assertThat(storedMessage.getPayload().getName()).isEqualTo("Barak Obama");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@@ -119,8 +116,8 @@ public class RedisMessageStoreTests extends RedisAvailableTests {
|
||||
Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
|
||||
store.addMessage(stringMessage);
|
||||
Message<String> retrievedMessage = (Message<String>) store.getMessage(stringMessage.getHeaders().getId());
|
||||
assertNotNull(retrievedMessage);
|
||||
assertEquals("Hello Redis", retrievedMessage.getPayload());
|
||||
assertThat(retrievedMessage).isNotNull();
|
||||
assertThat(retrievedMessage.getPayload()).isEqualTo("Hello Redis");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -132,13 +129,13 @@ public class RedisMessageStoreTests extends RedisAvailableTests {
|
||||
Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
|
||||
store.addMessage(stringMessage);
|
||||
Message<String> retrievedMessage = (Message<String>) store.getMessage(stringMessage.getHeaders().getId());
|
||||
assertNotNull(retrievedMessage);
|
||||
assertEquals("Hello Redis", retrievedMessage.getPayload());
|
||||
assertThat(retrievedMessage).isNotNull();
|
||||
assertThat(retrievedMessage.getPayload()).isEqualTo("Hello Redis");
|
||||
|
||||
StringRedisTemplate template = createStringRedisTemplate(getConnectionFactoryForTest());
|
||||
BoundValueOperations<String, String> ops =
|
||||
template.boundValueOps("foo" + "MESSAGE_" + stringMessage.getHeaders().getId());
|
||||
assertNotNull(ops.get());
|
||||
assertThat(ops.get()).isNotNull();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -150,9 +147,9 @@ public class RedisMessageStoreTests extends RedisAvailableTests {
|
||||
Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
|
||||
store.addMessage(stringMessage);
|
||||
Message<String> retrievedMessage = (Message<String>) store.removeMessage(stringMessage.getHeaders().getId());
|
||||
assertNotNull(retrievedMessage);
|
||||
assertEquals("Hello Redis", retrievedMessage.getPayload());
|
||||
assertNull(store.getMessage(stringMessage.getHeaders().getId()));
|
||||
assertThat(retrievedMessage).isNotNull();
|
||||
assertThat(retrievedMessage.getPayload()).isEqualTo("Hello Redis");
|
||||
assertThat(store.getMessage(stringMessage.getHeaders().getId())).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,11 +169,11 @@ public class RedisMessageStoreTests extends RedisAvailableTests {
|
||||
store.addMessage(message);
|
||||
message = store.getMessage(message.getHeaders().getId());
|
||||
MessageHistory messageHistory = MessageHistory.read(message);
|
||||
assertNotNull(messageHistory);
|
||||
assertEquals(2, messageHistory.size());
|
||||
assertThat(messageHistory).isNotNull();
|
||||
assertThat(messageHistory.size()).isEqualTo(2);
|
||||
Properties fooChannelHistory = messageHistory.get(0);
|
||||
assertEquals("fooChannel", fooChannelHistory.get("name"));
|
||||
assertEquals("channel", fooChannelHistory.get("type"));
|
||||
assertThat(fooChannelHistory.get("name")).isEqualTo("fooChannel");
|
||||
assertThat(fooChannelHistory.get("type")).isEqualTo("channel");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,7 +190,7 @@ public class RedisMessageStoreTests extends RedisAvailableTests {
|
||||
}
|
||||
messageStore.removeMessagesFromGroup(groupId, messages);
|
||||
MessageGroup group = messageStore.getMessageGroup(groupId);
|
||||
assertEquals(0, group.size());
|
||||
assertThat(group.size()).isEqualTo(0);
|
||||
messageStore.removeMessageGroup("X");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.integration.redis.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -93,13 +90,14 @@ public class AggregatorWithRedisLocksTests extends RedisAvailableTests {
|
||||
this.releaseStrategy.reset(1);
|
||||
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 1));
|
||||
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 1));
|
||||
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
|
||||
assertEquals(1, this.template.keys("aggregatorWithRedisLocksTests:*").size());
|
||||
assertThat(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(this.template.keys("aggregatorWithRedisLocksTests:*").size()).isEqualTo(1);
|
||||
this.releaseStrategy.latch1.countDown();
|
||||
assertNotNull(this.out.receive(10000));
|
||||
assertEquals(1, this.releaseStrategy.maxCallers.get());
|
||||
assertThat(this.out.receive(10000)).isNotNull();
|
||||
assertThat(this.releaseStrategy.maxCallers.get()).isEqualTo(1);
|
||||
this.assertNoLocksAfterTest();
|
||||
assertNull("Unexpected exception:" + (this.exception != null ? this.exception.toString() : ""), this.exception);
|
||||
assertThat(this.exception)
|
||||
.as("Unexpected exception:" + (this.exception != null ? this.exception.toString() : "")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,17 +110,18 @@ public class AggregatorWithRedisLocksTests extends RedisAvailableTests {
|
||||
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 2));
|
||||
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 3));
|
||||
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 3));
|
||||
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
|
||||
assertEquals(3, this.template.keys("aggregatorWithRedisLocksTests:*").size());
|
||||
assertThat(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(this.template.keys("aggregatorWithRedisLocksTests:*").size()).isEqualTo(3);
|
||||
this.releaseStrategy.latch1.countDown();
|
||||
this.releaseStrategy.latch1.countDown();
|
||||
this.releaseStrategy.latch1.countDown();
|
||||
assertNotNull(this.out.receive(10000));
|
||||
assertNotNull(this.out.receive(10000));
|
||||
assertNotNull(this.out.receive(10000));
|
||||
assertEquals(3, this.releaseStrategy.maxCallers.get());
|
||||
assertThat(this.out.receive(10000)).isNotNull();
|
||||
assertThat(this.out.receive(10000)).isNotNull();
|
||||
assertThat(this.out.receive(10000)).isNotNull();
|
||||
assertThat(this.releaseStrategy.maxCallers.get()).isEqualTo(3);
|
||||
this.assertNoLocksAfterTest();
|
||||
assertNull("Unexpected exception:" + (this.exception != null ? this.exception.toString() : ""), this.exception);
|
||||
assertThat(this.exception)
|
||||
.as("Unexpected exception:" + (this.exception != null ? this.exception.toString() : "")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,13 +138,14 @@ public class AggregatorWithRedisLocksTests extends RedisAvailableTests {
|
||||
exception = e;
|
||||
}
|
||||
});
|
||||
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
|
||||
assertEquals(1, this.template.keys("aggregatorWithRedisLocksTests:*").size());
|
||||
assertThat(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(this.template.keys("aggregatorWithRedisLocksTests:*").size()).isEqualTo(1);
|
||||
this.releaseStrategy.latch1.countDown();
|
||||
assertNotNull(this.out.receive(10000));
|
||||
assertEquals(1, this.releaseStrategy.maxCallers.get());
|
||||
assertThat(this.out.receive(10000)).isNotNull();
|
||||
assertThat(this.releaseStrategy.maxCallers.get()).isEqualTo(1);
|
||||
this.assertNoLocksAfterTest();
|
||||
assertNull("Unexpected exception:" + (this.exception != null ? this.exception.toString() : ""), this.exception);
|
||||
assertThat(this.exception)
|
||||
.as("Unexpected exception:" + (this.exception != null ? this.exception.toString() : "")).isNull();
|
||||
}
|
||||
|
||||
private void assertNoLocksAfterTest() throws Exception {
|
||||
@@ -153,7 +153,7 @@ public class AggregatorWithRedisLocksTests extends RedisAvailableTests {
|
||||
while (n++ < 100 && this.template.keys("aggregatorWithRedisLocksTests:*").size() > 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertEquals(0, this.template.keys("aggregatorWithRedisLocksTests:*").size());
|
||||
assertThat(this.template.keys("aggregatorWithRedisLocksTests:*").size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
private Runnable asyncSend(final String payload, final int sequence, final int correlation) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -16,15 +16,8 @@
|
||||
|
||||
package org.springframework.integration.redis.util;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -39,9 +32,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -66,9 +57,6 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
|
||||
private final String registryKey2 = UUID.randomUUID().toString();
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void setupShutDown() {
|
||||
@@ -89,14 +77,14 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
Lock lock = registry.obtain("foo");
|
||||
lock.lock();
|
||||
try {
|
||||
assertEquals(1, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(1);
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
registry.expireUnusedOlderThan(-1000);
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,14 +95,14 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
Lock lock = registry.obtain("foo");
|
||||
lock.lockInterruptibly();
|
||||
try {
|
||||
assertEquals(1, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(1);
|
||||
}
|
||||
finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
registry.expireUnusedOlderThan(-1000);
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +114,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
lock1.lock();
|
||||
try {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
assertSame(lock1, lock2);
|
||||
assertThat(lock2).isSameAs(lock1);
|
||||
lock2.lock();
|
||||
try {
|
||||
// just get the lock
|
||||
@@ -140,7 +128,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
}
|
||||
}
|
||||
registry.expireUnusedOlderThan(-1000);
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,7 +140,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
lock1.lockInterruptibly();
|
||||
try {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
assertSame(lock1, lock2);
|
||||
assertThat(lock2).isSameAs(lock1);
|
||||
lock2.lockInterruptibly();
|
||||
try {
|
||||
// just get the lock
|
||||
@@ -166,7 +154,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
}
|
||||
}
|
||||
registry.expireUnusedOlderThan(-1000);
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,7 +166,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
lock1.lockInterruptibly();
|
||||
try {
|
||||
Lock lock2 = registry.obtain("bar");
|
||||
assertNotSame(lock1, lock2);
|
||||
assertThat(lock2).isNotSameAs(lock1);
|
||||
lock2.lockInterruptibly();
|
||||
try {
|
||||
// just get the lock
|
||||
@@ -192,7 +180,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
}
|
||||
}
|
||||
registry.expireUnusedOlderThan(-1000);
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -215,14 +203,14 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
}
|
||||
return null;
|
||||
});
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertFalse(locked.get());
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(locked.get()).isFalse();
|
||||
lock1.unlock();
|
||||
Object ise = result.get(10, TimeUnit.SECONDS);
|
||||
assertThat(ise, instanceOf(IllegalStateException.class));
|
||||
assertThat(((Exception) ise).getMessage(), containsString("You do not own lock at"));
|
||||
assertThat(ise).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(((Exception) ise).getMessage()).contains("You do not own lock at");
|
||||
registry.expireUnusedOlderThan(-1000);
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,13 +223,13 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
CountDownLatch latch2 = new CountDownLatch(1);
|
||||
CountDownLatch latch3 = new CountDownLatch(1);
|
||||
lock1.lockInterruptibly();
|
||||
assertEquals(1, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(1);
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
try {
|
||||
latch1.countDown();
|
||||
lock2.lockInterruptibly();
|
||||
assertEquals(1, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(1);
|
||||
latch2.await(10, TimeUnit.SECONDS);
|
||||
locked.set(true);
|
||||
}
|
||||
@@ -253,14 +241,14 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
latch3.countDown();
|
||||
}
|
||||
});
|
||||
assertTrue(latch1.await(10, TimeUnit.SECONDS));
|
||||
assertFalse(locked.get());
|
||||
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(locked.get()).isFalse();
|
||||
lock1.unlock();
|
||||
latch2.countDown();
|
||||
assertTrue(latch3.await(10, TimeUnit.SECONDS));
|
||||
assertTrue(locked.get());
|
||||
assertThat(latch3.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(locked.get()).isTrue();
|
||||
registry.expireUnusedOlderThan(-1000);
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,13 +262,13 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
CountDownLatch latch2 = new CountDownLatch(1);
|
||||
CountDownLatch latch3 = new CountDownLatch(1);
|
||||
lock1.lockInterruptibly();
|
||||
assertEquals(1, TestUtils.getPropertyValue(registry1, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry1, "locks", Map.class).size()).isEqualTo(1);
|
||||
Executors.newSingleThreadExecutor().execute(() -> {
|
||||
Lock lock2 = registry2.obtain("foo");
|
||||
try {
|
||||
latch1.countDown();
|
||||
lock2.lockInterruptibly();
|
||||
assertEquals(1, TestUtils.getPropertyValue(registry2, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry2, "locks", Map.class).size()).isEqualTo(1);
|
||||
latch2.await(10, TimeUnit.SECONDS);
|
||||
locked.set(true);
|
||||
}
|
||||
@@ -298,16 +286,16 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
}
|
||||
}
|
||||
});
|
||||
assertTrue(latch1.await(10, TimeUnit.SECONDS));
|
||||
assertFalse(locked.get());
|
||||
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(locked.get()).isFalse();
|
||||
lock1.unlock();
|
||||
latch2.countDown();
|
||||
assertTrue(latch3.await(10, TimeUnit.SECONDS));
|
||||
assertTrue(locked.get());
|
||||
assertThat(latch3.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(locked.get()).isTrue();
|
||||
registry1.expireUnusedOlderThan(-1000);
|
||||
registry2.expireUnusedOlderThan(-1000);
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry1, "locks", Map.class).size());
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry2, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry1, "locks", Map.class).size()).isEqualTo(0);
|
||||
assertThat(TestUtils.getPropertyValue(registry2, "locks", Map.class).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -328,14 +316,14 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
}
|
||||
return null;
|
||||
});
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertFalse(locked.get());
|
||||
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(locked.get()).isFalse();
|
||||
lock.unlock();
|
||||
Object ise = result.get(10, TimeUnit.SECONDS);
|
||||
assertThat(ise, instanceOf(IllegalStateException.class));
|
||||
assertThat(((Exception) ise).getMessage(), containsString("You do not own lock at"));
|
||||
assertThat(ise).isInstanceOf(IllegalStateException.class);
|
||||
assertThat(((Exception) ise).getMessage()).contains("You do not own lock at");
|
||||
registry.expireUnusedOlderThan(-1000);
|
||||
assertEquals(0, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -345,11 +333,11 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
RedisLockRegistry registry2 = new RedisLockRegistry(getConnectionFactoryForTest(), this.registryKey, 100);
|
||||
Lock lock1 = registry1.obtain("foo");
|
||||
Lock lock2 = registry2.obtain("foo");
|
||||
assertTrue(lock1.tryLock());
|
||||
assertFalse(lock2.tryLock());
|
||||
assertThat(lock1.tryLock()).isTrue();
|
||||
assertThat(lock2.tryLock()).isFalse();
|
||||
waitForExpire("foo");
|
||||
assertTrue(lock2.tryLock());
|
||||
assertFalse(lock1.tryLock());
|
||||
assertThat(lock2.tryLock()).isTrue();
|
||||
assertThat(lock1.tryLock()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -357,11 +345,11 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
public void testExceptionOnExpire() throws Exception {
|
||||
RedisLockRegistry registry = new RedisLockRegistry(getConnectionFactoryForTest(), this.registryKey, 1);
|
||||
Lock lock1 = registry.obtain("foo");
|
||||
assertTrue(lock1.tryLock());
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Lock was released in the store due to expiration.");
|
||||
assertThat(lock1.tryLock()).isTrue();
|
||||
waitForExpire("foo");
|
||||
lock1.unlock();
|
||||
assertThatThrownBy(lock1::unlock)
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasMessageContaining("Lock was released in the store due to expiration.");
|
||||
}
|
||||
|
||||
|
||||
@@ -374,24 +362,24 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
RedisLockRegistry registry3 = new RedisLockRegistry(connectionFactory, this.registryKey2);
|
||||
Lock lock1 = registry1.obtain("foo");
|
||||
Lock lock2 = registry1.obtain("foo");
|
||||
assertEquals(lock1, lock2);
|
||||
assertThat(lock2).isEqualTo(lock1);
|
||||
lock1.lock();
|
||||
lock2.lock();
|
||||
assertEquals(lock1, lock2);
|
||||
assertThat(lock2).isEqualTo(lock1);
|
||||
lock1.unlock();
|
||||
lock2.unlock();
|
||||
assertEquals(lock1, lock2);
|
||||
assertThat(lock2).isEqualTo(lock1);
|
||||
|
||||
lock1 = registry1.obtain("foo");
|
||||
lock2 = registry2.obtain("foo");
|
||||
assertNotEquals(lock1, lock2);
|
||||
assertThat(lock2).isNotEqualTo(lock1);
|
||||
lock1.lock();
|
||||
assertFalse(lock2.tryLock());
|
||||
assertThat(lock2.tryLock()).isFalse();
|
||||
lock1.unlock();
|
||||
|
||||
lock1 = registry1.obtain("foo");
|
||||
lock2 = registry3.obtain("foo");
|
||||
assertNotEquals(lock1, lock2);
|
||||
assertThat(lock2).isNotEqualTo(lock1);
|
||||
lock1.lock();
|
||||
lock2.lock();
|
||||
lock1.unlock();
|
||||
@@ -406,19 +394,19 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
registry.obtain("foo" + i);
|
||||
}
|
||||
assertEquals(10, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(10);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Lock lock = registry.obtain("foo" + i);
|
||||
lock.lock();
|
||||
}
|
||||
assertEquals(10, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(10);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Lock lock = registry.obtain("foo" + i);
|
||||
lock.unlock();
|
||||
}
|
||||
assertEquals(10, TestUtils.getPropertyValue(registry, "locks", Map.class).size());
|
||||
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -433,11 +421,11 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
|
||||
Future<Object> result = Executors.newSingleThreadExecutor().submit(() -> {
|
||||
Lock lock2 = registry.obtain("foo");
|
||||
assertFalse(lock2.tryLock());
|
||||
assertThat(lock2.tryLock()).isFalse();
|
||||
return null;
|
||||
});
|
||||
result.get();
|
||||
assertEquals(expire, getExpire(registry, "foo"));
|
||||
assertThat(getExpire(registry, "foo")).isEqualTo(expire);
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
@@ -453,7 +441,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
|
||||
while (n++ < 100 && template.keys(this.registryKey + ":" + key).size() > 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertTrue(key + " key did not expire", n < 100);
|
||||
assertThat(n < 100).as(key + " key did not expire").isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user