Search in sources :

Example 11 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method changeClusterState_shouldFail_whenInitiatorDies_beforePrepare.

@Test
public void changeClusterState_shouldFail_whenInitiatorDies_beforePrepare() throws Exception {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance[] instances = factory.newInstances();
    final HazelcastInstance hz = instances[instances.length - 1];
    TransactionManagerServiceImpl transactionManagerService = spyTransactionManagerService(hz);
    TransactionOptions options = TransactionOptions.getDefault().setTimeout(30, TimeUnit.SECONDS);
    when(transactionManagerService.newAllowedDuringPassiveStateTransaction(options)).thenAnswer(new TransactionAnswer() {

        @Override
        protected void beforePrepare() {
            terminateInstance(hz);
        }
    });
    try {
        hz.getCluster().changeClusterState(ClusterState.FROZEN, options);
        fail("`changeClusterState` should throw HazelcastInstanceNotActiveException!");
    } catch (HazelcastInstanceNotActiveException ignored) {
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertClusterState(ClusterState.ACTIVE, instances[0], instances[1]);
        }
    });
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method changeClusterState_shouldFail_withoutBackup_whenInitiatorDies_afterPrepare.

@Test
public void changeClusterState_shouldFail_withoutBackup_whenInitiatorDies_afterPrepare() throws Exception {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance[] instances = factory.newInstances();
    final HazelcastInstance hz = instances[instances.length - 1];
    TransactionManagerServiceImpl transactionManagerService = spyTransactionManagerService(hz);
    TransactionOptions options = new TransactionOptions().setDurability(0).setTimeout(30, TimeUnit.SECONDS);
    when(transactionManagerService.newAllowedDuringPassiveStateTransaction(options)).thenAnswer(new TransactionAnswer() {

        @Override
        protected void afterPrepare() {
            terminateInstance(hz);
        }
    });
    try {
        hz.getCluster().changeClusterState(ClusterState.FROZEN, options);
        fail("This instance is terminated. Cannot commit the transaction!");
    } catch (HazelcastInstanceNotActiveException ignored) {
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertClusterState(ClusterState.ACTIVE, instances[0], instances[1]);
        }
    });
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionManagerServiceImpl(com.hazelcast.transaction.impl.TransactionManagerServiceImpl) TransactionOptions(com.hazelcast.transaction.TransactionOptions) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class BufferPoolThreadLocalTest method get_whenCleared.

@Test
public void get_whenCleared() throws Exception {
    // forces the creation of a bufferpool.
    bufferPoolThreadLocal.get();
    // we kill all strong references.
    bufferPoolThreadLocal.clear();
    // then eventually when we try to get the pool, we should get a HazelcastInstanceNotActiveException
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            System.gc();
            try {
                bufferPoolThreadLocal.get();
                fail();
            } catch (HazelcastInstanceNotActiveException ignore) {
            }
        }
    });
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) AssertTask(com.hazelcast.test.AssertTask) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class AbstractSerializationService method serializerFor.

protected final SerializerAdapter serializerFor(Object object) {
    //1-NULL serializer
    if (object == null) {
        return nullSerializerAdapter;
    }
    Class type = object.getClass();
    //2-Default serializers, Dataserializable, Portable, primitives, arrays, String and some helper Java types(BigInteger etc)
    SerializerAdapter serializer = lookupDefaultSerializer(type);
    //3-Custom registered types by user
    if (serializer == null) {
        serializer = lookupCustomSerializer(type);
    }
    //4-JDK serialization ( Serializable and Externalizable )
    if (serializer == null && !overrideJavaSerialization) {
        serializer = lookupJavaSerializer(type);
    }
    //5-Global serializer if registered by user
    if (serializer == null) {
        serializer = lookupGlobalSerializer(type);
    }
    if (serializer == null) {
        if (active) {
            throw new HazelcastSerializationException("There is no suitable serializer for " + type);
        }
        throw new HazelcastInstanceNotActiveException();
    }
    return serializer;
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SerializationUtil.createSerializerAdapter(com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)

Example 15 with HazelcastInstanceNotActiveException

use of com.hazelcast.core.HazelcastInstanceNotActiveException in project hazelcast by hazelcast.

the class AbstractSerializationService method toObject.

@Override
public final <T> T toObject(final Object object) {
    if (!(object instanceof Data)) {
        return (T) object;
    }
    Data data = (Data) object;
    if (isNullData(data)) {
        return null;
    }
    BufferPool pool = bufferPoolThreadLocal.get();
    BufferObjectDataInput in = pool.takeInputBuffer(data);
    try {
        ClassLocator.onStartDeserialization();
        final int typeId = data.getType();
        final SerializerAdapter serializer = serializerFor(typeId);
        if (serializer == null) {
            if (active) {
                throw newHazelcastSerializationException(typeId);
            }
            throw new HazelcastInstanceNotActiveException();
        }
        Object obj = serializer.read(in);
        if (managedContext != null) {
            obj = managedContext.initialize(obj);
        }
        return (T) obj;
    } catch (Throwable e) {
        throw handleException(e);
    } finally {
        ClassLocator.onFinishDeserialization();
        pool.returnInputBuffer(in);
    }
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) BufferPool(com.hazelcast.internal.serialization.impl.bufferpool.BufferPool) SerializationUtil.createSerializerAdapter(com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter) SerializationUtil.isNullData(com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData) Data(com.hazelcast.nio.serialization.Data) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput)

Aggregations

HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)34 HazelcastException (com.hazelcast.core.HazelcastException)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)8 Test (org.junit.Test)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)7 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)7 OException (com.orientechnologies.common.exception.OException)7 OIOException (com.orientechnologies.common.io.OIOException)7 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)7 TransactionException (com.hazelcast.transaction.TransactionException)6 OCallable (com.orientechnologies.common.util.OCallable)6 ExecutionException (java.util.concurrent.ExecutionException)6 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)5 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)5 AssertTask (com.hazelcast.test.AssertTask)5 Callable (java.util.concurrent.Callable)5 TransactionOptions (com.hazelcast.transaction.TransactionOptions)4