diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-05 10:38:52 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-13 15:50:53 +0200 |
commit | 562cc41a1db2c52337f2dc3ccf6e11387a68bc4f (patch) | |
tree | 2bad1a08dc03b16275d5ce0d442d59b14d613027 /server/sonar-cluster | |
parent | 4b0d1ba16eccdc9e79154f31549d437ad1be6e0b (diff) | |
download | sonarqube-562cc41a1db2c52337f2dc3ccf6e11387a68bc4f.tar.gz sonarqube-562cc41a1db2c52337f2dc3ccf6e11387a68bc4f.zip |
SONAR-9741 add HazelcastClient#getClusterTime
Diffstat (limited to 'server/sonar-cluster')
3 files changed, 24 insertions, 0 deletions
diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClient.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClient.java index 03689945860..0351deb2a69 100644 --- a/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClient.java +++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastClient.java @@ -67,4 +67,9 @@ public interface HazelcastClient { * Gets lock among the cluster, identified by name */ Lock getLock(String name); + + /** + * Retrieves the cluster time which is (alsmost) identical on all members of the cluster. + */ + long getClusterTime(); } diff --git a/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastLocalClient.java b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastLocalClient.java index 4e31de83ca8..c6e137e0374 100644 --- a/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastLocalClient.java +++ b/server/sonar-cluster/src/main/java/org/sonar/cluster/localclient/HazelcastLocalClient.java @@ -109,6 +109,11 @@ public class HazelcastLocalClient implements Startable, HazelcastClient { } @Override + public long getClusterTime() { + return hzInstance.getCluster().getClusterTime(); + } + + @Override public void start() { this.hzInstance = com.hazelcast.client.HazelcastClient.newHazelcastClient(hzConfig); } diff --git a/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastLocalClientTest.java b/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastLocalClientTest.java index 084941a7d0c..63727d487ef 100644 --- a/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastLocalClientTest.java +++ b/server/sonar-cluster/src/test/java/org/sonar/cluster/localclient/HazelcastLocalClientTest.java @@ -56,6 +56,7 @@ import org.sonar.api.config.internal.MapSettings; import org.sonar.cluster.internal.HazelcastTestHelper; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.within; import static org.assertj.core.data.MapEntry.entry; import static org.sonar.cluster.ClusterProperties.CLUSTER_ENABLED; import static org.sonar.cluster.ClusterProperties.CLUSTER_LOCALENDPOINT; @@ -259,6 +260,19 @@ public class HazelcastLocalClientTest { e -> Assertions.assertThat(e.getLoggerName()).startsWith("com.hazelcast")); } + @Test + public void getClusterTime_returns_time_of_cluster() { + try { + hzClient.start(); + + HazelcastClientInstanceImpl realClient = ((HazelcastClientProxy) hzClient.hzInstance).client; + assertThat(hzClient.getClusterTime()) + .isCloseTo(realClient.getCluster().getClusterTime(), within(1000L)); + } finally { + hzClient.stop(); + } + } + private class ClientListenerImpl implements ClientListener { CountDownLatch counter = new CountDownLatch(1); |