Skip to content

Commit 4fd6c27

Browse files
andrrossbrusic
authored andcommitted
Remove empty if/try-finally in base integ test class (opensearch-project#9098)
The [commit to comment out `forceFailure()`][1] was done about 8 years ago so I don't think we'll be bringing it back. Also this makes the code base a slightly friendlier place :) [1]: opensearch-project@e5a699f Signed-off-by: Andrew Ross <andrross@amazon.com> Signed-off-by: Ivan Brusic <ivan.brusic@flocksafety.com>
1 parent b22442b commit 4fd6c27

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java

+21-31
Original file line numberDiff line numberDiff line change
@@ -590,44 +590,34 @@ private static void clearClusters() throws Exception {
590590
}
591591

592592
private void afterInternal(boolean afterClass) throws Exception {
593-
boolean success = false;
593+
final Scope currentClusterScope = getCurrentClusterScope();
594+
if (isInternalCluster()) {
595+
internalCluster().clearDisruptionScheme();
596+
}
594597
try {
595-
final Scope currentClusterScope = getCurrentClusterScope();
596-
if (isInternalCluster()) {
597-
internalCluster().clearDisruptionScheme();
598-
}
599-
try {
600-
if (cluster() != null) {
601-
if (currentClusterScope != Scope.TEST) {
602-
Metadata metadata = client().admin().cluster().prepareState().execute().actionGet().getState().getMetadata();
598+
if (cluster() != null) {
599+
if (currentClusterScope != Scope.TEST) {
600+
Metadata metadata = client().admin().cluster().prepareState().execute().actionGet().getState().getMetadata();
603601

604-
final Set<String> persistentKeys = new HashSet<>(metadata.persistentSettings().keySet());
605-
assertThat("test leaves persistent cluster metadata behind", persistentKeys, empty());
602+
final Set<String> persistentKeys = new HashSet<>(metadata.persistentSettings().keySet());
603+
assertThat("test leaves persistent cluster metadata behind", persistentKeys, empty());
606604

607-
final Set<String> transientKeys = new HashSet<>(metadata.transientSettings().keySet());
608-
assertThat("test leaves transient cluster metadata behind", transientKeys, empty());
609-
}
610-
ensureClusterSizeConsistency();
611-
ensureClusterStateConsistency();
612-
ensureClusterStateCanBeReadByNodeTool();
613-
beforeIndexDeletion();
614-
cluster().wipe(excludeTemplates()); // wipe after to make sure we fail in the test that didn't ack the delete
615-
if (afterClass || currentClusterScope == Scope.TEST) {
616-
cluster().close();
617-
}
618-
cluster().assertAfterTest();
605+
final Set<String> transientKeys = new HashSet<>(metadata.transientSettings().keySet());
606+
assertThat("test leaves transient cluster metadata behind", transientKeys, empty());
619607
}
620-
} finally {
621-
if (currentClusterScope == Scope.TEST) {
622-
clearClusters(); // it is ok to leave persistent / transient cluster state behind if scope is TEST
608+
ensureClusterSizeConsistency();
609+
ensureClusterStateConsistency();
610+
ensureClusterStateCanBeReadByNodeTool();
611+
beforeIndexDeletion();
612+
cluster().wipe(excludeTemplates()); // wipe after to make sure we fail in the test that didn't ack the delete
613+
if (afterClass || currentClusterScope == Scope.TEST) {
614+
cluster().close();
623615
}
616+
cluster().assertAfterTest();
624617
}
625-
success = true;
626618
} finally {
627-
if (!success) {
628-
// if we failed here that means that something broke horribly so we should clear all clusters
629-
// TODO: just let the exception happen, WTF is all this horseshit
630-
// afterTestRule.forceFailure();
619+
if (currentClusterScope == Scope.TEST) {
620+
clearClusters(); // it is ok to leave persistent / transient cluster state behind if scope is TEST
631621
}
632622
}
633623
}

0 commit comments

Comments
 (0)