DATAREDIS-438 - Add support for geo commands.

Original Pulll Request: #187
CLA: 169220160326121428 (Ninad Divadkar)
This commit is contained in:
Ninad Divadkar
2016-03-27 14:58:18 -07:00
committed by Christoph Strobl
parent 83359a9c4f
commit b0e20d3da8
32 changed files with 5494 additions and 2747 deletions

View File

@@ -17,10 +17,7 @@ package org.springframework.data.redis.connection;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.*;
import org.junit.Before;
import org.junit.Test;
@@ -1306,6 +1303,142 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi
super.testZUnionStore();
}
@Test
public void testGeoAddBytes(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
super.testGeoAddBytes();
}
@Test
public void testGeoAdd(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
super.testGeoAddBytes();
}
@Test
public void testGeoAddCoordinateMapBytes(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
super.testGeoAddCoordinateMapBytes();
}
@Test
public void testGeoAddCoordinateMap(){
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
super.testGeoAddCoordinateMap();
}
@Test
public void testGeoDistBytes(){
doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).closePipeline();
super.testGeoDistBytes();
}
@Test
public void testGeoDist(){
doReturn(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[] { expected })).when(nativeConnection).closePipeline();
super.testGeoHashBytes();
}
@Test
public void testGeoHash(){
List<byte[]> expected = new ArrayList<byte[]>();
expected.add(barBytes);
doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).closePipeline();
super.testGeoHash();
}
@Test
public void testGeoPosBytes(){
doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).closePipeline();
super.testGeoPosBytes();
}
@Test
public void testGeoPos(){
doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).closePipeline();
super.testGeoPos();
}
@Test
public void testGeoRadiusWithoutParamBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithoutParamBytes();
}
@Test
public void testGeoRadiusWithoutParam(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithoutParam();
}
@Test
public void testGeoRadiusWithDistBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithDistBytes();
}
@Test
public void testGeoRadiusWithDist(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithDist();
}
@Test
public void testGeoRadiusWithCoordAndDescBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithCoordAndDescBytes();
}
@Test
public void testGeoRadiusWithCoordAndDesc(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusWithCoordAndDesc();
}
@Test
public void testGeoRadiusByMemberWithoutParamBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithoutParamBytes();
}
@Test
public void testGeoRadiusByMemberWithoutParam(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithoutParam();
}
@Test
public void testGeoRadiusByMemberWithDistAndAscBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithDistAndAscBytes();
}
@Test
public void testGeoRadiusByMemberWithDistAndAsc(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithDistAndAsc();
}
@Test
public void testGeoRadiusByMemberWithCoordAndCountBytes(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithCoordAndCountBytes();
}
@Test
public void testGeoRadiusByMemberWithCoordAndCount(){
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
super.testGeoRadiusByMemberWithCoordAndCount();
}
@Test
public void testPExpireBytes() {
doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline();

View File

@@ -4,10 +4,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.*;
import org.junit.Before;
import org.junit.Test;
@@ -1390,6 +1387,142 @@ 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)

View File

@@ -40,6 +40,10 @@ import org.springframework.data.redis.connection.RedisStringCommands.BitOperatio
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.serializer.StringRedisSerializer;
/**
@@ -62,10 +66,14 @@ public class DefaultStringRedisConnectionTests {
protected String bar = "bar";
protected String bar2 = "bar2";
protected byte[] fooBytes = serializer.serialize(foo);
protected byte[] barBytes = serializer.serialize(bar);
protected byte[] bar2Bytes = serializer.serialize(bar2);
protected List<byte[]> bytesList = Collections.singletonList(barBytes);
protected List<String> stringList = Collections.singletonList(bar);
@@ -83,12 +91,20 @@ 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 GeoRadiusResponse geoRadiusResponse = new GeoRadiusResponse(barBytes);
protected List<GeoRadiusResponse> geoRadiusResponses = new ArrayList<GeoRadiusResponse>();
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
this.connection = new DefaultStringRedisConnection(nativeConnection);
bytesMap.put(fooBytes, barBytes);
stringMap.put(foo, bar);
geoCoordinates.add(geoCoordinate);
geoRadiusResponses.add(geoRadiusResponse);
}
@Test
@@ -1570,6 +1586,188 @@ 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));

View File

@@ -17,13 +17,14 @@ package org.springframework.data.redis.connection;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.*;
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;
/**
* @author Jennifer Hickey
@@ -1292,6 +1293,142 @@ 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();

View File

@@ -28,8 +28,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.ObjectUtils;
@@ -260,6 +259,60 @@ 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);
}
@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);
}
@Override
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) {
return delegate.georadiusByMember(key, member, radius, unit);
}
@Override
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) {
return delegate.georadiusByMember(key, member, radius, unit, param);
}
@Override
public Long geoRemove(byte[] key, byte[]... values) {
return zRem(key, values);
}
public Set<byte[]> keys(byte[] pattern) {
return delegate.keys(pattern);
}

View File

@@ -2291,7 +2291,9 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
List<String> result = clusterConnection.getConfig("*max-*-entries*");
assertThat(result.size(), is(24));
// config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6.
// @link https://github.com/spring-projects/spring-data-redis/pull/187
assertThat(result.size() % 6, is(0));
for (int i = 0; i < result.size(); i++) {
if (i % 2 == 0) {

View File

@@ -2276,7 +2276,9 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
List<String> result = clusterConnection.getConfig("*max-*-entries*");
assertThat(result.size(), is(24));
// config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6.
// @link https://github.com/spring-projects/spring-data-redis/pull/187
assertThat(result.size() % 6, is(0));
for (int i = 0; i < result.size(); i++) {
if (i % 2 == 0) {

View File

@@ -0,0 +1,255 @@
/*
* Copyright 2013-2014 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.core;
import org.junit.After;
import org.junit.Assert;
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.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.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;
/**
* Integration test of {@link org.springframework.data.redis.core.DefaultGeoOperations}
*
* @author Ninad Divadkar
*/
@RunWith(Parameterized.class)
public class DefaultGeoOperationsTests<K, M> {
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) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
}
@Parameters
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@Before
public void setUp() {
geoOperations = redisTemplate.opsForGeo();
}
@After
public void tearDown() {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.flushDb();
return null;
}
});
}
@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);
}
@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);
}
@Test
public void testGeoDist() throws Exception {
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
Double dist = geoOperations.geoDist(key, v1, v2);
assertEquals(dist.doubleValue(), 166274.15156960033, 0.00001); // gives in meters
dist = geoOperations.geoDist(key, v1, v2, GeoUnit.KiloMeters);
assertEquals(dist.doubleValue(), 166.27415156960033, 0.00001);
dist = geoOperations.geoDist(key, v1, v2, GeoUnit.Miles);
assertEquals(dist.doubleValue(), 103.31822459492733, 0.00001);
dist = geoOperations.geoDist(key, v1, v2, GeoUnit.Feet);
assertEquals(dist.doubleValue(), 545518.8699790037, 0.00001);
}
@Test
public void testGeoHash() throws Exception {
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
List<byte[]> result = geoOperations.geoHash(key, v1, v2);
assertEquals(result.size(), 2);
final RedisSerializer<String> serializer = new StringRedisSerializer();
assertEquals(serializer.deserialize(result.get(0)), "sqc8b49rny0");
assertEquals(serializer.deserialize(result.get(1)), "sqdtr74hyu0");
}
@Test
public void testGeoPos() throws Exception {
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
M v3 = valueFactory.instance();
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
List<GeoCoordinate> result = geoOperations.geoPos(key, v1, v2, v3);// v3 is nonexisting
assertEquals(result.size(), 3);
assertEquals(result.get(0).getLongitude(), 13.361389338970184, 0.000001);
assertEquals(result.get(0).getLatitude(), 38.115556395496299, 0.000001);
assertEquals(result.get(1).getLongitude(), 15.087267458438873, 0.000001);
assertEquals(result.get(1).getLatitude(), 37.50266842333162, 0.000001);
assertNull(result.get(2));
}
@Test
public void testGeoRadius() throws Exception{
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
List<GeoRadiusResponse> result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters);
Assert.assertEquals(2, result.size());
// 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);
// 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);
// with coord and dist, ascending
result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().withDist().sortAscending());
Assert.assertEquals(2, result.size());
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);
}
@Test
public void testGeoRadiusByMember() throws Exception{
K key = keyFactory.instance();
M v1 = valueFactory.instance();
M v2 = valueFactory.instance();
M v3 = valueFactory.instance();
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);//palermo
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);//catania
geoOperations.geoAdd(key, 13.583333, 37.316667, v3);//Agrigento
List<GeoRadiusResponse> result = geoOperations.georadiusByMember(key, v3, 200, GeoUnit.KiloMeters);
Assert.assertEquals(3, result.size());
// 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
// 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);
// with coord and dist, ascending
result = geoOperations.georadiusByMember(key, v1, 100, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().withDist().sortAscending());
Assert.assertEquals(2, result.size());
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);
}
@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);
Long numRemoved = geoOperations.geoRemove(key, v1);
assertEquals(1L, numRemoved.longValue());
}
}