Search in sources :

Example 1 with AppStateListener

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();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AppStateListener(org.sonar.application.AppStateListener) TestAppSettings(org.sonar.application.config.TestAppSettings) Test(org.junit.Test)

Example 2 with AppStateListener

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);
    }
}
Also used : AppStateListener(org.sonar.application.AppStateListener) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 AppStateListener (org.sonar.application.AppStateListener)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 TestAppSettings (org.sonar.application.config.TestAppSettings)1