Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
n1v0lg committed Dec 11, 2024
1 parent d76db83 commit 11c6be9
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.CheckedFunction;
import org.elasticsearch.core.Strings;
import org.elasticsearch.test.MapMatcher;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
Expand Down Expand Up @@ -183,15 +184,15 @@ static Settings randomPragmas() {
return settings.build();
}

static void createDataStreamOnFulfillingCluster() throws IOException {
createDataStreamPolicy();
createDataStreamComponentTemplate();
createDataStreamIndexTemplate();
createDataStreamDocuments();
createDataStreamAlias();
static void createDataStreamOnFulfillingCluster() throws Exception {
createDataStreamPolicy(AbstractRemoteClusterSecurityTestCase::performRequestAgainstFulfillingCluster);
createDataStreamComponentTemplate(AbstractRemoteClusterSecurityTestCase::performRequestAgainstFulfillingCluster);
createDataStreamIndexTemplate(AbstractRemoteClusterSecurityTestCase::performRequestAgainstFulfillingCluster);
createDataStreamDocuments(AbstractRemoteClusterSecurityTestCase::performRequestAgainstFulfillingCluster);
createDataStreamAlias(AbstractRemoteClusterSecurityTestCase::performRequestAgainstFulfillingCluster);
}

private static void createDataStreamPolicy() throws IOException {
private static void createDataStreamPolicy(CheckedFunction<Request, Response, Exception> requestConsumer) throws Exception {
Request request = new Request("PUT", "_ilm/policy/my-lifecycle-policy");
request.setJsonEntity("""
{
Expand All @@ -214,10 +215,10 @@ private static void createDataStreamPolicy() throws IOException {
}
}""");

performRequestAgainstFulfillingCluster(request);
requestConsumer.apply(request);
}

private static void createDataStreamComponentTemplate() throws IOException {
private static void createDataStreamComponentTemplate(CheckedFunction<Request, Response, Exception> requestConsumer) throws Exception {
Request request = new Request("PUT", "_component_template/my-template");
request.setJsonEntity("""
{
Expand All @@ -241,10 +242,10 @@ private static void createDataStreamComponentTemplate() throws IOException {
}
}
}""");
performRequestAgainstFulfillingCluster(request);
requestConsumer.apply(request);
}

private static void createDataStreamIndexTemplate() throws IOException {
private static void createDataStreamIndexTemplate(CheckedFunction<Request, Response, Exception> requestConsumer) throws Exception {
Request request = new Request("PUT", "_index_template/my-index-template");
request.setJsonEntity("""
{
Expand All @@ -253,10 +254,10 @@ private static void createDataStreamIndexTemplate() throws IOException {
"composed_of": ["my-template"],
"priority": 500
}""");
performRequestAgainstFulfillingCluster(request);
requestConsumer.apply(request);
}

private static void createDataStreamDocuments() throws IOException {
private static void createDataStreamDocuments(CheckedFunction<Request, Response, Exception> requestConsumer) throws Exception {
Request request = new Request("POST", "logs-foo/_bulk");
request.addParameter("refresh", "");
request.setJsonEntity("""
Expand All @@ -265,10 +266,10 @@ private static void createDataStreamDocuments() throws IOException {
{ "create" : {} }
{ "@timestamp": "2001-05-06T16:21:15.000Z", "data_stream": {"namespace": "17", "environment": "prod"} }
""");
assertMap(entityAsMap(performRequestAgainstFulfillingCluster(request)), matchesMap().extraOk().entry("errors", false));
assertMap(entityAsMap(requestConsumer.apply(request)), matchesMap().extraOk().entry("errors", false));
}

private static void createDataStreamAlias() throws IOException {
private static void createDataStreamAlias(CheckedFunction<Request, Response, Exception> requestConsumer) throws Exception {
Request request = new Request("PUT", "_alias");
request.setJsonEntity("""
{
Expand All @@ -281,7 +282,7 @@ private static void createDataStreamAlias() throws IOException {
}
]
}""");
assertMap(entityAsMap(performRequestAgainstFulfillingCluster(request)), matchesMap().extraOk().entry("errors", false));
assertMap(entityAsMap(requestConsumer.apply(request)), matchesMap().extraOk().entry("errors", false));
}

static void doTestDataStreamsWithFlsAndDls() throws IOException {
Expand Down

0 comments on commit 11c6be9

Please sign in to comment.