DATAREDIS-549 - Migrate to AssertJ.

This commit is contained in:
Mark Paluch
2019-07-10 15:54:40 +02:00
parent 8bb7a9472f
commit 0205c9c98b
138 changed files with 3896 additions and 4157 deletions

View File

@@ -49,7 +49,6 @@ public abstract class ConnectionFactoryTracker {
try {
if (connectionFactory instanceof DisposableBean) {
((DisposableBean) connectionFactory).destroy();
// System.out.println("Succesfully cleaned up factory " + connectionFactory);
}
connFactories.remove(connectionFactory);
} catch (Exception ex) {

View File

@@ -15,11 +15,12 @@
*/
package org.springframework.data.redis;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.data.redis.core.RedisOperations;
@@ -46,10 +47,10 @@ public class PropertyEditorsTest {
RedisViewPE bean = ctx.getBean(RedisViewPE.class);
RedisOperations<?, ?> ops = ctx.getBean(RedisOperations.class);
assertSame(ops.opsForValue(), bean.getValueOps());
assertSame(ops.opsForList(), bean.getListOps());
assertSame(ops.opsForSet(), bean.getSetOps());
assertSame(ops.opsForZSet(), bean.getZsetOps());
assertSame(ops, bean.getHashOps().getOperations());
assertThat(bean.getValueOps()).isSameAs(ops.opsForValue());
assertThat(bean.getListOps()).isSameAs(ops.opsForList());
assertThat(bean.getSetOps()).isSameAs(ops.opsForSet());
assertThat(bean.getZsetOps()).isSameAs(ops.opsForZSet());
assertThat(bean.getHashOps().getOperations()).isSameAs(ops);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
@@ -27,31 +26,31 @@ public class VersionParserUnitTests {
@Test
public void shouldParseNullToUnknown() {
assertThat(VersionParser.parseVersion(null), equalTo(Version.UNKNOWN));
assertThat(VersionParser.parseVersion(null)).isEqualTo(Version.UNKNOWN);
}
@Test
public void shouldParseEmptyVersionStringToUnknown() {
assertThat(VersionParser.parseVersion(""), equalTo(Version.UNKNOWN));
assertThat(VersionParser.parseVersion("")).isEqualTo(Version.UNKNOWN);
}
@Test
public void shouldParseInvalidVersionStringToUnknown() {
assertThat(VersionParser.parseVersion("ThisIsNoValidVersion"), equalTo(Version.UNKNOWN));
assertThat(VersionParser.parseVersion("ThisIsNoValidVersion")).isEqualTo(Version.UNKNOWN);
}
@Test
public void shouldParseMajorMinorWithoutPatchCorrectly() {
assertThat(VersionParser.parseVersion("1.2"), equalTo(new Version(1, 2, 0)));
assertThat(VersionParser.parseVersion("1.2")).isEqualTo(new Version(1, 2, 0));
}
@Test
public void shouldParseMajorMinorPatchCorrectly() {
assertThat(VersionParser.parseVersion("1.2.3"), equalTo(new Version(1, 2, 3)));
assertThat(VersionParser.parseVersion("1.2.3")).isEqualTo(new Version(1, 2, 3));
}
@Test
public void shouldParseMajorWithoutMinorPatchCorrectly() {
assertThat(VersionParser.parseVersion("1.2.3.a"), equalTo(new Version(1, 2, 3)));
assertThat(VersionParser.parseVersion("1.2.3.a")).isEqualTo(new Version(1, 2, 3));
}
}

View File

@@ -16,14 +16,8 @@
package org.springframework.data.redis.cache;
import static edu.umd.cs.mtc.TestFramework.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.core.IsNot.*;
import static org.hamcrest.core.IsNull.*;
import static org.hamcrest.core.IsSame.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.*;
import edu.umd.cs.mtc.MultithreadedTestCase;
@@ -35,12 +29,12 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import org.hamcrest.core.IsInstanceOf;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.cache.Cache;
import org.springframework.cache.Cache.ValueRetrievalException;
import org.springframework.cache.Cache.ValueWrapper;
@@ -72,7 +66,7 @@ public class LegacyRedisCacheTests {
RedisCache cache;
public LegacyRedisCacheTests(RedisTemplate template, ObjectFactory<Object> keyFactory,
ObjectFactory<Object> valueFactory, boolean allowCacheNullValues) {
ObjectFactory<Object> valueFactory, boolean allowCacheNullValues) {
this.connectionFactory = template.getConnectionFactory();
this.keyFactory = keyFactory;
@@ -134,12 +128,12 @@ public class LegacyRedisCacheTests {
Object key = getKey();
Object value = getValue();
assertNotNull(value);
assertNull(cache.get(key));
assertThat(value).isNotNull();
assertThat(cache.get(key)).isNull();
cache.put(key, value);
ValueWrapper valueWrapper = cache.get(key);
if (valueWrapper != null) {
assertThat(valueWrapper.get(), isEqual(value));
assertThat(valueWrapper.get()).isEqualTo(value);
}
}
@@ -151,13 +145,13 @@ public class LegacyRedisCacheTests {
Object key2 = getKey();
Object value2 = getValue();
assertNull(cache.get(key1));
assertThat(cache.get(key1)).isNull();
cache.put(key1, value1);
assertNull(cache.get(key2));
assertThat(cache.get(key2)).isNull();
cache.put(key2, value2);
cache.clear();
assertNull(cache.get(key2));
assertNull(cache.get(key1));
assertThat(cache.get(key2)).isNull();
assertThat(cache.get(key1)).isNull();
}
@Test
@@ -189,7 +183,7 @@ public class LegacyRedisCacheTests {
th.start();
th.join();
assertFalse(failed.get());
assertThat(failed.get()).isFalse();
final Object key3 = getKey();
final Object key4 = getKey();
@@ -199,11 +193,11 @@ public class LegacyRedisCacheTests {
cache.put(key3, value3);
cache.put(key4, value4);
assertNull(cache.get(key1));
assertNull(cache.get(key2));
assertThat(cache.get(key1)).isNull();
assertThat(cache.get(key2)).isNull();
ValueWrapper valueWrapper = cache.get(k1);
assertNotNull(valueWrapper);
assertThat(valueWrapper.get(), isEqual(v1));
assertThat(valueWrapper).isNotNull();
assertThat(valueWrapper.get()).isEqualTo(v1);
}
@Test
@@ -229,7 +223,7 @@ public class LegacyRedisCacheTests {
new Thread(putCache).start();
}
latch.await();
assertFalse(monitorStateException.get());
assertThat(monitorStateException.get()).isFalse();
}
@Test // DATAREDIS-243
@@ -239,7 +233,7 @@ public class LegacyRedisCacheTests {
Object value = getValue();
cache.put(key, value);
assertThat(value, isEqual(cache.get(key, Object.class)));
assertThat(value).isEqualTo(cache.get(key, Object.class));
}
@Test // DATAREDIS-243
@@ -249,7 +243,7 @@ public class LegacyRedisCacheTests {
Object value = getValue();
cache.put(key, value);
assertThat(cache.get(key, value.getClass()), IsInstanceOf.<Object> instanceOf(value.getClass()));
assertThat(cache.get(key, value.getClass())).isInstanceOf(value.getClass());
}
@Test(expected = IllegalStateException.class) // DATAREDIS-243
@@ -271,7 +265,7 @@ public class LegacyRedisCacheTests {
cache.put(key, value);
Object invalidKey = "spring-data-redis".getBytes();
assertThat(cache.get(invalidKey, value.getClass()), nullValue());
assertThat(cache.get(invalidKey, value.getClass())).isNull();
}
@Test // DATAREDIS-344, DATAREDIS-416
@@ -281,21 +275,21 @@ public class LegacyRedisCacheTests {
Object value = getValue();
assertThat(cache.putIfAbsent(key, value), nullValue());
assertThat(cache.putIfAbsent(key, value)).isNull();
ValueWrapper wrapper = cache.putIfAbsent(key, value);
if (!(value instanceof Number)) {
assertThat(wrapper.get(), not(sameInstance(value)));
assertThat(wrapper.get()).isNotSameAs(value);
}
assertThat(wrapper.get(), equalTo(value));
assertThat(wrapper.get()).isEqualTo(value);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-510, DATAREDIS-606
public void cachePutWithNullShouldNotAddStuffToRedis() {
assumeThat("Only suitable when cache does NOT allow null values.", allowCacheNullValues, is(false));
assumeThat(allowCacheNullValues).as("Only suitable when cache does NOT allow null values.").isFalse();
Object key = getKey();
@@ -305,14 +299,14 @@ public class LegacyRedisCacheTests {
@Test // DATAREDIS-510, DATAREDIS-606
public void cachePutWithNullShouldErrorAndLeaveExistingKeyUntouched() {
assumeThat("Only suitable when cache does NOT allow null values.", allowCacheNullValues, is(false));
assumeThat(allowCacheNullValues).as("Only suitable when cache does NOT allow null values.").isFalse();
Object key = getKey();
Object value = getValue();
cache.put(key, value);
assertThat(cache.get(key).get(), is(equalTo(value)));
assertThat(cache.get(key).get()).isEqualTo(value);
try {
cache.put(key, null);
@@ -320,7 +314,7 @@ public class LegacyRedisCacheTests {
// forget this one.
}
assertThat(cache.get(key).get(), is(equalTo(value)));
assertThat(cache.get(key).get()).isEqualTo(value);
}
@Test // DATAREDIS-443, DATAREDIS-452
@@ -331,32 +325,32 @@ public class LegacyRedisCacheTests {
@Test // DATAREDIS-553
public void cachePutWithNullShouldAddStuffToRedisWhenCachingNullIsEnabled() {
assumeThat("Only suitable when cache does allow null values.", allowCacheNullValues, is(true));
assumeThat(allowCacheNullValues).as("Only suitable when cache does allow null values.").isTrue();
Object key = getKey();
Object value = getValue();
cache.put(key, null);
assertThat(cache.get(key, String.class), is(nullValue()));
assertThat(cache.get(key, String.class)).isNull();
}
@Test // DATAREDIS-553
public void testCacheGetSynchronizedNullAllowingNull() {
assumeThat("Only suitable when cache does allow null values.", allowCacheNullValues, is(true));
assumeThat(allowCacheNullValues).as("Only suitable when cache does allow null values.").isTrue();
Object key = getKey();
Object value = cache.get(key, () -> null);
assertThat(value, is(nullValue()));
assertThat(cache.get(key).get(), is(nullValue()));
assertThat(value).isNull();
assertThat(cache.get(key).get()).isNull();
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-553, DATAREDIS-606
public void testCacheGetSynchronizedNullNotAllowingNull() {
assumeThat("Only suitable when cache does NOT allow null values.", allowCacheNullValues, is(false));
assumeThat(allowCacheNullValues).as("Only suitable when cache does NOT allow null values.").isFalse();
Object key = getKey();
Object value = cache.get(key, () -> null);
@@ -374,14 +368,14 @@ public class LegacyRedisCacheTests {
@Test // DATAREDIS-553
public void testCacheGetSynchronizedNullWithStoredNull() {
assumeThat("Only suitable when cache does allow null values.", allowCacheNullValues, is(true));
assumeThat(allowCacheNullValues).as("Only suitable when cache does allow null values.").isTrue();
Object key = getKey();
cache.put(key, null);
Object cachedValue = cache.get(key, () -> null);
assertThat(cachedValue, is(nullValue()));
assertThat(cachedValue).isNull();
}
@SuppressWarnings("unused")
@@ -408,13 +402,13 @@ public class LegacyRedisCacheTests {
public void thread1() {
assertTick(0);
assertThat(redisCache.get("key", cacheLoader), equalTo("test"));
assertThat(redisCache.get("key", cacheLoader)).isEqualTo("test");
}
public void thread2() {
waitForTick(1);
assertThat(redisCache.get("key", new TestCacheLoader<>("illegal value")), equalTo("test"));
assertThat(redisCache.get("key", new TestCacheLoader<>("illegal value"))).isEqualTo("test");
assertTick(2);
}
}

View File

@@ -15,12 +15,13 @@
*/
package org.springframework.data.redis.config;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
@@ -46,7 +47,7 @@ public class NamespaceTest {
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testSanityTest() throws Exception {
assertTrue(container.isRunning());
assertThat(container.isRunning()).isTrue();
Thread.sleep(TimeUnit.SECONDS.toMillis(8));
}
@@ -62,6 +63,6 @@ public class NamespaceTest {
int index = handler.throwables.size();
template.convertAndSend("exception", "test1");
handler.throwables.pollLast(3, TimeUnit.SECONDS);
assertEquals(index + 1, handler.throwables.size());
assertThat(handler.throwables.size()).isEqualTo(index + 1);
}
}

View File

@@ -16,13 +16,14 @@
package org.springframework.data.redis.connection;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.test.annotation.IfProfileValue;
/**
@@ -117,7 +118,7 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends Abstrac
public void testClosePipelineNotOpen() {
getResults();
List<Object> results = connection.closePipeline();
assertTrue(results.isEmpty());
assertThat(results.isEmpty()).isTrue();
}
@Test // DATAREDIS-417
@@ -136,9 +137,9 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends Abstrac
for (int i = 0; i < actual.size(); i++) {
expectedPipeline.add(null);
}
assertEquals(expectedPipeline, actual);
assertThat(actual).isEqualTo(expectedPipeline);
List<Object> results = getResults();
assertEquals(expected, results);
assertThat(results).isEqualTo(expected);
}
protected List<Object> getResults() {

View File

@@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.test.annotation.IfProfileValue;
/**
@@ -127,8 +127,8 @@ abstract public class AbstractConnectionTransactionIntegrationTests extends Abst
for (int i = 0; i < actual.size(); i++) {
expectedTx.add(null);
}
assertEquals(expectedTx, actual);
assertThat(actual).isEqualTo(expectedTx);
List<Object> results = getResults();
assertEquals(expected, results);
assertThat(results).isEqualTo(expected);
}
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.connection;
import static org.assertj.core.api.Assertions.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;
@@ -22,12 +24,11 @@ import java.util.List;
import javax.sql.DataSource;
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -105,9 +106,9 @@ public abstract class AbstractTransactionalTestBase {
RedisConnection connection = factory.getConnection();
for (String key : KEYS) {
Assert.assertThat(
"Values for " + key + " should " + (valuesShouldHaveBeenPersisted ? "" : "NOT ") + "have been found.",
connection.exists(key.getBytes()), Is.is(valuesShouldHaveBeenPersisted));
assertThat(connection.exists(key.getBytes()))
.as("Values for " + key + " should " + (valuesShouldHaveBeenPersisted ? "" : "NOT ") + "have been found.")
.isEqualTo(valuesShouldHaveBeenPersisted);
}
connection.close();
}

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.redis.connection;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsCollectionContaining.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.redis.test.util.MockitoUtils.*;
@@ -25,7 +23,6 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -33,6 +30,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.dao.DataAccessException;
@@ -232,8 +230,8 @@ public class ClusterCommandExecutorUnitTests {
executor.executeCommandOnAllNodes(COMMAND_CALLBACK);
} catch (ClusterCommandExecutionFailureException e) {
assertThat(e.getCauses().size(), is(1));
assertThat(e.getCauses().iterator().next(), IsInstanceOf.instanceOf(DataAccessException.class));
assertThat(e.getCauses().size()).isEqualTo(1);
assertThat(e.getCauses().iterator().next()).isInstanceOf(DataAccessException.class);
}
verify(con1, times(1)).theWheelWeavesAsTheWheelWills();
@@ -250,7 +248,7 @@ public class ClusterCommandExecutorUnitTests {
MultiNodeResult<String> result = executor.executeCommandOnAllNodes(COMMAND_CALLBACK);
assertThat(result.resultsAsList(), hasItems("rand", "mat", "perrin"));
assertThat(result.resultsAsList()).contains("rand", "mat", "perrin");
}
@Test // DATAREDIS-315, DATAREDIS-467
@@ -267,10 +265,10 @@ public class ClusterCommandExecutorUnitTests {
new HashSet<>(
Arrays.asList("key-1".getBytes(), "key-2".getBytes(), "key-3".getBytes(), "key-9".getBytes())));
assertThat(result.resultsAsList(), hasItems("rand", "mat", "perrin", "egwene"));
assertThat(result.resultsAsList()).contains("rand", "mat", "perrin", "egwene");
// check that 2 keys have been routed to node1
assertThat(captor.getAllValues().size(), is(2));
assertThat(captor.getAllValues().size()).isEqualTo(2);
}
@Test // DATAREDIS-315
@@ -296,7 +294,7 @@ public class ClusterCommandExecutorUnitTests {
executor.setMaxRedirects(4);
executor.executeCommandOnSingleNode(COMMAND_CALLBACK, CLUSTER_NODE_1);
} catch (Exception e) {
assertThat(e, IsInstanceOf.instanceOf(TooManyClusterRedirectionsException.class));
assertThat(e).isInstanceOf(TooManyClusterRedirectionsException.class);
}
verify(con1, times(2)).theWheelWeavesAsTheWheelWills();

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.connection;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
@@ -28,6 +28,7 @@ import java.util.Random;
import org.junit.ClassRule;
import org.junit.Test;
import org.springframework.data.redis.test.util.RedisClusterRule;
import org.springframework.util.StringUtils;
@@ -54,9 +55,9 @@ public class ClusterSlotHashUtilsTests {
int slot = ClusterSlotHashUtil.calculateSlot(key);
Long serverSlot = jedis.clusterKeySlot(key);
assertEquals(
String.format("Expected slot for key '%s' to be %s but server calculated %s.", key, slot, serverSlot),
serverSlot.intValue(), slot);
assertThat(slot)
.as(String.format("Expected slot for key '%s' to be %s but server calculated %s.", key, slot, serverSlot))
.isEqualTo(serverSlot.intValue());
}
jedis.close();
@@ -87,18 +88,18 @@ public class ClusterSlotHashUtilsTests {
int slot1 = ClusterSlotHashUtil.calculateSlot(key1);
int slot2 = ClusterSlotHashUtil.calculateSlot(key2);
assertEquals(String.format("Expected slot for prefixed keys '%s' and '%s' to be %s but was %s.", key1, key2,
slot1, slot2), slot1, slot2);
assertThat(slot2).as(String.format("Expected slot for prefixed keys '%s' and '%s' to be %s but was %s.", key1,
key2, slot1, slot2)).isEqualTo(slot1);
Long serverSlot1 = jedis.clusterKeySlot(key1);
Long serverSlot2 = jedis.clusterKeySlot(key2);
assertEquals(
String.format("Expected slot for key '%s' to be %s but server calculated %s.", key1, slot1, serverSlot1),
serverSlot1.intValue(), slot1);
assertEquals(
String.format("Expected slot for key '%s' to be %s but server calculated %s.", key2, slot2, serverSlot2),
serverSlot1.intValue(), slot1);
assertThat(slot1).as(
String.format("Expected slot for key '%s' to be %s but server calculated %s.", key1, slot1, serverSlot1))
.isEqualTo(serverSlot1.intValue());
assertThat(slot1).as(
String.format("Expected slot for key '%s' to be %s but server calculated %s.", key2, slot2, serverSlot2))
.isEqualTo(serverSlot1.intValue());
}
jedis.close();

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.connection;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Arrays;
@@ -25,6 +25,7 @@ import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.geo.Distance;
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
import org.springframework.data.redis.connection.stream.RecordId;
@@ -1565,9 +1566,8 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
connection.get(bar);
connection.exec();
List<Object> results = connection.closePipeline();
assertEquals(
Arrays.asList(new Object[] { Arrays.asList(new Object[] { bar }), Arrays.asList(new Object[] { foo }) }),
results);
assertThat(results).isEqualTo(
Arrays.asList(new Object[] { Arrays.asList(new Object[] { bar }), Arrays.asList(new Object[] { foo }) }));
}
@Test // DATAREDIS-438

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.connection;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.ArrayList;
@@ -35,6 +35,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResult;
@@ -45,11 +46,6 @@ import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.connection.stream.StreamReadOptions;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
@@ -57,6 +53,11 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.connection.stream.StreamReadOptions;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@@ -2172,6 +2173,6 @@ public class DefaultStringRedisConnectionTests {
}
protected void verifyResults(List<?> expected) {
assertEquals(expected, getResults());
assertThat(getResults()).isEqualTo(expected);
}
}

View File

@@ -15,16 +15,14 @@
*/
package org.springframework.data.redis.connection;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsCollectionContaining.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import org.junit.Test;
import org.springframework.core.env.PropertySource;
import org.springframework.mock.env.MockPropertySource;
import org.springframework.util.StringUtils;
@@ -45,9 +43,9 @@ public class RedisClusterConfigurationUnitTests {
RedisClusterConfiguration config = new RedisClusterConfiguration(Collections.singleton(HOST_AND_PORT_1));
assertThat(config.getClusterNodes().size(), is(1));
assertThat(config.getClusterNodes(), hasItems(new RedisNode("127.0.0.1", 123)));
assertThat(config.getMaxRedirects(), nullValue());
assertThat(config.getClusterNodes().size()).isEqualTo(1);
assertThat(config.getClusterNodes()).contains(new RedisNode("127.0.0.1", 123));
assertThat(config.getMaxRedirects()).isNull();
}
@Test // DATAREDIS-315
@@ -57,9 +55,9 @@ public class RedisClusterConfigurationUnitTests {
new HashSet<>(Arrays.asList(HOST_AND_PORT_1,
HOST_AND_PORT_2, HOST_AND_PORT_3)));
assertThat(config.getClusterNodes().size(), is(3));
assertThat(config.getClusterNodes(),
hasItems(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456), new RedisNode("localhost", 789)));
assertThat(config.getClusterNodes().size()).isEqualTo(3);
assertThat(config.getClusterNodes()).contains(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456),
new RedisNode("localhost", 789));
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
@@ -77,7 +75,7 @@ public class RedisClusterConfigurationUnitTests {
RedisClusterConfiguration config = new RedisClusterConfiguration(Collections.<String> emptySet());
assertThat(config.getClusterNodes().size(), is(0));
assertThat(config.getClusterNodes().size()).isEqualTo(0);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
@@ -90,8 +88,8 @@ public class RedisClusterConfigurationUnitTests {
RedisClusterConfiguration config = new RedisClusterConfiguration(new MockPropertySource());
assertThat(config.getMaxRedirects(), nullValue());
assertThat(config.getClusterNodes().size(), is(0));
assertThat(config.getMaxRedirects()).isNull();
assertThat(config.getClusterNodes().size()).isEqualTo(0);
}
@Test // DATAREDIS-315
@@ -103,8 +101,8 @@ public class RedisClusterConfigurationUnitTests {
RedisClusterConfiguration config = new RedisClusterConfiguration(propertySource);
assertThat(config.getMaxRedirects(), is(5));
assertThat(config.getClusterNodes(), hasItems(new RedisNode("127.0.0.1", 123)));
assertThat(config.getMaxRedirects()).isEqualTo(5);
assertThat(config.getClusterNodes()).contains(new RedisNode("127.0.0.1", 123));
}
@Test // DATAREDIS-315
@@ -117,9 +115,9 @@ public class RedisClusterConfigurationUnitTests {
RedisClusterConfiguration config = new RedisClusterConfiguration(propertySource);
assertThat(config.getMaxRedirects(), is(5));
assertThat(config.getClusterNodes(),
hasItems(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456), new RedisNode("localhost", 789)));
assertThat(config.getMaxRedirects()).isEqualTo(5);
assertThat(config.getClusterNodes()).contains(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456),
new RedisNode("localhost", 789));
}
}

View File

@@ -15,16 +15,14 @@
*/
package org.springframework.data.redis.connection;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsCollectionContaining.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import org.junit.Test;
import org.springframework.core.env.PropertySource;
import org.springframework.mock.env.MockPropertySource;
import org.springframework.util.StringUtils;
@@ -45,8 +43,8 @@ public class RedisSentinelConfigurationUnitTests {
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster",
Collections.singleton(HOST_AND_PORT_1));
assertThat(config.getSentinels().size(), is(1));
assertThat(config.getSentinels(), hasItems(new RedisNode("127.0.0.1", 123)));
assertThat(config.getSentinels().size()).isEqualTo(1);
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123));
}
@Test // DATAREDIS-372
@@ -56,9 +54,9 @@ public class RedisSentinelConfigurationUnitTests {
new HashSet<>(Arrays.asList(
HOST_AND_PORT_1, HOST_AND_PORT_2, HOST_AND_PORT_3)));
assertThat(config.getSentinels().size(), is(3));
assertThat(config.getSentinels(),
hasItems(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456), new RedisNode("localhost", 789)));
assertThat(config.getSentinels().size()).isEqualTo(3);
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456),
new RedisNode("localhost", 789));
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-372
@@ -76,7 +74,7 @@ public class RedisSentinelConfigurationUnitTests {
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster", Collections.<String> emptySet());
assertThat(config.getSentinels().size(), is(0));
assertThat(config.getSentinels().size()).isEqualTo(0);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-372
@@ -89,8 +87,8 @@ public class RedisSentinelConfigurationUnitTests {
RedisSentinelConfiguration config = new RedisSentinelConfiguration(new MockPropertySource());
assertThat(config.getMaster(), nullValue());
assertThat(config.getSentinels().size(), is(0));
assertThat(config.getMaster()).isNull();
assertThat(config.getSentinels().size()).isEqualTo(0);
}
@Test // DATAREDIS-372
@@ -102,9 +100,9 @@ public class RedisSentinelConfigurationUnitTests {
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
assertThat(config.getMaster().getName(), is("myMaster"));
assertThat(config.getSentinels().size(), is(1));
assertThat(config.getSentinels(), hasItems(new RedisNode("127.0.0.1", 123)));
assertThat(config.getMaster().getName()).isEqualTo("myMaster");
assertThat(config.getSentinels().size()).isEqualTo(1);
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123));
}
@Test // DATAREDIS-372
@@ -117,8 +115,8 @@ public class RedisSentinelConfigurationUnitTests {
RedisSentinelConfiguration config = new RedisSentinelConfiguration(propertySource);
assertThat(config.getSentinels().size(), is(3));
assertThat(config.getSentinels(),
hasItems(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456), new RedisNode("localhost", 789)));
assertThat(config.getSentinels().size()).isEqualTo(3);
assertThat(config.getSentinels()).contains(new RedisNode("127.0.0.1", 123), new RedisNode("localhost", 456),
new RedisNode("localhost", 789));
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Properties;
@@ -34,7 +33,7 @@ public class RedisServerUnitTests {
RedisServer redisServer = RedisServer.newServerFrom(createProperties());
assertThat(redisServer.getNumberOtherSentinels(), is(2L));
assertThat(redisServer.getNumberOtherSentinels()).isEqualTo(2L);
}
private Properties createProperties() {

View File

@@ -15,14 +15,12 @@
*/
package org.springframework.data.redis.connection.convert;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsCollectionContaining.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Iterator;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisClusterNode.Flag;
import org.springframework.data.redis.connection.RedisClusterNode.LinkState;
@@ -64,48 +62,48 @@ public class ConvertersUnitTests {
Iterator<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(REDIS_3_0_CLUSTER_NODES_RESPONSE).iterator();
RedisClusterNode node = nodes.next(); // 127.0.0.1:6379
assertThat(node.getId(), is("ef570f86c7b1a953846668debc177a3a16733420"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(6379));
assertThat(node.getType(), is(NodeType.MASTER));
assertThat(node.getSlotRange().contains(0), is(true));
assertThat(node.getSlotRange().contains(5460), is(true));
assertThat(node.getSlotRange().contains(5461), is(false));
assertThat(node.getSlotRange().contains(5602), is(true));
assertThat(node.getFlags(), hasItems(Flag.MASTER, Flag.MYSELF));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getId()).isEqualTo("ef570f86c7b1a953846668debc177a3a16733420");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(6379);
assertThat(node.getType()).isEqualTo(NodeType.MASTER);
assertThat(node.getSlotRange().contains(0)).isTrue();
assertThat(node.getSlotRange().contains(5460)).isTrue();
assertThat(node.getSlotRange().contains(5461)).isFalse();
assertThat(node.getSlotRange().contains(5602)).isTrue();
assertThat(node.getFlags()).contains(Flag.MASTER, Flag.MYSELF);
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
node = nodes.next(); // 127.0.0.1:6380
assertThat(node.getId(), is("0f2ee5df45d18c50aca07228cc18b1da96fd5e84"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(6380));
assertThat(node.getType(), is(NodeType.MASTER));
assertThat(node.getSlotRange().contains(5460), is(false));
assertThat(node.getSlotRange().contains(5461), is(true));
assertThat(node.getSlotRange().contains(5462), is(false));
assertThat(node.getSlotRange().contains(10922), is(true));
assertThat(node.getFlags(), hasItems(Flag.MASTER));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getId()).isEqualTo("0f2ee5df45d18c50aca07228cc18b1da96fd5e84");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(6380);
assertThat(node.getType()).isEqualTo(NodeType.MASTER);
assertThat(node.getSlotRange().contains(5460)).isFalse();
assertThat(node.getSlotRange().contains(5461)).isTrue();
assertThat(node.getSlotRange().contains(5462)).isFalse();
assertThat(node.getSlotRange().contains(10922)).isTrue();
assertThat(node.getFlags()).contains(Flag.MASTER);
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
node = nodes.next(); // 127.0.0.1:638
assertThat(node.getId(), is("3b9b8192a874fa8f1f09dbc0ee20afab5738eee7"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(6381));
assertThat(node.getType(), is(NodeType.MASTER));
assertThat(node.getSlotRange().contains(10923), is(true));
assertThat(node.getSlotRange().contains(16383), is(true));
assertThat(node.getFlags(), hasItems(Flag.MASTER));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getId()).isEqualTo("3b9b8192a874fa8f1f09dbc0ee20afab5738eee7");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(6381);
assertThat(node.getType()).isEqualTo(NodeType.MASTER);
assertThat(node.getSlotRange().contains(10923)).isTrue();
assertThat(node.getSlotRange().contains(16383)).isTrue();
assertThat(node.getFlags()).contains(Flag.MASTER);
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
node = nodes.next(); // 127.0.0.1:7369
assertThat(node.getId(), is("8cad73f63eb996fedba89f041636f17d88cda075"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(7369));
assertThat(node.getType(), is(NodeType.SLAVE));
assertThat(node.getMasterId(), is("ef570f86c7b1a953846668debc177a3a16733420"));
assertThat(node.getSlotRange(), notNullValue());
assertThat(node.getFlags(), hasItems(Flag.SLAVE));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getId()).isEqualTo("8cad73f63eb996fedba89f041636f17d88cda075");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(7369);
assertThat(node.getType()).isEqualTo(NodeType.SLAVE);
assertThat(node.getMasterId()).isEqualTo("ef570f86c7b1a953846668debc177a3a16733420");
assertThat(node.getSlotRange()).isNotNull();
assertThat(node.getFlags()).contains(Flag.SLAVE);
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
}
@Test // DATAREDIS-315
@@ -114,48 +112,48 @@ public class ConvertersUnitTests {
Iterator<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(REDIS_3_2_CLUSTER_NODES_RESPONSE).iterator();
RedisClusterNode node = nodes.next(); // 127.0.0.1:6379
assertThat(node.getId(), is("ef570f86c7b1a953846668debc177a3a16733420"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(6379));
assertThat(node.getType(), is(NodeType.MASTER));
assertThat(node.getSlotRange().contains(0), is(true));
assertThat(node.getSlotRange().contains(5460), is(true));
assertThat(node.getSlotRange().contains(5461), is(false));
assertThat(node.getSlotRange().contains(5602), is(true));
assertThat(node.getFlags(), hasItems(Flag.MASTER, Flag.MYSELF));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getId()).isEqualTo("ef570f86c7b1a953846668debc177a3a16733420");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(6379);
assertThat(node.getType()).isEqualTo(NodeType.MASTER);
assertThat(node.getSlotRange().contains(0)).isTrue();
assertThat(node.getSlotRange().contains(5460)).isTrue();
assertThat(node.getSlotRange().contains(5461)).isFalse();
assertThat(node.getSlotRange().contains(5602)).isTrue();
assertThat(node.getFlags()).contains(Flag.MASTER, Flag.MYSELF);
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
node = nodes.next(); // 127.0.0.1:6380
assertThat(node.getId(), is("0f2ee5df45d18c50aca07228cc18b1da96fd5e84"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(6380));
assertThat(node.getType(), is(NodeType.MASTER));
assertThat(node.getSlotRange().contains(5460), is(false));
assertThat(node.getSlotRange().contains(5461), is(true));
assertThat(node.getSlotRange().contains(5462), is(false));
assertThat(node.getSlotRange().contains(10922), is(true));
assertThat(node.getFlags(), hasItems(Flag.MASTER));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getId()).isEqualTo("0f2ee5df45d18c50aca07228cc18b1da96fd5e84");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(6380);
assertThat(node.getType()).isEqualTo(NodeType.MASTER);
assertThat(node.getSlotRange().contains(5460)).isFalse();
assertThat(node.getSlotRange().contains(5461)).isTrue();
assertThat(node.getSlotRange().contains(5462)).isFalse();
assertThat(node.getSlotRange().contains(10922)).isTrue();
assertThat(node.getFlags()).contains(Flag.MASTER);
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
node = nodes.next(); // 127.0.0.1:638
assertThat(node.getId(), is("3b9b8192a874fa8f1f09dbc0ee20afab5738eee7"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(6381));
assertThat(node.getType(), is(NodeType.MASTER));
assertThat(node.getSlotRange().contains(10923), is(true));
assertThat(node.getSlotRange().contains(16383), is(true));
assertThat(node.getFlags(), hasItems(Flag.MASTER));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getId()).isEqualTo("3b9b8192a874fa8f1f09dbc0ee20afab5738eee7");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(6381);
assertThat(node.getType()).isEqualTo(NodeType.MASTER);
assertThat(node.getSlotRange().contains(10923)).isTrue();
assertThat(node.getSlotRange().contains(16383)).isTrue();
assertThat(node.getFlags()).contains(Flag.MASTER);
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
node = nodes.next(); // 127.0.0.1:7369
assertThat(node.getId(), is("8cad73f63eb996fedba89f041636f17d88cda075"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(7369));
assertThat(node.getType(), is(NodeType.SLAVE));
assertThat(node.getMasterId(), is("ef570f86c7b1a953846668debc177a3a16733420"));
assertThat(node.getSlotRange(), notNullValue());
assertThat(node.getFlags(), hasItems(Flag.SLAVE));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getId()).isEqualTo("8cad73f63eb996fedba89f041636f17d88cda075");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(7369);
assertThat(node.getType()).isEqualTo(NodeType.SLAVE);
assertThat(node.getMasterId()).isEqualTo("ef570f86c7b1a953846668debc177a3a16733420");
assertThat(node.getSlotRange()).isNotNull();
assertThat(node.getFlags()).contains(Flag.SLAVE);
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
}
@Test // DATAREDIS-315
@@ -165,11 +163,11 @@ public class ConvertersUnitTests {
.iterator();
RedisClusterNode node = nodes.next(); // 127.0.0.1:6379
assertThat(node.getId(), is("ef570f86c7b1a953846668debc177a3a16733420"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(6379));
assertThat(node.getType(), is(NodeType.MASTER));
assertThat(node.getSlotRange().contains(3456), is(true));
assertThat(node.getId()).isEqualTo("ef570f86c7b1a953846668debc177a3a16733420");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(6379);
assertThat(node.getType()).isEqualTo(NodeType.MASTER);
assertThat(node.getSlotRange().contains(3456)).isTrue();
}
@Test // DATAREDIS-315
@@ -179,13 +177,13 @@ public class ConvertersUnitTests {
CLUSTER_NODE_WITH_FAIL_FLAG_AND_DISCONNECTED_LINK_STATE).iterator();
RedisClusterNode node = nodes.next();
assertThat(node.getId(), is("b8b5ee73b1d1997abff694b3fe8b2397d2138b6d"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(7382));
assertThat(node.getType(), is(NodeType.MASTER));
assertThat(node.getFlags(), hasItems(Flag.MASTER, Flag.FAIL));
assertThat(node.getLinkState(), is(LinkState.DISCONNECTED));
assertThat(node.getSlotRange().getSlots().size(), is(0));
assertThat(node.getId()).isEqualTo("b8b5ee73b1d1997abff694b3fe8b2397d2138b6d");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(7382);
assertThat(node.getType()).isEqualTo(NodeType.MASTER);
assertThat(node.getFlags()).contains(Flag.MASTER, Flag.FAIL);
assertThat(node.getLinkState()).isEqualTo(LinkState.DISCONNECTED);
assertThat(node.getSlotRange().getSlots().size()).isEqualTo(0);
}
@Test // DATAREDIS-315
@@ -194,13 +192,13 @@ public class ConvertersUnitTests {
Iterator<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(CLUSTER_NODE_IMPORTING_SLOT).iterator();
RedisClusterNode node = nodes.next();
assertThat(node.getId(), is("ef570f86c7b1a953846668debc177a3a16733420"));
assertThat(node.getHost(), is("127.0.0.1"));
assertThat(node.getPort(), is(6379));
assertThat(node.getType(), is(NodeType.MASTER));
assertThat(node.getFlags(), hasItem(Flag.MASTER));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getSlotRange().getSlots().size(), is(0));
assertThat(node.getId()).isEqualTo("ef570f86c7b1a953846668debc177a3a16733420");
assertThat(node.getHost()).isEqualTo("127.0.0.1");
assertThat(node.getPort()).isEqualTo(6379);
assertThat(node.getType()).isEqualTo(NodeType.MASTER);
assertThat(node.getFlags()).contains(Flag.MASTER);
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
assertThat(node.getSlotRange().getSlots().size()).isEqualTo(0);
}
}

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.test.util.MockitoUtils.*;
@@ -169,11 +167,11 @@ public class JedisClusterConnectionUnitTests {
@Test // DATAREDIS-315
public void isClosedShouldReturnConnectionStateCorrectly() {
assertThat(connection.isClosed(), is(false));
assertThat(connection.isClosed()).isFalse();
connection.close();
assertThat(connection.isClosed(), is(true));
assertThat(connection.isClosed()).isTrue();
}
@Test // DATAREDIS-315
@@ -184,7 +182,7 @@ public class JedisClusterConnectionUnitTests {
when(con3Mock.clusterInfo()).thenReturn(CLUSTER_INFO_RESPONSE);
ClusterInfo p = connection.clusterGetClusterInfo();
assertThat(p.getSlotsAssigned(), is(16384L));
assertThat(p.getSlotsAssigned()).isEqualTo(16384L);
verifyInvocationsAcross("clusterInfo", times(1), con1Mock, con2Mock, con3Mock);
}
@@ -267,8 +265,8 @@ public class JedisClusterConnectionUnitTests {
try {
connection.serverCommands().dbSize(new RedisClusterNode(CLUSTER_HOST, SLAVEOF_NODE_1_PORT));
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(),
containsString("Node " + CLUSTER_HOST + ":" + SLAVEOF_NODE_1_PORT + " is unknown to cluster"));
assertThat(e.getMessage())
.contains("Node " + CLUSTER_HOST + ":" + SLAVEOF_NODE_1_PORT + " is unknown to cluster");
}
}
@@ -304,7 +302,7 @@ public class JedisClusterConnectionUnitTests {
Long result = connection.serverCommands().dbSize(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_3_PORT));
assertThat(result, is(42L));
assertThat(result).isEqualTo(42L);
}
@Test // DATAREDIS-315, DATAREDIS-890
@@ -362,13 +360,11 @@ public class JedisClusterConnectionUnitTests {
IllegalArgumentException exception = new IllegalArgumentException("Aw, snap!");
expectedException.expect(RedisSystemException.class);
expectedException.expectMessage(exception.getMessage());
expectedException.expectCause(is(exception));
doThrow(exception).when(clusterMock).set("foo".getBytes(), "bar".getBytes());
connection.set("foo".getBytes(), "bar".getBytes());
assertThatExceptionOfType(RedisSystemException.class)
.isThrownBy(() -> connection.set("foo".getBytes(), "bar".getBytes()))
.withMessageContaining(exception.getMessage()).withCause(exception);
}
@Test // DATAREDIS-794

View File

@@ -15,13 +15,13 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import redis.clients.jedis.JedisShardInfo;
import org.junit.After;
import org.junit.Test;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
@@ -52,7 +52,7 @@ public class JedisConnectionFactoryIntegrationTests {
factory.setPort(1234);
factory.afterPropertiesSet();
assertThat(factory.getConnection().ping(), equalTo("PONG"));
assertThat(factory.getConnection().ping()).isEqualTo("PONG");
}
@Test // DATAREDIS-574
@@ -63,6 +63,6 @@ public class JedisConnectionFactoryIntegrationTests {
JedisClientConfiguration.defaultConfiguration());
factory.afterPropertiesSet();
assertThat(factory.getConnection().ping(), equalTo("PONG"));
assertThat(factory.getConnection().ping()).isEqualTo("PONG");
}
}

View File

@@ -15,12 +15,12 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.test.util.RedisSentinelRule;
@@ -60,8 +60,8 @@ public class JedisConnectionFactorySentinelIntegrationTests {
RedisConnection connection = factory.getConnection();
assertThat(factory.getUsePool(), is(true));
assertThat(connection.getClientName(), equalTo("clientName"));
assertThat(factory.getUsePool()).isTrue();
assertThat(connection.getClientName()).isEqualTo("clientName");
}
@Test // DATAREDIS-324
@@ -70,7 +70,7 @@ public class JedisConnectionFactorySentinelIntegrationTests {
factory = new JedisConnectionFactory(SENTINEL_CONFIG);
factory.afterPropertiesSet();
assertThat(factory.getConnection().ping(), equalTo("PONG"));
assertThat(factory.getConnection().ping()).isEqualTo("PONG");
}
@Test // DATAREDIS-552
@@ -80,6 +80,6 @@ public class JedisConnectionFactorySentinelIntegrationTests {
factory.setClientName("clientName");
factory.afterPropertiesSet();
assertThat(factory.getConnection().getClientName(), equalTo("clientName"));
assertThat(factory.getConnection().getClientName()).isEqualTo("clientName");
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import redis.clients.jedis.JedisPoolConfig;
@@ -28,13 +27,11 @@ import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import org.hamcrest.core.AllOf;
import org.hamcrest.core.IsCollectionContaining;
import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.SettingsUtils;
@@ -100,8 +97,8 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
actual.add(byteConnection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
assertThat(Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }))
.isEqualTo(Arrays.asList(new Object[] { "key1", "arg1" }));
}
@Test
@@ -152,7 +149,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
strTuples.add(new DefaultStringTuple("Bob".getBytes(), "Bob", 2.0));
strTuples.add(new DefaultStringTuple("James".getBytes(), "James", 2.0));
Long added = connection.zAdd("myset", strTuples);
assertEquals(2L, added.longValue());
assertThat(added.longValue()).isEqualTo(2L);
}
@Test(expected = InvalidDataAccessApiUsageException.class)
@@ -256,9 +253,9 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
connection.subscribe(listener, expectedChannel.getBytes());
Message message = messages.poll(5, TimeUnit.SECONDS);
assertNotNull(message);
assertEquals(expectedMessage, new String(message.getBody()));
assertEquals(expectedChannel, new String(message.getChannel()));
assertThat(message).isNotNull();
assertThat(new String(message.getBody())).isEqualTo(expectedMessage);
assertThat(new String(message.getChannel())).isEqualTo(expectedChannel);
}
@Test
@@ -269,7 +266,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
final BlockingDeque<Message> messages = new LinkedBlockingDeque<>();
final MessageListener listener = (message, pattern) -> {
assertEquals(expectedPattern, new String(pattern));
assertThat(new String(pattern)).isEqualTo(expectedPattern);
messages.add(message);
};
@@ -314,11 +311,11 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
// Not all providers block on subscribe (Lettuce does not), give some
// time for messages to be received
Message message = messages.poll(5, TimeUnit.SECONDS);
assertNotNull(message);
assertEquals(expectedMessage, new String(message.getBody()));
assertThat(message).isNotNull();
assertThat(new String(message.getBody())).isEqualTo(expectedMessage);
message = messages.poll(5, TimeUnit.SECONDS);
assertNotNull(message);
assertEquals(expectedMessage, new String(message.getBody()));
assertThat(message).isNotNull();
assertThat(new String(message.getBody())).isEqualTo(expectedMessage);
}
@Test
@@ -351,9 +348,9 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
connection.set("redis", "supercalifragilisticexpialidocious");
assertThat(
(Iterable<byte[]>) connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()),
AllOf.allOf(IsInstanceOf.instanceOf(List.class), IsCollectionContaining.hasItems("awesome".getBytes(),
"cool".getBytes(), "supercalifragilisticexpialidocious".getBytes())));
(Iterable<byte[]>) connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()))
.isInstanceOf(List.class)
.contains("awesome".getBytes(), "cool".getBytes(), "supercalifragilisticexpialidocious".getBytes());
}
@Test // DATAREDIS-286, DATAREDIS-564
@@ -365,7 +362,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
connection.expire("expireKey", seconds);
long ttl = connection.ttl("expireKey");
assertThat(ttl, is(seconds));
assertThat(ttl).isEqualTo(seconds);
}
@Test // DATAREDIS-286
@@ -377,8 +374,10 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
connection.pExpire("pexpireKey", millis);
long ttl = connection.pTtl("pexpireKey");
assertTrue(String.format("difference between millis=%s and ttl=%s should not be greater than 20ms but is %s",
millis, ttl, millis - ttl), millis - ttl < 20L);
assertThat(millis - ttl < 20L)
.as(String.format("difference between millis=%s and ttl=%s should not be greater than 20ms but is %s", millis,
ttl, millis - ttl))
.isTrue();
}
@Test // DATAREDIS-330
@@ -387,12 +386,12 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
((JedisConnection) byteConnection).setSentinelConfiguration(
new RedisSentinelConfiguration().master("mymaster").sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380));
assertThat(connection.getSentinelConnection(), notNullValue());
assertThat(connection.getSentinelConnection()).isNotNull();
}
@Test // DATAREDIS-552
public void shouldSetClientName() {
assertThat(connection.getClientName(), is(equalTo("jedis-client")));
assertThat(connection.getClientName()).isEqualTo("jedis-client");
}
@Test // DATAREDIS-106
@@ -404,6 +403,6 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
Set<String> zRangeByScore = connection.zRangeByScore("myzset", "(1", "2");
assertEquals("two", zRangeByScore.iterator().next());
assertThat(zRangeByScore.iterator().next()).isEqualTo("two");
}
}

View File

@@ -15,7 +15,9 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import redis.clients.jedis.JedisPoolConfig;
import java.util.Arrays;
import java.util.List;
@@ -24,6 +26,7 @@ import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
@@ -33,8 +36,6 @@ import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import redis.clients.jedis.JedisPoolConfig;
/**
* Integration test of {@link JedisConnection} pipeline functionality
*
@@ -102,7 +103,7 @@ public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionP
actual.add(connection.exec());
List<Object> results = getResults();
List<Object> execResults = (List<Object>) results.get(0);
assertEquals(Arrays.asList(new Object[] { true, "somethingelse" }), execResults);
assertThat(execResults).isEqualTo(Arrays.asList(new Object[] { true, "somethingelse" }));
}
@Test

View File

@@ -15,12 +15,13 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisPipelineException;
import org.springframework.test.annotation.IfProfileValue;
@@ -60,10 +61,10 @@ public class JedisConnectionPipelineTxIntegrationTests extends JedisConnectionTr
@SuppressWarnings("unchecked")
protected List<Object> getResults() {
assertNull(connection.exec());
assertThat(connection.exec()).isNull();
List<Object> pipelined = connection.closePipeline();
// We expect only the results of exec to be in the closed pipeline
assertEquals(1, pipelined.size());
assertThat(pipelined.size()).isEqualTo(1);
List<Object> txResults = (List<Object>) pipelined.get(0);
// Return exec results and this test should behave exactly like its superclass
return txResults;

View File

@@ -19,6 +19,7 @@ import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import redis.clients.jedis.Client;
@@ -78,7 +77,7 @@ public class JedisConnectionUnitTestSuite {
ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
verifyNativeConnectionInvocation().eval(captor.capture(), any(byte[].class), any(byte[][].class));
assertThat(captor.getValue(), equalTo("return redis.call('SHUTDOWN','NOSAVE')".getBytes()));
assertThat(captor.getValue()).isEqualTo("return redis.call('SHUTDOWN','NOSAVE')".getBytes());
}
@Test // DATAREDIS-184
@@ -89,7 +88,7 @@ public class JedisConnectionUnitTestSuite {
ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
verifyNativeConnectionInvocation().eval(captor.capture(), any(byte[].class), any(byte[][].class));
assertThat(captor.getValue(), equalTo("return redis.call('SHUTDOWN','SAVE')".getBytes()));
assertThat(captor.getValue()).isEqualTo("return redis.call('SHUTDOWN','SAVE')".getBytes());
}
@Test // DATAREDIS-267
@@ -132,37 +131,27 @@ public class JedisConnectionUnitTestSuite {
@Test(expected = IllegalArgumentException.class) // DATAREDIS-472
public void restoreShouldThrowExceptionWhenTtlInMillisExceedsIntegerRange() {
connection.restore("foo".getBytes(), new Long(Integer.MAX_VALUE) + 1L, "bar".getBytes());
connection.restore("foo".getBytes(), (long) Integer.MAX_VALUE + 1L, "bar".getBytes());
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-472
public void setExShouldThrowExceptionWhenTimeExceedsIntegerRange() {
connection.setEx("foo".getBytes(), new Long(Integer.MAX_VALUE) + 1L, "bar".getBytes());
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-472
public void getRangeShouldThrowExceptionWhenStartExceedsIntegerRange() {
connection.getRange("foo".getBytes(), new Long(Integer.MAX_VALUE) + 1L, Integer.MAX_VALUE);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-472
public void getRangeShouldThrowExceptionWhenEndExceedsIntegerRange() {
connection.getRange("foo".getBytes(), Integer.MAX_VALUE, new Long(Integer.MAX_VALUE) + 1L);
connection.setEx("foo".getBytes(), (long) Integer.MAX_VALUE + 1L, "bar".getBytes());
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-472
public void sRandMemberShouldThrowExceptionWhenCountExceedsIntegerRange() {
connection.sRandMember("foo".getBytes(), new Long(Integer.MAX_VALUE) + 1L);
connection.sRandMember("foo".getBytes(), (long) Integer.MAX_VALUE + 1L);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-472
public void zRangeByScoreShouldThrowExceptionWhenOffsetExceedsIntegerRange() {
connection.zRangeByScore("foo".getBytes(), "foo", "bar", new Long(Integer.MAX_VALUE) + 1L, Integer.MAX_VALUE);
connection.zRangeByScore("foo".getBytes(), "foo", "bar", (long) Integer.MAX_VALUE + 1L, Integer.MAX_VALUE);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-472
public void zRangeByScoreShouldThrowExceptionWhenCountExceedsIntegerRange() {
connection.zRangeByScore("foo".getBytes(), "foo", "bar", Integer.MAX_VALUE, new Long(Integer.MAX_VALUE) + 1L);
connection.zRangeByScore("foo".getBytes(), "foo", "bar", Integer.MAX_VALUE, (long) Integer.MAX_VALUE + 1L);
}
@Test // DATAREDIS-531

View File

@@ -15,10 +15,7 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import redis.clients.jedis.params.SetParams;
@@ -30,6 +27,7 @@ import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
@@ -45,13 +43,13 @@ public class JedisConvertersUnitTests {
@Test // DATAREDIS-268
public void convertingEmptyStringToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(JedisConverters.toListOfRedisClientInformation(""), equalTo(Collections.<RedisClientInfo> emptyList()));
assertThat(JedisConverters.toListOfRedisClientInformation("")).isEqualTo(Collections.<RedisClientInfo> emptyList());
}
@Test // DATAREDIS-268
public void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(JedisConverters.toListOfRedisClientInformation(null),
equalTo(Collections.<RedisClientInfo> emptyList()));
assertThat(JedisConverters.toListOfRedisClientInformation(null))
.isEqualTo(Collections.<RedisClientInfo> emptyList());
}
@Test // DATAREDIS-268
@@ -62,7 +60,7 @@ public class JedisConvertersUnitTests {
sb.append("\r\n");
sb.append(CLIENT_ALL_SINGLE_LINE_RESPONSE);
assertThat(JedisConverters.toListOfRedisClientInformation(sb.toString()).size(), equalTo(2));
assertThat(JedisConverters.toListOfRedisClientInformation(sb.toString()).size()).isEqualTo(2);
}
@Test // DATAREDIS-330
@@ -71,7 +69,7 @@ public class JedisConvertersUnitTests {
Map<String, String> values = getRedisServerInfoMap("mymaster", 23697);
List<RedisServer> servers = JedisConverters.toListOfRedisServer(Collections.singletonList(values));
assertThat(servers.size(), is(1));
assertThat(servers.size()).isEqualTo(1);
verifyRedisServerInfo(servers.get(0), values);
}
@@ -82,7 +80,7 @@ public class JedisConvertersUnitTests {
getRedisServerInfoMap("yourmaster", 23680));
List<RedisServer> servers = JedisConverters.toListOfRedisServer(vals);
assertThat(servers.size(), is(vals.size()));
assertThat(servers.size()).isEqualTo(vals.size());
for (int i = 0; i < vals.size(); i++) {
verifyRedisServerInfo(servers.get(i), vals.get(i));
}
@@ -90,12 +88,12 @@ public class JedisConvertersUnitTests {
@Test // DATAREDIS-330
public void convertsRedisServersCorrectlyWhenGivenAnEmptyList() {
assertThat(JedisConverters.toListOfRedisServer(Collections.<Map<String, String>> emptyList()), notNullValue());
assertThat(JedisConverters.toListOfRedisServer(Collections.<Map<String, String>> emptyList())).isNotNull();
}
@Test // DATAREDIS-330
public void convertsRedisServersCorrectlyWhenGivenNull() {
assertThat(JedisConverters.toListOfRedisServer(null), notNullValue());
assertThat(JedisConverters.toListOfRedisServer(null)).isNotNull();
}
/**
@@ -105,7 +103,7 @@ public class JedisConvertersUnitTests {
byte[] defaultValue = "tyrion".getBytes();
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(null, defaultValue), is(defaultValue));
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(null, defaultValue)).isEqualTo(defaultValue);
}
@Test // DATAREDIS-378
@@ -113,38 +111,38 @@ public class JedisConvertersUnitTests {
byte[] defaultValue = "tyrion".getBytes();
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.unbounded().getMax(), defaultValue),
is(defaultValue));
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.unbounded().getMax(), defaultValue))
.isEqualTo(defaultValue);
}
@Test // DATAREDIS-378
public void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsIncluing() {
assertThat(
JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gte(JedisConverters.toBytes("a")).getMin(), null),
is(JedisConverters.toBytes("[a")));
JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gte(JedisConverters.toBytes("a")).getMin(), null))
.isEqualTo(JedisConverters.toBytes("[a"));
}
@Test // DATAREDIS-378
public void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsExcluding() {
assertThat(
JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(JedisConverters.toBytes("a")).getMin(), null),
is(JedisConverters.toBytes("(a")));
JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(JedisConverters.toBytes("a")).getMin(), null))
.isEqualTo(JedisConverters.toBytes("(a"));
}
@Test // DATAREDIS-378
public void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsAString() {
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt("a").getMin(), null),
is(JedisConverters.toBytes("(a")));
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt("a").getMin(), null))
.isEqualTo(JedisConverters.toBytes("(a"));
}
@Test // DATAREDIS-378
public void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsANumber() {
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(1L).getMin(), null),
is(JedisConverters.toBytes("(1")));
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(1L).getMin(), null))
.isEqualTo(JedisConverters.toBytes("(1"));
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-378
@@ -157,7 +155,7 @@ public class JedisConvertersUnitTests {
byte[] defaultValue = "tyrion".getBytes();
assertThat(JedisConverters.boundaryToBytesForZRange(null, defaultValue), is(defaultValue));
assertThat(JedisConverters.boundaryToBytesForZRange(null, defaultValue)).isEqualTo(defaultValue);
}
@Test // DATAREDIS-352
@@ -165,35 +163,36 @@ public class JedisConvertersUnitTests {
byte[] defaultValue = "tyrion".getBytes();
assertThat(JedisConverters.boundaryToBytesForZRange(Range.unbounded().getMax(), defaultValue), is(defaultValue));
assertThat(JedisConverters.boundaryToBytesForZRange(Range.unbounded().getMax(), defaultValue))
.isEqualTo(defaultValue);
}
@Test // DATAREDIS-352
public void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsIncluing() {
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gte(JedisConverters.toBytes("a")).getMin(), null),
is(JedisConverters.toBytes("a")));
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gte(JedisConverters.toBytes("a")).getMin(), null))
.isEqualTo(JedisConverters.toBytes("a"));
}
@Test // DATAREDIS-352
public void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsExcluding() {
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt(JedisConverters.toBytes("a")).getMin(), null),
is(JedisConverters.toBytes("(a")));
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt(JedisConverters.toBytes("a")).getMin(), null))
.isEqualTo(JedisConverters.toBytes("(a"));
}
@Test // DATAREDIS-352
public void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsAString() {
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt("a").getMin(), null),
is(JedisConverters.toBytes("(a")));
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt("a").getMin(), null))
.isEqualTo(JedisConverters.toBytes("(a"));
}
@Test // DATAREDIS-352
public void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsANumber() {
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt(1L).getMin(), null),
is(JedisConverters.toBytes("(1")));
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt(1L).getMin(), null))
.isEqualTo(JedisConverters.toBytes("(1"));
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-352
@@ -203,33 +202,33 @@ public class JedisConvertersUnitTests {
@Test // DATAREDIS-316, DATAREDIS-749
public void toSetCommandExPxOptionShouldReturnEXforSeconds() {
assertThat(toString(JedisConverters.toSetCommandExPxArgument(Expiration.seconds(100))), equalTo("ex 100"));
assertThat(toString(JedisConverters.toSetCommandExPxArgument(Expiration.seconds(100)))).isEqualTo("ex 100");
}
@Test // DATAREDIS-316, DATAREDIS-749
public void toSetCommandExPxOptionShouldReturnEXforMilliseconds() {
assertThat(toString(JedisConverters.toSetCommandExPxArgument(Expiration.milliseconds(100))), equalTo("px 100"));
assertThat(toString(JedisConverters.toSetCommandExPxArgument(Expiration.milliseconds(100)))).isEqualTo("px 100");
}
@Test // DATAREDIS-316, DATAREDIS-749
public void toSetCommandNxXxOptionShouldReturnNXforAbsent() {
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.ifAbsent())), equalTo("nx"));
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.ifAbsent()))).isEqualTo("nx");
}
@Test // DATAREDIS-316, DATAREDIS-749
public void toSetCommandNxXxOptionShouldReturnXXforAbsent() {
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.ifPresent())), equalTo("xx"));
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.ifPresent()))).isEqualTo("xx");
}
@Test // DATAREDIS-316, DATAREDIS-749
public void toSetCommandNxXxOptionShouldReturnEmptyArrayforUpsert() {
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.upsert())), equalTo(""));
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.upsert()))).isEqualTo("");
}
private void verifyRedisServerInfo(RedisServer server, Map<String, String> values) {
for (Map.Entry<String, String> entry : values.entrySet()) {
assertThat(server.get(entry.getKey()), equalTo(entry.getValue()));
assertThat(server.get(entry.getKey())).isEqualTo(entry.getValue());
}
}

View File

@@ -15,21 +15,20 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsInstanceOf.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.ClusterRedirectException;
import org.springframework.data.redis.TooManyClusterRedirectionsException;
import static org.assertj.core.api.Assertions.*;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.exceptions.JedisAskDataException;
import redis.clients.jedis.exceptions.JedisClusterMaxAttemptsException;
import redis.clients.jedis.exceptions.JedisMovedDataException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.ClusterRedirectException;
import org.springframework.data.redis.TooManyClusterRedirectionsException;
/**
* @author Christoph Strobl
*/
@@ -48,10 +47,10 @@ public class JedisExceptionConverterUnitTests {
DataAccessException converted = converter.convert(new JedisMovedDataException("MOVED 3999 127.0.0.1:6381",
new HostAndPort("127.0.0.1", 6381), 3999));
assertThat(converted, instanceOf(ClusterRedirectException.class));
assertThat(((ClusterRedirectException) converted).getSlot(), is(3999));
assertThat(((ClusterRedirectException) converted).getTargetHost(), is("127.0.0.1"));
assertThat(((ClusterRedirectException) converted).getTargetPort(), is(6381));
assertThat(converted).isInstanceOf(ClusterRedirectException.class);
assertThat(((ClusterRedirectException) converted).getSlot()).isEqualTo(3999);
assertThat(((ClusterRedirectException) converted).getTargetHost()).isEqualTo("127.0.0.1");
assertThat(((ClusterRedirectException) converted).getTargetPort()).isEqualTo(6381);
}
@Test // DATAREDIS-315
@@ -60,10 +59,10 @@ public class JedisExceptionConverterUnitTests {
DataAccessException converted = converter.convert(new JedisAskDataException("ASK 3999 127.0.0.1:6381",
new HostAndPort("127.0.0.1", 6381), 3999));
assertThat(converted, instanceOf(ClusterRedirectException.class));
assertThat(((ClusterRedirectException) converted).getSlot(), is(3999));
assertThat(((ClusterRedirectException) converted).getTargetHost(), is("127.0.0.1"));
assertThat(((ClusterRedirectException) converted).getTargetPort(), is(6381));
assertThat(converted).isInstanceOf(ClusterRedirectException.class);
assertThat(((ClusterRedirectException) converted).getSlot()).isEqualTo(3999);
assertThat(((ClusterRedirectException) converted).getTargetHost()).isEqualTo("127.0.0.1");
assertThat(((ClusterRedirectException) converted).getTargetPort()).isEqualTo(6381);
}
@Test // DATAREDIS-315
@@ -72,6 +71,6 @@ public class JedisExceptionConverterUnitTests {
DataAccessException converted = converter
.convert(new JedisClusterMaxAttemptsException("Too many redirections?"));
assertThat(converted, instanceOf(TooManyClusterRedirectionsException.class));
assertThat(converted).isInstanceOf(TooManyClusterRedirectionsException.class);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import redis.clients.jedis.Jedis;
@@ -30,6 +29,7 @@ import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
@@ -136,8 +136,8 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
public void shouldReadMastersCorrectly() {
List<RedisServer> servers = (List<RedisServer>) connectionFactory.getSentinelConnection().masters();
assertThat(servers.size(), is(1));
assertThat(servers.get(0).getName(), is(MASTER_NAME));
assertThat(servers.size()).isEqualTo(1);
assertThat(servers.get(0).getName()).isEqualTo(MASTER_NAME);
}
@Test // DATAREDIS-330
@@ -146,11 +146,11 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
List<RedisServer> servers = (List<RedisServer>) sentinelConnection.masters();
assertThat(servers.size(), is(1));
assertThat(servers.size()).isEqualTo(1);
Collection<RedisServer> slaves = sentinelConnection.slaves(servers.get(0));
assertThat(slaves.size(), is(2));
assertThat(slaves, hasItems(SLAVE_0, SLAVE_1));
assertThat(slaves.size()).isEqualTo(2);
assertThat(slaves).contains(SLAVE_0, SLAVE_1);
}
@Test // DATAREDIS-552
@@ -159,7 +159,7 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
Jedis jedis = (Jedis) ReflectionTestUtils.getField(sentinelConnection, "jedis");
assertThat(jedis.clientGetname(), is(equalTo("jedis-client")));
assertThat(jedis.clientGetname()).isEqualTo("jedis-client");
}
}

View File

@@ -15,23 +15,20 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import redis.clients.jedis.BinaryJedisPubSub;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.never;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisInvalidSubscriptionException;
import redis.clients.jedis.BinaryJedisPubSub;
/**
* Unit test of {@link JedisSubscription}
*
@@ -58,9 +55,9 @@ public class JedisSubscriptionTests {
subscription.unsubscribe();
verify(jedisPubSub, times(1)).unsubscribe();
verify(jedisPubSub, never()).punsubscribe();
assertFalse(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isFalse();
assertThat(subscription.getChannels().isEmpty()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -70,11 +67,11 @@ public class JedisSubscriptionTests {
subscription.unsubscribe();
verify(jedisPubSub, times(1)).unsubscribe();
verify(jedisPubSub, never()).punsubscribe();
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getChannels().isEmpty()).isTrue();
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
}
@Test
@@ -84,9 +81,9 @@ public class JedisSubscriptionTests {
subscription.unsubscribe(channel);
verify(jedisPubSub, times(1)).unsubscribe(channel);
verify(jedisPubSub, never()).punsubscribe();
assertFalse(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isFalse();
assertThat(subscription.getChannels().isEmpty()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -96,11 +93,11 @@ public class JedisSubscriptionTests {
subscription.unsubscribe(new byte[][] { "a".getBytes() });
verify(jedisPubSub, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
verify(jedisPubSub, never()).punsubscribe();
assertTrue(subscription.isAlive());
assertThat(subscription.isAlive()).isTrue();
Collection<byte[]> subChannels = subscription.getChannels();
assertEquals(1, subChannels.size());
assertArrayEquals("b".getBytes(), subChannels.iterator().next());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subChannels.size()).isEqualTo(1);
assertThat(subChannels.iterator().next()).isEqualTo("b".getBytes());
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -111,11 +108,11 @@ public class JedisSubscriptionTests {
subscription.unsubscribe(channel);
verify(jedisPubSub, times(1)).unsubscribe(channel);
verify(jedisPubSub, never()).punsubscribe();
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getChannels().isEmpty()).isTrue();
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
}
@Test
@@ -126,13 +123,13 @@ public class JedisSubscriptionTests {
subscription.unsubscribe(channel);
verify(jedisPubSub, times(1)).unsubscribe(channel);
verify(jedisPubSub, never()).punsubscribe();
assertTrue(subscription.isAlive());
assertThat(subscription.isAlive()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("b".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("b".getBytes());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
}
@Test
@@ -141,18 +138,18 @@ public class JedisSubscriptionTests {
subscription.unsubscribe();
verify(jedisPubSub, never()).unsubscribe();
verify(jedisPubSub, never()).punsubscribe();
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getChannels().isEmpty()).isTrue();
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
}
@Test
public void testUnsubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
assertThat(subscription.isAlive()).isFalse();
subscription.unsubscribe();
verify(jedisPubSub, times(1)).unsubscribe();
verify(jedisPubSub, never()).punsubscribe();
@@ -162,7 +159,7 @@ public class JedisSubscriptionTests {
public void testSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
assertThat(subscription.isAlive()).isFalse();
subscription.subscribe(new byte[][] { "s".getBytes() });
}
@@ -172,9 +169,9 @@ public class JedisSubscriptionTests {
subscription.pUnsubscribe();
verify(jedisPubSub, never()).unsubscribe();
verify(jedisPubSub, times(1)).punsubscribe();
assertFalse(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isFalse();
assertThat(subscription.getChannels().isEmpty()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -184,11 +181,11 @@ public class JedisSubscriptionTests {
subscription.pUnsubscribe();
verify(jedisPubSub, never()).unsubscribe();
verify(jedisPubSub, times(1)).punsubscribe();
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("a".getBytes());
}
@Test
@@ -198,9 +195,9 @@ public class JedisSubscriptionTests {
subscription.pUnsubscribe(pattern);
verify(jedisPubSub, never()).unsubscribe();
verify(jedisPubSub, times(1)).punsubscribe(pattern);
assertFalse(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isFalse();
assertThat(subscription.getChannels().isEmpty()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -210,11 +207,11 @@ public class JedisSubscriptionTests {
subscription.pUnsubscribe(new byte[][] { "a*".getBytes() });
verify(jedisPubSub, times(1)).punsubscribe(new byte[][] { "a*".getBytes() });
verify(jedisPubSub, never()).unsubscribe();
assertTrue(subscription.isAlive());
assertThat(subscription.isAlive()).isTrue();
Collection<byte[]> subPatterns = subscription.getPatterns();
assertEquals(1, subPatterns.size());
assertArrayEquals("b*".getBytes(), subPatterns.iterator().next());
assertTrue(subscription.getChannels().isEmpty());
assertThat(subPatterns.size()).isEqualTo(1);
assertThat(subPatterns.iterator().next()).isEqualTo("b*".getBytes());
assertThat(subscription.getChannels().isEmpty()).isTrue();
}
@Test
@@ -225,11 +222,11 @@ public class JedisSubscriptionTests {
subscription.pUnsubscribe(pattern);
verify(jedisPubSub, times(1)).punsubscribe(pattern);
verify(jedisPubSub, never()).unsubscribe();
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("a".getBytes());
}
@Test
@@ -240,13 +237,13 @@ public class JedisSubscriptionTests {
subscription.pUnsubscribe(pattern);
verify(jedisPubSub, never()).unsubscribe();
verify(jedisPubSub, times(1)).punsubscribe(pattern);
assertTrue(subscription.isAlive());
assertThat(subscription.isAlive()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("a".getBytes());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("b*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("b*".getBytes());
}
@Test
@@ -255,18 +252,18 @@ public class JedisSubscriptionTests {
subscription.pUnsubscribe();
verify(jedisPubSub, never()).unsubscribe();
verify(jedisPubSub, never()).punsubscribe();
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("s".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("s".getBytes());
}
@Test
public void testPUnsubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
assertThat(subscription.isAlive()).isFalse();
subscription.pUnsubscribe();
verify(jedisPubSub, times(1)).unsubscribe();
verify(jedisPubSub, never()).punsubscribe();
@@ -276,7 +273,7 @@ public class JedisSubscriptionTests {
public void testPSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
assertThat(subscription.isAlive()).isFalse();
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.List;
@@ -32,6 +31,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -129,6 +129,6 @@ public class ScanTests {
executor.shutdown();
assertThat(exception.get(), is(nullValue()));
assertThat(exception.get()).isNull();
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.test.util.ReflectionTestUtils.*;
import io.lettuce.core.RedisException;
@@ -30,6 +29,7 @@ import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.PoolException;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
@@ -66,7 +66,7 @@ public class DefaultLettucePoolTests {
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
assertNotNull(client);
assertThat(client).isNotNull();
client.sync().ping();
client.close();
}
@@ -81,7 +81,7 @@ public class DefaultLettucePoolTests {
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
assertNotNull(client);
assertThat(client).isNotNull();
try {
pool.getResource();
fail("PoolException should be thrown when pool exhausted");
@@ -99,7 +99,7 @@ public class DefaultLettucePoolTests {
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
assertNotNull(client);
assertThat(client).isNotNull();
client.close();
}
@@ -122,9 +122,9 @@ public class DefaultLettucePoolTests {
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
assertNotNull(client);
assertThat(client).isNotNull();
pool.returnResource(client);
assertNotNull(pool.getResource());
assertThat(pool.getResource()).isNotNull();
client.close();
}
@@ -138,10 +138,10 @@ public class DefaultLettucePoolTests {
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
assertNotNull(client);
assertThat(client).isNotNull();
pool.returnBrokenResource(client);
StatefulRedisConnection<byte[], byte[]> client2 = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
assertNotSame(client, client2);
assertThat(client2).isNotSameAs(client);
try {
client.sync().ping();
fail("Broken resouce connection should be closed");
@@ -158,7 +158,7 @@ public class DefaultLettucePoolTests {
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.setDatabase(1);
pool.afterPropertiesSet();
assertNotNull(pool.getResource());
assertThat(pool.getResource()).isNotNull();
}
@Test(expected = PoolException.class)
@@ -215,7 +215,7 @@ public class DefaultLettucePoolTests {
RedisURI redisUri = (RedisURI) getField(pool.getClient(), "redisURI");
assertThat(redisUri.getPassword(), is(equalTo(pool.getPassword().toCharArray())));
assertThat(redisUri.getPassword()).isEqualTo(pool.getPassword().toCharArray());
}
@Test // DATAREDIS-462
@@ -224,6 +224,6 @@ public class DefaultLettucePoolTests {
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setDatabase(1);
pool.afterPropertiesSet();
assertNotNull(pool.getResource());
assertThat(pool.getResource()).isNotNull();
}
}

View File

@@ -15,10 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.AnyOf.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.test.util.MockitoUtils.*;
@@ -46,6 +43,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.redis.connection.ClusterCommandExecutor;
import org.springframework.data.redis.connection.ClusterNodeResourceProvider;
import org.springframework.data.redis.connection.ClusterTopologyProvider;
@@ -185,11 +183,11 @@ public class LettuceClusterConnectionUnitTests {
@Test // DATAREDIS-315
public void isClosedShouldReturnConnectionStateCorrectly() {
assertThat(connection.isClosed(), is(false));
assertThat(connection.isClosed()).isFalse();
connection.close();
assertThat(connection.isClosed(), is(true));
assertThat(connection.isClosed()).isTrue();
}
@Test // DATAREDIS-315
@@ -229,7 +227,7 @@ public class LettuceClusterConnectionUnitTests {
when(clusterConnection2Mock.randomkey()).thenReturn(KEY_2_BYTES);
when(clusterConnection3Mock.randomkey()).thenReturn(KEY_3_BYTES);
assertThat(connection.randomKey(), anyOf(is(KEY_1_BYTES), is(KEY_2_BYTES), is(KEY_3_BYTES)));
assertThat(connection.randomKey()).isIn(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES);
verifyInvocationsAcross("randomkey", times(1), clusterConnection1Mock, clusterConnection2Mock,
clusterConnection3Mock);
}
@@ -240,7 +238,7 @@ public class LettuceClusterConnectionUnitTests {
when(clusterConnection3Mock.randomkey()).thenReturn(KEY_3_BYTES);
for (int i = 0; i < 100; i++) {
assertThat(connection.randomKey(), is(KEY_3_BYTES));
assertThat(connection.randomKey()).isEqualTo(KEY_3_BYTES);
}
}
@@ -251,7 +249,7 @@ public class LettuceClusterConnectionUnitTests {
when(clusterConnection2Mock.randomkey()).thenReturn(null);
when(clusterConnection3Mock.randomkey()).thenReturn(null);
assertThat(connection.randomKey(), nullValue());
assertThat(connection.randomKey()).isNull();
}
@Test // DATAREDIS-315

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import io.lettuce.core.EpollProvider;
@@ -37,6 +36,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.RedisSystemException;
@@ -102,9 +102,9 @@ public class LettuceConnectionFactoryTests {
// expected, shared conn is closed
}
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory.getConnection());
assertNotSame(nativeConn, conn2.getNativeConnection());
assertThat(conn2.getNativeConnection()).isNotSameAs(nativeConn);
conn2.set("anotherkey", "anothervalue");
assertEquals("anothervalue", conn2.get("anotherkey"));
assertThat(conn2.get("anotherkey")).isEqualTo("anothervalue");
conn2.close();
}
@@ -130,7 +130,7 @@ public class LettuceConnectionFactoryTests {
public void testValidateNoError() {
factory.setValidateConnection(true);
RedisConnection conn2 = factory.getConnection();
assertSame(connection.getNativeConnection(), conn2.getNativeConnection());
assertThat(conn2.getNativeConnection()).isSameAs(connection.getNativeConnection());
}
@Test // DATAREDIS-973
@@ -174,7 +174,7 @@ public class LettuceConnectionFactoryTests {
try {
// there should still be nothing in database 1
assertEquals(Long.valueOf(0), separateDatabase.dbSize());
assertThat(separateDatabase.dbSize()).isEqualTo(Long.valueOf(0));
} finally {
separateDatabase.close();
factory2.destroy();
@@ -223,11 +223,11 @@ public class LettuceConnectionFactoryTests {
public void testDisableSharedConnection() throws Exception {
factory.setShareNativeConnection(false);
RedisConnection conn2 = factory.getConnection();
assertNotSame(connection.getNativeConnection(), conn2.getNativeConnection());
assertThat(conn2.getNativeConnection()).isNotSameAs(connection.getNativeConnection());
// Give some time for native connection to asynchronously initialize, else close doesn't work
Thread.sleep(100);
conn2.close();
assertTrue(conn2.isClosed());
assertThat(conn2.isClosed()).isTrue();
// Give some time for native connection to asynchronously close
Thread.sleep(100);
try {
@@ -244,7 +244,7 @@ public class LettuceConnectionFactoryTests {
RedisAsyncCommands<byte[], byte[]> nativeConn = (RedisAsyncCommands<byte[], byte[]>) connection
.getNativeConnection();
factory.resetConnection();
assertNotSame(nativeConn, factory.getConnection().getNativeConnection());
assertThat(factory.getConnection().getNativeConnection()).isNotSameAs(nativeConn);
nativeConn.getStatefulConnection().close();
}
@@ -255,7 +255,7 @@ public class LettuceConnectionFactoryTests {
.getNativeConnection();
factory.initConnection();
RedisConnection newConnection = factory.getConnection();
assertNotSame(nativeConn, newConnection.getNativeConnection());
assertThat(newConnection.getNativeConnection()).isNotSameAs(nativeConn);
newConnection.close();
}
@@ -267,7 +267,7 @@ public class LettuceConnectionFactoryTests {
factory.resetConnection();
factory.initConnection();
RedisConnection newConnection = factory.getConnection();
assertNotSame(nativeConn, newConnection.getNativeConnection());
assertThat(newConnection.getNativeConnection()).isNotSameAs(nativeConn);
newConnection.close();
}
@@ -295,7 +295,7 @@ public class LettuceConnectionFactoryTests {
factory.setShareNativeConnection(false);
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
assertNull(factory.getSharedConnection());
assertThat(factory.getSharedConnection()).isNull();
}
@Test
@@ -363,8 +363,8 @@ public class LettuceConnectionFactoryTests {
String key = "key-in-db-2";
connectionToDbIndex2.set(key, "the wheel of time");
assertThat(connection.get(key), nullValue());
assertThat(connectionToDbIndex2.get(key), notNullValue());
assertThat(connection.get(key)).isNull();
assertThat(connectionToDbIndex2.get(key)).isNotNull();
} finally {
connectionToDbIndex2.close();
}
@@ -382,7 +382,7 @@ public class LettuceConnectionFactoryTests {
StringRedisConnection connection = new DefaultStringRedisConnection(factory.getConnection());
try {
assertThat(connection.ping(), is(equalTo("PONG")));
assertThat(connection.ping()).isEqualTo("PONG");
} finally {
connection.close();
}
@@ -397,7 +397,7 @@ public class LettuceConnectionFactoryTests {
ConnectionFactoryTracker.add(factory);
assertThat(factory.getReactiveConnection().execute(BaseRedisReactiveCommands::ping).blockFirst(), is("PONG"));
assertThat(factory.getReactiveConnection().execute(BaseRedisReactiveCommands::ping).blockFirst()).isEqualTo("PONG");
}
@Test // DATAREDIS-667
@@ -424,7 +424,7 @@ public class LettuceConnectionFactoryTests {
subsequent.close();
assertThat(initialNativeConnection, is(subsequentNativeConnection));
assertThat(initialNativeConnection).isEqualTo(subsequentNativeConnection);
factory.destroy();
}
@@ -442,7 +442,7 @@ public class LettuceConnectionFactoryTests {
factory.afterPropertiesSet();
RedisConnection connection = factory.getConnection();
assertThat(connection.ping(), is(equalTo("PONG")));
assertThat(connection.ping()).isEqualTo("PONG");
connection.close();
factory.destroy();
@@ -451,8 +451,8 @@ public class LettuceConnectionFactoryTests {
@Test // DATAREDIS-762, DATAREDIS-869
public void factoryUsesElastiCacheMasterReplicaConnections() {
assumeThat(String.format("No slaves connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true));
assumeTrue(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0);
LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder().readFrom(ReadFrom.SLAVE)
.build();
@@ -466,8 +466,8 @@ public class LettuceConnectionFactoryTests {
RedisConnection connection = factory.getConnection();
try {
assertThat(connection.ping(), is(equalTo("PONG")));
assertThat(connection.info().getProperty("role"), is(equalTo("slave")));
assertThat(connection.ping()).isEqualTo("PONG");
assertThat(connection.info().getProperty("role")).isEqualTo("slave");
} finally {
connection.close();
}
@@ -478,8 +478,8 @@ public class LettuceConnectionFactoryTests {
@Test // DATAREDIS-762, DATAREDIS-869
public void factoryUsesElastiCacheMasterWithoutMaster() {
assumeThat(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true));
assumeTrue(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0);
LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder().readFrom(ReadFrom.MASTER)
.build();
@@ -497,8 +497,8 @@ public class LettuceConnectionFactoryTests {
fail("Expected RedisException: Master is currently unknown");
} catch (RedisSystemException e) {
assertThat(e.getCause(), is(instanceOf(RedisException.class)));
assertThat(e.getCause().getMessage(), containsString("Master is currently unknown"));
assertThat(e.getCause()).isInstanceOf(RedisException.class);
assertThat(e.getCause().getMessage()).contains("Master is currently unknown");
} finally {
connection.close();
}
@@ -509,8 +509,8 @@ public class LettuceConnectionFactoryTests {
@Test // DATAREDIS-580, DATAREDIS-869
public void factoryUsesMasterReplicaConnections() {
assumeThat(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true));
assumeTrue(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0);
LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder().readFrom(ReadFrom.SLAVE)
.build();
@@ -522,8 +522,8 @@ public class LettuceConnectionFactoryTests {
RedisConnection connection = factory.getConnection();
try {
assertThat(connection.ping(), is(equalTo("PONG")));
assertThat(connection.info().getProperty("role"), is(equalTo("slave")));
assertThat(connection.ping()).isEqualTo("PONG");
assertThat(connection.info().getProperty("role")).isEqualTo("slave");
} finally {
connection.close();
}
@@ -545,7 +545,7 @@ public class LettuceConnectionFactoryTests {
RedisConnection connection = factory.getConnection();
assertThat(connection.getClientName(), is(equalTo("clientName")));
assertThat(connection.getClientName()).isEqualTo("clientName");
connection.close();
}
@@ -560,7 +560,7 @@ public class LettuceConnectionFactoryTests {
ConnectionFactoryTracker.add(factory);
RedisConnection connection = factory.getConnection();
assertThat(connection.getClientName(), equalTo("clientName"));
assertThat(connection.getClientName()).isEqualTo("clientName");
connection.close();
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
@@ -27,12 +26,10 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.hamcrest.core.AllOf;
import org.hamcrest.core.IsCollectionContaining;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.RedisVersionUtils;
@@ -79,7 +76,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
Thread.sleep(1000);
connection.set("heythere", "hi");
th.join();
assertEquals("hi", connection.get("heythere"));
assertThat(connection.get("heythere")).isEqualTo("hi");
}
@Test
@@ -92,14 +89,14 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
// We get immediate results executing command in separate conn (not part
// of tx)
conn2.set("txs2", "hi");
assertEquals("hi", conn2.get("txs2"));
assertThat(conn2.get("txs2")).isEqualTo("hi");
// Transactional value not yet set
assertEquals("rightnow", conn2.get("txs1"));
assertThat(conn2.get("txs1")).isEqualTo("rightnow");
connection.exec();
// Now it should be set
assertEquals("delay", conn2.get("txs1"));
assertThat(conn2.get("txs1")).isEqualTo("delay");
conn2.closePipeline();
conn2.close();
}
@@ -262,7 +259,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
th.start();
Thread.sleep(1000);
connection.scriptKill();
assertTrue(waitFor(scriptDead::get, 3000l));
assertThat(waitFor(scriptDead::get, 3000l)).isTrue();
}
@Test
@@ -278,7 +275,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
factory2.afterPropertiesSet();
StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
assertEquals("bar", conn2.get("foo"));
assertThat(conn2.get("foo")).isEqualTo("bar");
} finally {
if (conn2.exists("foo")) {
conn2.del("foo");
@@ -297,9 +294,9 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
connection.set("redis", "supercalifragilisticexpialidocious");
assertThat(
(Iterable<byte[]>) connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()),
AllOf.allOf(IsInstanceOf.instanceOf(List.class), IsCollectionContaining.hasItems("awesome".getBytes(),
"cool".getBytes(), "supercalifragilisticexpialidocious".getBytes())));
(Iterable<byte[]>) connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()))
.isInstanceOf(List.class)
.contains("awesome".getBytes(), "cool".getBytes(), "supercalifragilisticexpialidocious".getBytes());
}
@SuppressWarnings("unchecked")
@@ -312,8 +309,8 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
actual.add(byteConnection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes()));
List<Object> results = getResults();
List<byte[]> scriptResults = (List<byte[]>) results.get(0);
assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }),
Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }));
assertThat(Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) }))
.isEqualTo(Arrays.asList(new Object[] { "key1", "arg1" }));
}
@Test // DATAREDIS-106
@@ -325,7 +322,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
Set<String> zRangeByScore = connection.zRangeByScore("myzset", "(1", "2");
assertEquals("two", zRangeByScore.iterator().next());
assertThat(zRangeByScore.iterator().next()).isEqualTo("two");
}
@Test // DATAREDIS-348
@@ -334,6 +331,6 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
((LettuceConnection) byteConnection).setSentinelConfiguration(
new RedisSentinelConfiguration().master("mymaster").sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380));
assertThat(connection.getSentinelConnection(), notNullValue());
assertThat(connection.getSentinelConnection()).isNotNull();
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
@@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.RedisVersionUtils;
import org.springframework.data.redis.SettingsUtils;
@@ -78,7 +79,7 @@ public class LettuceConnectionPipelineIntegrationTests extends AbstractConnectio
Thread.sleep(1000);
connection.scriptKill();
getResults();
assertTrue(waitFor(scriptDead::get, 3000l));
assertThat(waitFor(scriptDead::get, 3000l)).isTrue();
}
@Test
@@ -94,7 +95,7 @@ public class LettuceConnectionPipelineIntegrationTests extends AbstractConnectio
factory2.afterPropertiesSet();
StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
assertEquals("bar", conn2.get("foo"));
assertThat(conn2.get("foo")).isEqualTo("bar");
} finally {
if (conn2.exists("foo")) {
conn2.del("foo");

View File

@@ -15,11 +15,12 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.List;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisPipelineException;
import org.springframework.test.annotation.IfProfileValue;
@@ -74,10 +75,10 @@ public class LettuceConnectionPipelineTxIntegrationTests extends LettuceConnecti
@SuppressWarnings("unchecked")
protected List<Object> getResults() {
assertNull(connection.exec());
assertThat(connection.exec()).isNull();
List<Object> pipelined = connection.closePipeline();
// We expect only the results of exec to be in the closed pipeline
assertEquals(1, pipelined.size());
assertThat(pipelined.size()).isEqualTo(1);
List<Object> txResults = (List<Object>) pipelined.get(0);
// Return exec results and this test should behave exactly like its superclass
return txResults;

View File

@@ -15,12 +15,13 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.StringRedisConnection;
@@ -54,7 +55,7 @@ public class LettuceConnectionTransactionIntegrationTests extends AbstractConnec
factory2.afterPropertiesSet();
StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
assertEquals("bar", conn2.get("foo"));
assertThat(conn2.get("foo")).isEqualTo("bar");
} finally {
if (conn2.exists("foo")) {
conn2.del("foo");

View File

@@ -15,19 +15,14 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.any;
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.protocol.RedisCommand;
import java.lang.reflect.InvocationTargetException;
@@ -35,7 +30,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.mockito.Mockito;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.data.redis.connection.AbstractConnectionUnitTestBase;
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
@@ -152,13 +147,8 @@ public class LettuceConnectionUnitTestSuite {
when(syncCommandsMock.set(any(), any())).thenThrow(exception);
connection = new LettuceConnection(null, 0, clientMock, null, 1);
try {
connection.set("foo".getBytes(), "bar".getBytes());
} catch (Exception e) {
assertThat(e.getMessage(), containsString(exception.getMessage()));
assertThat(e.getCause(), is((Throwable) exception));
}
assertThatThrownBy(() -> connection.set("foo".getBytes(), "bar".getBytes()))
.hasMessageContaining(exception.getMessage()).hasRootCause(exception);
}
@Test // DATAREDIS-603
@@ -166,19 +156,12 @@ public class LettuceConnectionUnitTestSuite {
IllegalArgumentException exception = new IllegalArgumentException("Aw, snap!");
RedisCommand future = mock(RedisCommand.class, Mockito.withSettings().extraInterfaces(RedisFuture.class));
when(((RedisFuture) future).get()).thenThrow(exception);
when(asyncCommandsMock.set(any(byte[].class), any(byte[].class))).thenReturn((RedisFuture) future);
when(asyncCommandsMock.set(any(byte[].class), any(byte[].class))).thenThrow(exception);
connection = new LettuceConnection(null, 0, clientMock, null, 1);
connection.openPipeline();
try {
connection.set("foo".getBytes(), "bar".getBytes());
} catch (Exception e) {
assertThat(e.getMessage(), containsString(exception.getMessage()));
assertThat(e.getCause(), is((Throwable) exception));
}
assertThatThrownBy(() -> connection.set("foo".getBytes(), "bar".getBytes()))
.hasMessageContaining(exception.getMessage()).hasRootCause(exception);
}
}

View File

@@ -15,11 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsCollectionContaining.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.test.util.ReflectionTestUtils.*;
@@ -35,6 +31,7 @@ import java.util.HashSet;
import java.util.List;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisClusterNode.Flag;
import org.springframework.data.redis.connection.RedisClusterNode.LinkState;
@@ -52,14 +49,14 @@ public class LettuceConvertersUnitTests {
@Test // DATAREDIS-268
public void convertingEmptyStringToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(LettuceConverters.toListOfRedisClientInformation(""),
equalTo(Collections.<RedisClientInfo> emptyList()));
assertThat(LettuceConverters.toListOfRedisClientInformation(""))
.isEqualTo(Collections.<RedisClientInfo> emptyList());
}
@Test // DATAREDIS-268
public void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(LettuceConverters.toListOfRedisClientInformation(null),
equalTo(Collections.<RedisClientInfo> emptyList()));
assertThat(LettuceConverters.toListOfRedisClientInformation(null))
.isEqualTo(Collections.<RedisClientInfo> emptyList());
}
@Test // DATAREDIS-268
@@ -70,12 +67,12 @@ public class LettuceConvertersUnitTests {
sb.append("\r\n");
sb.append(CLIENT_ALL_SINGLE_LINE_RESPONSE);
assertThat(LettuceConverters.toListOfRedisClientInformation(sb.toString()).size(), equalTo(2));
assertThat(LettuceConverters.toListOfRedisClientInformation(sb.toString()).size()).isEqualTo(2);
}
@Test // DATAREDIS-315
public void partitionsToClusterNodesShouldReturnEmptyCollectionWhenPartionsDoesNotContainElements() {
assertThat(LettuceConverters.partitionsToClusterNodes(new Partitions()), notNullValue());
assertThat(LettuceConverters.partitionsToClusterNodes(new Partitions())).isNotNull();
}
@Test // DATAREDIS-315
@@ -93,15 +90,15 @@ public class LettuceConvertersUnitTests {
partitions.add(partition);
List<RedisClusterNode> nodes = LettuceConverters.partitionsToClusterNodes(partitions);
assertThat(nodes.size(), is(1));
assertThat(nodes.size()).isEqualTo(1);
RedisClusterNode node = nodes.get(0);
assertThat(node.getHost(), is(CLUSTER_HOST));
assertThat(node.getPort(), is(MASTER_NODE_1_PORT));
assertThat(node.getFlags(), hasItems(Flag.MASTER, Flag.MYSELF));
assertThat(node.getId(), is(CLUSTER_NODE_1.getId()));
assertThat(node.getLinkState(), is(LinkState.CONNECTED));
assertThat(node.getSlotRange().getSlots(), hasItems(1, 2, 3, 4, 5));
assertThat(node.getHost()).isEqualTo(CLUSTER_HOST);
assertThat(node.getPort()).isEqualTo(MASTER_NODE_1_PORT);
assertThat(node.getFlags()).contains(Flag.MASTER, Flag.MYSELF);
assertThat(node.getId()).isEqualTo(CLUSTER_NODE_1.getId());
assertThat(node.getLinkState()).isEqualTo(LinkState.CONNECTED);
assertThat(node.getSlotRange().getSlots()).contains(1, 2, 3, 4, 5);
}
@Test // DATAREDIS-316
@@ -109,10 +106,10 @@ public class LettuceConvertersUnitTests {
SetArgs args = LettuceConverters.toSetArgs(null, null);
assertThat(getField(args, "ex"), is(nullValue()));
assertThat(getField(args, "px"), is(nullValue()));
assertThat((Boolean) getField(args, "nx"), is(Boolean.FALSE));
assertThat((Boolean) getField(args, "xx"), is(Boolean.FALSE));
assertThat(getField(args, "ex")).isNull();
assertThat(getField(args, "px")).isNull();
assertThat((Boolean) getField(args, "nx")).isEqualTo(Boolean.FALSE);
assertThat((Boolean) getField(args, "xx")).isEqualTo(Boolean.FALSE);
}
@Test // DATAREDIS-316
@@ -120,10 +117,10 @@ public class LettuceConvertersUnitTests {
SetArgs args = LettuceConverters.toSetArgs(Expiration.persistent(), null);
assertThat(getField(args, "ex"), is(nullValue()));
assertThat(getField(args, "px"), is(nullValue()));
assertThat((Boolean) getField(args, "nx"), is(Boolean.FALSE));
assertThat((Boolean) getField(args, "xx"), is(Boolean.FALSE));
assertThat(getField(args, "ex")).isNull();
assertThat(getField(args, "px")).isNull();
assertThat((Boolean) getField(args, "nx")).isEqualTo(Boolean.FALSE);
assertThat((Boolean) getField(args, "xx")).isEqualTo(Boolean.FALSE);
}
@Test // DATAREDIS-316
@@ -131,10 +128,10 @@ public class LettuceConvertersUnitTests {
SetArgs args = LettuceConverters.toSetArgs(Expiration.seconds(10), null);
assertThat((Long) getField(args, "ex"), is(10L));
assertThat(getField(args, "px"), is(nullValue()));
assertThat((Boolean) getField(args, "nx"), is(Boolean.FALSE));
assertThat((Boolean) getField(args, "xx"), is(Boolean.FALSE));
assertThat((Long) getField(args, "ex")).isEqualTo(10L);
assertThat(getField(args, "px")).isNull();
assertThat((Boolean) getField(args, "nx")).isEqualTo(Boolean.FALSE);
assertThat((Boolean) getField(args, "xx")).isEqualTo(Boolean.FALSE);
}
@Test // DATAREDIS-316
@@ -142,10 +139,10 @@ public class LettuceConvertersUnitTests {
SetArgs args = LettuceConverters.toSetArgs(Expiration.milliseconds(100), null);
assertThat(getField(args, "ex"), is(nullValue()));
assertThat((Long) getField(args, "px"), is(100L));
assertThat((Boolean) getField(args, "nx"), is(Boolean.FALSE));
assertThat((Boolean) getField(args, "xx"), is(Boolean.FALSE));
assertThat(getField(args, "ex")).isNull();
assertThat((Long) getField(args, "px")).isEqualTo(100L);
assertThat((Boolean) getField(args, "nx")).isEqualTo(Boolean.FALSE);
assertThat((Boolean) getField(args, "xx")).isEqualTo(Boolean.FALSE);
}
@Test // DATAREDIS-316
@@ -153,10 +150,10 @@ public class LettuceConvertersUnitTests {
SetArgs args = LettuceConverters.toSetArgs(null, SetOption.ifAbsent());
assertThat(getField(args, "ex"), is(nullValue()));
assertThat(getField(args, "px"), is(nullValue()));
assertThat((Boolean) getField(args, "nx"), is(Boolean.TRUE));
assertThat((Boolean) getField(args, "xx"), is(Boolean.FALSE));
assertThat(getField(args, "ex")).isNull();
assertThat(getField(args, "px")).isNull();
assertThat((Boolean) getField(args, "nx")).isEqualTo(Boolean.TRUE);
assertThat((Boolean) getField(args, "xx")).isEqualTo(Boolean.FALSE);
}
@Test // DATAREDIS-316
@@ -164,10 +161,10 @@ public class LettuceConvertersUnitTests {
SetArgs args = LettuceConverters.toSetArgs(null, SetOption.ifPresent());
assertThat(getField(args, "ex"), is(nullValue()));
assertThat(getField(args, "px"), is(nullValue()));
assertThat((Boolean) getField(args, "nx"), is(Boolean.FALSE));
assertThat((Boolean) getField(args, "xx"), is(Boolean.TRUE));
assertThat(getField(args, "ex")).isNull();
assertThat(getField(args, "px")).isNull();
assertThat((Boolean) getField(args, "nx")).isEqualTo(Boolean.FALSE);
assertThat((Boolean) getField(args, "xx")).isEqualTo(Boolean.TRUE);
}
@Test // DATAREDIS-316
@@ -175,25 +172,25 @@ public class LettuceConvertersUnitTests {
SetArgs args = LettuceConverters.toSetArgs(null, SetOption.upsert());
assertThat(getField(args, "ex"), is(nullValue()));
assertThat(getField(args, "px"), is(nullValue()));
assertThat((Boolean) getField(args, "nx"), is(Boolean.FALSE));
assertThat((Boolean) getField(args, "xx"), is(Boolean.FALSE));
assertThat(getField(args, "ex")).isNull();
assertThat(getField(args, "px")).isNull();
assertThat((Boolean) getField(args, "nx")).isEqualTo(Boolean.FALSE);
assertThat((Boolean) getField(args, "xx")).isEqualTo(Boolean.FALSE);
}
@Test // DATAREDIS-981
public void toLimit() {
Limit limit = LettuceConverters.toLimit(RedisZSetCommands.Limit.unlimited());
assertThat(limit.isLimited(), is(false));
assertThat(limit.getCount(), is(-1L));
assertThat(limit.isLimited()).isFalse();
assertThat(limit.getCount()).isEqualTo(-1L);
limit = LettuceConverters.toLimit(RedisZSetCommands.Limit.limit().count(-1));
assertThat(limit.isLimited(), is(true));
assertThat(limit.getCount(), is(-1L));
assertThat(limit.isLimited()).isTrue();
assertThat(limit.getCount()).isEqualTo(-1L);
limit = LettuceConverters.toLimit(RedisZSetCommands.Limit.limit().count(5));
assertThat(limit.isLimited(), is(true));
assertThat(limit.getCount(), is(5L));
assertThat(limit.isLimited()).isTrue();
assertThat(limit.getCount()).isEqualTo(5L);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
@@ -25,6 +24,7 @@ import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.springframework.data.redis.test.util.LettuceRedisClusterClientProvider;
/**
@@ -40,7 +40,9 @@ public abstract class LettuceReactiveClusterCommandsTestsBase {
@Before
public void before() {
assumeThat(clientProvider.test(), is(true));
assumeThat(clientProvider.test()).isTrue();
nativeCommands = clientProvider.getClient().connect().sync();
connection = new LettuceReactiveRedisClusterConnection(
new ClusterConnectionProvider(clientProvider.getClient(), LettuceReactiveRedisConnection.CODEC),

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import java.util.Arrays;
@@ -35,7 +34,7 @@ public class LettuceReactiveClusterHyperLogLogCommandsTests extends LettuceReact
nativeCommands.pfadd(SAME_SLOT_KEY_2, new String[] { VALUE_2, VALUE_3 });
assertThat(connection.hyperLogLogCommands().pfCount(Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER))
.block(), is(3L));
.block()).isEqualTo(3L);
}
@Test // DATAREDIS-525
@@ -44,12 +43,11 @@ public class LettuceReactiveClusterHyperLogLogCommandsTests extends LettuceReact
nativeCommands.pfadd(SAME_SLOT_KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(SAME_SLOT_KEY_2, new String[] { VALUE_2, VALUE_3 });
assertThat(
connection.hyperLogLogCommands()
.pfMerge(SAME_SLOT_KEY_3_BBUFFER, Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER)).block(),
is(true));
assertThat(connection.hyperLogLogCommands()
.pfMerge(SAME_SLOT_KEY_3_BBUFFER, Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER)).block())
.isTrue();
assertThat(nativeCommands.pfcount(new String[] { SAME_SLOT_KEY_3 }), is(3L));
assertThat(nativeCommands.pfcount(new String[] { SAME_SLOT_KEY_3 })).isEqualTo(3L);
}
}

View File

@@ -15,21 +15,18 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.RedisClusterNode.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import reactor.core.publisher.Mono;
import java.nio.ByteBuffer;
import java.util.List;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisClusterNode;
import reactor.core.publisher.Mono;
import org.springframework.data.redis.connection.RedisClusterNode;
/**
* @author Christoph Strobl
@@ -45,8 +42,8 @@ public class LettuceReactiveClusterKeyCommandsTests extends LettuceReactiveClust
nativeCommands.set(KEY_2, VALUE_2);
List<ByteBuffer> result = connection.keyCommands().keys(NODE_1, ByteBuffer.wrap("*".getBytes())).block();
assertThat(result, hasSize(1));
assertThat(result, contains(KEY_1_BBUFFER));
assertThat(result).hasSize(1);
assertThat(result).containsExactly(KEY_1_BBUFFER);
}
@Test // DATAREDIS-525
@@ -58,7 +55,7 @@ public class LettuceReactiveClusterKeyCommandsTests extends LettuceReactiveClust
Mono<ByteBuffer> randomkey = connection.keyCommands().randomKey(NODE_1);
for (int i = 0; i < 10; i++) {
assertThat(randomkey.block(), is(equalTo(KEY_1_BBUFFER)));
assertThat(randomkey.block()).isEqualTo(KEY_1_BBUFFER);
}
}

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import java.nio.ByteBuffer;
@@ -25,6 +23,7 @@ import java.time.Duration;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.data.redis.connection.ReactiveListCommands;
/**
@@ -41,9 +40,9 @@ public class LettuceReactiveClusterListCommandsTests extends LettuceReactiveClus
ByteBuffer result = connection.listCommands()
.bRPopLPush(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER, Duration.ofSeconds(1)).block();
assertThat(result, is(equalTo(VALUE_3_BBUFFER)));
assertThat(nativeCommands.llen(SAME_SLOT_KEY_2), is(2L));
assertThat(nativeCommands.lindex(SAME_SLOT_KEY_2, 0), is(equalTo(VALUE_3)));
assertThat(result).isEqualTo(VALUE_3_BBUFFER);
assertThat(nativeCommands.llen(SAME_SLOT_KEY_2)).isEqualTo(2L);
assertThat(nativeCommands.lindex(SAME_SLOT_KEY_2, 0)).isEqualTo(VALUE_3);
}
@Test // DATAREDIS-525
@@ -53,8 +52,8 @@ public class LettuceReactiveClusterListCommandsTests extends LettuceReactiveClus
ReactiveListCommands.PopResult result = connection.listCommands()
.blPop(Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER), Duration.ofSeconds(1L)).block();
assertThat(result.getKey(), is(equalTo(SAME_SLOT_KEY_1_BBUFFER)));
assertThat(result.getValue(), is(equalTo(VALUE_1_BBUFFER)));
assertThat(result.getKey()).isEqualTo(SAME_SLOT_KEY_1_BBUFFER);
assertThat(result.getValue()).isEqualTo(VALUE_1_BBUFFER);
}
}

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import java.nio.ByteBuffer;
@@ -26,6 +24,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisStringCommands;
/**
@@ -43,8 +42,8 @@ public class LettuceReactiveClusterStringCommandsTests extends LettuceReactiveCl
connection.stringCommands().mSetNX(map).block();
assertThat(nativeCommands.get(SAME_SLOT_KEY_1), is(equalTo(VALUE_1)));
assertThat(nativeCommands.get(SAME_SLOT_KEY_2), is(equalTo(VALUE_2)));
assertThat(nativeCommands.get(SAME_SLOT_KEY_1)).isEqualTo(VALUE_1);
assertThat(nativeCommands.get(SAME_SLOT_KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
@@ -56,10 +55,10 @@ public class LettuceReactiveClusterStringCommandsTests extends LettuceReactiveCl
map.put(SAME_SLOT_KEY_1_BBUFFER, VALUE_1_BBUFFER);
map.put(SAME_SLOT_KEY_2_BBUFFER, VALUE_2_BBUFFER);
assertThat(connection.stringCommands().mSetNX(map).block(), is(false));
assertThat(connection.stringCommands().mSetNX(map).block()).isFalse();
assertThat(nativeCommands.exists(SAME_SLOT_KEY_1), is(0L));
assertThat(nativeCommands.get(SAME_SLOT_KEY_2), is(equalTo(VALUE_2)));
assertThat(nativeCommands.exists(SAME_SLOT_KEY_1)).isEqualTo(0L);
assertThat(nativeCommands.get(SAME_SLOT_KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
@@ -69,8 +68,8 @@ public class LettuceReactiveClusterStringCommandsTests extends LettuceReactiveCl
nativeCommands.set(SAME_SLOT_KEY_2, VALUE_2);
assertThat(connection.stringCommands().bitOp(Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER),
RedisStringCommands.BitOperation.AND, SAME_SLOT_KEY_3_BBUFFER).block(), is(7L));
assertThat(nativeCommands.get(SAME_SLOT_KEY_3), is(equalTo("value-0")));
RedisStringCommands.BitOperation.AND, SAME_SLOT_KEY_3_BBUFFER).block()).isEqualTo(7L);
assertThat(nativeCommands.get(SAME_SLOT_KEY_3)).isEqualTo("value-0");
}
@Test // DATAREDIS-525
@@ -80,8 +79,8 @@ public class LettuceReactiveClusterStringCommandsTests extends LettuceReactiveCl
nativeCommands.set(SAME_SLOT_KEY_2, VALUE_2);
assertThat(connection.stringCommands().bitOp(Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER),
RedisStringCommands.BitOperation.OR, SAME_SLOT_KEY_3_BBUFFER).block(), is(7L));
assertThat(nativeCommands.get(SAME_SLOT_KEY_3), is(equalTo(VALUE_3)));
RedisStringCommands.BitOperation.OR, SAME_SLOT_KEY_3_BBUFFER).block()).isEqualTo(7L);
assertThat(nativeCommands.get(SAME_SLOT_KEY_3)).isEqualTo(VALUE_3);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-525

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import java.util.Arrays;
@@ -38,7 +37,7 @@ public class LettuceReactiveClusterZSetCommandsTests extends LettuceReactiveClus
nativeCommands.zadd(SAME_SLOT_KEY_2, 3D, VALUE_3);
assertThat(connection.zSetCommands().zUnionStore(SAME_SLOT_KEY_3_BBUFFER,
Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block(), is(3L));
Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block()).isEqualTo(3L);
}
@@ -52,6 +51,6 @@ public class LettuceReactiveClusterZSetCommandsTests extends LettuceReactiveClus
nativeCommands.zadd(SAME_SLOT_KEY_2, 3D, VALUE_3);
assertThat(connection.zSetCommands().zInterStore(SAME_SLOT_KEY_3_BBUFFER,
Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block(), is(2L));
Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block()).isEqualTo(2L);
}
}

View File

@@ -15,11 +15,8 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsNull.*;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.data.Offset.offset;
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
@@ -31,6 +28,7 @@ import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Metrics;
@@ -59,13 +57,13 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
@Test // DATAREDIS-525
public void geoAddShouldAddSingleGeoLocationCorrectly() {
assertThat(connection.geoCommands().geoAdd(KEY_1_BBUFFER, ARIGENTO).block(), is(1L));
assertThat(connection.geoCommands().geoAdd(KEY_1_BBUFFER, ARIGENTO).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
public void geoAddShouldAddMultipleGeoLocationsCorrectly() {
assertThat(connection.geoCommands().geoAdd(KEY_1_BBUFFER, Arrays.asList(ARIGENTO, CATANIA, PALERMO)).block(),
is(3L));
assertThat(connection.geoCommands().geoAdd(KEY_1_BBUFFER, Arrays.asList(ARIGENTO, CATANIA, PALERMO)).block())
.isEqualTo(3L);
}
@Test // DATAREDIS-525
@@ -74,8 +72,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
assertThat(connection.geoCommands().geoDist(KEY_1_BBUFFER, PALERMO.getName(), CATANIA.getName()).block().getValue(),
is(closeTo(166274.15156960033D, 0.005)));
assertThat(connection.geoCommands().geoDist(KEY_1_BBUFFER, PALERMO.getName(), CATANIA.getName()).block().getValue())
.isCloseTo(166274.15156960033D, offset(0.005));
}
@Test // DATAREDIS-525
@@ -85,7 +83,7 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
assertThat(connection.geoCommands().geoDist(KEY_1_BBUFFER, PALERMO.getName(), CATANIA.getName(), Metrics.KILOMETERS)
.block().getValue(), is(closeTo(166.27415156960033D, 0.005)));
.block().getValue()).isCloseTo(166.27415156960033D, offset(0.005));
}
@Test // DATAREDIS-525
@@ -95,8 +93,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
assertThat(
connection.geoCommands().geoHash(KEY_1_BBUFFER, Arrays.asList(PALERMO.getName(), CATANIA.getName())).block(),
contains("sqc8b49rny0", "sqdtr74hyu0"));
connection.geoCommands().geoHash(KEY_1_BBUFFER, Arrays.asList(PALERMO.getName(), CATANIA.getName())).block())
.containsExactly("sqc8b49rny0", "sqdtr74hyu0");
}
@Test // DATAREDIS-525
@@ -105,10 +103,9 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
assertThat(
connection.geoCommands()
.geoHash(KEY_1_BBUFFER, Arrays.asList(PALERMO.getName(), ARIGENTO.getName(), CATANIA.getName())).block(),
contains("sqc8b49rny0", null, "sqdtr74hyu0"));
assertThat(connection.geoCommands()
.geoHash(KEY_1_BBUFFER, Arrays.asList(PALERMO.getName(), ARIGENTO.getName(), CATANIA.getName())).block())
.containsExactly("sqc8b49rny0", null, "sqdtr74hyu0");
}
@Test // DATAREDIS-525
@@ -119,11 +116,11 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
List<Point> result = connection.geoCommands()
.geoPos(KEY_1_BBUFFER, Arrays.asList(PALERMO.getName(), CATANIA.getName())).block();
assertThat(result.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.get(0).getX()).isCloseTo(POINT_PALERMO.getX(), offset(0.005));
assertThat(result.get(0).getY()).isCloseTo(POINT_PALERMO.getY(), offset(0.005));
assertThat(result.get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(result.get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
assertThat(result.get(1).getX()).isCloseTo(POINT_CATANIA.getX(), offset(0.005));
assertThat(result.get(1).getY()).isCloseTo(POINT_CATANIA.getY(), offset(0.005));
}
@Test // DATAREDIS-525
@@ -134,13 +131,13 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
List<Point> result = connection.geoCommands()
.geoPos(KEY_1_BBUFFER, Arrays.asList(PALERMO.getName(), ARIGENTO.getName(), CATANIA.getName())).block();
assertThat(result.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.get(0).getX()).isCloseTo(POINT_PALERMO.getX(), offset(0.005));
assertThat(result.get(0).getY()).isCloseTo(POINT_PALERMO.getY(), offset(0.005));
assertThat(result.get(1), is(nullValue()));
assertThat(result.get(1)).isNull();
assertThat(result.get(2).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(result.get(2).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
assertThat(result.get(2).getX()).isCloseTo(POINT_CATANIA.getX(), offset(0.005));
assertThat(result.get(2).getY()).isCloseTo(POINT_CATANIA.getY(), offset(0.005));
}
@Test // DATAREDIS-525
@@ -175,8 +172,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().includeDistance())) //
.consumeNextWith(actual -> {
assertThat(actual.getDistance().getValue(), is(closeTo(130.423D, 0.005)));
assertThat(actual.getDistance().getUnit(), is("km"));
assertThat(actual.getDistance().getValue()).isCloseTo(130.423D, offset(0.005));
assertThat(actual.getDistance().getUnit()).isEqualTo("km");
}) //
.expectComplete();
}
@@ -206,10 +203,10 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
.create(connection.geoCommands().geoRadiusByMember(KEY_1_BBUFFER, ARIGENTO.getName(),
new Distance(100, KILOMETERS))) //
.consumeNextWith(actual -> {
assertThat(actual.getContent().getName(), is(ARIGENTO.getName()));
assertThat(actual.getContent().getName()).isEqualTo(ARIGENTO.getName());
}) //
.consumeNextWith(actual -> {
assertThat(actual.getContent().getName(), is(PALERMO.getName()));
assertThat(actual.getContent().getName()).isEqualTo(PALERMO.getName());
}) //
.expectComplete();
}
@@ -226,8 +223,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance())) //
.consumeNextWith(actual -> {
assertThat(actual.getDistance().getValue(), is(closeTo(90.978D, 0.005)));
assertThat(actual.getDistance().getUnit(), is("km"));
assertThat(actual.getDistance().getValue()).isCloseTo(90.978D, offset(0.005));
assertThat(actual.getDistance().getUnit()).isEqualTo("km");
}) //
.expectNextCount(1) //
.verifyComplete();

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import reactor.test.StepVerifier;
@@ -28,6 +27,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.data.redis.core.ScanOptions;
/**
@@ -101,7 +101,7 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
StepVerifier.create(connection.hashCommands().hMGet(KEY_1_BBUFFER, Arrays.asList(FIELD_1_BBUFFER, FIELD_3_BBUFFER)))
.consumeNextWith(actual -> {
assertThat(actual, hasItems(VALUE_1_BBUFFER, VALUE_3_BBUFFER));
assertThat(actual).contains(VALUE_1_BBUFFER, VALUE_3_BBUFFER);
}).verifyComplete();
}
@@ -126,8 +126,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
fieldValues.put(FIELD_2_BBUFFER, VALUE_2_BBUFFER);
StepVerifier.create(connection.hashCommands().hMSet(KEY_1_BBUFFER, fieldValues)).expectNext(true).verifyComplete();
assertThat(nativeCommands.hget(KEY_1, FIELD_1), is(equalTo(VALUE_1)));
assertThat(nativeCommands.hget(KEY_1, FIELD_2), is(equalTo(VALUE_2)));
assertThat(nativeCommands.hget(KEY_1, FIELD_1)).isEqualTo(VALUE_1);
assertThat(nativeCommands.hget(KEY_1, FIELD_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-791
@@ -143,7 +143,7 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
StepVerifier.create(connection.hashCommands().hMSet(KEY_1_BBUFFER, overwriteFieldValues)).expectNext(true)
.verifyComplete();
assertThat(nativeCommands.hget(KEY_1, FIELD_1), is(equalTo(VALUE_2)));
assertThat(nativeCommands.hget(KEY_1, FIELD_1)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
@@ -231,7 +231,7 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
StepVerifier.create(connection.hashCommands().hGetAll(KEY_1_BBUFFER).buffer(3)) //
.consumeNextWith(list -> {
assertTrue(list.containsAll(expected.entrySet()));
assertThat(list.containsAll(expected.entrySet())).isTrue();
}) //
.verifyComplete();
}

View File

@@ -15,14 +15,12 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeThat;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.data.redis.test.util.LettuceRedisClientProvider;
/**
* @author Christoph Strobl
@@ -34,7 +32,7 @@ public class LettuceReactiveHyperLogLogCommandsTests extends LettuceReactiveComm
public void pfAddShouldAddToNonExistingKeyCorrectly() {
assertThat(connection.hyperLogLogCommands()
.pfAdd(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER)).block(), is(1L));
.pfAdd(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER)).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
@@ -43,7 +41,8 @@ public class LettuceReactiveHyperLogLogCommandsTests extends LettuceReactiveComm
nativeCommands.pfadd(KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(KEY_1, new String[] { VALUE_3 });
assertThat(connection.hyperLogLogCommands().pfAdd(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER)).block(), is(0L));
assertThat(connection.hyperLogLogCommands().pfAdd(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER)).block())
.isEqualTo(0L);
}
@Test // DATAREDIS-525
@@ -51,32 +50,33 @@ public class LettuceReactiveHyperLogLogCommandsTests extends LettuceReactiveComm
nativeCommands.pfadd(KEY_1, new String[] { VALUE_1, VALUE_2 });
assertThat(connection.hyperLogLogCommands().pfCount(KEY_1_BBUFFER).block(), is(2L));
assertThat(connection.hyperLogLogCommands().pfCount(KEY_1_BBUFFER).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
public void pfCountWithMultipleKeysShouldReturnCorrectly() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.pfadd(KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(KEY_2, new String[] { VALUE_2, VALUE_3 });
assertThat(connection.hyperLogLogCommands().pfCount(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block(), is(3L));
assertThat(connection.hyperLogLogCommands().pfCount(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block())
.isEqualTo(3L);
}
@Test // DATAREDIS-525
public void pfMergeShouldWorkCorrectly() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.pfadd(KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(KEY_2, new String[] { VALUE_2, VALUE_3 });
assertThat(
connection.hyperLogLogCommands().pfMerge(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block(),
is(true));
connection.hyperLogLogCommands().pfMerge(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block())
.isTrue();
assertThat(nativeCommands.pfcount(new String[] { KEY_3 }), is(3L));
assertThat(nativeCommands.pfcount(new String[] { KEY_3 })).isEqualTo(3L);
}
}

View File

@@ -15,9 +15,8 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.*;
import io.lettuce.core.SetArgs;
import reactor.core.publisher.Flux;
@@ -33,6 +32,7 @@ import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand;
@@ -138,8 +138,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
StepVerifier.create(connection.keyCommands().rename(KEY_1_BBUFFER, KEY_2_BBUFFER)).expectNext(true)
.verifyComplete();
assertThat(nativeCommands.exists(KEY_2), is(1L));
assertThat(nativeCommands.exists(KEY_1), is(0L));
assertThat(nativeCommands.exists(KEY_2)).isEqualTo(1L);
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L);
}
@Test // DATAREDIS-525
@@ -157,8 +157,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
StepVerifier.create(connection.keyCommands().renameNX(KEY_1_BBUFFER, KEY_2_BBUFFER)).expectNext(true)
.verifyComplete();
assertThat(nativeCommands.exists(KEY_2), is(1L));
assertThat(nativeCommands.exists(KEY_1), is(0L));
assertThat(nativeCommands.exists(KEY_2)).isEqualTo(1L);
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L);
}
@Test // DATAREDIS-525
@@ -275,7 +275,7 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.expectComplete() //
.verify();
assertThat(nativeCommands.ttl(KEY_1), is(greaterThan(8L)));
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8L);
}
@Test // DATAREDIS-602
@@ -288,7 +288,7 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.expectComplete() //
.verify();
assertThat(nativeCommands.ttl(KEY_1), is(greaterThan(8L)));
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8L);
}
@Test // DATAREDIS-602
@@ -302,7 +302,7 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.expectComplete() //
.verify();
assertThat(nativeCommands.ttl(KEY_1), is(greaterThan(8L)));
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8L);
}
@Test // DATAREDIS-602
@@ -316,7 +316,7 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.expectComplete() //
.verify();
assertThat(nativeCommands.ttl(KEY_1), is(greaterThan(8L)));
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8L);
}
@Test // DATAREDIS-602
@@ -326,7 +326,7 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
StepVerifier.create(connection.keyCommands().ttl(KEY_1_BBUFFER)) //
.expectNextMatches(actual -> {
assertThat(nativeCommands.ttl(KEY_1), is(greaterThan(8L)));
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8L);
return true;
}) //
.expectComplete() //
@@ -340,7 +340,7 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
StepVerifier.create(connection.keyCommands().pTtl(KEY_1_BBUFFER)) //
.expectNextMatches(actual -> {
assertThat(actual, is(greaterThan(8000L)));
assertThat(actual).isGreaterThan(8000L);
return true;
}) //
.expectComplete() //
@@ -357,13 +357,13 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.expectComplete() //
.verify();
assertThat(nativeCommands.ttl(KEY_1), is(-1L));
assertThat(nativeCommands.ttl(KEY_1)).isEqualTo(-1L);
}
@Test // DATAREDIS-602
public void shouldMoveToDatabase() {
assumeThat(connection, is(not(instanceOf(LettuceReactiveRedisClusterConnection.class))));
assumeThat(connection).isNotInstanceOf(LettuceReactiveRedisClusterConnection.class);
nativeCommands.set(KEY_1, VALUE_1);
@@ -371,7 +371,7 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.expectNext(true) //
.expectComplete() //
.verify();
assertThat(nativeCommands.exists(KEY_1), is(0L));
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L);
}
@Test // DATAREDIS-694

View File

@@ -15,11 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.core.IsNot.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.springframework.data.domain.Range.Bound.*;
@@ -31,6 +27,7 @@ import java.time.Duration;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.ReactiveListCommands.PopResult;
@@ -52,9 +49,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.lpush(KEY_1, VALUE_1);
assertThat(connection.listCommands().rPush(KEY_1_BBUFFER, Arrays.asList(VALUE_2_BBUFFER, VALUE_3_BBUFFER)).block(),
is(3L));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_1, VALUE_2, VALUE_3));
assertThat(connection.listCommands().rPush(KEY_1_BBUFFER, Arrays.asList(VALUE_2_BBUFFER, VALUE_3_BBUFFER)).block())
.isEqualTo(3L);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2, VALUE_3);
}
@Test // DATAREDIS-525
@@ -62,9 +59,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.lpush(KEY_1, VALUE_1);
assertThat(connection.listCommands().lPush(KEY_1_BBUFFER, Arrays.asList(VALUE_2_BBUFFER, VALUE_3_BBUFFER)).block(),
is(3L));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_3, VALUE_2, VALUE_1));
assertThat(connection.listCommands().lPush(KEY_1_BBUFFER, Arrays.asList(VALUE_2_BBUFFER, VALUE_3_BBUFFER)).block())
.isEqualTo(3L);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_3, VALUE_2, VALUE_1);
}
@Test // DATAREDIS-525
@@ -72,8 +69,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.lpush(KEY_1, VALUE_1);
assertThat(connection.listCommands().rPushX(KEY_1_BBUFFER, VALUE_2_BBUFFER).block(), is(2L));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_1, VALUE_2));
assertThat(connection.listCommands().rPushX(KEY_1_BBUFFER, VALUE_2_BBUFFER).block()).isEqualTo(2L);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2);
}
@Test // DATAREDIS-525
@@ -81,8 +78,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.lpush(KEY_1, VALUE_1);
assertThat(connection.listCommands().lPushX(KEY_1_BBUFFER, VALUE_2_BBUFFER).block(), is(2L));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_2, VALUE_1));
assertThat(connection.listCommands().lPushX(KEY_1_BBUFFER, VALUE_2_BBUFFER).block()).isEqualTo(2L);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_2, VALUE_1);
}
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAREDIS-525
@@ -99,7 +96,7 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.lpush(KEY_1, VALUE_1, VALUE_2);
assertThat(connection.listCommands().lLen(KEY_1_BBUFFER).block(), is(2L));
assertThat(connection.listCommands().lLen(KEY_1_BBUFFER).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -107,8 +104,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.listCommands().lRange(KEY_1_BBUFFER, 1, 2).toIterable(),
contains(VALUE_2_BBUFFER, VALUE_3_BBUFFER));
assertThat(connection.listCommands().lRange(KEY_1_BBUFFER, 1, 2).toIterable()).containsExactly(VALUE_2_BBUFFER,
VALUE_3_BBUFFER);
}
@Test // DATAREDIS-852
@@ -138,8 +135,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.listCommands().lTrim(KEY_1_BBUFFER, 1, 2).block(), is(true));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), not(contains(VALUE_1_BBUFFER)));
assertThat(connection.listCommands().lTrim(KEY_1_BBUFFER, 1, 2).block()).isTrue();
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).doesNotContain(VALUE_1);
}
@Test // DATAREDIS-852
@@ -171,7 +168,7 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.listCommands().lIndex(KEY_1_BBUFFER, 1).block(), is(equalTo(VALUE_2_BBUFFER)));
assertThat(connection.listCommands().lIndex(KEY_1_BBUFFER, 1).block()).isEqualTo(VALUE_2_BBUFFER);
}
@Test // DATAREDIS-525
@@ -180,9 +177,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2);
assertThat(
connection.listCommands().lInsert(KEY_1_BBUFFER, Position.BEFORE, VALUE_2_BBUFFER, VALUE_3_BBUFFER).block(),
is(3L));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_1, VALUE_3, VALUE_2));
connection.listCommands().lInsert(KEY_1_BBUFFER, Position.BEFORE, VALUE_2_BBUFFER, VALUE_3_BBUFFER).block())
.isEqualTo(3L);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_3, VALUE_2);
}
@Test // DATAREDIS-525
@@ -191,9 +188,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2);
assertThat(
connection.listCommands().lInsert(KEY_1_BBUFFER, Position.AFTER, VALUE_2_BBUFFER, VALUE_3_BBUFFER).block(),
is(3L));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_1, VALUE_2, VALUE_3));
connection.listCommands().lInsert(KEY_1_BBUFFER, Position.AFTER, VALUE_2_BBUFFER, VALUE_3_BBUFFER).block())
.isEqualTo(3L);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2, VALUE_3);
}
@Test // DATAREDIS-525
@@ -201,9 +198,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2);
assertThat(connection.listCommands().lSet(KEY_1_BBUFFER, 1L, VALUE_3_BBUFFER).block(), is(true));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_1, VALUE_3));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), not(contains(VALUE_2)));
assertThat(connection.listCommands().lSet(KEY_1_BBUFFER, 1L, VALUE_3_BBUFFER).block()).isTrue();
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_3);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).doesNotContain(VALUE_2);
}
@Test // DATAREDIS-525
@@ -211,9 +208,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_1, VALUE_3);
assertThat(connection.listCommands().lRem(KEY_1_BBUFFER, VALUE_1_BBUFFER).block(), is(2L));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_2, VALUE_3));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), not(contains(VALUE_1)));
assertThat(connection.listCommands().lRem(KEY_1_BBUFFER, VALUE_1_BBUFFER).block()).isEqualTo(2L);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_2, VALUE_3);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).doesNotContain(VALUE_1);
}
@Test // DATAREDIS-525
@@ -221,8 +218,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_1, VALUE_3);
assertThat(connection.listCommands().lRem(KEY_1_BBUFFER, 1L, VALUE_1_BBUFFER).block(), is(1L));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_2, VALUE_1, VALUE_3));
assertThat(connection.listCommands().lRem(KEY_1_BBUFFER, 1L, VALUE_1_BBUFFER).block()).isEqualTo(1L);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_2, VALUE_1, VALUE_3);
}
@Test // DATAREDIS-525
@@ -230,8 +227,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_1, VALUE_3);
assertThat(connection.listCommands().lRem(KEY_1_BBUFFER, -1L, VALUE_1_BBUFFER).block(), is(1L));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_1, VALUE_2, VALUE_3));
assertThat(connection.listCommands().lRem(KEY_1_BBUFFER, -1L, VALUE_1_BBUFFER).block()).isEqualTo(1L);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2, VALUE_3);
}
@Test // DATAREDIS-525
@@ -239,8 +236,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.listCommands().lPop(KEY_1_BBUFFER).block(), is(equalTo(VALUE_1_BBUFFER)));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_2, VALUE_3));
assertThat(connection.listCommands().lPop(KEY_1_BBUFFER).block()).isEqualTo(VALUE_1_BBUFFER);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_2, VALUE_3);
}
@Test // DATAREDIS-525
@@ -248,34 +245,34 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.listCommands().rPop(KEY_1_BBUFFER).block(), is(equalTo(VALUE_3_BBUFFER)));
assertThat(nativeCommands.lrange(KEY_1, 0, -1), contains(VALUE_1, VALUE_2));
assertThat(connection.listCommands().rPop(KEY_1_BBUFFER).block()).isEqualTo(VALUE_3_BBUFFER);
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2);
}
@Test // DATAREDIS-525
public void blPopShouldReturnFirstAvailable() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
PopResult result = connection.listCommands()
.blPop(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Duration.ofSeconds(1L)).block();
assertThat(result.getKey(), is(equalTo(KEY_1_BBUFFER)));
assertThat(result.getValue(), is(equalTo(VALUE_1_BBUFFER)));
assertThat(result.getKey()).isEqualTo(KEY_1_BBUFFER);
assertThat(result.getValue()).isEqualTo(VALUE_1_BBUFFER);
}
@Test // DATAREDIS-525
public void brPopShouldReturnLastAvailable() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
PopResult result = connection.listCommands()
.brPop(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Duration.ofSeconds(1L)).block();
assertThat(result.getKey(), is(equalTo(KEY_1_BBUFFER)));
assertThat(result.getValue(), is(equalTo(VALUE_3_BBUFFER)));
assertThat(result.getKey()).isEqualTo(KEY_1_BBUFFER);
assertThat(result.getValue()).isEqualTo(VALUE_3_BBUFFER);
}
@Test // DATAREDIS-525
@@ -286,15 +283,15 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
ByteBuffer result = connection.listCommands().rPopLPush(KEY_1_BBUFFER, KEY_2_BBUFFER).block();
assertThat(result, is(equalTo(VALUE_3_BBUFFER)));
assertThat(nativeCommands.llen(KEY_2), is(2L));
assertThat(nativeCommands.lindex(KEY_2, 0), is(equalTo(VALUE_3)));
assertThat(result).isEqualTo(VALUE_3_BBUFFER);
assertThat(nativeCommands.llen(KEY_2)).isEqualTo(2L);
assertThat(nativeCommands.lindex(KEY_2, 0)).isEqualTo(VALUE_3);
}
@Test // DATAREDIS-525
public void brPopLPushShouldWorkCorrectly() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
nativeCommands.rpush(KEY_2, VALUE_1);
@@ -302,8 +299,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
ByteBuffer result = connection.listCommands().bRPopLPush(KEY_1_BBUFFER, KEY_2_BBUFFER, Duration.ofSeconds(1))
.block();
assertThat(result, is(equalTo(VALUE_3_BBUFFER)));
assertThat(nativeCommands.llen(KEY_2), is(2L));
assertThat(nativeCommands.lindex(KEY_2, 0), is(equalTo(VALUE_3)));
assertThat(result).isEqualTo(VALUE_3_BBUFFER);
assertThat(nativeCommands.llen(KEY_2)).isEqualTo(2L);
assertThat(nativeCommands.lindex(KEY_2, 0)).isEqualTo(VALUE_3);
}
}

View File

@@ -15,9 +15,8 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.data.Offset.offset;
import org.junit.Test;
@@ -28,22 +27,22 @@ public class LettuceReactiveNumberCommandsTests extends LettuceReactiveCommandsT
@Test // DATAREDIS-525
public void incrByDoubleShouldIncreaseValueCorrectly() {
assertThat(connection.numberCommands().incrBy(KEY_1_BBUFFER, 1.5D).block(), is(closeTo(1.5D, 0D)));
assertThat(connection.numberCommands().incrBy(KEY_1_BBUFFER, 1.5D).block()).isCloseTo(1.5D, offset(0D));
}
@Test // DATAREDIS-525
public void incrByIntegerShouldIncreaseValueCorrectly() {
assertThat(connection.numberCommands().incrBy(KEY_1_BBUFFER, 3).block(), is(3));
assertThat(connection.numberCommands().incrBy(KEY_1_BBUFFER, 3).block()).isEqualTo(3);
}
@Test // DATAREDIS-525
public void decrByDoubleShouldDecreaseValueCorrectly() {
assertThat(connection.numberCommands().decrBy(KEY_1_BBUFFER, 1.5D).block(), is(closeTo(-1.5D, 0D)));
assertThat(connection.numberCommands().decrBy(KEY_1_BBUFFER, 1.5D).block()).isCloseTo(-1.5D, offset(0D));
}
@Test // DATAREDIS-525
public void decrByIntegerShouldDecreaseValueCorrectly() {
assertThat(connection.numberCommands().decrBy(KEY_1_BBUFFER, 3).block(), is(-3));
assertThat(connection.numberCommands().decrBy(KEY_1_BBUFFER, 3).block()).isEqualTo(-3);
}
@Test // DATAREDIS-525
@@ -51,7 +50,8 @@ public class LettuceReactiveNumberCommandsTests extends LettuceReactiveCommandsT
nativeCommands.hset(KEY_1, KEY_1, "2");
assertThat(connection.numberCommands().hIncrBy(KEY_1_BBUFFER, KEY_1_BBUFFER, 1.5D).block(), is(closeTo(3.5D, 0D)));
assertThat(connection.numberCommands().hIncrBy(KEY_1_BBUFFER, KEY_1_BBUFFER, 1.5D).block()).isCloseTo(3.5D,
offset(0D));
}
@Test // DATAREDIS-525
@@ -59,6 +59,6 @@ public class LettuceReactiveNumberCommandsTests extends LettuceReactiveCommandsT
nativeCommands.hset(KEY_1, KEY_1, "2");
assertThat(connection.numberCommands().hIncrBy(KEY_1_BBUFFER, KEY_1_BBUFFER, 3).block(), is(5));
assertThat(connection.numberCommands().hIncrBy(KEY_1_BBUFFER, KEY_1_BBUFFER, 3).block()).isEqualTo(5);
}
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
@@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.ReactiveRedisClusterConnection;
import org.springframework.data.redis.connection.ReturnType;
@@ -173,7 +174,7 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
StepVerifier.create(connection.scriptingCommands().scriptKill()).expectNext("OK").verifyComplete();
assertTrue(waitFor(scriptDead::get, 3000L));
assertThat(waitFor(scriptDead::get, 3000L)).isTrue();
}
private static ByteBuffer wrap(String content) {

View File

@@ -15,18 +15,14 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.*;
import static org.hamcrest.core.AnyOf.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import reactor.test.StepVerifier;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.data.redis.core.ScanOptions;
/**
@@ -39,13 +35,13 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
@Test // DATAREDIS-525
public void sAddShouldAddSingleValue() {
assertThat(connection.setCommands().sAdd(KEY_1_BBUFFER, VALUE_1_BBUFFER).block(), is(1L));
assertThat(connection.setCommands().sAdd(KEY_1_BBUFFER, VALUE_1_BBUFFER).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
public void sAddShouldAddValues() {
assertThat(connection.setCommands().sAdd(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER)).block(),
is(2L));
assertThat(connection.setCommands().sAdd(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER)).block())
.isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -53,8 +49,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sRem(KEY_1_BBUFFER, VALUE_1_BBUFFER).block(), is(1L));
assertThat(nativeCommands.sismember(KEY_1, VALUE_1), is(false));
assertThat(connection.setCommands().sRem(KEY_1_BBUFFER, VALUE_1_BBUFFER).block()).isEqualTo(1L);
assertThat(nativeCommands.sismember(KEY_1, VALUE_1)).isFalse();
}
@Test // DATAREDIS-525
@@ -62,10 +58,10 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sRem(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER)).block(),
is(2L));
assertThat(nativeCommands.sismember(KEY_1, VALUE_1), is(false));
assertThat(nativeCommands.sismember(KEY_1, VALUE_2), is(false));
assertThat(connection.setCommands().sRem(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER)).block())
.isEqualTo(2L);
assertThat(nativeCommands.sismember(KEY_1, VALUE_1)).isFalse();
assertThat(nativeCommands.sismember(KEY_1, VALUE_2)).isFalse();
}
@Test // DATAREDIS-525
@@ -73,7 +69,7 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sPop(KEY_1_BBUFFER).block(), is(notNullValue()));
assertThat(connection.setCommands().sPop(KEY_1_BBUFFER).block()).isNotNull();
}
@Test // DATAREDIS-668
@@ -86,7 +82,7 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
@Test // DATAREDIS-525
public void sPopShouldReturnNullWhenNotPresent() {
assertThat(connection.setCommands().sPop(KEY_1_BBUFFER).block(), is(nullValue()));
assertThat(connection.setCommands().sPop(KEY_1_BBUFFER).block()).isNull();
}
@Test // DATAREDIS-525
@@ -95,8 +91,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
nativeCommands.sadd(KEY_2, VALUE_1);
assertThat(connection.setCommands().sMove(KEY_1_BBUFFER, KEY_2_BBUFFER, VALUE_3_BBUFFER).block(), is(true));
assertThat(nativeCommands.sismember(KEY_2, VALUE_3), is(true));
assertThat(connection.setCommands().sMove(KEY_1_BBUFFER, KEY_2_BBUFFER, VALUE_3_BBUFFER).block()).isTrue();
assertThat(nativeCommands.sismember(KEY_2, VALUE_3)).isTrue();
}
@Test // DATAREDIS-525
@@ -105,8 +101,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_1);
assertThat(connection.setCommands().sMove(KEY_1_BBUFFER, KEY_2_BBUFFER, VALUE_3_BBUFFER).block(), is(false));
assertThat(nativeCommands.sismember(KEY_2, VALUE_3), is(false));
assertThat(connection.setCommands().sMove(KEY_1_BBUFFER, KEY_2_BBUFFER, VALUE_3_BBUFFER).block()).isFalse();
assertThat(nativeCommands.sismember(KEY_2, VALUE_3)).isFalse();
}
@Test // DATAREDIS-525
@@ -115,9 +111,9 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
nativeCommands.sadd(KEY_2, VALUE_1, VALUE_3);
assertThat(connection.setCommands().sMove(KEY_1_BBUFFER, KEY_2_BBUFFER, VALUE_3_BBUFFER).block(), is(true));
assertThat(nativeCommands.sismember(KEY_1, VALUE_3), is(false));
assertThat(nativeCommands.sismember(KEY_2, VALUE_3), is(true));
assertThat(connection.setCommands().sMove(KEY_1_BBUFFER, KEY_2_BBUFFER, VALUE_3_BBUFFER).block()).isTrue();
assertThat(nativeCommands.sismember(KEY_1, VALUE_3)).isFalse();
assertThat(nativeCommands.sismember(KEY_2, VALUE_3)).isTrue();
}
@Test // DATAREDIS-525
@@ -125,7 +121,7 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sCard(KEY_1_BBUFFER).block(), is(3L));
assertThat(connection.setCommands().sCard(KEY_1_BBUFFER).block()).isEqualTo(3L);
}
@Test // DATAREDIS-525
@@ -133,7 +129,7 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
assertThat(connection.setCommands().sIsMember(KEY_1_BBUFFER, VALUE_1_BBUFFER).block(), is(true));
assertThat(connection.setCommands().sIsMember(KEY_1_BBUFFER, VALUE_1_BBUFFER).block()).isTrue();
}
@Test // DATAREDIS-525
@@ -141,7 +137,7 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
assertThat(connection.setCommands().sIsMember(KEY_1_BBUFFER, VALUE_3_BBUFFER).block(), is(false));
assertThat(connection.setCommands().sIsMember(KEY_1_BBUFFER, VALUE_3_BBUFFER).block()).isFalse();
}
@Test // DATAREDIS-525, DATAREDIS-647
@@ -165,9 +161,9 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sInterStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block(),
is(1L));
assertThat(nativeCommands.sismember(KEY_3, VALUE_2), is(true));
assertThat(connection.setCommands().sInterStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block())
.isEqualTo(1L);
assertThat(nativeCommands.sismember(KEY_3, VALUE_2)).isTrue();
}
@Test // DATAREDIS-525
@@ -187,8 +183,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sUnionStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block(),
is(3L));
assertThat(connection.setCommands().sUnionStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block())
.isEqualTo(3L);
}
@Test // DATAREDIS-525, DATAREDIS-647
@@ -212,8 +208,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sDiffStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block(),
is(1L));
assertThat(connection.setCommands().sDiffStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block())
.isEqualTo(1L);
}
@Test // DATAREDIS-525
@@ -222,8 +218,7 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
StepVerifier.create(connection.setCommands().sMembers(KEY_1_BBUFFER).buffer(3)) //
.consumeNextWith(
list -> assertThat(list, containsInAnyOrder(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER))) //
.consumeNextWith(list -> assertThat(list).contains(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER)) //
.verifyComplete();
}
@@ -247,8 +242,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sRandMember(KEY_1_BBUFFER).block(),
anyOf(equalTo(VALUE_1_BBUFFER), equalTo(VALUE_2_BBUFFER), equalTo(VALUE_3_BBUFFER)));
assertThat(connection.setCommands().sRandMember(KEY_1_BBUFFER).block()).isIn(VALUE_1_BBUFFER, VALUE_2_BBUFFER,
VALUE_3_BBUFFER);
}
@Test // DATAREDIS-525

View File

@@ -15,15 +15,12 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.connection.BitFieldSubCommands.*;
import static org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldIncrBy.Overflow.*;
import static org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldType.*;
import static org.springframework.data.redis.connection.BitFieldSubCommands.Offset.*;
import static org.springframework.data.redis.connection.BitFieldSubCommands.Offset.offset;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -41,6 +38,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Test;
import org.springframework.data.domain.Range;
import org.springframework.data.domain.Range.Bound;
import org.springframework.data.redis.connection.ReactiveRedisConnection;
@@ -71,7 +69,7 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(VALUE_1_BBUFFER) //
.verifyComplete();
assertThat(nativeCommands.get(KEY_1), is(equalTo(VALUE_2)));
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525, DATAREDIS-645
@@ -79,7 +77,7 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
StepVerifier.create(connection.stringCommands().getSet(KEY_1_BBUFFER, VALUE_2_BBUFFER)).verifyComplete();
assertThat(nativeCommands.get(KEY_1), is(equalTo(VALUE_2)));
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
@@ -89,7 +87,7 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(true) //
.verifyComplete();
assertThat(nativeCommands.get(KEY_1), is(equalTo(VALUE_1)));
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_1);
}
@Test // DATAREDIS-525
@@ -102,8 +100,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNextCount(2) //
.verifyComplete();
assertThat(nativeCommands.get(KEY_1), is(equalTo(VALUE_1)));
assertThat(nativeCommands.get(KEY_2), is(equalTo(VALUE_2)));
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_1);
assertThat(nativeCommands.get(KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
@@ -156,7 +154,7 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
nativeCommands.set(KEY_2, VALUE_2);
StepVerifier.create(connection.stringCommands().mGet(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER))) //
.consumeNextWith(byteBuffers -> assertThat(byteBuffers, contains(VALUE_1_BBUFFER, VALUE_2_BBUFFER)))//
.consumeNextWith(byteBuffers -> assertThat(byteBuffers).containsExactly(VALUE_1_BBUFFER, VALUE_2_BBUFFER))//
.verifyComplete();
}
@@ -170,7 +168,7 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
Mono<List<ByteBuffer>> result = connection.stringCommands()
.mGet(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER, KEY_3_BBUFFER));
assertThat(result.block(), contains(VALUE_1_BBUFFER, ByteBuffer.allocate(0), VALUE_3_BBUFFER));
assertThat(result.block()).containsExactly(VALUE_1_BBUFFER, ByteBuffer.allocate(0), VALUE_3_BBUFFER);
}
@Test // DATAREDIS-525
@@ -218,7 +216,7 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(true) //
.verifyComplete();
assertThat(nativeCommands.ttl(KEY_1) > 1, is(true));
assertThat(nativeCommands.ttl(KEY_1) > 1).isTrue();
}
@Test // DATAREDIS-525
@@ -229,7 +227,7 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(true) //
.verifyComplete();
assertThat(nativeCommands.pttl(KEY_1) > 1, is(true));
assertThat(nativeCommands.pttl(KEY_1) > 1).isTrue();
}
@Test // DATAREDIS-525
@@ -241,14 +239,14 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
StepVerifier.create(connection.stringCommands().mSet(map)).expectNext(true).verifyComplete();
assertThat(nativeCommands.get(KEY_1), is(equalTo(VALUE_1)));
assertThat(nativeCommands.get(KEY_2), is(equalTo(VALUE_2)));
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_1);
assertThat(nativeCommands.get(KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
public void mSetNXShouldAddMultipleKeyValuePairs() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
Map<ByteBuffer, ByteBuffer> map = new LinkedHashMap<>();
map.put(KEY_1_BBUFFER, VALUE_1_BBUFFER);
@@ -256,14 +254,14 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
StepVerifier.create(connection.stringCommands().mSetNX(map)).expectNext(true).verifyComplete();
assertThat(nativeCommands.get(KEY_1), is(equalTo(VALUE_1)));
assertThat(nativeCommands.get(KEY_2), is(equalTo(VALUE_2)));
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_1);
assertThat(nativeCommands.get(KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
public void mSetNXShouldNotAddMultipleKeyValuePairsWhenAlreadyExit() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.set(KEY_2, VALUE_2);
@@ -273,8 +271,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
StepVerifier.create(connection.stringCommands().mSetNX(map)).expectNext(false).verifyComplete();
assertThat(nativeCommands.exists(KEY_1), is(0L));
assertThat(nativeCommands.get(KEY_2), is(equalTo(VALUE_2)));
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L);
assertThat(nativeCommands.get(KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
@@ -304,7 +302,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
nativeCommands.set(KEY_1, VALUE_1);
RangeCommand rangeCommand = RangeCommand.key(KEY_1_BBUFFER).within(Range.of(Bound.unbounded(), Bound.inclusive(2L)));
RangeCommand rangeCommand = RangeCommand.key(KEY_1_BBUFFER)
.within(Range.of(Bound.unbounded(), Bound.inclusive(2L)));
StepVerifier.create(connection.stringCommands().getRange(Mono.just(rangeCommand))) //
.expectNext(new ReactiveRedisConnection.ByteBufferResponse<>(rangeCommand, ByteBuffer.wrap("val".getBytes())))
@@ -316,7 +315,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
nativeCommands.set(KEY_1, VALUE_1);
RangeCommand rangeCommand = RangeCommand.key(KEY_1_BBUFFER).within(Range.of(Bound.inclusive(0L), Bound.unbounded()));
RangeCommand rangeCommand = RangeCommand.key(KEY_1_BBUFFER)
.within(Range.of(Bound.inclusive(0L), Bound.unbounded()));
StepVerifier.create(connection.stringCommands().getRange(Mono.just(rangeCommand))) //
.expectNext(new ReactiveRedisConnection.ByteBufferResponse<>(rangeCommand, ByteBuffer.wrap(VALUE_1.getBytes())))
@@ -356,7 +356,7 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(true) //
.verifyComplete();
assertThat(nativeCommands.getbit(KEY_1, 1), is(0L));
assertThat(nativeCommands.getbit(KEY_1, 1)).isEqualTo(0L);
}
@Test // DATAREDIS-525
@@ -439,7 +439,7 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
@Test // DATAREDIS-525
public void bitOpAndShouldWorkAsExpected() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -450,13 +450,13 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(7L) //
.verifyComplete();
assertThat(nativeCommands.get(KEY_3), is(equalTo("value-0")));
assertThat(nativeCommands.get(KEY_3)).isEqualTo("value-0");
}
@Test // DATAREDIS-525
public void bitOpOrShouldWorkAsExpected() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -467,13 +467,13 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(7L) //
.verifyComplete();
assertThat(nativeCommands.get(KEY_3), is(equalTo(VALUE_3)));
assertThat(nativeCommands.get(KEY_3)).isEqualTo(VALUE_3);
}
@Test // DATAREDIS-525
public void bitNotShouldThrowExceptionWhenMoreThanOnSourceKey() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
StepVerifier
.create(connection.stringCommands().bitOp(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), BitOperation.NOT,
@@ -505,8 +505,10 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
nativeBinaryCommands.set(KEY_1_BBUFFER, ByteBuffer.wrap(HexStringUtils.hexToBytes("fff0f0")));
StepVerifier.create(connection.stringCommands().bitPos(KEY_1_BBUFFER, true,
org.springframework.data.domain.Range.of(Bound.inclusive(2L), Bound.unbounded()))).expectNext(16L).verifyComplete();
StepVerifier
.create(connection.stringCommands().bitPos(KEY_1_BBUFFER, true,
org.springframework.data.domain.Range.of(Bound.inclusive(2L), Bound.unbounded())))
.expectNext(16L).verifyComplete();
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.springframework.data.domain.Range.Bound.*;
@@ -25,8 +24,8 @@ import reactor.test.StepVerifier;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.hamcrest.collection.IsIterableContainingInOrder;
import org.junit.Test;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.core.ScanOptions;
@@ -48,7 +47,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
@Test // DATAREDIS-525
public void zAddShouldAddValuesWithScores() {
assertThat(connection.zSetCommands().zAdd(KEY_1_BBUFFER, 3.5D, VALUE_1_BBUFFER).block(), is(1L));
assertThat(connection.zSetCommands().zAdd(KEY_1_BBUFFER, 3.5D, VALUE_1_BBUFFER).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
@@ -58,8 +57,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zRem(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_3_BBUFFER)).block(),
is(2L));
assertThat(connection.zSetCommands().zRem(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_3_BBUFFER)).block())
.isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -67,7 +66,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
assertThat(connection.zSetCommands().zIncrBy(KEY_1_BBUFFER, 3.5D, VALUE_1_BBUFFER).block(), is(4.5D));
assertThat(connection.zSetCommands().zIncrBy(KEY_1_BBUFFER, 3.5D, VALUE_1_BBUFFER).block()).isEqualTo(4.5D);
}
@Test // DATAREDIS-525
@@ -77,7 +76,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zRank(KEY_1_BBUFFER, VALUE_3_BBUFFER).block(), is(2L));
assertThat(connection.zSetCommands().zRank(KEY_1_BBUFFER, VALUE_3_BBUFFER).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -87,7 +86,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zRevRank(KEY_1_BBUFFER, VALUE_3_BBUFFER).block(), is(0L));
assertThat(connection.zSetCommands().zRevRank(KEY_1_BBUFFER, VALUE_3_BBUFFER).block()).isEqualTo(0L);
}
@Test // DATAREDIS-525
@@ -337,7 +336,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, TWO_TO_THREE_ALL_INCLUSIVE).block(), is(2L));
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, TWO_TO_THREE_ALL_INCLUSIVE).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -347,7 +346,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, TWO_EXCLUSIVE_TO_THREE_INCLUSIVE).block(), is(1L));
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, TWO_EXCLUSIVE_TO_THREE_INCLUSIVE).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
@@ -357,7 +356,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, TWO_INCLUSIVE_TO_THREE_EXCLUSIVE).block(), is(1L));
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, TWO_INCLUSIVE_TO_THREE_EXCLUSIVE).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
@@ -367,7 +366,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, Range.leftUnbounded(inclusive(2D))).block(), is(2L));
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, Range.leftUnbounded(inclusive(2D))).block())
.isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -377,7 +377,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, Range.rightUnbounded(inclusive(2D))).block(), is(2L));
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, Range.rightUnbounded(inclusive(2D))).block())
.isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -387,7 +388,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zCard(KEY_1_BBUFFER).block(), is(3L));
assertThat(connection.zSetCommands().zCard(KEY_1_BBUFFER).block()).isEqualTo(3L);
}
@Test // DATAREDIS-525
@@ -395,7 +396,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
assertThat(connection.zSetCommands().zScore(KEY_1_BBUFFER, VALUE_2_BBUFFER).block(), is(2D));
assertThat(connection.zSetCommands().zScore(KEY_1_BBUFFER, VALUE_2_BBUFFER).block()).isEqualTo(2D);
}
@Test // DATAREDIS-525
@@ -405,7 +406,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zRemRangeByRank(KEY_1_BBUFFER, ONE_TO_TWO).block(), is(2L));
assertThat(connection.zSetCommands().zRemRangeByRank(KEY_1_BBUFFER, ONE_TO_TWO).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -415,7 +416,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, Range.closed(1D, 2D)).block(), is(2L));
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, Range.closed(1D, 2D)).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -425,8 +426,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, Range.leftUnbounded(inclusive(2D))).block(),
is(2L));
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, Range.leftUnbounded(inclusive(2D))).block())
.isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -436,8 +437,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, Range.rightUnbounded(inclusive(2D))).block(),
is(2L));
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, Range.rightUnbounded(inclusive(2D))).block())
.isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -447,8 +448,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, TWO_EXCLUSIVE_TO_THREE_INCLUSIVE).block(),
is(1L));
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, TWO_EXCLUSIVE_TO_THREE_INCLUSIVE).block())
.isEqualTo(1L);
}
@Test // DATAREDIS-525
@@ -458,14 +459,14 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, TWO_INCLUSIVE_TO_THREE_EXCLUSIVE).block(),
is(1L));
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, TWO_INCLUSIVE_TO_THREE_EXCLUSIVE).block())
.isEqualTo(1L);
}
@Test // DATAREDIS-525
public void zUnionStoreShouldWorkCorrectly() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -473,16 +474,15 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_2, 2D, VALUE_2);
nativeCommands.zadd(KEY_2, 3D, VALUE_3);
assertThat(
connection.zSetCommands()
.zUnionStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block(),
is(3L));
assertThat(connection.zSetCommands()
.zUnionStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block())
.isEqualTo(3L);
}
@Test // DATAREDIS-525
public void zInterStoreShouldWorkCorrectly() {
assumeThat(connectionProvider instanceof StandaloneConnectionProvider, is(true));
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -490,10 +490,9 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_2, 2D, VALUE_2);
nativeCommands.zadd(KEY_2, 3D, VALUE_3);
assertThat(
connection.zSetCommands()
.zInterStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block(),
is(2L));
assertThat(connection.zSetCommands()
.zInterStore(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER), Arrays.asList(2D, 3D)).block())
.isEqualTo(2L);
}
@Test // DATAREDIS-525
@@ -509,16 +508,15 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
Range<String> emptyToC = Range.closed("", "c");
assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, emptyToC).collectList().block(),
IsIterableContainingInOrder.contains(ByteBuffer.wrap("a".getBytes()), ByteBuffer.wrap("b".getBytes()),
ByteBuffer.wrap("c".getBytes())));
assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, emptyToC).collectList().block()).containsExactly(
ByteBuffer.wrap("a".getBytes()), ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("c".getBytes()));
assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, Range.rightOpen("", "c")).collectList().block(),
IsIterableContainingInOrder.contains(ByteBuffer.wrap("a".getBytes()), ByteBuffer.wrap("b".getBytes())));
assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, Range.rightOpen("", "c")).collectList().block())
.containsExactly(ByteBuffer.wrap("a".getBytes()), ByteBuffer.wrap("b".getBytes()));
assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, Range.rightOpen("aaa", "g")).collectList().block(),
IsIterableContainingInOrder.contains(ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("c".getBytes()),
ByteBuffer.wrap("d".getBytes()), ByteBuffer.wrap("e".getBytes()), ByteBuffer.wrap("f".getBytes())));
assertThat(connection.zSetCommands().zRangeByLex(KEY_1_BBUFFER, Range.rightOpen("aaa", "g")).collectList().block())
.containsExactly(ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("c".getBytes()),
ByteBuffer.wrap("d".getBytes()), ByteBuffer.wrap("e".getBytes()), ByteBuffer.wrap("f".getBytes()));
}
@Test // DATAREDIS-525
@@ -532,17 +530,17 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 0D, "f");
nativeCommands.zadd(KEY_1, 0D, "g");
assertThat(connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, Range.closed("", "c")).collectList().block(),
IsIterableContainingInOrder.contains(ByteBuffer.wrap("c".getBytes()), ByteBuffer.wrap("b".getBytes()),
ByteBuffer.wrap("a".getBytes())));
assertThat(connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, Range.closed("", "c")).collectList().block())
.containsExactly(ByteBuffer.wrap("c".getBytes()), ByteBuffer.wrap("b".getBytes()),
ByteBuffer.wrap("a".getBytes()));
assertThat(connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, Range.rightOpen("", "c")).collectList().block(),
IsIterableContainingInOrder.contains(ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("a".getBytes())));
assertThat(connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, Range.rightOpen("", "c")).collectList().block())
.containsExactly(ByteBuffer.wrap("b".getBytes()), ByteBuffer.wrap("a".getBytes()));
assertThat(
connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, Range.rightOpen("aaa", "g")).collectList().block(),
IsIterableContainingInOrder.contains(ByteBuffer.wrap("f".getBytes()), ByteBuffer.wrap("e".getBytes()),
ByteBuffer.wrap("d".getBytes()), ByteBuffer.wrap("c".getBytes()), ByteBuffer.wrap("b".getBytes())));
connection.zSetCommands().zRevRangeByLex(KEY_1_BBUFFER, Range.rightOpen("aaa", "g")).collectList().block())
.containsExactly(ByteBuffer.wrap("f".getBytes()), ByteBuffer.wrap("e".getBytes()),
ByteBuffer.wrap("d".getBytes()), ByteBuffer.wrap("c".getBytes()), ByteBuffer.wrap("b".getBytes()));
}
}

View File

@@ -15,10 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import io.lettuce.core.ReadFrom;
import reactor.test.StepVerifier;
@@ -128,8 +125,8 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
public void shouldReadMastersCorrectly() {
List<RedisServer> servers = (List<RedisServer>) connectionFactory.getSentinelConnection().masters();
assertThat(servers.size(), is(1));
assertThat(servers.get(0).getName(), is(MASTER_NAME));
assertThat(servers.size()).isEqualTo(1);
assertThat(servers.get(0).getName()).isEqualTo(MASTER_NAME);
}
@Test // DATAREDIS-842, DATAREDIS-973
@@ -149,10 +146,10 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
connectionFactory.afterPropertiesSet();
RedisConnection directConnection = connectionFactory.getConnection();
assertThat(directConnection.exists("foo".getBytes()), is(true));
assertThat(directConnection.exists("foo".getBytes())).isTrue();
directConnection.select(0);
assertThat(directConnection.exists("foo".getBytes()), is(false));
assertThat(directConnection.exists("foo".getBytes())).isFalse();
directConnection.close();
connectionFactory.destroy();
}
@@ -190,11 +187,11 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
List<RedisServer> servers = (List<RedisServer>) sentinelConnection.masters();
assertThat(servers.size(), is(1));
assertThat(servers.size()).isEqualTo(1);
Collection<RedisServer> slaves = sentinelConnection.slaves(servers.get(0));
assertThat(slaves.size(), is(2));
assertThat(slaves, hasItems(SLAVE_0, SLAVE_1));
assertThat(slaves.size()).isEqualTo(2);
assertThat(slaves).contains(SLAVE_0, SLAVE_1);
}
@Test // DATAREDIS-462
@@ -209,7 +206,7 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
StringRedisConnection connection = new DefaultStringRedisConnection(factory.getConnection());
try {
assertThat(connection.ping(), is(equalTo("PONG")));
assertThat(connection.ping()).isEqualTo("PONG");
} finally {
connection.close();
}
@@ -229,7 +226,7 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
StringRedisConnection connection = new DefaultStringRedisConnection(factory.getConnection());
try {
assertThat(connection.getClientName(), is(equalTo("clientName")));
assertThat(connection.getClientName()).isEqualTo("clientName");
} finally {
connection.close();
}
@@ -247,8 +244,8 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
StringRedisConnection connection = new DefaultStringRedisConnection(factory.getConnection());
try {
assertThat(connection.ping(), is(equalTo("PONG")));
assertThat(connection.info().getProperty("role"), is(equalTo("master")));
assertThat(connection.ping()).isEqualTo("PONG");
assertThat(connection.info().getProperty("role")).isEqualTo("master");
} finally {
connection.close();
}
@@ -266,8 +263,8 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
StringRedisConnection connection = new DefaultStringRedisConnection(factory.getConnection());
try {
assertThat(connection.ping(), is(equalTo("PONG")));
assertThat(connection.info().getProperty("role"), is(equalTo("slave")));
assertThat(connection.ping()).isEqualTo("PONG");
assertThat(connection.info().getProperty("role")).isEqualTo("slave");
} finally {
connection.close();
}
@@ -285,8 +282,8 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
RedisConnection connection = factory.getConnection();
try {
assertThat(connection.ping(), is(equalTo("PONG")));
assertThat(connection.info().getProperty("role"), is(equalTo("slave")));
assertThat(connection.ping()).isEqualTo("PONG");
assertThat(connection.info().getProperty("role")).isEqualTo("slave");
} finally {
connection.close();
}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
@@ -26,6 +26,7 @@ import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisInvalidSubscriptionException;
@@ -70,9 +71,9 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, never()).punsubscribe(new byte[0]);
verify(connectionProvider).release(pubsub);
verify(pubsub).removeListener(any(LettuceMessageListener.class));
assertFalse(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isFalse();
assertThat(subscription.getChannels().isEmpty()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -83,11 +84,11 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getChannels().isEmpty()).isTrue();
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
}
@Test
@@ -100,9 +101,9 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, never()).punsubscribe(new byte[0]);
verify(connectionProvider).release(pubsub);
verify(pubsub).removeListener(any(LettuceMessageListener.class));
assertFalse(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isFalse();
assertThat(subscription.getChannels().isEmpty()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -113,11 +114,11 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
assertTrue(subscription.isAlive());
assertThat(subscription.isAlive()).isTrue();
Collection<byte[]> subChannels = subscription.getChannels();
assertEquals(1, subChannels.size());
assertArrayEquals("b".getBytes(), subChannels.iterator().next());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subChannels.size()).isEqualTo(1);
assertThat(subChannels.iterator().next()).isEqualTo("b".getBytes());
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -129,11 +130,11 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, times(1)).unsubscribe(channel);
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getChannels().isEmpty()).isTrue();
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
}
@Test
@@ -145,13 +146,13 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, times(1)).unsubscribe(channel);
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
assertTrue(subscription.isAlive());
assertThat(subscription.isAlive()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("b".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("b".getBytes());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
}
@Test
@@ -160,11 +161,11 @@ public class LettuceSubscriptionTests {
subscription.unsubscribe();
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
assertTrue(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getChannels().isEmpty()).isTrue();
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("s*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("s*".getBytes());
}
@Test
@@ -173,7 +174,7 @@ public class LettuceSubscriptionTests {
subscription.unsubscribe();
verify(connectionProvider, times(1)).release(pubsub);
verify(pubsub, times(1)).removeListener(any(LettuceMessageListener.class));
assertFalse(subscription.isAlive());
assertThat(subscription.isAlive()).isFalse();
subscription.unsubscribe();
verify(asyncCommands, times(1)).unsubscribe(new byte[][] { "a".getBytes() });
verify(asyncCommands, never()).unsubscribe(new byte[0]);
@@ -184,7 +185,7 @@ public class LettuceSubscriptionTests {
public void testSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
assertThat(subscription.isAlive()).isFalse();
subscription.subscribe(new byte[][] { "s".getBytes() });
}
@@ -195,11 +196,11 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
verify(asyncCommands, times(1)).punsubscribe(new byte[][] { "a*".getBytes() });
assertFalse(subscription.isAlive());
assertThat(subscription.isAlive()).isFalse();
verify(connectionProvider).release(pubsub);
verify(pubsub).removeListener(any(LettuceMessageListener.class));
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.getChannels().isEmpty()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -210,11 +211,11 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
verify(asyncCommands, times(1)).punsubscribe(new byte[][] { "s*".getBytes() });
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("a".getBytes());
}
@Test
@@ -227,9 +228,9 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, times(1)).punsubscribe(pattern);
verify(connectionProvider).release(pubsub);
verify(pubsub).removeListener(any(LettuceMessageListener.class));
assertFalse(subscription.isAlive());
assertTrue(subscription.getChannels().isEmpty());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isFalse();
assertThat(subscription.getChannels().isEmpty()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
}
@Test
@@ -240,11 +241,11 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, times(1)).punsubscribe(new byte[][] { "a*".getBytes() });
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
assertTrue(subscription.isAlive());
assertThat(subscription.isAlive()).isTrue();
Collection<byte[]> subPatterns = subscription.getPatterns();
assertEquals(1, subPatterns.size());
assertArrayEquals("b*".getBytes(), subPatterns.iterator().next());
assertTrue(subscription.getChannels().isEmpty());
assertThat(subPatterns.size()).isEqualTo(1);
assertThat(subPatterns.iterator().next()).isEqualTo("b*".getBytes());
assertThat(subscription.getChannels().isEmpty()).isTrue();
}
@Test
@@ -256,11 +257,11 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, times(1)).punsubscribe(pattern);
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("a".getBytes());
}
@Test
@@ -272,13 +273,13 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
verify(asyncCommands, times(1)).punsubscribe(pattern);
assertTrue(subscription.isAlive());
assertThat(subscription.isAlive()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("a".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("a".getBytes());
Collection<byte[]> patterns = subscription.getPatterns();
assertEquals(1, patterns.size());
assertArrayEquals("b*".getBytes(), patterns.iterator().next());
assertThat(patterns.size()).isEqualTo(1);
assertThat(patterns.iterator().next()).isEqualTo("b*".getBytes());
}
@Test
@@ -287,18 +288,18 @@ public class LettuceSubscriptionTests {
subscription.pUnsubscribe();
verify(asyncCommands, never()).unsubscribe(new byte[0]);
verify(asyncCommands, never()).punsubscribe(new byte[0]);
assertTrue(subscription.isAlive());
assertTrue(subscription.getPatterns().isEmpty());
assertThat(subscription.isAlive()).isTrue();
assertThat(subscription.getPatterns().isEmpty()).isTrue();
Collection<byte[]> channels = subscription.getChannels();
assertEquals(1, channels.size());
assertArrayEquals("s".getBytes(), channels.iterator().next());
assertThat(channels.size()).isEqualTo(1);
assertThat(channels.iterator().next()).isEqualTo("s".getBytes());
}
@Test
public void testPUnsubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
assertThat(subscription.isAlive()).isFalse();
subscription.pUnsubscribe();
verify(connectionProvider, times(1)).release(pubsub);
verify(pubsub, times(1)).removeListener(any(LettuceMessageListener.class));
@@ -311,7 +312,7 @@ public class LettuceSubscriptionTests {
public void testPSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertFalse(subscription.isAlive());
assertThat(subscription.isAlive()).isFalse();
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
}

View File

@@ -15,10 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsCollectionContaining.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Arrays;
@@ -32,6 +29,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.redis.connection.RedisClusterCommands.AddSlots;
import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisClusterNode;
@@ -84,7 +82,7 @@ public class DefaultClusterOperationsUnitTests {
Set<byte[]> keys = new HashSet<>(Arrays.asList(serializer.serialize("key-1"), serializer.serialize("key-2")));
when(connection.keys(any(RedisClusterNode.class), any(byte[].class))).thenReturn(keys);
assertThat(clusterOps.keys(NODE_1, "*"), hasItems("key-1", "key-2"));
assertThat(clusterOps.keys(NODE_1, "*")).contains("key-1", "key-2");
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
@@ -97,7 +95,7 @@ public class DefaultClusterOperationsUnitTests {
when(connection.keys(any(RedisClusterNode.class), any(byte[].class))).thenReturn(null);
assertThat(clusterOps.keys(NODE_1, "*"), notNullValue());
assertThat(clusterOps.keys(NODE_1, "*")).isNotNull();
}
@Test // DATAREDIS-315
@@ -105,7 +103,7 @@ public class DefaultClusterOperationsUnitTests {
when(connection.randomKey(any(RedisClusterNode.class))).thenReturn(serializer.serialize("key-1"));
assertThat(clusterOps.randomKey(NODE_1), is("key-1"));
assertThat(clusterOps.randomKey(NODE_1)).isEqualTo("key-1");
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315
@@ -118,7 +116,7 @@ public class DefaultClusterOperationsUnitTests {
when(connection.randomKey(any(RedisClusterNode.class))).thenReturn(null);
assertThat(clusterOps.randomKey(NODE_1), nullValue());
assertThat(clusterOps.randomKey(NODE_1)).isNull();
}
@Test // DATAREDIS-315
@@ -126,7 +124,7 @@ public class DefaultClusterOperationsUnitTests {
when(connection.ping(any(RedisClusterNode.class))).thenReturn("PONG");
assertThat(clusterOps.ping(NODE_1), is("PONG"));
assertThat(clusterOps.ping(NODE_1)).isEqualTo("PONG");
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-315

View File

@@ -15,12 +15,8 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.core.IsNull.*;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.data.Offset.offset;
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
@@ -37,6 +33,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
@@ -45,8 +42,6 @@ import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
@@ -116,7 +111,7 @@ public class DefaultGeoOperationsTests<K, M> {
Long numAdded = geoOperations.add(keyFactory.instance(), POINT_PALERMO, valueFactory.instance());
assertThat(numAdded, is(1L));
assertThat(numAdded).isEqualTo(1L);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -128,7 +123,7 @@ public class DefaultGeoOperationsTests<K, M> {
Long numAdded = geoOperations.add(keyFactory.instance(), memberCoordinateMap);
assertThat(numAdded, is(2L));
assertThat(numAdded).isEqualTo(2L);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -142,8 +137,8 @@ public class DefaultGeoOperationsTests<K, M> {
geoOperations.add(key, POINT_CATANIA, member2);
Distance dist = geoOperations.distance(key, member1, member2);
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_METERS, 0.005));
assertThat(dist.getUnit(), is(equalTo("m")));
assertThat(dist.getValue()).isCloseTo(DISTANCE_PALERMO_CATANIA_METERS, offset(0.005));
assertThat(dist.getUnit()).isEqualTo("m");
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -157,8 +152,8 @@ public class DefaultGeoOperationsTests<K, M> {
geoOperations.add(key, POINT_CATANIA, member2);
Distance dist = geoOperations.distance(key, member1, member2, KILOMETERS);
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_KILOMETERS, 0.005));
assertThat(dist.getUnit(), is(equalTo("km")));
assertThat(dist.getValue()).isCloseTo(DISTANCE_PALERMO_CATANIA_KILOMETERS, offset(0.005));
assertThat(dist.getUnit()).isEqualTo("km");
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -172,8 +167,8 @@ public class DefaultGeoOperationsTests<K, M> {
geoOperations.add(key, POINT_CATANIA, member2);
Distance dist = geoOperations.distance(key, member1, member2, DistanceUnit.MILES);
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_MILES, 0.005));
assertThat(dist.getUnit(), is(equalTo("mi")));
assertThat(dist.getValue()).isCloseTo(DISTANCE_PALERMO_CATANIA_MILES, offset(0.005));
assertThat(dist.getUnit()).isEqualTo("mi");
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -187,8 +182,8 @@ public class DefaultGeoOperationsTests<K, M> {
geoOperations.add(key, POINT_CATANIA, member2);
Distance dist = geoOperations.distance(key, member1, member2, DistanceUnit.FEET);
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_FEET, 0.005));
assertThat(dist.getUnit(), is(equalTo("ft")));
assertThat(dist.getValue()).isCloseTo(DISTANCE_PALERMO_CATANIA_FEET, offset(0.005));
assertThat(dist.getUnit()).isEqualTo("ft");
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -202,10 +197,10 @@ public class DefaultGeoOperationsTests<K, M> {
geoOperations.add(key, POINT_CATANIA, v2);
List<String> result = geoOperations.hash(key, v1, v2);
assertThat(result, hasSize(2));
assertThat(result).hasSize(2);
assertThat(result.get(0), is(equalTo("sqc8b49rny0")));
assertThat(result.get(1), is(equalTo("sqdtr74hyu0")));
assertThat(result.get(0)).isEqualTo("sqc8b49rny0");
assertThat(result.get(1)).isEqualTo("sqdtr74hyu0");
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -220,15 +215,15 @@ public class DefaultGeoOperationsTests<K, M> {
geoOperations.add(key, POINT_CATANIA, v2);
List<Point> result = geoOperations.position(key, v1, v2, v3);// v3 is nonexisting
assertThat(result, hasSize(3));
assertThat(result).hasSize(3);
assertThat(result.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.get(0).getX()).isCloseTo(POINT_PALERMO.getX(), offset(0.005));
assertThat(result.get(0).getY()).isCloseTo(POINT_PALERMO.getY(), offset(0.005));
assertThat(result.get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(result.get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
assertThat(result.get(1).getX()).isCloseTo(POINT_CATANIA.getX(), offset(0.005));
assertThat(result.get(1).getY()).isCloseTo(POINT_CATANIA.getY(), offset(0.005));
assertThat(result.get(2), is(nullValue()));
assertThat(result.get(2)).isNull();
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -244,7 +239,7 @@ public class DefaultGeoOperationsTests<K, M> {
GeoResults<GeoLocation<M>> result = geoOperations.radius(key,
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)));
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent()).hasSize(2);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -261,14 +256,14 @@ public class DefaultGeoOperationsTests<K, M> {
new Circle(new Point(15, 37), new Distance(200, KILOMETERS)),
newGeoRadiusArgs().includeDistance().sortDescending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(190.4424d, 0.005)));
assertThat(result.getContent().get(0).getDistance().getUnit(), is(equalTo("km")));
assertThat(result.getContent().get(0).getContent().getName(), is(member1));
assertThat(result.getContent()).hasSize(2);
assertThat(result.getContent().get(0).getDistance().getValue()).isCloseTo(190.4424d, offset(0.005));
assertThat(result.getContent().get(0).getDistance().getUnit()).isEqualTo("km");
assertThat(result.getContent().get(0).getContent().getName()).isEqualTo(member1);
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(56.4413d, 0.005)));
assertThat(result.getContent().get(1).getDistance().getUnit(), is(equalTo("km")));
assertThat(result.getContent().get(1).getContent().getName(), is(member2));
assertThat(result.getContent().get(1).getDistance().getValue()).isCloseTo(56.4413d, offset(0.005));
assertThat(result.getContent().get(1).getDistance().getUnit()).isEqualTo("km");
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member2);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -285,14 +280,18 @@ public class DefaultGeoOperationsTests<K, M> {
new Circle(new Point(15, 37), new Distance(200, KILOMETERS)),
newGeoRadiusArgs().includeCoordinates().sortAscending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member2));
assertThat(result.getContent()).hasSize(2);
assertThat(result.getContent().get(0).getContent().getPoint().getX()).isCloseTo(POINT_CATANIA.getX(),
offset(0.005));
assertThat(result.getContent().get(0).getContent().getPoint().getY()).isCloseTo(POINT_CATANIA.getY(),
offset(0.005));
assertThat(result.getContent().get(0).getContent().getName()).isEqualTo(member2);
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.getContent().get(1).getContent().getName(), is(member1));
assertThat(result.getContent().get(1).getContent().getPoint().getX()).isCloseTo(POINT_PALERMO.getX(),
offset(0.005));
assertThat(result.getContent().get(1).getContent().getPoint().getY()).isCloseTo(POINT_PALERMO.getY(),
offset(0.005));
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member1);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -308,19 +307,23 @@ public class DefaultGeoOperationsTests<K, M> {
GeoResults<GeoLocation<M>> result = geoOperations.radius(key,
new Circle(new Point(15, 37), new Distance(200, KILOMETERS)),
newGeoRadiusArgs().includeCoordinates().includeDistance().sortAscending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent()).hasSize(2);
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(56.4413d, 0.005)));
assertThat(result.getContent().get(0).getDistance().getUnit(), is(equalTo("km")));
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member2));
assertThat(result.getContent().get(0).getDistance().getValue()).isCloseTo(56.4413d, offset(0.005));
assertThat(result.getContent().get(0).getDistance().getUnit()).isEqualTo("km");
assertThat(result.getContent().get(0).getContent().getPoint().getX()).isCloseTo(POINT_CATANIA.getX(),
offset(0.005));
assertThat(result.getContent().get(0).getContent().getPoint().getY()).isCloseTo(POINT_CATANIA.getY(),
offset(0.005));
assertThat(result.getContent().get(0).getContent().getName()).isEqualTo(member2);
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(190.4424d, 0.005)));
assertThat(result.getContent().get(1).getDistance().getUnit(), is(equalTo("km")));
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.getContent().get(1).getContent().getName(), is(member1));
assertThat(result.getContent().get(1).getDistance().getValue()).isCloseTo(190.4424d, offset(0.005));
assertThat(result.getContent().get(1).getDistance().getUnit()).isEqualTo("km");
assertThat(result.getContent().get(1).getContent().getPoint().getX()).isCloseTo(POINT_PALERMO.getX(),
offset(0.005));
assertThat(result.getContent().get(1).getContent().getPoint().getY()).isCloseTo(POINT_PALERMO.getY(),
offset(0.005));
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member1);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -336,7 +339,7 @@ public class DefaultGeoOperationsTests<K, M> {
geoOperations.add(key, POINT_ARIGENTO, member3);
GeoResults<GeoLocation<M>> result = geoOperations.radius(key, member3, new Distance(200, KILOMETERS));
assertThat(result.getContent(), hasSize(3));
assertThat(result.getContent()).hasSize(3);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -354,11 +357,11 @@ public class DefaultGeoOperationsTests<K, M> {
GeoResults<GeoLocation<M>> result = geoOperations.radius(key, member3, new Distance(100, KILOMETERS),
newGeoRadiusArgs().includeDistance().sortDescending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.9778d, 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member1));
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(0.0d, 0.005))); // itself
assertThat(result.getContent().get(1).getContent().getName(), is(member3));
assertThat(result.getContent()).hasSize(2);
assertThat(result.getContent().get(0).getDistance().getValue()).isCloseTo(90.9778d, offset(0.005));
assertThat(result.getContent().get(0).getContent().getName()).isEqualTo(member1);
assertThat(result.getContent().get(1).getDistance().getValue()).isCloseTo(0.0d, offset(0.005)); // itself
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member3);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -376,14 +379,18 @@ public class DefaultGeoOperationsTests<K, M> {
GeoResults<GeoLocation<M>> result = geoOperations.radius(key, member3, new Distance(100, DistanceUnit.KILOMETERS),
newGeoRadiusArgs().includeCoordinates().sortAscending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_ARIGENTO.getX(), 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_ARIGENTO.getY(), 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member3));
assertThat(result.getContent()).hasSize(2);
assertThat(result.getContent().get(0).getContent().getPoint().getX()).isCloseTo(POINT_ARIGENTO.getX(),
offset(0.005));
assertThat(result.getContent().get(0).getContent().getPoint().getY()).isCloseTo(POINT_ARIGENTO.getY(),
offset(0.005));
assertThat(result.getContent().get(0).getContent().getName()).isEqualTo(member3);
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.getContent().get(1).getContent().getName(), is(member1));
assertThat(result.getContent().get(1).getContent().getPoint().getX()).isCloseTo(POINT_PALERMO.getX(),
offset(0.005));
assertThat(result.getContent().get(1).getContent().getPoint().getY()).isCloseTo(POINT_PALERMO.getY(),
offset(0.005));
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member1);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -401,17 +408,21 @@ public class DefaultGeoOperationsTests<K, M> {
// with coord and dist, ascending
GeoResults<GeoLocation<M>> result = geoOperations.radius(key, member1, new Distance(100, KILOMETERS),
newGeoRadiusArgs().includeCoordinates().includeDistance().sortAscending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent()).hasSize(2);
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(0.0d, 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member1));
assertThat(result.getContent().get(0).getDistance().getValue()).isCloseTo(0.0d, offset(0.005));
assertThat(result.getContent().get(0).getContent().getPoint().getX()).isCloseTo(POINT_PALERMO.getX(),
offset(0.005));
assertThat(result.getContent().get(0).getContent().getPoint().getY()).isCloseTo(POINT_PALERMO.getY(),
offset(0.005));
assertThat(result.getContent().get(0).getContent().getName()).isEqualTo(member1);
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(90.9778d, 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_ARIGENTO.getX(), 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_ARIGENTO.getY(), 0.005)));
assertThat(result.getContent().get(1).getContent().getName(), is(member3));
assertThat(result.getContent().get(1).getDistance().getValue()).isCloseTo(90.9778d, offset(0.005));
assertThat(result.getContent().get(1).getContent().getPoint().getX()).isCloseTo(POINT_ARIGENTO.getX(),
offset(0.005));
assertThat(result.getContent().get(1).getContent().getPoint().getY()).isCloseTo(POINT_ARIGENTO.getY(),
offset(0.005));
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member3);
}
@Test // DATAREDIS-438, DATAREDIS-614
@@ -422,6 +433,6 @@ public class DefaultGeoOperationsTests<K, M> {
geoOperations.add(key, POINT_PALERMO, member1);
assertThat(geoOperations.remove(key, member1), is(1L));
assertThat(geoOperations.remove(key, member1)).isEqualTo(1L);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import java.io.IOException;
@@ -32,6 +31,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RawObjectFactory;
@@ -128,8 +128,8 @@ public class DefaultHashOperationsTests<K, HK, HV> {
hashOps.put(key, key2, val2);
for (Map.Entry<HK, HV> entry : hashOps.entries(key).entrySet()) {
assertThat(entry.getKey(), anyOf(equalTo(key1), equalTo(key2)));
assertThat(entry.getValue(), anyOf(equalTo(val1), equalTo(val2)));
assertThat(entry.getKey()).isIn(key1, key2);
assertThat(entry.getValue()).isIn(val1, val2);
}
}
@@ -143,8 +143,8 @@ public class DefaultHashOperationsTests<K, HK, HV> {
hashOps.put(key, key1, val1);
hashOps.put(key, key2, val2);
Long numDeleted = hashOps.delete(key, key1, key2);
assertTrue(hashOps.keys(key).isEmpty());
assertEquals(2L, numDeleted.longValue());
assertThat(hashOps.keys(key).isEmpty()).isTrue();
assertThat(numDeleted.longValue()).isEqualTo(2L);
}
@Test // DATAREDIS-305
@@ -164,20 +164,20 @@ public class DefaultHashOperationsTests<K, HK, HV> {
long count = 0;
while (it.hasNext()) {
Map.Entry<HK, HV> entry = it.next();
assertThat(entry.getKey(), anyOf(equalTo(key1), equalTo(key2)));
assertThat(entry.getValue(), anyOf(equalTo(val1), equalTo(val2)));
assertThat(entry.getKey()).isIn(key1, key2);
assertThat(entry.getValue()).isIn(val1, val2);
count++;
}
it.close();
assertThat(count, is(hashOps.size(key)));
assertThat(count).isEqualTo(hashOps.size(key));
}
@Test // DATAREDIS-698
@IfProfileValue(name = "redisVersion", value = "3.0.3+")
public void lengthOfValue() throws IOException {
assumeThat(hashValueFactory instanceof StringObjectFactory, is(true));
assumeTrue(hashValueFactory instanceof StringObjectFactory);
K key = keyFactory.instance();
HK key1 = hashKeyFactory.instance();
@@ -188,7 +188,7 @@ public class DefaultHashOperationsTests<K, HK, HV> {
hashOps.put(key, key1, val1);
hashOps.put(key, key2, val2);
assertThat(hashOps.lengthOfValue(key, key1), is(Long.valueOf(val1.toString().length())));
assertThat(hashOps.lengthOfValue(key, key1)).isEqualTo(Long.valueOf(val1.toString().length()));
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Collection;
@@ -28,6 +27,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
@@ -92,7 +92,7 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
assertThat(hyperLogLogOps.add(key, v1, v2, v3), equalTo(1L));
assertThat(hyperLogLogOps.add(key, v1, v2, v3)).isEqualTo(1L);
}
@Test // DATAREDIS-308
@@ -105,7 +105,7 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
V v3 = valueFactory.instance();
hyperLogLogOps.add(key, v1, v2, v3);
assertThat(hyperLogLogOps.add(key, v2), equalTo(0L));
assertThat(hyperLogLogOps.add(key, v2)).isEqualTo(0L);
}
@Test // DATAREDIS-308
@@ -118,7 +118,7 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
V v3 = valueFactory.instance();
hyperLogLogOps.add(key, v1, v2, v3);
assertThat(hyperLogLogOps.size(key), equalTo(3L));
assertThat(hyperLogLogOps.size(key)).isEqualTo(3L);
}
@Test // DATAREDIS-308
@@ -135,7 +135,7 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
hyperLogLogOps.add(key, v1, v2, v3);
hyperLogLogOps.add(key2, v4);
assertThat(hyperLogLogOps.size(key, key2), equalTo(4L));
assertThat(hyperLogLogOps.size(key, key2)).isEqualTo(4L);
}
@Test // DATAREDIS-308
@@ -159,6 +159,6 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
hyperLogLogOps.union(desinationKey, sourceKey_1, sourceKey_2);
Thread.sleep(10); // give redis a little time to catch up
assertThat(hyperLogLogOps.size(desinationKey), equalTo(4L));
assertThat(hyperLogLogOps.size(desinationKey)).isEqualTo(4L);
}
}

View File

@@ -15,9 +15,8 @@
*/
package org.springframework.data.redis.core;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import java.util.Arrays;
import java.util.Collection;
@@ -31,6 +30,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
@@ -90,97 +90,110 @@ public class DefaultListOperationsTests<K, V> {
@Test
public void testLeftPushWithPivot() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
System.out.println("Value1" + v1);
System.out.println("Value2" + v2);
System.out.println("Value3" + v3);
assertEquals(Long.valueOf(1), listOps.leftPush(key, v1));
assertEquals(Long.valueOf(2), listOps.leftPush(key, v2));
assertEquals(Long.valueOf(3), listOps.leftPush(key, v1, v3));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v2, v3, v1 })));
assertThat(listOps.leftPush(key, v1)).isEqualTo(Long.valueOf(1));
assertThat(listOps.leftPush(key, v2)).isEqualTo(Long.valueOf(2));
assertThat(listOps.leftPush(key, v1, v3)).isEqualTo(Long.valueOf(3));
assertThat(listOps.range(key, 0, -1)).containsSequence(v2, v3, v1);
}
@Test
public void testLeftPushIfPresent() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
assertEquals(Long.valueOf(0), listOps.leftPushIfPresent(key, v1));
assertEquals(Long.valueOf(1), listOps.leftPush(key, v1));
assertEquals(Long.valueOf(2), listOps.leftPushIfPresent(key, v2));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v2, v1 })));
assertThat(listOps.leftPushIfPresent(key, v1)).isEqualTo(Long.valueOf(0));
assertThat(listOps.leftPush(key, v1)).isEqualTo(Long.valueOf(1));
assertThat(listOps.leftPushIfPresent(key, v2)).isEqualTo(Long.valueOf(2));
assertThat(listOps.range(key, 0, -1)).contains(v2, v1);
}
@SuppressWarnings("unchecked")
@Test
public void testLeftPushAll() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
assertEquals(Long.valueOf(2), listOps.leftPushAll(key, v1, v2));
assertEquals(Long.valueOf(3), listOps.leftPush(key, v3));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v3, v2, v1 })));
assertThat(listOps.leftPushAll(key, v1, v2)).isEqualTo(Long.valueOf(2));
assertThat(listOps.leftPush(key, v3)).isEqualTo(Long.valueOf(3));
assertThat(listOps.range(key, 0, -1)).contains(v3, v2, v1);
}
@Test
public void testRightPopAndLeftPushTimeout() {
// 1 ms timeout gets upgraded to 1 sec timeout at the moment
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
K key = keyFactory.instance();
K key2 = keyFactory.instance();
V v1 = valueFactory.instance();
assertNull(listOps.rightPopAndLeftPush(key, key2, 1, TimeUnit.MILLISECONDS));
assertThat(listOps.rightPopAndLeftPush(key, key2, 1, TimeUnit.MILLISECONDS)).isNull();
listOps.leftPush(key, v1);
assertThat(listOps.rightPopAndLeftPush(key, key2, 1, TimeUnit.MILLISECONDS), isEqual(v1));
assertThat(listOps.rightPopAndLeftPush(key, key2, 1, TimeUnit.MILLISECONDS)).isEqualTo(v1);
}
@Test
public void testRightPopAndLeftPush() {
K key = keyFactory.instance();
K key2 = keyFactory.instance();
V v1 = valueFactory.instance();
assertNull(listOps.rightPopAndLeftPush(key, key2));
assertThat(listOps.rightPopAndLeftPush(key, key2)).isNull();
listOps.leftPush(key, v1);
assertThat(listOps.rightPopAndLeftPush(key, key2), isEqual(v1));
assertThat(listOps.rightPopAndLeftPush(key, key2)).isEqualTo(v1);
}
@Test
public void testRightPushWithPivot() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
assertEquals(Long.valueOf(1), listOps.rightPush(key, v1));
assertEquals(Long.valueOf(2), listOps.rightPush(key, v2));
assertEquals(Long.valueOf(3), listOps.rightPush(key, v1, v3));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v3, v2 })));
assertThat(listOps.rightPush(key, v1)).isEqualTo(Long.valueOf(1));
assertThat(listOps.rightPush(key, v2)).isEqualTo(Long.valueOf(2));
assertThat(listOps.rightPush(key, v1, v3)).isEqualTo(Long.valueOf(3));
assertThat(listOps.range(key, 0, -1)).containsSequence(v1, v3, v2);
}
@Test
public void testRightPushIfPresent() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
assertEquals(Long.valueOf(0), listOps.rightPushIfPresent(key, v1));
assertEquals(Long.valueOf(1), listOps.rightPush(key, v1));
assertEquals(Long.valueOf(2), listOps.rightPushIfPresent(key, v2));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v2 })));
assertThat(listOps.rightPushIfPresent(key, v1)).isEqualTo(Long.valueOf(0));
assertThat(listOps.rightPush(key, v1)).isEqualTo(Long.valueOf(1));
assertThat(listOps.rightPushIfPresent(key, v2)).isEqualTo(Long.valueOf(2));
assertThat(listOps.range(key, 0, -1)).containsSequence(v1, v2);
}
@SuppressWarnings("unchecked")
@Test
public void testRightPushAll() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
assertEquals(Long.valueOf(2), listOps.rightPushAll(key, v1, v2));
assertEquals(Long.valueOf(3), listOps.rightPush(key, v3));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v2, v3 })));
assertThat(listOps.rightPushAll(key, v1, v2)).isEqualTo(Long.valueOf(2));
assertThat(listOps.rightPush(key, v3)).isEqualTo(Long.valueOf(3));
assertThat(listOps.range(key, 0, -1)).containsSequence(v1, v2, v3);
}
@Test // DATAREDIS-288
@@ -193,8 +206,8 @@ public class DefaultListOperationsTests<K, V> {
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
assertEquals(Long.valueOf(3), listOps.rightPushAll(key, Arrays.<V> asList(v1, v2, v3)));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v2, v3 })));
assertThat(listOps.rightPushAll(key, Arrays.<V> asList(v1, v2, v3))).isEqualTo(Long.valueOf(3));
assertThat(listOps.range(key, 0, -1)).containsSequence(v1, v2, v3);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-288
@@ -223,8 +236,8 @@ public class DefaultListOperationsTests<K, V> {
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
assertEquals(Long.valueOf(3), listOps.leftPushAll(key, Arrays.<V> asList(v1, v2, v3)));
assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v3, v2, v1 })));
assertThat(listOps.leftPushAll(key, Arrays.<V> asList(v1, v2, v3))).isEqualTo(Long.valueOf(3));
assertThat(listOps.range(key, 0, -1)).containsSequence(v3, v2, v1);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-288
@@ -232,7 +245,6 @@ public class DefaultListOperationsTests<K, V> {
listOps.leftPushAll(keyFactory.instance(), Collections.<V> emptyList());
}
@SuppressWarnings("unchecked")
@Test(expected = IllegalArgumentException.class) // DATAREDIS-288
public void leftPushAllShouldThrowExceptionWhenCollectionContainsNullValue() {
listOps.leftPushAll(keyFactory.instance(), Arrays.asList(valueFactory.instance(), null));

View File

@@ -15,21 +15,15 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -38,6 +32,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
@@ -53,6 +48,7 @@ import org.springframework.test.annotation.IfProfileValue;
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
@SuppressWarnings("unchecked")
public class DefaultSetOperationsTests<K, V> {
private RedisTemplate<K, V> redisTemplate;
@@ -101,41 +97,43 @@ public class DefaultSetOperationsTests<K, V> {
@SuppressWarnings("unchecked")
@Test
public void testDistinctRandomMembers() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
K setKey = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
setOps.add(setKey, v1);
setOps.add(setKey, v2);
setOps.add(setKey, v3);
Set<V> members = setOps.distinctRandomMembers(setKey, 2);
assertEquals(2, members.size());
Set<V> expected = new HashSet<>();
expected.add(v1);
expected.add(v2);
expected.add(v3);
assertThat(expected, hasItems((V[]) members.toArray()));
assertThat(members).hasSize(2).contains(v1, v2, v3);
}
@SuppressWarnings("unchecked")
@Test
public void testRandomMembersWithDuplicates() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
K setKey = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
setOps.add(setKey, v1);
setOps.add(setKey, v2);
List<V> members = setOps.randomMembers(setKey, 2);
assertEquals(2, members.size());
assertThat(members, CoreMatchers.<Iterable<? super V>> either(hasItem(v1)).or(hasItem(v2)));
List<V> members = setOps.randomMembers(setKey, 2);
assertThat(members).hasSize(2).contains(v1, v2);
}
@Test
public void testRandomMembersNegative() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
try {
setOps.randomMembers(keyFactory.instance(), -1);
fail("IllegalArgumentException should be thrown");
@@ -144,7 +142,9 @@ public class DefaultSetOperationsTests<K, V> {
@Test
public void testDistinctRandomMembersNegative() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
try {
setOps.distinctRandomMembers(keyFactory.instance(), -2);
fail("IllegalArgumentException should be thrown");
@@ -154,25 +154,31 @@ public class DefaultSetOperationsTests<K, V> {
@SuppressWarnings("unchecked")
@Test
public void testMove() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
setOps.add(key1, v1);
setOps.add(key1, v2);
setOps.move(key1, v1, key2);
assertThat(setOps.members(key1), isEqual(new HashSet<>(Collections.singletonList(v2))));
assertThat(setOps.members(key2), isEqual(new HashSet<>(Collections.singletonList(v1))));
assertThat(setOps.members(key1)).containsOnly(v2);
assertThat(setOps.members(key2)).containsOnly(v1);
}
@SuppressWarnings("unchecked")
@Test
public void testPop() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
setOps.add(key, v1);
assertThat(setOps.pop(key), isEqual(v1));
assertTrue(setOps.members(key).isEmpty());
assertThat(setOps.pop(key)).isEqualTo(v1);
assertThat(setOps.members(key)).isEmpty();
}
@Test // DATAREDIS-668
@@ -182,46 +188,50 @@ public class DefaultSetOperationsTests<K, V> {
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
setOps.add(key, v1, v2, v3);
List<V> result = setOps.pop(key, 2);
assertThat(result, hasSize(2));
assertThat(result.get(0), instanceOf(v1.getClass()));
assertThat(result).hasSize(2);
assertThat(result.get(0)).isInstanceOf(v1.getClass());
}
@SuppressWarnings("unchecked")
@Test
public void testRandomMember() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
setOps.add(key, v1);
assertThat(setOps.randomMember(key), isEqual(v1));
assertThat(setOps.randomMember(key)).isEqualTo(v1);
}
@SuppressWarnings("unchecked")
@Test
public void testAdd() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
assertEquals(Long.valueOf(2), setOps.add(key, v1, v2));
Set<V> expected = new HashSet<>();
expected.add(v1);
expected.add(v2);
assertThat(setOps.members(key), isEqual(expected));
assertThat(setOps.add(key, v1, v2)).isEqualTo(Long.valueOf(2));
assertThat(setOps.members(key)).containsOnly(v1, v2);
}
@SuppressWarnings("unchecked")
@Test
public void testRemove() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
V v3 = valueFactory.instance();
V v4 = valueFactory.instance();
setOps.add(key, v1, v2, v3);
assertEquals(Long.valueOf(2), setOps.remove(key, v1, v2, v4));
assertThat(setOps.members(key), isEqual(Collections.singleton(v3)));
assertThat(setOps.remove(key, v1, v2, v4)).isEqualTo(Long.valueOf(2));
assertThat(setOps.members(key)).containsOnly(v3);
}
@Test // DATAREDIS-304
@@ -238,11 +248,11 @@ public class DefaultSetOperationsTests<K, V> {
Cursor<V> it = setOps.scan(key, ScanOptions.scanOptions().count(1).build());
long count = 0;
while (it.hasNext()) {
assertThat(it.next(), anyOf(equalTo(v1), equalTo(v2), equalTo(v3)));
assertThat(it.next()).isIn(v1, v2, v3);
count++;
}
it.close();
assertThat(count, is(setOps.size(key)));
assertThat(count).isEqualTo(setOps.size(key));
}
@Test // DATAREDIS-873
@@ -259,7 +269,7 @@ public class DefaultSetOperationsTests<K, V> {
setOps.add(sourceKey1, v1, v2, v3);
setOps.add(sourceKey2, v2, v3, v4);
assertThat(setOps.difference(Arrays.asList(sourceKey1, sourceKey2)), hasItems(v1));
assertThat(setOps.difference(Arrays.asList(sourceKey1, sourceKey2))).contains(v1);
}
@Test // DATAREDIS-873
@@ -277,7 +287,7 @@ public class DefaultSetOperationsTests<K, V> {
setOps.add(sourceKey1, v1, v2, v3);
setOps.add(sourceKey2, v2, v3, v4);
assertThat(setOps.differenceAndStore(Arrays.asList(sourceKey1, sourceKey2), destinationKey), isEqual(1L));
assertThat(setOps.differenceAndStore(Arrays.asList(sourceKey1, sourceKey2), destinationKey)).isEqualTo(1L);
}
@Test // DATAREDIS-873
@@ -294,7 +304,7 @@ public class DefaultSetOperationsTests<K, V> {
setOps.add(sourceKey1, v1, v2, v3);
setOps.add(sourceKey2, v2, v3, v4);
assertThat(setOps.union(Arrays.asList(sourceKey1, sourceKey2)), hasItems(v1, v2, v3, v4));
assertThat(setOps.union(Arrays.asList(sourceKey1, sourceKey2))).contains(v1, v2, v3, v4);
}
@Test // DATAREDIS-873
@@ -312,7 +322,7 @@ public class DefaultSetOperationsTests<K, V> {
setOps.add(sourceKey1, v1, v2, v3);
setOps.add(sourceKey2, v2, v3, v4);
assertThat(setOps.unionAndStore(Arrays.asList(sourceKey1, sourceKey2), destinationKey), isEqual(4L));
assertThat(setOps.unionAndStore(Arrays.asList(sourceKey1, sourceKey2), destinationKey)).isEqualTo(4L);
}
@Test // DATAREDIS-873
@@ -329,7 +339,7 @@ public class DefaultSetOperationsTests<K, V> {
setOps.add(sourceKey1, v1, v2, v3);
setOps.add(sourceKey2, v2, v3, v4);
assertThat(setOps.intersect(Arrays.asList(sourceKey1, sourceKey2)), hasSize(2));
assertThat(setOps.intersect(Arrays.asList(sourceKey1, sourceKey2))).hasSize(2);
}
@Test // DATAREDIS-448, DATAREDIS-873
@@ -347,7 +357,7 @@ public class DefaultSetOperationsTests<K, V> {
setOps.add(sourceKey1, v1, v2, v3);
setOps.add(sourceKey2, v2, v3, v4);
assertThat(setOps.intersectAndStore(sourceKey1, sourceKey2, destinationKey), is(2L));
assertThat(setOps.intersectAndStore(Arrays.asList(sourceKey1, sourceKey2), destinationKey), is(2L));
assertThat(setOps.intersectAndStore(sourceKey1, sourceKey2, destinationKey)).isEqualTo(2L);
assertThat(setOps.intersectAndStore(Arrays.asList(sourceKey1, sourceKey2), destinationKey)).isEqualTo(2L);
}
}

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
/**
@@ -34,22 +34,22 @@ public class DefaultTypedTupleUnitTests {
@Test // DATAREDIS-294
public void compareToShouldUseScore() {
assertThat(WITH_SCORE_1.compareTo(WITH_SCORE_2), equalTo(-1));
assertThat(WITH_SCORE_2.compareTo(WITH_SCORE_1), equalTo(1));
assertThat(WITH_SCORE_1.compareTo(ANOTHER_ONE_WITH_SCORE_1), equalTo(0));
assertThat(WITH_SCORE_1.compareTo(WITH_SCORE_2)).isEqualTo(-1);
assertThat(WITH_SCORE_2.compareTo(WITH_SCORE_1)).isEqualTo(1);
assertThat(WITH_SCORE_1.compareTo(ANOTHER_ONE_WITH_SCORE_1)).isEqualTo(0);
}
@Test // DATAREDIS-294
public void compareToShouldConsiderGivenNullAsZeroScore() {
assertThat(WITH_SCORE_1.compareTo(null), equalTo(1));
assertThat(WITH_SCORE_NULL.compareTo(null), equalTo(0));
assertThat(WITH_SCORE_1.compareTo(null)).isEqualTo(1);
assertThat(WITH_SCORE_NULL.compareTo(null)).isEqualTo(0);
}
@Test // DATAREDIS-294
public void compareToShouldConsiderNullScoreAsZeroScore() {
assertThat(WITH_SCORE_1.compareTo(WITH_SCORE_NULL), equalTo(1));
assertThat(WITH_SCORE_NULL.compareTo(WITH_SCORE_1), equalTo(-1));
assertThat(WITH_SCORE_1.compareTo(WITH_SCORE_NULL)).isEqualTo(1);
assertThat(WITH_SCORE_NULL.compareTo(WITH_SCORE_1)).isEqualTo(-1);
}
}

View File

@@ -15,15 +15,13 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import java.text.DecimalFormat;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
@@ -38,6 +36,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
@@ -102,12 +101,12 @@ public class DefaultValueOperationsTests<K, V> {
K key = keyFactory.instance();
V value = valueFactory.instance();
assumeTrue(value instanceof Long);
assumeThat(value).isInstanceOf(Long.class);
valueOps.set(key, value);
assertEquals(Long.valueOf((Long) value + 1), valueOps.increment(key));
assertEquals(Long.valueOf((Long) value + 1), valueOps.get(key));
assertThat(valueOps.increment(key)).isEqualTo(Long.valueOf((Long) value + 1));
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value + 1));
}
@Test
@@ -116,15 +115,15 @@ public class DefaultValueOperationsTests<K, V> {
K key = keyFactory.instance();
V value = valueFactory.instance();
assumeTrue(value instanceof Long);
assumeThat(value).isInstanceOf(Long.class);
valueOps.set(key, value);
assertEquals(Long.valueOf((Long) value - 10), valueOps.increment(key, -10));
assertEquals(Long.valueOf((Long) value - 10), valueOps.get(key));
assertThat(valueOps.increment(key, -10)).isEqualTo(Long.valueOf((Long) value - 10));
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value - 10));
valueOps.increment(key, -10);
assertEquals(Long.valueOf((Long) value - 20), valueOps.get(key));
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value - 20));
}
@Test // DATAREDIS-247
@@ -141,11 +140,11 @@ public class DefaultValueOperationsTests<K, V> {
DecimalFormat twoDForm = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
assertEquals(Double.valueOf(twoDForm.format((Double) value + 1.4)), valueOps.increment(key, 1.4));
assertEquals(Double.valueOf(twoDForm.format((Double) value + 1.4)), valueOps.get(key));
assertThat(valueOps.increment(key, 1.4)).isEqualTo(Double.valueOf(twoDForm.format((Double) value + 1.4)));
assertThat(valueOps.get(key)).isEqualTo(Double.valueOf(twoDForm.format((Double) value + 1.4)));
valueOps.increment(key, -10d);
assertEquals(Double.valueOf(twoDForm.format((Double) value + 1.4 - 10d)), valueOps.get(key));
assertThat(valueOps.get(key)).isEqualTo(Double.valueOf(twoDForm.format((Double) value + 1.4 - 10d)));
}
@Test // DATAREDIS-784
@@ -154,12 +153,12 @@ public class DefaultValueOperationsTests<K, V> {
K key = keyFactory.instance();
V value = valueFactory.instance();
assumeTrue(value instanceof Long);
assumeThat(value).isInstanceOf(Long.class);
valueOps.set(key, value);
assertEquals(Long.valueOf((Long) value - 1), valueOps.decrement(key));
assertEquals(Long.valueOf((Long) value - 1), valueOps.get(key));
assertThat(valueOps.decrement(key)).isEqualTo(Long.valueOf((Long) value - 1));
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value - 1));
}
@Test // DATAREDIS-784
@@ -168,12 +167,12 @@ public class DefaultValueOperationsTests<K, V> {
K key = keyFactory.instance();
V value = valueFactory.instance();
assumeTrue(value instanceof Long);
assumeThat(value).isInstanceOf(Long.class);
valueOps.set(key, value);
assertEquals(Long.valueOf((Long) value - 5), valueOps.decrement(key, 5));
assertEquals(Long.valueOf((Long) value - 5), valueOps.get(key));
assertThat(valueOps.decrement(key, 5)).isEqualTo(Long.valueOf((Long) value - 5));
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value - 5));
}
@Test
@@ -188,8 +187,8 @@ public class DefaultValueOperationsTests<K, V> {
keysAndValues.put(key1, value1);
keysAndValues.put(key2, value2);
assertTrue(valueOps.multiSetIfAbsent(keysAndValues));
assertThat(valueOps.multiGet(keysAndValues.keySet()), isEqual(new ArrayList<>(keysAndValues.values())));
assertThat(valueOps.multiSetIfAbsent(keysAndValues)).isTrue();
assertThat(valueOps.multiGet(keysAndValues.keySet())).containsExactlyElementsOf(keysAndValues.values());
}
@Test
@@ -207,7 +206,7 @@ public class DefaultValueOperationsTests<K, V> {
keysAndValues.put(key1, value2);
keysAndValues.put(key2, value3);
assertFalse(valueOps.multiSetIfAbsent(keysAndValues));
assertThat(valueOps.multiSetIfAbsent(keysAndValues)).isFalse();
}
@Test
@@ -224,7 +223,7 @@ public class DefaultValueOperationsTests<K, V> {
valueOps.multiSet(keysAndValues);
assertThat(valueOps.multiGet(keysAndValues.keySet()), isEqual(new ArrayList<>(keysAndValues.values())));
assertThat(valueOps.multiGet(keysAndValues.keySet())).containsExactlyElementsOf(keysAndValues.values());
}
@Test
@@ -235,7 +234,7 @@ public class DefaultValueOperationsTests<K, V> {
valueOps.set(key, value);
assertThat(valueOps.get(key), isEqual(value));
assertThat(valueOps.get(key)).isEqualTo(value);
}
@Test
@@ -247,7 +246,7 @@ public class DefaultValueOperationsTests<K, V> {
valueOps.set(key, value1);
assertThat(valueOps.getAndSet(key, value2), isEqual(value1));
assertThat(valueOps.getAndSet(key, value2)).isEqualTo(value1);
}
@Test
@@ -260,8 +259,7 @@ public class DefaultValueOperationsTests<K, V> {
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire, is(lessThan(TimeUnit.SECONDS.toMillis(6))));
assertThat(expire, is(greaterThan(TimeUnit.MILLISECONDS.toMillis(1))));
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-815
@@ -274,8 +272,7 @@ public class DefaultValueOperationsTests<K, V> {
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire, is(lessThan(TimeUnit.SECONDS.toMillis(6))));
assertThat(expire, is(greaterThan(TimeUnit.MILLISECONDS.toMillis(1))));
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-815
@@ -288,14 +285,14 @@ public class DefaultValueOperationsTests<K, V> {
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire, is(lessThan(TimeUnit.SECONDS.toMillis(6))));
assertThat(expire, is(greaterThan(TimeUnit.MILLISECONDS.toMillis(1))));
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6));
assertThat(expire).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-271
public void testSetWithExpirationWithTimeUnitMilliseconds() {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
assumeThat(RedisTestProfileValueSource.matches("runLongTests", "true")).isTrue();
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -311,12 +308,12 @@ public class DefaultValueOperationsTests<K, V> {
K key = keyFactory.instance();
V value = valueFactory.instance();
assumeTrue(redisTemplate instanceof StringRedisTemplate);
assumeThat(redisTemplate).isInstanceOf(StringRedisTemplate.class);
valueOps.set(key, value);
assertEquals(Integer.valueOf(((String) value).length() + 3), valueOps.append(key, "aaa"));
assertEquals((String) value + "aaa", valueOps.get(key));
assertThat(valueOps.append(key, "aaa")).isEqualTo(Integer.valueOf(((String) value).length() + 3));
assertThat(valueOps.get(key)).isEqualTo(value + "aaa");
}
@Test
@@ -325,11 +322,11 @@ public class DefaultValueOperationsTests<K, V> {
K key = keyFactory.instance();
V value = valueFactory.instance();
assumeTrue(value instanceof String);
assumeThat(value).isInstanceOf(String.class);
valueOps.set(key, value);
assertEquals(2, valueOps.get(key, 0, 1).length());
assertThat(valueOps.get(key, 0, 1)).hasSize(2);
}
@Test
@@ -339,12 +336,12 @@ public class DefaultValueOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
assumeTrue(value1 instanceof String);
assumeThat(value1).isInstanceOf(String.class);
valueOps.set(key, value1);
valueOps.set(key, value2, 0);
assertEquals(value2, valueOps.get(key));
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test
@@ -354,8 +351,8 @@ public class DefaultValueOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
assertTrue(valueOps.setIfAbsent(key, value1));
assertFalse(valueOps.setIfAbsent(key, value2));
assertThat(valueOps.setIfAbsent(key, value1)).isTrue();
assertThat(valueOps.setIfAbsent(key, value2)).isFalse();
}
@Test // DATAREDIS-782
@@ -365,13 +362,12 @@ public class DefaultValueOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
assertTrue(valueOps.setIfAbsent(key, value1, 5, TimeUnit.SECONDS));
assertFalse(valueOps.setIfAbsent(key, value2, 5, TimeUnit.SECONDS));
assertThat(valueOps.setIfAbsent(key, value1, 5, TimeUnit.SECONDS)).isTrue();
assertThat(valueOps.setIfAbsent(key, value2, 5, TimeUnit.SECONDS)).isFalse();
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire, is(lessThan(TimeUnit.SECONDS.toMillis(6))));
assertThat(expire, is(greaterThan(TimeUnit.MILLISECONDS.toMillis(1))));
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-815
@@ -381,13 +377,12 @@ public class DefaultValueOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
assertTrue(valueOps.setIfAbsent(key, value1, Duration.ofSeconds(5)));
assertFalse(valueOps.setIfAbsent(key, value2, Duration.ofSeconds(5)));
assertThat(valueOps.setIfAbsent(key, value1, Duration.ofSeconds(5))).isTrue();
assertThat(valueOps.setIfAbsent(key, value2, Duration.ofSeconds(5))).isFalse();
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire, is(lessThan(TimeUnit.SECONDS.toMillis(6))));
assertThat(expire, is(greaterThan(TimeUnit.MILLISECONDS.toMillis(1))));
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-815
@@ -397,13 +392,12 @@ public class DefaultValueOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
assertTrue(valueOps.setIfAbsent(key, value1, Duration.ofMillis(5500)));
assertFalse(valueOps.setIfAbsent(key, value2, Duration.ofMillis(5500)));
assertThat(valueOps.setIfAbsent(key, value1, Duration.ofMillis(5500))).isTrue();
assertThat(valueOps.setIfAbsent(key, value2, Duration.ofMillis(5500))).isFalse();
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire, is(lessThan(TimeUnit.SECONDS.toMillis(6))));
assertThat(expire, is(greaterThan(TimeUnit.MILLISECONDS.toMillis(1))));
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-786
@@ -415,13 +409,13 @@ public class DefaultValueOperationsTests<K, V> {
valueOps.set(key, value1);
assertTrue(valueOps.setIfPresent(key, value2));
assertThat(valueOps.get(key), is(value2));
assertThat(valueOps.setIfPresent(key, value2)).isTrue();
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test // DATAREDIS-786
public void setIfPresentReturnsFalseWhenKeyDoesNotExist() {
assertFalse(valueOps.setIfPresent(keyFactory.instance(), valueFactory.instance()));
assertThat(valueOps.setIfPresent(keyFactory.instance(), valueFactory.instance())).isFalse();
}
@Test // DATAREDIS-786
@@ -431,15 +425,14 @@ public class DefaultValueOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
assertFalse(valueOps.setIfPresent(key, value1, 5, TimeUnit.SECONDS));
assertThat(valueOps.setIfPresent(key, value1, 5, TimeUnit.SECONDS)).isFalse();
valueOps.set(key, value1);
assertTrue(valueOps.setIfPresent(key, value2, 5, TimeUnit.SECONDS));
assertThat(valueOps.setIfPresent(key, value2, 5, TimeUnit.SECONDS)).isTrue();
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire, is(lessThan(TimeUnit.SECONDS.toMillis(6))));
assertThat(expire, is(greaterThan(TimeUnit.MILLISECONDS.toMillis(1))));
assertThat(valueOps.get(key), is(value2));
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test // DATAREDIS-815
@@ -449,15 +442,14 @@ public class DefaultValueOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
assertFalse(valueOps.setIfPresent(key, value1, Duration.ofSeconds(5)));
assertThat(valueOps.setIfPresent(key, value1, Duration.ofSeconds(5))).isFalse();
valueOps.set(key, value1);
assertTrue(valueOps.setIfPresent(key, value2, Duration.ofSeconds(5)));
assertThat(valueOps.setIfPresent(key, value2, Duration.ofSeconds(5))).isTrue();
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire, is(lessThan(TimeUnit.SECONDS.toMillis(6))));
assertThat(expire, is(greaterThan(TimeUnit.MILLISECONDS.toMillis(1))));
assertThat(valueOps.get(key), is(value2));
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test // DATAREDIS-815
@@ -467,15 +459,14 @@ public class DefaultValueOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
assertFalse(valueOps.setIfPresent(key, value1, Duration.ofMillis(5500)));
assertThat(valueOps.setIfPresent(key, value1, Duration.ofMillis(5500))).isFalse();
valueOps.set(key, value1);
assertTrue(valueOps.setIfPresent(key, value2, Duration.ofMillis(5500)));
assertThat(valueOps.setIfPresent(key, value2, Duration.ofMillis(5500))).isTrue();
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire, is(lessThan(TimeUnit.SECONDS.toMillis(6))));
assertThat(expire, is(greaterThan(TimeUnit.MILLISECONDS.toMillis(1))));
assertThat(valueOps.get(key), is(value2));
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test
@@ -486,7 +477,7 @@ public class DefaultValueOperationsTests<K, V> {
valueOps.set(key, value);
assertTrue(valueOps.size(key) > 0);
assertThat(valueOps.size(key) > 0).isTrue();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -498,7 +489,7 @@ public class DefaultValueOperationsTests<K, V> {
byte[][] rawKeys = ((DefaultValueOperations) valueOps).rawKeys(key1, key2);
assertEquals(2, rawKeys.length);
assertThat(rawKeys.length).isEqualTo(2);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -510,7 +501,7 @@ public class DefaultValueOperationsTests<K, V> {
byte[][] rawKeys = ((DefaultValueOperations) valueOps).rawKeys(Arrays.asList(new Object[] { key1, key2 }));
assertEquals(2, rawKeys.length);
assertThat(rawKeys.length).isEqualTo(2);
}
@SuppressWarnings("rawtypes")
@@ -519,20 +510,20 @@ public class DefaultValueOperationsTests<K, V> {
K key = keyFactory.instance();
assumeTrue(key instanceof byte[]);
assumeThat(key).isInstanceOf(byte[].class);
assertNotNull(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key));
assertThat(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key)).isNotNull();
}
@Test // DATAREDIS-197
public void testSetAndGetBit() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
assumeThat(redisTemplate).isInstanceOf(StringRedisTemplate.class);
K key = keyFactory.instance();
int bitOffset = 65;
valueOps.setBit(key, bitOffset, true);
assertEquals(true, valueOps.getBit(key, bitOffset));
assertThat(valueOps.getBit(key, bitOffset)).isTrue();
}
}

View File

@@ -22,7 +22,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.redis.connection.BitFieldSubCommands;
import org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldType;
import org.springframework.data.redis.connection.RedisConnection;

View File

@@ -15,16 +15,14 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.*;
import static org.assertj.core.data.Offset.offset;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import org.junit.After;
@@ -35,6 +33,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.DoubleAsStringObjectFactory;
import org.springframework.data.redis.DoubleObjectFactory;
@@ -57,6 +56,7 @@ import org.springframework.test.annotation.IfProfileValue;
* @param <K> Key type
* @param <V> Value type
*/
@SuppressWarnings("unchecked")
@RunWith(Parameterized.class)
public class DefaultZSetOperationsTests<K, V> {
@@ -105,86 +105,100 @@ public class DefaultZSetOperationsTests<K, V> {
@Test
public void testCount() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
zSetOps.add(key1, value1, 2.5);
zSetOps.add(key1, value2, 5.5);
assertEquals(Long.valueOf(1), zSetOps.count(key1, 2.7, 5.7));
assertThat(zSetOps.count(key1, 2.7, 5.7)).isEqualTo(Long.valueOf(1));
}
@Test
public void testIncrementScore() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
zSetOps.add(key1, value1, 2.5);
assertEquals(Double.valueOf(5.7), zSetOps.incrementScore(key1, value1, 3.2));
assertThat(zSetOps.incrementScore(key1, value1, 3.2)).isEqualTo(Double.valueOf(5.7));
Set<TypedTuple<V>> values = zSetOps.rangeWithScores(key1, 0, -1);
assertEquals(1, values.size());
assertThat(values).hasSize(1);
TypedTuple<V> tuple = values.iterator().next();
assertEquals(new DefaultTypedTuple<>(value1, 5.7), tuple);
assertThat(tuple).isEqualTo(new DefaultTypedTuple<>(value1, 5.7));
}
@Test
public void testRangeByScoreOffsetCount() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
System.out.println(value1 + "*" + value2 + "*" + value3);
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
assertThat(zSetOps.rangeByScore(key, 1.5, 4.7, 0, 1), isEqual(Collections.singleton(value1)));
assertThat(zSetOps.rangeByScore(key, 1.5, 4.7, 0, 1)).containsOnly(value1);
}
@Test
public void testRangeByScoreWithScoresOffsetCount() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
Set<TypedTuple<V>> tuples = zSetOps.rangeByScoreWithScores(key, 1.5, 4.7, 0, 1);
assertEquals(1, tuples.size());
TypedTuple<V> tuple = tuples.iterator().next();
assertThat(tuple, isEqual(new DefaultTypedTuple<>(value1, 1.9)));
assertThat(tuples).hasSize(1).contains(new DefaultTypedTuple<>(value1, 1.9));
}
@Test
public void testReverseRangeByScoreOffsetCount() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
assertThat(zSetOps.reverseRangeByScore(key, 1.5, 4.7, 0, 1), isEqual(Collections.singleton(value2)));
assertThat(zSetOps.reverseRangeByScore(key, 1.5, 4.7, 0, 1)).containsOnly(value2);
}
@Test
public void testReverseRangeByScoreWithScoresOffsetCount() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
Set<TypedTuple<V>> tuples = zSetOps.reverseRangeByScoreWithScores(key, 1.5, 4.7, 0, 1);
assertEquals(1, tuples.size());
TypedTuple<V> tuple = tuples.iterator().next();
assertThat(tuple, isEqual(new DefaultTypedTuple<>(value2, 3.7)));
assertThat(tuples).hasSize(1).contains(new DefaultTypedTuple<>(value2, 3.7));
}
@Test // DATAREDIS-407
public void testRangeByLexUnbounded() {
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -196,16 +210,14 @@ public class DefaultZSetOperationsTests<K, V> {
zSetOps.add(key, value3, 5.8);
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.unbounded());
assertEquals(3, tuples.size());
V tuple = tuples.iterator().next();
assertThat(tuple, isEqual(value1));
assertThat(tuples).hasSize(3).contains(value1);
}
@Test // DATAREDIS-407
public void testRangeByLexBounded() {
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -217,16 +229,14 @@ public class DefaultZSetOperationsTests<K, V> {
zSetOps.add(key, value3, 5.8);
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gt(value1).lt(value3));
assertEquals(1, tuples.size());
V tuple = tuples.iterator().next();
assertThat(tuple, isEqual(value2));
assertThat(tuples).hasSize(1).contains(value2);
}
@Test // DATAREDIS-407
public void testRangeByLexUnboundedWithLimit() {
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -239,16 +249,14 @@ public class DefaultZSetOperationsTests<K, V> {
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.unbounded(),
RedisZSetCommands.Limit.limit().count(1).offset(1));
assertEquals(1, tuples.size());
V tuple = tuples.iterator().next();
assertThat(tuple, isEqual(value2));
assertThat(tuples).hasSize(1).startsWith(value2);
}
@Test // DATAREDIS-407
public void testRangeByLexBoundedWithLimit() {
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -261,44 +269,42 @@ public class DefaultZSetOperationsTests<K, V> {
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1),
RedisZSetCommands.Limit.limit().count(1).offset(1));
assertEquals(1, tuples.size());
V tuple = tuples.iterator().next();
assertThat(tuple, isEqual(value2));
assertThat(tuples).hasSize(1).startsWith(value2);
}
@Test
public void testAddMultiple() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
Set<TypedTuple<V>> values = new HashSet<>();
values.add(new DefaultTypedTuple<>(value1, 1.7));
values.add(new DefaultTypedTuple<>(value2, 3.2));
values.add(new DefaultTypedTuple<>(value3, 0.8));
assertEquals(Long.valueOf(3), zSetOps.add(key, values));
Set<V> expected = new LinkedHashSet<>();
expected.add(value3);
expected.add(value1);
expected.add(value2);
assertThat(zSetOps.range(key, 0, -1), isEqual(expected));
assertThat(zSetOps.add(key, values)).isEqualTo(Long.valueOf(3));
assertThat(zSetOps.range(key, 0, -1)).containsExactly(value3, value1, value2);
}
@Test
public void testRemove() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
Set<TypedTuple<V>> values = new HashSet<>();
values.add(new DefaultTypedTuple<>(value1, 1.7));
values.add(new DefaultTypedTuple<>(value2, 3.2));
values.add(new DefaultTypedTuple<>(value3, 0.8));
assertEquals(Long.valueOf(3), zSetOps.add(key, values));
assertEquals(Long.valueOf(2), zSetOps.remove(key, value1, value3));
Set<V> expected = new LinkedHashSet<>();
expected.add(value2);
assertThat(zSetOps.range(key, 0, -1), isEqual(expected));
assertThat(zSetOps.add(key, values)).isEqualTo(Long.valueOf(3));
assertThat(zSetOps.remove(key, value1, value3)).isEqualTo(Long.valueOf(2));
assertThat(zSetOps.range(key, 0, -1)).containsOnly(value2);
}
@Test
@@ -315,7 +321,7 @@ public class DefaultZSetOperationsTests<K, V> {
values.add(new DefaultTypedTuple<>(value3, 0.8));
zSetOps.add(key, values);
assertThat(zSetOps.zCard(key), equalTo(3L));
assertThat(zSetOps.zCard(key)).isEqualTo(3L);
}
@Test
@@ -332,7 +338,7 @@ public class DefaultZSetOperationsTests<K, V> {
values.add(new DefaultTypedTuple<>(value3, 0.8));
zSetOps.add(key, values);
assertThat(zSetOps.size(key), equalTo(3L));
assertThat(zSetOps.size(key)).isEqualTo(3L);
}
@Test // DATAREDIS-306
@@ -358,12 +364,12 @@ public class DefaultZSetOperationsTests<K, V> {
int count = 0;
Cursor<TypedTuple<V>> it = zSetOps.scan(key, ScanOptions.scanOptions().count(2).build());
while (it.hasNext()) {
assertThat(it.next(), anyOf(equalTo(tuple1), equalTo(tuple2), equalTo(tuple3)));
assertThat(it.next()).isIn(tuple1, tuple2, tuple3);
count++;
}
it.close();
assertThat(count, equalTo(3));
assertThat(count).isEqualTo(3);
}
@Test // DATAREDIS-746
@@ -381,7 +387,7 @@ public class DefaultZSetOperationsTests<K, V> {
zSetOps.unionAndStore(key1, Collections.singletonList(key2), key1, RedisZSetCommands.Aggregate.MIN);
assertThat(zSetOps.score(key1, value2), closeTo(2.0, 0.1));
assertThat(zSetOps.score(key1, value2)).isCloseTo(2.0, offset(0.1));
}
@Test // DATAREDIS-746
@@ -397,7 +403,7 @@ public class DefaultZSetOperationsTests<K, V> {
zSetOps.unionAndStore(key1, Collections.singletonList(key2), key1, RedisZSetCommands.Aggregate.MAX,
Weights.of(1, 2));
assertThat(zSetOps.score(key1, value1), closeTo(6.0, 0.1));
assertThat(zSetOps.score(key1, value1)).isCloseTo(6.0, offset(0.1));
}
@Test // DATAREDIS-746
@@ -415,7 +421,7 @@ public class DefaultZSetOperationsTests<K, V> {
zSetOps.intersectAndStore(key1, Collections.singletonList(key2), key1, RedisZSetCommands.Aggregate.MIN);
assertThat(zSetOps.score(key1, value2), closeTo(2.0, 0.1));
assertThat(zSetOps.score(key1, value2)).isCloseTo(2.0, offset(0.1));
}
@Test // DATAREDIS-746
@@ -431,6 +437,6 @@ public class DefaultZSetOperationsTests<K, V> {
zSetOps.intersectAndStore(key1, Collections.singletonList(key2), key1, RedisZSetCommands.Aggregate.MAX,
Weights.of(1, 2));
assertThat(zSetOps.score(key1, value1), closeTo(6.0, 0.1));
assertThat(zSetOps.score(key1, value1)).isCloseTo(6.0, offset(0.1));
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.core.IsCollectionContaining.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.nio.charset.Charset;
@@ -30,6 +29,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -127,7 +127,7 @@ public class IndexWriterUnitTests {
ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class);
verify(connectionMock, times(1)).del(captor.capture());
assertThat(captor.getAllValues(), hasItems(indexKey1, indexKey2));
assertThat(captor.getAllValues()).contains(indexKey1, indexKey2);
}
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAREDIS-425

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collection;
@@ -28,6 +28,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
@@ -83,7 +84,7 @@ public class MultithreadedRedisTemplateTests {
}
executor.shutdown();
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
assertThat(executor.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
}
}

View File

@@ -23,6 +23,7 @@ import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.LongObjectFactory;
import org.springframework.data.redis.ObjectFactory;

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Rule;
import org.junit.Test;
@@ -36,32 +35,32 @@ public class RedisCommandUnitTests {
@Test // DATAREDIS-73
public void shouldIdentifyAliasCorrectly() {
assertThat(RedisCommand.CONFIG_SET.isRepresentedBy("setconfig"), equalTo(true));
assertThat(RedisCommand.CONFIG_SET.isRepresentedBy("setconfig")).isTrue();
}
@Test // DATAREDIS-73
public void shouldIdentifyAliasCorrectlyWhenNamePassedInMixedCase() {
assertThat(RedisCommand.CONFIG_SET.isRepresentedBy("SetConfig"), equalTo(true));
assertThat(RedisCommand.CONFIG_SET.isRepresentedBy("SetConfig")).isTrue();
}
@Test // DATAREDIS-73
public void shouldNotThrowExceptionWhenUsingNullKeyForRepresentationCheck() {
assertThat(RedisCommand.CONFIG_SET.isRepresentedBy(null), equalTo(false));
assertThat(RedisCommand.CONFIG_SET.isRepresentedBy(null)).isFalse();
}
@Test // DATAREDIS-73
public void shouldIdentifyAliasCorrectlyViaLookup() {
assertThat(RedisCommand.failsafeCommandLookup("setconfig"), is(RedisCommand.CONFIG_SET));
assertThat(RedisCommand.failsafeCommandLookup("setconfig")).isEqualTo(RedisCommand.CONFIG_SET);
}
@Test // DATAREDIS-73
public void shouldIdentifyAliasCorrectlyWhenNamePassedInMixedCaseViaLookup() {
assertThat(RedisCommand.failsafeCommandLookup("SetConfig"), is(RedisCommand.CONFIG_SET));
assertThat(RedisCommand.failsafeCommandLookup("SetConfig")).isEqualTo(RedisCommand.CONFIG_SET);
}
@Test // DATAREDIS-73
public void shouldReturnUnknownCommandForUnknownCommandString() {
assertThat(RedisCommand.failsafeCommandLookup("strangecommand"), is(RedisCommand.UNKNOWN));
assertThat(RedisCommand.failsafeCommandLookup("strangecommand")).isEqualTo(RedisCommand.UNKNOWN);
}
@Test // DATAREDIS-73, DATAREDIS-972

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
@@ -30,17 +29,16 @@ public class RedisKeyExpiredEventUnitTests {
@Test // DATAREDIS-744
public void shouldReturnKeyspace() {
assertThat(new RedisKeyExpiredEvent<Object>("foo".getBytes(), "").getKeyspace(), is(nullValue()));
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar".getBytes(), "").getKeyspace(), is(equalTo("foo")));
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar:baz".getBytes(), "").getKeyspace(), is(equalTo("foo")));
assertThat(new RedisKeyExpiredEvent<Object>("foo".getBytes(), "").getKeyspace()).isNull();
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar".getBytes(), "").getKeyspace()).isEqualTo("foo");
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar:baz".getBytes(), "").getKeyspace()).isEqualTo("foo");
}
@Test // DATAREDIS-744
public void shouldReturnId() {
assertThat(new RedisKeyExpiredEvent<Object>("foo".getBytes(), "").getId(), is(equalTo("foo".getBytes())));
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar".getBytes(), "").getId(), is(equalTo("bar".getBytes())));
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar:baz".getBytes(), "").getId(),
is(equalTo("bar:baz".getBytes())));
assertThat(new RedisKeyExpiredEvent<Object>("foo".getBytes(), "").getId()).isEqualTo("foo".getBytes());
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar".getBytes(), "").getId()).isEqualTo("bar".getBytes());
assertThat(new RedisKeyExpiredEvent<Object>("foo:bar:baz".getBytes(), "").getId()).isEqualTo("bar:baz".getBytes());
}
}

View File

@@ -15,8 +15,8 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.data.Offset.offset;
import static org.junit.Assume.*;
import java.util.Arrays;
@@ -37,6 +37,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Reference;
@@ -140,10 +141,10 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
assertThat(template.keys("persons*"), hasItems("persons", "persons:1"));
assertThat(template.opsForSet().size("persons"), is(1L));
assertThat(template.opsForSet().members("persons"), hasItems("1"));
assertThat(template.opsForHash().entries("persons:1").size(), is(2));
assertThat(template.keys("persons*")).contains("persons", "persons:1");
assertThat(template.opsForSet().size("persons")).isEqualTo(1L);
assertThat(template.opsForSet().members("persons")).contains("1");
assertThat(template.opsForHash().entries("persons:1").size()).isEqualTo(2);
}
@Test // DATAREDIS-744
@@ -154,10 +155,10 @@ public class RedisKeyValueAdapterTests {
adapter.put("1:a", rand, "persons");
assertThat(template.keys("persons*"), hasItems("persons", "persons:1:a"));
assertThat(template.opsForSet().size("persons"), is(1L));
assertThat(template.opsForSet().members("persons"), hasItems("1:a"));
assertThat(template.opsForHash().entries("persons:1:a").size(), is(2));
assertThat(template.keys("persons*")).contains("persons", "persons:1:a");
assertThat(template.opsForSet().size("persons")).isEqualTo(1L);
assertThat(template.opsForSet().members("persons")).contains("1:a");
assertThat(template.opsForHash().entries("persons:1:a").size()).isEqualTo(2);
}
@Test // DATAREDIS-425
@@ -168,8 +169,8 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
assertThat(template.keys("persons*"), hasItem("persons:firstname:rand"));
assertThat(template.opsForSet().members("persons:firstname:rand"), hasItems("1"));
assertThat(template.keys("persons*")).contains("persons:firstname:rand");
assertThat(template.opsForSet().members("persons:firstname:rand")).contains("1");
}
@Test // DATAREDIS-744
@@ -180,8 +181,8 @@ public class RedisKeyValueAdapterTests {
adapter.put("1:a", rand, "persons");
assertThat(template.keys("persons*"), hasItem("persons:firstname:rand"));
assertThat(template.opsForSet().members("persons:firstname:rand"), hasItems("1:a"));
assertThat(template.keys("persons*")).contains("persons:firstname:rand");
assertThat(template.opsForSet().members("persons:firstname:rand")).contains("1:a");
}
@Test // DATAREDIS-425
@@ -193,8 +194,8 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
assertThat(template.keys("persons*"), hasItems("persons", "persons:1"));
assertThat(template.opsForHash().entries("persons:1").size(), is(2));
assertThat(template.keys("persons*")).contains("persons", "persons:1");
assertThat(template.opsForHash().entries("persons:1").size()).isEqualTo(2);
}
@Test // DATAREDIS-425
@@ -206,8 +207,8 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
assertThat(template.keys("persons*"), hasItem("persons:address.country:Andor"));
assertThat(template.opsForSet().members("persons:address.country:Andor"), hasItems("1"));
assertThat(template.keys("persons*")).contains("persons:address.country:Andor");
assertThat(template.opsForSet().members("persons:address.country:Andor")).contains("1");
}
@Test // DATAREDIS-425
@@ -220,8 +221,8 @@ public class RedisKeyValueAdapterTests {
Object loaded = adapter.get("load-1", "persons");
assertThat(loaded, instanceOf(Person.class));
assertThat(((Person) loaded).age, is(24));
assertThat(loaded).isInstanceOf(Person.class);
assertThat(((Person) loaded).age).isEqualTo(24);
}
@Test // DATAREDIS-744
@@ -234,8 +235,8 @@ public class RedisKeyValueAdapterTests {
Object loaded = adapter.get("load-1:a", "persons");
assertThat(loaded, instanceOf(Person.class));
assertThat(((Person) loaded).age, is(24));
assertThat(loaded).isInstanceOf(Person.class);
assertThat(((Person) loaded).age).isEqualTo(24);
}
@Test // DATAREDIS-425
@@ -248,8 +249,8 @@ public class RedisKeyValueAdapterTests {
Object loaded = adapter.get("load-1", "persons");
assertThat(loaded, instanceOf(Person.class));
assertThat(((Person) loaded).address.country, is("Andor"));
assertThat(loaded).isInstanceOf(Person.class);
assertThat(((Person) loaded).address.country).isEqualTo("Andor");
}
@Test // DATAREDIS-425
@@ -262,7 +263,7 @@ public class RedisKeyValueAdapterTests {
template.opsForSet().add("persons", "1", "2", "3");
assertThat(adapter.count("persons"), is(3L));
assertThat(adapter.count("persons")).isEqualTo(3L);
}
@Test // DATAREDIS-425
@@ -276,8 +277,8 @@ public class RedisKeyValueAdapterTests {
adapter.delete("1", "persons");
assertThat(template.opsForSet().members("persons"), not(hasItem("1")));
assertThat(template.hasKey("persons:1"), is(false));
assertThat(template.opsForSet().members("persons")).doesNotContain("1");
assertThat(template.hasKey("persons:1")).isFalse();
}
@Test // DATAREDIS-425
@@ -294,7 +295,7 @@ public class RedisKeyValueAdapterTests {
adapter.delete("1", "persons");
assertThat(template.opsForSet().members("persons:firstname:rand"), not(hasItem("1")));
assertThat(template.opsForSet().members("persons:firstname:rand")).doesNotContain("1");
}
@Test // DATAREDIS-425
@@ -319,10 +320,11 @@ public class RedisKeyValueAdapterTests {
waitUntilKeyIsGone(template, "persons:1:phantom");
waitUntilKeyIsGone(template, "persons:firstname:rand");
assertThat(template.hasKey("persons:1"), is(false));
assertThat(template.hasKey("persons:firstname:rand"), is(false));
assertThat(template.hasKey("persons:1:idx"), is(false));
assertThat(template.opsForSet().members("persons"), not(hasItem("1")));
assertThat(template.hasKey("persons:1")).isFalse();
assertThat(template.hasKey("persons:firstname:rand")).isFalse();
assertThat(template.hasKey("persons:1:idx")).isFalse();
assertThat(template.opsForSet().members("persons")).doesNotContain("1");
;
}
@Test // DATAREDIS-744
@@ -347,10 +349,10 @@ public class RedisKeyValueAdapterTests {
waitUntilKeyIsGone(template, "persons:1:b:phantom");
waitUntilKeyIsGone(template, "persons:firstname:rand");
assertThat(template.hasKey("persons:1"), is(false));
assertThat(template.hasKey("persons:firstname:rand"), is(false));
assertThat(template.hasKey("persons:1:b:idx"), is(false));
assertThat(template.opsForSet().members("persons"), not(hasItem("1:b")));
assertThat(template.hasKey("persons:1")).isFalse();
assertThat(template.hasKey("persons:firstname:rand")).isFalse();
assertThat(template.hasKey("persons:1:b:idx")).isFalse();
assertThat(template.opsForSet().members("persons")).doesNotContain("1:b");
}
@Test // DATAREDIS-589
@@ -374,10 +376,10 @@ public class RedisKeyValueAdapterTests {
waitUntilKeyIsGone(template, "1");
assertThat(template.hasKey("persons:1"), is(true));
assertThat(template.hasKey("persons:firstname:rand"), is(true));
assertThat(template.hasKey("persons:1:idx"), is(true));
assertThat(template.opsForSet().members("persons"), hasItem("1"));
assertThat(template.hasKey("persons:1")).isTrue();
assertThat(template.hasKey("persons:firstname:rand")).isTrue();
assertThat(template.hasKey("persons:1:idx")).isTrue();
assertThat(template.opsForSet().members("persons")).contains("1");
}
@Test // DATAREDIS-512
@@ -389,31 +391,31 @@ public class RedisKeyValueAdapterTests {
adapter.put("rand", rand, "persons");
assertThat(template.hasKey("persons:firstname:rand"), is(true));
assertThat(template.hasKey("persons:rand:idx"), is(true));
assertThat(template.opsForSet().isMember("persons:rand:idx", "persons:firstname:rand"), is(true));
assertThat(template.hasKey("persons:firstname:rand")).isTrue();
assertThat(template.hasKey("persons:rand:idx")).isTrue();
assertThat(template.opsForSet().isMember("persons:rand:idx", "persons:firstname:rand")).isTrue();
Person mat = new Person();
mat.age = 22;
mat.firstname = "mat";
adapter.put("mat", mat, "persons");
assertThat(template.hasKey("persons:firstname:rand"), is(true));
assertThat(template.hasKey("persons:firstname:mat"), is(true));
assertThat(template.hasKey("persons:rand:idx"), is(true));
assertThat(template.hasKey("persons:mat:idx"), is(true));
assertThat(template.opsForSet().isMember("persons:rand:idx", "persons:firstname:rand"), is(true));
assertThat(template.opsForSet().isMember("persons:mat:idx", "persons:firstname:mat"), is(true));
assertThat(template.hasKey("persons:firstname:rand")).isTrue();
assertThat(template.hasKey("persons:firstname:mat")).isTrue();
assertThat(template.hasKey("persons:rand:idx")).isTrue();
assertThat(template.hasKey("persons:mat:idx")).isTrue();
assertThat(template.opsForSet().isMember("persons:rand:idx", "persons:firstname:rand")).isTrue();
assertThat(template.opsForSet().isMember("persons:mat:idx", "persons:firstname:mat")).isTrue();
rand.firstname = "frodo";
adapter.put("rand", rand, "persons");
assertThat(template.hasKey("persons:firstname:rand"), is(false));
assertThat(template.hasKey("persons:firstname:mat"), is(true));
assertThat(template.hasKey("persons:firstname:frodo"), is(true));
assertThat(template.hasKey("persons:rand:idx"), is(true));
assertThat(template.opsForSet().isMember("persons:rand:idx", "persons:firstname:frodo"), is(true));
assertThat(template.opsForSet().isMember("persons:mat:idx", "persons:firstname:mat"), is(true));
assertThat(template.hasKey("persons:firstname:rand")).isFalse();
assertThat(template.hasKey("persons:firstname:mat")).isTrue();
assertThat(template.hasKey("persons:firstname:frodo")).isTrue();
assertThat(template.hasKey("persons:rand:idx")).isTrue();
assertThat(template.opsForSet().isMember("persons:rand:idx", "persons:firstname:frodo")).isTrue();
assertThat(template.opsForSet().isMember("persons:mat:idx", "persons:firstname:mat")).isTrue();
}
@Test // DATAREDIS-471
@@ -424,15 +426,15 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
assertThat(template.hasKey("persons:firstname:rand"), is(true));
assertThat(template.hasKey("persons:firstname:rand")).isTrue();
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
.set("firstname", "mat");
adapter.update(update);
assertThat(template.hasKey("persons:firstname:rand"), is(false));
assertThat(template.hasKey("persons:firstname:mat"), is(true));
assertThat(template.hasKey("persons:firstname:rand")).isFalse();
assertThat(template.hasKey("persons:firstname:mat")).isTrue();
}
@Test // DATAREDIS-744
@@ -443,15 +445,15 @@ public class RedisKeyValueAdapterTests {
adapter.put("1:a", rand, "persons");
assertThat(template.hasKey("persons:firstname:rand"), is(true));
assertThat(template.hasKey("persons:firstname:rand")).isTrue();
PartialUpdate<Person> update = new PartialUpdate<>("1:a", Person.class) //
.set("firstname", "mat");
adapter.update(update);
assertThat(template.hasKey("persons:firstname:rand"), is(false));
assertThat(template.hasKey("persons:firstname:mat"), is(true));
assertThat(template.hasKey("persons:firstname:rand")).isFalse();
assertThat(template.hasKey("persons:firstname:mat")).isTrue();
}
@Test // DATAREDIS-471
@@ -463,7 +465,7 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
assertThat(template.hasKey("persons:address.country:andor"), is(true));
assertThat(template.hasKey("persons:address.country:andor")).isTrue();
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class);
Address addressUpdate = new Address();
@@ -473,8 +475,8 @@ public class RedisKeyValueAdapterTests {
adapter.update(update);
assertThat(template.hasKey("persons:address.country:andor"), is(false));
assertThat(template.hasKey("persons:address.country:tear"), is(true));
assertThat(template.hasKey("persons:address.country:andor")).isFalse();
assertThat(template.hasKey("persons:address.country:tear")).isTrue();
}
@Test // DATAREDIS-471
@@ -486,15 +488,15 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
assertThat(template.hasKey("persons:address.country:andor"), is(true));
assertThat(template.hasKey("persons:address.country:andor")).isTrue();
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.set("address.country", "tear");
adapter.update(update);
assertThat(template.hasKey("persons:address.country:andor"), is(false));
assertThat(template.hasKey("persons:address.country:tear"), is(true));
assertThat(template.hasKey("persons:address.country:andor")).isFalse();
assertThat(template.hasKey("persons:address.country:tear")).isTrue();
}
@Test // DATAREDIS-471
@@ -512,9 +514,9 @@ public class RedisKeyValueAdapterTests {
adapter.update(update);
assertThat(template.opsForHash().hasKey("persons:1", "address.country"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "address.city"), is(false));
assertThat(template.opsForSet().isMember("persons:address.country:andor", "1"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "address.country")).isFalse();
assertThat(template.opsForHash().hasKey("persons:1", "address.city")).isFalse();
assertThat(template.opsForSet().isMember("persons:address.country:andor", "1")).isFalse();
}
@Test // DATAREDIS-471
@@ -530,8 +532,8 @@ public class RedisKeyValueAdapterTests {
adapter.update(update);
assertThat(template.opsForHash().hasKey("persons:1", "nicknames.[0]"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "nicknames.[1]"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "nicknames.[0]")).isFalse();
assertThat(template.opsForHash().hasKey("persons:1", "nicknames.[1]")).isFalse();
}
@Test // DATAREDIS-471
@@ -555,10 +557,10 @@ public class RedisKeyValueAdapterTests {
adapter.update(update);
assertThat(template.opsForHash().hasKey("persons:1", "coworkers.[0].firstname"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "coworkers.[0].nicknames.[0]"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "coworkers.[1].firstname"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "coworkers.[1].nicknames.[0]"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "coworkers.[0].firstname")).isFalse();
assertThat(template.opsForHash().hasKey("persons:1", "coworkers.[0].nicknames.[0]")).isFalse();
assertThat(template.opsForHash().hasKey("persons:1", "coworkers.[1].firstname")).isFalse();
assertThat(template.opsForHash().hasKey("persons:1", "coworkers.[1].nicknames.[0]")).isFalse();
}
@Test // DATAREDIS-471
@@ -574,7 +576,7 @@ public class RedisKeyValueAdapterTests {
adapter.update(update);
assertThat(template.opsForHash().hasKey("persons:1", "physicalAttributes.[eye-color]"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "physicalAttributes.[eye-color]")).isFalse();
}
@Test // DATAREDIS-471
@@ -593,7 +595,7 @@ public class RedisKeyValueAdapterTests {
adapter.update(update);
assertThat(template.opsForHash().hasKey("persons:1", "relatives.[stepfather].firstname"), is(false));
assertThat(template.opsForHash().hasKey("persons:1", "relatives.[stepfather].firstname")).isFalse();
}
@Test // DATAREDIS-533
@@ -607,7 +609,7 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", tam, "persons");
assertThat(template.opsForZSet().score("persons:address:location", "1"), is(notNullValue()));
assertThat(template.opsForZSet().score("persons:address:location", "1")).isNotNull();
}
@Test // DATAREDIS-533
@@ -623,7 +625,7 @@ public class RedisKeyValueAdapterTests {
adapter.delete("1", "persons", Person.class);
assertThat(template.opsForZSet().score("persons:address:location", "1"), is(nullValue()));
assertThat(template.opsForZSet().score("persons:address:location", "1")).isNull();
}
@Test // DATAREDIS-533
@@ -642,7 +644,7 @@ public class RedisKeyValueAdapterTests {
adapter.update(update);
assertThat(template.opsForZSet().score("persons:address:location", "1"), is(nullValue()));
assertThat(template.opsForZSet().score("persons:address:location", "1")).isNull();
}
@Test // DATAREDIS-533, DATAREDIS-614
@@ -661,11 +663,11 @@ public class RedisKeyValueAdapterTests {
adapter.update(update);
assertThat(template.opsForZSet().score("persons:address:location", "1"), is(notNullValue()));
assertThat(template.opsForZSet().score("persons:address:location", "1")).isNotNull();
Point updatedLocation = template.opsForGeo().position("persons:address:location", "1").iterator().next();
assertThat(updatedLocation.getX(), is(closeTo(17D, 0.005)));
assertThat(updatedLocation.getY(), is(closeTo(18D, 0.005)));
assertThat(updatedLocation.getX()).isCloseTo(17D, offset(0.005));
assertThat(updatedLocation.getY()).isCloseTo(18D, offset(0.005));
}
/**

View File

@@ -16,10 +16,8 @@
package org.springframework.data.redis.core;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.any;
import static org.springframework.test.util.ReflectionTestUtils.*;
import java.util.Arrays;
@@ -35,6 +33,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
@@ -138,7 +137,7 @@ public class RedisKeyValueAdapterUnitTests {
KeyExpirationEventMessageListener listener = ((AtomicReference<KeyExpirationEventMessageListener>) getField(adapter,
"expirationListener")).get();
assertThat(listener, notNullValue());
assertThat(listener).isNotNull();
}
@Test // DATAREDIS-491
@@ -152,17 +151,17 @@ public class RedisKeyValueAdapterUnitTests {
KeyExpirationEventMessageListener listener = ((AtomicReference<KeyExpirationEventMessageListener>) getField(adapter,
"expirationListener")).get();
assertThat(listener, nullValue());
assertThat(listener).isNull();
adapter.put("should-NOT-start-listener", new WithoutTimeToLive(), "keyspace");
listener = ((AtomicReference<KeyExpirationEventMessageListener>) getField(adapter, "expirationListener")).get();
assertThat(listener, nullValue());
assertThat(listener).isNull();
adapter.put("should-start-listener", new WithTimeToLive(), "keyspace");
listener = ((AtomicReference<KeyExpirationEventMessageListener>) getField(adapter, "expirationListener")).get();
assertThat(listener, notNullValue());
assertThat(listener).isNotNull();
}
@Test // DATAREDIS-491
@@ -175,17 +174,17 @@ public class RedisKeyValueAdapterUnitTests {
KeyExpirationEventMessageListener listener = ((AtomicReference<KeyExpirationEventMessageListener>) getField(adapter,
"expirationListener")).get();
assertThat(listener, nullValue());
assertThat(listener).isNull();
adapter.put("should-NOT-start-listener", new WithoutTimeToLive(), "keyspace");
listener = ((AtomicReference<KeyExpirationEventMessageListener>) getField(adapter, "expirationListener")).get();
assertThat(listener, nullValue());
assertThat(listener).isNull();
adapter.put("should-start-listener", new WithTimeToLive(), "keyspace");
listener = ((AtomicReference<KeyExpirationEventMessageListener>) getField(adapter, "expirationListener")).get();
assertThat(listener, nullValue());
assertThat(listener).isNull();
}
static class WithoutTimeToLive {

View File

@@ -15,9 +15,8 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.data.Offset.offset;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -39,6 +38,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -124,7 +124,7 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.exists(("template-test-person:" + rand.id).getBytes()), is(true));
assertThat(connection.exists(("template-test-person:" + rand.id).getBytes())).isTrue();
return null;
});
}
@@ -143,8 +143,8 @@ public class RedisKeyValueTemplateTests {
List<Person> result = template.find(connection -> mat.id.getBytes(), Person.class);
assertThat(result.size(), is(1));
assertThat(result, hasItems(mat));
assertThat(result.size()).isEqualTo(1);
assertThat(result).contains(mat);
}
@Test // DATAREDIS-425
@@ -162,8 +162,8 @@ public class RedisKeyValueTemplateTests {
List<Person> result = template.find(connection -> Arrays.asList(rand.id.getBytes(), mat.id.getBytes()),
Person.class);
assertThat(result.size(), is(2));
assertThat(result, hasItems(rand, mat));
assertThat(result.size()).isEqualTo(2);
assertThat(result).contains(rand, mat);
}
@Test // DATAREDIS-425
@@ -180,7 +180,7 @@ public class RedisKeyValueTemplateTests {
List<Person> result = template.find(connection -> null, Person.class);
assertThat(result.size(), is(0));
assertThat(result.size()).isEqualTo(0);
}
@Test // DATAREDIS-471
@@ -199,14 +199,13 @@ public class RedisKeyValueTemplateTests {
template.insert(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, "rand", "al-thor")))));
assertThat(template.findById(rand.id, Person.class)).isEqualTo(Optional.of(new Person(rand.id, "rand", "al-thor")));
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.hGet(("template-test-person:" + rand.id).getBytes(), "firstname".getBytes()),
is(equalTo("rand".getBytes())));
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes()), is(true));
assertThat(connection.sIsMember("template-test-person:lastname:al-thor".getBytes(), rand.id.getBytes()),
is(true));
assertThat(connection.hGet(("template-test-person:" + rand.id).getBytes(), "firstname".getBytes()))
.isEqualTo("rand".getBytes());
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes())).isTrue();
assertThat(connection.sIsMember("template-test-person:lastname:al-thor".getBytes(), rand.id.getBytes())).isTrue();
return null;
});
@@ -217,12 +216,12 @@ public class RedisKeyValueTemplateTests {
template.update(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, "frodo", "al-thor")))));
assertThat(template.findById(rand.id, Person.class))
.isEqualTo(Optional.of(new Person(rand.id, "frodo", "al-thor")));
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes()), is(true));
assertThat(connection.sIsMember("template-test-person:lastname:al-thor".getBytes(), rand.id.getBytes()),
is(true));
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes())).isTrue();
assertThat(connection.sIsMember("template-test-person:lastname:al-thor".getBytes(), rand.id.getBytes())).isTrue();
return null;
});
@@ -234,13 +233,12 @@ public class RedisKeyValueTemplateTests {
template.doPartialUpdate(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, null, "baggins")))));
assertThat(template.findById(rand.id, Person.class)).isEqualTo(Optional.of(new Person(rand.id, null, "baggins")));
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes()), is(false));
assertThat(connection.exists("template-test-person:lastname:baggins".getBytes()), is(true));
assertThat(connection.sIsMember("template-test-person:lastname:baggins".getBytes(), rand.id.getBytes()),
is(true));
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes())).isFalse();
assertThat(connection.exists("template-test-person:lastname:baggins".getBytes())).isTrue();
assertThat(connection.sIsMember("template-test-person:lastname:baggins".getBytes(), rand.id.getBytes())).isTrue();
return null;
});
@@ -252,10 +250,10 @@ public class RedisKeyValueTemplateTests {
template.doPartialUpdate(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, null, null)))));
assertThat(template.findById(rand.id, Person.class)).isEqualTo(Optional.of(new Person(rand.id, null, null)));
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.keys("template-test-person:lastname:*".getBytes()).size(), is(0));
assertThat(connection.keys("template-test-person:lastname:*".getBytes()).size()).isEqualTo(0);
return null;
});
}
@@ -275,10 +273,10 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "stringValue".getBytes()),
is("hooya!".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "stringValue".getBytes()))
.isEqualTo("hooya!".getBytes());
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap._class".getBytes()), is(false));
"simpleTypedMap._class".getBytes())).isFalse();
return null;
});
}
@@ -310,15 +308,15 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "complexValue.name".getBytes()),
is("Portal Stone".getBytes()));
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "complexValue.name".getBytes()))
.isEqualTo("Portal Stone".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexValue.dimension.height".getBytes()), is("350".getBytes()));
"complexValue.dimension.height".getBytes())).isEqualTo("350".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexValue.dimension.width".getBytes()), is("70".getBytes()));
"complexValue.dimension.width".getBytes())).isEqualTo("70".getBytes());
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexValue.dimension.length".getBytes()), is(false));
"complexValue.dimension.length".getBytes())).isFalse();
return null;
});
}
@@ -350,17 +348,17 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "objectValue._class".getBytes()),
is(Item.class.getName().getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "objectValue.name".getBytes()),
is("Portal Stone".getBytes()));
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "objectValue._class".getBytes()))
.isEqualTo(Item.class.getName().getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "objectValue.name".getBytes()))
.isEqualTo("Portal Stone".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"objectValue.dimension.height".getBytes()), is("350".getBytes()));
"objectValue.dimension.height".getBytes())).isEqualTo("350".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"objectValue.dimension.width".getBytes()), is("70".getBytes()));
"objectValue.dimension.width".getBytes())).isEqualTo("70".getBytes());
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "objectValue".getBytes()),
is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "objectValue".getBytes()))
.isFalse();
return null;
});
}
@@ -384,14 +382,14 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedMap.[spring]".getBytes()),
is("data".getBytes()));
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedMap.[spring]".getBytes()))
.isEqualTo("data".getBytes());
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[key-1]".getBytes()), is(false));
"simpleTypedMap.[key-1]".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[key-2]".getBytes()), is(false));
"simpleTypedMap.[key-2]".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[key-2]".getBytes()), is(false));
"simpleTypedMap.[key-2]".getBytes())).isFalse();
return null;
});
}
@@ -432,25 +430,25 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[horn-of-valere].name".getBytes()), is("Horn of Valere".getBytes()));
"complexTypedMap.[horn-of-valere].name".getBytes())).isEqualTo("Horn of Valere".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[horn-of-valere].dimension.height".getBytes()), is("70".getBytes()));
"complexTypedMap.[horn-of-valere].dimension.height".getBytes())).isEqualTo("70".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[horn-of-valere].dimension.width".getBytes()), is("25".getBytes()));
"complexTypedMap.[horn-of-valere].dimension.width".getBytes())).isEqualTo("25".getBytes());
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[callandor].name".getBytes()), is(false));
"complexTypedMap.[callandor].name".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[callandor].dimension.height".getBytes()), is(false));
"complexTypedMap.[callandor].dimension.height".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[callandor].dimension.width".getBytes()), is(false));
"complexTypedMap.[callandor].dimension.width".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[portal-stone].name".getBytes()), is(false));
"complexTypedMap.[portal-stone].name".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[portal-stone].dimension.height".getBytes()), is(false));
"complexTypedMap.[portal-stone].dimension.height".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[portal-stone].dimension.width".getBytes()), is(false));
"complexTypedMap.[portal-stone].dimension.width".getBytes())).isFalse();
return null;
});
}
@@ -497,36 +495,36 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[horn-of-valere].name".getBytes()), is("Horn of Valere".getBytes()));
"untypedMap.[horn-of-valere].name".getBytes())).isEqualTo("Horn of Valere".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[horn-of-valere].dimension.height".getBytes()), is("70".getBytes()));
"untypedMap.[horn-of-valere].dimension.height".getBytes())).isEqualTo("70".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[horn-of-valere].dimension.width".getBytes()), is("25".getBytes()));
"untypedMap.[horn-of-valere].dimension.width".getBytes())).isEqualTo("25".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[spring]._class".getBytes()), is("java.lang.String".getBytes()));
"untypedMap.[spring]._class".getBytes())).isEqualTo("java.lang.String".getBytes());
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedMap.[spring]".getBytes()),
is("data".getBytes()));
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedMap.[spring]".getBytes()))
.isEqualTo("data".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[some-number]._class".getBytes()), is("java.lang.Long".getBytes()));
"untypedMap.[some-number]._class".getBytes())).isEqualTo("java.lang.Long".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[some-number]".getBytes()), is("100".getBytes()));
"untypedMap.[some-number]".getBytes())).isEqualTo("100".getBytes());
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[callandor].name".getBytes()), is(false));
"untypedMap.[callandor].name".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[callandor].dimension.height".getBytes()), is(false));
"untypedMap.[callandor].dimension.height".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[callandor].dimension.width".getBytes()), is(false));
"untypedMap.[callandor].dimension.width".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[portal-stone].name".getBytes()), is(false));
"untypedMap.[portal-stone].name".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[portal-stone].dimension.height".getBytes()), is(false));
"untypedMap.[portal-stone].dimension.height".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[portal-stone].dimension.width".getBytes()), is(false));
"untypedMap.[portal-stone].dimension.width".getBytes())).isFalse();
return null;
});
}
@@ -550,17 +548,17 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[0]".getBytes()),
is("spring".getBytes()));
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[0]".getBytes()))
.isEqualTo("spring".getBytes());
assertThat(
connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[1]".getBytes()),
is(false));
connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[1]".getBytes()))
.isFalse();
assertThat(
connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[2]".getBytes()),
is(false));
connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[2]".getBytes()))
.isFalse();
assertThat(
connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[3]".getBytes()),
is(false));
connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[3]".getBytes()))
.isFalse();
return null;
});
}
@@ -601,18 +599,18 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedList.[0].name".getBytes()), is("Horn of Valere".getBytes()));
"complexTypedList.[0].name".getBytes())).isEqualTo("Horn of Valere".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedList.[0].dimension.height".getBytes()), is("70".getBytes()));
"complexTypedList.[0].dimension.height".getBytes())).isEqualTo("70".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedList.[0].dimension.width".getBytes()), is("25".getBytes()));
"complexTypedList.[0].dimension.width".getBytes())).isEqualTo("25".getBytes());
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[1].name".getBytes()), is(false));
"complexTypedMap.[1].name".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[1].dimension.height".getBytes()), is(false));
"complexTypedMap.[1].dimension.height".getBytes())).isFalse();
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[1].dimension.width".getBytes()), is(false));
"complexTypedMap.[1].dimension.width".getBytes())).isFalse();
return null;
});
}
@@ -659,24 +657,24 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[0]._class".getBytes()),
is("java.lang.String".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[0]".getBytes()),
is("spring".getBytes()));
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[0]._class".getBytes()))
.isEqualTo("java.lang.String".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[0]".getBytes()))
.isEqualTo("spring".getBytes());
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[1].name".getBytes()),
is("Horn of Valere".getBytes()));
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[1].name".getBytes()))
.isEqualTo("Horn of Valere".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedList.[1].dimension.height".getBytes()), is("70".getBytes()));
"untypedList.[1].dimension.height".getBytes())).isEqualTo("70".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedList.[1].dimension.width".getBytes()), is("25".getBytes()));
"untypedList.[1].dimension.width".getBytes())).isEqualTo("25".getBytes());
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[2]._class".getBytes()),
is("java.lang.Long".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[2]".getBytes()),
is("100".getBytes()));
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[2]._class".getBytes()))
.isEqualTo("java.lang.Long".getBytes());
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[2]".getBytes()))
.isEqualTo("100".getBytes());
return null;
});
@@ -701,11 +699,11 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.hGet(("template-test-person:" + rand.id).getBytes(), "lastname".getBytes()),
is(equalTo("doe".getBytes())));
assertThat(connection.exists("template-test-person:email:rand@twof.com".getBytes()), is(true));
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes()), is(false));
assertThat(connection.sIsMember("template-test-person:lastname:doe".getBytes(), rand.id.getBytes()), is(true));
assertThat(connection.hGet(("template-test-person:" + rand.id).getBytes(), "lastname".getBytes()))
.isEqualTo("doe".getBytes());
assertThat(connection.exists("template-test-person:email:rand@twof.com".getBytes())).isTrue();
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes())).isFalse();
assertThat(connection.sIsMember("template-test-person:lastname:doe".getBytes(), rand.id.getBytes())).isTrue();
return null;
});
}
@@ -722,8 +720,8 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.exists("template-test-person:email:rand@twof.com".getBytes()), is(true));
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes()), is(true));
assertThat(connection.exists("template-test-person:email:rand@twof.com".getBytes())).isTrue();
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes())).isTrue();
return null;
});
@@ -733,8 +731,8 @@ public class RedisKeyValueTemplateTests {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
assertThat(connection.exists("template-test-person:email:rand@twof.com".getBytes()), is(true));
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes()), is(false));
assertThat(connection.exists("template-test-person:email:rand@twof.com".getBytes())).isTrue();
assertThat(connection.exists("template-test-person:lastname:al-thor".getBytes())).isFalse();
return null;
});
}
@@ -752,8 +750,8 @@ public class RedisKeyValueTemplateTests {
Thread.sleep(1100);
Optional<WithTtl> target = template.findById(source.id, WithTtl.class);
assertThat(target.get().ttl, is(notNullValue()));
assertThat(target.get().ttl.doubleValue(), is(closeTo(3D, 1D)));
assertThat(target.get().ttl).isNotNull();
assertThat(target.get().ttl.doubleValue()).isCloseTo(3D, offset(1D));
}
@Test // DATAREDIS-523
@@ -769,7 +767,7 @@ public class RedisKeyValueTemplateTests {
Thread.sleep(1100);
Optional<WithPrimitiveTtl> target = template.findById(source.id, WithPrimitiveTtl.class);
assertThat((double) target.get().ttl, is(closeTo(3D, 1D)));
assertThat((double) target.get().ttl).isCloseTo(3D, offset(1D));
}
@Test // DATAREDIS-523
@@ -786,8 +784,8 @@ public class RedisKeyValueTemplateTests {
WithTtl target = template.findAll(WithTtl.class).iterator().next();
assertThat(target.ttl, is(notNullValue()));
assertThat(target.ttl.doubleValue(), is(closeTo(3D, 1D)));
assertThat(target.ttl).isNotNull();
assertThat(target.ttl.doubleValue()).isCloseTo(3D, offset(1D));
}
@Test // DATAREDIS-523
@@ -804,7 +802,7 @@ public class RedisKeyValueTemplateTests {
(RedisCallback<Boolean>) connection -> connection.persist((WithTtl.class.getName() + ":ttl-1").getBytes()));
Optional<WithTtl> target = template.findById(source.id, WithTtl.class);
assertThat(target.get().ttl, is(-1L));
assertThat(target.get().ttl).isEqualTo(-1L);
}
@Test // DATAREDIS-849
@@ -814,8 +812,8 @@ public class RedisKeyValueTemplateTests {
ImmutableObject inserted = template.insert(source);
assertThat(source.id, is(nullValue()));
assertThat(inserted.id, is(notNullValue()));
assertThat(source.id).isNull();
assertThat(inserted.id).isNotNull();
}
@Test // DATAREDIS-849
@@ -826,12 +824,12 @@ public class RedisKeyValueTemplateTests {
Optional<ImmutableObject> loaded = template.findById(inserted.id, ImmutableObject.class);
assertThat(loaded.isPresent(), is(true));
assertThat(loaded.isPresent()).isTrue();
ImmutableObject immutableObject = loaded.get();
assertThat(immutableObject.id, is(inserted.id));
assertThat(immutableObject.ttl, is(notNullValue()));
assertThat(immutableObject.value, is(inserted.value));
assertThat(immutableObject.id).isEqualTo(inserted.id);
assertThat(immutableObject.ttl).isNotNull();
assertThat(immutableObject.value).isEqualTo(inserted.value);
}
@EqualsAndHashCode

View File

@@ -15,22 +15,21 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import org.hamcrest.core.IsNot;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -51,6 +50,7 @@ import org.springframework.data.redis.serializer.GenericToStringSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.util.CollectionAwareComparator;
/**
* Integration test of {@link RedisTemplate}
@@ -100,28 +100,28 @@ public class RedisTemplateTests<K, V> {
@Test
public void testDumpAndRestoreNoTtl() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
assumeThat(RedisTestProfileValueSource.matches("redisVersion", "2.6")).isTrue();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
byte[] serializedValue = redisTemplate.dump(key1);
assertNotNull(serializedValue);
assertThat(serializedValue).isNotNull();
redisTemplate.delete(key1);
redisTemplate.restore(key1, serializedValue, 0, TimeUnit.SECONDS);
assertThat(redisTemplate.boundValueOps(key1).get(), isEqual(value1));
assertThat(redisTemplate.boundValueOps(key1).get()).isEqualTo(value1);
}
@Test
public void testRestoreTtl() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
byte[] serializedValue = redisTemplate.dump(key1);
assertNotNull(serializedValue);
assertThat(serializedValue).isNotNull();
redisTemplate.delete(key1);
redisTemplate.restore(key1, serializedValue, 200, TimeUnit.MILLISECONDS);
assertThat(redisTemplate.boundValueOps(key1).get(), isEqual(value1));
assertThat(redisTemplate.boundValueOps(key1).get()).isEqualTo(value1);
waitFor(() -> (!redisTemplate.hasKey(key1)), 400);
}
@@ -133,7 +133,7 @@ public class RedisTemplateTests<K, V> {
assumeTrue(key1 instanceof String || key1 instanceof byte[]);
redisTemplate.opsForValue().set(key1, value1);
K keyPattern = key1 instanceof String ? (K) "*" : (K) "*".getBytes();
assertNotNull(redisTemplate.keys(keyPattern));
assertThat(redisTemplate.keys(keyPattern)).isNotNull();
}
@SuppressWarnings("rawtypes")
@@ -152,19 +152,19 @@ public class RedisTemplateTests<K, V> {
stringConn.set("test", "it");
return stringConn.get("test");
});
assertEquals(value, "it");
assertThat("it").isEqualTo(value);
}
@Test
public void testExec() {
final K key1 = keyFactory.instance();
final V value1 = valueFactory.instance();
final K listKey = keyFactory.instance();
final V listValue = valueFactory.instance();
final K setKey = keyFactory.instance();
final V setValue = valueFactory.instance();
final K zsetKey = keyFactory.instance();
final V zsetValue = valueFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
K listKey = keyFactory.instance();
V listValue = valueFactory.instance();
K setKey = keyFactory.instance();
V setValue = valueFactory.instance();
K zsetKey = keyFactory.instance();
V zsetValue = valueFactory.instance();
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Object> execute(RedisOperations operations) throws DataAccessException {
@@ -172,11 +172,11 @@ public class RedisTemplateTests<K, V> {
operations.opsForValue().set(key1, value1);
operations.opsForValue().get(key1);
operations.opsForList().leftPush(listKey, listValue);
operations.opsForList().range(listKey, 0l, 1l);
operations.opsForList().range(listKey, 0L, 1L);
operations.opsForSet().add(setKey, setValue);
operations.opsForSet().members(setKey);
operations.opsForZSet().add(zsetKey, zsetValue, 1d);
operations.opsForZSet().rangeWithScores(zsetKey, 0l, -1l);
operations.opsForZSet().rangeWithScores(zsetKey, 0L, -1L);
return operations.exec();
}
});
@@ -184,14 +184,16 @@ public class RedisTemplateTests<K, V> {
Set<V> set = new HashSet<>(Collections.singletonList(setValue));
Set<TypedTuple<V>> tupleSet = new LinkedHashSet<>(
Collections.singletonList(new DefaultTypedTuple<>(zsetValue, 1d)));
assertThat(results, isEqual(Arrays.asList(new Object[] { true, value1, 1l, list, 1l, set, true, tupleSet })));
assertThat(results).usingElementComparator(CollectionAwareComparator.INSTANCE).containsExactly(true, value1, 1L,
list, 1L, set, true, tupleSet);
}
@Test
public void testDiscard() {
final K key1 = keyFactory.instance();
final V value1 = valueFactory.instance();
final V value2 = valueFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "rawtypes", "unchecked" })
@@ -202,7 +204,7 @@ public class RedisTemplateTests<K, V> {
return null;
}
});
assertThat(redisTemplate.boundValueOps(key1).get(), isEqual(value1));
assertThat(redisTemplate.boundValueOps(key1).get()).isEqualTo(value1);
}
@Test
@@ -216,11 +218,11 @@ public class RedisTemplateTests<K, V> {
operations.opsForValue().get("foo");
operations.opsForValue().append("foo1", "5");
operations.opsForList().leftPush("foolist", "6");
operations.opsForList().range("foolist", 0l, 1l);
operations.opsForList().range("foolist", 0L, 1L);
operations.opsForSet().add("fooset", "7");
operations.opsForSet().members("fooset");
operations.opsForZSet().add("foozset", "9", 1d);
operations.opsForZSet().rangeWithScores("foozset", 0l, -1l);
operations.opsForZSet().rangeWithScores("foozset", 0L, -1L);
operations.opsForZSet().range("foozset", 0, -1);
operations.opsForHash().put("foomap", "10", "11");
operations.opsForHash().entries("foomap");
@@ -228,14 +230,14 @@ public class RedisTemplateTests<K, V> {
}
});
// Everything should be converted to Longs
List<Long> list = Collections.singletonList(6l);
Set<Long> longSet = new HashSet<>(Collections.singletonList(7l));
Set<TypedTuple<Long>> tupleSet = new LinkedHashSet<>(Collections.singletonList(new DefaultTypedTuple<>(9l, 1d)));
Set<Long> zSet = new LinkedHashSet<>(Collections.singletonList(9l));
List<Long> list = Collections.singletonList(6L);
Set<Long> longSet = new HashSet<>(Collections.singletonList(7L));
Set<TypedTuple<Long>> tupleSet = new LinkedHashSet<>(Collections.singletonList(new DefaultTypedTuple<>(9L, 1d)));
Set<Long> zSet = new LinkedHashSet<>(Collections.singletonList(9L));
Map<Long, Long> map = new LinkedHashMap<>();
map.put(10l, 11l);
assertThat(results,
isEqual(Arrays.asList(new Object[] { true, 5l, 1L, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map })));
map.put(10L, 11L);
assertThat(results).containsExactly(true, 5L, 1L, 1L, list, 1L, longSet, true, tupleSet, zSet, true, map);
}
@Test
@@ -260,17 +262,17 @@ public class RedisTemplateTests<K, V> {
}
});
// first value is "OK" from set call, results should still be in byte[]
assertEquals("bar", new String((byte[]) results.get(1)));
assertThat(new String((byte[]) results.get(1))).isEqualTo("bar");
}
@SuppressWarnings("rawtypes")
@Test
public void testExecutePipelined() {
final K key1 = keyFactory.instance();
final V value1 = valueFactory.instance();
final K listKey = keyFactory.instance();
final V listValue = valueFactory.instance();
final V listValue2 = valueFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
K listKey = keyFactory.instance();
V listValue = valueFactory.instance();
V listValue2 = valueFactory.instance();
List<Object> results = redisTemplate.executePipelined((RedisCallback) connection -> {
byte[] rawKey = serialize(key1, redisTemplate.getKeySerializer());
byte[] rawListKey = serialize(listKey, redisTemplate.getKeySerializer());
@@ -281,8 +283,8 @@ public class RedisTemplateTests<K, V> {
connection.lRange(rawListKey, 0, -1);
return null;
});
assertThat(results,
isEqual(Arrays.asList(new Object[] { true, value1, 1l, 2l, Arrays.asList(new Object[] { listValue, listValue2 }) })));
assertThat(results).usingElementComparator(CollectionAwareComparator.INSTANCE).containsExactly(true, value1, 1L, 2L,
Arrays.asList(listValue, listValue2));
}
@SuppressWarnings("rawtypes")
@@ -301,7 +303,7 @@ public class RedisTemplateTests<K, V> {
return null;
}, new GenericToStringSerializer<>(Long.class));
assertEquals(Arrays.asList(new Object[] { true, 5l, 1l, 2l, Arrays.asList(new Long[] { 10l, 11l }) }), results);
assertThat(results).containsExactly(true, 5L, 1L, 2L, Arrays.asList(10L, 11L));
}
@Test // DATAREDIS-500
@@ -322,7 +324,7 @@ public class RedisTemplateTests<K, V> {
return null;
});
assertEquals(((Map) results.get(0)).get(1L), person);
assertThat(person).isEqualTo(((Map) results.get(0)).get(1L));
}
@Test(expected = InvalidDataAccessApiUsageException.class)
@@ -333,8 +335,8 @@ public class RedisTemplateTests<K, V> {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testExecutePipelinedTx() {
final K key1 = keyFactory.instance();
final V value1 = valueFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
List<Object> pipelinedResults = redisTemplate.executePipelined(new SessionCallback() {
public Object execute(RedisOperations operations) throws DataAccessException {
operations.multi();
@@ -353,8 +355,8 @@ public class RedisTemplateTests<K, V> {
}
});
// Should contain the List of deserialized exec results and the result of the last call to get()
assertThat(pipelinedResults,
isEqual(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, value1, 0l }), true, value1 })));
assertThat(pipelinedResults).usingElementComparator(CollectionAwareComparator.INSTANCE)
.containsExactly(Arrays.asList(1L, value1, 0L), true, value1);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@@ -374,7 +376,7 @@ public class RedisTemplateTests<K, V> {
}
}, new GenericToStringSerializer<>(Long.class));
// Should contain the List of deserialized exec results and the result of the last call to get()
assertEquals(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, 5l, 0l }), true, 2l }), pipelinedResults);
assertThat(pipelinedResults).isEqualTo(Arrays.asList(Arrays.asList(1L, 5L, 0L), true, 2L));
}
@Test(expected = InvalidDataAccessApiUsageException.class)
@@ -395,9 +397,9 @@ public class RedisTemplateTests<K, V> {
redisTemplate.opsForValue().set(key1, value1);
assertTrue(redisTemplate.hasKey(key1));
assertTrue(redisTemplate.delete(key1));
assertFalse(redisTemplate.hasKey(key1));
assertThat(redisTemplate.hasKey(key1)).isTrue();
assertThat(redisTemplate.delete(key1)).isTrue();
assertThat(redisTemplate.hasKey(key1)).isFalse();
}
@Test // DATAREDIS-688
@@ -411,9 +413,9 @@ public class RedisTemplateTests<K, V> {
redisTemplate.opsForValue().set(key1, value1);
redisTemplate.opsForValue().set(key2, value2);
assertEquals(2L, redisTemplate.delete(Arrays.asList(key1, key2)).longValue());
assertFalse(redisTemplate.hasKey(key1));
assertFalse(redisTemplate.hasKey(key2));
assertThat(redisTemplate.delete(Arrays.asList(key1, key2)).longValue()).isEqualTo(2L);
assertThat(redisTemplate.hasKey(key1)).isFalse();
assertThat(redisTemplate.hasKey(key2)).isFalse();
}
@Test
@@ -427,7 +429,7 @@ public class RedisTemplateTests<K, V> {
redisTemplate.opsForList().rightPush(key1, value1);
List<V> results = redisTemplate.sort(SortQueryBuilder.sort(key1).build());
assertEquals(Collections.singletonList(value1), results);
assertThat(results).isEqualTo(Collections.singletonList(value1));
}
@Test
@@ -437,8 +439,8 @@ public class RedisTemplateTests<K, V> {
V value1 = valueFactory.instance();
assumeTrue(value1 instanceof Number);
redisTemplate.opsForList().rightPush(key1, value1);
assertEquals(Long.valueOf(1), redisTemplate.sort(SortQueryBuilder.sort(key1).build(), key2));
assertEquals(Collections.singletonList(value1), redisTemplate.boundListOps(key2).range(0, -1));
assertThat(redisTemplate.sort(SortQueryBuilder.sort(key1).build(), key2)).isEqualTo(Long.valueOf(1));
assertThat(redisTemplate.boundListOps(key2).range(0, -1)).isEqualTo(Collections.singletonList(value1));
}
@Test
@@ -448,47 +450,47 @@ public class RedisTemplateTests<K, V> {
assumeTrue(value1 instanceof Number);
redisTemplate.opsForList().rightPush(key1, value1);
List<String> results = redisTemplate.sort(SortQueryBuilder.sort(key1).get("#").build(), tuple -> "FOO");
assertEquals(Collections.singletonList("FOO"), results);
assertThat(results).isEqualTo(Collections.singletonList("FOO"));
}
@Test
public void testExpireAndGetExpireMillis() {
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
redisTemplate.expire(key1, 500, TimeUnit.MILLISECONDS);
assertTrue(redisTemplate.getExpire(key1, TimeUnit.MILLISECONDS) > 0l);
assertThat(redisTemplate.getExpire(key1, TimeUnit.MILLISECONDS) > 0L).isTrue();
// Timeout is longer because expire will be 1 sec if pExpire not supported
waitFor(() -> (!redisTemplate.hasKey(key1)), 1500l);
waitFor(() -> (!redisTemplate.hasKey(key1)), 1500L);
}
@Test
public void testGetExpireNoTimeUnit() {
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
redisTemplate.expire(key1, 2, TimeUnit.SECONDS);
Long expire = redisTemplate.getExpire(key1);
// Default behavior is to return seconds
assertTrue(expire > 0l && expire <= 2l);
assertThat(expire > 0L && expire <= 2L).isTrue();
}
@Test
public void testGetExpireSeconds() {
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
redisTemplate.expire(key1, 1500, TimeUnit.MILLISECONDS);
assertEquals(Long.valueOf(1), redisTemplate.getExpire(key1, TimeUnit.SECONDS));
assertThat(redisTemplate.getExpire(key1, TimeUnit.SECONDS)).isEqualTo(Long.valueOf(1));
}
@Test // DATAREDIS-526
public void testGetExpireSecondsForKeyDoesNotExist() {
Long expire = redisTemplate.getExpire(keyFactory.instance(), TimeUnit.SECONDS);
assertTrue(expire < 0L);
assertThat(expire < 0L).isTrue();
}
@Test // DATAREDIS-526
@@ -497,7 +499,7 @@ public class RedisTemplateTests<K, V> {
K key = keyFactory.instance();
Long expire = redisTemplate.getExpire(key, TimeUnit.SECONDS);
assertTrue(expire < 0L);
assertThat(expire < 0L).isTrue();
}
@Test // DATAREDIS-526
@@ -505,7 +507,7 @@ public class RedisTemplateTests<K, V> {
Long expire = redisTemplate.getExpire(keyFactory.instance(), TimeUnit.MILLISECONDS);
assertTrue(expire < 0L);
assertThat(expire < 0L).isTrue();
}
@Test // DATAREDIS-526
@@ -516,7 +518,7 @@ public class RedisTemplateTests<K, V> {
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertTrue(expire < 0L);
assertThat(expire < 0L).isTrue();
}
@Test // DATAREDIS-526
@@ -525,14 +527,14 @@ public class RedisTemplateTests<K, V> {
assumeTrue(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory
|| redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory);
final K key = keyFactory.instance();
K key = keyFactory.instance();
redisTemplate.boundValueOps(key).set(valueFactory.instance());
redisTemplate.expire(key, 1, TimeUnit.DAYS);
Long ttl = redisTemplate.getExpire(key, TimeUnit.HOURS);
assertThat(ttl, greaterThanOrEqualTo(23L));
assertThat(ttl, lessThan(25L));
assertThat(ttl).isGreaterThanOrEqualTo(23L);
assertThat(ttl).isLessThan(25L);
}
@Test // DATAREDIS-526
@@ -542,7 +544,7 @@ public class RedisTemplateTests<K, V> {
assumeTrue(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory
|| redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory);
final K key = keyFactory.instance();
K key = keyFactory.instance();
List<Object> result = redisTemplate.execute(new SessionCallback<List<Object>>() {
@Override
@@ -557,9 +559,9 @@ public class RedisTemplateTests<K, V> {
}
});
assertThat(result, hasSize(3));
assertThat(((Long) result.get(2)), greaterThanOrEqualTo(23L));
assertThat(((Long) result.get(2)), lessThan(25L));
assertThat(result).hasSize(3);
assertThat(((Long) result.get(2))).isGreaterThanOrEqualTo(23L);
assertThat(((Long) result.get(2))).isLessThan(25L);
}
@Test // DATAREDIS-526
@@ -569,7 +571,7 @@ public class RedisTemplateTests<K, V> {
assumeTrue(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory
|| redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory);
final K key = keyFactory.instance();
K key = keyFactory.instance();
List<Object> result = redisTemplate.executePipelined(new SessionCallback<Object>() {
@Override
@@ -583,9 +585,9 @@ public class RedisTemplateTests<K, V> {
}
});
assertThat(result, hasSize(3));
assertThat(((Long) result.get(2)), greaterThanOrEqualTo(23L));
assertThat(((Long) result.get(2)), lessThan(25L));
assertThat(result).hasSize(3);
assertThat(((Long) result.get(2))).isGreaterThanOrEqualTo(23L);
assertThat(((Long) result.get(2))).isLessThan(25L);
}
@Test
@@ -593,26 +595,26 @@ public class RedisTemplateTests<K, V> {
assumeTrue(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory);
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeTrue(key1 instanceof String && value1 instanceof String);
final StringRedisTemplate template2 = new StringRedisTemplate(redisTemplate.getConnectionFactory());
StringRedisTemplate template2 = new StringRedisTemplate(redisTemplate.getConnectionFactory());
template2.boundValueOps((String) key1).set((String) value1);
template2.expire((String) key1, 5, TimeUnit.SECONDS);
long expire = template2.getExpire((String) key1, TimeUnit.MILLISECONDS);
// we should still get expire in milliseconds if requested
assertTrue(expire > 1000 && expire <= 5000);
assertThat(expire > 1000 && expire <= 5000).isTrue();
}
@Test
public void testExpireAt() {
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
redisTemplate.expireAt(key1, new Date(System.currentTimeMillis() + 5l));
waitFor(() -> (!redisTemplate.hasKey(key1)), 5l);
redisTemplate.expireAt(key1, new Date(System.currentTimeMillis() + 5L));
waitFor(() -> (!redisTemplate.hasKey(key1)), 5L);
}
@Test
@@ -621,29 +623,29 @@ public class RedisTemplateTests<K, V> {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
assumeTrue(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory);
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeTrue(key1 instanceof String && value1 instanceof String);
final StringRedisTemplate template2 = new StringRedisTemplate(redisTemplate.getConnectionFactory());
StringRedisTemplate template2 = new StringRedisTemplate(redisTemplate.getConnectionFactory());
template2.boundValueOps((String) key1).set((String) value1);
template2.expireAt((String) key1, new Date(System.currentTimeMillis() + 5l));
template2.expireAt((String) key1, new Date(System.currentTimeMillis() + 5L));
// Just ensure this works as expected, pExpireAt just adds some precision over expireAt
waitFor(() -> (!template2.hasKey((String) key1)), 5l);
waitFor(() -> (!template2.hasKey((String) key1)), 5L);
}
@Test
public void testPersist() throws Exception {
// Test is meaningless in Redis 2.4 because key won't expire after 10 ms
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
redisTemplate.expire(key1, 10, TimeUnit.MILLISECONDS);
redisTemplate.persist(key1);
Thread.sleep(10);
assertTrue(redisTemplate.hasKey(key1));
assertThat(redisTemplate.hasKey(key1)).isTrue();
}
@Test
@@ -651,7 +653,7 @@ public class RedisTemplateTests<K, V> {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
assertThat(redisTemplate.randomKey(), isEqual(key1));
assertThat(redisTemplate.randomKey()).isEqualTo(key1);
}
@Test
@@ -661,7 +663,7 @@ public class RedisTemplateTests<K, V> {
V value1 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
redisTemplate.rename(key1, key2);
assertThat(redisTemplate.opsForValue().get(key2), isEqual(value1));
assertThat(redisTemplate.opsForValue().get(key2)).isEqualTo(value1);
}
@Test
@@ -671,7 +673,7 @@ public class RedisTemplateTests<K, V> {
V value1 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
redisTemplate.renameIfAbsent(key1, key2);
assertTrue(redisTemplate.hasKey(key2));
assertThat(redisTemplate.hasKey(key2)).isTrue();
}
@Test
@@ -679,18 +681,18 @@ public class RedisTemplateTests<K, V> {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
assertEquals(DataType.STRING, redisTemplate.type(key1));
assertThat(redisTemplate.type(key1)).isEqualTo(DataType.STRING);
}
@Test // DATAREDIS-506
public void testWatch() {
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
final V value2 = valueFactory.instance();
final V value3 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
final Thread th = new Thread(() -> redisTemplate.opsForValue().set(key1, value2));
Thread th = new Thread(() -> redisTemplate.opsForValue().set(key1, value2));
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -709,20 +711,20 @@ public class RedisTemplateTests<K, V> {
}
});
assertThat(results, is(empty()));
assertThat(results).isEmpty();
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value2));
assertThat(redisTemplate.opsForValue().get(key1)).isEqualTo(value2);
}
@Test
public void testUnwatch() {
final K key1 = keyFactory.instance();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
final V value2 = valueFactory.instance();
final V value3 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
final Thread th = new Thread(() -> redisTemplate.opsForValue().set(key1, value2));
Thread th = new Thread(() -> redisTemplate.opsForValue().set(key1, value2));
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -742,21 +744,21 @@ public class RedisTemplateTests<K, V> {
}
});
assertTrue(results.size() == 1);
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value3));
assertThat(results.size() == 1).isTrue();
assertThat(redisTemplate.opsForValue().get(key1)).isEqualTo(value3);
}
@Test // DATAREDIS-506
public void testWatchMultipleKeys() {
final K key1 = keyFactory.instance();
final K key2 = keyFactory.instance();
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
V value1 = valueFactory.instance();
final V value2 = valueFactory.instance();
final V value3 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
final Thread th = new Thread(() -> redisTemplate.opsForValue().set(key1, value2));
Thread th = new Thread(() -> redisTemplate.opsForValue().set(key1, value2));
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -778,9 +780,9 @@ public class RedisTemplateTests<K, V> {
}
});
assertThat(results, is(empty()));
assertThat(results).isEmpty();
assertThat(redisTemplate.opsForValue().get(key1), isEqual(value2));
assertThat(redisTemplate.opsForValue().get(key1)).isEqualTo(value2);
}
@Test
@@ -794,16 +796,16 @@ public class RedisTemplateTests<K, V> {
public void testExecuteScriptCustomSerializers() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
K key1 = keyFactory.instance();
final DefaultRedisScript<String> script = new DefaultRedisScript<>();
DefaultRedisScript<String> script = new DefaultRedisScript<>();
script.setScriptText("return 'Hey'");
script.setResultType(String.class);
assertEquals("Hey", redisTemplate.execute(script, redisTemplate.getValueSerializer(), StringRedisSerializer.UTF_8,
Collections.singletonList(key1)));
assertThat(redisTemplate.execute(script, redisTemplate.getValueSerializer(), StringRedisSerializer.UTF_8,
Collections.singletonList(key1))).isEqualTo("Hey");
}
@Test
public void clientListShouldReturnCorrectly() {
assertThat(redisTemplate.getClientList().size(), IsNot.not(0));
assertThat(redisTemplate.getClientList().size()).isNotEqualTo(0);
}
@Test // DATAREDIS-529
@@ -816,7 +818,7 @@ public class RedisTemplateTests<K, V> {
redisTemplate.opsForValue().multiSet(source);
assertThat(redisTemplate.countExistingKeys(source.keySet()), is(3L));
assertThat(redisTemplate.countExistingKeys(source.keySet())).isEqualTo(3L);
}
@SuppressWarnings({ "unchecked", "rawtypes" })

View File

@@ -15,10 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsNull.*;
import static org.hamcrest.core.IsSame.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.io.Serializable;
@@ -90,8 +87,8 @@ public class RedisTemplateUnitTests {
.thenReturn(new JdkSerializationRedisSerializer().serialize(new SomeArbitrarySerializableObject()));
Object deserialized = template.opsForValue().get("spring");
assertThat(deserialized, notNullValue());
assertThat(deserialized.getClass().getClassLoader(), is((ClassLoader) scl));
assertThat(deserialized).isNotNull();
assertThat(deserialized.getClass().getClassLoader()).isEqualTo((ClassLoader) scl);
}
@Test // DATAREDIS-531
@@ -100,7 +97,7 @@ public class RedisTemplateUnitTests {
CapturingCallback callback = new CapturingCallback();
template.executeWithStickyConnection(callback);
assertThat(callback.getConnection(), sameInstance(redisConnectionMock));
assertThat(callback.getConnection()).isSameAs(redisConnectionMock);
verify(redisConnectionMock, never()).close();
}

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsCollectionContaining.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.io.IOException;
import java.util.ArrayList;
@@ -32,6 +30,7 @@ import java.util.Stack;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
/**
@@ -45,7 +44,7 @@ public class ScanCursorUnitTests {
public void cursorShouldNotLoopWhenNoValuesFound() {
CapturingCursorDummy cursor = initCursor(new LinkedList<>());
assertThat(cursor.hasNext(), is(false));
assertThat(cursor.hasNext()).isFalse();
}
@Test(expected = NoSuchElementException.class) // DATAREDIS-290
@@ -60,17 +59,17 @@ public class ScanCursorUnitTests {
values.add(createIteration(0, "spring", "data", "redis"));
CapturingCursorDummy cursor = initCursor(values);
assertThat(cursor.next(), is("spring"));
assertThat(cursor.getCursorId(), is(0L));
assertThat(cursor.hasNext(), is(true));
assertThat(cursor.next()).isEqualTo("spring");
assertThat(cursor.getCursorId()).isEqualTo(0L);
assertThat(cursor.hasNext()).isTrue();
assertThat(cursor.next(), is("data"));
assertThat(cursor.getCursorId(), is(0L));
assertThat(cursor.hasNext(), is(true));
assertThat(cursor.next()).isEqualTo("data");
assertThat(cursor.getCursorId()).isEqualTo(0L);
assertThat(cursor.hasNext()).isTrue();
assertThat(cursor.next(), is("redis"));
assertThat(cursor.getCursorId(), is(0L));
assertThat(cursor.hasNext(), is(false));
assertThat(cursor.next()).isEqualTo("redis");
assertThat(cursor.getCursorId()).isEqualTo(0L);
assertThat(cursor.hasNext()).isFalse();
}
@Test // DATAREDIS-290
@@ -82,17 +81,17 @@ public class ScanCursorUnitTests {
values.add(createIteration(0, "redis"));
CapturingCursorDummy cursor = initCursor(values);
assertThat(cursor.next(), is("spring"));
assertThat(cursor.getCursorId(), is(1L));
assertThat(cursor.hasNext(), is(true));
assertThat(cursor.next()).isEqualTo("spring");
assertThat(cursor.getCursorId()).isEqualTo(1L);
assertThat(cursor.hasNext()).isTrue();
assertThat(cursor.next(), is("data"));
assertThat(cursor.getCursorId(), is(2L));
assertThat(cursor.hasNext(), is(true));
assertThat(cursor.next()).isEqualTo("data");
assertThat(cursor.getCursorId()).isEqualTo(2L);
assertThat(cursor.hasNext()).isTrue();
assertThat(cursor.next(), is("redis"));
assertThat(cursor.getCursorId(), is(0L));
assertThat(cursor.hasNext(), is(false));
assertThat(cursor.next()).isEqualTo("redis");
assertThat(cursor.getCursorId()).isEqualTo(0L);
assertThat(cursor.hasNext()).isFalse();
}
@Test // DATAREDIS-290
@@ -100,7 +99,7 @@ public class ScanCursorUnitTests {
CapturingCursorDummy cursor = new CapturingCursorDummy(null);
assertThat(cursor.isClosed(), is(false));
assertThat(cursor.isClosed()).isFalse();
exception.expect(InvalidDataAccessApiUsageException.class);
exception.expectMessage("closed cursor");
@@ -117,12 +116,12 @@ public class ScanCursorUnitTests {
values.add(createIteration(0, "redis"));
Cursor<String> cursor = initCursor(values).open();
assertThat(cursor.next(), is("spring"));
assertThat(cursor.getCursorId(), is(1L));
assertThat(cursor.next()).isEqualTo("spring");
assertThat(cursor.getCursorId()).isEqualTo(1L);
// close the cursor
cursor.close();
assertThat(cursor.isClosed(), is(true));
assertThat(cursor.isClosed()).isTrue();
// reopen cursor at last position
cursor.open();
@@ -137,13 +136,13 @@ public class ScanCursorUnitTests {
values.add(createIteration(0, "redis"));
Cursor<String> cursor = initCursor(values);
assertThat(cursor.getPosition(), is(0L));
assertThat(cursor.getPosition()).isEqualTo(0L);
cursor.next();
assertThat(cursor.getPosition(), is(1L));
assertThat(cursor.getPosition()).isEqualTo(1L);
cursor.next();
assertThat(cursor.getPosition(), is(2L));
assertThat(cursor.getPosition()).isEqualTo(2L);
}
@Test // DATAREDIS-417
@@ -163,8 +162,8 @@ public class ScanCursorUnitTests {
result.add(cursor.next());
}
assertThat(result.size(), is(2));
assertThat(result, hasItems("spring", "redis"));
assertThat(result.size()).isEqualTo(2);
assertThat(result).contains("spring", "redis");
}
@Test // DATAREDIS-417
@@ -186,8 +185,8 @@ public class ScanCursorUnitTests {
result.add(cursor.next());
}
assertThat(result.size(), is(2));
assertThat(result, hasItems("spring", "data"));
assertThat(result.size()).isEqualTo(2);
assertThat(result).contains("spring", "data");
}
@Test // DATAREDIS-417
@@ -202,7 +201,7 @@ public class ScanCursorUnitTests {
values.add(createIteration(0));
Cursor<String> cursor = initCursor(values);
assertThat(cursor.getPosition(), is(0L));
assertThat(cursor.getPosition()).isEqualTo(0L);
int loops = 0;
while (cursor.hasNext()) {
@@ -210,8 +209,8 @@ public class ScanCursorUnitTests {
loops++;
}
assertThat(loops, is(0));
assertThat(cursor.getCursorId(), is(0L));
assertThat(loops).isEqualTo(0);
assertThat(cursor.getCursorId()).isEqualTo(0L);
}
private CapturingCursorDummy initCursor(Queue<ScanIteration<String>> values) {

View File

@@ -15,10 +15,11 @@
*/
package org.springframework.data.redis.core;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.StringRedisConnection;
@@ -42,7 +43,7 @@ public class SessionTest {
public Object execute(RedisOperations operations) {
checkConnection(template, stringConn);
template.discard();
assertSame(template, operations);
assertThat(operations).isSameAs(template);
checkConnection(template, stringConn);
return null;
}
@@ -51,7 +52,7 @@ public class SessionTest {
private void checkConnection(RedisTemplate<?, ?> template, final RedisConnection expectedConnection) {
template.execute(connection -> {
assertSame(expectedConnection, connection);
assertThat(connection).isSameAs(expectedConnection);
return null;
}, true);
}

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.data.redis.core.convert;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.data.redis.core.convert.MappingRedisConverter.BinaryKeyspaceIdentifier;
/**
@@ -31,37 +31,35 @@ public class BinaryKeyspaceIdentifierUnitTests {
@Test // DATAREDIS-744
public void shouldReturnIfKeyIsValid() {
assertThat(BinaryKeyspaceIdentifier.isValid(null), is(false));
assertThat(BinaryKeyspaceIdentifier.isValid("foo".getBytes()), is(false));
assertThat(BinaryKeyspaceIdentifier.isValid("".getBytes()), is(false));
assertThat(BinaryKeyspaceIdentifier.isValid("foo:bar".getBytes()), is(true));
assertThat(BinaryKeyspaceIdentifier.isValid("foo:bar:baz".getBytes()), is(true));
assertThat(BinaryKeyspaceIdentifier.isValid("foo:bar:baz:phantom".getBytes()), is(true));
assertThat(BinaryKeyspaceIdentifier.isValid(null)).isFalse();
assertThat(BinaryKeyspaceIdentifier.isValid("foo".getBytes())).isFalse();
assertThat(BinaryKeyspaceIdentifier.isValid("".getBytes())).isFalse();
assertThat(BinaryKeyspaceIdentifier.isValid("foo:bar".getBytes())).isTrue();
assertThat(BinaryKeyspaceIdentifier.isValid("foo:bar:baz".getBytes())).isTrue();
assertThat(BinaryKeyspaceIdentifier.isValid("foo:bar:baz:phantom".getBytes())).isTrue();
}
@Test // DATAREDIS-744
public void shouldReturnKeyspace() {
assertThat(BinaryKeyspaceIdentifier.of("foo:bar".getBytes()).getKeyspace(), is(equalTo("foo".getBytes())));
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz".getBytes()).getKeyspace(), is(equalTo("foo".getBytes())));
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz:phantom".getBytes()).getKeyspace(),
is(equalTo("foo".getBytes())));
assertThat(BinaryKeyspaceIdentifier.of("foo:bar".getBytes()).getKeyspace()).isEqualTo("foo".getBytes());
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz".getBytes()).getKeyspace()).isEqualTo("foo".getBytes());
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz:phantom".getBytes()).getKeyspace()).isEqualTo("foo".getBytes());
}
@Test // DATAREDIS-744
public void shouldReturnId() {
assertThat(BinaryKeyspaceIdentifier.of("foo:bar".getBytes()).getId(), is(equalTo("bar".getBytes())));
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz".getBytes()).getId(), is(equalTo("bar:baz".getBytes())));
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz:phantom".getBytes()).getId(),
is(equalTo("bar:baz".getBytes())));
assertThat(BinaryKeyspaceIdentifier.of("foo:bar".getBytes()).getId()).isEqualTo("bar".getBytes());
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz".getBytes()).getId()).isEqualTo("bar:baz".getBytes());
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz:phantom".getBytes()).getId()).isEqualTo("bar:baz".getBytes());
}
@Test // DATAREDIS-744
public void shouldReturnPhantomKey() {
assertThat(BinaryKeyspaceIdentifier.of("foo:bar".getBytes()).isPhantomKey(), is(false));
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz".getBytes()).isPhantomKey(), is(false));
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz:phantom".getBytes()).isPhantomKey(), is(true));
assertThat(BinaryKeyspaceIdentifier.of("foo:bar".getBytes()).isPhantomKey()).isFalse();
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz".getBytes()).isPhantomKey()).isFalse();
assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz:phantom".getBytes()).isPhantomKey()).isTrue();
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.core.convert;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Arrays;
@@ -26,6 +25,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.util.TypeInformation;
/**
@@ -58,6 +58,6 @@ public class CompositeIndexResolverUnitTests {
CompositeIndexResolver resolver = new CompositeIndexResolver(Arrays.asList(resolver1, resolver2));
assertThat(resolver.resolveIndexesFor(typeInfoMock, "o.O").size(), equalTo(2));
assertThat(resolver.resolveIndexesFor(typeInfoMock, "o.O").size()).isEqualTo(2);
}
}

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.data.redis.core.convert;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.data.redis.core.convert.MappingRedisConverter.KeyspaceIdentifier;
/**
@@ -31,35 +31,35 @@ public class KeyspaceIdentifierUnitTests {
@Test // DATAREDIS-744
public void shouldReturnIfKeyIsValid() {
assertThat(KeyspaceIdentifier.isValid(null), is(false));
assertThat(KeyspaceIdentifier.isValid("foo"), is(false));
assertThat(KeyspaceIdentifier.isValid(""), is(false));
assertThat(KeyspaceIdentifier.isValid("foo:bar"), is(true));
assertThat(KeyspaceIdentifier.isValid("foo:bar:baz"), is(true));
assertThat(KeyspaceIdentifier.isValid("foo:bar:baz:phantom"), is(true));
assertThat(KeyspaceIdentifier.isValid(null)).isFalse();
assertThat(KeyspaceIdentifier.isValid("foo")).isFalse();
assertThat(KeyspaceIdentifier.isValid("")).isFalse();
assertThat(KeyspaceIdentifier.isValid("foo:bar")).isTrue();
assertThat(KeyspaceIdentifier.isValid("foo:bar:baz")).isTrue();
assertThat(KeyspaceIdentifier.isValid("foo:bar:baz:phantom")).isTrue();
}
@Test // DATAREDIS-744
public void shouldReturnKeyspace() {
assertThat(KeyspaceIdentifier.of("foo:bar").getKeyspace(), is("foo"));
assertThat(KeyspaceIdentifier.of("foo:bar:baz").getKeyspace(), is("foo"));
assertThat(KeyspaceIdentifier.of("foo:bar:baz:phantom").getKeyspace(), is("foo"));
assertThat(KeyspaceIdentifier.of("foo:bar").getKeyspace()).isEqualTo("foo");
assertThat(KeyspaceIdentifier.of("foo:bar:baz").getKeyspace()).isEqualTo("foo");
assertThat(KeyspaceIdentifier.of("foo:bar:baz:phantom").getKeyspace()).isEqualTo("foo");
}
@Test // DATAREDIS-744
public void shouldReturnId() {
assertThat(KeyspaceIdentifier.of("foo:bar").getId(), is("bar"));
assertThat(KeyspaceIdentifier.of("foo:bar:baz").getId(), is("bar:baz"));
assertThat(KeyspaceIdentifier.of("foo:bar:baz:phantom").getId(), is("bar:baz"));
assertThat(KeyspaceIdentifier.of("foo:bar").getId()).isEqualTo("bar");
assertThat(KeyspaceIdentifier.of("foo:bar:baz").getId()).isEqualTo("bar:baz");
assertThat(KeyspaceIdentifier.of("foo:bar:baz:phantom").getId()).isEqualTo("bar:baz");
}
@Test // DATAREDIS-744
public void shouldReturnPhantomKey() {
assertThat(KeyspaceIdentifier.of("foo:bar").isPhantomKey(), is(false));
assertThat(KeyspaceIdentifier.of("foo:bar:baz").isPhantomKey(), is(false));
assertThat(KeyspaceIdentifier.of("foo:bar:baz:phantom").isPhantomKey(), is(true));
assertThat(KeyspaceIdentifier.of("foo:bar").isPhantomKey()).isFalse();
assertThat(KeyspaceIdentifier.of("foo:bar:baz").isPhantomKey()).isFalse();
assertThat(KeyspaceIdentifier.of("foo:bar:baz:phantom").isPhantomKey()).isTrue();
}
}

View File

@@ -15,11 +15,7 @@
*/
package org.springframework.data.redis.core.convert;
import static org.hamcrest.collection.IsEmptyCollection.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsCollectionContaining.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.redis.core.convert.ConversionTestEntities.*;
@@ -30,8 +26,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hamcrest.core.IsCollectionContaining;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -39,6 +33,7 @@ import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.geo.Point;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.redis.core.convert.ConversionTestEntities.*;
@@ -84,8 +79,8 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Address.class), address);
assertThat(indexes.size(), is(1));
assertThat(indexes, hasItem(new SimpleIndexedPropertyValue(Address.class.getName(), "country", "andor")));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes).contains(new SimpleIndexedPropertyValue(Address.class.getName(), "country", "andor"));
}
@Test // DATAREDIS-425
@@ -96,7 +91,7 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Address.class), address);
assertThat(indexes.size(), is(0));
assertThat(indexes.size()).isEqualTo(0);
}
@Test // DATAREDIS-425
@@ -108,8 +103,8 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), person);
assertThat(indexes.size(), is(1));
assertThat(indexes, hasItem(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "address.country", "andor")));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes).contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "address.country", "andor"));
}
@Test // DATAREDIS-425
@@ -131,11 +126,10 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TheWheelOfTime.class), twot);
assertThat(indexes.size(), is(2));
assertThat(indexes,
IsCollectionContaining.<IndexedData> hasItems(
new SimpleIndexedPropertyValue(KEYSPACE_TWOT, "mainCharacters.address.country", "andor"),
new SimpleIndexedPropertyValue(KEYSPACE_TWOT, "mainCharacters.address.country", "saldaea")));
assertThat(indexes.size()).isEqualTo(2);
assertThat(indexes).contains(
new SimpleIndexedPropertyValue(KEYSPACE_TWOT, "mainCharacters.address.country", "andor"),
new SimpleIndexedPropertyValue(KEYSPACE_TWOT, "mainCharacters.address.country", "saldaea"));
}
@Test // DATAREDIS-425
@@ -154,9 +148,9 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TheWheelOfTime.class), twot);
assertThat(indexes.size(), is(1));
assertThat(indexes,
hasItem(new SimpleIndexedPropertyValue(KEYSPACE_TWOT, "places.stone-of-tear.address.country", "illian")));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes)
.contains(new SimpleIndexedPropertyValue(KEYSPACE_TWOT, "places.stone-of-tear.address.country", "illian"));
}
@Test // DATAREDIS-425
@@ -170,9 +164,9 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), rand);
assertThat(indexes.size(), is(1));
assertThat(indexes,
hasItem(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "physicalAttributes.eye-color", "grey")));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes)
.contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "physicalAttributes.eye-color", "grey"));
}
@Test // DATAREDIS-425
@@ -190,9 +184,9 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), rand);
assertThat(indexes.size(), is(1));
assertThat(indexes,
hasItem(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "relatives.father.firstname", "janduin")));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes)
.contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "relatives.father.firstname", "janduin"));
}
@Test // DATAREDIS-425, DATAREDIS-471
@@ -206,8 +200,8 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), rand);
assertThat(indexes.size(), is(1));
assertThat(indexes.iterator().next(), IsInstanceOf.instanceOf(RemoveIndexedData.class));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes.iterator().next()).isInstanceOf(RemoveIndexedData.class);
}
@Test // DATAREDIS-425
@@ -221,14 +215,14 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver
.resolveIndexesFor(ClassTypeInformation.from(PersonWithAddressReference.class), rand);
assertThat(indexes.size(), is(0));
assertThat(indexes.size()).isEqualTo(0);
}
@Test // DATAREDIS-425
public void resolveIndexShouldReturnNullWhenNoIndexConfigured() {
when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(false);
assertThat(resolve("foo", "rand"), nullValue());
assertThat(resolve("foo", "rand")).isNull();
}
@Test // DATAREDIS-425
@@ -237,7 +231,7 @@ public class PathIndexResolverUnitTests {
when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(false);
indexConfig.addIndexDefinition(new SimpleIndexDefinition(KEYSPACE_PERSON, "foo"));
assertThat(resolve("foo", "rand"), notNullValue());
assertThat(resolve("foo", "rand")).isNotNull();
}
@Test // DATAREDIS-425
@@ -246,7 +240,7 @@ public class PathIndexResolverUnitTests {
when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(true);
when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(createIndexedInstance());
assertThat(resolve("foo", "rand"), notNullValue());
assertThat(resolve("foo", "rand")).isNotNull();
}
@Test // DATAREDIS-425
@@ -258,7 +252,7 @@ public class PathIndexResolverUnitTests {
IndexedData index = resolve("list.[0].name", "rand");
assertThat(index.getIndexName(), is("list.name"));
assertThat(index.getIndexName()).isEqualTo("list.name");
}
@Test // DATAREDIS-425
@@ -270,7 +264,7 @@ public class PathIndexResolverUnitTests {
IndexedData index = resolve("map.[foo].name", "rand");
assertThat(index.getIndexName(), is("map.foo.name"));
assertThat(index.getIndexName()).isEqualTo("map.foo.name");
}
@Test // DATAREDIS-425
@@ -282,7 +276,7 @@ public class PathIndexResolverUnitTests {
IndexedData index = resolve("map.[0].name", "rand");
assertThat(index.getIndexName(), is("map.0.name"));
assertThat(index.getIndexName()).isEqualTo("map.0.name");
}
@Test // DATAREDIS-425
@@ -296,8 +290,8 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat);
assertThat(indexes.size(), is(1));
assertThat(indexes, hasItem(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "feature.type", "hat")));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes).contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "feature.type", "hat"));
}
@Test // DATAREDIS-425
@@ -311,7 +305,7 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat);
assertThat(indexes.size(), is(0));
assertThat(indexes.size()).isEqualTo(0);
}
@Test // DATAREDIS-425
@@ -327,9 +321,9 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat);
assertThat(indexes.size(), is(1));
assertThat(indexes,
hasItem(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "characteristics.clothing.type", "hat")));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes)
.contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "characteristics.clothing.type", "hat"));
}
@Test // DATAREDIS-425
@@ -345,8 +339,8 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat);
assertThat(indexes.size(), is(1));
assertThat(indexes, hasItem(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "items.type", "hat")));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes).contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "items.type", "hat"));
}
@Test // DATAREDIS-425
@@ -364,8 +358,8 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat);
assertThat(indexes.size(), is(1));
assertThat(indexes, hasItem(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "itemsType", "hat")));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes).contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "itemsType", "hat"));
}
@Test // DATAREDIS-425
@@ -377,7 +371,7 @@ public class PathIndexResolverUnitTests {
size.width = 30;
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Size.class), size);
assertThat(indexes, is(empty()));
assertThat(indexes).isEmpty();
}
@Test // DATAREDIS-425
@@ -392,11 +386,10 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(IndexedOnMapField.class),
source);
assertThat(indexes.size(), is(2));
assertThat(indexes,
IsCollectionContaining.<IndexedData> hasItems(
new SimpleIndexedPropertyValue(IndexedOnMapField.class.getName(), "values.jon", "snow"),
new SimpleIndexedPropertyValue(IndexedOnMapField.class.getName(), "values.arya", "stark")));
assertThat(indexes.size()).isEqualTo(2);
assertThat(indexes).contains(
new SimpleIndexedPropertyValue(IndexedOnMapField.class.getName(), "values.jon", "snow"),
new SimpleIndexedPropertyValue(IndexedOnMapField.class.getName(), "values.arya", "stark"));
}
@Test // DATAREDIS-425
@@ -411,11 +404,9 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(IndexedOnListField.class),
source);
assertThat(indexes.size(), is(2));
assertThat(indexes,
IsCollectionContaining.<IndexedData> hasItems(
new SimpleIndexedPropertyValue(IndexedOnListField.class.getName(), "values", "jon"),
new SimpleIndexedPropertyValue(IndexedOnListField.class.getName(), "values", "arya")));
assertThat(indexes.size()).isEqualTo(2);
assertThat(indexes).contains(new SimpleIndexedPropertyValue(IndexedOnListField.class.getName(), "values", "jon"),
new SimpleIndexedPropertyValue(IndexedOnListField.class.getName(), "values", "arya"));
}
@Test // DATAREDIS-509
@@ -427,12 +418,11 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver
.resolveIndexesFor(ClassTypeInformation.from(IndexedOnPrimitiveArrayField.class), source);
assertThat(indexes.size(), is(3));
assertThat(indexes,
IsCollectionContaining.<IndexedData> hasItems(
new SimpleIndexedPropertyValue(IndexedOnPrimitiveArrayField.class.getName(), "values", 1),
new SimpleIndexedPropertyValue(IndexedOnPrimitiveArrayField.class.getName(), "values", 2),
new SimpleIndexedPropertyValue(IndexedOnPrimitiveArrayField.class.getName(), "values", 3)));
assertThat(indexes.size()).isEqualTo(3);
assertThat(indexes).contains(
new SimpleIndexedPropertyValue(IndexedOnPrimitiveArrayField.class.getName(), "values", 1),
new SimpleIndexedPropertyValue(IndexedOnPrimitiveArrayField.class.getName(), "values", 2),
new SimpleIndexedPropertyValue(IndexedOnPrimitiveArrayField.class.getName(), "values", 3));
}
@Test // DATAREDIS-533
@@ -444,7 +434,7 @@ public class PathIndexResolverUnitTests {
IndexedData index = resolve("location", new Point(1D, 2D));
assertThat(index.getIndexName(), is("location"));
assertThat(index.getIndexName()).isEqualTo("location");
}
@Test // DATAREDIS-533
@@ -456,7 +446,7 @@ public class PathIndexResolverUnitTests {
IndexedData index = resolve("property.location", new Point(1D, 2D));
assertThat(index.getIndexName(), is("property:location"));
assertThat(index.getIndexName()).isEqualTo("property:location");
}
@Test // DATAREDIS-533
@@ -468,9 +458,9 @@ public class PathIndexResolverUnitTests {
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(GeoIndexedOnPoint.class),
source);
assertThat(indexes.size(), is(1));
assertThat(indexes, IsCollectionContaining.<IndexedData> hasItems(
new GeoIndexedPropertyValue(GeoIndexedOnPoint.class.getName(), "location", source.location)));
assertThat(indexes.size()).isEqualTo(1);
assertThat(indexes)
.contains(new GeoIndexedPropertyValue(GeoIndexedOnPoint.class.getName(), "location", source.location));
}
@Test // DATAREDIS-533
@@ -493,7 +483,7 @@ public class PathIndexResolverUnitTests {
return null;
}
assertThat(data.size(), is(1));
assertThat(data.size()).isEqualTo(1);
return data.iterator().next();
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.core.convert;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.HashMap;
import java.util.Map;
@@ -24,6 +23,7 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.core.convert.KeyspaceConfiguration.KeyspaceSettings;
import org.springframework.data.redis.core.index.IndexConfiguration;
import org.springframework.data.redis.core.index.SpelIndexDefinition;
@@ -87,7 +87,7 @@ public class SpelIndexResolverUnitTests {
Set<IndexedData> indexes = resolver.resolveIndexesFor(typeInformation, null);
assertThat(indexes.size(), equalTo(0));
assertThat(indexes.size()).isEqualTo(0);
}
@Test // DATAREDIS-425
@@ -96,7 +96,7 @@ public class SpelIndexResolverUnitTests {
typeInformation = ClassTypeInformation.from(String.class);
Set<IndexedData> indexes = resolver.resolveIndexesFor(typeInformation, "");
assertThat(indexes.size(), equalTo(0));
assertThat(indexes.size()).isEqualTo(0);
}
@Test // DATAREDIS-425
@@ -105,7 +105,7 @@ public class SpelIndexResolverUnitTests {
session = new Session();
Set<IndexedData> indexes = resolver.resolveIndexesFor(typeInformation, session);
assertThat(indexes.size(), equalTo(0));
assertThat(indexes.size()).isEqualTo(0);
}
@Test // DATAREDIS-425
@@ -113,7 +113,7 @@ public class SpelIndexResolverUnitTests {
Set<IndexedData> indexes = resolver.resolveIndexesFor(typeInformation, session);
assertThat(indexes, hasItem(new SimpleIndexedPropertyValue(keyspace, indexName, username)));
assertThat(indexes).contains(new SimpleIndexedPropertyValue(keyspace, indexName, username));
}
@Test(expected = SpelEvaluationException.class) // DATAREDIS-425
@@ -137,7 +137,7 @@ public class SpelIndexResolverUnitTests {
Set<IndexedData> indexes = resolver.resolveIndexesFor(typeInformation, session);
assertThat(indexes, hasItem(new SimpleIndexedPropertyValue(keyspace, indexName, session)));
assertThat(indexes).contains(new SimpleIndexedPropertyValue(keyspace, indexName, session));
}
private SpelIndexResolver createWithExpression(String expression) {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.core.index;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
@@ -31,7 +30,7 @@ public class IndexConfigurationUnitTests {
String path = "path";
SimpleIndexDefinition setting = new SimpleIndexDefinition("keyspace", path);
assertThat(setting.getIndexName(), equalTo(path));
assertThat(setting.getIndexName()).isEqualTo(path);
}
@Test // DATAREDIS-425
@@ -39,7 +38,7 @@ public class IndexConfigurationUnitTests {
String indexName = "indexName";
SimpleIndexDefinition setting = new SimpleIndexDefinition("keyspace", "index", indexName);
assertThat(setting.getIndexName(), equalTo(indexName));
assertThat(setting.getIndexName()).isEqualTo(indexName);
}
@Test // DATAREDIS-425
@@ -49,7 +48,7 @@ public class IndexConfigurationUnitTests {
SimpleIndexDefinition setting2 = new SimpleIndexDefinition(setting1.getKeyspace(), "path", setting1.getIndexName()
+ "other");
assertThat(setting1, not(equalTo(setting2)));
assertThat(setting1).isNotEqualTo(setting2);
}
@Test // DATAREDIS-425
@@ -59,6 +58,6 @@ public class IndexConfigurationUnitTests {
SimpleIndexDefinition setting2 = new SimpleIndexDefinition(setting1.getKeyspace(), "path", setting1.getIndexName()
+ "other");
assertThat(setting1.hashCode(), not(equalTo(setting2.hashCode())));
assertThat(setting1.hashCode()).isNotEqualTo(setting2.hashCode());
}
}

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.redis.core.mapping;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Before;
@@ -27,6 +25,7 @@ import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.keyvalue.core.mapping.KeySpaceResolver;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.redis.core.TimeToLiveAccessor;
@@ -109,6 +108,6 @@ public class BasicRedisPersistentEntityUnitTests<T> {
entity.addPersistentProperty(property1);
entity.addPersistentProperty(property2);
assertThat(entity.getIdProperty(), is(equalTo(property2)));
assertThat(entity.getIdProperty()).isEqualTo(property2);
}
}

View File

@@ -15,11 +15,11 @@
*/
package org.springframework.data.redis.core.mapping;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.core.convert.KeyspaceConfiguration;
import org.springframework.data.redis.core.convert.KeyspaceConfiguration.KeyspaceSettings;
import org.springframework.data.redis.core.mapping.RedisMappingContext.ConfigAwareKeySpaceResolver;
@@ -45,14 +45,15 @@ public class ConfigAwareKeySpaceResolverUnitTests {
@Test // DATAREDIS-425
public void resolveShouldUseClassNameAsDefaultKeyspace() {
assertThat(resolver.resolveKeySpace(TypeWithoutAnySettings.class), is(TypeWithoutAnySettings.class.getName()));
assertThat(resolver.resolveKeySpace(TypeWithoutAnySettings.class))
.isEqualTo(TypeWithoutAnySettings.class.getName());
}
@Test // DATAREDIS-425
public void resolveShouldFavorConfiguredNameOverClassName() {
config.addKeyspaceSettings(new KeyspaceSettings(TypeWithoutAnySettings.class, "ji'e'toh"));
assertThat(resolver.resolveKeySpace(TypeWithoutAnySettings.class), is("ji'e'toh"));
assertThat(resolver.resolveKeySpace(TypeWithoutAnySettings.class)).isEqualTo("ji'e'toh");
}
static class TypeWithoutAnySettings {

View File

@@ -15,11 +15,11 @@
*/
package org.springframework.data.redis.core.mapping;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.core.PartialUpdate;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.TimeToLive;
@@ -49,7 +49,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
@Test // DATAREDIS-425
public void getTimeToLiveShouldReturnNullIfNothingConfiguredOrAnnotated() {
assertThat(accessor.getTimeToLive(new SimpleType()), nullValue());
assertThat(accessor.getTimeToLive(new SimpleType())).isNull();
}
@Test // DATAREDIS-425
@@ -59,12 +59,12 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
setting.setTimeToLive(10L);
config.addKeyspaceSettings(setting);
assertThat(accessor.getTimeToLive(new SimpleType()), is(10L));
assertThat(accessor.getTimeToLive(new SimpleType())).isEqualTo(10L);
}
@Test // DATAREDIS-425
public void getTimeToLiveShouldReturnValueWhenTypeIsAnnotated() {
assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotation()), is(5L));
assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotation())).isEqualTo(5L);
}
@Test // DATAREDIS-425
@@ -74,22 +74,22 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
setting.setTimeToLive(10L);
config.addKeyspaceSettings(setting);
assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotation()), is(5L));
assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotation())).isEqualTo(5L);
}
@Test // DATAREDIS-425
public void getTimeToLiveShouldReturnValueWhenPropertyIsAnnotatedAndHasValue() {
assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotationAndTTLProperty(20L)), is(20L));
assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotationAndTTLProperty(20L))).isEqualTo(20L);
}
@Test // DATAREDIS-425
public void getTimeToLiveShouldReturnValueFromTypeAnnotationWhenPropertyIsAnnotatedAndHasNullValue() {
assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotationAndTTLProperty()), is(10L));
assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotationAndTTLProperty())).isEqualTo(10L);
}
@Test // DATAREDIS-425
public void getTimeToLiveShouldReturnNullWhenPropertyIsAnnotatedAndHasNullValue() {
assertThat(accessor.getTimeToLive(new SimpleTypeWithTTLProperty()), nullValue());
assertThat(accessor.getTimeToLive(new SimpleTypeWithTTLProperty())).isNull();
}
@Test // DATAREDIS-425
@@ -99,7 +99,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
setting.setTimeToLive(10L);
config.addKeyspaceSettings(setting);
assertThat(accessor.getTimeToLive(new SimpleTypeWithTTLProperty()), is(10L));
assertThat(accessor.getTimeToLive(new SimpleTypeWithTTLProperty())).isEqualTo(10L);
}
@Test // DATAREDIS-425
@@ -109,12 +109,12 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
setting.setTimeToLive(10L);
config.addKeyspaceSettings(setting);
assertThat(accessor.getTimeToLive(new SimpleTypeWithTTLProperty(25L)), is(25L));
assertThat(accessor.getTimeToLive(new SimpleTypeWithTTLProperty(25L))).isEqualTo(25L);
}
@Test // DATAREDIS-425
public void getTimeToLiveShouldReturnMethodLevelTimeToLiveIfPresent() {
assertThat(accessor.getTimeToLive(new TypeWithTtlOnMethod(10L)), is(10L));
assertThat(accessor.getTimeToLive(new TypeWithTtlOnMethod(10L))).isEqualTo(10L);
}
@Test // DATAREDIS-425
@@ -124,7 +124,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
setting.setTimeToLive(10L);
config.addKeyspaceSettings(setting);
assertThat(accessor.getTimeToLive(new TypeWithTtlOnMethod(null)), is(10L));
assertThat(accessor.getTimeToLive(new TypeWithTtlOnMethod(null))).isEqualTo(10L);
}
@Test // DATAREDIS-425
@@ -134,7 +134,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
setting.setTimeToLive(10L);
config.addKeyspaceSettings(setting);
assertThat(accessor.getTimeToLive(new TypeWithTtlOnMethod(100L)), is(100L));
assertThat(accessor.getTimeToLive(new TypeWithTtlOnMethod(100L))).isEqualTo(100L);
}
@Test // DATAREDIS-471
@@ -143,7 +143,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
Long ttl = accessor
.getTimeToLive(new PartialUpdate<>("123", new TypeWithRedisHashAnnotation()));
assertThat(ttl, is(5L));
assertThat(ttl).isEqualTo(5L);
}
@Test // DATAREDIS-471
@@ -153,7 +153,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
.getTimeToLive(new PartialUpdate<>("123", new SimpleTypeWithTTLProperty())
.set("ttl", 100).refreshTtl(true));
assertThat(ttl, is(100L));
assertThat(ttl).isEqualTo(100L);
}
@Test // DATAREDIS-471
@@ -163,7 +163,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
new PartialUpdate<>("123",
new TypeWithRedisHashAnnotationAndTTLProperty()).set("ttl", 100).refreshTtl(true));
assertThat(ttl, is(100L));
assertThat(ttl).isEqualTo(100L);
}
@Test // DATAREDIS-471
@@ -173,7 +173,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
.getTimeToLive(new PartialUpdate<>("123",
new TypeWithRedisHashAnnotationAndTTLProperty()).refreshTtl(true));
assertThat(ttl, is(10L));
assertThat(ttl).isEqualTo(10L);
}
static class SimpleType {}

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.core.script;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collections;
@@ -23,6 +23,7 @@ import java.util.List;
import org.junit.ClassRule;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.Person;
@@ -52,7 +53,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
public static @ClassRule MinimumRedisVersionRule minRedisVersion = new MinimumRedisVersionRule();
@SuppressWarnings("rawtypes")//
@SuppressWarnings("rawtypes") //
private RedisTemplate template;
protected abstract RedisConnectionFactory getConnectionFactory();
@@ -82,9 +83,9 @@ public abstract class AbstractDefaultScriptExecutorTests {
script.setResultType(Long.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
Long result = scriptExecutor.execute(script, Collections.singletonList("mykey"));
assertNull(result);
assertThat(result).isNull();
template.boundValueOps("mykey").set("2");
assertEquals(Long.valueOf(3), scriptExecutor.execute(script, Collections.singletonList("mykey")));
assertThat(scriptExecutor.execute(script, Collections.singletonList("mykey"))).isEqualTo(Long.valueOf(3));
}
@SuppressWarnings("unchecked")
@@ -99,10 +100,10 @@ public abstract class AbstractDefaultScriptExecutorTests {
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/cas.lua"));
script.setResultType(Boolean.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
template.boundValueOps("counter").set(0l);
template.boundValueOps("counter").set(0L);
Boolean valueSet = scriptExecutor.execute(script, Collections.singletonList("counter"), 0, 3);
assertTrue(valueSet);
assertFalse(scriptExecutor.execute(script, Collections.singletonList("counter"), 0, 3));
assertThat(valueSet).isTrue();
assertThat(scriptExecutor.execute(script, Collections.singletonList("counter"), 0, 3)).isFalse();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -117,8 +118,8 @@ public abstract class AbstractDefaultScriptExecutorTests {
script.setResultType(List.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
List<String> result = scriptExecutor.execute(script, new GenericToStringSerializer<>(Long.class),
template.getValueSerializer(), Collections.singletonList("mylist"), 1l);
assertEquals(Collections.singletonList("a"), result);
template.getValueSerializer(), Collections.singletonList("mylist"), 1L);
assertThat(result).isEqualTo(Collections.singletonList("a"));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -132,10 +133,9 @@ public abstract class AbstractDefaultScriptExecutorTests {
script.setResultType(List.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
List<Object> results = scriptExecutor.execute(script, Collections.singletonList("mylist"));
assertEquals(Arrays.asList(new Object[] { null, 0l }), results);
assertThat(results).isEqualTo(Arrays.asList(null, 0L));
template.boundListOps("mylist").leftPushAll("a", "b");
assertEquals(Arrays.asList(new Object[] { "a", 1l }),
scriptExecutor.execute(script, Collections.singletonList("mylist")));
assertThat(scriptExecutor.execute(script, Collections.singletonList("mylist"))).isEqualTo(Arrays.asList("a", 1L));
}
@SuppressWarnings("unchecked")
@@ -149,7 +149,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
script.setResultType(String.class);
template.opsForValue().set("foo", "bar");
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
assertEquals("bar", scriptExecutor.execute(script, Collections.singletonList("foo")));
assertThat(scriptExecutor.execute(script, Collections.singletonList("foo"))).isEqualTo("bar");
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -163,8 +163,9 @@ public abstract class AbstractDefaultScriptExecutorTests {
DefaultRedisScript script = new DefaultRedisScript();
script.setScriptText("return redis.call('SET',KEYS[1], ARGV[1])");
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
assertNull(scriptExecutor.execute(script, Collections.singletonList("foo"), 3l));
assertEquals(Long.valueOf(3), template.opsForValue().get("foo"));
Object result = scriptExecutor.execute(script, Collections.singletonList("foo"), 3L);
assertThat(result).isNull();
assertThat(template.opsForValue().get("foo")).isEqualTo(3L);
}
@SuppressWarnings("unchecked")
@@ -183,8 +184,8 @@ public abstract class AbstractDefaultScriptExecutorTests {
Person joe = new Person("Joe", "Schmoe", 23);
String result = scriptExecutor.execute(script, personSerializer, StringRedisSerializer.UTF_8,
Collections.singletonList("bar"), joe);
assertEquals("FOO", result);
assertEquals(joe, template.boundValueOps("bar").get());
assertThat(result).isEqualTo("FOO");
assertThat(template.boundValueOps("bar").get()).isEqualTo(joe);
}
@SuppressWarnings("unchecked")
@@ -204,7 +205,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
});
// Result is deserialized by RedisTemplate as part of executePipelined
assertEquals(Collections.singletonList("foo"), results);
assertThat(results).isEqualTo(Collections.singletonList("foo"));
}
@SuppressWarnings("unchecked")
@@ -226,7 +227,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
});
// Result is deserialized by RedisTemplate as part of exec
assertEquals(Collections.singletonList("barfoo"), results);
assertThat(results).isEqualTo(Collections.singletonList("barfoo"));
}
@SuppressWarnings("unchecked")
@@ -240,8 +241,8 @@ public abstract class AbstractDefaultScriptExecutorTests {
script.setResultType(String.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
// Execute script twice, second time should be from cache
assertEquals("HELLO", scriptExecutor.execute(script, null));
assertEquals("HELLO", scriptExecutor.execute(script, null));
assertThat(scriptExecutor.execute(script, null)).isEqualTo("HELLO");
assertThat(scriptExecutor.execute(script, null)).isEqualTo("HELLO");
}
@Test // DATAREDIS-356
@@ -256,6 +257,6 @@ public abstract class AbstractDefaultScriptExecutorTests {
script.setResultType(String.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
assertEquals("BUBU", scriptExecutor.execute(script, null).substring(0, 4));
assertThat(scriptExecutor.execute(script, null).substring(0, 4)).isEqualTo("BUBU");
}
}

View File

@@ -15,9 +15,10 @@
*/
package org.springframework.data.redis.core.script;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scripting.support.ResourceScriptSource;
import org.springframework.scripting.support.StaticScriptSource;
@@ -39,10 +40,10 @@ public class DefaultRedisScriptTests {
redisScript.setResultType(String.class);
String sha1 = redisScript.getSha1();
// Ensure multiple calls return same sha
assertEquals(sha1, redisScript.getSha1());
assertThat(redisScript.getSha1()).isEqualTo(sha1);
script.setScript("return KEYS[2]");
// Sha should now be different as script text has changed
assertFalse(sha1.equals(redisScript.getSha1()));
assertThat(sha1.equals(redisScript.getSha1())).isFalse();
}
@Test
@@ -51,7 +52,7 @@ public class DefaultRedisScriptTests {
DefaultRedisScript<String> redisScript = new DefaultRedisScript<>();
redisScript.setScriptText("return ARGS[1]");
redisScript.setResultType(String.class);
assertEquals("return ARGS[1]", redisScript.getScriptAsString());
assertThat(redisScript.getScriptAsString()).isEqualTo("return ARGS[1]");
}
@Test(expected = ScriptingException.class)

View File

@@ -17,6 +17,7 @@ package org.springframework.data.redis.core.script.lettuce;
import org.junit.After;
import org.junit.Before;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;

View File

@@ -16,8 +16,7 @@
package org.springframework.data.redis.core.types;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.*;
import java.util.concurrent.TimeUnit;
@@ -33,8 +32,8 @@ public class ExpirationUnitTests {
Expiration expiration = Expiration.from(5, null);
assertThat(expiration.getExpirationTime(), is(5L));
assertThat(expiration.getTimeUnit(), is(TimeUnit.SECONDS));
assertThat(expiration.getExpirationTime()).isEqualTo(5L);
assertThat(expiration.getTimeUnit()).isEqualTo(TimeUnit.SECONDS);
}
@Test // DATAREDIS-316
@@ -42,8 +41,8 @@ public class ExpirationUnitTests {
Expiration expiration = Expiration.from(5L * 1000 * 1000, TimeUnit.NANOSECONDS);
assertThat(expiration.getExpirationTime(), is(5L));
assertThat(expiration.getTimeUnit(), is(TimeUnit.MILLISECONDS));
assertThat(expiration.getExpirationTime()).isEqualTo(5L);
assertThat(expiration.getTimeUnit()).isEqualTo(TimeUnit.MILLISECONDS);
}
@Test // DATAREDIS-316
@@ -51,7 +50,7 @@ public class ExpirationUnitTests {
Expiration expiration = Expiration.from(5, TimeUnit.MINUTES);
assertThat(expiration.getExpirationTime(), is(5L * 60));
assertThat(expiration.getTimeUnit(), is(TimeUnit.SECONDS));
assertThat(expiration.getExpirationTime()).isEqualTo(5L * 60);
assertThat(expiration.getTimeUnit()).isEqualTo(TimeUnit.SECONDS);
}
}

View File

@@ -15,12 +15,11 @@
*/
package org.springframework.data.redis.core.types;
import org.hamcrest.core.Is;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
import org.junit.Assert;
import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.core.types.RedisClientInfo.RedisClientInfoBuilder;
/**
@@ -56,16 +55,16 @@ public class RedisClientInfoUnitTests {
@Test
public void testGetReturnsNullForPropertiesNotAvailable() {
Assert.assertThat(info.get("foo-bar"), IsEqual.equalTo(null));
assertThat(info.get("foo-bar")).isEqualTo(null);
}
private void assertValues(RedisClientInfo info, String[] values) {
for (String potentialValue : values) {
if (potentialValue.contains("=")) {
String[] keyValuePair = potentialValue.split("=");
Assert.assertThat(info.get(keyValuePair[0]), Is.is(keyValuePair[1]));
assertThat(info.get(keyValuePair[0])).isEqualTo(keyValuePair[1]);
} else {
Assert.assertThat(info.get(potentialValue), IsNot.not(null));
assertThat(info.get(potentialValue)).isNotEqualTo(null);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.listener;
import static org.hamcrest.core.Is.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.UUID;
@@ -28,6 +27,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
@@ -104,7 +104,7 @@ public class KeyExpirationEventMessageListenerTests {
ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class);
verify(publisherMock, times(1)).publishEvent(captor.capture());
assertThat((byte[]) captor.getValue().getSource(), is(key));
assertThat((byte[]) captor.getValue().getSource()).isEqualTo(key);
}
@Test // DATAREDIS-425

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.redis.listener;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsInstanceOf.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.Before;
@@ -26,6 +24,7 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.connection.DefaultMessage;
@@ -61,8 +60,8 @@ public class KeyExpirationEventMessageListenerUnitTests {
ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class);
verify(publisherMock, times(1)).publishEvent(captor.capture());
assertThat(captor.getValue(), instanceOf(RedisKeyExpiredEvent.class));
assertThat((byte[]) captor.getValue().getSource(), is(MESSAGE_BODY.getBytes()));
assertThat(captor.getValue()).isInstanceOf(RedisKeyExpiredEvent.class);
assertThat((byte[]) captor.getValue().getSource()).isEqualTo(MESSAGE_BODY.getBytes());
}
@Test // DATAREDIS-425

View File

@@ -15,7 +15,7 @@
*/
package org.springframework.data.redis.listener;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
@@ -40,6 +40,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.runners.model.Statement;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.data.redis.ConnectionFactoryTracker;
@@ -193,13 +194,13 @@ public class PubSubResubscribeTests {
msgs.add(bag2.poll(500, TimeUnit.MILLISECONDS));
msgs.add(bag2.poll(500, TimeUnit.MILLISECONDS));
assertEquals(2, msgs.size());
assertTrue(msgs.contains(payload1));
assertTrue(msgs.contains(payload2));
assertThat(msgs.size()).isEqualTo(2);
assertThat(msgs.contains(payload1)).isTrue();
assertThat(msgs.contains(payload2)).isTrue();
msgs.clear();
// unsubscribed adapter did not receive message
assertNull(bag.poll(500, TimeUnit.MILLISECONDS));
assertThat(bag.poll(500, TimeUnit.MILLISECONDS)).isNull();
// bind original listener on another channel
container.addMessageListener(adapter, new ChannelTopic(ANOTHER_CHANNEL));
@@ -215,16 +216,16 @@ public class PubSubResubscribeTests {
msgs.add(bag.poll(500, TimeUnit.MILLISECONDS));
msgs.add(bag.poll(500, TimeUnit.MILLISECONDS));
assertTrue(msgs.contains(payload2));
assertTrue(msgs.contains(null));
assertThat(msgs.contains(payload2)).isTrue();
assertThat(msgs.contains(null)).isTrue();
// another listener receives messages on both channels
msgs.clear();
msgs.add(bag2.poll(500, TimeUnit.MILLISECONDS));
msgs.add(bag2.poll(500, TimeUnit.MILLISECONDS));
assertEquals(2, msgs.size());
assertTrue(msgs.contains(payload1));
assertTrue(msgs.contains(payload2));
assertThat(msgs.size()).isEqualTo(2);
assertThat(msgs.contains(payload1)).isTrue();
assertThat(msgs.contains(payload2)).isTrue();
}
@Test
@@ -258,11 +259,11 @@ public class PubSubResubscribeTests {
set.add(bag.poll(500, TimeUnit.MILLISECONDS));
set.add(bag.poll(500, TimeUnit.MILLISECONDS));
assertFalse(set.contains(payload1));
assertFalse(set.contains(payload2));
assertThat(set.contains(payload1)).isFalse();
assertThat(set.contains(payload2)).isFalse();
assertTrue(set.contains(anotherPayload1));
assertTrue(set.contains(anotherPayload2));
assertThat(set.contains(anotherPayload1)).isTrue();
assertThat(set.contains(anotherPayload2)).isTrue();
}
/**
@@ -291,7 +292,7 @@ public class PubSubResubscribeTests {
set.add(bag.poll(500, TimeUnit.MILLISECONDS));
set.add(bag.poll(500, TimeUnit.MILLISECONDS));
assertEquals(new HashSet<>(Arrays.asList(new String[] { "HELLO", "WORLD" })), set);
assertThat(set).isEqualTo(new HashSet<>(Arrays.asList(new String[] { "HELLO", "WORLD" })));
}
private class MessageHandler {

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.listener;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import java.util.Arrays;
@@ -135,7 +134,7 @@ public class PubSubTests<T> {
set.add((T) bag.poll(1, TimeUnit.SECONDS));
set.add((T) bag.poll(1, TimeUnit.SECONDS));
assertThat(set, hasItems(payload1, payload2));
assertThat(set).contains(payload1, payload2);
}
@Test
@@ -146,7 +145,7 @@ public class PubSubTests<T> {
}
Thread.sleep(1000);
assertEquals(COUNT, bag.size());
assertThat(bag.size()).isEqualTo(COUNT);
}
@Test
@@ -158,7 +157,7 @@ public class PubSubTests<T> {
template.convertAndSend(CHANNEL, payload1);
template.convertAndSend(CHANNEL, payload2);
assertNull(bag.poll(1, TimeUnit.SECONDS));
assertThat(bag.poll(1, TimeUnit.SECONDS)).isNull();
}
@Test
@@ -188,7 +187,7 @@ public class PubSubTests<T> {
Set<T> set = new LinkedHashSet<>();
set.add((T) bag.poll(3, TimeUnit.SECONDS));
assertThat(set, hasItems(payload));
assertThat(set).contains(payload);
}
private static boolean isClusterAware(RedisConnectionFactory connectionFactory) {

Some files were not shown because too many files have changed in this diff Show More