Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify and fail-fast GeoSearchParam #3827

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/main/java/redis/clients/jedis/params/GeoSearchParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,25 @@ public GeoSearchParam any() {

@Override
public void addParams(CommandArguments args) {
if (this.fromMember) {
args.add(Keyword.FROMMEMBER).add(this.member);
} else if (this.fromLonLat) {
if (fromMember && fromLonLat) {
throw new IllegalArgumentException("Both FROMMEMBER and FROMLONLAT cannot be used.");
} else if (fromMember) {
args.add(Keyword.FROMMEMBER).add(member);
} else if (fromLonLat) {
args.add(Keyword.FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude());
} else {
throw new IllegalArgumentException("Either FROMMEMBER or FROMLONLAT must be used.");
}

if (this.byRadius) {
args.add(Keyword.BYRADIUS).add(this.radius);
} else if (this.byBox) {
args.add(Keyword.BYBOX).add(this.width).add(this.height);
if (byRadius && byBox) {
throw new IllegalArgumentException("Both BYRADIUS and BYBOX cannot be used.");
} else if (byRadius) {
args.add(Keyword.BYRADIUS).add(radius).add(unit);
} else if (byBox) {
args.add(Keyword.BYBOX).add(width).add(height).add(unit);
} else {
throw new IllegalArgumentException("Either BYRADIUS or BYBOX must be used.");
}
args.add(this.unit);

if (withCoord) {
args.add(Keyword.WITHCOORD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,30 +540,30 @@ public void geosearchNegative() {
// combine byradius and bybox
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
.byRadius(3000, GeoUnit.M)
.byBox(300, 300, GeoUnit.M));
fail();
} catch (Exception ignored) { }
} catch (IllegalArgumentException ignored) { }

// without byradius and without bybox
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.fromMember("foobar"));
jedis.geosearch("barcelona", new GeoSearchParam().fromMember("foobar"));
fail();
} catch (Exception ignored) { }
} catch (IllegalArgumentException ignored) { }

// combine frommember and fromlonlat
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.fromMember("foobar").fromLonLat(10,10));
.fromMember("foobar")
.fromLonLat(10,10));
fail();
} catch (Exception ignored) { }
} catch (IllegalArgumentException ignored) { }

// without frommember and without fromlonlat
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.byRadius(10, GeoUnit.MI));
jedis.geosearch("barcelona", new GeoSearchParam().byRadius(10, GeoUnit.MI));
fail();
} catch (Exception ignored) { }
} catch (IllegalArgumentException ignored) { }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,30 +537,30 @@ public void geosearchNegative() {
// combine byradius and bybox
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
.byRadius(3000, GeoUnit.M)
.byBox(300, 300, GeoUnit.M));
fail();
} catch (redis.clients.jedis.exceptions.JedisDataException ignored) { }
} catch (IllegalArgumentException ignored) { }

// without byradius and without bybox
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.fromMember("foobar"));
jedis.geosearch("barcelona", new GeoSearchParam().fromMember("foobar"));
fail();
} catch (java.lang.IllegalArgumentException ignored) { }
} catch (IllegalArgumentException ignored) { }

// combine frommember and fromlonlat
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.fromMember("foobar").fromLonLat(10,10));
.fromMember("foobar")
.fromLonLat(10,10));
fail();
} catch (java.lang.IllegalArgumentException ignored) { }
} catch (IllegalArgumentException ignored) { }

// without frommember and without fromlonlat
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.byRadius(10, GeoUnit.MI));
jedis.geosearch("barcelona", new GeoSearchParam().byRadius(10, GeoUnit.MI));
fail();
} catch (redis.clients.jedis.exceptions.JedisDataException ignored) { }
} catch (IllegalArgumentException ignored) { }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public void georadiusByMemberStore() {
public void georadiusByMemberStoreBinary() {
}

@Test
@Ignore
@Override
public void geosearchstore() {
}

@Test
@Ignore
@Override
public void geosearchstoreWithdist() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -798,32 +798,24 @@ public void geosearch() {
contains(0L));
}

@Test
public void geosearchNegative() {
// combine byradius and bybox
pipe.geosearch("barcelona",
new GeoSearchParam().byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));

// without frommember and without fromlonlat
pipe.geosearch("barcelona",
new GeoSearchParam().byRadius(10, GeoUnit.MI));
@Test(expected = IllegalArgumentException.class)
public void geosearchSearchParamCombineFromMemberAndFromLonLat() {
pipe.geosearch("barcelona", new GeoSearchParam().fromMember("foobar").fromLonLat(10, 10));
}

assertThat(pipe.syncAndReturnAll(), contains(
instanceOf(JedisDataException.class),
instanceOf(JedisDataException.class)
));
@Test(expected = IllegalArgumentException.class)
public void geosearchSearchParamWithoutFromMemberAndFromLonLat() {
pipe.geosearch("barcelona", new GeoSearchParam().byRadius(10, GeoUnit.MI));
}

@Test(expected = IllegalArgumentException.class)
public void geosearchSearchParamWithoutRadiousAndWithoutBox() {
pipe.geosearch("barcelona",
new GeoSearchParam().fromMember("foobar"));
public void geosearchSearchParamCombineByRadiousAndByBox() {
pipe.geosearch("barcelona", new GeoSearchParam().byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
}

@Test(expected = IllegalArgumentException.class)
public void geosearchSearchParamCombineMemberAndLonLat() {
pipe.geosearch("barcelona",
new GeoSearchParam().fromMember("foobar").fromLonLat(10, 10));
public void geosearchSearchParamWithoutByRadiousAndByBox() {
pipe.geosearch("barcelona", new GeoSearchParam().fromMember("foobar"));
}

@Test
Expand Down
Loading