|
| 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 | +} |
0 commit comments