mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-26 23:07:45 +00:00
test: after each test, ensure that watcher only runs on one node (elected master)
Original commit: elastic/x-pack-elasticsearch@c5d0d4e1d3
This commit is contained in:
parent
59218733ea
commit
87e3a6a41d
@ -70,6 +70,11 @@ public class LicenseIntegrationTests extends AbstractWatcherIntegrationTests {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkWatcherRunningOnlyOnce() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnableDisableBehaviour() throws Exception {
|
||||
|
||||
|
@ -141,6 +141,10 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg
|
||||
return LicensePlugin.class;
|
||||
}
|
||||
|
||||
protected boolean checkWatcherRunningOnlyOnce() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void _setup() throws Exception {
|
||||
setupTimeWarp();
|
||||
@ -151,6 +155,9 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg
|
||||
public void _cleanup() throws Exception {
|
||||
// Clear all internal watcher state for the next test method:
|
||||
logger.info("[{}#{}]: clearing watcher state", getTestClass().getSimpleName(), getTestName());
|
||||
if (checkWatcherRunningOnlyOnce()) {
|
||||
ensureWatcherOnlyRunningOnce();
|
||||
}
|
||||
stopWatcher();
|
||||
}
|
||||
|
||||
@ -487,6 +494,16 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg
|
||||
ensureWatcherStopped(false);
|
||||
}
|
||||
|
||||
protected void ensureWatcherOnlyRunningOnce() {
|
||||
int running = 0;
|
||||
for (WatcherService watcherService : internalTestCluster().getInstances(WatcherService.class)) {
|
||||
if (watcherService.state() == WatcherService.State.STARTED) {
|
||||
running++;
|
||||
}
|
||||
}
|
||||
assertThat("watcher should only run on the elected master node, but it is running on [" + running + "] nodes", running, equalTo(1));
|
||||
}
|
||||
|
||||
protected static InternalTestCluster internalTestCluster() {
|
||||
return (InternalTestCluster) ((WatcherWrappingCluster) cluster()).testCluster;
|
||||
}
|
||||
|
@ -228,6 +228,7 @@ public class NoMasterNodeTests extends AbstractWatcherIntegrationTests {
|
||||
private void startElectedMasterNodeAndWait() throws Exception {
|
||||
internalTestCluster().startNode();
|
||||
ensureWatcherStarted(false);
|
||||
ensureWatcherOnlyRunningOnce();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user