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