use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class AbstractPartitionAssignmentsCorrectnessTest method assertPartitionAssignments.
static void assertPartitionAssignments(TestHazelcastInstanceFactory factory) {
Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
final int replicaCount = Math.min(instances.size(), InternalPartition.MAX_REPLICA_COUNT);
for (HazelcastInstance hz : instances) {
Node node = getNode(hz);
InternalPartitionService partitionService = node.getPartitionService();
InternalPartition[] partitions = partitionService.getInternalPartitions();
for (InternalPartition partition : partitions) {
for (int i = 0; i < replicaCount; i++) {
Address replicaAddress = partition.getReplicaAddress(i);
assertNotNull("Replica " + i + " is not found in " + partition, replicaAddress);
assertTrue("Not member: " + replicaAddress, node.getClusterService().getMember(replicaAddress) != null);
}
}
}
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class InternalPartitionServiceImplTest method setup.
@Before
public void setup() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
NodeContext nodeContext = new MockNodeContext(factory.getRegistry(), factory.nextAddress()) {
@Override
public NodeExtension createNodeExtension(Node node) {
return new DefaultNodeExtension(node) {
@Override
public boolean isStartCompleted() {
return startupDone.get();
}
};
}
};
instance = HazelcastInstanceFactory.newHazelcastInstance(new Config(), randomName(), nodeContext);
partitionService = (InternalPartitionServiceImpl) getPartitionService(instance);
thisAddress = getNode(instance).getThisAddress();
partitionCount = partitionService.getPartitionCount();
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class LocalOperationStatsImplTest method testNodeConstructor.
@Test
public void testNodeConstructor() {
Config config = new Config();
config.setProperty(GroupProperty.MC_MAX_VISIBLE_SLOW_OPERATION_COUNT.getName(), "139");
HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
Node node = getNode(hazelcastInstance);
LocalOperationStatsImpl localOperationStats = new LocalOperationStatsImpl(node);
assertEquals(139, localOperationStats.getMaxVisibleSlowOperationCount());
assertEquals(0, localOperationStats.getSlowOperations().size());
assertTrue(localOperationStats.getCreationTime() > 0);
assertNotNull(localOperationStats.toString());
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class Invocation_NetworkSplitTest method testWaitNotifyService_whenNodeSplitFromCluster.
private void testWaitNotifyService_whenNodeSplitFromCluster(SplitAction action) throws Exception {
Config config = createConfig();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(5);
HazelcastInstance hz1 = factory.newHazelcastInstance(config);
HazelcastInstance hz2 = factory.newHazelcastInstance(config);
HazelcastInstance hz3 = factory.newHazelcastInstance(config);
final Node node1 = TestUtil.getNode(hz1);
Node node2 = TestUtil.getNode(hz2);
Node node3 = TestUtil.getNode(hz3);
warmUpPartitions(hz1, hz2, hz3);
int partitionId = getPartitionId(hz3);
NodeEngineImpl nodeEngine1 = node1.getNodeEngine();
OperationService operationService1 = nodeEngine1.getOperationService();
operationService1.invokeOnPartition("", new AlwaysBlockingOperation(), partitionId);
final OperationParkerImpl waitNotifyService3 = (OperationParkerImpl) node3.getNodeEngine().getOperationParker();
assertEqualsEventually(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return waitNotifyService3.getTotalParkedOperationCount();
}
}, 1);
action.run(node1, node2, node3);
// create a new node to prevent same partition assignments
// after node3 rejoins
factory.newHazelcastInstance(config);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Assert.assertEquals(0, node1.partitionService.getMigrationQueueSize());
}
});
// Let node3 detect the split and merge it back to other two.
ClusterServiceImpl clusterService3 = node3.getClusterService();
clusterService3.merge(node1.address);
assertEquals(4, node1.getClusterService().getSize());
assertEquals(4, node2.getClusterService().getSize());
assertEquals(4, node3.getClusterService().getSize());
assertEquals(0, waitNotifyService3.getTotalParkedOperationCount());
}
use of com.hazelcast.instance.Node in project hazelcast by hazelcast.
the class OperationServiceImpl_timeoutTest method testOperationTimeout.
private void testOperationTimeout(int memberCount, boolean async) {
assertTrue(memberCount > 0);
Config config = new Config();
config.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "3000");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(memberCount);
HazelcastInstance[] instances = factory.newInstances(config);
warmUpPartitions(instances);
final HazelcastInstance hz = instances[memberCount - 1];
Node node = TestUtil.getNode(hz);
NodeEngine nodeEngine = node.nodeEngine;
OperationService operationService = nodeEngine.getOperationService();
int partitionId = (int) (Math.random() * node.getPartitionService().getPartitionCount());
InternalCompletableFuture<Object> future = operationService.invokeOnPartition(null, new TimedOutBackupAwareOperation(), partitionId);
final CountDownLatch latch = new CountDownLatch(1);
if (async) {
future.andThen(new ExecutionCallback<Object>() {
@Override
public void onResponse(Object response) {
}
@Override
public void onFailure(Throwable t) {
if (t instanceof OperationTimeoutException) {
latch.countDown();
}
}
});
} else {
try {
future.join();
fail("Should throw OperationTimeoutException!");
} catch (OperationTimeoutException ignored) {
latch.countDown();
}
}
assertOpenEventually("Should throw OperationTimeoutException", latch);
for (HazelcastInstance instance : instances) {
OperationServiceImpl_BasicTest.assertNoLitterInOpService(instance);
}
}
Aggregations