test(controller): try to fix flaky test

This commit is contained in:
TheR1sing3un
2023-03-12 22:41:31 +08:00
committed by rongtong
parent 506a8a9037
commit 600d873fba
3 changed files with 14 additions and 4 deletions
@@ -140,6 +140,7 @@ public class ReplicasManager {
}
public void start() {
this.state = State.INITIAL;
updateControllerAddr();
scanAvailableControllerAddresses();
this.scheduledService.scheduleAtFixedRate(this::updateControllerAddr, 2 * 60 * 1000, 2 * 60 * 1000, TimeUnit.MILLISECONDS);
@@ -165,6 +166,7 @@ public class ReplicasManager {
}
private boolean startBasicService() {
if (this.state == State.SHUTDOWN) return false;
if (this.state == State.INITIAL) {
if (schedulingSyncControllerMetadata()) {
this.state = State.FIRST_TIME_SYNC_CONTROLLER_METADATA_DONE;
@@ -219,8 +221,9 @@ public class ReplicasManager {
public void shutdown() {
this.state = State.SHUTDOWN;
this.registerState = RegisterState.INITIAL;
this.executorService.shutdown();
this.scheduledService.shutdown();
this.executorService.shutdownNow();
this.scheduledService.shutdownNow();
this.scanExecutor.shutdownNow();
}
public synchronized void changeBrokerRole(final Long newMasterBrokerId, final String newMasterAddress, final Integer newMasterEpoch,
@@ -437,6 +440,7 @@ public class ReplicasManager {
this.tempBrokerMetadata.clear();
// back to the first step
this.registerState = RegisterState.INITIAL;
LOGGER.info("Register state change to: {}", this.registerState);
return false;
}
if (!createMetadataFileAndDeleteTemp()) {
@@ -132,6 +132,7 @@ public class ReplicasManagerRegisterTest {
checkMetadataFile(replicasManager0.getBrokerMetadata(), 1L);
Assert.assertFalse(replicasManager0.getTempBrokerMetadata().isLoaded());
Assert.assertFalse(replicasManager0.getTempBrokerMetadata().fileExists());
replicasManager0.shutdown();
}
@Test
@@ -159,6 +160,7 @@ public class ReplicasManagerRegisterTest {
replicasManagerRestart.start();
Assert.assertEquals(ReplicasManager.RegisterState.CREATE_METADATA_FILE_DONE, replicasManagerRestart.getRegisterState());
mockedBrokerController.getBrokerConfig().setBrokerName(BROKER_NAME);
replicasManagerRestart.shutdown();
// change cluster name in broker config
mockedBrokerController.getBrokerConfig().setBrokerClusterName(CLUSTER_NAME + "1");
@@ -166,6 +168,7 @@ public class ReplicasManagerRegisterTest {
replicasManagerRestart.start();
Assert.assertEquals(ReplicasManager.RegisterState.CREATE_METADATA_FILE_DONE, replicasManagerRestart.getRegisterState());
mockedBrokerController.getBrokerConfig().setBrokerClusterName(CLUSTER_NAME);
replicasManagerRestart.shutdown();
}
@Test
@@ -180,6 +183,7 @@ public class ReplicasManagerRegisterTest {
Assert.assertFalse(replicasManager.getTempBrokerMetadata().fileExists());
Assert.assertFalse(replicasManager.getBrokerMetadata().fileExists());
Assert.assertNull(replicasManager.getBrokerControllerId());
replicasManager.shutdown();
}
@Test
@@ -199,6 +203,7 @@ public class ReplicasManagerRegisterTest {
Assert.assertFalse(spyReplicasManager.getTempBrokerMetadata().fileExists());
Assert.assertFalse(spyReplicasManager.getBrokerMetadata().fileExists());
Assert.assertNull(spyReplicasManager.getBrokerControllerId());
spyReplicasManager.shutdown();
}
@Test
@@ -261,7 +266,7 @@ public class ReplicasManagerRegisterTest {
Assert.assertTrue(replicasManagerNew.getBrokerMetadata().isLoaded());
Assert.assertEquals(1L, replicasManagerNew.getBrokerMetadata().getBrokerId().longValue());
Assert.assertEquals(1L, replicasManagerNew.getBrokerControllerId().longValue());
replicasManagerNew.shutdown();
}
@Test
@@ -313,6 +318,7 @@ public class ReplicasManagerRegisterTest {
Assert.assertTrue(replicasManagerNew.getBrokerMetadata().isLoaded());
Assert.assertEquals(1L, replicasManagerNew.getBrokerMetadata().getBrokerId().longValue());
Assert.assertEquals(1L, replicasManagerNew.getBrokerControllerId().longValue());
replicasManagerNew.shutdown();
}
@@ -160,7 +160,7 @@ public class ControllerManagerTest {
final String brokerName, final Long brokerId, final RemotingClient client) throws Exception {
final ElectMasterRequestHeader requestHeader = ElectMasterRequestHeader.ofBrokerTrigger(clusterName, brokerName, brokerId);
final RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CONTROLLER_ELECT_MASTER, requestHeader);
RemotingCommand response = client.invokeSync(controllerAddress, request, 3000);
RemotingCommand response = client.invokeSync(controllerAddress, request, 10000);
assertNotNull(response);
return response;
}