|
@@ -11,6 +11,9 @@ import org.elasticsearch.TransportVersion;
|
|
|
import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.coordination.Coordinator;
|
|
|
+import org.elasticsearch.cluster.coordination.PreVoteCollector;
|
|
|
+import org.elasticsearch.cluster.coordination.Reconfigurator;
|
|
|
+import org.elasticsearch.cluster.coordination.StatefulPreVoteCollector;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
|
import org.elasticsearch.cluster.routing.RerouteService;
|
|
|
import org.elasticsearch.cluster.service.ClusterApplier;
|
|
@@ -24,6 +27,7 @@ import org.elasticsearch.gateway.GatewayMetaState;
|
|
|
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
|
|
import org.elasticsearch.plugins.ClusterCoordinationPlugin;
|
|
|
import org.elasticsearch.plugins.DiscoveryPlugin;
|
|
|
+import org.elasticsearch.plugins.Plugin;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.elasticsearch.test.transport.MockTransportService;
|
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
@@ -36,10 +40,13 @@ import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.function.BiConsumer;
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
+import static org.hamcrest.Matchers.containsString;
|
|
|
+import static org.hamcrest.Matchers.is;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
|
public class DiscoveryModuleTests extends ESTestCase {
|
|
@@ -219,4 +226,77 @@ public class DiscoveryModuleTests extends ESTestCase {
|
|
|
+ "[multi-node] instead."
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ public void testRejectsMultipleReconfigurators() {
|
|
|
+ assertThat(
|
|
|
+ expectThrows(
|
|
|
+ IllegalStateException.class,
|
|
|
+ () -> DiscoveryModule.getReconfigurator(
|
|
|
+ Settings.EMPTY,
|
|
|
+ new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS),
|
|
|
+ List.of(
|
|
|
+ new BaseTestClusterCoordinationPlugin(),
|
|
|
+ new TestClusterCoordinationPlugin1(),
|
|
|
+ new TestClusterCoordinationPlugin2()
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ).getMessage(),
|
|
|
+ containsString("multiple reconfigurator factories found")
|
|
|
+ );
|
|
|
+
|
|
|
+ assertThat(
|
|
|
+ DiscoveryModule.getReconfigurator(
|
|
|
+ Settings.EMPTY,
|
|
|
+ new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS),
|
|
|
+ List.of(new BaseTestClusterCoordinationPlugin())
|
|
|
+ ),
|
|
|
+ is(BaseTestClusterCoordinationPlugin.reconfiguratorInstance)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testRejectsMultiplePreVoteCollectorFactories() {
|
|
|
+ assertThat(
|
|
|
+ expectThrows(
|
|
|
+ IllegalStateException.class,
|
|
|
+ () -> DiscoveryModule.getPreVoteCollectorFactory(
|
|
|
+ List.of(new BaseTestClusterCoordinationPlugin(), new TestClusterCoordinationPlugin1() {
|
|
|
+ @Override
|
|
|
+ public Optional<ReconfiguratorFactory> getReconfiguratorFactory() {
|
|
|
+ return Optional.empty();
|
|
|
+ }
|
|
|
+ }, new TestClusterCoordinationPlugin2() {
|
|
|
+ @Override
|
|
|
+ public Optional<ReconfiguratorFactory> getReconfiguratorFactory() {
|
|
|
+ return Optional.empty();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ )
|
|
|
+ ).getMessage(),
|
|
|
+ containsString("multiple pre-vote collector factories found")
|
|
|
+ );
|
|
|
+
|
|
|
+ assertThat(
|
|
|
+ DiscoveryModule.getPreVoteCollectorFactory(List.of(new BaseTestClusterCoordinationPlugin())),
|
|
|
+ is(BaseTestClusterCoordinationPlugin.preVoteCollectorFactory)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class BaseTestClusterCoordinationPlugin extends Plugin implements ClusterCoordinationPlugin {
|
|
|
+ static Reconfigurator reconfiguratorInstance;
|
|
|
+ static PreVoteCollector.Factory preVoteCollectorFactory = StatefulPreVoteCollector::new;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Optional<ReconfiguratorFactory> getReconfiguratorFactory() {
|
|
|
+ return Optional.of((settings, clusterSettings) -> reconfiguratorInstance = new Reconfigurator(settings, clusterSettings));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Optional<PreVoteCollector.Factory> getPreVoteCollectorFactory() {
|
|
|
+ return Optional.of(preVoteCollectorFactory);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class TestClusterCoordinationPlugin1 extends BaseTestClusterCoordinationPlugin {}
|
|
|
+
|
|
|
+ public static class TestClusterCoordinationPlugin2 extends BaseTestClusterCoordinationPlugin {}
|
|
|
}
|