Fix MasterServiceTests.testClusterStateUpdateLogging
This changes the test to not use a `CountDownlatch`, instead adding an assertion
for the final logging message and waiting until the `MockAppender` has seen it
before proceeding.
Related to
Resolves
@@ -325,11 +325,16 @@ public class MasterServiceTests extends ESTestCase {
MasterService.class.getCanonicalName(),
Level.DEBUG,
"*processing [test3]: took [3s] done publishing updated cluster state (version: *, uuid: *)"));
+ mockAppender.addExpectation(
+ new MockLogAppender.SeenEventExpectation(
+ "test4",
+ MasterService.class.getCanonicalName(),
+ Level.DEBUG,
+ "*processing [test4]: took [0s] no change in cluster state"));
Logger clusterLogger = LogManager.getLogger(MasterService.class);
Loggers.addAppender(clusterLogger, mockAppender);
try {
- final CountDownLatch latch = new CountDownLatch(4);
masterService.currentTimeOverride = System.nanoTime();
masterService.submitStateUpdateTask("test1", new ClusterStateUpdateTask() {
@Override
@@ -339,9 +344,7 @@ public class MasterServiceTests extends ESTestCase {
}
@Override
- public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
- latch.countDown();
- }
+ public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }
@Override
public void onFailure(String source, Exception e) {
@@ -361,9 +364,7 @@ public class MasterServiceTests extends ESTestCase {
}
@Override
- public void onFailure(String source, Exception e) {
- latch.countDown();
- }
+ public void onFailure(String source, Exception e) { }
});
masterService.submitStateUpdateTask("test3", new ClusterStateUpdateTask() {
@Override
@@ -373,9 +374,7 @@ public class MasterServiceTests extends ESTestCase {
}
@Override
- public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
- latch.countDown();
- }
+ public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }
@Override
public void onFailure(String source, Exception e) {
@@ -391,21 +390,18 @@ public class MasterServiceTests extends ESTestCase {
}
@Override
- public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
- latch.countDown();
- }
+ public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }
@Override
public void onFailure(String source, Exception e) {
fail();
}
});
- latch.await();
+ assertBusy(mockAppender::assertAllExpectationsMatched);
} finally {
Loggers.removeAppender(clusterLogger, mockAppender);
mockAppender.stop();
}
- mockAppender.assertAllExpectationsMatched();
}
public void testClusterStateBatchedUpdates() throws BrokenBarrierException, InterruptedException {
