Skip to content

Commit 5dc679c

Browse files
committed
Integration Tests
1 parent 2fa713f commit 5dc679c

File tree

3 files changed

+87
-5
lines changed

3 files changed

+87
-5
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.rest.streams;
11+
12+
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
13+
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
14+
import org.elasticsearch.action.support.master.AcknowledgedResponse;
15+
import org.elasticsearch.cluster.metadata.ProjectId;
16+
import org.elasticsearch.cluster.metadata.ProjectMetadata;
17+
import org.elasticsearch.plugins.Plugin;
18+
import org.elasticsearch.rest.streams.logs.LogsStreamsActivationToggleAction;
19+
import org.elasticsearch.test.ESIntegTestCase;
20+
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
21+
import org.elasticsearch.test.transport.MockTransportService;
22+
23+
import java.io.IOException;
24+
import java.util.Collection;
25+
import java.util.List;
26+
import java.util.concurrent.ExecutionException;
27+
28+
import static org.hamcrest.Matchers.is;
29+
30+
public class TestToggleIT extends ESIntegTestCase {
31+
32+
@Override
33+
protected Collection<Class<? extends Plugin>> nodePlugins() {
34+
return List.of(StreamsPlugin.class, MockTransportService.TestPlugin.class);
35+
}
36+
37+
public void testLogStreamToggle() throws IOException, ExecutionException, InterruptedException {
38+
boolean[] testParams = new boolean[] { true, false, true };
39+
for (boolean enable : testParams) {
40+
doLogStreamToggleTest(enable);
41+
}
42+
}
43+
44+
private void doLogStreamToggleTest(boolean enable) throws IOException, ExecutionException, InterruptedException {
45+
LogsStreamsActivationToggleAction.Request request = new LogsStreamsActivationToggleAction.Request(
46+
TEST_REQUEST_TIMEOUT,
47+
TEST_REQUEST_TIMEOUT,
48+
enable
49+
);
50+
51+
AcknowledgedResponse acknowledgedResponse = client().execute(LogsStreamsActivationToggleAction.INSTANCE, request).get();
52+
ElasticsearchAssertions.assertAcked(acknowledgedResponse);
53+
54+
ClusterStateRequest state = new ClusterStateRequest(TEST_REQUEST_TIMEOUT);
55+
ClusterStateResponse clusterStateResponse = client().admin().cluster().state(state).get();
56+
ProjectMetadata projectMetadata = clusterStateResponse.getState().metadata().getProject(ProjectId.DEFAULT);
57+
58+
assertThat(projectMetadata.<StreamsMetadata>custom(StreamsMetadata.TYPE).isLogsEnabled(), is(enable));
59+
}
60+
61+
}

modules/streams/src/main/java/org/elasticsearch/rest/streams/StreamsMetadata.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.TransportVersion;
1313
import org.elasticsearch.TransportVersions;
1414
import org.elasticsearch.cluster.AbstractNamedDiffable;
15+
import org.elasticsearch.cluster.NamedDiff;
1516
import org.elasticsearch.cluster.metadata.Metadata;
1617
import org.elasticsearch.common.collect.Iterators;
1718
import org.elasticsearch.common.io.stream.StreamInput;
@@ -22,6 +23,7 @@
2223
import java.io.IOException;
2324
import java.util.EnumSet;
2425
import java.util.Iterator;
26+
import java.util.Objects;
2527

2628
/**
2729
* Metadata for the Streams feature, which allows enabling or disabling logs for data streams.
@@ -46,10 +48,6 @@ public boolean isLogsEnabled() {
4648
return logsEnabled;
4749
}
4850

49-
public void setLogsEnabled(boolean logsEnabled) {
50-
this.logsEnabled = logsEnabled;
51-
}
52-
5351
@Override
5452
public EnumSet<Metadata.XContentContext> context() {
5553
return Metadata.ALL_CONTEXTS;
@@ -65,6 +63,12 @@ public TransportVersion getMinimalSupportedVersion() {
6563
return TransportVersions.STREAMS_LOGS_SUPPORT;
6664
}
6765

66+
public static NamedDiff<Metadata.ProjectCustom> readDiffFrom(StreamInput in) throws IOException {
67+
return readDiffFrom(Metadata.ProjectCustom.class, TYPE, in);
68+
}
69+
70+
71+
6872
@Override
6973
public void writeTo(StreamOutput out) throws IOException {
7074
out.writeBoolean(logsEnabled);
@@ -75,4 +79,17 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
7579
return Iterators.concat(ChunkedToXContentHelper.chunk((builder, bParams) -> builder.field("logs_enabled", logsEnabled)));
7680
}
7781

82+
@Override
83+
public boolean equals(Object o) {
84+
if ((o instanceof StreamsMetadata that)) {
85+
return logsEnabled == that.logsEnabled;
86+
} else {
87+
return false;
88+
}
89+
}
90+
91+
@Override
92+
public int hashCode() {
93+
return Objects.hashCode(logsEnabled);
94+
}
7895
}

modules/streams/src/main/java/org/elasticsearch/rest/streams/StreamsPlugin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.elasticsearch.rest.streams;
1111

12+
import org.elasticsearch.cluster.NamedDiff;
1213
import org.elasticsearch.cluster.metadata.DataStream;
1314
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1415
import org.elasticsearch.cluster.metadata.Metadata;
@@ -68,6 +69,9 @@ public List<ActionHandler> getActions() {
6869

6970
@Override
7071
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
71-
return List.of(new NamedWriteableRegistry.Entry(Metadata.ProjectCustom.class, StreamsMetadata.TYPE, StreamsMetadata::new));
72+
return List.of(
73+
new NamedWriteableRegistry.Entry(Metadata.ProjectCustom.class, StreamsMetadata.TYPE, StreamsMetadata::new),
74+
new NamedWriteableRegistry.Entry(NamedDiff.class, StreamsMetadata.TYPE, StreamsMetadata::readDiffFrom)
75+
);
7276
}
7377
}

0 commit comments

Comments
 (0)