From 667bb340b4d8d343f25b318a1725b455c3dc29bd Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Tue, 15 Nov 2016 13:42:59 +0000 Subject: [PATCH] Update tests for new auto management of min master nodes (elastic/elasticsearch#4068) The internal test cluster now auto manages min_master_nodes ( see https://github.com/elastic/elasticsearch/pull/21458 ). This requires some code changes but also changes the timings of forming a cluster. This has had a funny side effect where the master is no longer always the first node to be started in the cluster. This caused issues with watcher tests which freeze time. Original commit: elastic/x-pack-elasticsearch@1e5ea8ae94638eb700b1bd1202d0b356629168de --- .../license/LicenseServiceClusterTests.java | 3 +-- .../license/TribeTransportTestCase.java | 5 ++-- .../resolver/node/MultiNodesStatsTests.java | 6 +++-- .../xpack/security/SecurityTribeIT.java | 2 +- .../audit/index/IndexAuditTrailTests.java | 2 +- .../RemoteIndexAuditTrailStartingTests.java | 3 +-- .../AbstractWatcherIntegrationTestCase.java | 23 +++++++++++++++++++ 7 files changed, 33 insertions(+), 11 deletions(-) diff --git a/elasticsearch/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java b/elasticsearch/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java index 3352ca4b04f..391213273a0 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java @@ -21,12 +21,11 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.Collection; -import static org.elasticsearch.license.TestUtils.generateSignedLicense; import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.nullValue; -@ClusterScope(scope = TEST, numDataNodes = 0, numClientNodes = 0, maxNumDataNodes = 0, transportClientRatio = 0) +@ClusterScope(scope = TEST, numDataNodes = 0, numClientNodes = 0, maxNumDataNodes = 0, transportClientRatio = 0, autoMinMasterNodes = false) public class LicenseServiceClusterTests extends AbstractLicensesIntegrationTestCase { @Override diff --git a/elasticsearch/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java b/elasticsearch/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java index b285d1c8874..1267a1bad73 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java +++ b/elasticsearch/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java @@ -46,7 +46,7 @@ import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; -@ClusterScope(scope = Scope.TEST, transportClientRatio = 0, numClientNodes = 1, numDataNodes = 0) +@ClusterScope(scope = Scope.TEST, transportClientRatio = 0, numClientNodes = 1, numDataNodes = 2) public abstract class TribeTransportTestCase extends ESIntegTestCase { protected List enabledFeatures() { @@ -99,12 +99,11 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { } }; final InternalTestCluster cluster2 = new InternalTestCluster( - randomLong(), createTempDir(), true, 2, 2, + randomLong(), createTempDir(), true, true, 2, 2, UUIDs.randomBase64UUID(random()), nodeConfigurationSource, 1, false, "tribe_node2", getMockPlugins(), getClientWrapper()); cluster2.beforeTest(random(), 0.0); - cluster2.ensureAtLeastNumDataNodes(2); logger.info("create 2 indices, test1 on t1, and test2 on t2"); assertAcked(internalCluster().client().admin().indices().prepareCreate("test1").get()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/MultiNodesStatsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/MultiNodesStatsTests.java index 63bd91ebeb9..b413f20735c 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/MultiNodesStatsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/resolver/node/MultiNodesStatsTests.java @@ -69,8 +69,10 @@ public class MultiNodesStatsTests extends MonitoringIntegTestCase { n = randomIntBetween(1, 2); logger.debug("--> starting {} extra nodes", n); - InternalTestCluster.Async> extraNodes = internalCluster().startNodesAsync(n); - extraNodes.get(); + // starting one by one to allow moving , for example, from a 2 node cluster to a 4 one while updating min_master_nodes + for (int i=0;i { for (XPackLicenseState licenseState : internalCluster().getInstances(XPackLicenseState.class)) { assertThat(licenseState.isWatcherAllowed(), is(true)); @@ -595,6 +603,21 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase }); } + private void progressClocksAboveMaster(InternalTestCluster cluster) { + long minClock = Long.MAX_VALUE; + long maxClock = Long.MIN_VALUE; + for (Clock clock: cluster.getInstances(Clock.class)) { + final long millis = clock.millis(); + minClock = Math.min(millis, minClock); + maxClock = Math.max(millis, maxClock); + } + // now move all the clocks ahead to make sure they are beyond the highest clock + final TimeValue delta = TimeValue.timeValueMillis(maxClock - minClock); + for (Clock clock: cluster.getInstances(Clock.class)) { + ((ClockMock)clock).fastForward(delta); + } + } + protected void ensureWatcherStopped() throws Exception { ensureWatcherStopped(true); }