DATAREDIS-668 - Polishing.

Align JavaDoc for consistent wording. Remove superfluous final keyword from variables in DefaultSetOperations.

Replace anonymous inner classes with lambdas/method references, where possible. Remove superfluous final keywords used for local variable. Add override JavaDocs and missing Override annoations. Use diamond syntax where possible. Formatting, license headers. Reduce visibility of Default Operations implementations to package-scope.

Original pull request: #259.
This commit is contained in:
Mark Paluch
2017-07-27 15:34:32 +02:00
parent 6ef4a6f8eb
commit 65d320b3c8
180 changed files with 3592 additions and 3327 deletions

View File

@@ -32,7 +32,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
*/
public abstract class ConnectionFactoryTracker {
private static Set<Object> connFactories = new LinkedHashSet<Object>();
private static Set<Object> connFactories = new LinkedHashSet<>();
public static void add(RedisConnectionFactory factory) {
connFactories.add(factory);

View File

@@ -88,7 +88,7 @@ public class LegacyRedisCacheTests {
Collection<Object[]> params = AbstractOperationsTestParams.testParams();
Collection<Object[]> target = new ArrayList<Object[]>();
Collection<Object[]> target = new ArrayList<>();
for (Object[] source : params) {
Object[] cacheNullDisabled = Arrays.copyOf(source, source.length + 1);
@@ -179,14 +179,12 @@ public class LegacyRedisCacheTests {
cache.put(key1, value1);
cache.put(key2, value2);
Thread th = new Thread(new Runnable() {
public void run() {
cache.clear();
cache.put(k1, v1);
cache.put(k2, v2);
failed.set(v1.equals(cache.get(k1)));
Thread th = new Thread(() -> {
cache.clear();
cache.put(k1, v1);
cache.put(k2, v2);
failed.set(v1.equals(cache.get(k1)));
}
}, "concurrent-cache-access");
th.start();
th.join();
@@ -216,20 +214,14 @@ public class LegacyRedisCacheTests {
int numTries = 10;
final AtomicBoolean monitorStateException = new AtomicBoolean(false);
final CountDownLatch latch = new CountDownLatch(numTries);
Runnable clearCache = new Runnable() {
public void run() {
cache.clear();
}
};
Runnable putCache = new Runnable() {
public void run() {
try {
cache.put(key1, value1);
} catch (IllegalMonitorStateException e) {
monitorStateException.set(true);
} finally {
latch.countDown();
}
Runnable clearCache = cache::clear;
Runnable putCache = () -> {
try {
cache.put(key1, value1);
} catch (IllegalMonitorStateException e) {
monitorStateException.set(true);
} finally {
latch.countDown();
}
};
for (int i = 0; i < numTries; i++) {
@@ -355,12 +347,7 @@ public class LegacyRedisCacheTests {
assumeThat("Only suitable when cache does allow null values.", allowCacheNullValues, is(true));
Object key = getKey();
Object value = cache.get(key, new Callable<Object>() {
@Override
public Object call() throws Exception {
return null;
}
});
Object value = cache.get(key, () -> null);
assertThat(value, is(nullValue()));
assertThat(cache.get(key).get(), is(nullValue()));
@@ -372,23 +359,15 @@ public class LegacyRedisCacheTests {
assumeThat("Only suitable when cache does NOT allow null values.", allowCacheNullValues, is(false));
Object key = getKey();
Object value = cache.get(key, new Callable<Object>() {
@Override
public Object call() throws Exception {
return null;
}
});
Object value = cache.get(key, () -> null);
}
@Test(expected = ValueRetrievalException.class)
public void testCacheGetSynchronizedThrowsExceptionInValueLoader() {
Object key = getKey();
Object value = cache.get(key, new Callable<Object>() {
@Override
public Object call() throws Exception {
throw new RuntimeException("doh!");
}
Object value = cache.get(key, () -> {
throw new RuntimeException("doh!");
});
}
@@ -400,12 +379,7 @@ public class LegacyRedisCacheTests {
Object key = getKey();
cache.put(key, null);
Object cachedValue = cache.get(key, new Callable<Object>() {
@Override
public Object call() throws Exception {
return null;
}
});
Object cachedValue = cache.get(key, () -> null);
assertThat(cachedValue, is(nullValue()));
}
@@ -440,7 +414,7 @@ public class LegacyRedisCacheTests {
public void thread2() {
waitForTick(1);
assertThat(redisCache.get("key", new TestCacheLoader<String>("illegal value")), equalTo("test"));
assertThat(redisCache.get("key", new TestCacheLoader<>("illegal value")), equalTo("test"));
assertTick(2);
}
}

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Copyright 2011-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,7 +25,7 @@ import org.springframework.util.ErrorHandler;
*/
public class StubErrorHandler implements ErrorHandler {
public BlockingDeque<Throwable> throwables = new LinkedBlockingDeque<Throwable>();
public BlockingDeque<Throwable> throwables = new LinkedBlockingDeque<>();
public void handleError(Throwable t) {
throwables.add(t);

View File

@@ -27,18 +27,7 @@ import static org.springframework.data.redis.connection.RedisGeoCommands.Distanc
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
import static org.springframework.data.redis.core.ScanOptions.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque;
@@ -650,7 +639,7 @@ public abstract class AbstractConnectionIntegrationTests {
public void testPubSubWithNamedChannels() throws Exception {
final String expectedChannel = "channel1";
final String expectedMessage = "msg";
final BlockingDeque<Message> messages = new LinkedBlockingDeque<Message>();
final BlockingDeque<Message> messages = new LinkedBlockingDeque<>();
MessageListener listener = (message, pattern) -> {
messages.add(message);
@@ -659,12 +648,7 @@ public abstract class AbstractConnectionIntegrationTests {
Thread th = new Thread(() -> {
// sync to let the registration happen
waitFor(new TestCondition() {
@Override
public boolean passes() {
return connection.isSubscribed();
}
}, 2000);
waitFor(connection::isSubscribed, 2000);
try {
Thread.sleep(500);
} catch (InterruptedException o_O) {}
@@ -706,12 +690,7 @@ public abstract class AbstractConnectionIntegrationTests {
Thread th = new Thread(() -> {
// sync to let the registration happen
waitFor(new TestCondition() {
@Override
public boolean passes() {
return connection.isSubscribed();
}
}, 2000);
waitFor(connection::isSubscribed, 2000);
try {
Thread.sleep(500);
@@ -1101,7 +1080,7 @@ public abstract class AbstractConnectionIntegrationTests {
@Test
public void testMSet() {
Map<String, String> vals = new HashMap<String, String>();
Map<String, String> vals = new HashMap<>();
vals.put("color", "orange");
vals.put("size", "1");
connection.mSetString(vals);
@@ -1111,7 +1090,7 @@ public abstract class AbstractConnectionIntegrationTests {
@Test
public void testMSetNx() {
Map<String, String> vals = new HashMap<String, String>();
Map<String, String> vals = new HashMap<>();
vals.put("height", "5");
vals.put("width", "1");
actual.add(connection.mSetNXString(vals));
@@ -1122,7 +1101,7 @@ public abstract class AbstractConnectionIntegrationTests {
@Test
public void testMSetNxFailure() {
connection.set("height", "2");
Map<String, String> vals = new HashMap<String, String>();
Map<String, String> vals = new HashMap<>();
vals.put("height", "5");
vals.put("width", "1");
actual.add(connection.mSetNXString(vals));
@@ -1376,7 +1355,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sMembers("myset"));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })) }));
Arrays.asList(new Object[] { 1l, 1l, new HashSet<>(Arrays.asList(new String[] { "foo", "bar" })) }));
}
@Test
@@ -1385,7 +1364,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "baz"));
actual.add(connection.sMembers("myset"));
verifyResults(Arrays
.asList(new Object[] { 2l, 1l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
.asList(new Object[] { 2l, 1l, new HashSet<>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
}
@Test
@@ -1402,7 +1381,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sDiff("myset", "otherset"));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("foo")) }));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet<>(Collections.singletonList("foo")) }));
}
@Test
@@ -1413,7 +1392,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sDiffStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("foo")) }));
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<>(Collections.singletonList("foo")) }));
}
@Test
@@ -1422,7 +1401,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sInter("myset", "otherset"));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("bar")) }));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet<>(Collections.singletonList("bar")) }));
}
@Test
@@ -1433,7 +1412,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sInterStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("bar")) }));
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<>(Collections.singletonList("bar")) }));
}
@Test
@@ -1460,7 +1439,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sPop("myset"));
assertTrue(
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
new HashSet<>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
}
@Test // DATAREDIS-688
@@ -1479,7 +1458,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "foo"));
actual.add(connection.sAdd("myset", "bar"));
actual.add(connection.sRandMember("myset"));
assertTrue(new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains(getResults().get(2)));
assertTrue(new HashSet<>(Arrays.asList(new String[] { "foo", "bar" })).contains(getResults().get(2)));
}
@Test
@@ -1572,10 +1551,10 @@ public abstract class AbstractConnectionIntegrationTests {
@Test
public void testZAddMultiple() {
Set<StringTuple> strTuples = new HashSet<StringTuple>();
Set<StringTuple> strTuples = new HashSet<>();
strTuples.add(new DefaultStringTuple("Bob".getBytes(), "Bob", 2.0));
strTuples.add(new DefaultStringTuple("James".getBytes(), "James", 1.0));
Set<Tuple> tuples = new HashSet<Tuple>();
Set<Tuple> tuples = new HashSet<>();
tuples.add(new DefaultTuple("Joe".getBytes(), 2.5));
actual.add(connection.zAdd("myset", strTuples));
actual.add(connection.zAdd("myset".getBytes(), tuples));
@@ -1665,7 +1644,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRangeByScore("myset", 1d, 3d, 1, -1));
verifyResults(
Arrays.asList(new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList(new String[] { "Bob" })) }));
}
@Test
@@ -1673,7 +1652,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRangeByScoreWithScores("myset", 2d, 5d));
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<StringTuple>(
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
}
@@ -1682,7 +1661,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRangeByScoreWithScores("myset", 1d, 5d, 0, 1));
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<StringTuple>(
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
}
@@ -1728,7 +1707,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 3d, 0, 1));
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<StringTuple>(
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
}
@@ -1921,7 +1900,7 @@ public abstract class AbstractConnectionIntegrationTests {
@Test
public void testHMGetSet() {
Map<String, String> tuples = new HashMap<String, String>();
Map<String, String> tuples = new HashMap<>();
tuples.put("key", "foo");
tuples.put("key2", "bar");
connection.hMSet("test", tuples);

View File

@@ -31,7 +31,7 @@ import org.springframework.test.annotation.IfProfileValue;
* <p>
* Pipelined results are generally native to the provider and not transformed by our {@link RedisConnection}, so this
* test overrides {@link AbstractConnectionIntegrationTests} when result types are different
*
*
* @author Jennifer Hickey
* @author Christoph Strobl
*/
@@ -132,7 +132,7 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends Abstrac
}
protected void verifyResults(List<Object> expected) {
List<Object> expectedPipeline = new ArrayList<Object>();
List<Object> expectedPipeline = new ArrayList<>();
for (int i = 0; i < actual.size(); i++) {
expectedPipeline.add(null);
}

View File

@@ -123,7 +123,7 @@ abstract public class AbstractConnectionTransactionIntegrationTests extends Abst
}
protected void verifyResults(List<Object> expected) {
List<Object> expectedTx = new ArrayList<Object>();
List<Object> expectedTx = new ArrayList<>();
for (int i = 0; i < actual.size(); i++) {
expectedTx.add(null);
}

View File

@@ -82,37 +82,18 @@ public class ClusterCommandExecutorUnitTests {
private ClusterCommandExecutor executor;
private static final ConnectionCommandCallback<String> COMMAND_CALLBACK = new ConnectionCommandCallback<String>() {
private static final ConnectionCommandCallback<String> COMMAND_CALLBACK = Connection::theWheelWeavesAsTheWheelWills;
@Override
public String doInCluster(Connection connection) {
return connection.theWheelWeavesAsTheWheelWills();
}
};
private static final Converter<Exception, DataAccessException> exceptionConverter = source -> {
private static final Converter<Exception, DataAccessException> exceptionConverter = new Converter<Exception, DataAccessException>() {
@Override
public DataAccessException convert(Exception source) {
if (source instanceof MovedException) {
return new ClusterRedirectException(1000, ((MovedException) source).host, ((MovedException) source).port,
source);
}
return new InvalidDataAccessApiUsageException(source.getMessage(), source);
if (source instanceof MovedException) {
return new ClusterRedirectException(1000, ((MovedException) source).host, ((MovedException) source).port, source);
}
return new InvalidDataAccessApiUsageException(source.getMessage(), source);
};
private static final MultiKeyConnectionCommandCallback<String> MULTIKEY_CALLBACK = new MultiKeyConnectionCommandCallback<String>() {
@Override
public String doInCluster(Connection connection, byte[] key) {
return connection.bloodAndAshes(key);
}
};
private static final MultiKeyConnectionCommandCallback<String> MULTIKEY_CALLBACK = Connection::bloodAndAshes;
@Mock Connection con1;
@Mock Connection con2;
@@ -282,7 +263,8 @@ public class ClusterCommandExecutorUnitTests {
when(con2.bloodAndAshes(any(byte[].class))).thenReturn("mat");
when(con3.bloodAndAshes(any(byte[].class))).thenReturn("perrin");
MulitNodeResult<String> result = executor.executeMuliKeyCommand(MULTIKEY_CALLBACK, new HashSet<byte[]>(
MulitNodeResult<String> result = executor.executeMuliKeyCommand(MULTIKEY_CALLBACK,
new HashSet<>(
Arrays.asList("key-1".getBytes(), "key-2".getBytes(), "key-3".getBytes(), "key-9".getBytes())));
assertThat(result.resultsAsList(), hasItems("rand", "mat", "perrin", "egwene"));
@@ -335,7 +317,7 @@ public class ClusterCommandExecutorUnitTests {
@Override
public ClusterTopology getTopology() {
return new ClusterTopology(
new LinkedHashSet<RedisClusterNode>(Arrays.asList(CLUSTER_NODE_1, CLUSTER_NODE_2, CLUSTER_NODE_3)));
new LinkedHashSet<>(Arrays.asList(CLUSTER_NODE_1, CLUSTER_NODE_2, CLUSTER_NODE_3)));
}
}

View File

@@ -55,13 +55,13 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* Unit test of {@link DefaultStringRedisConnection}
*
* @author Jennifer Hickey
* @auhtor Christoph Strobl
* @author Christoph Strobl
* @author Ninad Divadkar
* @author Mark Paluch
*/
public class DefaultStringRedisConnectionTests {
protected List<Object> actual = new ArrayList<Object>();
protected List<Object> actual = new ArrayList<>();
@Mock protected RedisConnection nativeConnection;
@@ -85,25 +85,25 @@ public class DefaultStringRedisConnectionTests {
protected List<String> stringList = Collections.singletonList(bar);
protected Set<byte[]> bytesSet = new LinkedHashSet<byte[]>(Collections.singletonList(barBytes));
protected Set<byte[]> bytesSet = new LinkedHashSet<>(Collections.singletonList(barBytes));
protected Set<String> stringSet = new LinkedHashSet<String>(Collections.singletonList(bar));
protected Set<String> stringSet = new LinkedHashSet<>(Collections.singletonList(bar));
protected Map<byte[], byte[]> bytesMap = new HashMap<byte[], byte[]>();
protected Map<byte[], byte[]> bytesMap = new HashMap<>();
protected Map<String, String> stringMap = new HashMap<String, String>();
protected Map<String, String> stringMap = new HashMap<>();
protected Set<Tuple> tupleSet = new HashSet<Tuple>(Collections.singletonList(new DefaultTuple(barBytes, 3d)));
protected Set<Tuple> tupleSet = new HashSet<>(Collections.singletonList(new DefaultTuple(barBytes, 3d)));
protected Set<StringTuple> stringTupleSet = new HashSet<StringTuple>(
protected Set<StringTuple> stringTupleSet = new HashSet<>(
Collections.singletonList(new DefaultStringTuple(new DefaultTuple(barBytes, 3d), bar)));
protected Point point = new Point(213.00, 324.343);
protected List<Point> points = new ArrayList<Point>();
protected List<Point> points = new ArrayList<>();
protected List<GeoResult<GeoLocation<byte[]>>> geoResultList = Collections
.singletonList(new GeoResult<GeoLocation<byte[]>>(new GeoLocation<byte[]>(barBytes, null), new Distance(0D)));
protected GeoResults<GeoLocation<byte[]>> geoResults = new GeoResults<GeoLocation<byte[]>>(geoResultList);
.singletonList(new GeoResult<>(new GeoLocation<>(barBytes, null), new Distance(0D)));
protected GeoResults<GeoLocation<byte[]>> geoResults = new GeoResults<>(geoResultList);
@Before
public void setUp() {
@@ -1233,7 +1233,7 @@ public class DefaultStringRedisConnectionTests {
@Test
public void testZAddMultipleBytes() {
Set<Tuple> tuples = new HashSet<Tuple>();
Set<Tuple> tuples = new HashSet<>();
tuples.add(new DefaultTuple(barBytes, 3.0));
doReturn(1l).when(nativeConnection).zAdd(fooBytes, tuples);
actual.add(connection.zAdd(fooBytes, tuples));
@@ -1242,9 +1242,9 @@ public class DefaultStringRedisConnectionTests {
@Test
public void testZAddMultiple() {
Set<Tuple> tuples = new HashSet<Tuple>();
Set<Tuple> tuples = new HashSet<>();
tuples.add(new DefaultTuple(barBytes, 3.0));
Set<StringTuple> strTuples = new HashSet<StringTuple>();
Set<StringTuple> strTuples = new HashSet<>();
strTuples.add(new DefaultStringTuple(barBytes, bar, 3.0));
doReturn(1l).when(nativeConnection).zAdd(fooBytes, tuples);
actual.add(connection.zAdd(foo, strTuples));
@@ -1795,9 +1795,9 @@ public class DefaultStringRedisConnectionTests {
public void testGeoAddWithGeoLocationBytes() {
doReturn(1l).when(nativeConnection).geoAdd(fooBytes,
new GeoLocation<byte[]>(barBytes, new Point(1.23232, 34.2342434)));
new GeoLocation<>(barBytes, new Point(1.23232, 34.2342434)));
actual.add(connection.geoAdd(fooBytes, new GeoLocation<byte[]>(barBytes, new Point(1.23232, 34.2342434))));
actual.add(connection.geoAdd(fooBytes, new GeoLocation<>(barBytes, new Point(1.23232, 34.2342434))));
verifyResults(Collections.singletonList(1L));
}
@@ -1806,7 +1806,7 @@ public class DefaultStringRedisConnectionTests {
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes);
actual.add(connection.geoAdd(foo, new GeoLocation<String>(bar, new Point(1.23232, 34.2342434))));
actual.add(connection.geoAdd(foo, new GeoLocation<>(bar, new Point(1.23232, 34.2342434))));
verifyResults(Collections.singletonList(1L));
}
@@ -1832,7 +1832,7 @@ public class DefaultStringRedisConnectionTests {
@Test // DATAREDIS-438
public void testGeoAddWithIterableOfGeoLocationBytes() {
List<GeoLocation<byte[]>> values = Collections.singletonList(new GeoLocation<byte[]>(barBytes, new Point(1, 2)));
List<GeoLocation<byte[]>> values = Collections.singletonList(new GeoLocation<>(barBytes, new Point(1, 2)));
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, values);
actual.add(connection.geoAdd(fooBytes, values));
@@ -1844,7 +1844,7 @@ public class DefaultStringRedisConnectionTests {
doReturn(1l).when(nativeConnection).geoAdd(eq(fooBytes), anyMap());
actual.add(connection.geoAdd(foo, Collections.singletonList(new GeoLocation<String>(bar, new Point(1, 2)))));
actual.add(connection.geoAdd(foo, Collections.singletonList(new GeoLocation<>(bar, new Point(1, 2)))));
verifyResults(Collections.singletonList(1L));
}

View File

@@ -53,7 +53,8 @@ public class RedisClusterConfigurationUnitTests {
@Test // DATAREDIS-315
public void shouldCreateRedisClusterConfigurationCorrectlyGivenMultipleHostAndPortStrings() {
RedisClusterConfiguration config = new RedisClusterConfiguration(new HashSet<String>(Arrays.asList(HOST_AND_PORT_1,
RedisClusterConfiguration config = new RedisClusterConfiguration(
new HashSet<>(Arrays.asList(HOST_AND_PORT_1,
HOST_AND_PORT_2, HOST_AND_PORT_3)));
assertThat(config.getClusterNodes().size(), is(3));

View File

@@ -52,7 +52,8 @@ public class RedisSentinelConfigurationUnitTests {
@Test // DATAREDIS-372
public void shouldCreateRedisSentinelConfigurationCorrectlyGivenMasterAndMultipleHostAndPortStrings() {
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster", new HashSet<String>(Arrays.asList(
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster",
new HashSet<>(Arrays.asList(
HOST_AND_PORT_1, HOST_AND_PORT_2, HOST_AND_PORT_3)));
assertThat(config.getSentinels().size(), is(3));

View File

@@ -91,11 +91,11 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
static final byte[] VALUE_2_BYTES = JedisConverters.toBytes(VALUE_2);
static final byte[] VALUE_3_BYTES = JedisConverters.toBytes(VALUE_3);
static final GeoLocation<byte[]> ARIGENTO = new GeoLocation<byte[]>("arigento".getBytes(Charset.forName("UTF-8")),
static final GeoLocation<byte[]> ARIGENTO = new GeoLocation<>("arigento".getBytes(Charset.forName("UTF-8")),
POINT_ARIGENTO);
static final GeoLocation<byte[]> CATANIA = new GeoLocation<byte[]>("catania".getBytes(Charset.forName("UTF-8")),
static final GeoLocation<byte[]> CATANIA = new GeoLocation<>("catania".getBytes(Charset.forName("UTF-8")),
POINT_CATANIA);
static final GeoLocation<byte[]> PALERMO = new GeoLocation<byte[]>("palermo".getBytes(Charset.forName("UTF-8")),
static final GeoLocation<byte[]> PALERMO = new GeoLocation<>("palermo".getBytes(Charset.forName("UTF-8")),
POINT_PALERMO);
JedisCluster nativeConnection;
@@ -114,7 +114,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
@Before
public void setUp() throws IOException {
nativeConnection = new JedisCluster(new HashSet<HostAndPort>(CLUSTER_NODES));
nativeConnection = new JedisCluster(new HashSet<>(CLUSTER_NODES));
clusterConnection = new JedisClusterConnection(this.nativeConnection);
}
@@ -523,7 +523,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void mSetShouldWorkWhenKeysMapToSameSlot() {
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES);
map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES);
@@ -536,7 +536,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void mSetShouldWorkWhenKeysDoNotMapToSameSlot() {
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(KEY_1_BYTES, VALUE_1_BYTES);
map.put(KEY_2_BYTES, VALUE_2_BYTES);
@@ -549,7 +549,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void mSetNXShouldReturnTrueIfAllKeysSet() {
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(KEY_1_BYTES, VALUE_1_BYTES);
map.put(KEY_2_BYTES, VALUE_2_BYTES);
@@ -563,7 +563,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
public void mSetNXShouldReturnFalseIfNotAllKeysSet() {
nativeConnection.set(KEY_2_BYTES, VALUE_3_BYTES);
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(KEY_1_BYTES, VALUE_1_BYTES);
map.put(KEY_2_BYTES, VALUE_2_BYTES);
@@ -576,7 +576,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void mSetNXShouldWorkForOnSameSlotKeys() {
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES);
map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES);
@@ -1483,7 +1483,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void hMSetShouldAddValuesCorrectly() {
Map<byte[], byte[]> hashes = new HashMap<byte[], byte[]>();
Map<byte[], byte[]> hashes = new HashMap<>();
hashes.put(KEY_2_BYTES, VALUE_1_BYTES);
hashes.put(KEY_3_BYTES, VALUE_2_BYTES);
@@ -1566,7 +1566,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void hGetAllShouldRetrieveEntriesCorrectly() {
Map<byte[], byte[]> hashes = new HashMap<byte[], byte[]>();
Map<byte[], byte[]> hashes = new HashMap<>();
hashes.put(KEY_2_BYTES, VALUE_1_BYTES);
hashes.put(KEY_3_BYTES, VALUE_2_BYTES);

View File

@@ -21,6 +21,11 @@ import static org.mockito.Mockito.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.test.util.MockitoUtils.*;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.exceptions.JedisConnectionException;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashMap;
@@ -40,11 +45,6 @@ import org.springframework.data.redis.connection.RedisClusterCommands.AddSlots;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisClusterTopologyProvider;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.exceptions.JedisConnectionException;
/**
* @author Christoph Strobl
* @author Mark Paluch
@@ -87,7 +87,7 @@ public class JedisClusterConnectionUnitTests {
@Before
public void setUp() {
Map<String, JedisPool> nodes = new LinkedHashMap<String, JedisPool>(3);
Map<String, JedisPool> nodes = new LinkedHashMap<>(3);
nodes.put(CLUSTER_HOST + ":" + MASTER_NODE_1_PORT, node1PoolMock);
nodes.put(CLUSTER_HOST + ":" + MASTER_NODE_2_PORT, node2PoolMock);
nodes.put(CLUSTER_HOST + ":" + MASTER_NODE_3_PORT, node3PoolMock);

View File

@@ -18,6 +18,8 @@ package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import redis.clients.jedis.JedisPoolConfig;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -51,11 +53,9 @@ import org.springframework.data.redis.test.util.RequiresRedisSentinel;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import redis.clients.jedis.JedisPoolConfig;
/**
* Integration test of {@link JedisConnection}
*
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
@@ -142,7 +142,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
@Test
public void testZAddSameScores() {
Set<StringTuple> strTuples = new HashSet<StringTuple>();
Set<StringTuple> strTuples = new HashSet<>();
strTuples.add(new DefaultStringTuple("Bob".getBytes(), "Bob", 2.0));
strTuples.add(new DefaultStringTuple("James".getBytes(), "James", 2.0));
Long added = connection.zAdd("myset", strTuples);
@@ -204,13 +204,11 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
final String expectedChannel = "channel1";
final String expectedMessage = "msg";
final BlockingDeque<Message> messages = new LinkedBlockingDeque<Message>();
final BlockingDeque<Message> messages = new LinkedBlockingDeque<>();
MessageListener listener = new MessageListener() {
public void onMessage(Message message, byte[] pattern) {
messages.add(message);
System.out.println("Received message '" + new String(message.getBody()) + "'");
}
MessageListener listener = (message, pattern) -> {
messages.add(message);
System.out.println("Received message '" + new String(message.getBody()) + "'");
};
Thread t = new Thread() {
@@ -263,14 +261,12 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
final String expectedPattern = "channel*";
final String expectedMessage = "msg";
final BlockingDeque<Message> messages = new LinkedBlockingDeque<Message>();
final BlockingDeque<Message> messages = new LinkedBlockingDeque<>();
final MessageListener listener = new MessageListener() {
public void onMessage(Message message, byte[] pattern) {
assertEquals(expectedPattern, new String(pattern));
messages.add(message);
System.out.println("Received message '" + new String(message.getBody()) + "'");
}
final MessageListener listener = (message, pattern) -> {
assertEquals(expectedPattern, new String(pattern));
messages.add(message);
System.out.println("Received message '" + new String(message.getBody()) + "'");
};
Thread th = new Thread() {

View File

@@ -19,6 +19,11 @@ import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.ScanResult;
import java.io.IOException;
import java.util.Collections;
import java.util.Map.Entry;
@@ -38,11 +43,6 @@ import org.springframework.data.redis.connection.jedis.JedisConnectionUnitTestSu
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.ScanResult;
/**
* @author Christoph Strobl
*/
@@ -168,7 +168,7 @@ public class JedisConnectionUnitTestSuite {
@Test // DATAREDIS-531
public void scanShouldKeepTheConnectionOpen() {
doReturn(new ScanResult<String>("0", Collections.<String> emptyList())).when(jedisSpy).scan(anyString(),
doReturn(new ScanResult<>("0", Collections.<String> emptyList())).when(jedisSpy).scan(anyString(),
any(ScanParams.class));
connection.scan(ScanOptions.NONE);
@@ -179,7 +179,7 @@ public class JedisConnectionUnitTestSuite {
@Test // DATAREDIS-531
public void scanShouldCloseTheConnectionWhenCursorIsClosed() throws IOException {
doReturn(new ScanResult<String>("0", Collections.<String> emptyList())).when(jedisSpy).scan(anyString(),
doReturn(new ScanResult<>("0", Collections.<String> emptyList())).when(jedisSpy).scan(anyString(),
any(ScanParams.class));
Cursor<byte[]> cursor = connection.scan(ScanOptions.NONE);
@@ -191,7 +191,7 @@ public class JedisConnectionUnitTestSuite {
@Test // DATAREDIS-531
public void sScanShouldKeepTheConnectionOpen() {
doReturn(new ScanResult<String>("0", Collections.<String> emptyList())).when(jedisSpy).sscan(any(byte[].class),
doReturn(new ScanResult<>("0", Collections.<String> emptyList())).when(jedisSpy).sscan(any(byte[].class),
any(byte[].class), any(ScanParams.class));
connection.sScan("foo".getBytes(), ScanOptions.NONE);
@@ -202,7 +202,7 @@ public class JedisConnectionUnitTestSuite {
@Test // DATAREDIS-531
public void sScanShouldCloseTheConnectionWhenCursorIsClosed() throws IOException {
doReturn(new ScanResult<String>("0", Collections.<String> emptyList())).when(jedisSpy).sscan(any(byte[].class),
doReturn(new ScanResult<>("0", Collections.<String> emptyList())).when(jedisSpy).sscan(any(byte[].class),
any(byte[].class), any(ScanParams.class));
Cursor<byte[]> cursor = connection.sScan("foo".getBytes(), ScanOptions.NONE);
@@ -214,7 +214,7 @@ public class JedisConnectionUnitTestSuite {
@Test // DATAREDIS-531
public void zScanShouldKeepTheConnectionOpen() {
doReturn(new ScanResult<String>("0", Collections.<String> emptyList())).when(jedisSpy).zscan(any(byte[].class),
doReturn(new ScanResult<>("0", Collections.<String> emptyList())).when(jedisSpy).zscan(any(byte[].class),
any(byte[].class), any(ScanParams.class));
connection.zScan("foo".getBytes(), ScanOptions.NONE);
@@ -225,7 +225,7 @@ public class JedisConnectionUnitTestSuite {
@Test // DATAREDIS-531
public void zScanShouldCloseTheConnectionWhenCursorIsClosed() throws IOException {
doReturn(new ScanResult<String>("0", Collections.<String> emptyList())).when(jedisSpy).zscan(any(byte[].class),
doReturn(new ScanResult<>("0", Collections.<String> emptyList())).when(jedisSpy).zscan(any(byte[].class),
any(byte[].class), any(ScanParams.class));
Cursor<Tuple> cursor = connection.zScan("foo".getBytes(), ScanOptions.NONE);
@@ -237,7 +237,7 @@ public class JedisConnectionUnitTestSuite {
@Test // DATAREDIS-531
public void hScanShouldKeepTheConnectionOpen() {
doReturn(new ScanResult<String>("0", Collections.<String> emptyList())).when(jedisSpy).hscan(any(byte[].class),
doReturn(new ScanResult<>("0", Collections.<String> emptyList())).when(jedisSpy).hscan(any(byte[].class),
any(byte[].class), any(ScanParams.class));
connection.hScan("foo".getBytes(), ScanOptions.NONE);
@@ -248,7 +248,7 @@ public class JedisConnectionUnitTestSuite {
@Test // DATAREDIS-531
public void hScanShouldCloseTheConnectionWhenCursorIsClosed() throws IOException {
doReturn(new ScanResult<String>("0", Collections.<String> emptyList())).when(jedisSpy).hscan(any(byte[].class),
doReturn(new ScanResult<>("0", Collections.<String> emptyList())).when(jedisSpy).hscan(any(byte[].class),
any(byte[].class), any(ScanParams.class));
Cursor<Entry<byte[], byte[]>> cursor = connection.hScan("foo".getBytes(), ScanOptions.NONE);

View File

@@ -239,7 +239,7 @@ public class JedisConvertersUnitTests {
}
private Map<String, String> getRedisServerInfoMap(String name, int port) {
Map<String, String> map = new HashMap<String, String>();
Map<String, String> map = new HashMap<>();
map.put("name", name);
map.put("ip", "127.0.0.1");
map.put("port", Integer.toString(port));

View File

@@ -53,7 +53,7 @@ public class ScanTests {
RedisTemplate<String, String> redisOperations;
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 1, TimeUnit.MINUTES,
new LinkedBlockingDeque<Runnable>());
new LinkedBlockingDeque<>());
public ScanTests(RedisConnectionFactory factory) {
@@ -94,7 +94,7 @@ public class ScanTests {
public void contextLoads() throws InterruptedException {
BoundHashOperations<String, String, String> hash = redisOperations.boundHashOps("hash");
final AtomicReference<Exception> exception = new AtomicReference<Exception>();
final AtomicReference<Exception> exception = new AtomicReference<>();
// Create some keys so that SCAN requires a while to return all data.
for (int i = 0; i < 10000; i++) {
@@ -104,22 +104,19 @@ public class ScanTests {
// Concurrent access
for (int i = 0; i < 10; i++) {
executor.submit(new Runnable() {
@Override
public void run() {
try {
executor.submit(() -> {
try {
Cursor<Entry<Object, Object>> cursorMap = redisOperations.boundHashOps("hash")
.scan(ScanOptions.scanOptions().match("*").count(100).build());
Cursor<Entry<Object, Object>> cursorMap = redisOperations.boundHashOps("hash")
.scan(ScanOptions.scanOptions().match("*").count(100).build());
// This line invokes the lazy SCAN invocation
while (cursorMap.hasNext()) {
cursorMap.next();
}
cursorMap.close();
} catch (Exception e) {
exception.set(e);
// This line invokes the lazy SCAN invocation
while (cursorMap.hasNext()) {
cursorMap.next();
}
cursorMap.close();
} catch (Exception e) {
exception.set(e);
}
});
}

View File

@@ -88,15 +88,15 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
static final byte[] VALUE_2_BYTES = LettuceConverters.toBytes(VALUE_2);
static final byte[] VALUE_3_BYTES = LettuceConverters.toBytes(VALUE_3);
static final GeoLocation<String> ARIGENTO = new GeoLocation<String>("arigento", POINT_ARIGENTO);
static final GeoLocation<String> CATANIA = new GeoLocation<String>("catania", POINT_CATANIA);
static final GeoLocation<String> PALERMO = new GeoLocation<String>("palermo", POINT_PALERMO);
static final GeoLocation<String> ARIGENTO = new GeoLocation<>("arigento", POINT_ARIGENTO);
static final GeoLocation<String> CATANIA = new GeoLocation<>("catania", POINT_CATANIA);
static final GeoLocation<String> PALERMO = new GeoLocation<>("palermo", POINT_PALERMO);
static final GeoLocation<byte[]> ARIGENTO_BYTES = new GeoLocation<byte[]>(
static final GeoLocation<byte[]> ARIGENTO_BYTES = new GeoLocation<>(
"arigento".getBytes(Charset.forName("UTF-8")), POINT_ARIGENTO);
static final GeoLocation<byte[]> CATANIA_BYTES = new GeoLocation<byte[]>("catania".getBytes(Charset.forName("UTF-8")),
static final GeoLocation<byte[]> CATANIA_BYTES = new GeoLocation<>("catania".getBytes(Charset.forName("UTF-8")),
POINT_CATANIA);
static final GeoLocation<byte[]> PALERMO_BYTES = new GeoLocation<byte[]>("palermo".getBytes(Charset.forName("UTF-8")),
static final GeoLocation<byte[]> PALERMO_BYTES = new GeoLocation<>("palermo".getBytes(Charset.forName("UTF-8")),
POINT_PALERMO);
RedisClusterClient client;
@@ -529,7 +529,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void mSetShouldWorkWhenKeysMapToSameSlot() {
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES);
map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES);
@@ -542,7 +542,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void mSetShouldWorkWhenKeysDoNotMapToSameSlot() {
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(KEY_1_BYTES, VALUE_1_BYTES);
map.put(KEY_2_BYTES, VALUE_2_BYTES);
@@ -555,7 +555,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void mSetNXShouldReturnTrueIfAllKeysSet() {
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(KEY_1_BYTES, VALUE_1_BYTES);
map.put(KEY_2_BYTES, VALUE_2_BYTES);
@@ -569,7 +569,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
public void mSetNXShouldReturnFalseIfNotAllKeysSet() {
nativeConnection.set(KEY_2, VALUE_3);
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(KEY_1_BYTES, VALUE_1_BYTES);
map.put(KEY_2_BYTES, VALUE_2_BYTES);
@@ -582,7 +582,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void mSetNXShouldWorkForOnSameSlotKeys() {
Map<byte[], byte[]> map = new LinkedHashMap<byte[], byte[]>();
Map<byte[], byte[]> map = new LinkedHashMap<>();
map.put(SAME_SLOT_KEY_1_BYTES, VALUE_1_BYTES);
map.put(SAME_SLOT_KEY_2_BYTES, VALUE_2_BYTES);
@@ -1488,7 +1488,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void hMSetShouldAddValuesCorrectly() {
Map<byte[], byte[]> hashes = new HashMap<byte[], byte[]>();
Map<byte[], byte[]> hashes = new HashMap<>();
hashes.put(KEY_2_BYTES, VALUE_1_BYTES);
hashes.put(KEY_3_BYTES, VALUE_2_BYTES);
@@ -1571,7 +1571,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
@Test // DATAREDIS-315
public void hGetAllShouldRetrieveEntriesCorrectly() {
Map<String, String> hashes = new HashMap<String, String>();
Map<String, String> hashes = new HashMap<>();
hashes.put(KEY_2, VALUE_1);
hashes.put(KEY_3, VALUE_2);

View File

@@ -257,11 +257,7 @@ public class LettuceConnectionFactoryTests {
ConnectionFactoryTracker.add(factory2);
for (int i = 1; i < 1000; i++) {
Thread th = new Thread(new Runnable() {
public void run() {
factory2.getConnection().bRPop(50000, "foo".getBytes());
}
});
Thread th = new Thread(() -> factory2.getConnection().bRPop(50000, "foo".getBytes()));
th.start();
}
Thread.sleep(234234234);

View File

@@ -38,7 +38,6 @@ import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.RedisVersionUtils;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.TestCondition;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
@@ -53,7 +52,7 @@ import org.springframework.test.context.ContextConfiguration;
/**
* Integration test of {@link LettuceConnection}
*
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
@@ -70,14 +69,12 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testMultiThreadsOneBlocking() throws Exception {
Thread th = new Thread(new Runnable() {
public void run() {
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.openPipeline();
conn2.bLPop(3, "multilist");
conn2.closePipeline();
conn2.close();
}
Thread th = new Thread(() -> {
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.openPipeline();
conn2.bLPop(3, "multilist");
conn2.closePipeline();
conn2.close();
});
th.start();
Thread.sleep(1000);
@@ -247,32 +244,26 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
getResults();
assumeTrue(RedisVersionUtils.atLeast("2.6", byteConnection));
final AtomicBoolean scriptDead = new AtomicBoolean(false);
Thread th = new Thread(new Runnable() {
public void run() {
// Use a different factory to get a non-shared native conn for blocking script
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
factory2.setClientResources(LettuceTestClientResources.getSharedClientResources());
factory2.setShutdownTimeout(0);
factory2.afterPropertiesSet();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0);
} catch (DataAccessException e) {
scriptDead.set(true);
}
conn2.close();
factory2.destroy();
Thread th = new Thread(() -> {
// Use a different factory to get a non-shared native conn for blocking script
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
factory2.setClientResources(LettuceTestClientResources.getSharedClientResources());
factory2.setShutdownTimeout(0);
factory2.afterPropertiesSet();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0);
} catch (DataAccessException e) {
scriptDead.set(true);
}
conn2.close();
factory2.destroy();
});
th.start();
Thread.sleep(1000);
connection.scriptKill();
assertTrue(waitFor(new TestCondition() {
public boolean passes() {
return scriptDead.get();
}
}, 3000l));
assertTrue(waitFor(scriptDead::get, 3000l));
}
@Test

View File

@@ -27,7 +27,6 @@ import org.junit.runner.RunWith;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.RedisVersionUtils;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.TestCondition;
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.ReturnType;
@@ -38,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration;
/**
* Integration test of {@link LettuceConnection} pipeline functionality
*
*
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
@@ -60,32 +59,26 @@ public class LettuceConnectionPipelineIntegrationTests extends AbstractConnectio
assumeTrue(RedisVersionUtils.atLeast("2.6", byteConnection));
initConnection();
final AtomicBoolean scriptDead = new AtomicBoolean(false);
Thread th = new Thread(new Runnable() {
public void run() {
// Use separate conn factory to avoid using the underlying shared native conn on blocking script
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
factory2.setClientResources(LettuceTestClientResources.getSharedClientResources());
factory2.afterPropertiesSet();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0);
} catch (DataAccessException e) {
scriptDead.set(true);
}
conn2.close();
factory2.destroy();
Thread th = new Thread(() -> {
// Use separate conn factory to avoid using the underlying shared native conn on blocking script
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
factory2.setClientResources(LettuceTestClientResources.getSharedClientResources());
factory2.afterPropertiesSet();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0);
} catch (DataAccessException e) {
scriptDead.set(true);
}
conn2.close();
factory2.destroy();
});
th.start();
Thread.sleep(1000);
connection.scriptKill();
getResults();
assertTrue(waitFor(new TestCondition() {
public boolean passes() {
return scriptDead.get();
}
}, 3000l));
assertTrue(waitFor(scriptDead::get, 3000l));
}
@Test

View File

@@ -84,7 +84,7 @@ public class LettuceConvertersUnitTests {
io.lettuce.core.cluster.models.partitions.RedisClusterNode partition = new io.lettuce.core.cluster.models.partitions.RedisClusterNode();
partition.setNodeId(CLUSTER_NODE_1.getId());
partition.setConnected(true);
partition.setFlags(new HashSet<NodeFlag>(Arrays.asList(NodeFlag.MASTER, NodeFlag.MYSELF)));
partition.setFlags(new HashSet<>(Arrays.asList(NodeFlag.MASTER, NodeFlag.MYSELF)));
partition.setUri(RedisURI.create("redis://" + CLUSTER_HOST + ":" + MASTER_NODE_1_PORT));
partition.setSlots(Arrays.<Integer> asList(1, 2, 3, 4, 5));

View File

@@ -87,7 +87,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
StepVerifier.create(connection.zSetCommands().zRange(KEY_1_BBUFFER, new Range<Long>(1L, 2L))) //
StepVerifier.create(connection.zSetCommands().zRange(KEY_1_BBUFFER, new Range<>(1L, 2L))) //
.expectNext(VALUE_2_BBUFFER, VALUE_3_BBUFFER) //
.verifyComplete();
}
@@ -99,7 +99,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
StepVerifier.create(connection.zSetCommands().zRangeWithScores(KEY_1_BBUFFER, new Range<Long>(1L, 2L))) //
StepVerifier.create(connection.zSetCommands().zRangeWithScores(KEY_1_BBUFFER, new Range<>(1L, 2L))) //
.expectNext(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D), new DefaultTuple(VALUE_3_BBUFFER.array(), 3D)) //
.verifyComplete();
}
@@ -111,7 +111,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
StepVerifier.create(connection.zSetCommands().zRevRange(KEY_1_BBUFFER, new Range<Long>(1L, 2L))) //
StepVerifier.create(connection.zSetCommands().zRevRange(KEY_1_BBUFFER, new Range<>(1L, 2L))) //
.expectNext(VALUE_2_BBUFFER, VALUE_1_BBUFFER) //
.verifyComplete();
}
@@ -123,7 +123,7 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
nativeCommands.zadd(KEY_1, 3D, VALUE_3);
StepVerifier.create(connection.zSetCommands().zRevRangeWithScores(KEY_1_BBUFFER, new Range<Long>(1L, 2L))) //
StepVerifier.create(connection.zSetCommands().zRevRangeWithScores(KEY_1_BBUFFER, new Range<>(1L, 2L))) //
.expectNext(new DefaultTuple(VALUE_2_BBUFFER.array(), 2D), new DefaultTuple(VALUE_1_BBUFFER.array(), 1D)) //
.verifyComplete();
}

View File

@@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
* A {@link io.lettuce.core.resource.EventLoopGroupProvider} suitable for testing. Preserves the event loop groups
* between tests. Every time a new {@link TestEventLoopGroupProvider} instance is created, a
* {@link Runtime#addShutdownHook(Thread) shutdown hook} is added to close the resources.
*
*
* @author Mark Paluch
* @author Christoph Strobl
*/
@@ -54,7 +54,7 @@ class TestEventLoopGroupProvider extends DefaultEventLoopGroupProvider {
@Override
public Promise<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit) {
DefaultPromise<Boolean> result = new DefaultPromise<Boolean>(ImmediateEventExecutor.INSTANCE);
DefaultPromise<Boolean> result = new DefaultPromise<>(ImmediateEventExecutor.INSTANCE);
result.setSuccess(true);
return result;

View File

@@ -104,7 +104,7 @@ abstract public class AbstractOperationsTestParams {
xstreamPersonTemplate.setValueSerializer(serializer);
xstreamPersonTemplate.afterPropertiesSet();
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<>();
jackson2JsonPersonTemplate.setConnectionFactory(jedisConnectionFactory);
jackson2JsonPersonTemplate.setValueSerializer(jackson2JsonSerializer);

View File

@@ -32,7 +32,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisClusterCommands.AddSlots;
import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisClusterNode;
@@ -69,19 +68,19 @@ public class DefaultClusterOperationsUnitTests {
serializer = new StringRedisSerializer();
RedisTemplate<String, String> template = new RedisTemplate<String, String>();
RedisTemplate<String, String> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
template.setValueSerializer(serializer);
template.setKeySerializer(serializer);
template.afterPropertiesSet();
this.clusterOps = new DefaultClusterOperations<String, String>(template);
this.clusterOps = new DefaultClusterOperations<>(template);
}
@Test // DATAREDIS-315
public void keysShouldDelegateToConnectionCorrectly() {
Set<byte[]> keys = new HashSet<byte[]>(Arrays.asList(serializer.serialize("key-1"), serializer.serialize("key-2")));
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"));
@@ -255,13 +254,7 @@ public class DefaultClusterOperationsUnitTests {
public void executeShouldDelegateToConnection() {
final byte[] key = serializer.serialize("foo");
clusterOps.execute(new RedisClusterCallback<String>() {
@Override
public String doInRedis(RedisClusterConnection connection) throws DataAccessException {
return serializer.deserialize(connection.get(key));
}
});
clusterOps.execute(connection -> serializer.deserialize(connection.get(key)));
verify(connection, times(1)).get(eq(key));
}

View File

@@ -43,7 +43,6 @@ import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.serializer.RedisSerializer;
@@ -105,11 +104,9 @@ public class DefaultGeoOperationsTests<K, M> {
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@@ -124,7 +121,7 @@ public class DefaultGeoOperationsTests<K, M> {
@Test // DATAREDIS-438
public void testGeoAddWithLocationMap() {
Map<M, Point> memberCoordinateMap = new HashMap<M, Point>();
Map<M, Point> memberCoordinateMap = new HashMap<>();
memberCoordinateMap.put(valueFactory.instance(), POINT_PALERMO);
memberCoordinateMap.put(valueFactory.instance(), POINT_CATANIA);

View File

@@ -36,14 +36,13 @@ import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RawObjectFactory;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test of {@link DefaultHashOperations}
*
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @param <K> Key type
@@ -90,7 +89,7 @@ public class DefaultHashOperationsTests<K, HK, HV> {
stringTemplate.setConnectionFactory(jedisConnectionFactory);
stringTemplate.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<>();
rawTemplate.setConnectionFactory(jedisConnectionFactory);
rawTemplate.setEnableDefaultSerializer(false);
rawTemplate.afterPropertiesSet();
@@ -111,11 +110,9 @@ public class DefaultHashOperationsTests<K, HK, HV> {
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}

View File

@@ -30,7 +30,6 @@ 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.connection.RedisConnection;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
@@ -78,11 +77,9 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}

View File

@@ -34,11 +34,10 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.connection.RedisConnection;
/**
* Integration test of {@link DefaultListOperations}
*
*
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
@@ -83,11 +82,9 @@ public class DefaultListOperationsTests<K, V> {
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}

View File

@@ -158,7 +158,7 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
Map<K, V> map = new LinkedHashMap<K, V>();
Map<K, V> map = new LinkedHashMap<>();
map.put(key1, value1);
map.put(key2, value2);
@@ -176,7 +176,7 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
Map<K, V> map = new LinkedHashMap<K, V>();
Map<K, V> map = new LinkedHashMap<>();
map.put(key1, value1);
@@ -235,7 +235,7 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
absentValue = (V) ByteBuffer.wrap(new byte[0]);
}
Map<K, V> map = new LinkedHashMap<K, V>();
Map<K, V> map = new LinkedHashMap<>();
map.put(key1, value1);
map.put(key2, value2);

View File

@@ -344,7 +344,7 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete();
StepVerifier.create(zSetOperations.reverseRangeByScoreWithScores(key, new Range<>(9d, 11d))) //
.expectNext(new DefaultTypedTuple<V>(value2, 10d)) //
.expectNext(new DefaultTypedTuple<>(value2, 10d)) //
.verifyComplete();
}
@@ -396,9 +396,9 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
StepVerifier.create(zSetOperations.add(key, value1, 42.1)).expectNext(true).verifyComplete();
StepVerifier.create(zSetOperations.add(key, value2, 10)).expectNext(true).verifyComplete();
StepVerifier.create(zSetOperations.count(key, new Range<Double>(0d, 100d))).expectNext(2L).expectComplete()
StepVerifier.create(zSetOperations.count(key, new Range<>(0d, 100d))).expectNext(2L).expectComplete()
.verify();
StepVerifier.create(zSetOperations.count(key, new Range<Double>(0d, 10d))).expectNext(1L).verifyComplete();
StepVerifier.create(zSetOperations.count(key, new Range<>(0d, 10d))).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-602

View File

@@ -16,7 +16,7 @@
package org.springframework.data.redis.core;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
@@ -29,7 +29,6 @@ import java.util.List;
import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.hamcrest.collection.IsCollectionWithSize;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -41,13 +40,12 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test of {@link DefaultSetOperations}
*
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Thomas Darimont
@@ -92,11 +90,9 @@ public class DefaultSetOperationsTests<K, V> {
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@@ -113,7 +109,7 @@ public class DefaultSetOperationsTests<K, V> {
setOps.add(setKey, v3);
Set<V> members = setOps.distinctRandomMembers(setKey, 2);
assertEquals(2, members.size());
Set<V> expected = new HashSet<V>();
Set<V> expected = new HashSet<>();
expected.add(v1);
expected.add(v2);
expected.add(v3);
@@ -163,8 +159,8 @@ public class DefaultSetOperationsTests<K, V> {
setOps.add(key1, v1);
setOps.add(key1, v2);
setOps.move(key1, v1, key2);
assertThat(setOps.members(key1), isEqual(new HashSet<V>(Collections.singletonList(v2))));
assertThat(setOps.members(key2), isEqual(new HashSet<V>(Collections.singletonList(v1))));
assertThat(setOps.members(key1), isEqual(new HashSet<>(Collections.singletonList(v2))));
assertThat(setOps.members(key2), isEqual(new HashSet<>(Collections.singletonList(v1))));
}
@SuppressWarnings("unchecked")
@@ -207,7 +203,7 @@ public class DefaultSetOperationsTests<K, V> {
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
assertEquals(Long.valueOf(2), setOps.add(key, v1, v2));
Set<V> expected = new HashSet<V>();
Set<V> expected = new HashSet<>();
expected.add(v1);
expected.add(v2);
assertThat(setOps.members(key), isEqual(expected));

View File

@@ -26,10 +26,10 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
*/
public class DefaultTypedTupleUnitTests {
private static final TypedTuple<String> WITH_SCORE_1 = new DefaultTypedTuple<String>("foo", 1D);
private static final TypedTuple<String> ANOTHER_ONE_WITH_SCORE_1 = new DefaultTypedTuple<String>("another", 1D);
private static final TypedTuple<String> WITH_SCORE_2 = new DefaultTypedTuple<String>("bar", 2D);
private static final TypedTuple<String> WITH_SCORE_NULL = new DefaultTypedTuple<String>("foo", null);
private static final TypedTuple<String> WITH_SCORE_1 = new DefaultTypedTuple<>("foo", 1D);
private static final TypedTuple<String> ANOTHER_ONE_WITH_SCORE_1 = new DefaultTypedTuple<>("another", 1D);
private static final TypedTuple<String> WITH_SCORE_2 = new DefaultTypedTuple<>("bar", 2D);
private static final TypedTuple<String> WITH_SCORE_NULL = new DefaultTypedTuple<>("foo", null);
@Test // DATAREDIS-294
public void compareToShouldUseScore() {

View File

@@ -39,12 +39,10 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.TestCondition;
import org.springframework.data.redis.connection.RedisConnection;
/**
* Integration test of {@link DefaultValueOperations}
*
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author David Liu
@@ -88,11 +86,9 @@ public class DefaultValueOperationsTests<K, V> {
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@@ -126,7 +122,7 @@ public class DefaultValueOperationsTests<K, V> {
@Test
public void testMultiSetIfAbsent() {
Map<K, V> keysAndValues = new HashMap<K, V>();
Map<K, V> keysAndValues = new HashMap<>();
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -134,7 +130,7 @@ 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<V>(keysAndValues.values())));
assertThat(valueOps.multiGet(keysAndValues.keySet()), isEqual(new ArrayList<>(keysAndValues.values())));
}
@Test
@@ -145,7 +141,7 @@ public class DefaultValueOperationsTests<K, V> {
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
valueOps.set(key1, value1);
Map<K, V> keysAndValues = new HashMap<K, V>();
Map<K, V> keysAndValues = new HashMap<>();
keysAndValues.put(key1, value2);
keysAndValues.put(key2, value3);
assertFalse(valueOps.multiSetIfAbsent(keysAndValues));
@@ -153,7 +149,7 @@ public class DefaultValueOperationsTests<K, V> {
@Test
public void testMultiSet() {
Map<K, V> keysAndValues = new HashMap<K, V>();
Map<K, V> keysAndValues = new HashMap<>();
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -161,7 +157,7 @@ public class DefaultValueOperationsTests<K, V> {
keysAndValues.put(key1, value1);
keysAndValues.put(key2, value2);
valueOps.multiSet(keysAndValues);
assertThat(valueOps.multiGet(keysAndValues.keySet()), isEqual(new ArrayList<V>(keysAndValues.values())));
assertThat(valueOps.multiGet(keysAndValues.keySet()), isEqual(new ArrayList<>(keysAndValues.values())));
}
@Test
@@ -187,11 +183,7 @@ public class DefaultValueOperationsTests<K, V> {
final K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
valueOps.set(key1, value1, 1, TimeUnit.SECONDS);
waitFor(new TestCondition() {
public boolean passes() {
return (!redisTemplate.hasKey(key1));
}
}, 1000);
waitFor(() -> (!redisTemplate.hasKey(key1)), 1000);
}
@Test // DATAREDIS-271
@@ -201,11 +193,7 @@ public class DefaultValueOperationsTests<K, V> {
final K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
valueOps.set(key1, value1, 1, TimeUnit.MILLISECONDS);
waitFor(new TestCondition() {
public boolean passes() {
return (!redisTemplate.hasKey(key1));
}
}, 500);
waitFor(() -> (!redisTemplate.hasKey(key1)), 500);
}
@Test

View File

@@ -43,7 +43,6 @@ import org.springframework.data.redis.DoubleObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
import org.springframework.data.redis.LongObjectFactory;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
@@ -51,7 +50,7 @@ import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test of {@link DefaultZSetOperations}
*
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Mark Paluch
@@ -98,11 +97,9 @@ public class DefaultZSetOperationsTests<K, V> {
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@@ -125,7 +122,7 @@ public class DefaultZSetOperationsTests<K, V> {
Set<TypedTuple<V>> values = zSetOps.rangeWithScores(key1, 0, -1);
assertEquals(1, values.size());
TypedTuple<V> tuple = values.iterator().next();
assertEquals(new DefaultTypedTuple<V>(value1, 5.7), tuple);
assertEquals(new DefaultTypedTuple<>(value1, 5.7), tuple);
}
@Test
@@ -153,7 +150,7 @@ public class DefaultZSetOperationsTests<K, V> {
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<V>(value1, 1.9)));
assertThat(tuple, isEqual(new DefaultTypedTuple<>(value1, 1.9)));
}
@Test
@@ -180,7 +177,7 @@ public class DefaultZSetOperationsTests<K, V> {
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<V>(value2, 3.7)));
assertThat(tuple, isEqual(new DefaultTypedTuple<>(value2, 3.7)));
}
@Test // DATAREDIS-407
@@ -275,12 +272,12 @@ public class DefaultZSetOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
Set<TypedTuple<V>> values = new HashSet<TypedTuple<V>>();
values.add(new DefaultTypedTuple<V>(value1, 1.7));
values.add(new DefaultTypedTuple<V>(value2, 3.2));
values.add(new DefaultTypedTuple<V>(value3, 0.8));
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<V>();
Set<V> expected = new LinkedHashSet<>();
expected.add(value3);
expected.add(value1);
expected.add(value2);
@@ -293,13 +290,13 @@ public class DefaultZSetOperationsTests<K, V> {
V value1 = valueFactory.instance();
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
Set<TypedTuple<V>> values = new HashSet<TypedTuple<V>>();
values.add(new DefaultTypedTuple<V>(value1, 1.7));
values.add(new DefaultTypedTuple<V>(value2, 3.2));
values.add(new DefaultTypedTuple<V>(value3, 0.8));
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<V>();
Set<V> expected = new LinkedHashSet<>();
expected.add(value2);
assertThat(zSetOps.range(key, 0, -1), isEqual(expected));
}
@@ -312,10 +309,10 @@ public class DefaultZSetOperationsTests<K, V> {
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
Set<TypedTuple<V>> values = new HashSet<TypedTuple<V>>();
values.add(new DefaultTypedTuple<V>(value1, 1.7));
values.add(new DefaultTypedTuple<V>(value2, 3.2));
values.add(new DefaultTypedTuple<V>(value3, 0.8));
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));
zSetOps.add(key, values);
assertThat(zSetOps.zCard(key), equalTo(3L));
@@ -329,10 +326,10 @@ public class DefaultZSetOperationsTests<K, V> {
V value2 = valueFactory.instance();
V value3 = valueFactory.instance();
Set<TypedTuple<V>> values = new HashSet<TypedTuple<V>>();
values.add(new DefaultTypedTuple<V>(value1, 1.7));
values.add(new DefaultTypedTuple<V>(value2, 3.2));
values.add(new DefaultTypedTuple<V>(value3, 0.8));
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));
zSetOps.add(key, values);
assertThat(zSetOps.size(key), equalTo(3L));
@@ -344,9 +341,9 @@ public class DefaultZSetOperationsTests<K, V> {
K key = keyFactory.instance();
final TypedTuple<V> tuple1 = new DefaultTypedTuple<V>(valueFactory.instance(), 1.7);
final TypedTuple<V> tuple2 = new DefaultTypedTuple<V>(valueFactory.instance(), 3.2);
final TypedTuple<V> tuple3 = new DefaultTypedTuple<V>(valueFactory.instance(), 0.8);
final TypedTuple<V> tuple1 = new DefaultTypedTuple<>(valueFactory.instance(), 1.7);
final TypedTuple<V> tuple2 = new DefaultTypedTuple<>(valueFactory.instance(), 3.2);
final TypedTuple<V> tuple3 = new DefaultTypedTuple<>(valueFactory.instance(), 0.8);
Set<TypedTuple<V>> values = new HashSet<TypedTuple<V>>() {
{

View File

@@ -45,7 +45,7 @@ import org.springframework.util.ObjectUtils;
/**
* @author Christoph Strobl
* @auhtor Rob Winch
* @author Rob Winch
*/
@RunWith(MockitoJUnitRunner.Silent.class)
public class IndexWriterUnitTests {
@@ -100,7 +100,7 @@ public class IndexWriterUnitTests {
byte[] indexKey2 = "persons:firstname:mat".getBytes(CHARSET);
when(connectionMock.keys(any(byte[].class)))
.thenReturn(new LinkedHashSet<byte[]>(Arrays.asList(indexKey1, indexKey2)));
.thenReturn(new LinkedHashSet<>(Arrays.asList(indexKey1, indexKey2)));
writer.removeKeyFromExistingIndexes(KEY_BIN, new StubIndxedData());
@@ -120,7 +120,7 @@ public class IndexWriterUnitTests {
byte[] indexKey2 = "persons:firstname:mat".getBytes(CHARSET);
when(connectionMock.keys(any(byte[].class)))
.thenReturn(new LinkedHashSet<byte[]>(Arrays.asList(indexKey1, indexKey2)));
.thenReturn(new LinkedHashSet<>(Arrays.asList(indexKey1, indexKey2)));
writer.removeAllIndexes(KEYSPACE);
@@ -159,7 +159,7 @@ public class IndexWriterUnitTests {
public void createIndexShouldNotTryToRemoveExistingValues() {
when(connectionMock.keys(any(byte[].class)))
.thenReturn(new LinkedHashSet<byte[]>(Arrays.asList("persons:firstname:rand".getBytes(CHARSET))));
.thenReturn(new LinkedHashSet<>(Arrays.asList("persons:firstname:rand".getBytes(CHARSET))));
writer.createIndexes(KEY_BIN,
Collections.<IndexedData> singleton(new SimpleIndexedPropertyValue(KEYSPACE, "firstname", "Rand")));
@@ -174,7 +174,7 @@ public class IndexWriterUnitTests {
public void updateIndexShouldRemoveExistingValues() {
when(connectionMock.keys(any(byte[].class)))
.thenReturn(new LinkedHashSet<byte[]>(Arrays.asList("persons:firstname:rand".getBytes(CHARSET))));
.thenReturn(new LinkedHashSet<>(Arrays.asList("persons:firstname:rand".getBytes(CHARSET))));
writer.updateIndexes(KEY_BIN,
Collections.<IndexedData> singleton(new SimpleIndexedPropertyValue(KEYSPACE, "firstname", "Rand")));
@@ -190,7 +190,7 @@ public class IndexWriterUnitTests {
byte[] indexKey1 = "persons:location".getBytes(CHARSET);
when(connectionMock.keys(any(byte[].class))).thenReturn(new LinkedHashSet<byte[]>(Arrays.asList(indexKey1)));
when(connectionMock.keys(any(byte[].class))).thenReturn(new LinkedHashSet<>(Arrays.asList(indexKey1)));
writer.removeKeyFromExistingIndexes(KEY_BIN, new GeoIndexedPropertyValue(KEYSPACE, "address.city", null));

View File

@@ -72,20 +72,14 @@ public class MultithreadedRedisTemplateTests {
@Test // DATAREDIS-300
public void assertResouresAreReleasedProperlyWhenSharingRedisTemplate() throws InterruptedException {
final RedisTemplate<Object, Object> template = new RedisTemplate<Object, Object>();
final RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
template.afterPropertiesSet();
ExecutorService executor = Executors.newCachedThreadPool();
for (int i = 0; i < 9; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
template.boundValueOps("foo").get();
}
});
executor.execute(template.boundValueOps("foo")::get);
}
executor.shutdown();

View File

@@ -157,7 +157,7 @@ public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
}
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
// JEDIS
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(new RedisClusterConfiguration(
@@ -165,32 +165,32 @@ public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
jedisConnectionFactory.afterPropertiesSet();
RedisTemplate<String, String> jedisStringTemplate = new RedisTemplate<String, String>();
RedisTemplate<String, String> jedisStringTemplate = new RedisTemplate<>();
jedisStringTemplate.setDefaultSerializer(new StringRedisSerializer());
jedisStringTemplate.setConnectionFactory(jedisConnectionFactory);
jedisStringTemplate.afterPropertiesSet();
RedisTemplate<String, Long> jedisLongTemplate = new RedisTemplate<String, Long>();
RedisTemplate<String, Long> jedisLongTemplate = new RedisTemplate<>();
jedisLongTemplate.setKeySerializer(new StringRedisSerializer());
jedisLongTemplate.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
jedisLongTemplate.setValueSerializer(new GenericToStringSerializer<>(Long.class));
jedisLongTemplate.setConnectionFactory(jedisConnectionFactory);
jedisLongTemplate.afterPropertiesSet();
RedisTemplate<byte[], byte[]> jedisRawTemplate = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> jedisRawTemplate = new RedisTemplate<>();
jedisRawTemplate.setEnableDefaultSerializer(false);
jedisRawTemplate.setConnectionFactory(jedisConnectionFactory);
jedisRawTemplate.afterPropertiesSet();
RedisTemplate<String, Person> jedisPersonTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> jedisPersonTemplate = new RedisTemplate<>();
jedisPersonTemplate.setConnectionFactory(jedisConnectionFactory);
jedisPersonTemplate.afterPropertiesSet();
RedisTemplate<String, String> jedisXstreamStringTemplate = new RedisTemplate<String, String>();
RedisTemplate<String, String> jedisXstreamStringTemplate = new RedisTemplate<>();
jedisXstreamStringTemplate.setConnectionFactory(jedisConnectionFactory);
jedisXstreamStringTemplate.setDefaultSerializer(serializer);
jedisXstreamStringTemplate.afterPropertiesSet();
RedisTemplate<String, Person> jedisJackson2JsonPersonTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> jedisJackson2JsonPersonTemplate = new RedisTemplate<>();
jedisJackson2JsonPersonTemplate.setConnectionFactory(jedisConnectionFactory);
jedisJackson2JsonPersonTemplate.setValueSerializer(jackson2JsonSerializer);
jedisJackson2JsonPersonTemplate.afterPropertiesSet();
@@ -203,32 +203,32 @@ public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
lettuceConnectionFactory.afterPropertiesSet();
RedisTemplate<String, String> lettuceStringTemplate = new RedisTemplate<String, String>();
RedisTemplate<String, String> lettuceStringTemplate = new RedisTemplate<>();
lettuceStringTemplate.setDefaultSerializer(new StringRedisSerializer());
lettuceStringTemplate.setConnectionFactory(lettuceConnectionFactory);
lettuceStringTemplate.afterPropertiesSet();
RedisTemplate<String, Long> lettuceLongTemplate = new RedisTemplate<String, Long>();
RedisTemplate<String, Long> lettuceLongTemplate = new RedisTemplate<>();
lettuceLongTemplate.setKeySerializer(new StringRedisSerializer());
lettuceLongTemplate.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
lettuceLongTemplate.setValueSerializer(new GenericToStringSerializer<>(Long.class));
lettuceLongTemplate.setConnectionFactory(lettuceConnectionFactory);
lettuceLongTemplate.afterPropertiesSet();
RedisTemplate<byte[], byte[]> lettuceRawTemplate = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> lettuceRawTemplate = new RedisTemplate<>();
lettuceRawTemplate.setEnableDefaultSerializer(false);
lettuceRawTemplate.setConnectionFactory(lettuceConnectionFactory);
lettuceRawTemplate.afterPropertiesSet();
RedisTemplate<String, Person> lettucePersonTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> lettucePersonTemplate = new RedisTemplate<>();
lettucePersonTemplate.setConnectionFactory(lettuceConnectionFactory);
lettucePersonTemplate.afterPropertiesSet();
RedisTemplate<String, String> lettuceXstreamStringTemplate = new RedisTemplate<String, String>();
RedisTemplate<String, String> lettuceXstreamStringTemplate = new RedisTemplate<>();
lettuceXstreamStringTemplate.setConnectionFactory(lettuceConnectionFactory);
lettuceXstreamStringTemplate.setDefaultSerializer(serializer);
lettuceXstreamStringTemplate.afterPropertiesSet();
RedisTemplate<String, Person> lettuceJackson2JsonPersonTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> lettuceJackson2JsonPersonTemplate = new RedisTemplate<>();
lettuceJackson2JsonPersonTemplate.setConnectionFactory(lettuceConnectionFactory);
lettuceJackson2JsonPersonTemplate.setValueSerializer(jackson2JsonSerializer);
lettuceJackson2JsonPersonTemplate.afterPropertiesSet();

View File

@@ -38,7 +38,6 @@ 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.dao.DataAccessException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Reference;
import org.springframework.data.geo.Point;
@@ -65,7 +64,7 @@ import org.springframework.data.redis.core.mapping.RedisMappingContext;
@RunWith(Parameterized.class)
public class RedisKeyValueAdapterTests {
private static Set<RedisConnectionFactory> initializedFactories = new HashSet<RedisConnectionFactory>();
private static Set<RedisConnectionFactory> initializedFactories = new HashSet<>();
RedisKeyValueAdapter adapter;
StringRedisTemplate template;
@@ -109,13 +108,9 @@ public class RedisKeyValueAdapterTests {
adapter.setEnableKeyspaceEvents(EnableKeyspaceEvents.ON_STARTUP);
adapter.afterPropertiesSet();
template.execute(new RedisCallback<Void>() {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
connection.flushDb();
return null;
}
template.execute((RedisCallback<Void>) connection -> {
connection.flushDb();
return null;
});
RedisConnection connection = template.getConnectionFactory().getConnection();
@@ -192,7 +187,7 @@ public class RedisKeyValueAdapterTests {
@Test // DATAREDIS-425
public void getShouldReadSimpleObjectCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("_class", Person.class.getName());
map.put("age", "24");
template.opsForHash().putAll("persons:load-1", map);
@@ -206,7 +201,7 @@ public class RedisKeyValueAdapterTests {
@Test // DATAREDIS-425
public void getShouldReadNestedObjectCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("_class", Person.class.getName());
map.put("address.country", "Andor");
template.opsForHash().putAll("persons:load-1", map);
@@ -220,7 +215,7 @@ public class RedisKeyValueAdapterTests {
@Test // DATAREDIS-425
public void couldReadsKeyspaceSizeCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("_class", Person.class.getName());
map.put("address.country", "Andor");
template.opsForHash().putAll("persons:load-1", map);
@@ -233,7 +228,7 @@ public class RedisKeyValueAdapterTests {
@Test // DATAREDIS-425
public void deleteRemovesEntriesCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("_class", Person.class.getName());
map.put("address.country", "Andor");
template.opsForHash().putAll("persons:1", map);
@@ -248,7 +243,7 @@ public class RedisKeyValueAdapterTests {
@Test // DATAREDIS-425
public void deleteCleansIndexedDataCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("_class", Person.class.getName());
map.put("firstname", "rand");
map.put("address.country", "Andor");
@@ -267,7 +262,7 @@ public class RedisKeyValueAdapterTests {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("_class", Person.class.getName());
map.put("firstname", "rand");
map.put("address.country", "Andor");
@@ -295,7 +290,7 @@ public class RedisKeyValueAdapterTests {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("_class", Person.class.getName());
map.put("firstname", "rand");
map.put("address.country", "Andor");
@@ -363,7 +358,7 @@ public class RedisKeyValueAdapterTests {
assertThat(template.hasKey("persons:firstname:rand"), is(true));
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.set("firstname", "mat");
adapter.update(update);
@@ -383,7 +378,7 @@ public class RedisKeyValueAdapterTests {
assertThat(template.hasKey("persons:address.country:andor"), is(true));
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class);
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class);
Address addressUpdate = new Address();
addressUpdate.country = "tear";
@@ -406,7 +401,7 @@ public class RedisKeyValueAdapterTests {
assertThat(template.hasKey("persons:address.country:andor"), is(true));
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.set("address.country", "tear");
adapter.update(update);
@@ -425,7 +420,7 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.del("address");
adapter.update(update);
@@ -443,7 +438,7 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.del("nicknames");
adapter.update(update);
@@ -468,7 +463,7 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.del("coworkers");
adapter.update(update);
@@ -487,7 +482,7 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.del("physicalAttributes");
adapter.update(update);
@@ -506,7 +501,7 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", rand, "persons");
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.del("relatives");
adapter.update(update);
@@ -555,7 +550,7 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", tam, "persons");
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.del("address.location");
adapter.update(update);
@@ -574,7 +569,7 @@ public class RedisKeyValueAdapterTests {
adapter.put("1", tam, "persons");
PartialUpdate<Person> update = new PartialUpdate<Person>("1", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("1", Person.class) //
.set("address.location", new Point(17, 18));
adapter.update(update);

View File

@@ -66,7 +66,7 @@ public class RedisKeyValueAdapterUnitTests {
@Before
public void setUp() throws Exception {
template = new RedisTemplate<Object, Object>();
template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactoryMock);
template.afterPropertiesSet();
@@ -104,7 +104,7 @@ public class RedisKeyValueAdapterUnitTests {
rd.addIndexedData(new SimpleIndexedPropertyValue("persons", "firstname", "rand"));
when(redisConnectionMock.sMembers(Mockito.any(byte[].class)))
.thenReturn(new LinkedHashSet<byte[]>(Arrays.asList("persons:firstname:rand".getBytes())));
.thenReturn(new LinkedHashSet<>(Arrays.asList("persons:firstname:rand".getBytes())));
when(redisConnectionMock.del((byte[][]) any())).thenReturn(1L);
adapter.put("1", rd, "persons");
@@ -119,7 +119,7 @@ public class RedisKeyValueAdapterUnitTests {
rd.addIndexedData(new SimpleIndexedPropertyValue("persons", "firstname", "rand"));
when(redisConnectionMock.sMembers(Mockito.any(byte[].class)))
.thenReturn(new LinkedHashSet<byte[]>(Arrays.asList("persons:firstname:rand".getBytes())));
.thenReturn(new LinkedHashSet<>(Arrays.asList("persons:firstname:rand".getBytes())));
when(redisConnectionMock.del((byte[][]) any())).thenReturn(0L);
adapter.put("1", rd, "persons");

View File

@@ -37,10 +37,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataAccessException;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
@@ -92,7 +90,7 @@ public class RedisKeyValueTemplateTests {
@Before
public void setUp() {
nativeTemplate = new RedisTemplate<Object, Object>();
nativeTemplate = new RedisTemplate<>();
nativeTemplate.setConnectionFactory(connectionFactory);
nativeTemplate.afterPropertiesSet();
@@ -104,14 +102,10 @@ public class RedisKeyValueTemplateTests {
@After
public void tearDown() throws Exception {
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
connection.flushDb();
return null;
}
connection.flushDb();
return null;
});
template.destroy();
@@ -126,14 +120,10 @@ public class RedisKeyValueTemplateTests {
template.insert(rand);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
assertThat(connection.exists(("template-test-person:" + rand.id).getBytes()), is(true));
return null;
}
assertThat(connection.exists(("template-test-person:" + rand.id).getBytes()), is(true));
return null;
});
}
@@ -149,13 +139,7 @@ public class RedisKeyValueTemplateTests {
template.insert(rand);
template.insert(mat);
List<Person> result = template.find(new RedisCallback<byte[]>() {
@Override
public byte[] doInRedis(RedisConnection connection) throws DataAccessException {
return mat.id.getBytes();
}
}, Person.class);
List<Person> result = template.find(connection -> mat.id.getBytes(), Person.class);
assertThat(result.size(), is(1));
assertThat(result, hasItems(mat));
@@ -173,13 +157,8 @@ public class RedisKeyValueTemplateTests {
template.insert(rand);
template.insert(mat);
List<Person> result = template.find(new RedisCallback<List<byte[]>>() {
@Override
public List<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
return Arrays.asList(rand.id.getBytes(), mat.id.getBytes());
}
}, Person.class);
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));
@@ -197,13 +176,7 @@ public class RedisKeyValueTemplateTests {
template.insert(rand);
template.insert(mat);
List<Person> result = template.find(new RedisCallback<List<byte[]>>() {
@Override
public List<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
return null;
}
}, Person.class);
List<Person> result = template.find(connection -> null, Person.class);
assertThat(result.size(), is(0));
}
@@ -220,84 +193,68 @@ public class RedisKeyValueTemplateTests {
* Set the lastname and make sure we've an index on it afterwards
*/
Person update1 = new Person(rand.id, null, "al-thor");
PartialUpdate<Person> update = new PartialUpdate<Person>(rand.id, update1);
PartialUpdate<Person> update = new PartialUpdate<>(rand.id, update1);
template.insert(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, "rand", "al-thor")))));
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
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));
return null;
}
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));
return null;
});
/*
* Set the firstname and make sure lastname index and value is not affected
*/
update = new PartialUpdate<Person>(rand.id, Person.class).set("firstname", "frodo");
update = new PartialUpdate<>(rand.id, Person.class).set("firstname", "frodo");
template.update(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, "frodo", "al-thor")))));
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
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));
return null;
}
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));
return null;
});
/*
* Remote firstname and update lastname. Make sure lastname index is updated
*/
update = new PartialUpdate<Person>(rand.id, Person.class) //
update = new PartialUpdate<>(rand.id, Person.class) //
.del("firstname").set("lastname", "baggins");
template.doPartialUpdate(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, null, "baggins")))));
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
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));
return null;
}
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));
return null;
});
/*
* Remove lastname and make sure the index vanishes
*/
update = new PartialUpdate<Person>(rand.id, Person.class) //
update = new PartialUpdate<>(rand.id, Person.class) //
.del("lastname");
template.doPartialUpdate(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, null, null)))));
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
assertThat(connection.keys("template-test-person:lastname:*".getBytes()).size(), is(0));
return null;
}
assertThat(connection.keys("template-test-person:lastname:*".getBytes()).size(), is(0));
return null;
});
}
@@ -309,22 +266,18 @@ public class RedisKeyValueTemplateTests {
template.insert(source);
PartialUpdate<VariousTypes> update = new PartialUpdate<VariousTypes>(source.id, VariousTypes.class) //
PartialUpdate<VariousTypes> update = new PartialUpdate<>(source.id, VariousTypes.class) //
.set("stringValue", "hooya!");
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "stringValue".getBytes()),
is("hooya!".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap._class".getBytes()), is(false));
return null;
}
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "stringValue".getBytes()),
is("hooya!".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap._class".getBytes()), is(false));
return null;
});
}
@@ -347,28 +300,24 @@ public class RedisKeyValueTemplateTests {
portalStone.dimension.height = 350;
portalStone.dimension.width = 70;
PartialUpdate<VariousTypes> update = new PartialUpdate<VariousTypes>(source.id, VariousTypes.class) //
PartialUpdate<VariousTypes> update = new PartialUpdate<>(source.id, VariousTypes.class) //
.set("complexValue", portalStone);
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "complexValue.name".getBytes()),
is("Portal Stone".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexValue.dimension.height".getBytes()), is("350".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexValue.dimension.width".getBytes()), is("70".getBytes()));
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "complexValue.name".getBytes()),
is("Portal Stone".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexValue.dimension.height".getBytes()), is("350".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexValue.dimension.width".getBytes()), is("70".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexValue.dimension.length".getBytes()), is(false));
return null;
}
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexValue.dimension.length".getBytes()), is(false));
return null;
});
}
@@ -391,31 +340,26 @@ public class RedisKeyValueTemplateTests {
portalStone.dimension.height = 350;
portalStone.dimension.width = 70;
PartialUpdate<VariousTypes> update = new PartialUpdate<VariousTypes>(source.id, VariousTypes.class) //
PartialUpdate<VariousTypes> update = new PartialUpdate<>(source.id, VariousTypes.class) //
.set("objectValue", portalStone);
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
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()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"objectValue.dimension.height".getBytes()), is("350".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"objectValue.dimension.width".getBytes()), is("70".getBytes()));
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()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"objectValue.dimension.height".getBytes()), is("350".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"objectValue.dimension.width".getBytes()), is("70".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "objectValue".getBytes()),
is(false));
return null;
}
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "objectValue".getBytes()),
is(false));
return null;
});
}
@@ -423,33 +367,30 @@ public class RedisKeyValueTemplateTests {
public void partialUpdateSimpleTypedMap() {
final VariousTypes source = new VariousTypes();
source.simpleTypedMap = new LinkedHashMap<String, String>();
source.simpleTypedMap = new LinkedHashMap<>();
source.simpleTypedMap.put("key-1", "rand");
source.simpleTypedMap.put("key-2", "mat");
source.simpleTypedMap.put("key-3", "perrin");
template.insert(source);
PartialUpdate<VariousTypes> update = new PartialUpdate<VariousTypes>(source.id, VariousTypes.class) //
PartialUpdate<VariousTypes> update = new PartialUpdate<>(source.id, VariousTypes.class) //
.set("simpleTypedMap", Collections.singletonMap("spring", "data"));
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[spring]".getBytes()), is("data".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[key-1]".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[key-2]".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[key-2]".getBytes()), is(false));
return null;
}
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedMap.[spring]".getBytes()),
is("data".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[key-1]".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[key-2]".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedMap.[key-2]".getBytes()), is(false));
return null;
});
}
@@ -457,7 +398,7 @@ public class RedisKeyValueTemplateTests {
public void partialUpdateComplexTypedMap() {
final VariousTypes source = new VariousTypes();
source.complexTypedMap = new LinkedHashMap<String, Item>();
source.complexTypedMap = new LinkedHashMap<>();
Item callandor = new Item();
callandor.name = "Callandor";
@@ -481,38 +422,34 @@ public class RedisKeyValueTemplateTests {
hornOfValere.dimension.height = 70;
hornOfValere.dimension.width = 25;
PartialUpdate<VariousTypes> update = new PartialUpdate<VariousTypes>(source.id, VariousTypes.class) //
PartialUpdate<VariousTypes> update = new PartialUpdate<>(source.id, VariousTypes.class) //
.set("complexTypedMap", Collections.singletonMap("horn-of-valere", hornOfValere));
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[horn-of-valere].name".getBytes()), is("Horn of Valere".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[horn-of-valere].dimension.height".getBytes()), is("70".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[horn-of-valere].dimension.width".getBytes()), is("25".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[horn-of-valere].name".getBytes()), is("Horn of Valere".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[horn-of-valere].dimension.height".getBytes()), is("70".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[horn-of-valere].dimension.width".getBytes()), is("25".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[callandor].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[callandor].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[callandor].dimension.width".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[callandor].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[callandor].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[callandor].dimension.width".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[portal-stone].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[portal-stone].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[portal-stone].dimension.width".getBytes()), is(false));
return null;
}
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[portal-stone].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[portal-stone].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[portal-stone].dimension.width".getBytes()), is(false));
return null;
});
}
@@ -520,7 +457,7 @@ public class RedisKeyValueTemplateTests {
public void partialUpdateObjectTypedMap() {
final VariousTypes source = new VariousTypes();
source.untypedMap = new LinkedHashMap<String, Object>();
source.untypedMap = new LinkedHashMap<>();
Item callandor = new Item();
callandor.name = "Callandor";
@@ -545,54 +482,50 @@ public class RedisKeyValueTemplateTests {
hornOfValere.dimension.height = 70;
hornOfValere.dimension.width = 25;
Map<String, Object> map = new LinkedHashMap<String, Object>();
Map<String, Object> map = new LinkedHashMap<>();
map.put("spring", "data");
map.put("horn-of-valere", hornOfValere);
map.put("some-number", 100L);
PartialUpdate<VariousTypes> update = new PartialUpdate<VariousTypes>(source.id, VariousTypes.class) //
PartialUpdate<VariousTypes> update = new PartialUpdate<>(source.id, VariousTypes.class) //
.set("untypedMap", map);
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[horn-of-valere].name".getBytes()), is("Horn of Valere".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[horn-of-valere].dimension.height".getBytes()), is("70".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[horn-of-valere].dimension.width".getBytes()), is("25".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[horn-of-valere].name".getBytes()), is("Horn of Valere".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[horn-of-valere].dimension.height".getBytes()), is("70".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[horn-of-valere].dimension.width".getBytes()), is("25".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[spring]._class".getBytes()), is("java.lang.String".getBytes()));
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedMap.[spring]".getBytes()),
is("data".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[spring]._class".getBytes()), is("java.lang.String".getBytes()));
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedMap.[spring]".getBytes()),
is("data".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[some-number]._class".getBytes()), is("java.lang.Long".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[some-number]".getBytes()), is("100".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[some-number]._class".getBytes()), is("java.lang.Long".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[some-number]".getBytes()), is("100".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[callandor].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[callandor].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[callandor].dimension.width".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[callandor].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[callandor].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[callandor].dimension.width".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[portal-stone].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[portal-stone].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[portal-stone].dimension.width".getBytes()), is(false));
return null;
}
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[portal-stone].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[portal-stone].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"untypedMap.[portal-stone].dimension.width".getBytes()), is(false));
return null;
});
}
@@ -600,34 +533,33 @@ public class RedisKeyValueTemplateTests {
public void partialUpdateSimpleTypedList() {
final VariousTypes source = new VariousTypes();
source.simpleTypedList = new ArrayList<String>();
source.simpleTypedList = new ArrayList<>();
source.simpleTypedList.add("rand");
source.simpleTypedList.add("mat");
source.simpleTypedList.add("perrin");
template.insert(source);
PartialUpdate<VariousTypes> update = new PartialUpdate<VariousTypes>(source.id, VariousTypes.class) //
PartialUpdate<VariousTypes> update = new PartialUpdate<>(source.id, VariousTypes.class) //
.set("simpleTypedList", Collections.singletonList("spring"));
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[0]".getBytes()),
is("spring".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedList.[1]".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedList.[2]".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"simpleTypedList.[3]".getBytes()), is(false));
return null;
}
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[0]".getBytes()),
is("spring".getBytes()));
assertThat(
connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[1]".getBytes()),
is(false));
assertThat(
connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[2]".getBytes()),
is(false));
assertThat(
connection.hExists(("template-test-type-mapping:" + source.id).getBytes(), "simpleTypedList.[3]".getBytes()),
is(false));
return null;
});
}
@@ -635,7 +567,7 @@ public class RedisKeyValueTemplateTests {
public void partialUpdateComplexTypedList() {
final VariousTypes source = new VariousTypes();
source.complexTypedList = new ArrayList<Item>();
source.complexTypedList = new ArrayList<>();
Item callandor = new Item();
callandor.name = "Callandor";
@@ -659,31 +591,27 @@ public class RedisKeyValueTemplateTests {
hornOfValere.dimension.height = 70;
hornOfValere.dimension.width = 25;
PartialUpdate<VariousTypes> update = new PartialUpdate<VariousTypes>(source.id, VariousTypes.class) //
PartialUpdate<VariousTypes> update = new PartialUpdate<>(source.id, VariousTypes.class) //
.set("complexTypedList", Collections.singletonList(hornOfValere));
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedList.[0].name".getBytes()), is("Horn of Valere".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedList.[0].dimension.height".getBytes()), is("70".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedList.[0].dimension.width".getBytes()), is("25".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedList.[0].name".getBytes()), is("Horn of Valere".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedList.[0].dimension.height".getBytes()), is("70".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedList.[0].dimension.width".getBytes()), is("25".getBytes()));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[1].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[1].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[1].dimension.width".getBytes()), is(false));
return null;
}
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[1].name".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[1].dimension.height".getBytes()), is(false));
assertThat(connection.hExists(("template-test-type-mapping:" + source.id).getBytes(),
"complexTypedMap.[1].dimension.width".getBytes()), is(false));
return null;
});
}
@@ -691,7 +619,7 @@ public class RedisKeyValueTemplateTests {
public void partialUpdateObjectTypedList() {
final VariousTypes source = new VariousTypes();
source.untypedList = new ArrayList<Object>();
source.untypedList = new ArrayList<>();
Item callandor = new Item();
callandor.name = "Callandor";
@@ -716,43 +644,39 @@ public class RedisKeyValueTemplateTests {
hornOfValere.dimension.height = 70;
hornOfValere.dimension.width = 25;
List<Object> list = new ArrayList<Object>();
List<Object> list = new ArrayList<>();
list.add("spring");
list.add(hornOfValere);
list.add(100L);
PartialUpdate<VariousTypes> update = new PartialUpdate<VariousTypes>(source.id, VariousTypes.class) //
PartialUpdate<VariousTypes> update = new PartialUpdate<>(source.id, VariousTypes.class) //
.set("untypedList", list);
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
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()));
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()));
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[1].name".getBytes()),
is("Horn of Valere".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedList.[1].dimension.height".getBytes()), is("70".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedList.[1].dimension.width".getBytes()), is("25".getBytes()));
assertThat(
connection.hGet(("template-test-type-mapping:" + source.id).getBytes(), "untypedList.[1].name".getBytes()),
is("Horn of Valere".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedList.[1].dimension.height".getBytes()), is("70".getBytes()));
assertThat(connection.hGet(("template-test-type-mapping:" + source.id).getBytes(),
"untypedList.[1].dimension.width".getBytes()), is("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()));
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()));
return null;
}
return null;
});
}
@@ -773,18 +697,14 @@ public class RedisKeyValueTemplateTests {
template.doPartialUpdate(update);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
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));
return null;
}
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));
return null;
});
}
@@ -798,30 +718,22 @@ public class RedisKeyValueTemplateTests {
template.insert(rand);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
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));
return null;
}
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));
return null;
});
rand.lastname = null;
template.update(rand);
nativeTemplate.execute(new RedisCallback<Void>() {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
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));
return null;
}
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));
return null;
});
}
@@ -886,13 +798,8 @@ public class RedisKeyValueTemplateTests {
template.insert(source);
nativeTemplate.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
return connection.persist((WithTtl.class.getName() + ":ttl-1").getBytes());
}
});
nativeTemplate.execute(
(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));

View File

@@ -39,9 +39,7 @@ import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.TestCondition;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
@@ -83,11 +81,9 @@ public class RedisTemplateTests<K, V> {
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@@ -125,11 +121,7 @@ public class RedisTemplateTests<K, V> {
redisTemplate.delete(key1);
redisTemplate.restore(key1, serializedValue, 200, TimeUnit.MILLISECONDS);
assertThat(redisTemplate.boundValueOps(key1).get(), isEqual(value1));
waitFor(new TestCondition() {
public boolean passes() {
return (!redisTemplate.hasKey(key1));
}
}, 400);
waitFor(() -> (!redisTemplate.hasKey(key1)), 400);
}
@SuppressWarnings("unchecked")
@@ -154,12 +146,10 @@ public class RedisTemplateTests<K, V> {
@Test
public void testStringTemplateExecutesWithStringConn() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
String value = redisTemplate.execute(new RedisCallback<String>() {
public String doInRedis(RedisConnection connection) {
StringRedisConnection stringConn = (StringRedisConnection) connection;
stringConn.set("test", "it");
return stringConn.get("test");
}
String value = redisTemplate.execute((RedisCallback<String>) connection -> {
StringRedisConnection stringConn = (StringRedisConnection) connection;
stringConn.set("test", "it");
return stringConn.get("test");
});
assertEquals(value, "it");
}
@@ -190,9 +180,9 @@ public class RedisTemplateTests<K, V> {
}
});
List<V> list = Collections.singletonList(listValue);
Set<V> set = new HashSet<V>(Collections.singletonList(setValue));
Set<TypedTuple<V>> tupleSet = new LinkedHashSet<TypedTuple<V>>(
Collections.singletonList(new DefaultTypedTuple<V>(zsetValue, 1d)));
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[] { value1, 1l, list, 1l, set, true, tupleSet })));
}
@@ -233,16 +223,15 @@ public class RedisTemplateTests<K, V> {
operations.opsForZSet().range("foozset", 0, -1);
operations.opsForHash().put("foomap", "10", "11");
operations.opsForHash().entries("foomap");
return operations.exec(new GenericToStringSerializer<Long>(Long.class));
return operations.exec(new GenericToStringSerializer<>(Long.class));
}
});
// Everything should be converted to Longs
List<Long> list = Collections.singletonList(6l);
Set<Long> longSet = new HashSet<Long>(Collections.singletonList(7l));
Set<TypedTuple<Long>> tupleSet = new LinkedHashSet<TypedTuple<Long>>(
Collections.singletonList(new DefaultTypedTuple<Long>(9l, 1d)));
Set<Long> zSet = new LinkedHashSet<Long>(Collections.singletonList(9l));
Map<Long, Long> map = new LinkedHashMap<Long, Long>();
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[] { 5l, 1L, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map })));
@@ -281,17 +270,15 @@ public class RedisTemplateTests<K, V> {
final K listKey = keyFactory.instance();
final V listValue = valueFactory.instance();
final V listValue2 = valueFactory.instance();
List<Object> results = redisTemplate.executePipelined(new RedisCallback() {
public Object doInRedis(RedisConnection connection) throws DataAccessException {
byte[] rawKey = serialize(key1, redisTemplate.getKeySerializer());
byte[] rawListKey = serialize(listKey, redisTemplate.getKeySerializer());
connection.set(rawKey, serialize(value1, redisTemplate.getValueSerializer()));
connection.get(rawKey);
connection.rPush(rawListKey, serialize(listValue, redisTemplate.getValueSerializer()));
connection.rPush(rawListKey, serialize(listValue2, redisTemplate.getValueSerializer()));
connection.lRange(rawListKey, 0, -1);
return null;
}
List<Object> results = redisTemplate.executePipelined((RedisCallback) connection -> {
byte[] rawKey = serialize(key1, redisTemplate.getKeySerializer());
byte[] rawListKey = serialize(listKey, redisTemplate.getKeySerializer());
connection.set(rawKey, serialize(value1, redisTemplate.getValueSerializer()));
connection.get(rawKey);
connection.rPush(rawListKey, serialize(listValue, redisTemplate.getValueSerializer()));
connection.rPush(rawListKey, serialize(listValue2, redisTemplate.getValueSerializer()));
connection.lRange(rawListKey, 0, -1);
return null;
});
assertThat(results,
isEqual(Arrays.asList(new Object[] { value1, 1l, 2l, Arrays.asList(new Object[] { listValue, listValue2 }) })));
@@ -303,17 +290,15 @@ public class RedisTemplateTests<K, V> {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
List<Object> results = redisTemplate.executePipelined(new RedisCallback() {
public Object doInRedis(RedisConnection connection) throws DataAccessException {
StringRedisConnection stringRedisConn = (StringRedisConnection) connection;
stringRedisConn.set("foo", "5");
stringRedisConn.get("foo");
stringRedisConn.rPush("foolist", "10");
stringRedisConn.rPush("foolist", "11");
stringRedisConn.lRange("foolist", 0, -1);
return null;
}
}, new GenericToStringSerializer<Long>(Long.class));
List<Object> results = redisTemplate.executePipelined((RedisCallback) connection -> {
StringRedisConnection stringRedisConn = (StringRedisConnection) connection;
stringRedisConn.set("foo", "5");
stringRedisConn.get("foo");
stringRedisConn.rPush("foolist", "10");
stringRedisConn.rPush("foolist", "11");
stringRedisConn.lRange("foolist", 0, -1);
return null;
}, new GenericToStringSerializer<>(Long.class));
assertEquals(Arrays.asList(new Object[] { 5l, 1l, 2l, Arrays.asList(new Long[] { 10l, 11l }) }), results);
}
@@ -324,18 +309,16 @@ public class RedisTemplateTests<K, V> {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new GenericToStringSerializer<Long>(Long.class));
redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<Person>(Person.class));
redisTemplate.setHashKeySerializer(new GenericToStringSerializer<>(Long.class));
redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(Person.class));
Person person = new Person("Homer", "Simpson", 38);
redisTemplate.opsForHash().put((K) "foo", 1L, person);
List<Object> results = redisTemplate.executePipelined(new RedisCallback() {
public Object doInRedis(RedisConnection connection) throws DataAccessException {
connection.hGetAll(((StringRedisSerializer) redisTemplate.getKeySerializer()).serialize("foo"));
return null;
}
List<Object> results = redisTemplate.executePipelined((RedisCallback) connection -> {
connection.hGetAll(((StringRedisSerializer) redisTemplate.getKeySerializer()).serialize("foo"));
return null;
});
assertEquals(((Map) results.get(0)).get(1L), person);
@@ -343,11 +326,7 @@ public class RedisTemplateTests<K, V> {
@Test(expected = InvalidDataAccessApiUsageException.class)
public void testExecutePipelinedNonNullRedisCallback() {
redisTemplate.executePipelined(new RedisCallback<String>() {
public String doInRedis(RedisConnection connection) throws DataAccessException {
return "Hey There";
}
});
redisTemplate.executePipelined((RedisCallback<String>) connection -> "Hey There");
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@@ -387,7 +366,7 @@ public class RedisTemplateTests<K, V> {
operations.opsForValue().get("foo");
return null;
}
}, new GenericToStringSerializer<Long>(Long.class));
}, 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 }), 2l }), pipelinedResults);
}
@@ -420,7 +399,7 @@ public class RedisTemplateTests<K, V> {
V value2 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
redisTemplate.opsForValue().set(key2, value2);
List<K> keys = new ArrayList<K>();
List<K> keys = new ArrayList<>();
keys.add(key1);
keys.add(key2);
redisTemplate.delete(keys);
@@ -456,11 +435,7 @@ public class RedisTemplateTests<K, V> {
assumeTrue(value1 instanceof Number);
redisTemplate.opsForList().rightPush(key1, value1);
List<String> results = redisTemplate.sort(SortQueryBuilder.sort(key1).get("#").build(),
new BulkMapper<String, V>() {
public String mapBulk(List<V> tuple) {
return "FOO";
}
});
tuple -> "FOO");
assertEquals(Collections.singletonList("FOO"), results);
}
@@ -474,11 +449,7 @@ public class RedisTemplateTests<K, V> {
assertTrue(redisTemplate.getExpire(key1, TimeUnit.MILLISECONDS) > 0l);
// Timeout is longer because expire will be 1 sec if pExpire not supported
waitFor(new TestCondition() {
public boolean passes() {
return (!redisTemplate.hasKey(key1));
}
}, 1500l);
waitFor(() -> (!redisTemplate.hasKey(key1)), 1500l);
}
@Test
@@ -629,11 +600,7 @@ public class RedisTemplateTests<K, V> {
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
redisTemplate.expireAt(key1, new Date(System.currentTimeMillis() + 5l));
waitFor(new TestCondition() {
public boolean passes() {
return (!redisTemplate.hasKey(key1));
}
}, 5l);
waitFor(() -> (!redisTemplate.hasKey(key1)), 5l);
}
@Test
@@ -651,11 +618,7 @@ public class RedisTemplateTests<K, V> {
template2.boundValueOps((String) key1).set((String) value1);
template2.expireAt((String) key1, new Date(System.currentTimeMillis() + 5l));
// Just ensure this works as expected, pExpireAt just adds some precision over expireAt
waitFor(new TestCondition() {
public boolean passes() {
return (!template2.hasKey((String) key1));
}
}, 5l);
waitFor(() -> (!template2.hasKey((String) key1)), 5l);
}
@Test
@@ -715,11 +678,7 @@ public class RedisTemplateTests<K, V> {
final V value3 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
final Thread th = new Thread(new Runnable() {
public void run() {
redisTemplate.opsForValue().set(key1, value2);
}
});
final Thread th = new Thread(() -> redisTemplate.opsForValue().set(key1, value2));
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -755,11 +714,7 @@ public class RedisTemplateTests<K, V> {
final V value2 = valueFactory.instance();
final V value3 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
final Thread th = new Thread(new Runnable() {
public void run() {
redisTemplate.opsForValue().set(key1, value2);
}
});
final Thread th = new Thread(() -> redisTemplate.opsForValue().set(key1, value2));
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -793,17 +748,13 @@ public class RedisTemplateTests<K, V> {
final V value3 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
final Thread th = new Thread(new Runnable() {
public void run() {
redisTemplate.opsForValue().set(key1, value2);
}
});
final Thread th = new Thread(() -> redisTemplate.opsForValue().set(key1, value2));
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Object> execute(RedisOperations operations) throws DataAccessException {
List<K> keys = new ArrayList<K>();
List<K> keys = new ArrayList<>();
keys.add(key1);
keys.add(key2);
operations.watch(keys);
@@ -839,7 +790,7 @@ public class RedisTemplateTests<K, V> {
public void testExecuteScriptCustomSerializers() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
K key1 = keyFactory.instance();
final DefaultRedisScript<String> script = new DefaultRedisScript<String>();
final DefaultRedisScript<String> script = new DefaultRedisScript<>();
script.setScriptText("return 'Hey'");
script.setResultType(String.class);
assertEquals("Hey", redisTemplate.execute(script, redisTemplate.getValueSerializer(), new StringRedisSerializer(),

View File

@@ -47,7 +47,7 @@ public class RedisTemplateUnitTests {
@Before
public void setUp() {
template = new RedisTemplate<Object, Object>();
template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactoryMock);
when(connectionFactoryMock.getConnection()).thenReturn(redisConnectionMock);
@@ -73,7 +73,7 @@ public class RedisTemplateUnitTests {
ShadowingClassLoader scl = new ShadowingClassLoader(ClassLoader.getSystemClassLoader());
template = new RedisTemplate<Object, Object>();
template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactoryMock);
template.setBeanClassLoader(scl);
template.afterPropertiesSet();

View File

@@ -44,19 +44,19 @@ public class ScanCursorUnitTests {
@Test // DATAREDIS-290
public void cursorShouldNotLoopWhenNoValuesFound() {
CapturingCursorDummy cursor = initCursor(new LinkedList<ScanIteration<String>>());
CapturingCursorDummy cursor = initCursor(new LinkedList<>());
assertThat(cursor.hasNext(), is(false));
}
@Test(expected = NoSuchElementException.class) // DATAREDIS-290
public void cursorShouldReturnNullWhenNoNextElementAvailable() {
initCursor(new LinkedList<ScanIteration<String>>()).next();
initCursor(new LinkedList<>()).next();
}
@Test // DATAREDIS-290
public void cursorShouldNotLoopWhenReachingStartingPointInFistLoop() {
LinkedList<ScanIteration<String>> values = new LinkedList<ScanIteration<String>>();
LinkedList<ScanIteration<String>> values = new LinkedList<>();
values.add(createIteration(0, "spring", "data", "redis"));
CapturingCursorDummy cursor = initCursor(values);
@@ -76,7 +76,7 @@ public class ScanCursorUnitTests {
@Test // DATAREDIS-290
public void cursorShouldStopLoopWhenReachingStartingPoint() {
LinkedList<ScanIteration<String>> values = new LinkedList<ScanIteration<String>>();
LinkedList<ScanIteration<String>> values = new LinkedList<>();
values.add(createIteration(1, "spring"));
values.add(createIteration(2, "data"));
values.add(createIteration(0, "redis"));
@@ -111,7 +111,7 @@ public class ScanCursorUnitTests {
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAREDIS-290
public void repoeningCursorShouldHappenAtLastPosition() throws IOException {
LinkedList<ScanIteration<String>> values = new LinkedList<ScanIteration<String>>();
LinkedList<ScanIteration<String>> values = new LinkedList<>();
values.add(createIteration(1, "spring"));
values.add(createIteration(2, "data"));
values.add(createIteration(0, "redis"));
@@ -131,7 +131,7 @@ public class ScanCursorUnitTests {
@Test // DATAREDIS-290
public void positionShouldBeIncrementedCorrectly() throws IOException {
LinkedList<ScanIteration<String>> values = new LinkedList<ScanIteration<String>>();
LinkedList<ScanIteration<String>> values = new LinkedList<>();
values.add(createIteration(1, "spring"));
values.add(createIteration(2, "data"));
values.add(createIteration(0, "redis"));
@@ -149,7 +149,7 @@ public class ScanCursorUnitTests {
@Test // DATAREDIS-417
public void hasNextShouldCallScanUntilFinishedWhenScanResultIsAnEmptyCollection() {
LinkedList<ScanIteration<String>> values = new LinkedList<ScanIteration<String>>();
LinkedList<ScanIteration<String>> values = new LinkedList<>();
values.add(createIteration(1, "spring"));
values.add(createIteration(2));
values.add(createIteration(3));
@@ -158,7 +158,7 @@ public class ScanCursorUnitTests {
values.add(createIteration(0, "redis"));
Cursor<String> cursor = initCursor(values);
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
while (cursor.hasNext()) {
result.add(cursor.next());
}
@@ -170,7 +170,7 @@ public class ScanCursorUnitTests {
@Test // DATAREDIS-417
public void hasNextShouldStopWhenScanResultIsAnEmptyCollectionAndStateIsFinished() {
LinkedList<ScanIteration<String>> values = new LinkedList<ScanIteration<String>>();
LinkedList<ScanIteration<String>> values = new LinkedList<>();
values.add(createIteration(1, "spring"));
values.add(createIteration(2));
values.add(createIteration(3));
@@ -181,7 +181,7 @@ public class ScanCursorUnitTests {
values.add(createIteration(0));
Cursor<String> cursor = initCursor(values);
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
while (cursor.hasNext()) {
result.add(cursor.next());
}
@@ -193,7 +193,7 @@ public class ScanCursorUnitTests {
@Test // DATAREDIS-417
public void hasNextShouldStopCorrectlyWhenWholeScanIterationDoesNotReturnResultsAndStateIsFinished() {
LinkedList<ScanIteration<String>> values = new LinkedList<ScanIteration<String>>();
LinkedList<ScanIteration<String>> values = new LinkedList<>();
values.add(createIteration(1));
values.add(createIteration(2));
values.add(createIteration(3));
@@ -221,8 +221,7 @@ public class ScanCursorUnitTests {
}
private ScanIteration<String> createIteration(long cursorId, String... values) {
return new ScanIteration<String>(cursorId, values.length > 0 ? Arrays.asList(values)
: Collections.<String> emptyList());
return new ScanIteration<>(cursorId, values.length > 0 ? Arrays.asList(values) : Collections.<String> emptyList());
}
private class CapturingCursorDummy extends ScanCursor<String> {
@@ -239,7 +238,7 @@ public class ScanCursorUnitTests {
protected ScanIteration<String> doScan(long cursorId, ScanOptions options) {
if (cursors == null) {
cursors = new Stack<Long>();
cursors = new Stack<>();
}
this.cursors.push(cursorId);
return this.values.poll();

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,15 +19,9 @@ import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SessionCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
/**
* @author Costin Leau
@@ -56,11 +50,9 @@ public class SessionTest {
}
private void checkConnection(RedisTemplate<?, ?> template, final RedisConnection expectedConnection) {
template.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) throws DataAccessException {
assertSame(expectedConnection, connection);
return null;
}
template.execute(connection -> {
assertSame(expectedConnection, connection);
return null;
}, true);
}
}

View File

@@ -179,7 +179,7 @@ public class ConversionTestEntities {
static class TypeWithObjectValueTypes {
Object object;
Map<String, Object> map = new HashMap<String, Object>();
List<Object> list = new ArrayList<Object>();
Map<String, Object> map = new HashMap<>();
List<Object> list = new ArrayList<>();
}
}

View File

@@ -32,7 +32,16 @@ import java.time.LocalTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.hamcrest.core.IsEqual;
import org.junit.Before;
@@ -213,7 +222,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readConsidersClassTypeInformationCorrectlyForNonMatchingTypes() {
Map<String, String> map = new HashMap<String, String>();
Map<String, String> map = new HashMap<>();
map.put("address._class", AddressWithPostcode.class.getName());
map.put("address.postcode", "1234");
@@ -246,7 +255,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readConvertsListOfSimplePropertiesCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("nicknames.[0]", "dragon reborn");
map.put("nicknames.[1]", "lews therin");
RedisData rdo = new RedisData(Bucket.newBucketFromStringMap(map));
@@ -257,7 +266,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readConvertsUnorderedListOfSimplePropertiesCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("nicknames.[9]", "car'a'carn");
map.put("nicknames.[10]", "lews therin");
map.put("nicknames.[1]", "dragon reborn");
@@ -269,7 +278,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readComplexPropertyCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("address.city", "two rivers");
map.put("address.country", "andor");
RedisData rdo = new RedisData(Bucket.newBucketFromStringMap(map));
@@ -284,7 +293,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readListComplexPropertyCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("coworkers.[0].firstname", "mat");
map.put("coworkers.[0].nicknames.[0]", "prince of the ravens");
map.put("coworkers.[0].nicknames.[1]", "gambler");
@@ -307,7 +316,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readUnorderedListOfComplexPropertyCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("coworkers.[10].firstname", "perrin");
map.put("coworkers.[10].address.city", "two rivers");
map.put("coworkers.[1].firstname", "mat");
@@ -331,7 +340,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readListComplexPropertyCorrectlyAndConsidersClassTypeInformation() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("coworkers.[0]._class", TaVeren.class.getName());
map.put("coworkers.[0].firstname", "mat");
@@ -347,7 +356,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void writeAppendsMapWithSimpleKeyCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("hair-color", "red");
map.put("eye-color", "grey");
@@ -362,11 +371,11 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void writeAppendsMapWithSimpleKeyOnNestedObjectCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("hair-color", "red");
map.put("eye-color", "grey");
rand.coworkers = new ArrayList<Person>();
rand.coworkers = new ArrayList<>();
rand.coworkers.add(new Person());
rand.coworkers.get(0).physicalAttributes = map;
@@ -380,7 +389,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readSimpleMapValuesCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("physicalAttributes.[hair-color]", "red");
map.put("physicalAttributes.[eye-color]", "grey");
@@ -396,7 +405,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void writeAppendsMapWithComplexObjectsCorrectly() {
Map<String, Person> map = new LinkedHashMap<String, Person>();
Map<String, Person> map = new LinkedHashMap<>();
Person janduin = new Person();
janduin.firstname = "janduin";
map.put("father", janduin);
@@ -415,7 +424,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readMapWithComplexObjectsCorrectly() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("relatives.[father].firstname", "janduin");
map.put("relatives.[step-father].firstname", "tam");
@@ -431,7 +440,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void writeAppendsClassTypeInformationCorrectlyForMapWithComplexObjects() {
Map<String, Person> map = new LinkedHashMap<String, Person>();
Map<String, Person> map = new LinkedHashMap<>();
Person lews = new TaVeren();
lews.firstname = "lews";
map.put("previous-incarnation", lews);
@@ -447,7 +456,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-425
public void readConsidersClassTypeInformationCorrectlyForMapWithComplexObjects() {
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("relatives.[previous-incarnation]._class", TaVeren.class.getName());
map.put("relatives.[previous-incarnation].firstname", "lews");
@@ -695,14 +704,14 @@ public class MappingRedisConverterUnitTests {
location.id = "1";
location.name = "tar valon";
Map<String, String> locationMap = new LinkedHashMap<String, String>();
Map<String, String> locationMap = new LinkedHashMap<>();
locationMap.put("id", location.id);
locationMap.put("name", location.name);
when(resolverMock.resolveReference(eq("1"), eq("locations")))
.thenReturn(Bucket.newBucketFromStringMap(locationMap).rawMap());
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("location", "locations:1");
Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(map)));
@@ -737,14 +746,14 @@ public class MappingRedisConverterUnitTests {
location.id = "1";
location.name = "tar valon";
Map<String, String> locationMap = new LinkedHashMap<String, String>();
Map<String, String> locationMap = new LinkedHashMap<>();
locationMap.put("id", location.id);
locationMap.put("name", location.name);
when(resolverMock.resolveReference(eq("1"), eq("locations")))
.thenReturn(Bucket.newBucketFromStringMap(locationMap).rawMap());
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("coworkers.[0].location", "locations:1");
Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(map)));
@@ -792,15 +801,15 @@ public class MappingRedisConverterUnitTests {
tear.id = "3";
tear.name = "city of tear";
Map<String, String> tarValonMap = new LinkedHashMap<String, String>();
Map<String, String> tarValonMap = new LinkedHashMap<>();
tarValonMap.put("id", tarValon.id);
tarValonMap.put("name", tarValon.name);
Map<String, String> falmeMap = new LinkedHashMap<String, String>();
Map<String, String> falmeMap = new LinkedHashMap<>();
falmeMap.put("id", falme.id);
falmeMap.put("name", falme.name);
Map<String, String> tearMap = new LinkedHashMap<String, String>();
Map<String, String> tearMap = new LinkedHashMap<>();
tearMap.put("id", tear.id);
tearMap.put("name", tear.name);
@@ -813,7 +822,7 @@ public class MappingRedisConverterUnitTests {
when(resolverMock.resolveReference(eq("3"), eq("locations")))
.thenReturn(Bucket.newBucketFromStringMap(tearMap).rawMap());
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("visited.[0]", "locations:1");
map.put("visited.[1]", "locations:2");
map.put("visited.[2]", "locations:3");
@@ -955,7 +964,7 @@ public class MappingRedisConverterUnitTests {
.setCustomConversions(new RedisCustomConversions(Collections.singletonList(new BytesToAddressConverter())));
this.converter.afterPropertiesSet();
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("_raw", "{\"city\":\"unknown\",\"country\":\"Tel'aran'rhiod\"}");
Address target = converter.read(Address.class, new RedisData(Bucket.newBucketFromStringMap(map)));
@@ -972,7 +981,7 @@ public class MappingRedisConverterUnitTests {
.setCustomConversions(new RedisCustomConversions(Collections.singletonList(new BytesToAddressConverter())));
this.converter.afterPropertiesSet();
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("address", "{\"city\":\"unknown\",\"country\":\"Tel'aran'rhiod\"}");
Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(map)));
@@ -1038,7 +1047,7 @@ public class MappingRedisConverterUnitTests {
this.converter
.setCustomConversions(new RedisCustomConversions(Collections.singletonList(new MapToSpeciesConverter())));
this.converter.afterPropertiesSet();
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("species-name", "trolloc");
Species target = converter.read(Species.class, new RedisData(Bucket.newBucketFromStringMap(map)));
@@ -1055,7 +1064,7 @@ public class MappingRedisConverterUnitTests {
.setCustomConversions(new RedisCustomConversions(Collections.singletonList(new MapToSpeciesConverter())));
this.converter.afterPropertiesSet();
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("species.species-name", "trolloc");
Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(map)));
@@ -1073,7 +1082,7 @@ public class MappingRedisConverterUnitTests {
this.converter.afterPropertiesSet();
TheWheelOfTime twot = new TheWheelOfTime();
twot.species = new ArrayList<Species>();
twot.species = new ArrayList<>();
Species myrddraal = new Species();
myrddraal.name = "myrddraal";
@@ -1092,7 +1101,7 @@ public class MappingRedisConverterUnitTests {
.setCustomConversions(new RedisCustomConversions(Collections.singletonList(new MapToSpeciesConverter())));
this.converter.afterPropertiesSet();
Map<String, String> map = new LinkedHashMap<String, String>();
Map<String, String> map = new LinkedHashMap<>();
map.put("species.[0].species-name", "trolloc");
TheWheelOfTime target = converter.read(TheWheelOfTime.class, new RedisData(Bucket.newBucketFromStringMap(map)));
@@ -1111,11 +1120,11 @@ public class MappingRedisConverterUnitTests {
.setCustomConversions(new RedisCustomConversions(Collections.singletonList(new ListToByteConverter())));
this.converter.afterPropertiesSet();
Map<String, Object> innerMap = new LinkedHashMap<String, Object>();
Map<String, Object> innerMap = new LinkedHashMap<>();
innerMap.put("address", "tyrionl@netflix.com");
innerMap.put("when", new String[] { "pipeline.failed" });
Map<String, Object> map = new LinkedHashMap<String, Object>();
Map<String, Object> map = new LinkedHashMap<>();
map.put("email", Collections.singletonList(innerMap));
RedisData target = write(map);
@@ -1136,7 +1145,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-492
public void readHandlesArraysOfSimpleTypeProperly() {
Map<String, String> source = new LinkedHashMap<String, String>();
Map<String, String> source = new LinkedHashMap<>();
source.put("arrayOfSimpleTypes.[0]", "rand");
source.put("arrayOfSimpleTypes.[1]", "mat");
source.put("arrayOfSimpleTypes.[2]", "perrin");
@@ -1171,7 +1180,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-492
public void readHandlesArraysOfComplexTypeProperly() {
Map<String, String> source = new LinkedHashMap<String, String>();
Map<String, String> source = new LinkedHashMap<>();
source.put("arrayOfCompexTypes.[0].name", "trolloc");
source.put("arrayOfCompexTypes.[1].name", "myrddraal");
source.put("arrayOfCompexTypes.[1].alsoKnownAs.[0]", "halfmen");
@@ -1208,7 +1217,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-489
public void readHandlesArraysOfObjectTypeProperly() {
Map<String, String> source = new LinkedHashMap<String, String>();
Map<String, String> source = new LinkedHashMap<>();
source.put("arrayOfObject.[0]", "rand");
source.put("arrayOfObject.[0]._class", "java.lang.String");
source.put("arrayOfObject.[1]._class", Species.class.getName());
@@ -1320,7 +1329,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-509
public void writeHandlesArraysOfPrimitivesProperly() {
Map<String, String> source = new LinkedHashMap<String, String>();
Map<String, String> source = new LinkedHashMap<>();
source.put("arrayOfPrimitives.[0]", "1");
source.put("arrayOfPrimitives.[1]", "2");
source.put("arrayOfPrimitives.[2]", "3");
@@ -1348,7 +1357,7 @@ public class MappingRedisConverterUnitTests {
value.firstname = "rand";
value.age = 24;
PartialUpdate<Person> update = new PartialUpdate<Person>("123", value);
PartialUpdate<Person> update = new PartialUpdate<>("123", value);
assertThat(write(update).getBucket().get("_class"), is(nullValue()));
}
@@ -1360,7 +1369,7 @@ public class MappingRedisConverterUnitTests {
value.firstname = "rand";
value.age = 24;
PartialUpdate<Person> update = new PartialUpdate<Person>("123", value);
PartialUpdate<Person> update = new PartialUpdate<>("123", value);
assertThat(write(update).getBucket(),
isBucket().containingUtf8String("firstname", "rand").containingUtf8String("age", "24"));
@@ -1369,7 +1378,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-471
public void writeShouldWritePartialUpdatePathWithSimpleValueCorrectly() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("firstname", "rand").set("age",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("firstname", "rand").set("age",
24);
assertThat(write(update).getBucket(),
@@ -1379,7 +1388,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-471
public void writeShouldWritePartialUpdateNestedPathWithSimpleValueCorrectly() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("address.city", "two rivers");
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("address.city", "two rivers");
assertThat(write(update).getBucket(), isBucket().containingUtf8String("address.city", "two rivers"));
}
@@ -1391,7 +1400,7 @@ public class MappingRedisConverterUnitTests {
address.city = "two rivers";
address.country = "andor";
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("address", address);
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("address", address);
assertThat(write(update).getBucket(),
isBucket().containingUtf8String("address.city", "two rivers").containingUtf8String("address.country", "andor"));
@@ -1400,7 +1409,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-471
public void writeShouldWritePartialUpdatePathWithSimpleListValueCorrectly() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("nicknames",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("nicknames",
Arrays.asList("dragon", "lews"));
assertThat(write(update).getBucket(),
@@ -1417,7 +1426,7 @@ public class MappingRedisConverterUnitTests {
Person perrin = new Person();
perrin.firstname = "perrin";
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("coworkers",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("coworkers",
Arrays.asList(mat, perrin));
assertThat(write(update).getBucket(), isBucket().containingUtf8String("coworkers.[0].firstname", "mat")
@@ -1427,7 +1436,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-471
public void writeShouldWritePartialUpdatePathWithSimpleListValueWhenNotPassedInAsCollectionCorrectly() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("nicknames", "dragon");
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("nicknames", "dragon");
assertThat(write(update).getBucket(), isBucket().containingUtf8String("nicknames.[0]", "dragon"));
}
@@ -1439,7 +1448,7 @@ public class MappingRedisConverterUnitTests {
mat.firstname = "mat";
mat.age = 24;
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("coworkers", mat);
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("coworkers", mat);
assertThat(write(update).getBucket(), isBucket().containingUtf8String("coworkers.[0].firstname", "mat")
.containingUtf8String("coworkers.[0].age", "24"));
@@ -1448,7 +1457,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-471
public void writeShouldWritePartialUpdatePathWithSimpleListValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("nicknames.[5]", "dragon");
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("nicknames.[5]", "dragon");
assertThat(write(update).getBucket(), isBucket().containingUtf8String("nicknames.[5]", "dragon"));
}
@@ -1460,7 +1469,7 @@ public class MappingRedisConverterUnitTests {
mat.firstname = "mat";
mat.age = 24;
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("coworkers.[5]", mat);
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("coworkers.[5]", mat);
assertThat(write(update).getBucket(), isBucket().containingUtf8String("coworkers.[5].firstname", "mat")
.containingUtf8String("coworkers.[5].age", "24"));
@@ -1469,7 +1478,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-471
public void writeShouldWritePartialUpdatePathWithSimpleMapValueCorrectly() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("physicalAttributes",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("physicalAttributes",
Collections.singletonMap("eye-color", "grey"));
assertThat(write(update).getBucket(), isBucket().containingUtf8String("physicalAttributes.[eye-color]", "grey"));
@@ -1482,7 +1491,7 @@ public class MappingRedisConverterUnitTests {
tam.firstname = "tam";
tam.alive = false;
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("relatives",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("relatives",
Collections.singletonMap("father", tam));
assertThat(write(update).getBucket(), isBucket().containingUtf8String("relatives.[father].firstname", "tam")
@@ -1492,7 +1501,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-471
public void writeShouldWritePartialUpdatePathWithSimpleMapValueWhenNotPassedInAsCollectionCorrectly() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("physicalAttributes",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("physicalAttributes",
Collections.singletonMap("eye-color", "grey").entrySet().iterator().next());
assertThat(write(update).getBucket(), isBucket().containingUtf8String("physicalAttributes.[eye-color]", "grey"));
@@ -1505,7 +1514,7 @@ public class MappingRedisConverterUnitTests {
tam.firstname = "tam";
tam.alive = false;
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("relatives",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("relatives",
Collections.singletonMap("father", tam).entrySet().iterator().next());
assertThat(write(update).getBucket(), isBucket().containingUtf8String("relatives.[father].firstname", "tam")
@@ -1515,7 +1524,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-471
public void writeShouldWritePartialUpdatePathWithSimpleMapValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("physicalAttributes.[eye-color]",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("physicalAttributes.[eye-color]",
"grey");
assertThat(write(update).getBucket(), isBucket().containingUtf8String("physicalAttributes.[eye-color]", "grey"));
@@ -1524,7 +1533,7 @@ public class MappingRedisConverterUnitTests {
@Test // DATAREDIS-471
public void writeShouldWritePartialUpdatePathWithSimpleMapValueOnNestedElementCorrectly() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("relatives.[father].firstname",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("relatives.[father].firstname",
"tam");
assertThat(write(update).getBucket(), isBucket().containingUtf8String("relatives.[father].firstname", "tam"));
@@ -1533,7 +1542,7 @@ public class MappingRedisConverterUnitTests {
@Test(expected = MappingException.class) // DATAREDIS-471
public void writeShouldThrowExceptionOnPartialUpdatePathWithSimpleMapValueWhenItsASingleValueWithoutPath() {
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("physicalAttributes", "grey");
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("physicalAttributes", "grey");
write(update);
}
@@ -1550,7 +1559,7 @@ public class MappingRedisConverterUnitTests {
address.country = "Tel'aran'rhiod";
address.city = "unknown";
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("address", address);
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("address", address);
assertThat(write(update).getBucket(),
isBucket().containingUtf8String("address", "{\"city\":\"unknown\",\"country\":\"Tel'aran'rhiod\"}"));
@@ -1567,7 +1576,7 @@ public class MappingRedisConverterUnitTests {
tear.id = "2";
tear.name = "city of tear";
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class).set("visited",
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class).set("visited",
Arrays.asList(tar, tear));
assertThat(write(update).getBucket(),
@@ -1583,7 +1592,7 @@ public class MappingRedisConverterUnitTests {
location.id = "1";
location.name = "tar valon";
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class) //
.set("location", location);
assertThat(write(update).getBucket(),
@@ -1600,7 +1609,7 @@ public class MappingRedisConverterUnitTests {
exception.expectMessage("java.lang.Integer");
exception.expectMessage("age");
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class) //
.set("age", "twenty-four");
assertThat(write(update).getBucket().get("_class"), is(nullValue()));
@@ -1614,7 +1623,7 @@ public class MappingRedisConverterUnitTests {
exception.expectMessage(Person.class.getName());
exception.expectMessage("coworkers.[0]");
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class) //
.set("coworkers.[0]", "buh buh the bear");
assertThat(write(update).getBucket().get("_class"), is(nullValue()));
@@ -1628,7 +1637,7 @@ public class MappingRedisConverterUnitTests {
exception.expectMessage(Person.class.getName());
exception.expectMessage("coworkers");
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class) //
.set("coworkers", Collections.singletonList("foo"));
assertThat(write(update).getBucket().get("_class"), is(nullValue()));
@@ -1642,7 +1651,7 @@ public class MappingRedisConverterUnitTests {
exception.expectMessage(Person.class.getName());
exception.expectMessage("relatives.[father]");
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class) //
.set("relatives.[father]", "buh buh the bear");
assertThat(write(update).getBucket().get("_class"), is(nullValue()));
@@ -1656,7 +1665,7 @@ public class MappingRedisConverterUnitTests {
exception.expectMessage(Person.class.getName());
exception.expectMessage("relatives.[father]");
PartialUpdate<Person> update = new PartialUpdate<Person>("123", Person.class) //
PartialUpdate<Person> update = new PartialUpdate<>("123", Person.class) //
.set("relatives", Collections.singletonMap("father", "buh buh the bear"));
assertThat(write(update).getBucket().get("_class"), is(nullValue()));
@@ -1686,7 +1695,7 @@ public class MappingRedisConverterUnitTests {
.withFieldVisibility(Visibility.ANY).withGetterVisibility(Visibility.NONE)
.withSetterVisibility(Visibility.NONE).withCreatorVisibility(Visibility.NONE));
serializer = new Jackson2JsonRedisSerializer<Address>(Address.class);
serializer = new Jackson2JsonRedisSerializer<>(Address.class);
serializer.setObjectMapper(mapper);
}
@@ -1706,7 +1715,7 @@ public class MappingRedisConverterUnitTests {
return null;
}
Map<String, byte[]> map = new LinkedHashMap<String, byte[]>();
Map<String, byte[]> map = new LinkedHashMap<>();
if (source.name != null) {
map.put("species-name", source.name.getBytes(Charset.forName("UTF-8")));
}
@@ -1729,7 +1738,7 @@ public class MappingRedisConverterUnitTests {
.withFieldVisibility(Visibility.ANY).withGetterVisibility(Visibility.NONE)
.withSetterVisibility(Visibility.NONE).withCreatorVisibility(Visibility.NONE));
serializer = new Jackson2JsonRedisSerializer<List>(List.class);
serializer = new Jackson2JsonRedisSerializer<>(List.class);
serializer.setObjectMapper(mapper);
}
@@ -1780,7 +1789,7 @@ public class MappingRedisConverterUnitTests {
.withFieldVisibility(Visibility.ANY).withGetterVisibility(Visibility.NONE)
.withSetterVisibility(Visibility.NONE).withCreatorVisibility(Visibility.NONE));
serializer = new Jackson2JsonRedisSerializer<Address>(Address.class);
serializer = new Jackson2JsonRedisSerializer<>(Address.class);
serializer.setObjectMapper(mapper);
}

View File

@@ -116,7 +116,7 @@ public class PathIndexResolverUnitTests {
public void shouldResolveMultipleAnnotatedIndexesInLists() {
TheWheelOfTime twot = new TheWheelOfTime();
twot.mainCharacters = new ArrayList<Person>();
twot.mainCharacters = new ArrayList<>();
Person rand = new Person();
rand.address = new Address();
@@ -142,7 +142,7 @@ public class PathIndexResolverUnitTests {
public void shouldResolveAnnotatedIndexesInMap() {
TheWheelOfTime twot = new TheWheelOfTime();
twot.places = new LinkedHashMap<String, ConversionTestEntities.Location>();
twot.places = new LinkedHashMap<>();
Location stoneOfTear = new Location();
stoneOfTear.name = "Stone of Tear";
@@ -165,7 +165,7 @@ public class PathIndexResolverUnitTests {
indexConfig.addIndexDefinition(new SimpleIndexDefinition(KEYSPACE_PERSON, "physicalAttributes.eye-color"));
Person rand = new Person();
rand.physicalAttributes = new LinkedHashMap<String, String>();
rand.physicalAttributes = new LinkedHashMap<>();
rand.physicalAttributes.put("eye-color", "grey");
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), rand);
@@ -181,7 +181,7 @@ public class PathIndexResolverUnitTests {
indexConfig.addIndexDefinition(new SimpleIndexDefinition(KEYSPACE_PERSON, "relatives.father.firstname"));
Person rand = new Person();
rand.relatives = new LinkedHashMap<String, Person>();
rand.relatives = new LinkedHashMap<>();
Person janduin = new Person();
janduin.firstname = "janduin";
@@ -201,7 +201,7 @@ public class PathIndexResolverUnitTests {
indexConfig.addIndexDefinition(new SimpleIndexDefinition(KEYSPACE_PERSON, "physicalAttributes.eye-color"));
Person rand = new Person();
rand.physicalAttributes = new LinkedHashMap<String, String>();
rand.physicalAttributes = new LinkedHashMap<>();
rand.physicalAttributes.put("eye-color", null);
Set<IndexedData> indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), rand);
@@ -321,7 +321,7 @@ public class PathIndexResolverUnitTests {
hat.type = "hat";
TaVeren mat = new TaVeren();
mat.characteristics = new LinkedHashMap<String, Object>(2);
mat.characteristics = new LinkedHashMap<>(2);
mat.characteristics.put("clothing", hat);
mat.characteristics.put("gambling", "owns the dark one's luck");
@@ -339,7 +339,7 @@ public class PathIndexResolverUnitTests {
hat.type = "hat";
TaVeren mat = new TaVeren();
mat.items = new ArrayList<Object>(2);
mat.items = new ArrayList<>(2);
mat.items.add(hat);
mat.items.add("foxhead medallion");
@@ -358,7 +358,7 @@ public class PathIndexResolverUnitTests {
hat.type = "hat";
TaVeren mat = new TaVeren();
mat.items = new ArrayList<Object>(2);
mat.items = new ArrayList<>(2);
mat.items.add(hat);
mat.items.add("foxhead medallion");
@@ -384,7 +384,7 @@ public class PathIndexResolverUnitTests {
public void resolveIndexOnMapField() {
IndexedOnMapField source = new IndexedOnMapField();
source.values = new LinkedHashMap<String, String>();
source.values = new LinkedHashMap<>();
source.values.put("jon", "snow");
source.values.put("arya", "stark");
@@ -403,7 +403,7 @@ public class PathIndexResolverUnitTests {
public void resolveIndexOnListField() {
IndexedOnListField source = new IndexedOnListField();
source.values = new ArrayList<String>();
source.values = new ArrayList<>();
source.values.add("jon");
source.values.add("arya");

View File

@@ -30,9 +30,6 @@ import org.springframework.data.redis.core.index.SpelIndexDefinition;
import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.core.mapping.RedisPersistentEntity;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.expression.AccessException;
import org.springframework.expression.BeanResolver;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.spel.SpelEvaluationException;
/**
@@ -131,15 +128,10 @@ public class SpelIndexResolverUnitTests {
public void withBeanAndThis() {
this.resolver = createWithExpression("@bean.run(#this)");
this.resolver.setBeanResolver(new BeanResolver() {
@Override
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
return new Object() {
@SuppressWarnings("unused")
public Object run(Object arg) {
return arg;
}
};
this.resolver.setBeanResolver((context, beanName) -> new Object() {
@SuppressWarnings("unused")
public Object run(Object arg) {
return arg;
}
});
@@ -174,7 +166,7 @@ public class SpelIndexResolverUnitTests {
static class Session {
private Map<String, Object> sessionAttrs = new HashMap<String, Object>();
private Map<String, Object> sessionAttrs = new HashMap<>();
public void setAttribute(String attrName, Object attrValue) {
this.sessionAttrs.put(attrName, attrValue);

View File

@@ -20,8 +20,6 @@ import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.io.Serializable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -57,7 +55,7 @@ public class BasicRedisPersistentEntityUnitTests<T> {
public void setUp() {
when(entityInformation.getType()).thenReturn((Class<T>) ConversionTestEntities.Person.class);
entity = new BasicRedisPersistentEntity<T>(entityInformation, keySpaceResolver, ttlAccessor);
entity = new BasicRedisPersistentEntity<>(entityInformation, keySpaceResolver, ttlAccessor);
}
@Test // DATAREDIS-425

View File

@@ -141,7 +141,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
public void getTimeToLiveShouldReturnDefaultValue() {
Long ttl = accessor
.getTimeToLive(new PartialUpdate<TypeWithRedisHashAnnotation>("123", new TypeWithRedisHashAnnotation()));
.getTimeToLive(new PartialUpdate<>("123", new TypeWithRedisHashAnnotation()));
assertThat(ttl, is(5L));
}
@@ -150,7 +150,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
public void getTimeToLiveShouldReturnValueWhenUpdateModifiesTtlProperty() {
Long ttl = accessor
.getTimeToLive(new PartialUpdate<SimpleTypeWithTTLProperty>("123", new SimpleTypeWithTTLProperty())
.getTimeToLive(new PartialUpdate<>("123", new SimpleTypeWithTTLProperty())
.set("ttl", 100).refreshTtl(true));
assertThat(ttl, is(100L));
@@ -159,7 +159,8 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
@Test // DATAREDIS-471
public void getTimeToLiveShouldReturnPropertyValueWhenUpdateModifiesTtlProperty() {
Long ttl = accessor.getTimeToLive(new PartialUpdate<TypeWithRedisHashAnnotationAndTTLProperty>("123",
Long ttl = accessor.getTimeToLive(
new PartialUpdate<>("123",
new TypeWithRedisHashAnnotationAndTTLProperty()).set("ttl", 100).refreshTtl(true));
assertThat(ttl, is(100L));
@@ -168,7 +169,8 @@ public class ConfigAwareTimeToLiveAccessorUnitTests {
@Test // DATAREDIS-471
public void getTimeToLiveShouldReturnDefaultValueWhenUpdateDoesNotModifyTtlProperty() {
Long ttl = accessor.getTimeToLive(new PartialUpdate<TypeWithRedisHashAnnotationAndTTLProperty>("123",
Long ttl = accessor
.getTimeToLive(new PartialUpdate<>("123",
new TypeWithRedisHashAnnotationAndTTLProperty()).refreshTtl(true));
assertThat(ttl, is(10L));

View File

@@ -26,7 +26,6 @@ import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisOperations;
@@ -42,7 +41,7 @@ import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test of {@link DefaultScriptExecutor}
*
*
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
@@ -64,12 +63,10 @@ public abstract class AbstractDefaultScriptExecutorTests {
return;
}
template.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
connection.scriptFlush();
return null;
}
template.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
connection.scriptFlush();
return null;
});
}
@@ -79,7 +76,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
this.template = new StringRedisTemplate();
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
DefaultRedisScript<Long> script = new DefaultRedisScript<Long>();
DefaultRedisScript<Long> script = new DefaultRedisScript<>();
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/increment.lua"));
script.setResultType(Long.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
@@ -94,10 +91,10 @@ public abstract class AbstractDefaultScriptExecutorTests {
public void testExecuteBooleanResult() {
this.template = new RedisTemplate<String, Long>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
template.setValueSerializer(new GenericToStringSerializer<>(Long.class));
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
DefaultRedisScript<Boolean> script = new DefaultRedisScript<Boolean>();
DefaultRedisScript<Boolean> script = new DefaultRedisScript<>();
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/cas.lua"));
script.setResultType(Boolean.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
@@ -114,11 +111,11 @@ public abstract class AbstractDefaultScriptExecutorTests {
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
template.boundListOps("mylist").leftPushAll("a", "b", "c", "d");
DefaultRedisScript<List> script = new DefaultRedisScript<List>();
DefaultRedisScript<List> script = new DefaultRedisScript<>();
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/bulkpop.lua"));
script.setResultType(List.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
List<String> result = scriptExecutor.execute(script, new GenericToStringSerializer<Long>(Long.class),
List<String> result = scriptExecutor.execute(script, new GenericToStringSerializer<>(Long.class),
template.getValueSerializer(), Collections.singletonList("mylist"), 1l);
assertEquals(Collections.singletonList("a"), result);
}
@@ -129,7 +126,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
this.template = new StringRedisTemplate();
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
DefaultRedisScript<List> script = new DefaultRedisScript<List>();
DefaultRedisScript<List> script = new DefaultRedisScript<>();
script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/popandlength.lua"));
script.setResultType(List.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
@@ -146,7 +143,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
this.template = new StringRedisTemplate();
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
DefaultRedisScript<String> script = new DefaultRedisScript<String>();
DefaultRedisScript<String> script = new DefaultRedisScript<>();
script.setScriptText("return redis.call('GET',KEYS[1])");
script.setResultType(String.class);
template.opsForValue().set("foo", "bar");
@@ -159,7 +156,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
public void testExecuteStatusResult() {
this.template = new RedisTemplate<String, Long>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
template.setValueSerializer(new GenericToStringSerializer<>(Long.class));
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
DefaultRedisScript script = new DefaultRedisScript();
@@ -172,13 +169,13 @@ public abstract class AbstractDefaultScriptExecutorTests {
@SuppressWarnings("unchecked")
@Test
public void testExecuteCustomResultSerializer() {
Jackson2JsonRedisSerializer<Person> personSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
Jackson2JsonRedisSerializer<Person> personSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
this.template = new RedisTemplate<String, Person>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(personSerializer);
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
DefaultRedisScript<String> script = new DefaultRedisScript<String>();
DefaultRedisScript<String> script = new DefaultRedisScript<>();
script.setScriptSource(new StaticScriptSource("redis.call('SET',KEYS[1], ARGV[1])\nreturn 'FOO'"));
script.setResultType(String.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
@@ -195,7 +192,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
this.template = new StringRedisTemplate();
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
final DefaultRedisScript<String> script = new DefaultRedisScript<String>();
final DefaultRedisScript<String> script = new DefaultRedisScript<>();
script.setScriptText("return KEYS[1]");
script.setResultType(String.class);
List<Object> results = template.executePipelined(new SessionCallback<String>() {
@@ -215,7 +212,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
this.template = new StringRedisTemplate();
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
final DefaultRedisScript<String> script = new DefaultRedisScript<String>();
final DefaultRedisScript<String> script = new DefaultRedisScript<>();
script.setScriptText("return 'bar'..KEYS[1]");
script.setResultType(String.class);
List<Object> results = (List<Object>) template.execute(new SessionCallback<List<Object>>() {
@@ -237,7 +234,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
this.template = new StringRedisTemplate();
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
DefaultRedisScript<String> script = new DefaultRedisScript<String>();
DefaultRedisScript<String> script = new DefaultRedisScript<>();
script.setScriptText("return 'HELLO'");
script.setResultType(String.class);
ScriptExecutor<String> scriptExecutor = new DefaultScriptExecutor<String>(template);
@@ -253,7 +250,7 @@ public abstract class AbstractDefaultScriptExecutorTests {
template.setConnectionFactory(getConnectionFactory());
template.afterPropertiesSet();
DefaultRedisScript<String> script = new DefaultRedisScript<String>();
DefaultRedisScript<String> script = new DefaultRedisScript<>();
script.setScriptText("return 'BUBU" + System.currentTimeMillis() + "'");
script.setResultType(String.class);

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.redis.core.script;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
@@ -25,7 +24,7 @@ import org.springframework.scripting.support.StaticScriptSource;
/**
* Test of {@link DefaultRedisScript}
*
*
* @author Jennifer Hickey
*/
public class DefaultRedisScriptTests {
@@ -33,7 +32,7 @@ public class DefaultRedisScriptTests {
@Test
public void testGetSha1() {
StaticScriptSource script = new StaticScriptSource("return KEYS[1]");
DefaultRedisScript<String> redisScript = new DefaultRedisScript<String>();
DefaultRedisScript<String> redisScript = new DefaultRedisScript<>();
redisScript.setScriptSource(script);
redisScript.setResultType(String.class);
String sha1 = redisScript.getSha1();
@@ -46,7 +45,7 @@ public class DefaultRedisScriptTests {
@Test
public void testGetScriptAsString() {
DefaultRedisScript<String> redisScript = new DefaultRedisScript<String>();
DefaultRedisScript<String> redisScript = new DefaultRedisScript<>();
redisScript.setScriptText("return ARGS[1]");
redisScript.setResultType(String.class);
assertEquals("return ARGS[1]", redisScript.getScriptAsString());
@@ -54,7 +53,7 @@ public class DefaultRedisScriptTests {
@Test(expected = ScriptingException.class)
public void testGetScriptAsStringError() {
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<Long>();
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("nonexistent")));
redisScript.setResultType(Long.class);
redisScript.getScriptAsString();
@@ -62,7 +61,7 @@ public class DefaultRedisScriptTests {
@Test(expected = IllegalArgumentException.class)
public void initializeWithNoScript() throws Exception {
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<Long>();
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
redisScript.afterPropertiesSet();
}
}

View File

@@ -34,7 +34,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
@RunWith(MockitoJUnitRunner.class)
public class DefaultScriptExecutorUnitTests {
private final DefaultRedisScript<String> SCRIPT = new DefaultRedisScript<String>("return KEYS[0]", String.class);
private final DefaultRedisScript<String> SCRIPT = new DefaultRedisScript<>("return KEYS[0]", String.class);
private StringRedisTemplate template;
private @Mock RedisConnection redisConnectionMock;
@@ -49,7 +49,7 @@ public class DefaultScriptExecutorUnitTests {
template = spy(new StringRedisTemplate(connectionFactoryMock));
template.afterPropertiesSet();
executor = new DefaultScriptExecutor<String>(template);
executor = new DefaultScriptExecutor<>(template);
}
@Test // DATAREDIS-347

View File

@@ -45,7 +45,6 @@ import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.TestCondition;
import org.springframework.data.redis.connection.ClusterTestVariables;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -68,7 +67,7 @@ public class PubSubResubscribeTests {
private static final String CHANNEL = "pubsub::test";
private final BlockingDeque<String> bag = new LinkedBlockingDeque<String>(99);
private final BlockingDeque<String> bag = new LinkedBlockingDeque<>(99);
private final Object handler = new MessageHandler("handler1", bag);
private final MessageListenerAdapter adapter = new MessageListenerAdapter(handler);
@@ -156,12 +155,7 @@ public class PubSubResubscribeTests {
container.afterPropertiesSet();
container.start();
waitFor(new TestCondition() {
@Override
public boolean passes() {
return container.getConnectionFactory().getConnection().isSubscribed();
}
}, 1000);
waitFor(container.getConnectionFactory().getConnection()::isSubscribed, 1000);
}
@After
@@ -178,7 +172,7 @@ public class PubSubResubscribeTests {
final String PATTERN = "p*";
final String ANOTHER_CHANNEL = "pubsub::test::extra";
BlockingDeque<String> bag2 = new LinkedBlockingDeque<String>(99);
BlockingDeque<String> bag2 = new LinkedBlockingDeque<>(99);
MessageListenerAdapter anotherListener = new MessageListenerAdapter(new MessageHandler("handler2", bag2));
anotherListener.setSerializer(template.getValueSerializer());
anotherListener.afterPropertiesSet();
@@ -195,7 +189,7 @@ public class PubSubResubscribeTests {
template.convertAndSend(ANOTHER_CHANNEL, payload2);
// anotherListener receives both messages
List<String> msgs = new ArrayList<String>();
List<String> msgs = new ArrayList<>();
msgs.add(bag2.poll(500, TimeUnit.MILLISECONDS));
msgs.add(bag2.poll(500, TimeUnit.MILLISECONDS));
@@ -260,7 +254,7 @@ public class PubSubResubscribeTests {
template.convertAndSend(ANOTHER_CHANNEL, anotherPayload1);
template.convertAndSend(ANOTHER_CHANNEL, anotherPayload2);
Set<String> set = new LinkedHashSet<String>();
Set<String> set = new LinkedHashSet<>();
set.add(bag.poll(500, TimeUnit.MILLISECONDS));
set.add(bag.poll(500, TimeUnit.MILLISECONDS));
@@ -293,11 +287,11 @@ public class PubSubResubscribeTests {
template.convertAndSend("somechannel", "HELLO");
template.convertAndSend(CHANNEL, "WORLD");
Set<String> set = new LinkedHashSet<String>();
Set<String> set = new LinkedHashSet<>();
set.add(bag.poll(500, TimeUnit.MILLISECONDS));
set.add(bag.poll(500, TimeUnit.MILLISECONDS));
assertEquals(new HashSet<String>(Arrays.asList(new String[] { "HELLO", "WORLD" })), set);
assertEquals(new HashSet<>(Arrays.asList(new String[] { "HELLO", "WORLD" })), set);
}
private class MessageHandler {

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2016 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -52,10 +52,10 @@ public class PubSubTestParams {
jedisConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplate = new StringRedisTemplate(jedisConnFactory);
RedisTemplate<String, Person> personTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> personTemplate = new RedisTemplate<>();
personTemplate.setConnectionFactory(jedisConnFactory);
personTemplate.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<>();
rawTemplate.setEnableDefaultSerializer(false);
rawTemplate.setConnectionFactory(jedisConnFactory);
rawTemplate.afterPropertiesSet();
@@ -68,10 +68,10 @@ public class PubSubTestParams {
lettuceConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateLtc = new StringRedisTemplate(lettuceConnFactory);
RedisTemplate<String, Person> personTemplateLtc = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> personTemplateLtc = new RedisTemplate<>();
personTemplateLtc.setConnectionFactory(lettuceConnFactory);
personTemplateLtc.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplateLtc = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> rawTemplateLtc = new RedisTemplate<>();
rawTemplateLtc.setEnableDefaultSerializer(false);
rawTemplateLtc.setConnectionFactory(lettuceConnFactory);
rawTemplateLtc.afterPropertiesSet();

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -47,7 +47,7 @@ import org.springframework.data.redis.test.util.RedisSentinelRule;
/**
* Base test class for PubSub integration tests
*
*
* @author Costin Leau
* @author Jennifer Hickey
*/
@@ -62,7 +62,7 @@ public class PubSubTests<T> {
protected ObjectFactory<T> factory;
@SuppressWarnings("rawtypes") protected RedisTemplate template;
private final BlockingDeque<Object> bag = new LinkedBlockingDeque<Object>(99);
private final BlockingDeque<Object> bag = new LinkedBlockingDeque<>(99);
private final Object handler = new Object() {
@SuppressWarnings("unused")
@@ -121,7 +121,7 @@ public class PubSubTests<T> {
/**
* Return a new instance of T
*
*
* @return
*/
protected T getT() {
@@ -137,7 +137,7 @@ public class PubSubTests<T> {
template.convertAndSend(CHANNEL, payload1);
template.convertAndSend(CHANNEL, payload2);
Set<T> set = new LinkedHashSet<T>();
Set<T> set = new LinkedHashSet<>();
set.add((T) bag.poll(1, TimeUnit.SECONDS));
set.add((T) bag.poll(1, TimeUnit.SECONDS));
@@ -188,7 +188,7 @@ public class PubSubTests<T> {
template.convertAndSend(CHANNEL, payload);
Set<T> set = new LinkedHashSet<T>();
Set<T> set = new LinkedHashSet<>();
set.add((T) bag.poll(3, TimeUnit.SECONDS));
assertThat(set, hasItems(payload));

View File

@@ -25,8 +25,6 @@ import java.util.concurrent.Executor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
@@ -84,14 +82,10 @@ public class RedisMessageListenerContainerTests {
final Thread main = Thread.currentThread();
// interrupt thread once Executor.execute is called
doAnswer(new Answer<Object>() {
doAnswer(invocationOnMock -> {
@Override
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
main.interrupt();
return null;
}
main.interrupt();
return null;
}).when(executorMock).execute(any(Runnable.class));
container.addMessageListener(adapter, new ChannelTopic("a"));

View File

@@ -42,7 +42,7 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
/**
* Integration tests confirming that {@link RedisMessageListenerContainer} closes connections after unsubscribing
*
*
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
@@ -56,7 +56,7 @@ public class SubscriptionConnectionTests {
private RedisConnectionFactory connectionFactory;
private List<RedisMessageListenerContainer> containers = new ArrayList<RedisMessageListenerContainer>();
private List<RedisMessageListenerContainer> containers = new ArrayList<>();
private final Object handler = new Object() {
@SuppressWarnings("unused")

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Copyright 2011-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,7 +25,7 @@ import org.springframework.data.redis.hash.BeanUtilsHashMapper;
public class BeanUtilsHashMapperTest extends AbstractHashMapperTest {
protected <T> BeanUtilsHashMapper<T> mapperFor(Class<T> t) {
return new BeanUtilsHashMapper<T>(t);
return new BeanUtilsHashMapper<>(t);
}
@Test(expected = Exception.class)

View File

@@ -76,7 +76,7 @@ public class Jackson2HashMapperTests {
@Before
public void setUp() {
this.template = new RedisTemplate<String, Object>();
this.template = new RedisTemplate<>();
this.template.setConnectionFactory(factory);
template.afterPropertiesSet();

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.mapping;
import lombok.Data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -31,8 +33,6 @@ import org.springframework.data.redis.Person;
import org.springframework.data.redis.hash.HashMapper;
import org.springframework.data.redis.hash.Jackson2HashMapper;
import lombok.Data;
/**
* Unit tests for {@link Jackson2HashMapper}.
*
@@ -114,7 +114,7 @@ public class Jackson2HashMapperUnitTests extends AbstractHashMapperTest {
public void shouldMapTypedMapOfSimpleTypes() {
WithMap source = new WithMap();
source.strings = new LinkedHashMap<String, String>();
source.strings = new LinkedHashMap<>();
source.strings.put("1", "spring");
source.strings.put("2", "data");
source.strings.put("3", "redis");
@@ -125,7 +125,7 @@ public class Jackson2HashMapperUnitTests extends AbstractHashMapperTest {
public void shouldMapTypedMapOfComplexTypes() {
WithMap source = new WithMap();
source.persons = new LinkedHashMap<String, Person>();
source.persons = new LinkedHashMap<>();
source.persons.put("1", new Person("jon", "snow", 19));
source.persons.put("2", new Person("tyrion", "lannister", 19));
assertBackAndForwardMapping(source);
@@ -135,7 +135,7 @@ public class Jackson2HashMapperUnitTests extends AbstractHashMapperTest {
public void shouldMapUntypedMap() {
WithMap source = new WithMap();
source.objects = new LinkedHashMap<String, Object>();
source.objects = new LinkedHashMap<>();
source.objects.put("1", "spring");
source.objects.put("2", Integer.valueOf(100));
source.objects.put("3", "redis");
@@ -146,16 +146,16 @@ public class Jackson2HashMapperUnitTests extends AbstractHashMapperTest {
public void nestedStuff() {
WithList nestedList = new WithList();
nestedList.objects = new ArrayList<Object>();
nestedList.objects = new ArrayList<>();
WithMap deepNestedMap = new WithMap();
deepNestedMap.persons = new LinkedHashMap<String, Person>();
deepNestedMap.persons = new LinkedHashMap<>();
deepNestedMap.persons.put("jon", new Person("jon", "snow", 24));
nestedList.objects.add(deepNestedMap);
WithMap outer = new WithMap();
outer.objects = new LinkedHashMap<String, Object>();
outer.objects = new LinkedHashMap<>();
outer.objects.put("1", nestedList);
assertBackAndForwardMapping(outer);

View File

@@ -63,7 +63,7 @@ public class RedisRepositoryClusterIntegrationTests extends RedisRepositoryInteg
connectionFactory.afterPropertiesSet();
RedisTemplate<byte[], byte[]> template = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
return template;

View File

@@ -45,7 +45,7 @@ public class RedisRepositoryIntegrationTests extends RedisRepositoryIntegrationT
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
connectionFactory.afterPropertiesSet();
RedisTemplate<byte[], byte[]> template = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
return template;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ public class RedisCdiDependenciesProducer {
@Produces
public RedisOperations<byte[], byte[]> redisOperationsProducer(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<byte[], byte[]> template = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
template.afterPropertiesSet();
return template;

View File

@@ -36,7 +36,7 @@ public class Jackson2JsonRedisSerializerTests {
@Before
public void setUp() {
this.serializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
this.serializer = new Jackson2JsonRedisSerializer<>(Person.class);
}
@Test // DATAREDIS-241

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -170,7 +170,7 @@ public class SimpleRedisSerializerTests {
@Test
public void testJsonSerializer() throws Exception {
Jackson2JsonRedisSerializer<Person> serializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
Jackson2JsonRedisSerializer<Person> serializer = new Jackson2JsonRedisSerializer<>(Person.class);
String value = UUID.randomUUID().toString();
Person p1 = new Person(value, value, 1, new Address(value, 2));
assertEquals(p1, serializer.deserialize(serializer.serialize(p1)));

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,10 +28,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.BoundKeyOperations;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
@@ -72,13 +70,9 @@ public class BoundKeyOperationsTest {
@SuppressWarnings("unchecked")
@After
public void tearDown() {
template.execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
connection.flushDb();
return null;
}
template.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}

View File

@@ -60,10 +60,10 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
this.doubleCounter = new RedisAtomicDouble(getClass().getSimpleName() + ":double", factory);
this.factory = factory;
this.template = new RedisTemplate<String, Double>();
this.template = new RedisTemplate<>();
this.template.setConnectionFactory(factory);
this.template.setKeySerializer(new StringRedisSerializer());
this.template.setValueSerializer(new GenericToStringSerializer<Double>(Double.class));
this.template.setValueSerializer(new GenericToStringSerializer<>(Double.class));
this.template.afterPropertiesSet();
ConnectionFactoryTracker.add(factory);
@@ -182,7 +182,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("a valid key serializer in template is required");
new RedisAtomicDouble("foo", new RedisTemplate<String, Double>());
new RedisAtomicDouble("foo", new RedisTemplate<>());
}
@Test // DATAREDIS-317
@@ -191,7 +191,7 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("a valid value serializer in template is required");
RedisTemplate<String, Double> template = new RedisTemplate<String, Double>();
RedisTemplate<String, Double> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
new RedisAtomicDouble("foo", template);
}

View File

@@ -58,10 +58,10 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
this.intCounter = new RedisAtomicInteger(getClass().getSimpleName() + ":int", factory);
this.factory = factory;
this.template = new RedisTemplate<String, Integer>();
this.template = new RedisTemplate<>();
this.template.setConnectionFactory(factory);
this.template.setKeySerializer(new StringRedisSerializer());
this.template.setValueSerializer(new GenericToStringSerializer<Integer>(Integer.class));
this.template.setValueSerializer(new GenericToStringSerializer<>(Integer.class));
this.template.afterPropertiesSet();
ConnectionFactoryTracker.add(factory);
@@ -155,20 +155,18 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
final AtomicBoolean failed = new AtomicBoolean(false);
for (int i = 0; i < NUM; i++) {
new Thread(new Runnable() {
public void run() {
RedisAtomicInteger atomicInteger = new RedisAtomicInteger(KEY, factory);
try {
if (atomicInteger.compareAndSet(0, 1)) {
System.out.println(atomicInteger.get());
if (alreadySet.get()) {
failed.set(true);
}
alreadySet.set(true);
new Thread(() -> {
RedisAtomicInteger atomicInteger = new RedisAtomicInteger(KEY, factory);
try {
if (atomicInteger.compareAndSet(0, 1)) {
System.out.println(atomicInteger.get());
if (alreadySet.get()) {
failed.set(true);
}
} finally {
latch.countDown();
alreadySet.set(true);
}
} finally {
latch.countDown();
}
}).start();
}
@@ -183,7 +181,7 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("a valid key serializer in template is required");
new RedisAtomicInteger("foo", new RedisTemplate<String, Integer>());
new RedisAtomicInteger("foo", new RedisTemplate<>());
}
@Test // DATAREDIS-317
@@ -192,7 +190,7 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("a valid value serializer in template is required");
RedisTemplate<String, Integer> template = new RedisTemplate<String, Integer>();
RedisTemplate<String, Integer> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
new RedisAtomicInteger("foo", template);
}

View File

@@ -54,10 +54,10 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
this.longCounter = new RedisAtomicLong(getClass().getSimpleName() + ":long", factory);
this.factory = factory;
this.template = new RedisTemplate<String, Long>();
this.template = new RedisTemplate<>();
this.template.setConnectionFactory(factory);
this.template.setKeySerializer(new StringRedisSerializer());
this.template.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
this.template.setValueSerializer(new GenericToStringSerializer<>(Long.class));
this.template.afterPropertiesSet();
ConnectionFactoryTracker.add(factory);
@@ -154,7 +154,7 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("a valid key serializer in template is required");
RedisTemplate<String, Long> template = new RedisTemplate<String, Long>();
RedisTemplate<String, Long> template = new RedisTemplate<>();
new RedisAtomicLong("foo", template);
}
@@ -164,7 +164,7 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("a valid value serializer in template is required");
RedisTemplate<String, Long> template = new RedisTemplate<String, Long>();
RedisTemplate<String, Long> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
new RedisAtomicLong("foo", template);
}
@@ -172,10 +172,10 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests {
@Test // DATAREDIS-317
public void testShouldBeAbleToUseRedisAtomicLongWithProperlyConfiguredRedisTemplate() {
RedisTemplate<String, Long> template = new RedisTemplate<String, Long>();
RedisTemplate<String, Long> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericToStringSerializer<Long>(Long.class));
template.setValueSerializer(new GenericToStringSerializer<>(Long.class));
template.afterPropertiesSet();
RedisAtomicLong ral = new RedisAtomicLong("DATAREDIS-317.atomicLong", template);

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Copyright 2011-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,18 +15,9 @@
*/
package org.springframework.data.redis.support.collections;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import java.util.Arrays;
import java.util.Collection;
@@ -43,14 +34,14 @@ 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.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
/**
* Base test for Redis collections.
*
*
* @author Costin Leau
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
public abstract class AbstractRedisCollectionTests<T> {
@@ -87,7 +78,7 @@ public abstract class AbstractRedisCollectionTests<T> {
/**
* Return a new instance of T
*
*
* @return
*/
protected T getT() {
@@ -99,12 +90,9 @@ public abstract class AbstractRedisCollectionTests<T> {
public void tearDown() throws Exception {
// remove the collection entirely since clear() doesn't always work
collection.getOperations().delete(Collections.singleton(collection.getKey()));
template.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
template.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}

View File

@@ -59,7 +59,7 @@ public class AbstractRedisCollectionUnitTests {
collection = new AbstractRedisCollection<String>("key", redisTemplateSpy) {
private List<String> delegate = new ArrayList<String>();
private List<String> delegate = new ArrayList<>();
@Override
public boolean add(String value) {

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Copyright 2011-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,7 +33,7 @@ import org.springframework.data.redis.core.RedisTemplate;
/**
* Integration test for RedisList
*
*
* @author Costin Leau
* @author Jennifer Hickey
*/
@@ -43,7 +43,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
/**
* Constructs a new <code>AbstractRedisListTests</code> instance.
*
*
* @param factory
* @param template
*/
@@ -367,7 +367,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
list.add(t2);
list.add(t3);
List<T> c = new ArrayList<T>();
List<T> c = new ArrayList<>();
list.drainTo(c, 2);
assertEquals(1, list.size());
@@ -387,7 +387,7 @@ public abstract class AbstractRedisListTests<T> extends AbstractRedisCollectionT
list.add(t2);
list.add(t3);
List<T> c = new ArrayList<T>();
List<T> c = new ArrayList<>();
list.drainTo(c);
assertTrue(list.isEmpty());

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -44,7 +44,6 @@ import org.springframework.data.redis.DoubleAsStringObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisCallback;
@@ -58,11 +57,11 @@ import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test for Redis Map.
*
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Christoph Strobl
* @auhtor Thomas Darimont
* @author Thomas Darimont
*/
@RunWith(Parameterized.class)
public abstract class AbstractRedisMapTests<K, V> {
@@ -118,12 +117,9 @@ public abstract class AbstractRedisMapTests<K, V> {
public void tearDown() throws Exception {
// remove the collection entirely since clear() doesn't always work
map.getOperations().delete(Collections.singleton(map.getKey()));
template.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
template.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@@ -178,7 +174,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testNotEquals() {
RedisOperations<String, ?> ops = map.getOperations();
RedisStore newInstance = new DefaultRedisMap<K, V>(ops.<K, V> boundHashOps(map.getKey() + ":new"));
RedisStore newInstance = new DefaultRedisMap<>(ops.<K, V> boundHashOps(map.getKey() + ":new"));
assertFalse(map.equals(newInstance));
assertFalse(newInstance.equals(map));
}
@@ -290,7 +286,7 @@ public abstract class AbstractRedisMapTests<K, V> {
@Test
public void testPutAll() {
Map<K, V> m = new LinkedHashMap<K, V>();
Map<K, V> m = new LinkedHashMap<>();
K k1 = getKey();
K k2 = getKey();
@@ -385,8 +381,8 @@ public abstract class AbstractRedisMapTests<K, V> {
entries = map.entrySet();
Set<K> keys = new LinkedHashSet<K>();
Collection<V> values = new ArrayList<V>();
Set<K> keys = new LinkedHashSet<>();
Collection<V> values = new ArrayList<>();
for (Entry<K, V> entry : entries) {
keys.add(entry.getKey());

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -42,7 +42,7 @@ import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test for Redis set.
*
*
* @author Costin Leau
* @author Christoph Strobl
* @author Thomas Darimont
@@ -61,7 +61,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
/**
* Constructs a new <code>AbstractRedisSetTests</code> instance.
*
*
* @param factory
* @param template
*/
@@ -79,7 +79,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
@SuppressWarnings("unchecked")
private RedisSet<T> createSetFor(String key) {
return new DefaultRedisSet<T>((BoundSetOperations<String, T>) set.getOperations().boundSetOps(key));
return new DefaultRedisSet<>((BoundSetOperations<String, T>) set.getOperations().boundSetOps(key));
}
@Test
@@ -238,7 +238,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
assertThat(collection.addAll(list), is(true));
Iterator<T> iterator = collection.iterator();
List<T> result = new ArrayList<T>(list);
List<T> result = new ArrayList<>(list);
while (iterator.hasNext()) {
T expected = iterator.next();
@@ -264,7 +264,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
Object[] array = collection.toArray();
List<T> result = new ArrayList<T>(list);
List<T> result = new ArrayList<>(list);
for (int i = 0; i < array.length; i++) {
Iterator<T> resultItr = result.iterator();
@@ -288,7 +288,7 @@ public abstract class AbstractRedisSetTests<T> extends AbstractRedisCollectionTe
assertThat(collection.addAll(list), is(true));
Object[] array = collection.toArray(new Object[expectedArray.length]);
List<T> result = new ArrayList<T>(list);
List<T> result = new ArrayList<>(list);
for (int i = 0; i < array.length; i++) {
Iterator<T> resultItr = result.iterator();

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2017 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -48,7 +48,7 @@ import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test for Redis ZSet.
*
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Thomas Darimont
@@ -68,7 +68,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
/**
* Constructs a new <code>AbstractRedisZSetTest</code> instance.
*
*
* @param factory
* @param template
*/
@@ -212,7 +212,7 @@ public abstract class AbstractRedisZSetTest<T> extends AbstractRedisCollectionTe
@SuppressWarnings("unchecked")
private RedisZSet<T> createZSetFor(String key) {
return new DefaultRedisZSet<T>((BoundZSetOperations<String, T>) zSet.getOperations().boundZSetOps(key));
return new DefaultRedisZSet<>((BoundZSetOperations<String, T>) zSet.getOperations().boundZSetOps(key));
}
@SuppressWarnings("unchecked")

View File

@@ -53,7 +53,7 @@ public abstract class CollectionTestParams {
throw new RuntimeException("Cannot init XStream", ex);
}
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
StringRedisSerializer stringSerializer = new StringRedisSerializer();
// create Jedis Factory
@@ -71,27 +71,27 @@ public abstract class CollectionTestParams {
jedisConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplate = new StringRedisTemplate(jedisConnFactory);
RedisTemplate<String, Person> personTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> personTemplate = new RedisTemplate<>();
personTemplate.setConnectionFactory(jedisConnFactory);
personTemplate.afterPropertiesSet();
RedisTemplate<String, String> xstreamStringTemplate = new RedisTemplate<String, String>();
RedisTemplate<String, String> xstreamStringTemplate = new RedisTemplate<>();
xstreamStringTemplate.setConnectionFactory(jedisConnFactory);
xstreamStringTemplate.setDefaultSerializer(serializer);
xstreamStringTemplate.afterPropertiesSet();
RedisTemplate<String, Person> xstreamPersonTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> xstreamPersonTemplate = new RedisTemplate<>();
xstreamPersonTemplate.setConnectionFactory(jedisConnFactory);
xstreamPersonTemplate.setValueSerializer(serializer);
xstreamPersonTemplate.afterPropertiesSet();
// jackson2
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<>();
jackson2JsonPersonTemplate.setConnectionFactory(jedisConnFactory);
jackson2JsonPersonTemplate.setValueSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplate.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> rawTemplate = new RedisTemplate<>();
rawTemplate.setConnectionFactory(jedisConnFactory);
rawTemplate.setEnableDefaultSerializer(false);
rawTemplate.setKeySerializer(stringSerializer);
@@ -105,26 +105,26 @@ public abstract class CollectionTestParams {
lettuceConnFactory.afterPropertiesSet();
RedisTemplate<String, String> stringTemplateLtc = new StringRedisTemplate(lettuceConnFactory);
RedisTemplate<String, Person> personTemplateLtc = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> personTemplateLtc = new RedisTemplate<>();
personTemplateLtc.setConnectionFactory(lettuceConnFactory);
personTemplateLtc.afterPropertiesSet();
RedisTemplate<String, Person> xstreamStringTemplateLtc = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> xstreamStringTemplateLtc = new RedisTemplate<>();
xstreamStringTemplateLtc.setConnectionFactory(lettuceConnFactory);
xstreamStringTemplateLtc.setDefaultSerializer(serializer);
xstreamStringTemplateLtc.afterPropertiesSet();
RedisTemplate<String, Person> xstreamPersonTemplateLtc = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> xstreamPersonTemplateLtc = new RedisTemplate<>();
xstreamPersonTemplateLtc.setValueSerializer(serializer);
xstreamPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
xstreamPersonTemplateLtc.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateLtc = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> jackson2JsonPersonTemplateLtc = new RedisTemplate<>();
jackson2JsonPersonTemplateLtc.setValueSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
jackson2JsonPersonTemplateLtc.afterPropertiesSet();
RedisTemplate<byte[], byte[]> rawTemplateLtc = new RedisTemplate<byte[], byte[]>();
RedisTemplate<byte[], byte[]> rawTemplateLtc = new RedisTemplate<>();
rawTemplateLtc.setConnectionFactory(lettuceConnFactory);
rawTemplateLtc.setEnableDefaultSerializer(false);
rawTemplateLtc.setKeySerializer(stringSerializer);

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2011-2013 the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,16 +25,9 @@ import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.collections.DefaultRedisList;
import org.springframework.data.redis.support.collections.DefaultRedisMap;
import org.springframework.data.redis.support.collections.DefaultRedisSet;
import org.springframework.data.redis.support.collections.RedisCollectionFactoryBean;
import org.springframework.data.redis.support.collections.RedisProperties;
import org.springframework.data.redis.support.collections.RedisStore;
import org.springframework.data.redis.support.collections.RedisCollectionFactoryBean.CollectionType;
/**
@@ -67,12 +60,9 @@ public class RedisCollectionFactoryBeanTests {
@After
public void tearDown() throws Exception {
// clean up the whole db
template.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
template.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}

View File

@@ -72,8 +72,8 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
throw new RuntimeException("Cannot init XStream", ex);
}
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
Jackson2JsonRedisSerializer<String> jackson2JsonStringSerializer = new Jackson2JsonRedisSerializer<String>(
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
Jackson2JsonRedisSerializer<String> jackson2JsonStringSerializer = new Jackson2JsonRedisSerializer<>(
String.class);
StringRedisSerializer stringSerializer = new StringRedisSerializer();
@@ -98,19 +98,19 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
genericTemplate.setConnectionFactory(jedisConnFactory);
genericTemplate.afterPropertiesSet();
RedisTemplate<String, String> xstreamGenericTemplate = new RedisTemplate<String, String>();
RedisTemplate<String, String> xstreamGenericTemplate = new RedisTemplate<>();
xstreamGenericTemplate.setConnectionFactory(jedisConnFactory);
xstreamGenericTemplate.setDefaultSerializer(serializer);
xstreamGenericTemplate.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<>();
jackson2JsonPersonTemplate.setConnectionFactory(jedisConnFactory);
jackson2JsonPersonTemplate.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplate.setHashKeySerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplate.setHashValueSerializer(jackson2JsonStringSerializer);
jackson2JsonPersonTemplate.afterPropertiesSet();
RedisTemplate<String, byte[]> rawTemplate = new RedisTemplate<String, byte[]>();
RedisTemplate<String, byte[]> rawTemplate = new RedisTemplate<>();
rawTemplate.setEnableDefaultSerializer(false);
rawTemplate.setConnectionFactory(jedisConnFactory);
rawTemplate.setKeySerializer(stringSerializer);
@@ -127,12 +127,12 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
genericTemplateLettuce.setConnectionFactory(lettuceConnFactory);
genericTemplateLettuce.afterPropertiesSet();
RedisTemplate<String, Person> xGenericTemplateLettuce = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> xGenericTemplateLettuce = new RedisTemplate<>();
xGenericTemplateLettuce.setConnectionFactory(lettuceConnFactory);
xGenericTemplateLettuce.setDefaultSerializer(serializer);
xGenericTemplateLettuce.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateLettuce = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> jackson2JsonPersonTemplateLettuce = new RedisTemplate<>();
jackson2JsonPersonTemplateLettuce.setConnectionFactory(lettuceConnFactory);
jackson2JsonPersonTemplateLettuce.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateLettuce.setHashKeySerializer(jackson2JsonSerializer);
@@ -143,7 +143,7 @@ public class RedisMapTests extends AbstractRedisMapTests<Object, Object> {
stringTemplateLtc.setConnectionFactory(lettuceConnFactory);
stringTemplateLtc.afterPropertiesSet();
RedisTemplate<String, byte[]> rawTemplateLtc = new RedisTemplate<String, byte[]>();
RedisTemplate<String, byte[]> rawTemplateLtc = new RedisTemplate<>();
rawTemplateLtc.setEnableDefaultSerializer(false);
rawTemplateLtc.setConnectionFactory(lettuceConnFactory);
rawTemplateLtc.setKeySerializer(stringSerializer);

View File

@@ -188,7 +188,7 @@ public class RedisPropertiesTests extends RedisMapTests {
props.setProperty(key2, val);
Enumeration<?> names = props.propertyNames();
Set<Object> keys = new LinkedHashSet<Object>();
Set<Object> keys = new LinkedHashSet<>();
keys.add(names.nextElement());
keys.add(names.nextElement());
keys.add(names.nextElement());
@@ -238,8 +238,8 @@ public class RedisPropertiesTests extends RedisMapTests {
throw new RuntimeException("Cannot init XStream", ex);
}
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Person>(Person.class);
Jackson2JsonRedisSerializer<String> jackson2JsonStringSerializer = new Jackson2JsonRedisSerializer<String>(
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
Jackson2JsonRedisSerializer<String> jackson2JsonStringSerializer = new Jackson2JsonRedisSerializer<>(
String.class);
// create Jedis Factory
@@ -257,12 +257,12 @@ public class RedisPropertiesTests extends RedisMapTests {
RedisTemplate<String, String> genericTemplate = new StringRedisTemplate(jedisConnFactory);
RedisTemplate<String, String> xstreamGenericTemplate = new RedisTemplate<String, String>();
RedisTemplate<String, String> xstreamGenericTemplate = new RedisTemplate<>();
xstreamGenericTemplate.setConnectionFactory(jedisConnFactory);
xstreamGenericTemplate.setDefaultSerializer(serializer);
xstreamGenericTemplate.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> jackson2JsonPersonTemplate = new RedisTemplate<>();
jackson2JsonPersonTemplate.setConnectionFactory(jedisConnFactory);
jackson2JsonPersonTemplate.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplate.setHashKeySerializer(jackson2JsonSerializer);
@@ -277,12 +277,12 @@ public class RedisPropertiesTests extends RedisMapTests {
lettuceConnFactory.afterPropertiesSet();
RedisTemplate<String, String> genericTemplateLtc = new StringRedisTemplate(lettuceConnFactory);
RedisTemplate<String, Person> xGenericTemplateLtc = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> xGenericTemplateLtc = new RedisTemplate<>();
xGenericTemplateLtc.setConnectionFactory(lettuceConnFactory);
xGenericTemplateLtc.setDefaultSerializer(serializer);
xGenericTemplateLtc.afterPropertiesSet();
RedisTemplate<String, Person> jackson2JsonPersonTemplateLtc = new RedisTemplate<String, Person>();
RedisTemplate<String, Person> jackson2JsonPersonTemplateLtc = new RedisTemplate<>();
jackson2JsonPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
jackson2JsonPersonTemplateLtc.setDefaultSerializer(jackson2JsonSerializer);
jackson2JsonPersonTemplateLtc.setHashKeySerializer(jackson2JsonSerializer);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,14 +29,14 @@ import org.springframework.data.redis.core.convert.Bucket;
/**
* {@link TypeSafeMatcher} implementation for checking contents of {@link Bucket}.
*
*
* @author Christoph Strobl
* @since 1.7
*/
public class IsBucketMatcher extends TypeSafeMatcher<Bucket> {
Map<String, Object> expected = new LinkedHashMap<String, Object>();
Set<String> without = new LinkedHashSet<String>();
Map<String, Object> expected = new LinkedHashMap<>();
Set<String> without = new LinkedHashSet<>();
/*
* (non-Javadoc)
@@ -122,7 +122,7 @@ public class IsBucketMatcher extends TypeSafeMatcher<Bucket> {
/**
* Creates new {@link IsBucketMatcher}.
*
*
* @return
*/
public static IsBucketMatcher isBucket() {
@@ -131,7 +131,7 @@ public class IsBucketMatcher extends TypeSafeMatcher<Bucket> {
/**
* Checks for presence of type hint at given path.
*
*
* @param path
* @param type
* @return
@@ -144,7 +144,7 @@ public class IsBucketMatcher extends TypeSafeMatcher<Bucket> {
/**
* Checks for presence of equivalent String value at path.
*
*
* @param path
* @param value
* @return
@@ -157,7 +157,7 @@ public class IsBucketMatcher extends TypeSafeMatcher<Bucket> {
/**
* Checks for presence of given value at path.
*
*
* @param path
* @param value
* @return
@@ -176,7 +176,7 @@ public class IsBucketMatcher extends TypeSafeMatcher<Bucket> {
/**
* Checks for presence of equivalent time in msec value at path.
*
*
* @param path
* @param date
* @return
@@ -189,7 +189,7 @@ public class IsBucketMatcher extends TypeSafeMatcher<Bucket> {
/**
* Checks given path is not present.
*
*
* @param path
* @return
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ public class MockitoUtils {
/**
* Verifies a given method is called a total number of times across all given mocks.
*
*
* @param method
* @param mode
* @param mocks
@@ -62,7 +62,7 @@ public class MockitoUtils {
private static List<Invocation> getInvocations(String method, Object... mocks) {
List<Invocation> invocations = new ArrayList<Invocation>();
List<Invocation> invocations = new ArrayList<>();
for (Object mock : mocks) {
if (StringUtils.hasText(method)) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.test.util;
import redis.clients.jedis.Jedis;
import java.util.HashMap;
import java.util.Map;
@@ -25,8 +27,6 @@ import org.junit.runners.model.Statement;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import redis.clients.jedis.Jedis;
/**
* @author Christoph Strobl
*/
@@ -42,7 +42,7 @@ public class RedisSentinelRule implements TestRule {
private RedisSentinelConfiguration sentinelConfig;
private SentinelsAvailable requiredSentinels;
private Map<Object, Boolean> cache = new HashMap<Object, Boolean>();
private Map<Object, Boolean> cache = new HashMap<>();
protected RedisSentinelRule(RedisSentinelConfiguration config) {
this.sentinelConfig = config;
@@ -50,7 +50,7 @@ public class RedisSentinelRule implements TestRule {
/**
* Create new {@link RedisSentinelRule} for given {@link RedisSentinelConfiguration}.
*
*
* @param config
* @return
*/
@@ -60,7 +60,7 @@ public class RedisSentinelRule implements TestRule {
/**
* Create new {@link RedisSentinelRule} using default configuration.
*
*
* @return
*/
public static RedisSentinelRule withDefaultConfig() {
@@ -75,7 +75,7 @@ public class RedisSentinelRule implements TestRule {
/**
* Verifies all {@literal Sentinel} nodes are available.
*
*
* @return
*/
public RedisSentinelRule allActive() {
@@ -86,7 +86,7 @@ public class RedisSentinelRule implements TestRule {
/**
* Verifies at least one {@literal Sentinel} node is available.
*
*
* @return
*/
public RedisSentinelRule oneActive() {
@@ -98,7 +98,7 @@ public class RedisSentinelRule implements TestRule {
/**
* Will only check {@link RedisSentinelConfiguration} configuration in case {@link RequiresRedisSentinel} is detected
* on test method.
*
*
* @return
*/
public RedisSentinelRule dynamicModeSelection() {