Search in sources :

Example 21 with HazelcastInstance

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

the class ClientConsoleApp method main.

/**
     * Starts the test application. Loads the config from classpath hazelcast.xml,
     * if it fails to load, will use default config.
     *
     * @param args none
     * @throws Exception
     */
public static void main(String[] args) throws Exception {
    ClientConfig clientConfig;
    try {
        clientConfig = new XmlClientConfigBuilder().build();
    } catch (IllegalArgumentException e) {
        clientConfig = new ClientConfig();
    }
    final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    ClientConsoleApp clientConsoleApp = new ClientConsoleApp(client);
    clientConsoleApp.start(args);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 22 with HazelcastInstance

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

the class ClientMultiMapProxy method aggregate.

@Override
public <SuppliedValue, Result> Result aggregate(Supplier<K, V, SuppliedValue> supplier, Aggregation<K, SuppliedValue, Result> aggregation) {
    HazelcastInstance hazelcastInstance = getContext().getHazelcastInstance();
    JobTracker jobTracker = hazelcastInstance.getJobTracker("hz::aggregation-multimap-" + name);
    return aggregate(supplier, aggregation, jobTracker);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) JobTracker(com.hazelcast.mapreduce.JobTracker)

Example 23 with HazelcastInstance

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

the class ClientConnectionTest method testWithLegalAndIllegalAddressTogether.

@Test
public void testWithLegalAndIllegalAddressTogether() {
    String illegalAddress = randomString();
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
    ClientConfig config = new ClientConfig();
    config.setProperty(ClientProperty.SHUFFLE_MEMBER_LIST.getName(), "false");
    config.getNetworkConfig().addAddress(illegalAddress).addAddress("localhost");
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
    Collection<Client> connectedClients = server.getClientService().getConnectedClients();
    assertEquals(connectedClients.size(), 1);
    Client serverSideClientInfo = connectedClients.iterator().next();
    assertEquals(serverSideClientInfo.getUuid(), client.getLocalEndpoint().getUuid());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) Client(com.hazelcast.core.Client) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with HazelcastInstance

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

the class ClientConnectionTest method testAsyncConnectionCreationInAsyncMethods.

@Test
public void testAsyncConnectionCreationInAsyncMethods() throws ExecutionException, InterruptedException {
    hazelcastFactory.newHazelcastInstance();
    CountDownLatch countDownLatch = new CountDownLatch(1);
    ClientConfig config = new ClientConfig();
    WaitingCredentials credentials = new WaitingCredentials("dev", "dev-pass", countDownLatch);
    config.setCredentials(credentials);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
    final IExecutorService executorService = client.getExecutorService(randomString());
    credentials.waitFlag.set(true);
    final HazelcastInstance secondInstance = hazelcastFactory.newHazelcastInstance();
    final AtomicReference<Future> atomicReference = new AtomicReference<Future>();
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            Member secondMember = secondInstance.getCluster().getLocalMember();
            Future future = executorService.submitToMember(new DummySerializableCallable(), secondMember);
            atomicReference.set(future);
        }
    });
    thread.start();
    try {
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() throws Exception {
                assertNotNull(atomicReference.get());
            }
        }, 30);
    } finally {
        thread.interrupt();
        thread.join();
        countDownLatch.countDown();
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Future(java.util.concurrent.Future) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with HazelcastInstance

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

the class ClientConnectionTest method destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce.

@Test
public void destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce() {
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    final CountingConnectionRemoveListener listener = new CountingConnectionRemoveListener();
    connectionManager.addConnectionListener(listener);
    final Address serverAddress = new Address(server.getCluster().getLocalMember().getSocketAddress());
    final Connection connectionToServer = connectionManager.getConnection(serverAddress);
    final CountDownLatch isConnected = new CountDownLatch(1);
    clientImpl.getLifecycleService().addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            if (LifecycleEvent.LifecycleState.CLIENT_CONNECTED == event.getState()) {
                isConnected.countDown();
            }
        }
    });
    connectionToServer.close(null, null);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(isConnected.await(5, TimeUnit.SECONDS));
        }
    });
    connectionToServer.close(null, null);
    assertEquals("connection removed should be called only once", 1, listener.count.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) Connection(com.hazelcast.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) LifecycleEvent(com.hazelcast.core.LifecycleEvent) AssertTask(com.hazelcast.test.AssertTask) LifecycleListener(com.hazelcast.core.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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