use of com.hazelcast.core.HazelcastInstance in project neo4j by neo4j.
the class HazelcastClientTest method shouldSwallowNPEFromHazelcast.
@Test
public void shouldSwallowNPEFromHazelcast() throws Throwable {
// given
Endpoint endpoint = mock(Endpoint.class);
when(endpoint.getUuid()).thenReturn("12345");
HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
when(hazelcastInstance.getLocalEndpoint()).thenReturn(endpoint);
when(hazelcastInstance.getMap(anyString())).thenReturn(new HazelcastMap());
when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
doThrow(new NullPointerException("boom!!!")).when(hazelcastInstance).shutdown();
HazelcastConnector connector = mock(HazelcastConnector.class);
when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
HazelcastClient hazelcastClient = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
hazelcastClient.start();
jobScheduler.runJob();
// when
hazelcastClient.stop();
// then no NPE has been thrown
}
use of com.hazelcast.core.HazelcastInstance in project orientdb by orientechnologies.
the class HazelcastQueueThroughputTest method main.
public static void main(String[] args) throws InterruptedException {
final HazelcastInstance hz = Hazelcast.newHazelcastInstance();
final IQueue[] ring = new IQueue[QUEUE_RING_SIZE];
for (int q = 0; q < QUEUE_RING_SIZE; ++q) ring[q] = hz.getQueue("test" + q);
final long start = System.currentTimeMillis();
long lastLap = start;
Thread t = new Thread() {
long lastLap = start;
@Override
public void run() {
int senderQueueIndex = 0;
System.out.println((System.currentTimeMillis() - lastLap) + " Start receiving msgs");
for (int i = 1; i < TOTAL + 1; ++i) {
try {
if (senderQueueIndex >= QUEUE_RING_SIZE)
senderQueueIndex = 0;
Object msg = ring[senderQueueIndex++].take();
if (i % LAP == 0) {
final long lapTime = System.currentTimeMillis() - lastLap;
System.out.printf("<- messages %d/%d = %dms (%f msg/sec)\n", i, TOTAL, lapTime, ((float) LAP * 1000 / lapTime));
lastLap = System.currentTimeMillis();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
t.start();
int receiverQueueIndex = 0;
System.out.println((System.currentTimeMillis() - lastLap) + " Start sending msgs");
for (int i = 1; i < TOTAL + 1; ++i) {
if (receiverQueueIndex >= QUEUE_RING_SIZE)
receiverQueueIndex = 0;
ring[receiverQueueIndex++].offer(i);
if (i % LAP == 0) {
final long lapTime = System.currentTimeMillis() - lastLap;
System.out.printf("-> messages %d/%d = %dms (%f msg/sec)\n", i, TOTAL, lapTime, ((float) LAP * 1000 / lapTime));
lastLap = System.currentTimeMillis();
}
}
System.out.println((System.currentTimeMillis() - start) + " Finished sending msgs");
t.join();
System.out.println((System.currentTimeMillis() - start) + " Test finished");
}
use of com.hazelcast.core.HazelcastInstance in project orientdb by orientechnologies.
the class AbstractServerClusterTest method execute.
public void execute() throws Exception {
System.out.println("Starting test against " + serverInstance.size() + " server nodes...");
try {
startServers();
banner("Executing test...");
try {
executeTest();
} finally {
onAfterExecution();
}
} catch (Exception e) {
System.out.println("ERROR: ");
e.printStackTrace();
OLogManager.instance().flush();
throw e;
} finally {
banner("Test finished");
OLogManager.instance().flush();
banner("Shutting down " + serverInstance.size() + " nodes...");
for (ServerRun server : serverInstance) {
log("Shutting down node " + server.getServerId() + "...");
if (terminateAtShutdown)
server.terminateServer();
else
server.shutdownServer();
}
onTestEnded();
banner("Terminate HZ...");
for (HazelcastInstance in : Hazelcast.getAllHazelcastInstances()) {
if (terminateAtShutdown)
// TERMINATE (HARD SHUTDOWN)
in.getLifecycleService().terminate();
else
// SOFT SHUTDOWN
in.shutdown();
}
banner("Clean server directories...");
deleteServers();
}
}
use of com.hazelcast.core.HazelcastInstance in project orientdb by orientechnologies.
the class ServerRun method terminateServer.
public void terminateServer() {
if (server != null) {
try {
HazelcastInstance hz = ((OHazelcastPlugin) server.getDistributedManager()).getHazelcastInstance();
final Node node = getHazelcastNode(hz);
node.getConnectionManager().shutdown();
node.shutdown(true);
hz.getLifecycleService().terminate();
} catch (Exception e) {
// IGNORE IT
}
try {
server.shutdown();
} catch (Exception e) {
// IGNORE IT
}
}
closeStorages();
}
use of com.hazelcast.core.HazelcastInstance in project spring-boot by spring-projects.
the class CacheAutoConfigurationTests method hazelcastAsJCacheWithExistingHazelcastInstance.
@Test
public void hazelcastAsJCacheWithExistingHazelcastInstance() throws IOException {
String cachingProviderFqn = HazelcastCachingProvider.class.getName();
load(new Class[] { HazelcastAutoConfiguration.class, DefaultCacheConfiguration.class }, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn);
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
javax.cache.CacheManager jCacheManager = cacheManager.getCacheManager();
assertThat(jCacheManager).isInstanceOf(com.hazelcast.cache.HazelcastCacheManager.class);
assertThat(this.context.getBeansOfType(HazelcastInstance.class)).hasSize(1);
HazelcastInstance hazelcastInstance = this.context.getBean(HazelcastInstance.class);
assertThat(((com.hazelcast.cache.HazelcastCacheManager) jCacheManager).getHazelcastInstance()).isSameAs(hazelcastInstance);
assertThat(hazelcastInstance.getName()).isEqualTo("default-instance");
assertThat(Hazelcast.getAllHazelcastInstances()).hasSize(1);
}
Aggregations