Skip to content

Commit

Permalink
address warns
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-khludnev committed Oct 17, 2024
1 parent bebebac commit eb73e63
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static org.hamcrest.Matchers.equalTo;

import org.hamcrest.MatcherAssert;

import static org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;

public class SearchIpFieldTermsTest extends OpenSearchSingleNodeTestCase {
Expand All @@ -41,7 +45,7 @@ public void testMassive() throws Exception {
int cidrs = 0;
int ips = 0;
List<String> toQuery = new ArrayList<>();
for (int i = 0; ips <= 1024; i++) {
for (int i = 0; ips <= 1024 && i < 1000000; i++) {
final String ip;
final int prefix;
if (IPv4_ONLY) {
Expand Down Expand Up @@ -93,7 +97,7 @@ public void testMassive() throws Exception {
SearchResponse result = client().prepareSearch(defaultIndexName)
.setQuery(QueryBuilders.termsQuery("addr", toQuery))
.get();
assertThat(result.getHits().getTotalHits().value, equalTo(0L + cidrs + ips + addMatches));
MatcherAssert.assertThat(Objects.requireNonNull(result.getHits().getTotalHits()).value, equalTo((long) cidrs + ips + addMatches));
}


Expand Down Expand Up @@ -126,9 +130,7 @@ private static boolean isIPInCIDR(String ip, String cidr) throws UnknownHostExce
// Compare extra bits (if any)
if (extraBits > 0) {
int mask = 0xFF << (8 - extraBits);
if ((ipBytes[fullBytes] & mask) != (cidrIpBytes[fullBytes] & mask)) {
return false;
}
return (ipBytes[fullBytes] & mask) == (cidrIpBytes[fullBytes] & mask);
}

return true;
Expand All @@ -155,7 +157,7 @@ private static String generateRandomIPv6() {
}

private XContentBuilder createMapping() throws IOException {
XContentBuilder xcb = XContentFactory.jsonBuilder()
return XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject("addr")
Expand All @@ -173,6 +175,5 @@ private XContentBuilder createMapping() throws IOException {
.endObject()
.endObject()
.endObject();
return xcb;
}
}

0 comments on commit eb73e63

Please sign in to comment.