use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.
the class IndeterminateOperationStateExceptionTest method partitionInvocation_shouldFail_whenPartitionPrimaryLeaves.
@Test
public void partitionInvocation_shouldFail_whenPartitionPrimaryLeaves() throws InterruptedException, TimeoutException {
setup(true);
int partitionId = getPartitionId(instance2);
OperationServiceImpl operationService = getNodeEngineImpl(instance1).getOperationService();
InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new SilentOperation(), partitionId).invoke();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertTrue(instance2.getUserContext().containsKey(SilentOperation.EXECUTION_STARTED));
}
});
spawn(new Runnable() {
@Override
public void run() {
instance2.getLifecycleService().terminate();
}
});
try {
future.get(2, TimeUnit.MINUTES);
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof IndeterminateOperationStateException);
}
}
use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.
the class BaseInvocation method detectAndHandleBackupTimeout.
/**
* @param timeoutMillis timeout value to wait for backups after the response received
* @return true if invocation is completed
*/
public boolean detectAndHandleBackupTimeout(long timeoutMillis) {
// since the backupsAcksExpected will always be equal to the backupsAcksReceived
if (backupsAcksExpected == backupsAcksReceived) {
return false;
}
// if the response of the primary has been received, but the backups have not replied
if (pendingResponse == VOID) {
return false;
}
// if this has not yet expired (so has not been in the system for a too long period) we ignore it
long expirationTime = pendingResponseReceivedMillis + timeoutMillis;
boolean timeoutReached = expirationTime > 0 && expirationTime < Clock.currentTimeMillis();
if (!timeoutReached) {
return false;
}
if (shouldFailOnIndeterminateOperationState()) {
completeExceptionally(new IndeterminateOperationStateException(this + " failed because backup acks missed."));
return true;
}
if (shouldCompleteWithoutBackups()) {
// the backups have not yet completed, but we are going to release the future anyway if a pendingResponse has been set
completeWithPendingResponse();
return true;
}
return false;
}
use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.
the class InvocationFuture method resolve.
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
@Override
protected Object resolve(Object unresolved) {
if (unresolved == null) {
return null;
} else if (unresolved == INTERRUPTED) {
return new ExceptionalResult(new InterruptedException(invocation.op.getClass().getSimpleName() + " was interrupted. " + invocation));
} else if (unresolved == CALL_TIMEOUT) {
return new ExceptionalResult(newOperationTimeoutException(false));
} else if (unresolved == HEARTBEAT_TIMEOUT) {
return new ExceptionalResult(newOperationTimeoutException(true));
} else if (unresolved.getClass() == Packet.class) {
NormalResponse response = invocation.context.serializationService.toObject(unresolved);
unresolved = response.getValue();
}
Object value = unresolved;
if (deserialize && value instanceof Data) {
value = invocation.context.serializationService.toObject(value);
if (value == null) {
return null;
}
}
Throwable cause = (value instanceof ExceptionalResult) ? ((ExceptionalResult) value).getCause() : null;
if (invocation.shouldFailOnIndeterminateOperationState() && (value instanceof IndeterminateOperationState || cause instanceof IndeterminateOperationState)) {
value = wrapThrowable(new IndeterminateOperationStateException("indeterminate operation state", cause == null ? (Throwable) value : cause));
}
return value;
}
use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.
the class IndeterminateOperationStateExceptionTest method transaction_shouldFail_whenBackupTimeoutOccurs.
@Test
public void transaction_shouldFail_whenBackupTimeoutOccurs() {
setup(true);
dropOperationsBetween(instance1, instance2, F_ID, singletonList(SpiDataSerializerHook.BACKUP));
dropOperationsBetween(instance2, instance1, F_ID, singletonList(SpiDataSerializerHook.BACKUP));
String name = randomMapName();
String key1 = generateKeyOwnedBy(instance1);
String key2 = generateKeyOwnedBy(instance2);
TransactionContext context = instance1.newTransactionContext();
context.beginTransaction();
try {
TransactionalMap<Object, Object> map = context.getMap(name);
map.put(key1, "value");
map.put(key2, "value");
context.commitTransaction();
fail("Should fail with IndeterminateOperationStateException");
} catch (IndeterminateOperationStateException e) {
context.rollbackTransaction();
}
IMap<Object, Object> map = instance1.getMap(name);
assertNull(map.get(key1));
assertNull(map.get(key2));
}
use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.
the class IndeterminateOperationStateExceptionTest method partitionInvocation_shouldFailOnBackupTimeout_whenConfigurationEnabledForInvocation.
@Test
public void partitionInvocation_shouldFailOnBackupTimeout_whenConfigurationEnabledForInvocation() throws InterruptedException, TimeoutException {
setup(false);
dropOperationsBetween(instance1, instance2, F_ID, singletonList(SpiDataSerializerHook.BACKUP));
int partitionId = getPartitionId(instance1);
OperationServiceImpl operationService = getNodeEngineImpl(instance1).getOperationService();
InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new PrimaryOperation(), partitionId).setFailOnIndeterminateOperationState(true).invoke();
try {
future.get(2, TimeUnit.MINUTES);
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof IndeterminateOperationStateException);
}
}
Aggregations