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);
}
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);
}
}
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());
}
}
}
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);
}
}
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();
}
Aggregations