diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinTests.java index 740ac2bfee392..d18cd9b9bdb56 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinTests.java @@ -121,6 +121,7 @@ private void setupFakeMasterServiceAndCoordinator(long term, ClusterState initia fakeThreadPool, deterministicTaskQueue::scheduleNow); setupMasterServiceAndCoordinator(term, initialState, fakeMasterService, fakeThreadPool, Randomness.get(), nodeHealthService); fakeMasterService.setClusterStatePublisher((clusterStatePublicationEvent, publishListener, ackListener) -> { + ClusterServiceUtils.setAllElapsedMillis(clusterStatePublicationEvent); coordinator.handlePublishRequest(new PublishRequest(clusterStatePublicationEvent.getNewState())); publishListener.onResponse(null); }); @@ -132,6 +133,7 @@ private void setupRealMasterServiceAndCoordinator(long term, ClusterState initia new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadPool); AtomicReference clusterStateRef = new AtomicReference<>(initialState); masterService.setClusterStatePublisher((clusterStatePublicationEvent, publishListener, ackListener) -> { + ClusterServiceUtils.setAllElapsedMillis(clusterStatePublicationEvent); clusterStateRef.set(clusterStatePublicationEvent.getNewState()); publishListener.onResponse(null); }); diff --git a/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java index a87815b2375e3..3b20eb7e8da46 100644 --- a/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java @@ -39,6 +39,7 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.core.Tuple; import org.elasticsearch.node.Node; +import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.MockLogAppender; import org.elasticsearch.test.junit.annotations.TestLogging; @@ -118,6 +119,7 @@ private MasterService createMasterService(boolean makeMaster) { final AtomicReference clusterStateRef = new AtomicReference<>(initialClusterState); masterService.setClusterStatePublisher((clusterStatePublicationEvent, publishListener, ackListener) -> { clusterStateRef.set(clusterStatePublicationEvent.getNewState()); + ClusterServiceUtils.setAllElapsedMillis(clusterStatePublicationEvent); publishListener.onResponse(null); }); masterService.setClusterStateSupplier(clusterStateRef::get); @@ -726,6 +728,7 @@ public void testLongClusterStateUpdateLogging() throws Exception { .blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).build(); final AtomicReference clusterStateRef = new AtomicReference<>(initialClusterState); masterService.setClusterStatePublisher((clusterStatePublicationEvent, publishListener, ackListener) -> { + ClusterServiceUtils.setAllElapsedMillis(clusterStatePublicationEvent); if (clusterStatePublicationEvent.getSummary().contains("test5")) { relativeTimeInMillis += MasterService.MASTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING.get(Settings.EMPTY).millis() + randomLongBetween(1, 1000000); @@ -894,7 +897,10 @@ public void testAcking() throws InterruptedException { .masterNodeId(node1.getId())) .blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).build(); final AtomicReference publisherRef = new AtomicReference<>(); - masterService.setClusterStatePublisher((e, pl, al) -> publisherRef.get().publish(e, pl, al)); + masterService.setClusterStatePublisher((e, pl, al) -> { + ClusterServiceUtils.setAllElapsedMillis(e); + publisherRef.get().publish(e, pl, al); + }); masterService.setClusterStateSupplier(() -> initialClusterState); masterService.start(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java b/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java index dae5dced378b6..656f8dbc96c10 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java @@ -12,6 +12,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.ClusterStatePublicationEvent; import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.NodeConnectionsService; import org.elasticsearch.cluster.block.ClusterBlocks; @@ -135,7 +136,8 @@ public void disconnectFromNodesExcept(DiscoveryNodes nodesToKeep) { } public static ClusterStatePublisher createClusterStatePublisher(ClusterApplier clusterApplier) { - return (clusterStatePublicationEvent, publishListener, ackListener) -> + return (clusterStatePublicationEvent, publishListener, ackListener) -> { + setAllElapsedMillis(clusterStatePublicationEvent); clusterApplier.onNewClusterState( "mock_publish_to_self[" + clusterStatePublicationEvent.getSummary() + "]", clusterStatePublicationEvent::getNewState, @@ -149,8 +151,8 @@ public void onSuccess(String source) { public void onFailure(String source, Exception e) { publishListener.onFailure(e); } - } - ); + }); + }; } public static ClusterService createClusterService(ClusterState initialState, ThreadPool threadPool) { @@ -169,4 +171,12 @@ public static void setState(ClusterService clusterService, ClusterState.Builder public static void setState(ClusterService clusterService, ClusterState clusterState) { setState(clusterService.getClusterApplierService(), clusterState); } + + public static void setAllElapsedMillis(ClusterStatePublicationEvent clusterStatePublicationEvent) { + clusterStatePublicationEvent.setPublicationContextConstructionElapsedMillis(0L); + clusterStatePublicationEvent.setPublicationCommitElapsedMillis(0L); + clusterStatePublicationEvent.setPublicationCompletionElapsedMillis(0L); + clusterStatePublicationEvent.setMasterApplyElapsedMillis(0L); + } + } diff --git a/test/framework/src/test/java/org/elasticsearch/cluster/service/FakeThreadPoolMasterServiceTests.java b/test/framework/src/test/java/org/elasticsearch/cluster/service/FakeThreadPoolMasterServiceTests.java index 033c6d07bcc84..fd9f66cab7852 100644 --- a/test/framework/src/test/java/org/elasticsearch/cluster/service/FakeThreadPoolMasterServiceTests.java +++ b/test/framework/src/test/java/org/elasticsearch/cluster/service/FakeThreadPoolMasterServiceTests.java @@ -18,6 +18,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -58,6 +59,7 @@ public void testFakeMasterService() { FakeThreadPoolMasterService masterService = new FakeThreadPoolMasterService("test_node","test", mockThreadPool, runnableTasks::add); masterService.setClusterStateSupplier(lastClusterStateRef::get); masterService.setClusterStatePublisher((clusterStatePublicationEvent, publishListener, ackListener) -> { + ClusterServiceUtils.setAllElapsedMillis(clusterStatePublicationEvent); lastClusterStateRef.set(clusterStatePublicationEvent.getNewState()); publishingCallback.set(publishListener); });