@Test(timeout = 10000) public void testControllerTimeout() throws InterruptedException { long begin = System.currentTimeMillis(); TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE) .thenApply(x -> ModelHelper.decode(x.getKey())) .join(); Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (1.3 * LEASE), TimeUnit.MILLISECONDS); long end = System.currentTimeMillis(); Assert.assertNotNull(result); log.info("Delay until timeout = " + (end - begin)); Assert.assertTrue((end - begin) >= LEASE); TxnState txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.ABORTING, txnState.getState()); }
@Override public CompletableFuture<Transaction.Status> checkTransactionStatus(final Stream stream, final UUID txId) { Exceptions.checkNotClosed(closed.get(), this); Preconditions.checkNotNull(stream, "stream"); Preconditions.checkNotNull(txId, "txId"); long traceId = LoggerHelpers.traceEnter(log, "checkTransactionStatus", stream, txId); final CompletableFuture<TxnState> result = this.retryConfig.runAsync(() -> { RPCAsyncCallback<TxnState> callback = new RPCAsyncCallback<>(traceId, "checkTransactionStatus"); client.checkTransactionState(TxnRequest.newBuilder() .setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())) .setTxnId(ModelHelper.decode(txId)) .build(), callback); return callback.getFuture(); }, this.executor); return result.thenApply(status -> ModelHelper.encode(status.getState(), stream + " " + txId)) .whenComplete((x, e) -> { if (e != null) { log.warn("checkTransactionStatus failed: ", e); } LoggerHelpers.traceLeave(log, "checkTransactionStatus", traceId); }); }
@Test(timeout = 10000) public void testControllerPingFailureMaxExecutionTimeExceeded() throws InterruptedException { int lease = 10; TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, lease) .thenApply(x -> ModelHelper.decode(x.getKey())) .join(); TxnState txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, txnState.getState()); PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, 1000 * lease).join(); Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus()); txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, txnState.getState()); }
@Test(timeout = 10000) public void testControllerPingFailureDisconnected() throws InterruptedException { TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE) .thenApply(x -> ModelHelper.decode(x.getKey())) .join(); Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNull(result); TxnState status = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, status.getState()); // Stop timeoutService, and then try pinging the transaction. timeoutService.stopAsync(); PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, LEASE).join(); Assert.assertEquals(PingTxnStatus.Status.DISCONNECTED, pingStatus.getStatus()); result = timeoutService.getTaskCompletionQueue().poll((long) (0.5 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNull(result); // Check that the transaction status is still open, since timeoutService has been stopped. status = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, status.getState()); }
@Test(timeout = 10000) public void testControllerPingSuccess() throws InterruptedException { TxnId txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE) .thenApply(x -> ModelHelper.decode(x.getKey())) .join(); Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNull(result); TxnState txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, txnState.getState()); PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, LEASE).join(); Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus()); result = timeoutService.getTaskCompletionQueue().poll((long) (0.5 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNull(result); txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, txnState.getState()); result = timeoutService.getTaskCompletionQueue().poll((long) (0.8 * LEASE), TimeUnit.MILLISECONDS); Assert.assertNotNull(result); txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.ABORTING, txnState.getState()); }
@Override public CompletableFuture<Transaction.Status> checkTransactionStatus(Stream stream, UUID txnId) { return controller.checkTransactionStatus(stream.getScope(), stream.getStreamName(), ModelHelper.decode(txnId)) .thenApply(status -> ModelHelper.encode(status.getState(), stream + " " + txnId)); }
@Test(timeout = 5000) public void testCloseUnknownTxn() { UUID txId = streamStore.generateTransactionId(SCOPE, STREAM, null, executor).join(); VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txId, LEASE, 10 * LEASE, null, executor).join(); TxnId txnId = convert(txData.getId()); Controller.TxnState state = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId).join(); Assert.assertEquals(TxnState.State.OPEN, state.getState()); Controller.TxnStatus.Status status = controllerService.abortTransaction(SCOPE, STREAM, txnId).join().getStatus(); Assert.assertEquals(Controller.TxnStatus.Status.SUCCESS, status); }