use of org.sonar.application.AppStateListener in project sonarqube by SonarSource.
the class AppStateClusterImplTest method simulate_network_cluster.
@Test
public void simulate_network_cluster() throws InterruptedException {
TestAppSettings settings = newClusterSettings();
settings.set(ProcessProperties.CLUSTER_NETWORK_INTERFACES, InetAddress.getLoopbackAddress().getHostAddress());
AppStateListener listener = mock(AppStateListener.class);
try (AppStateClusterImpl appStateCluster = new AppStateClusterImpl(settings)) {
appStateCluster.addListener(listener);
HazelcastInstance hzInstance = createHazelcastClient(appStateCluster);
String uuid = UUID.randomUUID().toString();
ReplicatedMap<ClusterProcess, Boolean> replicatedMap = hzInstance.getReplicatedMap(OPERATIONAL_PROCESSES);
// process is not up yet --> no events are sent to listeners
replicatedMap.put(new ClusterProcess(uuid, ProcessId.ELASTICSEARCH), Boolean.FALSE);
// process is up yet --> notify listeners
replicatedMap.replace(new ClusterProcess(uuid, ProcessId.ELASTICSEARCH), Boolean.TRUE);
// should be called only once
verify(listener, timeout(20_000)).onAppStateOperational(ProcessId.ELASTICSEARCH);
verifyNoMoreInteractions(listener);
hzInstance.shutdown();
}
}
use of org.sonar.application.AppStateListener in project sonarqube by SonarSource.
the class AppStateClusterImplTest method test_listeners.
@Test
public void test_listeners() throws InterruptedException {
AppStateListener listener = mock(AppStateListener.class);
try (AppStateClusterImpl underTest = new AppStateClusterImpl(newClusterSettings())) {
underTest.addListener(listener);
underTest.setOperational(ProcessId.ELASTICSEARCH);
verify(listener, timeout(20_000)).onAppStateOperational(ProcessId.ELASTICSEARCH);
assertThat(underTest.isOperational(ProcessId.ELASTICSEARCH, true)).isEqualTo(true);
assertThat(underTest.isOperational(ProcessId.APP, true)).isEqualTo(false);
assertThat(underTest.isOperational(ProcessId.WEB_SERVER, true)).isEqualTo(false);
assertThat(underTest.isOperational(ProcessId.COMPUTE_ENGINE, true)).isEqualTo(false);
}
}
Aggregations