Search in sources :

Example 11 with ServiceConfig

use of com.hazelcast.config.ServiceConfig in project hazelcast by hazelcast.

the class DistributedObjectTest method testInitialization_whenEachNodeExecutesPostJoinOperations.

@Test
public void testInitialization_whenEachNodeExecutesPostJoinOperations() {
    int nodeCount = 4;
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    Config config = new Config();
    config.getServicesConfig().addServiceConfig(new ServiceConfig().setImplementation(new TestInitializingObjectService()).setEnabled(true).setName(TestInitializingObjectService.NAME));
    String serviceName = TestInitializingObjectService.NAME;
    String objectName = "test-object";
    HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < instances.length; i++) {
        instances[i] = factory.newHazelcastInstance(config);
        instances[i].getDistributedObject(serviceName, objectName);
    }
    for (int i = 0; i < nodeCount; i++) {
        Node node = TestUtil.getNode(instances[i]);
        ProxyServiceImpl proxyService = (ProxyServiceImpl) node.nodeEngine.getProxyService();
        Operation postJoinOperation = proxyService.getPostJoinOperation();
        for (int j = 0; j < nodeCount; j++) {
            if (i == j)
                continue;
            Node node2 = TestUtil.getNode(instances[j]);
            node.nodeEngine.getOperationService().send(postJoinOperation, node2.address);
        }
    }
    for (HazelcastInstance instance : instances) {
        TestInitializingObject obj = instance.getDistributedObject(serviceName, objectName);
        assertTrue(obj.init.get());
        assertFalse(obj.error);
    }
}
Also used : ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) Node(com.hazelcast.instance.Node) Operation(com.hazelcast.spi.Operation) ProxyServiceImpl(com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with ServiceConfig

use of com.hazelcast.config.ServiceConfig in project hazelcast by hazelcast.

the class DistributedObjectTest method testFailingInitialization.

@Test(expected = HazelcastException.class)
public void testFailingInitialization() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    Config config = new Config();
    config.getServicesConfig().addServiceConfig(new ServiceConfig().setImplementation(new FailingInitializingObjectService()).setEnabled(true).setName(FailingInitializingObjectService.NAME));
    String serviceName = FailingInitializingObjectService.NAME;
    String objectName = "test-object";
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    hz.getDistributedObject(serviceName, objectName);
}
Also used : ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with ServiceConfig

use of com.hazelcast.config.ServiceConfig in project hazelcast by hazelcast.

the class DistributedObjectTest method testFailingInitialization_whenGetProxyCalledByMultipleThreads.

@Test
public void testFailingInitialization_whenGetProxyCalledByMultipleThreads() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    Config config = new Config();
    config.getServicesConfig().addServiceConfig(new ServiceConfig().setImplementation(new FailingInitializingObjectService()).setEnabled(true).setName(FailingInitializingObjectService.NAME));
    final String serviceName = FailingInitializingObjectService.NAME;
    final String objectName = "test-object";
    final HazelcastInstance hz = factory.newHazelcastInstance(config);
    int threads = 3;
    final CountDownLatch latch = new CountDownLatch(threads);
    for (int i = 0; i < threads; i++) {
        new Thread() {

            public void run() {
                for (int j = 0; j < 1000; j++) {
                    try {
                        hz.getDistributedObject(serviceName, objectName);
                        fail("Proxy creation should fail!");
                    } catch (HazelcastException expected) {
                        ignore(expected);
                    }
                    LockSupport.parkNanos(1);
                }
                latch.countDown();
            }
        }.start();
    }
    assertOpenEventually(latch, 30);
}
Also used : ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with ServiceConfig

use of com.hazelcast.config.ServiceConfig in project hazelcast by hazelcast.

the class DistributedObjectTest method testCustomObject.

@Test
public void testCustomObject() {
    Config config = new Config();
    config.getServicesConfig().addServiceConfig(new ServiceConfig().setImplementation(new TestInitializingObjectService()).setEnabled(true).setName(TestInitializingObjectService.NAME));
    HazelcastInstance instance = createHazelcastInstance(config);
    TestInitializingObject object = instance.getDistributedObject(TestInitializingObjectService.NAME, "test-object");
    test(instance, object);
}
Also used : ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with ServiceConfig

use of com.hazelcast.config.ServiceConfig in project hazelcast by hazelcast.

the class MigrationAwareServiceEventTest method migrationCommitEvents_shouldBeEqual_onSource_and_onDestination.

@Test
public void migrationCommitEvents_shouldBeEqual_onSource_and_onDestination() throws Exception {
    Config config = new Config();
    final MigrationEventCounterService counter = new MigrationEventCounterService();
    ServiceConfig serviceConfig = new ServiceConfig().setEnabled(true).setName("event-counter").setImplementation(counter);
    config.getServicesConfig().addServiceConfig(serviceConfig);
    final HazelcastInstance hz = factory.newHazelcastInstance(config);
    warmUpPartitions(hz);
    final AssertTask assertTask = new AssertTask() {

        final InternalPartitionService partitionService = getNode(hz).getPartitionService();

        @Override
        public void run() throws Exception {
            assertEquals(0, partitionService.getMigrationQueueSize());
            final int source = counter.sourceCommits.get();
            final int destination = counter.destinationCommits.get();
            assertEquals(source, destination);
        }
    };
    factory.newHazelcastInstance(config);
    assertTrueEventually(assertTask);
    factory.newHazelcastInstance(config);
    assertTrueEventually(assertTask);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) AssertTask(com.hazelcast.test.AssertTask) MigrationEndpoint(com.hazelcast.spi.partition.MigrationEndpoint) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ServiceConfig (com.hazelcast.config.ServiceConfig)17 Config (com.hazelcast.config.Config)15 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Before (org.junit.Before)3 ServicesConfig (com.hazelcast.config.ServicesConfig)2 Operation (com.hazelcast.spi.Operation)2 AssertTask (com.hazelcast.test.AssertTask)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ProxyFactoryConfig (com.hazelcast.client.config.ProxyFactoryConfig)1 Node (com.hazelcast.instance.Node)1 TestPutOperation (com.hazelcast.internal.partition.service.TestPutOperation)1 NodeEngine (com.hazelcast.spi.NodeEngine)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 ProxyServiceImpl (com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl)1 MigrationEndpoint (com.hazelcast.spi.partition.MigrationEndpoint)1 UnknownHostException (java.net.UnknownHostException)1