Search in sources :

Example 71 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class LifeCycleListenerTest method testListenerInvocationWhenNodeStarts.

@Test
public void testListenerInvocationWhenNodeStarts() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    final Config config = new Config();
    final EventCountingListener listener = new EventCountingListener();
    config.addListenerConfig(new ListenerConfig(listener));
    factory.newHazelcastInstance(config);
    assertEquals(LifecycleState.STARTING, listener.events.get(0));
    assertEquals(LifecycleState.STARTED, listener.events.get(1));
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) ListenerConfig(com.hazelcast.config.ListenerConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 72 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method partitionAssignment_shouldFail_whenTriggered_inPassiveState.

@Test(expected = IllegalStateException.class)
public void partitionAssignment_shouldFail_whenTriggered_inPassiveState() {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances(config);
    HazelcastInstance hz1 = instances[0];
    HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    hz2.getCluster().changeClusterState(ClusterState.PASSIVE);
    InternalPartitionService partitionService = getPartitionService(hz1);
    partitionService.getPartitionOwnerOrWait(1);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 73 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method partitionAssignment_shouldFail_whenTriggered_inFrozenState.

@Test(expected = IllegalStateException.class)
public void partitionAssignment_shouldFail_whenTriggered_inFrozenState() {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances(config);
    HazelcastInstance hz1 = instances[0];
    HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    hz2.getCluster().changeClusterState(ClusterState.FROZEN);
    InternalPartitionService partitionService = getPartitionService(hz1);
    partitionService.getPartitionOwnerOrWait(1);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 74 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method nodesCanShutDown_whenClusterState_frozen.

@Test
public void nodesCanShutDown_whenClusterState_frozen() {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance[] instances = factory.newInstances(new Config());
    HazelcastInstance hz = instances[instances.length - 1];
    // for updating partition version
    hz.getMap(randomMapName()).put(1, 1);
    changeClusterStateEventually(hz, ClusterState.FROZEN);
    List<HazelcastInstance> instanceList = new ArrayList<HazelcastInstance>(Arrays.asList(instances));
    while (!instanceList.isEmpty()) {
        HazelcastInstance instanceToShutdown = instanceList.remove(0);
        instanceToShutdown.shutdown();
        for (HazelcastInstance instance : instanceList) {
            assertClusterSizeEventually(instanceList.size(), instance);
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ArrayList(java.util.ArrayList) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 75 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method partitionInvocation_shouldFail_whenPartitionsNotAssigned_inPassiveState.

@Test(expected = IllegalStateException.class)
public void partitionInvocation_shouldFail_whenPartitionsNotAssigned_inPassiveState() throws InterruptedException {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances(config);
    HazelcastInstance hz1 = instances[0];
    HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    hz2.getCluster().changeClusterState(ClusterState.PASSIVE);
    InternalOperationService operationService = getNode(hz3).getNodeEngine().getOperationService();
    Operation op = new AddAndGetOperation(randomName(), 1);
    Future<Long> future = operationService.invokeOnPartition(AtomicLongService.SERVICE_NAME, op, 1);
    try {
        future.get();
        fail("Partition invocation must fail, because partitions cannot be assigned!");
    } catch (ExecutionException e) {
        // IllegalStateException should be cause of ExecutionException.
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AddAndGetOperation(com.hazelcast.concurrent.atomiclong.operations.AddAndGetOperation) Config(com.hazelcast.config.Config) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) Operation(com.hazelcast.spi.Operation) AddAndGetOperation(com.hazelcast.concurrent.atomiclong.operations.AddAndGetOperation) ExecutionException(java.util.concurrent.ExecutionException) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)948 HazelcastInstance (com.hazelcast.core.HazelcastInstance)827 Test (org.junit.Test)774 QuickTest (com.hazelcast.test.annotation.QuickTest)726 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)575 Config (com.hazelcast.config.Config)488 MapConfig (com.hazelcast.config.MapConfig)185 ParallelTest (com.hazelcast.test.annotation.ParallelTest)145 MapStoreConfig (com.hazelcast.config.MapStoreConfig)121 CountDownLatch (java.util.concurrent.CountDownLatch)108 AssertTask (com.hazelcast.test.AssertTask)97 NightlyTest (com.hazelcast.test.annotation.NightlyTest)86 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)81 Before (org.junit.Before)75 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)58 NearCacheConfig (com.hazelcast.config.NearCacheConfig)53 SlowTest (com.hazelcast.test.annotation.SlowTest)53 IndexConfig (com.hazelcast.config.IndexConfig)50 ArrayList (java.util.ArrayList)45 Map (java.util.Map)43