use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class Invocation_NetworkSplitTest method testWaitingInvocations_whenNodeSplitFromCluster.
private void testWaitingInvocations_whenNodeSplitFromCluster(SplitAction splitAction) throws Exception {
Config config = createConfig();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
HazelcastInstance hz3 = factory.newHazelcastInstance(config);
Node node1 = TestUtil.getNode(hz1);
Node node2 = TestUtil.getNode(hz2);
Node node3 = TestUtil.getNode(hz3);
warmUpPartitions(hz1, hz2, hz3);
int partitionId = getPartitionId(hz2);
NodeEngineImpl nodeEngine3 = node3.getNodeEngine();
OperationService operationService3 = nodeEngine3.getOperationService();
Operation op = new AlwaysBlockingOperation();
Future<Object> future = operationService3.invokeOnPartition("", op, partitionId);
// just wait a little to make sure
// operation is landed on wait-queue
sleepSeconds(1);
// execute the given split action
splitAction.run(node1, node2, node3);
// Let node3 detect the split and merge it back to other two.
ClusterServiceImpl clusterService3 = node3.getClusterService();
clusterService3.merge(node1.address);
assertClusterSizeEventually(3, hz1);
assertClusterSizeEventually(3, hz2);
assertClusterSizeEventually(3, hz3);
try {
future.get(1, TimeUnit.MINUTES);
fail("Future.get() should fail with a MemberLeftException!");
} catch (MemberLeftException e) {
// expected
EmptyStatement.ignore(e);
} catch (Exception e) {
fail(e.getClass().getName() + ": " + e.getMessage());
}
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class ConnectedClientOperationTest method testNumberOfConnectedClients.
@Test
public void testNumberOfConnectedClients() throws Exception {
HazelcastInstance h1 = factory.newHazelcastInstance();
HazelcastInstance h2 = factory.newHazelcastInstance();
assertClusterSizeEventually(2, h1);
assertClusterSizeEventually(2, h2);
int numberOfClients = 6;
for (int i = 0; i < numberOfClients; i++) {
factory.newHazelcastClient();
}
Node node = TestUtil.getNode(h1);
Map<ClientType, Integer> clientStats = node.clientEngine.getConnectedClientStats();
assertEquals(numberOfClients, clientStats.get(ClientType.JAVA).intValue());
assertEquals(0, clientStats.get(ClientType.CPP).intValue());
assertEquals(0, clientStats.get(ClientType.CSHARP).intValue());
assertEquals(0, clientStats.get(ClientType.NODEJS).intValue());
assertEquals(0, clientStats.get(ClientType.PYTHON).intValue());
assertEquals(0, clientStats.get(ClientType.OTHER).intValue());
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenZeroClientConnects.
@Test
public void testGetConnectedClientsOperation_WhenZeroClientConnects() throws Exception {
HazelcastInstance instance = factory.newHazelcastInstance();
Node node = TestUtil.getNode(instance);
Operation operation = new GetConnectedClientsOperation();
OperationService operationService = node.nodeEngine.getOperationService();
Future<Map<String, ClientType>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
Map<String, ClientType> clients = future.get();
assertEquals(0, clients.size());
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class NodeQueryCacheContext method flushPublishersOnNodeShutdown.
/**
* This is a best effort approach; there is no guarantee that events in publishers internal buffers will be fired,
* {@link com.hazelcast.spi.EventService} can drop them.
*/
private void flushPublishersOnNodeShutdown() {
Node node = ((NodeEngineImpl) this.nodeEngine).getNode();
LifecycleServiceImpl lifecycleService = node.hazelcastInstance.getLifecycleService();
lifecycleService.addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (SHUTTING_DOWN == event.getState()) {
publisherContext.flush();
}
}
});
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class CacheClearTest method testClear.
@Test
public void testClear() {
ICache<String, String> cache = createCache();
String cacheName = cache.getName();
Map<String, String> entries = createAndFillEntries();
for (Map.Entry<String, String> entry : entries.entrySet()) {
cache.put(entry.getKey(), entry.getValue());
}
// Verify that put works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String expectedValue = entries.get(key);
String actualValue = cache.get(key);
assertEquals(expectedValue, actualValue);
}
Node node = getNode(hazelcastInstance);
InternalPartitionService partitionService = node.getPartitionService();
SerializationService serializationService = node.getSerializationService();
// Verify that backup of put works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String expectedValue = entries.get(key);
Data keyData = serializationService.toData(key);
int keyPartitionId = partitionService.getPartitionId(keyData);
for (int i = 0; i < INSTANCE_COUNT; i++) {
Node n = getNode(hazelcastInstances[i]);
ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
assertNotNull(recordStore);
String actualValue = serializationService.toObject(recordStore.get(keyData, null));
assertEquals(expectedValue, actualValue);
}
}
cache.clear();
// Verify that clear works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String actualValue = cache.get(key);
assertNull(actualValue);
}
// Verify that backup of clear works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
Data keyData = serializationService.toData(key);
int keyPartitionId = partitionService.getPartitionId(keyData);
for (int i = 0; i < INSTANCE_COUNT; i++) {
Node n = getNode(hazelcastInstances[i]);
ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
assertNotNull(recordStore);
String actualValue = serializationService.toObject(recordStore.get(keyData, null));
assertNull(actualValue);
}
}
}
Aggregations