Search in sources :

Example 1 with AddAndGetOperation

use of com.hazelcast.concurrent.atomiclong.operations.AddAndGetOperation 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)

Example 2 with AddAndGetOperation

use of com.hazelcast.concurrent.atomiclong.operations.AddAndGetOperation in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method partitionInvocation_shouldFail_whenPartitionsNotAssigned_inFrozenState.

@Test(expected = IllegalStateException.class)
public void partitionInvocation_shouldFail_whenPartitionsNotAssigned_inFrozenState() 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.FROZEN);
    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

AddAndGetOperation (com.hazelcast.concurrent.atomiclong.operations.AddAndGetOperation)2 Config (com.hazelcast.config.Config)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 Operation (com.hazelcast.spi.Operation)2 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2