Search in sources :

Example 21 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();
    ConfigAccessor.getServicesConfig(config).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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with ServiceConfig

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

the class DistributedObjectTest method testInitialization.

@Test
public void testInitialization() {
    int nodeCount = 4;
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    Config config = new Config();
    ConfigAccessor.getServicesConfig(config).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);
        TestInitializingObject obj2 = instances[i].getDistributedObject(serviceName, objectName);
        assertTrue(obj2.init.get());
        assertFalse(obj2.error);
    }
}
Also used : ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with ServiceConfig

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

the class DistributedObjectTest method testProxyCreation_whenLocalOnly.

@Test
public void testProxyCreation_whenLocalOnly() {
    int nodeCount = 4;
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    Config config = new Config();
    ConfigAccessor.getServicesConfig(config).addServiceConfig(new ServiceConfig().setImplementation(new TestInitializingObjectService()).setEnabled(true).setName(TestInitializingObjectService.NAME));
    String serviceName = TestInitializingObjectService.NAME;
    String objectName = "test-object";
    HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    ProxyRegistry[] registries = new ProxyRegistry[nodeCount];
    for (int i = 0; i < instances.length; i++) {
        instances[i] = factory.newHazelcastInstance(config);
        NodeEngine nodeEngine = getNodeEngineImpl(instances[i]);
        ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
        registries[i] = proxyService.getOrCreateRegistry(serviceName);
    }
    for (int i = 0; i < instances.length; i++) {
        NodeEngine nodeEngine = getNodeEngineImpl(instances[i]);
        UUID source = nodeEngine.getLocalMember().getUuid();
        registries[i].createProxy(objectName, source, true, true);
        for (int j = i + 1; j < instances.length; j++) {
            Collection<DistributedObject> objects = new ArrayList<>();
            registries[j].getDistributedObjects(objects);
            assertTrue(objects.isEmpty());
        }
    }
}
Also used : Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) ArrayList(java.util.ArrayList) ProxyServiceImpl(com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ServiceConfig(com.hazelcast.config.ServiceConfig) ProxyRegistry(com.hazelcast.spi.impl.proxyservice.impl.ProxyRegistry) UUID(java.util.UUID) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 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();
    ConfigAccessor.getServicesConfig(config).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++) {
        NodeEngine nodeEngine = getNodeEngineImpl(instances[i]);
        OperationService operationService = nodeEngine.getOperationService();
        ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
        Operation postJoinOperation = proxyService.getPostJoinOperation();
        for (int j = 0; j < nodeCount; j++) {
            if (i == j) {
                continue;
            }
            Node node2 = getNode(instances[j]);
            operationService.send(postJoinOperation, node2.address);
        }
    }
    for (HazelcastInstance instance : instances) {
        TestInitializingObject obj = instance.getDistributedObject(serviceName, objectName);
        assertTrue(obj.init.get());
        assertFalse(obj.error);
    }
}
Also used : Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) Operation(com.hazelcast.spi.impl.operationservice.Operation) ProxyServiceImpl(com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ServiceConfig(com.hazelcast.config.ServiceConfig) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with ServiceConfig

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

the class DistributedObjectTest method testDistributedObjectDestroyed_whenDestroyDuringInitialization.

@Test
public void testDistributedObjectDestroyed_whenDestroyDuringInitialization() throws InterruptedException, ExecutionException {
    final CountDownLatch initializationStarted = new CountDownLatch(1);
    final CountDownLatch objectDestroyed = new CountDownLatch(1);
    Config config = new Config();
    ConfigAccessor.getServicesConfig(config).addServiceConfig(new ServiceConfig().setEnabled(true).setName(TestInitializingObjectService.NAME).setImplementation(new TestInitializingObjectService(() -> {
        initializationStarted.countDown();
        try {
            objectDestroyed.await();
        } catch (InterruptedException e) {
            ignore(e);
        }
    })));
    String serviceName = TestInitializingObjectService.NAME;
    String objectName = "test-object";
    HazelcastInstance instance = createHazelcastInstance(config);
    Future f = spawn(() -> {
        // must fail with DistributedObjectDestroyedException
        instance.getDistributedObject(serviceName, objectName);
    });
    initializationStarted.await();
    NodeEngineImpl nodeEngine = getNodeEngineImpl(instance);
    UUID source = nodeEngine.getLocalMember().getUuid();
    nodeEngine.getProxyService().destroyDistributedObject(serviceName, objectName, source);
    objectDestroyed.countDown();
    expectedException.expect(ExecutionException.class);
    expectedException.expectCause(new RootCauseMatcher(DistributedObjectDestroyedException.class));
    f.get();
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) DistributedObjectDestroyedException(com.hazelcast.spi.exception.DistributedObjectDestroyedException) ServiceConfig(com.hazelcast.config.ServiceConfig) Config(com.hazelcast.config.Config) ServiceConfig(com.hazelcast.config.ServiceConfig) Future(java.util.concurrent.Future) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ServiceConfig (com.hazelcast.config.ServiceConfig)30 Config (com.hazelcast.config.Config)27 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 Before (org.junit.Before)6 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 ProxyFactoryConfig (com.hazelcast.client.config.ProxyFactoryConfig)2 IndexConfig (com.hazelcast.config.IndexConfig)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 ProxyServiceImpl (com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl)2 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)2 UUID (java.util.UUID)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 MapConfig (com.hazelcast.config.MapConfig)1 ServicesConfig (com.hazelcast.config.ServicesConfig)1