mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-09 06:25:07 +00:00
Fix testDataOnlyNodePersistence (#56893)
This test failed if all 1000 top-level `rarely()` calls in the loop returned `false`, because then we would never set the term of the persisted state. This commit fixes this by adding an earlier call to `persistedState#setCurrentTerm`. It also changes the test to clean up the threadpools it starts whether it passes or fails.
This commit is contained in:
parent
74554f1ae8
commit
64280b489b
@ -49,6 +49,7 @@ import org.elasticsearch.threadpool.TestThreadPool;
|
|||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.IOError;
|
import java.io.IOError;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -328,13 +329,18 @@ public class GatewayMetaStatePersistedStateTests extends ESTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testDataOnlyNodePersistence() throws Exception {
|
public void testDataOnlyNodePersistence() throws Exception {
|
||||||
|
final List<Closeable> cleanup = new ArrayList<>(2);
|
||||||
|
|
||||||
|
try {
|
||||||
DiscoveryNode localNode = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Collections.emptyMap(),
|
DiscoveryNode localNode = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Collections.emptyMap(),
|
||||||
Sets.newHashSet(DiscoveryNodeRole.DATA_ROLE), Version.CURRENT);
|
Sets.newHashSet(DiscoveryNodeRole.DATA_ROLE), Version.CURRENT);
|
||||||
Settings settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName.value()).put(
|
Settings settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName.value()).put(
|
||||||
Node.NODE_MASTER_SETTING.getKey(), false).put(Node.NODE_NAME_SETTING.getKey(), "test").build();
|
Node.NODE_MASTER_SETTING.getKey(), false).put(Node.NODE_NAME_SETTING.getKey(), "test").build();
|
||||||
final MockGatewayMetaState gateway = new MockGatewayMetaState(localNode);
|
final MockGatewayMetaState gateway = new MockGatewayMetaState(localNode);
|
||||||
|
cleanup.add(gateway);
|
||||||
final TransportService transportService = mock(TransportService.class);
|
final TransportService transportService = mock(TransportService.class);
|
||||||
TestThreadPool threadPool = new TestThreadPool("testMarkAcceptedConfigAsCommittedOnDataOnlyNode");
|
TestThreadPool threadPool = new TestThreadPool("testMarkAcceptedConfigAsCommittedOnDataOnlyNode");
|
||||||
|
cleanup.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS));
|
||||||
when(transportService.getThreadPool()).thenReturn(threadPool);
|
when(transportService.getThreadPool()).thenReturn(threadPool);
|
||||||
ClusterService clusterService = mock(ClusterService.class);
|
ClusterService clusterService = mock(ClusterService.class);
|
||||||
when(clusterService.getClusterSettings()).thenReturn(
|
when(clusterService.getClusterSettings()).thenReturn(
|
||||||
@ -356,6 +362,7 @@ public class GatewayMetaStatePersistedStateTests extends ESTestCase {
|
|||||||
ClusterState state = createClusterState(randomNonNegativeLong(),
|
ClusterState state = createClusterState(randomNonNegativeLong(),
|
||||||
Metadata.builder().coordinationMetadata(coordinationMetadata)
|
Metadata.builder().coordinationMetadata(coordinationMetadata)
|
||||||
.clusterUUID(randomAlphaOfLength(10)).build());
|
.clusterUUID(randomAlphaOfLength(10)).build());
|
||||||
|
persistedState.setCurrentTerm(state.term());
|
||||||
persistedState.setLastAcceptedState(state);
|
persistedState.setLastAcceptedState(state);
|
||||||
assertBusy(() -> assertTrue(gateway.allPendingAsyncStatesWritten()));
|
assertBusy(() -> assertTrue(gateway.allPendingAsyncStatesWritten()));
|
||||||
|
|
||||||
@ -408,6 +415,7 @@ public class GatewayMetaStatePersistedStateTests extends ESTestCase {
|
|||||||
assertBusy(() -> assertTrue(gateway.allPendingAsyncStatesWritten()));
|
assertBusy(() -> assertTrue(gateway.allPendingAsyncStatesWritten()));
|
||||||
|
|
||||||
gateway.close();
|
gateway.close();
|
||||||
|
assertTrue(cleanup.remove(gateway));
|
||||||
|
|
||||||
try (CoordinationState.PersistedState reloadedPersistedState = newGatewayPersistedState()) {
|
try (CoordinationState.PersistedState reloadedPersistedState = newGatewayPersistedState()) {
|
||||||
assertEquals(currentTerm, reloadedPersistedState.getCurrentTerm());
|
assertEquals(currentTerm, reloadedPersistedState.getCurrentTerm());
|
||||||
@ -415,8 +423,9 @@ public class GatewayMetaStatePersistedStateTests extends ESTestCase {
|
|||||||
reloadedPersistedState.getLastAcceptedState());
|
reloadedPersistedState.getLastAcceptedState());
|
||||||
assertNotNull(reloadedPersistedState.getLastAcceptedState().metadata().index(indexName));
|
assertNotNull(reloadedPersistedState.getLastAcceptedState().metadata().index(indexName));
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
|
IOUtils.close(cleanup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStatePersistenceWithIOIssues() throws IOException {
|
public void testStatePersistenceWithIOIssues() throws IOException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user