Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
masseyke committed Dec 1, 2023
1 parent 1f425e5 commit 5619b39
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ void prepareBulkRequest(long thisBatchStartTimeNS, ScrollConsumableHitsResponse
/*
* If we noop-ed the entire batch then just skip to the next batch or the BulkRequest would fail validation.
*/
notifyDone(thisBatchStartTimeNS, asyncResponse, 0);
try {
notifyDone(thisBatchStartTimeNS, asyncResponse, 0);
} finally {
request.close();
}
return;
}
request.timeout(mainRequest.getTimeout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ public boolean awaitClose(long timeout, TimeUnit unit) throws InterruptedExcepti
return this.bulkRequestHandler.awaitClose(timeout, unit);
} finally {
onClose.run();
if (bulkRequest.hasReferences()) {
bulkRequest.close();
}
}
} finally {
if (bulkRequest.hasReferences()) {
bulkRequest.close();
}
lock.unlock();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ public void testKnownIssueWithCellLeftOfDatelineTouchingPolygonOnRightOfDateline
.endObject();
indicesAdmin().prepareCreate("test").setMapping(xcb).get();

BulkRequestBuilder builder = client().prepareBulk();
builder.add(
new IndexRequest("test").source("{\"geometry\" : \"BBOX (179.99999, 180.0, -11.29550, -11.29552)\"}", XContentType.JSON)
);
builder.add(
new IndexRequest("test").source("{\"geometry\" : \"BBOX (-180.0, -179.99999, -11.29550, -11.29552)\"}", XContentType.JSON)
);
try (BulkRequestBuilder builder = client().prepareBulk()) {
builder.add(
new IndexRequest("test").source("{\"geometry\" : \"BBOX (179.99999, 180.0, -11.29550, -11.29552)\"}", XContentType.JSON)
);
builder.add(
new IndexRequest("test").source("{\"geometry\" : \"BBOX (-180.0, -179.99999, -11.29550, -11.29552)\"}", XContentType.JSON)
);

assertFalse(builder.get().hasFailures());
assertFalse(builder.get().hasFailures());
}
indicesAdmin().prepareRefresh("test").get();

GeoBoundingBox boundingBox = new GeoBoundingBox(new GeoPoint(-11.29550, 179.999992), new GeoPoint(-11.29552, -179.999992));
Expand Down Expand Up @@ -148,17 +149,18 @@ public void testKnownIssueWithCellIntersectingPolygonAndBoundingBox() throws IOE
.endObject();
indicesAdmin().prepareCreate("test").setMapping(xcb).get();

BulkRequestBuilder builder = client().prepareBulk();
builder.add(
new IndexRequest("test").source("{\"geometry\" : \"POINT (169.12088680200193 86.17678739494652)\"}", XContentType.JSON)
);
builder.add(
new IndexRequest("test").source("{\"geometry\" : \"POINT (169.12088680200193 86.17678739494652)\"}", XContentType.JSON)
);
String mp = "POLYGON ((150.0 70.0, 150.0 85.91811374669217, 168.77544806565834 85.91811374669217, 150.0 70.0))";
builder.add(new IndexRequest("test").source("{\"geometry\" : \"" + mp + "\"}", XContentType.JSON));
try (BulkRequestBuilder builder = client().prepareBulk()) {
builder.add(
new IndexRequest("test").source("{\"geometry\" : \"POINT (169.12088680200193 86.17678739494652)\"}", XContentType.JSON)
);
builder.add(
new IndexRequest("test").source("{\"geometry\" : \"POINT (169.12088680200193 86.17678739494652)\"}", XContentType.JSON)
);
String mp = "POLYGON ((150.0 70.0, 150.0 85.91811374669217, 168.77544806565834 85.91811374669217, 150.0 70.0))";
builder.add(new IndexRequest("test").source("{\"geometry\" : \"" + mp + "\"}", XContentType.JSON));

assertFalse(builder.get().hasFailures());
assertFalse(builder.get().hasFailures());
}
indicesAdmin().prepareRefresh("test").get();

// BBOX (172.21916569181505, -173.17785081207947, 86.17678739494652, 83.01600086049713)
Expand Down Expand Up @@ -255,21 +257,22 @@ private void doTestGrid(
tiles[zoom] = pointEncoder.apply(zoom, queryPoint);
}

BulkRequestBuilder builder = client().prepareBulk();
for (int zoom = minPrecision; zoom < tiles.length; zoom++) {
List<Point> edgePoints = toPoints.apply(tiles[zoom]);
String[] multiPoint = new String[edgePoints.size()];
for (int i = 0; i < edgePoints.size(); i++) {
String wkt = WellKnownText.toWKT(edgePoints.get(i));
String doc = "{\"geometry\" : \"" + wkt + "\"}";
try (BulkRequestBuilder builder = client().prepareBulk()) {
for (int zoom = minPrecision; zoom < tiles.length; zoom++) {
List<Point> edgePoints = toPoints.apply(tiles[zoom]);
String[] multiPoint = new String[edgePoints.size()];
for (int i = 0; i < edgePoints.size(); i++) {
String wkt = WellKnownText.toWKT(edgePoints.get(i));
String doc = "{\"geometry\" : \"" + wkt + "\"}";
builder.add(new IndexRequest("test").source(doc, XContentType.JSON));
multiPoint[i] = "\"" + wkt + "\"";
}
String doc = "{\"geometry\" : " + Arrays.toString(multiPoint) + "}";
builder.add(new IndexRequest("test").source(doc, XContentType.JSON));
multiPoint[i] = "\"" + wkt + "\"";
}
String doc = "{\"geometry\" : " + Arrays.toString(multiPoint) + "}";
builder.add(new IndexRequest("test").source(doc, XContentType.JSON));

}
assertFalse(builder.get().hasFailures());
}
assertFalse(builder.get().hasFailures());
indicesAdmin().prepareRefresh("test").get();

for (int i = minPrecision; i <= maxPrecision; i++) {
Expand All @@ -281,14 +284,15 @@ private void doTestGrid(
});
}

builder = client().prepareBulk();
final int numDocs = randomIntBetween(10, 20);
for (int id = 0; id < numDocs; id++) {
String wkt = WellKnownText.toWKT(randomGeometriesSupplier.get());
String doc = "{\"geometry\" : \"" + wkt + "\"}";
builder.add(new IndexRequest("test").source(doc, XContentType.JSON));
try (BulkRequestBuilder builder = client().prepareBulk()) {
final int numDocs = randomIntBetween(10, 20);
for (int id = 0; id < numDocs; id++) {
String wkt = WellKnownText.toWKT(randomGeometriesSupplier.get());
String doc = "{\"geometry\" : \"" + wkt + "\"}";
builder.add(new IndexRequest("test").source(doc, XContentType.JSON));
}
assertFalse(builder.get().hasFailures());
}
assertFalse(builder.get().hasFailures());
indicesAdmin().prepareRefresh("test").get();

int zoom = randomIntBetween(minPrecision, maxPrecision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,16 @@ private void setUpDataStreamWriteDocsAndRollover(String dataStreamName, Settings
}

static void indexDocs(String dataStream, int numDocs) {
BulkRequest bulkRequest = new BulkRequest();
for (int i = 0; i < numDocs; i++) {
String value = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.formatMillis(System.currentTimeMillis());
bulkRequest.add(
new IndexRequest(dataStream).opType(DocWriteRequest.OpType.CREATE)
.source(Strings.format("{\"%s\":\"%s\"}", DEFAULT_TIMESTAMP_FIELD, value), XContentType.JSON)
);
try (BulkRequest bulkRequest = new BulkRequest()) {
for (int i = 0; i < numDocs; i++) {
String value = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.formatMillis(System.currentTimeMillis());
bulkRequest.add(
new IndexRequest(dataStream).opType(DocWriteRequest.OpType.CREATE)
.source(Strings.format("{\"%s\":\"%s\"}", DEFAULT_TIMESTAMP_FIELD, value), XContentType.JSON)
);
}
client().bulk(bulkRequest).actionGet();
}
client().bulk(bulkRequest).actionGet();
}

private void setHasValidLicense(boolean hasValidLicense) {
Expand Down

0 comments on commit 5619b39

Please sign in to comment.