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();
}
}
}
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()]);
}
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();
}
}
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");
}
}
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();
}
Aggregations