Search in sources :

Example 1 with ZenDiscovery

use of org.elasticsearch.discovery.zen.ZenDiscovery in project elasticsearch by elastic.

the class ESIntegTestCase method afterInternal.

protected final void afterInternal(boolean afterClass) throws Exception {
    boolean success = false;
    try {
        final Scope currentClusterScope = getCurrentClusterScope();
        clearDisruptionScheme();
        try {
            if (cluster() != null) {
                if (currentClusterScope != Scope.TEST) {
                    MetaData metaData = client().admin().cluster().prepareState().execute().actionGet().getState().getMetaData();
                    final Map<String, String> persistent = metaData.persistentSettings().getAsMap();
                    assertThat("test leaves persistent cluster metadata behind: " + persistent, persistent.size(), equalTo(0));
                    final Map<String, String> transientSettings = new HashMap<>(metaData.transientSettings().getAsMap());
                    if (isInternalCluster() && internalCluster().getAutoManageMinMasterNode()) {
                        // this is set by the test infra
                        transientSettings.remove(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey());
                    }
                    assertThat("test leaves transient cluster metadata behind: " + transientSettings, transientSettings.keySet(), empty());
                }
                ensureClusterSizeConsistency();
                ensureClusterStateConsistency();
                if (isInternalCluster()) {
                    // check no pending cluster states are leaked
                    for (Discovery discovery : internalCluster().getInstances(Discovery.class)) {
                        if (discovery instanceof ZenDiscovery) {
                            final ZenDiscovery zenDiscovery = (ZenDiscovery) discovery;
                            assertBusy(() -> {
                                final ClusterState[] states = zenDiscovery.pendingClusterStates();
                                assertThat(zenDiscovery.localNode().getName() + " still having pending states:\n" + Stream.of(states).map(ClusterState::toString).collect(Collectors.joining("\n")), states, emptyArray());
                            });
                        }
                    }
                }
                beforeIndexDeletion();
                // wipe after to make sure we fail in the test that didn't ack the delete
                cluster().wipe(excludeTemplates());
                if (afterClass || currentClusterScope == Scope.TEST) {
                    cluster().close();
                }
                cluster().assertAfterTest();
            }
        } finally {
            if (currentClusterScope == Scope.TEST) {
                // it is ok to leave persistent / transient cluster state behind if scope is TEST
                clearClusters();
            }
        }
        success = true;
    } finally {
        if (!success) {
        // if we failed here that means that something broke horribly so we should clear all clusters
        // TODO: just let the exception happen, WTF is all this horseshit
        // afterTestRule.forceFailure();
        }
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) ZenDiscovery(org.elasticsearch.discovery.zen.ZenDiscovery) TestZenDiscovery(org.elasticsearch.test.discovery.TestZenDiscovery) Discovery(org.elasticsearch.discovery.Discovery) ZenDiscovery(org.elasticsearch.discovery.zen.ZenDiscovery) TestZenDiscovery(org.elasticsearch.test.discovery.TestZenDiscovery)

Aggregations

HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 Discovery (org.elasticsearch.discovery.Discovery)1 ZenDiscovery (org.elasticsearch.discovery.zen.ZenDiscovery)1 TestZenDiscovery (org.elasticsearch.test.discovery.TestZenDiscovery)1