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]);
}
});
}
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]);
}
});
}
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) {
}
}
});
}
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;
}
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);
}
}
Aggregations