Skip to content

Commit

Permalink
Reset coordinate state of GeoWithinListOutput after completing an item
Browse files Browse the repository at this point in the history
…#805

GeoWithinListOutput now resets its longitude (x) coordinate state after completing a GeoWithin item. Previously, the longitude coordinate was never reset and subsequent items used the first reported longitude coordinate which rendered an incorrect result.
  • Loading branch information
mp911de committed Jun 21, 2018
1 parent bda3018 commit 84c3fdb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void complete(int depth) {
distance = null;
geohash = null;
coordinates = null;
x = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ protected RedisCommands<String, String> connect() {

@Ignore("MULTI not available on Redis Cluster")
@Override
public void geoaddWithTransaction() {
public void geoaddInTransaction() {
}

@Ignore("MULTI not available on Redis Cluster")
@Override
public void geoaddMultiWithTransaction() {
public void geoaddMultiInTransaction() {
}

@Ignore("MULTI not available on Redis Cluster")
@Override
public void georadiusWithTransaction() {
public void georadiusInTransaction() {
}

@Ignore("MULTI not available on Redis Cluster")
@Override
public void geodistWithTransaction() {
public void geodistInTransaction() {
}

@Ignore("MULTI not available on Redis Cluster")
Expand All @@ -96,16 +96,16 @@ public void georadiusWithArgsAndTransaction() {

@Ignore("MULTI not available on Redis Cluster")
@Override
public void georadiusbymemberWithArgsAndTransaction() {
public void georadiusbymemberWithArgsInTransaction() {
}

@Ignore("MULTI not available on Redis Cluster")
@Override
public void geoposWithTransaction() {
public void geoposInTransaction() {
}

@Ignore("MULTI not available on Redis Cluster")
@Override
public void geohashWithTransaction() {
public void geohashInTransaction() {
}
}
51 changes: 39 additions & 12 deletions src/test/java/io/lettuce/core/commands/GeoCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import io.lettuce.core.*;
import io.lettuce.core.api.StatefulRedisConnection;

/**
* @author Mark Paluch
*/
public class GeoCommandTest extends AbstractRedisClientTest {

@Rule
Expand All @@ -57,7 +60,7 @@ public void geoadd() {
}

@Test
public void geoaddWithTransaction() {
public void geoaddInTransaction() {

redis.multi();
redis.geoadd(key, -73.9454966, 40.747533, "lic market");
Expand All @@ -75,7 +78,7 @@ public void geoaddMulti() {
}

@Test
public void geoaddMultiWithTransaction() {
public void geoaddMultiInTransaction() {

redis.multi();
redis.geoadd(key, 8.6638775, 49.5282537, "Weinheim", 8.3796281, 48.9978127, "EFS9", 8.665351, 49.553302, "Bahn");
Expand All @@ -88,11 +91,6 @@ public void geoaddMultiWrongArgument() {
redis.geoadd(key, 49.528253);
}

protected void prepareGeo() {
redis.geoadd(key, 8.6638775, 49.5282537, "Weinheim");
redis.geoadd(key, 8.3796281, 48.9978127, "EFS9", 8.665351, 49.553302, "Bahn");
}

@Test
public void georadius() {

Expand All @@ -106,7 +104,7 @@ public void georadius() {
}

@Test
public void georadiusWithTransaction() {
public void georadiusInTransaction() {

prepareGeo();

Expand All @@ -122,6 +120,22 @@ public void georadiusWithTransaction() {
assertThat(largerGeoradius).hasSize(2).contains("Weinheim").contains("Bahn");
}

@Test
public void georadiusWithCoords() {

prepareGeo();

List<GeoWithin<String>> georadius = redis.georadius(key, 8.6582861, 49.5285695, 100, GeoArgs.Unit.km,
GeoArgs.Builder.coordinates());

assertThat(georadius).hasSize(3);
assertThat(getX(georadius, 0)).isBetween(8.66, 8.67);
assertThat(getY(georadius, 0)).isBetween(49.52, 49.53);

assertThat(getX(georadius, 2)).isBetween(8.37, 8.38);
assertThat(getY(georadius, 2)).isBetween(48.99, 49.00);
}

@Test
public void geodist() {

Expand All @@ -144,7 +158,7 @@ public void geodistMissingElements() {
}

@Test
public void geodistWithTransaction() {
public void geodistInTransaction() {

prepareGeo();

Expand Down Expand Up @@ -175,7 +189,7 @@ public void geopos() {
}

@Test
public void geoposWithTransaction() {
public void geoposInTransaction() {

prepareGeo();

Expand Down Expand Up @@ -282,7 +296,7 @@ public void geohashUnknownKey() {
}

@Test
public void geohashWithTransaction() {
public void geohashInTransaction() {

prepareGeo();

Expand Down Expand Up @@ -434,7 +448,7 @@ public void georadiusbymemberWithArgs() {
}

@Test
public void georadiusbymemberWithArgsAndTransaction() {
public void georadiusbymemberWithArgsInTransaction() {

prepareGeo();

Expand Down Expand Up @@ -488,4 +502,17 @@ public void georadiusStorebymemberWithNullArgs() {
redis.georadiusbymember(key, "Bahn", 1, GeoArgs.Unit.km, (GeoRadiusStoreArgs<String>) null);
}

protected void prepareGeo() {
redis.geoadd(key, 8.6638775, 49.5282537, "Weinheim");
redis.geoadd(key, 8.3796281, 48.9978127, "EFS9", 8.665351, 49.553302, "Bahn");
}

private static double getY(List<GeoWithin<String>> georadius, int i) {
return georadius.get(i).getCoordinates().getY().doubleValue();
}

private static double getX(List<GeoWithin<String>> georadius, int i) {
return georadius.get(i).getCoordinates().getX().doubleValue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public void geopos() {
@Test
@Ignore("API differences")
@Override
public void geoposWithTransaction() {
public void geoposInTransaction() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ protected RedisCommands<String, String> connect() {

@Ignore
@Override
public void georadiusbymemberWithArgsAndTransaction() {
public void georadiusbymemberWithArgsInTransaction() {
}

@Ignore
@Override
public void geoaddWithTransaction() {
public void geoaddInTransaction() {
}

@Ignore
@Override
public void geoaddMultiWithTransaction() {
public void geoaddMultiInTransaction() {
}

@Ignore
@Override
public void geoposWithTransaction() {
public void geoposInTransaction() {
}

@Ignore
Expand All @@ -57,16 +57,16 @@ public void georadiusWithArgsAndTransaction() {

@Ignore
@Override
public void georadiusWithTransaction() {
public void georadiusInTransaction() {
}

@Ignore
@Override
public void geodistWithTransaction() {
public void geodistInTransaction() {
}

@Ignore
@Override
public void geohashWithTransaction() {
public void geohashInTransaction() {
}
}

0 comments on commit 84c3fdb

Please sign in to comment.