Search in sources :

Example 6 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project camel by apache.

the class HazelcastConfigurationTest method testNamedInstance.

@Test
public void testNamedInstance() throws Exception {
    DefaultCamelContext context = null;
    try {
        String instanceName = UUID.randomUUID().toString();
        Config config = new Config();
        config.setInstanceName(instanceName);
        config.getNetworkConfig().setPort(6789);
        config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
        config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(true);
        config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
        Hazelcast.newHazelcastInstance(config);
        context = new DefaultCamelContext();
        context.start();
        HazelcastDefaultEndpoint endpoint1 = getHzEndpoint(context, "hazelcast:map:my-cache-1?hazelcastInstanceName=" + instanceName);
        HazelcastDefaultEndpoint endpoint2 = getHzEndpoint(context, "hazelcast:map:my-cache-2?hazelcastInstanceName=" + instanceName);
        Assert.assertNotNull(endpoint1.getHazelcastInstance());
        Assert.assertNotNull(endpoint2.getHazelcastInstance());
        Assert.assertTrue(endpoint1.getHazelcastInstance() == endpoint2.getHazelcastInstance());
        HazelcastComponent component = context.getComponent("hazelcast", HazelcastComponent.class);
        Assert.assertNull(component.getHazelcastInstance());
        for (HazelcastDefaultEndpoint endpoint : Arrays.asList(endpoint1, endpoint2)) {
            HazelcastInstance hz = endpoint.getHazelcastInstance();
            Assert.assertEquals(instanceName, hz.getName());
            Assert.assertFalse(hz.getConfig().getNetworkConfig().getJoin().getAwsConfig().isEnabled());
            Assert.assertTrue(hz.getConfig().getNetworkConfig().getJoin().getMulticastConfig().isEnabled());
            Assert.assertFalse(hz.getConfig().getNetworkConfig().getJoin().getTcpIpConfig().isEnabled());
            Assert.assertEquals(6789, hz.getConfig().getNetworkConfig().getPort());
        }
    } finally {
        if (context != null) {
            context.stop();
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 7 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project cas by apereo.

the class HazelcastMonitor method getStatistics.

@Override
protected CacheStatistics[] getStatistics() {
    final List<CacheStatistics> statsList = new ArrayList<>();
    final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
    LOGGER.debug("Locating hazelcast instance [{}]...", hz.getCluster().getInstanceName());
    final HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(hz.getCluster().getInstanceName());
    instance.getConfig().getMapConfigs().keySet().forEach(key -> {
        final IMap map = instance.getMap(key);
        LOGGER.debug("Starting to collect hazelcast statistics for map [{}] identified by key [{}]...", map, key);
        statsList.add(new HazelcastStatistics(map, hz.getCluster().getMembers().size()));
    });
    return statsList.toArray(new CacheStatistics[statsList.size()]);
}
Also used : HazelcastProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ArrayList(java.util.ArrayList)

Example 8 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance 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 9 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project sonarqube by SonarSource.

the class AppStateClusterImplTest method registerSonarQubeVersion_publishes_version_on_first_call.

@Test
public void registerSonarQubeVersion_publishes_version_on_first_call() {
    TestAppSettings settings = newClusterSettings();
    try (AppStateClusterImpl appStateCluster = new AppStateClusterImpl(settings)) {
        appStateCluster.registerSonarQubeVersion("6.4.1.5");
        HazelcastInstance hzInstance = createHazelcastClient(appStateCluster);
        assertThat(hzInstance.getAtomicReference(SONARQUBE_VERSION).get()).isNotNull().isInstanceOf(String.class).isEqualTo("6.4.1.5");
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestAppSettings(org.sonar.application.config.TestAppSettings) Test(org.junit.Test)

Example 10 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project neo4j by neo4j.

the class HazelcastClientTest method shouldNotReconnectWhileHazelcastRemainsAvailable.

@Test
public void shouldNotReconnectWhileHazelcastRemainsAvailable() throws Throwable {
    // given
    HazelcastConnector connector = mock(HazelcastConnector.class);
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient client = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
    when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
    when(hazelcastInstance.getSet(anyString())).thenReturn(new HazelcastSet());
    when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
    when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
    com.hazelcast.core.Cluster cluster = mock(Cluster.class);
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    Set<Member> members = asSet(makeMember(1), makeMember(2));
    when(cluster.getMembers()).thenReturn(members);
    // when
    client.start();
    jobScheduler.runJob();
    CoreTopology topology;
    for (int i = 0; i < 5; i++) {
        topology = client.coreServers();
        assertEquals(members.size(), topology.members().size());
    }
    // then
    verify(connector, times(1)).connectToHazelcast();
}
Also used : OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) Endpoint(com.hazelcast.core.Endpoint) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)2077 Test (org.junit.Test)1684 QuickTest (com.hazelcast.test.annotation.QuickTest)1466 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1389 Config (com.hazelcast.config.Config)815 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)665 AssertTask (com.hazelcast.test.AssertTask)263 MapConfig (com.hazelcast.config.MapConfig)254 CountDownLatch (java.util.concurrent.CountDownLatch)251 NightlyTest (com.hazelcast.test.annotation.NightlyTest)230 MapStoreConfig (com.hazelcast.config.MapStoreConfig)169 IMap (com.hazelcast.core.IMap)145 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)144 ClientConfig (com.hazelcast.client.config.ClientConfig)137 Before (org.junit.Before)111 NearCacheConfig (com.hazelcast.config.NearCacheConfig)106 Member (com.hazelcast.core.Member)96 Map (java.util.Map)96 SlowTest (com.hazelcast.test.annotation.SlowTest)94 SqlPredicate (com.hazelcast.query.SqlPredicate)83