Search in sources :

Example 11 with HazelcastInstance

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
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Endpoint(com.hazelcast.core.Endpoint) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) Test(org.junit.Test)

Example 12 with HazelcastInstance

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");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IQueue(com.hazelcast.core.IQueue)

Example 13 with HazelcastInstance

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();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) OTimeoutException(com.orientechnologies.common.concur.OTimeoutException) IOException(java.io.IOException)

Example 14 with HazelcastInstance

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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) IOException(java.io.IOException)

Example 15 with HazelcastInstance

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);
}
Also used : HazelcastCacheManager(com.hazelcast.spring.cache.HazelcastCacheManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) 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