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:
Martijn van Groningen 2015-04-28 13:41:24 +02:00
parent 59218733ea
commit 87e3a6a41d
3 changed files with 23 additions and 0 deletions

View File

@ -70,6 +70,11 @@ public class LicenseIntegrationTests extends AbstractWatcherIntegrationTests {
return true;
}
@Override
protected boolean checkWatcherRunningOnlyOnce() {
return false;
}
@Test
public void testEnableDisableBehaviour() throws Exception {

View File

@ -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;
}

View File

@ -228,6 +228,7 @@ public class NoMasterNodeTests extends AbstractWatcherIntegrationTests {
private void startElectedMasterNodeAndWait() throws Exception {
internalTestCluster().startNode();
ensureWatcherStarted(false);
ensureWatcherOnlyRunningOnce();
}
}