Search in sources :

Example 16 with Node

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);
            }
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node)

Example 17 with Node

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();
}
Also used : DefaultNodeExtension(com.hazelcast.instance.DefaultNodeExtension) MockNodeContext(com.hazelcast.test.mocknetwork.MockNodeContext) NodeContext(com.hazelcast.instance.NodeContext) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MockNodeContext(com.hazelcast.test.mocknetwork.MockNodeContext) Before(org.junit.Before)

Example 18 with Node

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with Node

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());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) OperationParkerImpl(com.hazelcast.spi.impl.operationparker.impl.OperationParkerImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 20 with Node

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);
    }
}
Also used : OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) CountDownLatch(java.util.concurrent.CountDownLatch) NodeEngine(com.hazelcast.spi.NodeEngine) HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Aggregations

Node (com.hazelcast.instance.Node)131 HazelcastInstance (com.hazelcast.core.HazelcastInstance)60 Test (org.junit.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)45 ParallelTest (com.hazelcast.test.annotation.ParallelTest)42 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)21 ClientEventRegistration (com.hazelcast.client.spi.impl.listener.ClientEventRegistration)18 Address (com.hazelcast.nio.Address)17 Config (com.hazelcast.config.Config)14 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 ILogger (com.hazelcast.logging.ILogger)10 Data (com.hazelcast.nio.serialization.Data)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)10 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)9 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 SerializationService (com.hazelcast.spi.serialization.SerializationService)7 ItemListener (com.hazelcast.core.ItemListener)6 Operation (com.hazelcast.spi.Operation)6