DATAREDIS-438 - Polishing.

RedisGeoCommands now take and return Spring Data domain types like Distance and GeoResults.
Updated JavaDoc and Reference documentation.
Added and updated author and license headers.
Fixed minor formatting and code style issues.

Original Pulll Request: #187
This commit is contained in:
Christoph Strobl
2016-05-11 00:16:31 +02:00
parent b0e20d3da8
commit f732b5f6b9
49 changed files with 9106 additions and 5386 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2015 the original author or authors.
* 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.
@@ -39,6 +39,7 @@ public class RedisTestProfileValueSource implements ProfileValueSource {
private static final String REDIS_26 = "2.6";
private static final String REDIS_28 = "2.8";
private static final String REDIS_30 = "3.0";
private static final String REDIS_32 = "3.2";
private static final String REDIS_VERSION_KEY = "redisVersion";
private static RedisTestProfileValueSource INSTANCE;
@@ -95,6 +96,10 @@ public class RedisTestProfileValueSource implements ProfileValueSource {
return System.getProperty(key);
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_32)) >= 0) {
return REDIS_32;
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_30)) >= 0) {
return REDIS_30;
}

View File

@@ -16,10 +16,14 @@
package org.springframework.data.redis.connection;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
import static org.springframework.data.redis.core.ScanOptions.*;
import java.util.ArrayList;
@@ -48,10 +52,16 @@ import org.junit.Test;
import org.junit.internal.AssumptionViolatedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Metrics;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.RedisVersionUtils;
import org.springframework.data.redis.TestCondition;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
@@ -86,6 +96,14 @@ import org.springframework.test.annotation.ProfileValueSourceConfiguration;
@ProfileValueSourceConfiguration(RedisTestProfileValueSource.class)
public abstract class AbstractConnectionIntegrationTests {
private static final Point POINT_ARIGENTO = new Point(13.583333, 37.316667);
private static final Point POINT_CATANIA = new Point(15.087269, 37.502669);
private static final Point POINT_PALERMO = new Point(13.361389, 38.115556);
private static final GeoLocation<String> ARIGENTO = new GeoLocation<String>("arigento", POINT_ARIGENTO);
private static final GeoLocation<String> CATANIA = new GeoLocation<String>("catania", POINT_CATANIA);
private static final GeoLocation<String> PALERMO = new GeoLocation<String>("palermo", POINT_PALERMO);
protected StringRedisConnection connection;
protected RedisSerializer<Object> serializer = new JdkSerializationRedisSerializer();
protected RedisSerializer<String> stringSerializer = new StringRedisSerializer();
@@ -1219,7 +1237,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.rPush("PopList", "world"));
connection.lSet("PopList", 1, "cruel");
actual.add(connection.lRange("PopList", 0, -1));
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "cruel", "world" }) }));
verifyResults(
Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "cruel", "world" }) }));
}
@Test
@@ -1318,8 +1337,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "foo"));
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" })) }));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })) }));
}
@Test
@@ -1327,8 +1346,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "foo", "bar"));
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" })) }));
verifyResults(Arrays
.asList(new Object[] { 2l, 1l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
}
@Test
@@ -1355,7 +1374,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("otherset", "bar"));
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")) }));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("foo")) }));
}
@Test
@@ -1374,7 +1394,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("otherset", "bar"));
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")) }));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
@@ -1400,7 +1421,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "foo"));
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)));
assertTrue(
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
}
@Test
@@ -1408,7 +1430,8 @@ 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((String) getResults().get(2)));
assertTrue(
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
}
@Test
@@ -1452,7 +1475,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sRem("myset", "foo"));
actual.add(connection.sRem("myset", "baz"));
actual.add(connection.sMembers("myset"));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 0l, new HashSet<String>(Collections.singletonList("bar")) }));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 0l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
@@ -1462,7 +1486,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("myset", "baz"));
actual.add(connection.sRem("myset", "foo", "nope", "baz"));
actual.add(connection.sMembers("myset"));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 2l, new HashSet<String>(Collections.singletonList("bar")) }));
verifyResults(
Arrays.asList(new Object[] { 1l, 1l, 1l, 2l, new HashSet<String>(Collections.singletonList("bar")) }));
}
@Test
@@ -1472,8 +1497,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("otherset", "bar"));
actual.add(connection.sAdd("otherset", "baz"));
actual.add(connection.sUnion("myset", "otherset"));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l,
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
verifyResults(Arrays.asList(
new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
}
@Test
@@ -1484,8 +1509,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.sAdd("otherset", "baz"));
actual.add(connection.sUnionStore("thirdset", "myset", "otherset"));
actual.add(connection.sMembers("thirdset"));
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, 3l,
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
verifyResults(Arrays.asList(
new Object[] { 1l, 1l, 1l, 1l, 3l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
}
// ZSet
@@ -1495,8 +1520,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRange("myset", 0, -1));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "James", "Bob" })) }));
verifyResults(Arrays.asList(
new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "James", "Bob" })) }));
}
@Test
@@ -1509,8 +1534,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", strTuples));
actual.add(connection.zAdd("myset".getBytes(), tuples));
actual.add(connection.zRange("myset", 0, -1));
verifyResults(Arrays.asList(new Object[] { 2l, 1l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "James", "Bob", "Joe" })) }));
verifyResults(Arrays.asList(
new Object[] { 2l, 1l, new LinkedHashSet<String>(Arrays.asList(new String[] { "James", "Bob", "Joe" })) }));
}
@Test
@@ -1537,8 +1562,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 4, "Joe"));
actual.add(connection.zIncrBy("myset", 2, "Joe"));
actual.add(connection.zRangeByScore("myset", 6, 6));
verifyResults(Arrays.asList(new Object[] { true, true, true, 6d,
new LinkedHashSet<String>(Collections.singletonList("Joe")) }));
verifyResults(Arrays
.asList(new Object[] { true, true, true, 6d, new LinkedHashSet<String>(Collections.singletonList("Joe")) }));
}
@Test
@@ -1564,16 +1589,10 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zInterStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset"));
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
verifyResults(Arrays.asList(new Object[] {
true,
true,
true,
true,
true,
2l,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d),
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 2l,
new LinkedHashSet<StringTuple>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 4d),
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
}
@Test
@@ -1581,12 +1600,10 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRangeWithScores("myset", 0, -1));
verifyResults(Arrays.asList(new Object[] {
true,
true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("James".getBytes(), "James", 1d),
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<StringTuple>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(), "James", 1d),
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
}
@Test
@@ -1594,8 +1611,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRangeByScore("myset", 1, 1));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "James" })) }));
verifyResults(
Arrays.asList(new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "James" })) }));
}
@Test
@@ -1603,8 +1620,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
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" })) }));
verifyResults(
Arrays.asList(new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
}
@Test
@@ -1612,11 +1629,8 @@ 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>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(),
"Bob", 2d) })) }));
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<StringTuple>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
}
@Test
@@ -1624,11 +1638,8 @@ 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>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(),
"James", 1d) })) }));
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<StringTuple>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
}
@Test
@@ -1636,8 +1647,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRevRange("myset", 0, -1));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
verifyResults(Arrays.asList(
new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
}
@Test
@@ -1645,12 +1656,10 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 2, "Bob"));
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRevRangeWithScores("myset", 0, -1));
verifyResults(Arrays.asList(new Object[] {
true,
true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<StringTuple>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
}
@Test
@@ -1658,8 +1667,8 @@ 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.zRevRangeByScore("myset", 0d, 3d, 0, 5));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
verifyResults(Arrays.asList(
new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
}
@Test
@@ -1667,8 +1676,8 @@ 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.zRevRangeByScore("myset", 0d, 3d));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
verifyResults(Arrays.asList(
new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
}
@Test
@@ -1676,11 +1685,8 @@ 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>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(),
"Bob", 2d) })) }));
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<StringTuple>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
}
@Test
@@ -1689,13 +1695,10 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zAdd("myset", 3, "Joe"));
actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 2d));
verifyResults(Arrays.asList(new Object[] {
true,
true,
true,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
verifyResults(Arrays.asList(new Object[] { true, true, true,
new LinkedHashSet<StringTuple>(
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
}
@Test
@@ -1713,8 +1716,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRem("myset", "James"));
actual.add(connection.zRange("myset", 0l, -1l));
verifyResults(Arrays.asList(new Object[] { true, true, 1l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
verifyResults(Arrays
.asList(new Object[] { true, true, 1l, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
}
@Test
@@ -1744,8 +1747,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 1, "James"));
actual.add(connection.zRemRangeByScore("myset", 0d, 1d));
actual.add(connection.zRange("myset", 0l, -1l));
verifyResults(Arrays.asList(new Object[] { true, true, 1l,
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
verifyResults(Arrays
.asList(new Object[] { true, true, 1l, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
}
@Test
@@ -1788,13 +1791,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("otherset", 4, "James"));
actual.add(connection.zUnionStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset"));
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
verifyResults(Arrays.asList(new Object[] {
true,
true,
true,
true,
true,
3l,
verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 3l,
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), new DefaultStringTuple("Joe".getBytes(), "Joe", 8d),
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
@@ -1868,8 +1865,8 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.hSet("test", "key", "2"));
actual.add(connection.hSet("test", "key2", "2"));
actual.add(connection.hKeys("test"));
verifyResults(Arrays.asList(new Object[] { true, true,
new LinkedHashSet<String>(Arrays.asList(new String[] { "key", "key2" })) }));
verifyResults(Arrays
.asList(new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "key", "key2" })) }));
}
@Test
@@ -2098,8 +2095,8 @@ public abstract class AbstractConnectionIntegrationTests {
connection.hSet("hscankey", "foo-2", "v-2");
connection.hSet("hscankey", "foo-3", "v-3");
Cursor<Map.Entry<String, String>> cursor = connection
.hScan("hscankey", scanOptions().count(2).match("fo*").build());
Cursor<Map.Entry<String, String>> cursor = connection.hScan("hscankey",
scanOptions().count(2).match("fo*").build());
int i = 0;
while (cursor.hasNext()) {
@@ -2509,6 +2506,269 @@ public abstract class AbstractConnectionIntegrationTests {
assertThat(((Long) result.get(1)).doubleValue(), is(closeTo(-2, 0)));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoAddSingleGeoLocation() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, PALERMO));
List<Object> result = getResults();
assertThat((Long) result.get(0), is(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoAddMultipleGeoLocations() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, ARIGENTO, CATANIA, PALERMO)));
List<Object> result = getResults();
assertThat((Long) result.get(0), is(3L));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoDist() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
actual.add(connection.geoDist(key, PALERMO.getName(), CATANIA.getName()));
List<Object> result = getResults();
assertThat(((Distance) result.get(1)).getValue(), is(closeTo(166274.15156960033D, 0.005)));
assertThat(((Distance) result.get(1)).getUnit(), is("m"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoDistWithMetric() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
actual.add(connection.geoDist(key, PALERMO.getName(), CATANIA.getName(), Metrics.KILOMETERS));
List<Object> result = getResults();
assertThat(((Distance) result.get(1)).getValue(), is(closeTo(166.27415156960033D, 0.005)));
assertThat(((Distance) result.get(1)).getUnit(), is("km"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS })
public void geoHash() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
actual.add(connection.geoHash(key, PALERMO.getName(), CATANIA.getName()));
List<Object> result = getResults();
assertThat(((List<String>) result.get(1)).get(0), is("sqc8b49rny0"));
assertThat(((List<String>) result.get(1)).get(1), is("sqdtr74hyu0"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS })
public void geoHashNonExisting() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
actual.add(connection.geoHash(key, PALERMO.getName(), ARIGENTO.getName(), CATANIA.getName()));
List<Object> result = getResults();
assertThat(((List<String>) result.get(1)).get(0), is("sqc8b49rny0"));
assertThat(((List<String>) result.get(1)).get(1), is(nullValue()));
assertThat(((List<String>) result.get(1)).get(2), is("sqdtr74hyu0"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoPosition() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
actual.add(connection.geoPos(key, PALERMO.getName(), CATANIA.getName()));
List<Object> result = getResults();
assertThat(((List<Point>) result.get(1)).get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(((List<Point>) result.get(1)).get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(((List<Point>) result.get(1)).get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(((List<Point>) result.get(1)).get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoPositionNonExisting() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
actual.add(connection.geoPos(key, PALERMO.getName(), ARIGENTO.getName(), CATANIA.getName()));
List<Object> result = getResults();
assertThat(((List<Point>) result.get(1)).get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(((List<Point>) result.get(1)).get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(((List<Point>) result.get(1)).get(1), is(nullValue()));
assertThat(((List<Point>) result.get(1)).get(2).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(((List<Point>) result.get(1)).get(2).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoRadiusShouldReturnMembersCorrectly() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
actual.add(connection.georadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS))));
actual.add(connection.georadius(key, new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS))));
List<Object> results = getResults();
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(3));
assertThat(((GeoResults<GeoLocation<String>>) results.get(2)).getContent(), hasSize(2));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoRadiusShouldReturnDistanceCorrectly() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
actual.add(connection.georadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)),
newGeoRadiusArgs().includeDistance()));
List<Object> results = getResults();
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(3));
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getDistance().getValue(),
is(closeTo(130.423D, 0.005)));
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getDistance().getUnit(),
is("km"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoRadiusShouldApplyLimit() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
actual.add(connection.georadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)),
newGeoRadiusArgs().limit(2)));
List<Object> results = getResults();
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(2));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
actual.add(connection.georadiusByMember(key, PALERMO.getName(), new Distance(100, KILOMETERS),
newGeoRadiusArgs().sortAscending()));
List<Object> results = getResults();
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getContent().getName(),
is(PALERMO.getName()));
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(1).getContent().getName(),
is(ARIGENTO.getName()));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
actual.add(connection.georadiusByMember(key, PALERMO.getName(), new Distance(100, KILOMETERS),
newGeoRadiusArgs().includeDistance()));
List<Object> results = getResults();
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(2));
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getDistance().getValue(),
is(closeTo(90.978D, 0.005)));
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getDistance().getUnit(),
is("km"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
public void geoRadiusByMemberShouldApplyLimit() {
String key = "geo-" + UUID.randomUUID();
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
actual.add(connection.georadiusByMember(key, PALERMO.getName(), new Distance(200, KILOMETERS),
newGeoRadiusArgs().limit(2)));
List<Object> results = getResults();
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(2));
}
protected void verifyResults(List<Object> expected) {
assertEquals(expected, getResults());
}

View File

@@ -15,11 +15,17 @@
*/
package org.springframework.data.redis.connection;
import org.springframework.data.geo.Point;
/**
* @author Christoph Strobl
*/
public interface ClusterConnectionTests {
static final Point POINT_ARIGENTO = new Point(13.583333, 37.316667);
static final Point POINT_CATANIA = new Point(15.087269, 37.502669);
static final Point POINT_PALERMO = new Point(13.361389, 38.115556);
/**
* @see DATAREDIS-315
*/
@@ -946,4 +952,78 @@ public interface ClusterConnectionTests {
*/
void setWithExpirationAndIfPresentShouldNotBeAppliedWhenKeyDoesNotExists();
/**
* @see DATAREDIS-438
*/
void geoAddSingleGeoLocation();
/**
* @see DATAREDIS-438
*/
void geoAddMultipleGeoLocations();
/**
* @see DATAREDIS-438
*/
void geoDist();
/**
* @see DATAREDIS-438
*/
void geoDistWithMetric();
/**
* @see DATAREDIS-438
*/
void geoHash();
/**
* @see DATAREDIS-438
*/
void geoHashNonExisting();
/**
* @see DATAREDIS-438
*/
void geoPosition();
/**
* @see DATAREDIS-438
*/
void geoPositionNonExisting();
/**
* @see DATAREDIS-438
*/
void geoRadiusShouldReturnMembersCorrectly();
/**
* @see DATAREDIS-438
*/
void geoRadiusShouldReturnDistanceCorrectly();
/**
* @see DATAREDIS-438
*/
void geoRadiusShouldApplyLimit();
/**
* @see DATAREDIS-438
*/
void geoRadiusByMemberShouldReturnMembersCorrectly();
/**
* @see DATAREDIS-438
*/
void geoRadiusByMemberShouldReturnDistanceCorrectly();
/**
* @see DATAREDIS-438
*/
void geoRadiusByMemberShouldApplyLimit();
/**
* @see DATAREDIS-438
*/
void geoRemoveDeletesMembers();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.
@@ -17,16 +17,22 @@ package org.springframework.data.redis.connection;
import static org.mockito.Mockito.*;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.geo.Distance;
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
/**
* Unit test of {@link DefaultStringRedisConnection} that executes commands in a pipeline
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Ninad Divadkar
*/
public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedisConnectionTests {
@@ -1287,155 +1293,282 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi
@Test
public void testZUnionStoreAggWeights() {
doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline();
doReturn(Collections.singletonList(5l)).when(nativeConnection).closePipeline();
super.testZUnionStoreAggWeights();
}
@Test
public void testZUnionStoreBytes() {
doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline();
doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline();
super.testZUnionStoreBytes();
}
@Test
public void testZUnionStore() {
doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline();
doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline();
super.testZUnionStore();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddBytes(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
public void testGeoAddBytes() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
super.testGeoAddBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAdd(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
public void testGeoAdd() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
super.testGeoAddBytes();
}
/**
* @see DATAREDIS-438
*/
@Override
public void testGeoAddWithGeoLocationBytes() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
super.testGeoAddWithGeoLocationBytes();
}
/**
* @see DATAREDIS-438
*/
@Override
public void testGeoAddWithGeoLocation() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
super.testGeoAddWithGeoLocation();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddCoordinateMapBytes(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
public void testGeoAddCoordinateMapBytes() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
super.testGeoAddCoordinateMapBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddCoordinateMap(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
public void testGeoAddCoordinateMap() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
super.testGeoAddCoordinateMap();
}
/**
* @see DATAREDIS-438
*/
@Override
public void testGeoAddWithIterableOfGeoLocationBytes() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
super.testGeoAddWithIterableOfGeoLocationBytes();
}
/**
* @see DATAREDIS-438
*/
@Override
public void testGeoAddWithIterableOfGeoLocation() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
super.testGeoAddWithIterableOfGeoLocation();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoDistBytes(){
doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).closePipeline();
public void testGeoDistBytes() {
doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).closePipeline();
super.testGeoDistBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoDist(){
doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).closePipeline();
public void testGeoDist() {
doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).closePipeline();
super.testGeoDist();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoHashBytes(){
List<byte[]> expected = new ArrayList<byte[]>();
expected.add(barBytes);
doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).closePipeline();
public void testGeoHashBytes() {
doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).closePipeline();
super.testGeoHashBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoHash(){
List<byte[]> expected = new ArrayList<byte[]>();
expected.add(barBytes);
doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).closePipeline();
public void testGeoHash() {
doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).closePipeline();
super.testGeoHash();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoPosBytes(){
doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).closePipeline();
public void testGeoPosBytes() {
doReturn(Arrays.asList(points)).when(nativeConnection).closePipeline();
super.testGeoPosBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoPos(){
doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).closePipeline();
public void testGeoPos() {
doReturn(Arrays.asList(points)).when(nativeConnection).closePipeline();
super.testGeoPos();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithoutParamBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusWithoutParamBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusWithoutParamBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithoutParam(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusWithoutParam() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusWithoutParam();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithDistBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusWithDistBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusWithDistBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithDist(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusWithDist() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusWithDist();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithCoordAndDescBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusWithCoordAndDescBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusWithCoordAndDescBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithCoordAndDesc(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusWithCoordAndDesc() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusWithCoordAndDesc();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithoutParamBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusByMemberWithoutParamBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithoutParamBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithoutParam(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusByMemberWithoutParam() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithoutParam();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithDistAndAscBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusByMemberWithDistAndAscBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithDistAndAscBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithDistAndAsc(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusByMemberWithDistAndAsc() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithDistAndAsc();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithCoordAndCountBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusByMemberWithCoordAndCountBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithCoordAndCountBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithCoordAndCount(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
public void testGeoRadiusByMemberWithCoordAndCount() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithCoordAndCount();
}

View File

@@ -1,14 +1,38 @@
/*
* Copyright 2013-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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.geo.Distance;
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
/**
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Ninad Divadkar
*/
public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRedisConnectionTxTests {
@Before
@@ -1387,142 +1411,6 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
super.testZUnionStore();
}
@Test
public void testGeoAddBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
super.testGeoAddBytes();
}
@Test
public void testGeoAdd(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
super.testGeoAddBytes();
}
@Test
public void testGeoAddCoordinateMapBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
super.testGeoAddCoordinateMapBytes();
}
@Test
public void testGeoAddCoordinateMap(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
super.testGeoAddCoordinateMap();
}
@Test
public void testGeoDistBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 102121.12d }) })).when(nativeConnection).closePipeline();
super.testGeoDistBytes();
}
@Test
public void testGeoDist(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 102121.12d }) })).when(nativeConnection).closePipeline();
super.testGeoDist();
}
@Test
public void testGeoHashBytes(){
List<byte[]> expected = new ArrayList<byte[]>();
expected.add(barBytes);
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { expected }) })).when(nativeConnection).closePipeline();
super.testGeoHashBytes();
}
@Test
public void testGeoHash(){
List<byte[]> expected = new ArrayList<byte[]>();
expected.add(barBytes);
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { expected }) })).when(nativeConnection).closePipeline();
super.testGeoHash();
}
@Test
public void testGeoPosBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoCoordinates }) })).when(nativeConnection).closePipeline();
super.testGeoPosBytes();
}
@Test
public void testGeoPos(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoCoordinates }) })).when(nativeConnection).closePipeline();
super.testGeoPos();
}
@Test
public void testGeoRadiusWithoutParamBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithoutParamBytes();
}
@Test
public void testGeoRadiusWithoutParam(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithoutParam();
}
@Test
public void testGeoRadiusWithDistBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithDistBytes();
}
@Test
public void testGeoRadiusWithDist(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithDist();
}
@Test
public void testGeoRadiusWithCoordAndDescBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithCoordAndDescBytes();
}
@Test
public void testGeoRadiusWithCoordAndDesc(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithCoordAndDesc();
}
@Test
public void testGeoRadiusByMemberWithoutParamBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithoutParamBytes();
}
@Test
public void testGeoRadiusByMemberWithoutParam(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithoutParam();
}
@Test
public void testGeoRadiusByMemberWithDistAndAscBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithDistAndAscBytes();
}
@Test
public void testGeoRadiusByMemberWithDistAndAsc(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithDistAndAsc();
}
@Test
public void testGeoRadiusByMemberWithCoordAndCountBytes(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithCoordAndCountBytes();
}
@Test
public void testGeoRadiusByMemberWithCoordAndCount(){
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithCoordAndCount();
}
@Test
public void testPExpireBytes() {
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection)
@@ -1655,9 +1543,9 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
@Test
public void testTwoTxs() {
doReturn(
Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }), Arrays.asList(new Object[] { fooBytes }) }))
.when(nativeConnection).closePipeline();
doReturn(Arrays
.asList(new Object[] { Arrays.asList(new Object[] { barBytes }), Arrays.asList(new Object[] { fooBytes }) }))
.when(nativeConnection).closePipeline();
connection.get(foo);
connection.exec();
connection.get(bar);
@@ -1668,6 +1556,268 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
results);
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddBytes() {
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
super.testGeoAddBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAdd() {
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
super.testGeoAddBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddWithGeoLocationBytes() {
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
super.testGeoAddWithGeoLocationBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddWithGeoLocation() {
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
super.testGeoAddWithGeoLocation();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddCoordinateMapBytes() {
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
super.testGeoAddCoordinateMapBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddCoordinateMap() {
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
super.testGeoAddCoordinateMap();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddWithIterableOfGeoLocationBytes() {
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
super.testGeoAddWithIterableOfGeoLocationBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddWithIterableOfGeoLocation() {
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
super.testGeoAddWithIterableOfGeoLocation();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoDistBytes() {
doReturn(Arrays.asList(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS)))).when(nativeConnection)
.closePipeline();
super.testGeoDistBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoDist() {
doReturn(Arrays.asList(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS)))).when(nativeConnection)
.closePipeline();
super.testGeoDist();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoHashBytes() {
doReturn(Arrays.asList(Arrays.asList(Collections.singletonList(bar)))).when(nativeConnection).closePipeline();
super.testGeoHashBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoHash() {
doReturn(Arrays.asList(Arrays.asList(Collections.singletonList(bar)))).when(nativeConnection).closePipeline();
super.testGeoHash();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoPosBytes() {
doReturn(Arrays.asList(Arrays.asList(points))).when(nativeConnection).closePipeline();
super.testGeoPosBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoPos() {
doReturn(Arrays.asList(Arrays.asList(points))).when(nativeConnection).closePipeline();
super.testGeoPos();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithoutParamBytes() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusWithoutParamBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithoutParam() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusWithoutParam();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithDistBytes() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusWithDistBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithDist() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusWithDist();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithCoordAndDescBytes() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusWithCoordAndDescBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithCoordAndDesc() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusWithCoordAndDesc();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithoutParamBytes() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithoutParamBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithoutParam() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithoutParam();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithDistAndAscBytes() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithDistAndAscBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithDistAndAsc() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithDistAndAsc();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithCoordAndCountBytes() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithCoordAndCountBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithCoordAndCount() {
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithCoordAndCount();
}
@SuppressWarnings("unchecked")
protected List<Object> getResults() {
connection.exec();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.
@@ -34,16 +34,21 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResult;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
import org.springframework.data.redis.core.GeoCoordinate;
import org.springframework.data.redis.core.GeoRadiusParam;
import org.springframework.data.redis.core.GeoRadiusResponse;
import org.springframework.data.redis.core.GeoUnit;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
@@ -51,6 +56,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
*
* @author Jennifer Hickey
* @auhtor Christoph Strobl
* @author Ninad Divadkar
*/
public class DefaultStringRedisConnectionTests {
@@ -66,13 +72,13 @@ public class DefaultStringRedisConnectionTests {
protected String bar = "bar";
protected String bar2 = "bar2";
protected String bar2 = "bar2";
protected byte[] fooBytes = serializer.serialize(foo);
protected byte[] barBytes = serializer.serialize(bar);
protected byte[] bar2Bytes = serializer.serialize(bar2);
protected byte[] bar2Bytes = serializer.serialize(bar2);
protected List<byte[]> bytesList = Collections.singletonList(barBytes);
@@ -91,11 +97,12 @@ public class DefaultStringRedisConnectionTests {
protected Set<StringTuple> stringTupleSet = new HashSet<StringTuple>(
Collections.singletonList(new DefaultStringTuple(new DefaultTuple(barBytes, 3d), bar)));
protected GeoCoordinate geoCoordinate = new GeoCoordinate(213.00, 324.343);
protected List<GeoCoordinate> geoCoordinates = new ArrayList<GeoCoordinate>();
protected Point point = new Point(213.00, 324.343);
protected List<Point> points = new ArrayList<Point>();
protected GeoRadiusResponse geoRadiusResponse = new GeoRadiusResponse(barBytes);
protected List<GeoRadiusResponse> geoRadiusResponses = new ArrayList<GeoRadiusResponse>();
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);
@Before
public void setUp() {
@@ -103,8 +110,7 @@ public class DefaultStringRedisConnectionTests {
this.connection = new DefaultStringRedisConnection(nativeConnection);
bytesMap.put(fooBytes, barBytes);
stringMap.put(foo, bar);
geoCoordinates.add(geoCoordinate);
geoRadiusResponses.add(geoRadiusResponse);
points.add(point);
}
@Test
@@ -1586,188 +1592,6 @@ public class DefaultStringRedisConnectionTests {
}
@Test
public void testGeoAddBytes(){
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, 1.23232, 34.2342434, barBytes);
actual.add(connection.geoAdd(fooBytes, 1.23232, 34.2342434, barBytes));
verifyResults(Arrays.asList(new Object[] { 1l }));
}
@Test
public void testGeoAdd(){
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, 1.23232, 34.2342434, barBytes);
actual.add(connection.geoAdd(foo, 1.23232, 34.2342434, bar));
verifyResults(Arrays.asList(new Object[] { 1l }));
}
@Test
public void testGeoAddCoordinateMapBytes(){
Map<byte[], GeoCoordinate> memberGeoCoordinateMap = new HashMap<byte[], GeoCoordinate>();
memberGeoCoordinateMap.put(barBytes, new GeoCoordinate(1.23232, 34.2342434));
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, memberGeoCoordinateMap);
actual.add(connection.geoAdd(fooBytes, memberGeoCoordinateMap));
verifyResults(Arrays.asList(new Object[] { 1l }));
}
@Test
public void testGeoAddCoordinateMap(){
GeoCoordinate geoCoordinate = new GeoCoordinate(1.23232, 34.2342434);
doReturn(1l).when(nativeConnection).geoAdd(any(byte[].class), anyMapOf(byte[].class, GeoCoordinate.class));
Map<String, GeoCoordinate> stringGeoCoordinateMap = new HashMap<String, GeoCoordinate>();
stringGeoCoordinateMap.put(bar, geoCoordinate);
actual.add(connection.geoAdd(foo, stringGeoCoordinateMap));
verifyResults(Arrays.asList(new Object[] { 1l }));
}
@Test
public void testGeoDistBytes(){
doReturn(102121.12d).when(nativeConnection).geoDist(fooBytes, barBytes, bar2Bytes, GeoUnit.Meters);
actual.add(connection.geoDist(fooBytes, barBytes, bar2Bytes, GeoUnit.Meters));
verifyResults(Arrays.asList(new Object[] { 102121.12d }));
}
@Test
public void testGeoDist(){
doReturn(102121.12d).when(nativeConnection).geoDist(fooBytes, barBytes, bar2Bytes, GeoUnit.Meters);
actual.add(connection.geoDist(foo, bar, bar2, GeoUnit.Meters));
verifyResults(Arrays.asList(new Object[] { 102121.12d }));
}
@Test
public void testGeoHashBytes(){
doReturn(bytesList).when(nativeConnection).geoHash(fooBytes, barBytes);
actual.add(connection.geoHash(fooBytes, barBytes));
List<byte[]> expected = new ArrayList<byte[]>();
expected.add(barBytes);
verifyResults(Arrays.asList(new Object[]{expected}));
}
@Test
public void testGeoHash(){
doReturn(bytesList).when(nativeConnection).geoHash(fooBytes, barBytes);
actual.add(connection.geoHash(foo, bar));
List<String> expected = new ArrayList<String>();
expected.add(bar);
verifyResults(Arrays.asList(new Object[]{expected}));
}
@Test
public void testGeoPosBytes(){
doReturn(geoCoordinates).when(nativeConnection).geoPos(fooBytes, barBytes);
actual.add(connection.geoPos(fooBytes, barBytes));
verifyResults(Arrays.asList(new Object[] { geoCoordinates }));
}
@Test
public void testGeoPos(){
doReturn(geoCoordinates).when(nativeConnection).geoPos(fooBytes, barBytes);
actual.add(connection.geoPos(foo, bar));
verifyResults(Arrays.asList(new Object[] { geoCoordinates }));
}
@Test
public void testGeoRadiusWithoutParamBytes(){
doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet);
actual.add(connection.georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusWithoutParam(){
doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet);
actual.add(connection.georadius(foo, 13.361389, 38.115556, 10, GeoUnit.Feet));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusWithDistBytes(){
GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam();
geoRadiusParam.withDist();
doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam);
actual.add(connection.georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusWithDist(){
GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam();
geoRadiusParam.withDist();
doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam);
actual.add(connection.georadius(foo, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusWithCoordAndDescBytes(){
GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam();
geoRadiusParam.withCoord().sortDescending();
doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam);
actual.add(connection.georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusWithCoordAndDesc(){
GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam();
geoRadiusParam.withCoord().sortDescending();
doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam);
actual.add(connection.georadius(foo, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusByMemberWithoutParamBytes(){
doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet);
actual.add(connection.georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusByMemberWithoutParam(){
doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet);
actual.add(connection.georadiusByMember(foo, bar, 38.115556, GeoUnit.Feet));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusByMemberWithDistAndAscBytes(){
GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam();
geoRadiusParam.withDist().sortAscending();
doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam);
actual.add(connection.georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusByMemberWithDistAndAsc(){
GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam();
geoRadiusParam.withDist().sortAscending();
doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam);
actual.add(connection.georadiusByMember(foo, bar, 38.115556, GeoUnit.Feet, geoRadiusParam));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusByMemberWithCoordAndCountBytes(){
GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam();
geoRadiusParam.withDist().count(23);
doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam);
actual.add(connection.georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testGeoRadiusByMemberWithCoordAndCount(){
GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam();
geoRadiusParam.withDist().count(23);
doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam);
actual.add(connection.georadiusByMember(foo, bar, 38.115556, GeoUnit.Feet, geoRadiusParam));
verifyResults(Arrays.asList(new Object[] { geoRadiusResponses }));
}
@Test
public void testPExpireBytes() {
doReturn(true).when(nativeConnection).pExpire(fooBytes, 34l);
actual.add(connection.pExpire(fooBytes, 34l));
@@ -1960,6 +1784,342 @@ public class DefaultStringRedisConnectionTests {
verify(nativeConnection, times(1)).getClientName();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddBytes() {
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes);
actual.add(connection.geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes));
verifyResults(Collections.singletonList(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAdd() {
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes);
actual.add(connection.geoAdd(foo, new Point(1.23232, 34.2342434), bar));
verifyResults(Collections.singletonList(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddWithGeoLocationBytes() {
doReturn(1l).when(nativeConnection).geoAdd(fooBytes,
new GeoLocation<byte[]>(barBytes, new Point(1.23232, 34.2342434)));
actual.add(connection.geoAdd(fooBytes, new GeoLocation<byte[]>(barBytes, new Point(1.23232, 34.2342434))));
verifyResults(Collections.singletonList(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddWithGeoLocation() {
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))));
verifyResults(Collections.singletonList(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddCoordinateMapBytes() {
Map<byte[], Point> memberGeoCoordinateMap = Collections.singletonMap(barBytes, new Point(1.23232, 34.2342434));
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, memberGeoCoordinateMap);
actual.add(connection.geoAdd(fooBytes, memberGeoCoordinateMap));
verifyResults(Collections.singletonList(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddCoordinateMap() {
doReturn(1l).when(nativeConnection).geoAdd(any(byte[].class), anyMapOf(byte[].class, Point.class));
actual.add(connection.geoAdd(foo, Collections.singletonMap(bar, new Point(1.23232, 34.2342434))));
verifyResults(Collections.singletonList(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddWithIterableOfGeoLocationBytes() {
List<GeoLocation<byte[]>> values = Collections.singletonList(new GeoLocation<byte[]>(barBytes, new Point(1, 2)));
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, values);
actual.add(connection.geoAdd(fooBytes, values));
verifyResults(Collections.singletonList(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddWithIterableOfGeoLocation() {
doReturn(1l).when(nativeConnection).geoAdd(eq(fooBytes), anyMapOf(byte[].class, Point.class));
actual.add(connection.geoAdd(foo, Collections.singletonList(new GeoLocation<String>(bar, new Point(1, 2)))));
verifyResults(Collections.singletonList(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoDistBytes() {
doReturn(new Distance(102121.12d, DistanceUnit.METERS)).when(nativeConnection).geoDist(fooBytes, barBytes,
bar2Bytes, DistanceUnit.METERS);
actual.add(connection.geoDist(fooBytes, barBytes, bar2Bytes, DistanceUnit.METERS));
verifyResults(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS)));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoDist() {
doReturn(new Distance(102121.12d, DistanceUnit.METERS)).when(nativeConnection).geoDist(fooBytes, barBytes,
bar2Bytes, DistanceUnit.METERS);
actual.add(connection.geoDist(foo, bar, bar2, DistanceUnit.METERS));
verifyResults(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS)));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoHashBytes() {
doReturn(stringList).when(nativeConnection).geoHash(fooBytes, barBytes);
actual.add(connection.geoHash(fooBytes, barBytes));
verifyResults(Arrays.asList(Collections.singletonList(bar)));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoHash() {
doReturn(stringList).when(nativeConnection).geoHash(fooBytes, barBytes);
actual.add(connection.geoHash(foo, bar));
verifyResults(Arrays.asList(Collections.singletonList(bar)));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoPosBytes() {
doReturn(points).when(nativeConnection).geoPos(fooBytes, barBytes);
actual.add(connection.geoPos(fooBytes, barBytes));
verifyResults(Arrays.asList(points));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoPos() {
doReturn(points).when(nativeConnection).geoPos(fooBytes, barBytes);
actual.add(connection.geoPos(foo, bar));
verifyResults(Arrays.asList(points));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithoutParamBytes() {
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class));
actual.add(connection.geoRadius(fooBytes, null));
verifyResults(Arrays.asList(geoResults));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithoutParam() {
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class));
actual.add(
connection.georadius(foo, new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET))));
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithDistBytes() {
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance();
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class), eq(geoRadiusParam));
actual.add(connection.geoRadius(fooBytes,
new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam));
verifyResults(Arrays.asList(geoResults));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithDist() {
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance();
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class), eq(geoRadiusParam));
actual.add(connection.georadius(foo,
new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam));
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithCoordAndDescBytes() {
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeCoordinates().sortDescending();
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class), eq(geoRadiusParam));
actual.add(connection.geoRadius(fooBytes,
new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam));
verifyResults(Arrays.asList(geoResults));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithCoordAndDesc() {
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeCoordinates().sortDescending();
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class), eq(geoRadiusParam));
actual.add(connection.georadius(foo,
new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam));
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithoutParamBytes() {
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
new Distance(38.115556, DistanceUnit.FEET));
actual.add(connection.geoRadiusByMember(fooBytes, barBytes, new Distance(38.115556, DistanceUnit.FEET)));
verifyResults(Arrays.asList(geoResults));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithoutParam() {
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
new Distance(38.115556, DistanceUnit.FEET));
actual.add(connection.georadiusByMember(foo, bar, new Distance(38.115556, DistanceUnit.FEET)));
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithDistAndAscBytes() {
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().sortAscending();
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam);
actual.add(
connection.geoRadiusByMember(fooBytes, barBytes, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam));
verifyResults(Arrays.asList(geoResults));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithDistAndAsc() {
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().sortAscending();
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam);
actual.add(connection.georadiusByMember(foo, bar, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam));
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithCoordAndCountBytes() {
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().limit(23);
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam);
actual.add(
connection.geoRadiusByMember(fooBytes, barBytes, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam));
verifyResults(Arrays.asList(geoResults));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithCoordAndCount() {
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().limit(23);
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam);
actual.add(connection.georadiusByMember(foo, bar, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam));
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
}
protected List<Object> getResults() {
return actual;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.
@@ -17,18 +17,20 @@ package org.springframework.data.redis.connection;
import static org.mockito.Mockito.*;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.core.GeoCoordinate;
import org.springframework.data.redis.core.GeoRadiusParam;
import org.springframework.data.redis.core.GeoRadiusResponse;
import org.springframework.data.redis.core.GeoUnit;
import org.springframework.data.geo.Distance;
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
/**
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Ninad Divadkar
*/
public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConnectionTests {
@@ -1293,142 +1295,6 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
super.testZUnionStore();
}
@Test
public void testGeoAddBytes(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
super.testGeoAddBytes();
}
@Test
public void testGeoAdd(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
super.testGeoAddBytes();
}
@Test
public void testGeoAddCoordinateMapBytes(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
super.testGeoAddCoordinateMapBytes();
}
@Test
public void testGeoAddCoordinateMap(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
super.testGeoAddCoordinateMap();
}
@Test
public void testGeoDistBytes(){
doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).exec();
super.testGeoDistBytes();
}
@Test
public void testGeoDist(){
doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).exec();
super.testGeoDist();
}
@Test
public void testGeoHashBytes(){
List<byte[]> expected = new ArrayList<byte[]>();
expected.add(barBytes);
doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).exec();
super.testGeoHashBytes();
}
@Test
public void testGeoHash(){
List<byte[]> expected = new ArrayList<byte[]>();
expected.add(barBytes);
doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).exec();
super.testGeoHash();
}
@Test
public void testGeoPosBytes(){
doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).exec();
super.testGeoPosBytes();
}
@Test
public void testGeoPos(){
doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).exec();
super.testGeoPos();
}
@Test
public void testGeoRadiusWithoutParamBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusWithoutParamBytes();
}
@Test
public void testGeoRadiusWithoutParam(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusWithoutParam();
}
@Test
public void testGeoRadiusWithDistBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusWithDistBytes();
}
@Test
public void testGeoRadiusWithDist(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusWithDist();
}
@Test
public void testGeoRadiusWithCoordAndDescBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusWithCoordAndDescBytes();
}
@Test
public void testGeoRadiusWithCoordAndDesc(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusWithCoordAndDesc();
}
@Test
public void testGeoRadiusByMemberWithoutParamBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithoutParamBytes();
}
@Test
public void testGeoRadiusByMemberWithoutParam(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithoutParam();
}
@Test
public void testGeoRadiusByMemberWithDistAndAscBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithDistAndAscBytes();
}
@Test
public void testGeoRadiusByMemberWithDistAndAsc(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithDistAndAsc();
}
@Test
public void testGeoRadiusByMemberWithCoordAndCountBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithCoordAndCountBytes();
}
@Test
public void testGeoRadiusByMemberWithCoordAndCount(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithCoordAndCount();
}
@Test
public void testPExpireBytes() {
doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec();
@@ -1580,6 +1446,260 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
super.testTimeIsDelegatedCorrectlyToNativeConnection();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddBytes() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
super.testGeoAddBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAdd() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
super.testGeoAddBytes();
}
/**
* @see DATAREDIS-438
*/
@Override
public void testGeoAddWithGeoLocationBytes() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
super.testGeoAddWithGeoLocationBytes();
}
/**
* @see DATAREDIS-438
*/
@Override
public void testGeoAddWithGeoLocation() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
super.testGeoAddWithGeoLocation();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddCoordinateMapBytes() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
super.testGeoAddCoordinateMapBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddCoordinateMap() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
super.testGeoAddCoordinateMap();
}
/**
* @see DATAREDIS-438
*/
@Override
public void testGeoAddWithIterableOfGeoLocationBytes() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
super.testGeoAddWithIterableOfGeoLocationBytes();
}
/**
* @see DATAREDIS-438
*/
@Override
public void testGeoAddWithIterableOfGeoLocation() {
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
super.testGeoAddWithIterableOfGeoLocation();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoDistBytes() {
doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).exec();
super.testGeoDistBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoDist() {
doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).exec();
super.testGeoDist();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoHashBytes() {
doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).exec();
super.testGeoHashBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoHash() {
doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).exec();
super.testGeoHash();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoPosBytes() {
doReturn(Arrays.asList(points)).when(nativeConnection).exec();
super.testGeoPosBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoPos() {
doReturn(Arrays.asList(points)).when(nativeConnection).exec();
super.testGeoPos();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithoutParamBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusWithoutParamBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithoutParam() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusWithoutParam();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithDistBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusWithDistBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithDist() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusWithDist();
}
@Test
public void testGeoRadiusWithCoordAndDescBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusWithCoordAndDescBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusWithCoordAndDesc() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusWithCoordAndDesc();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithoutParamBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithoutParamBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithoutParam() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithoutParam();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithDistAndAscBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithDistAndAscBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithDistAndAsc() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithDistAndAsc();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithCoordAndCountBytes() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithCoordAndCountBytes();
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRadiusByMemberWithCoordAndCount() {
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
super.testGeoRadiusByMemberWithCoordAndCount();
}
protected List<Object> getResults() {
return connection.exec();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-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.
@@ -27,8 +27,14 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Metric;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.ObjectUtils;
@@ -37,6 +43,7 @@ import org.springframework.util.ObjectUtils;
* @author Christoph Strobl
* @author Thomas Darimont
* @author David Liu
* @author Ninad Divadkar
*/
public class RedisConnectionUnitTests {
@@ -259,53 +266,69 @@ public class RedisConnectionUnitTests {
delegate.subscribe(listener, channels);
}
public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) {
return delegate.geoAdd(key, longitude, latitude, member);
}
@Override
public Long geoAdd(byte[] key, Map<byte[], GeoCoordinate> memberCoordinateMap) {
return delegate.geoAdd(key, memberCoordinateMap);
}
@Override
public Double geoDist(byte[] key, byte[] member1, byte[] member2) {
return delegate.geoDist(key, member1, member2);
}
@Override
public Double geoDist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) {
return delegate.geoDist(key, member1, member2, unit);
}
@Override
public List<byte[]> geoHash(byte[] key, byte[]... members) {
return delegate.geoHash(key, members);
}
@Override
public List<GeoCoordinate> geoPos(byte[] key, byte[]... members) {
return delegate.geoPos(key, members);
}
@Override
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) {
return delegate.georadius(key, longitude, latitude, radius, unit);
public Long geoAdd(byte[] key, Point point, byte[] member) {
return delegate.geoAdd(key, point, member);
}
@Override
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) {
return delegate.georadius(key, longitude, latitude, radius, unit, param);
public Long geoAdd(byte[] key, GeoLocation<byte[]> location) {
return delegate.geoAdd(key, location);
}
@Override
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) {
return delegate.georadiusByMember(key, member, radius, unit);
public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) {
return delegate.geoAdd(key, memberCoordinateMap);
}
@Override
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) {
return delegate.georadiusByMember(key, member, radius, unit, param);
public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) {
return delegate.geoAdd(key, locations);
}
@Override
public Distance geoDist(byte[] key, byte[] member1, byte[] member2) {
return delegate.geoDist(key, member1, member2);
}
@Override
public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric unit) {
return delegate.geoDist(key, member1, member2, unit);
}
@Override
public List<String> geoHash(byte[] key, byte[]... members) {
return delegate.geoHash(key, members);
}
@Override
public List<Point> geoPos(byte[] key, byte[]... members) {
return delegate.geoPos(key, members);
}
@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
return delegate.geoRadius(key, null);
}
@Override
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs param) {
return delegate.geoRadius(key, null, param);
}
@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, double radius) {
return delegate.geoRadiusByMember(key, member, radius);
}
@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
return delegate.geoRadiusByMember(key, member, radius);
}
@Override
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
GeoRadiusCommandArgs param) {
return delegate.geoRadiusByMember(key, member, radius, param);
}
@Override

View File

@@ -16,13 +16,18 @@
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
import static org.springframework.data.redis.core.ScanOptions.*;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -38,14 +43,20 @@ import java.util.Set;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.ClusterConnectionTests;
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.DefaultSortParameters;
import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
@@ -55,7 +66,9 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.data.redis.test.util.RedisClusterRule;
import org.springframework.test.annotation.IfProfileValue;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
@@ -82,6 +95,13 @@ 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")),
POINT_ARIGENTO);
static final GeoLocation<byte[]> CATANIA = new GeoLocation<byte[]>("catania".getBytes(Charset.forName("UTF-8")),
POINT_CATANIA);
static final GeoLocation<byte[]> PALERMO = new GeoLocation<byte[]>("palermo".getBytes(Charset.forName("UTF-8")),
POINT_PALERMO);
JedisCluster nativeConnection;
JedisClusterConnection clusterConnection;
@@ -90,6 +110,11 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
*/
public static @ClassRule RedisClusterRule clusterRule = new RedisClusterRule();
/**
* Check for specific Redis Versions
*/
public @Rule MinimumRedisVersionRule version = new MinimumRedisVersionRule();
@Before
public void setUp() throws IOException {
@@ -2454,4 +2479,245 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
assertThat(nativeConnection.exists(KEY_1_BYTES), is(false));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoAddSingleGeoLocation() {
assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO), is(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoAddMultipleGeoLocations() {
assertThat(clusterConnection.geoAdd(KEY_1_BYTES, Arrays.asList(PALERMO, ARIGENTO, CATANIA, PALERMO)), is(3L));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoDist() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
Distance distance = clusterConnection.geoDist(KEY_1_BYTES, PALERMO.getName(), CATANIA.getName());
assertThat(distance.getValue(), is(closeTo(166274.15156960033D, 0.005)));
assertThat(distance.getUnit(), is("m"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoDistWithMetric() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
Distance distance = clusterConnection.geoDist(KEY_1_BYTES, PALERMO.getName(), CATANIA.getName(), KILOMETERS);
assertThat(distance.getValue(), is(closeTo(166.27415156960033D, 0.005)));
assertThat(distance.getUnit(), is("km"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoHash() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
List<String> result = clusterConnection.geoHash(KEY_1_BYTES, PALERMO.getName(), CATANIA.getName());
assertThat(result, contains("sqc8b49rny0", "sqdtr74hyu0"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoHashNonExisting() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
List<String> result = clusterConnection.geoHash(KEY_1_BYTES, PALERMO.getName(), ARIGENTO.getName(),
CATANIA.getName());
assertThat(result, contains("sqc8b49rny0", (String) null, "sqdtr74hyu0"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoPosition() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
List<Point> positions = clusterConnection.geoPos(KEY_1_BYTES, PALERMO.getName(), CATANIA.getName());
assertThat(positions.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(positions.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(positions.get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(positions.get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoPositionNonExisting() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
List<Point> positions = clusterConnection.geoPos(KEY_1_BYTES, PALERMO.getName(), ARIGENTO.getName(),
CATANIA.getName());
assertThat(positions.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(positions.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(positions.get(1), is(nullValue()));
assertThat(positions.get(2).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(positions.get(2).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldReturnMembersCorrectly() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS)));
assertThat(result.getContent(), hasSize(2));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldReturnDistanceCorrectly() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().includeDistance());
assertThat(result.getContent(), hasSize(3));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(130.423D, 0.005)));
assertThat(result.getContent().get(0).getDistance().getUnit(), is("km"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldApplyLimit() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2));
assertThat(result.getContent(), hasSize(2));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(),
new Distance(100, KILOMETERS), newGeoRadiusArgs().sortAscending());
assertThat(result.getContent().get(0).getContent().getName(), is(PALERMO.getName()));
assertThat(result.getContent().get(1).getContent().getName(), is(ARIGENTO.getName()));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(),
new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.978D, 0.005)));
assertThat(result.getContent().get(0).getDistance().getUnit(), is("km"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldApplyLimit() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(),
new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2));
assertThat(result.getContent(), hasSize(2));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRemoveDeletesMembers() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
assertThat(clusterConnection.geoRemove(KEY_1_BYTES, ARIGENTO.getName()), is(1L));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-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.
@@ -16,13 +16,14 @@
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;
import java.util.Collection;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@@ -32,6 +33,7 @@ import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisSentinelConnection;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.data.redis.test.util.RedisSentinelRule;
import org.springframework.test.annotation.IfProfileValue;
@@ -40,20 +42,19 @@ import org.springframework.test.annotation.IfProfileValue;
* @author Thomas Darimont
*/
public class JedisSentinelIntegrationTests extends AbstractConnectionIntegrationTests {
private static final String MASTER_NAME = "mymaster";
private static final RedisServer SENTINEL_0 = new RedisServer("127.0.0.1", 26379);
private static final RedisServer SENTINEL_1 = new RedisServer("127.0.0.1", 26380);
private static final RedisServer SLAVE_0 = new RedisServer("127.0.0.1", 6380);
private static final RedisServer SLAVE_1 = new RedisServer("127.0.0.1", 6381);
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
.master(MASTER_NAME)
.sentinel(SENTINEL_0)
.sentinel(SENTINEL_1);
public @Rule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
.master(MASTER_NAME).sentinel(SENTINEL_0).sentinel(SENTINEL_1);
public static @ClassRule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
public @Rule MinimumRedisVersionRule minimumVersionRule = new MinimumRedisVersionRule();
@Before
public void setUp() {
@@ -129,9 +130,9 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
List<RedisServer> servers = (List<RedisServer>) connectionFactory.getSentinelConnection().masters();
assertThat(servers.size(), is(1));
assertThat(servers.get(0).getName(),is(MASTER_NAME));
assertThat(servers.get(0).getName(), is(MASTER_NAME));
}
/**
* @see DATAREDIS-330
*/
@@ -139,10 +140,10 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
public void shouldReadSlavesOfMastersCorrectly() {
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
List<RedisServer> servers = (List<RedisServer>) sentinelConnection.masters();
assertThat(servers.size(), is(1));
Collection<RedisServer> slaves = sentinelConnection.slaves(servers.get(0));
assertThat(slaves.size(), is(2));
assertThat(slaves, hasItems(SLAVE_0, SLAVE_1));

View File

@@ -16,12 +16,18 @@
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
import static org.springframework.data.redis.core.ScanOptions.*;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -36,14 +42,21 @@ import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.ClusterConnectionTests;
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.DefaultSortParameters;
import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
@@ -54,7 +67,9 @@ import org.springframework.data.redis.connection.jedis.JedisConverters;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.data.redis.test.util.RedisClusterRule;
import org.springframework.test.annotation.IfProfileValue;
import com.lambdaworks.redis.RedisURI.Builder;
import com.lambdaworks.redis.cluster.RedisAdvancedClusterConnection;
@@ -78,12 +93,28 @@ 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<byte[]> ARIGENTO_BYTES = new GeoLocation<byte[]>(
"arigento".getBytes(Charset.forName("UTF-8")), POINT_ARIGENTO);
static final GeoLocation<byte[]> CATANIA_BYTES = new GeoLocation<byte[]>("catania".getBytes(Charset.forName("UTF-8")),
POINT_CATANIA);
static final GeoLocation<byte[]> PALERMO_BYTES = new GeoLocation<byte[]>("palermo".getBytes(Charset.forName("UTF-8")),
POINT_PALERMO);
RedisClusterClient client;
RedisAdvancedClusterConnection<String, String> nativeConnection;
LettuceClusterConnection clusterConnection;
public static @ClassRule RedisClusterRule clusterAvailable = new RedisClusterRule();
/**
* Check for specific Redis Versions
*/
public @Rule MinimumRedisVersionRule version = new MinimumRedisVersionRule();
@Before
public void setUp() {
@@ -2441,4 +2472,249 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
assertThat(nativeConnection.exists(KEY_1), is(false));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoAddSingleGeoLocation() {
assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO_BYTES), is(1L));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoAddMultipleGeoLocations() {
assertThat(clusterConnection.geoAdd(KEY_1_BYTES,
Arrays.asList(PALERMO_BYTES, ARIGENTO_BYTES, CATANIA_BYTES, PALERMO_BYTES)), is(3L));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoDist() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
Distance distance = clusterConnection.geoDist(KEY_1_BYTES, PALERMO_BYTES.getName(), CATANIA_BYTES.getName());
assertThat(distance.getValue(), is(closeTo(166274.15156960033D, 0.005)));
assertThat(distance.getUnit(), is("m"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoDistWithMetric() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
Distance distance = clusterConnection.geoDist(KEY_1_BYTES, PALERMO_BYTES.getName(), CATANIA_BYTES.getName(),
KILOMETERS);
assertThat(distance.getValue(), is(closeTo(166.27415156960033D, 0.005)));
assertThat(distance.getUnit(), is("km"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@Ignore("see mp911de/lettuce#241")
public void geoHash() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
List<String> result = clusterConnection.geoHash(KEY_1_BYTES, PALERMO_BYTES.getName(), CATANIA_BYTES.getName());
assertThat(result, contains("sqc8b49rny0", "sqdtr74hyu0"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
@Ignore("see mp911de/lettuce#241")
public void geoHashNonExisting() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
List<String> result = clusterConnection.geoHash(KEY_1_BYTES, PALERMO_BYTES.getName(), ARIGENTO_BYTES.getName(),
CATANIA_BYTES.getName());
assertThat(result, contains("sqc8b49rny0", (String) null, "sqdtr74hyu0"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoPosition() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
List<Point> positions = clusterConnection.geoPos(KEY_1_BYTES, PALERMO_BYTES.getName(), CATANIA_BYTES.getName());
assertThat(positions.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(positions.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(positions.get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(positions.get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoPositionNonExisting() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
List<Point> positions = clusterConnection.geoPos(KEY_1_BYTES, PALERMO_BYTES.getName(), ARIGENTO_BYTES.getName(),
CATANIA_BYTES.getName());
assertThat(positions.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(positions.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(positions.get(1), is(nullValue()));
assertThat(positions.get(2).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(positions.get(2).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldReturnMembersCorrectly() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS)));
assertThat(result.getContent(), hasSize(2));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldReturnDistanceCorrectly() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().includeDistance());
assertThat(result.getContent(), hasSize(3));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(130.423D, 0.005)));
assertThat(result.getContent().get(0).getDistance().getUnit(), is("km"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldApplyLimit() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2));
assertThat(result.getContent(), hasSize(2));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(),
new Distance(100, KILOMETERS), newGeoRadiusArgs().sortAscending());
assertThat(result.getContent().get(0).getContent().getName(), is(PALERMO_BYTES.getName()));
assertThat(result.getContent().get(1).getContent().getName(), is(ARIGENTO_BYTES.getName()));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(),
new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.978D, 0.005)));
assertThat(result.getContent().get(0).getDistance().getUnit(), is("km"));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldApplyLimit() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(),
new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2));
assertThat(result.getContent(), hasSize(2));
}
/**
* @see DATAREDIS-438
*/
@Test
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRemoveDeletesMembers() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
assertThat(clusterConnection.geoRemove(KEY_1_BYTES, ARIGENTO_BYTES.getName()), is(1L));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.

View File

@@ -19,6 +19,7 @@ import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
@@ -67,4 +68,83 @@ public class LettuceConnectionTransactionIntegrationTests extends AbstractConnec
super.testSelect();
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#241")
public void geoPosition() {
super.geoPosition();
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#241")
public void geoPositionNonExisting() {
super.geoPositionNonExisting();
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#241")
public void geoRadiusByMemberShouldApplyLimit() {
super.geoRadiusByMemberShouldApplyLimit();
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#241")
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
super.geoRadiusByMemberShouldReturnDistanceCorrectly();
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#241")
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
super.geoRadiusByMemberShouldReturnMembersCorrectly();
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#241")
public void geoRadiusShouldApplyLimit() {
super.geoRadiusShouldApplyLimit();
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#")
public void geoRadiusShouldReturnDistanceCorrectly() {
super.geoRadiusShouldReturnDistanceCorrectly();
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#241")
public void geoRadiusShouldReturnMembersCorrectly() {
super.geoRadiusShouldReturnMembersCorrectly();
}
}

View File

@@ -25,6 +25,8 @@ import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.data.redis.ConnectionFactoryTracker;
@@ -34,6 +36,7 @@ import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisSentinelConnection;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.data.redis.test.util.RedisSentinelRule;
/**
@@ -52,7 +55,8 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
.master(MASTER_NAME).sentinel(SENTINEL_0).sentinel(SENTINEL_1);
public @Rule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
public static @ClassRule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
public @Rule MinimumRedisVersionRule minimumVersionRule = new MinimumRedisVersionRule();
@Before
public void setUp() {
@@ -121,4 +125,23 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
}
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#241")
public void geoHash() {
super.geoHash();
}
/**
* @see DATAREDIS-438
*/
@Test
@Override
@Ignore("see mp911de/lettuce#241")
public void geoHashNonExisting() {
super.geoHashNonExisting();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 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.
@@ -15,51 +15,76 @@
*/
package org.springframework.data.redis.core;
import static org.hamcrest.collection.IsCollectionWithSize.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
import static org.hamcrest.core.IsNull.*;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.Assert;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Point;
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;
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
import static org.springframework.data.redis.SpinBarrier.waitFor;
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
/**
* Integration test of {@link org.springframework.data.redis.core.DefaultGeoOperations}
*
* @author Ninad Divadkar
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
@IfProfileValue(name = "redisVersion", value = "3.2.0+")
public class DefaultGeoOperationsTests<K, M> {
public static @ClassRule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule();
private static final Point POINT_ARIGENTO = new Point(13.583333, 37.316667);
private static final Point POINT_CATANIA = new Point(15.087269, 37.502669);
private static final Point POINT_PALERMO = new Point(13.361389, 38.115556);
private static final double DISTANCE_PALERMO_CATANIA_METERS = 166274.15156960033;
private static final double DISTANCE_PALERMO_CATANIA_KILOMETERS = 166.27415156960033;
private static final double DISTANCE_PALERMO_CATANIA_MILES = 103.31822459492733;
private static final double DISTANCE_PALERMO_CATANIA_FEET = 545518.8699790037;
private RedisTemplate<K, M> redisTemplate;
private ObjectFactory<K> keyFactory;
private ObjectFactory<M> valueFactory;
private GeoOperations<K, M> geoOperations;
public DefaultGeoOperationsTests(RedisTemplate<K, M> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<M> valueFactory) {
ObjectFactory<M> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
}
@Parameters
@@ -67,6 +92,11 @@ public class DefaultGeoOperationsTests<K, M> {
return AbstractOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@Before
public void setUp() {
geoOperations = redisTemplate.opsForGeo();
@@ -74,6 +104,7 @@ public class DefaultGeoOperationsTests<K, M> {
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
@@ -82,174 +113,370 @@ public class DefaultGeoOperationsTests<K, M> {
});
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAdd() throws Exception {
K key = keyFactory.instance();
M v1 = valueFactory.instance();
Long numAdded = geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
assertEquals(numAdded.longValue(), 1L);
public void testGeoAdd() {
Long numAdded = geoOperations.geoAdd(keyFactory.instance(), POINT_PALERMO, valueFactory.instance());
assertThat(numAdded, is(1L));
}
@Test
public void testGeoAdd2() throws Exception {
K key = keyFactory.instance();
Map<M, GeoCoordinate> memberCoordinateMap = new HashMap<M, GeoCoordinate>();
memberCoordinateMap.put(valueFactory.instance(), new GeoCoordinate(2.2323, 43.324));
memberCoordinateMap.put(valueFactory.instance(), new GeoCoordinate(12.993, 31.3994));
Long numAdded = geoOperations.geoAdd(key, memberCoordinateMap);
assertEquals(numAdded.longValue(), 2L);
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoAddWithLocationMap() {
@Test
public void testGeoDist() throws Exception {
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
Map<M, Point> memberCoordinateMap = new HashMap<M, Point>();
memberCoordinateMap.put(valueFactory.instance(), POINT_PALERMO);
memberCoordinateMap.put(valueFactory.instance(), POINT_CATANIA);
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
Long numAdded = geoOperations.geoAdd(keyFactory.instance(), memberCoordinateMap);
Double dist = geoOperations.geoDist(key, v1, v2);
assertEquals(dist.doubleValue(), 166274.15156960033, 0.00001); // gives in meters
assertThat(numAdded, is(2L));
}
dist = geoOperations.geoDist(key, v1, v2, GeoUnit.KiloMeters);
assertEquals(dist.doubleValue(), 166.27415156960033, 0.00001);
/**
* @see DATAREDIS-438
*/
@Test
public void geoDistShouldReturnDistanceInMetersByDefault() {
dist = geoOperations.geoDist(key, v1, v2, GeoUnit.Miles);
assertEquals(dist.doubleValue(), 103.31822459492733, 0.00001);
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
dist = geoOperations.geoDist(key, v1, v2, GeoUnit.Feet);
assertEquals(dist.doubleValue(), 545518.8699790037, 0.00001);
}
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
@Test
public void testGeoHash() throws Exception {
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
Distance dist = geoOperations.geoDist(key, member1, member2);
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_METERS, 0.005));
assertThat(dist.getUnit(), is(equalTo("m")));
}
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
/**
* @see DATAREDIS-438
*/
@Test
public void geoDistShouldReturnDistanceInKilometersCorrectly() {
List<byte[]> result = geoOperations.geoHash(key, v1, v2);
assertEquals(result.size(), 2);
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
final RedisSerializer<String> serializer = new StringRedisSerializer();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
assertEquals(serializer.deserialize(result.get(0)), "sqc8b49rny0");
assertEquals(serializer.deserialize(result.get(1)), "sqdtr74hyu0");
}
Distance dist = geoOperations.geoDist(key, member1, member2, KILOMETERS);
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_KILOMETERS, 0.005));
assertThat(dist.getUnit(), is(equalTo("km")));
}
@Test
public void testGeoPos() throws Exception {
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
M v3 = valueFactory.instance();
/**
* @see DATAREDIS-438
*/
@Test
public void geoDistShouldReturnDistanceInMilesCorrectly() {
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
List<GeoCoordinate> result = geoOperations.geoPos(key, v1, v2, v3);// v3 is nonexisting
assertEquals(result.size(), 3);
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
assertEquals(result.get(0).getLongitude(), 13.361389338970184, 0.000001);
assertEquals(result.get(0).getLatitude(), 38.115556395496299, 0.000001);
Distance dist = geoOperations.geoDist(key, member1, member2, DistanceUnit.MILES);
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_MILES, 0.005));
assertThat(dist.getUnit(), is(equalTo("mi")));
}
assertEquals(result.get(1).getLongitude(), 15.087267458438873, 0.000001);
assertEquals(result.get(1).getLatitude(), 37.50266842333162, 0.000001);
/**
* @see DATAREDIS-438
*/
@Test
public void geoDistShouldReturnDistanceInFeeCorrectly() {
assertNull(result.get(2));
}
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
@Test
public void testGeoRadius() throws Exception{
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
Distance dist = geoOperations.geoDist(key, member1, member2, DistanceUnit.FEET);
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_FEET, 0.005));
assertThat(dist.getUnit(), is(equalTo("ft")));
}
List<GeoRadiusResponse> result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters);
Assert.assertEquals(2, result.size());
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoHash() {
// with dist, descending
result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withDist().sortDescending());
Assert.assertEquals(2, result.size());
Assert.assertEquals(result.get(0).getDistance(), 190.4424d, 0.0001);
Assert.assertEquals(result.get(1).getDistance(), 56.4413d, 0.0001);
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
// with coord, ascending
result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().sortAscending());
Assert.assertEquals(2, result.size());
Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.361389338970184d, 0.0001);
Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 38.115556395496299d, 0.0001);
Assert.assertEquals(result.get(0).getCoordinate().getLongitude(), 15.087267458438873d, 0.0001);
Assert.assertEquals(result.get(0).getCoordinate().getLatitude(), 37.50266842333162d, 0.0001);
geoOperations.geoAdd(key, POINT_PALERMO, v1);
geoOperations.geoAdd(key, POINT_CATANIA, v2);
// with coord and dist, ascending
result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().withDist().sortAscending());
Assert.assertEquals(2, result.size());
List<String> result = geoOperations.geoHash(key, v1, v2);
assertThat(result, hasSize(2));
Assert.assertEquals(result.get(0).getDistance(), 56.4413d, 0.0001);
Assert.assertEquals(result.get(0).getCoordinate().getLongitude(), 15.087267458438873d, 0.0001);
Assert.assertEquals(result.get(0).getCoordinate().getLatitude(), 37.50266842333162d, 0.0001);
Assert.assertEquals(result.get(1).getDistance(), 190.4424d, 0.0001);
Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.361389338970184d, 0.0001);
Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 38.115556395496299d, 0.0001);
}
final RedisSerializer<String> serializer = new StringRedisSerializer();
@Test
public void testGeoRadiusByMember() throws Exception{
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
M v3 = valueFactory.instance();
assertThat(result.get(0), is(equalTo("sqc8b49rny0")));
assertThat(result.get(1), is(equalTo("sqdtr74hyu0")));
}
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);//palermo
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);//catania
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoPos() {
geoOperations.geoAdd(key, 13.583333, 37.316667, v3);//Agrigento
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
M v3 = valueFactory.instance();
List<GeoRadiusResponse> result = geoOperations.georadiusByMember(key, v3, 200, GeoUnit.KiloMeters);
Assert.assertEquals(3, result.size());
geoOperations.geoAdd(key, POINT_PALERMO, v1);
geoOperations.geoAdd(key, POINT_CATANIA, v2);
// with dist, descending
result = geoOperations.georadiusByMember(key, v3, 100, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withDist().sortDescending());
Assert.assertEquals(2, result.size());
Assert.assertEquals(result.get(0).getDistance(), 90.9778d, 0.0001);
Assert.assertEquals(result.get(1).getDistance(), 0.0d, 0.0001); //itself
List<Point> result = geoOperations.geoPos(key, v1, v2, v3);// v3 is nonexisting
assertThat(result, hasSize(3));
// with coord, ascending
result = geoOperations.georadiusByMember(key, v3, 100, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().sortAscending());
Assert.assertEquals(2, result.size());
Assert.assertEquals(result.get(0).getCoordinate().getLongitude(), 13.583331406116486d, 0.0001);
Assert.assertEquals(result.get(0).getCoordinate().getLatitude(), 37.316668049938166d, 0.0001);
Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.361389338970184d, 0.0001);
Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 38.115556395496299d, 0.0001);
assertThat(result.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(result.get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
// with coord and dist, ascending
result = geoOperations.georadiusByMember(key, v1, 100, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().withDist().sortAscending());
Assert.assertEquals(2, result.size());
assertThat(result.get(2), is(nullValue()));
}
Assert.assertEquals(result.get(0).getDistance(), 0.0d, 0.0001);
Assert.assertEquals(result.get(0).getCoordinate().getLongitude(), 13.361389338970184d, 0.0001);
Assert.assertEquals(result.get(0).getCoordinate().getLatitude(), 38.1155563954963d, 0.0001);
Assert.assertEquals(result.get(1).getDistance(), 90.9778d, 0.0001);
Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.583331406116486d, 0.0001);
Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 37.316668049938166d, 0.0001);
}
/**
* @see DATAREDIS-438
*/
@Test
public void geoRadiusShouldReturnMembersCorrectly() {
@Test
public void testGeoRemove(){
K key = keyFactory.instance();
M v1 = valueFactory.instance();
Long numAdded = geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
assertEquals(numAdded.longValue(), 1L);
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
Long numRemoved = geoOperations.geoRemove(key, v1);
assertEquals(1L, numRemoved.longValue());
}
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
GeoResults<GeoLocation<M>> result = geoOperations.georadius(key,
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)));
assertThat(result.getContent(), hasSize(2));
}
/**
* @see DATAREDIS-438
*/
@Test
public void geoRadiusShouldReturnLocationsWithDistance() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
GeoResults<GeoLocation<M>> result = geoOperations.georadius(key,
new Circle(new Point(15, 37), new Distance(200, KILOMETERS)),
newGeoRadiusArgs().includeDistance().sortDescending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(190.4424d, 0.005)));
assertThat(result.getContent().get(0).getDistance().getUnit(), is(equalTo("km")));
assertThat(result.getContent().get(0).getContent().getName(), is(member1));
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(56.4413d, 0.005)));
assertThat(result.getContent().get(1).getDistance().getUnit(), is(equalTo("km")));
assertThat(result.getContent().get(1).getContent().getName(), is(member2));
}
/**
* @see DATAREDIS-438
*/
@Test
public void geoRadiusShouldReturnLocationsWithCoordinates() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
GeoResults<GeoLocation<M>> result = geoOperations.georadius(key,
new Circle(new Point(15, 37), new Distance(200, KILOMETERS)),
newGeoRadiusArgs().includeCoordinates().sortAscending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member2));
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.getContent().get(1).getContent().getName(), is(member1));
}
/**
* @see DATAREDIS-438
*/
@Test
public void geoRadiusShouldReturnLocationsWithCoordinatesAndDistance() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
GeoResults<GeoLocation<M>> result = geoOperations.georadius(key,
new Circle(new Point(15, 37), new Distance(200, KILOMETERS)),
newGeoRadiusArgs().includeCoordinates().includeDistance().sortAscending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(56.4413d, 0.005)));
assertThat(result.getContent().get(0).getDistance().getUnit(), is(equalTo("km")));
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member2));
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(190.4424d, 0.005)));
assertThat(result.getContent().get(1).getDistance().getUnit(), is(equalTo("km")));
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.getContent().get(1).getContent().getName(), is(member1));
}
/**
* @see DATAREDIS-438
*/
@Test
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
M member3 = valueFactory.instance();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
geoOperations.geoAdd(key, POINT_ARIGENTO, member3);
GeoResults<GeoLocation<M>> result = geoOperations.georadiusByMember(key, member3, new Distance(200, KILOMETERS));
assertThat(result.getContent(), hasSize(3));
}
/**
* @see DATAREDIS-438
*/
@Test
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
M member3 = valueFactory.instance();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
geoOperations.geoAdd(key, POINT_ARIGENTO, member3);
GeoResults<GeoLocation<M>> result = geoOperations.georadiusByMember(key, member3, new Distance(100, KILOMETERS),
newGeoRadiusArgs().includeDistance().sortDescending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.9778d, 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member1));
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(0.0d, 0.005))); // itself
assertThat(result.getContent().get(1).getContent().getName(), is(member3));
}
/**
* @see DATAREDIS-438
*/
@Test
public void geoRadiusByMemberShouldReturnCoordinates() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
M member3 = valueFactory.instance();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
geoOperations.geoAdd(key, POINT_ARIGENTO, member3);
GeoResults<GeoLocation<M>> result = geoOperations.georadiusByMember(key, member3,
new Distance(100, DistanceUnit.KILOMETERS), newGeoRadiusArgs().includeCoordinates().sortAscending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_ARIGENTO.getX(), 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_ARIGENTO.getY(), 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member3));
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.getContent().get(1).getContent().getName(), is(member1));
}
/**
* @see DATAREDIS-438
*/
@Test
public void geoRadiusByMemberShouldReturnCoordinatesAndDistance() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
M member2 = valueFactory.instance();
M member3 = valueFactory.instance();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
geoOperations.geoAdd(key, POINT_CATANIA, member2);
geoOperations.geoAdd(key, POINT_ARIGENTO, member3);
// with coord and dist, ascending
GeoResults<GeoLocation<M>> result = geoOperations.georadiusByMember(key, member1, new Distance(100, KILOMETERS),
newGeoRadiusArgs().includeCoordinates().includeDistance().sortAscending());
assertThat(result.getContent(), hasSize(2));
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(0.0d, 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
assertThat(result.getContent().get(0).getContent().getName(), is(member1));
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(90.9778d, 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_ARIGENTO.getX(), 0.005)));
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_ARIGENTO.getY(), 0.005)));
assertThat(result.getContent().get(1).getContent().getName(), is(member3));
}
/**
* @see DATAREDIS-438
*/
@Test
public void testGeoRemove() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
geoOperations.geoAdd(key, POINT_PALERMO, member1);
assertThat(geoOperations.geoRemove(key, member1), is(1L));
}
}

View File

@@ -24,12 +24,14 @@ import java.util.Iterator;
import java.util.Map;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RawObjectFactory;
import org.springframework.data.redis.SettingsUtils;
@@ -44,7 +46,6 @@ import org.springframework.test.annotation.IfProfileValue;
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Ninad Divadkar
* @param <K> Key type
* @param <HK> Hash key type
* @param <HV> Hash value type
@@ -66,10 +67,13 @@ public class DefaultHashOperationsTests<K, HK, HV> {
public DefaultHashOperationsTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<HK> hashKeyFactory, ObjectFactory<HV> hashValueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.hashKeyFactory = hashKeyFactory;
this.hashValueFactory = hashValueFactory;
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
}
@Parameters
@@ -95,6 +99,11 @@ public class DefaultHashOperationsTests<K, HK, HV> {
{ rawTemplate, rawFactory, rawFactory, rawFactory } });
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@Before
public void setUp() {
hashOps = redisTemplate.opsForHash();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-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.
@@ -21,12 +21,14 @@ import static org.junit.Assert.*;
import java.util.Collection;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
@@ -51,9 +53,12 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
public DefaultHyperLogLogOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
}
@Parameters
@@ -61,6 +66,11 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
return AbstractOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@Before
public void setUp() {
hyperLogLogOps = redisTemplate.opsForHyperLogLog();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.
@@ -25,11 +25,13 @@ import java.util.Collections;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.connection.RedisConnection;
@@ -56,9 +58,12 @@ public class DefaultListOperationsTests<K, V> {
public DefaultListOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
}
@Parameters
@@ -66,6 +71,11 @@ public class DefaultListOperationsTests<K, V> {
return AbstractOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@Before
public void setUp() {
listOps = redisTemplate.opsForList();

View File

@@ -29,12 +29,14 @@ import java.util.Set;
import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.connection.RedisConnection;
@@ -63,9 +65,12 @@ public class DefaultSetOperationsTests<K, V> {
public DefaultSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
}
@Parameters
@@ -73,6 +78,11 @@ public class DefaultSetOperationsTests<K, V> {
return AbstractOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@Before
public void setUp() {
setOps = redisTemplate.opsForSet();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.
@@ -15,14 +15,10 @@
*/
package org.springframework.data.redis.core;
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.junit.Assume.assumeTrue;
import static org.springframework.data.redis.SpinBarrier.waitFor;
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.redis.SpinBarrier.*;
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
import java.text.DecimalFormat;
import java.util.ArrayList;
@@ -34,11 +30,13 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.TestCondition;
@@ -65,9 +63,12 @@ public class DefaultValueOperationsTests<K, V> {
public DefaultValueOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
}
@Parameters
@@ -75,6 +76,11 @@ public class DefaultValueOperationsTests<K, V> {
return AbstractOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@Before
public void setUp() {
valueOps = redisTemplate.opsForValue();
@@ -280,19 +286,19 @@ public class DefaultValueOperationsTests<K, V> {
assumeTrue(key1 instanceof byte[]);
assertNotNull(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key1));
}
/**
* @see DATAREDIS-197
*/
@Test
public void testSetAndGetBit() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
K key1 = keyFactory.instance();
int bitOffset = 65;
valueOps.setBit(key1, bitOffset, true);
assertEquals(true, valueOps.getBit(key1, bitOffset));
}

View File

@@ -30,12 +30,14 @@ import java.util.LinkedHashSet;
import java.util.Set;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.DoubleAsStringObjectFactory;
import org.springframework.data.redis.DoubleObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
@@ -71,9 +73,12 @@ public class DefaultZSetOperationsTests<K, V> {
public DefaultZSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
}
@Parameters
@@ -81,6 +86,11 @@ public class DefaultZSetOperationsTests<K, V> {
return AbstractOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@Before
public void setUp() {
zSetOps = redisTemplate.opsForZSet();
@@ -179,10 +189,8 @@ public class DefaultZSetOperationsTests<K, V> {
@Test
public void testRangeByLexUnbounded() {
assumeThat(
valueFactory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -205,10 +213,8 @@ public class DefaultZSetOperationsTests<K, V> {
@Test
public void testRangeByLexBounded() {
assumeThat(
valueFactory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -231,10 +237,8 @@ public class DefaultZSetOperationsTests<K, V> {
@Test
public void testRangeByLexUnboundedWithLimit() {
assumeThat(
valueFactory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -258,10 +262,8 @@ public class DefaultZSetOperationsTests<K, V> {
@Test
public void testRangeByLexBoundedWithLimit() {
assumeThat(
valueFactory,
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -271,8 +273,8 @@ public class DefaultZSetOperationsTests<K, V> {
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1), RedisZSetCommands.Limit
.limit().count(1).offset(1));
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1),
RedisZSetCommands.Limit.limit().count(1).offset(1));
assertEquals(1, tuples.size());
V tuple = tuples.iterator().next();