Skip to content

Commit

Permalink
fixed more java rest tests with a dummy rollup index
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvg committed May 15, 2024
1 parent a38459e commit 1e11c14
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ public void testInsufficientSearchPrivilegesOnPutWithJob() {
}

public void testCreationOnPutWithRollup() throws Exception {
createDummyRollupIndex();
setupDataAccessRole("airline-data-aggs-rollup");
String jobId = "privs-put-job-rollup";
String datafeedId = "datafeed-" + jobId;
Expand Down Expand Up @@ -1248,6 +1249,7 @@ public void testLookbackWithPipelineBucketAgg() throws Exception {
}

public void testLookbackOnlyGivenAggregationsWithHistogramAndRollupIndex() throws Exception {
createDummyRollupIndex();
String jobId = "aggs-histogram-rollup-job";
Request createJobRequest = new Request("PUT", MachineLearning.BASE_PATH + "anomaly_detectors/" + jobId);
createJobRequest.setJsonEntity("""
Expand Down Expand Up @@ -1351,6 +1353,7 @@ public void testLookbackOnlyGivenAggregationsWithHistogramAndRollupIndex() throw
}

public void testLookbackWithoutPermissionsAndRollup() throws Exception {
createDummyRollupIndex();
setupFullAccessRole("airline-data-aggs-rollup");
String jobId = "rollup-permission-test-network-job";
String datafeedId = "datafeed-" + jobId;
Expand Down Expand Up @@ -1878,4 +1881,23 @@ private Response createJobAndDataFeed(String jobId, String datafeedId) throws IO
.setAuthHeader(BASIC_AUTH_VALUE_ML_ADMIN_WITH_SOME_DATA_ACCESS)
.build();
}

private static void createDummyRollupIndex() throws IOException {
// create dummy rollup index to circumvent the check that prohibits rollup usage in empty clusters:
{
Request req = new Request("PUT", "dummy-rollup-index");
req.setJsonEntity("""
{
"mappings":{
"_meta": {
"_rollup":{
"my-id": {}
}
}
}
}
""");
client().performRequest(req);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,23 @@ public void testApiKeySuperuser() throws IOException {
*/
public void testRollupAfterRestart() throws Exception {
if (isRunningAgainstOldCluster()) {
// create dummy rollup index to circumvent the check that prohibits rollup usage in empty clusters:
{
Request req = new Request("PUT", "dummy-rollup-index");
req.setJsonEntity("""
{
"mappings":{
"_meta": {
"_rollup":{
"my-id": {}
}
}
}
}
""");
client().performRequest(req);
}

final int numDocs = 59;
final int year = randomIntBetween(1970, 2018);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,25 @@ private Settings getClientSettings(final String username, final String password)
}

public void testBigRollup() throws Exception {
final int numDocs = 200;
String dateFormat = "strict_date_optional_time";

// create dummy rollup index to circumvent the check that prohibits rollup usage in empty clusters:
try (XContentBuilder builder = jsonBuilder()) {
builder.startObject();
{
builder.startObject("mappings")
.startObject("_meta")
.startObject("_rollup")
.startObject("my-id")
.endObject()
.endObject()
.endObject()
.endObject();
}
builder.endObject();
final StringEntity entity = new StringEntity(Strings.toString(builder), ContentType.APPLICATION_JSON);
Request req = new Request("PUT", "dunmy-rollup-index");
req.setEntity(entity);
{
Request req = new Request("PUT", "dummy-rollup-index");
req.setJsonEntity("""
{
"mappings":{
"_meta": {
"_rollup":{
"my-id": {}
}
}
}
}
""");
client().performRequest(req);
}

final int numDocs = 200;
String dateFormat = "strict_date_optional_time";
// create the test-index index
try (XContentBuilder builder = jsonBuilder()) {
builder.startObject();
Expand Down

0 comments on commit 1e11c14

Please sign in to comment.