use of io.pravega.controller.stream.api.grpc.v1.Controller.TxnId in project pravega by pravega.
the class TimeoutServiceTest method testTimeout.
@Test(timeout = 10000)
public void testTimeout() throws InterruptedException {
UUID txnId = streamStore.generateTransactionId(SCOPE, STREAM, null, executor).join();
VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txnId, LEASE, 10 * LEASE, null, executor).join();
long begin = System.currentTimeMillis();
timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime());
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);
TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
Assert.assertEquals(TxnStatus.ABORTING, status);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.TxnId in project pravega by pravega.
the class TimeoutServiceTest method testPingOwnershipTransfer.
@Test(timeout = 30000)
public void testPingOwnershipTransfer() throws Exception {
StreamMetadataStore streamStore2 = getStore();
HostControllerStore hostStore = HostStoreFactory.createInMemoryStore(HostMonitorConfigImpl.dummyConfig());
BucketStore bucketStore = StreamStoreFactory.createInMemoryBucketStore();
TaskMetadataStore taskMetadataStore = TaskStoreFactory.createStore(PRAVEGA_ZK_CURATOR_RESOURCE.storeClient, executor);
SegmentHelper helperMock = SegmentHelperMock.getSegmentHelperMock();
@Cleanup StreamMetadataTasks streamMetadataTasks2 = new StreamMetadataTasks(streamStore2, bucketStore, taskMetadataStore, helperMock, executor, "2", GrpcAuthHelper.getDisabledAuthHelper());
@Cleanup StreamTransactionMetadataTasks streamTransactionMetadataTasks2 = new StreamTransactionMetadataTasks(streamStore2, helperMock, executor, "2", TimeoutServiceConfig.defaultConfig(), new LinkedBlockingQueue<>(5), GrpcAuthHelper.getDisabledAuthHelper());
streamTransactionMetadataTasks2.initializeStreamWriters(new EventStreamWriterMock<>(), new EventStreamWriterMock<>());
// Create TimeoutService
TimerWheelTimeoutService timeoutService2 = (TimerWheelTimeoutService) streamTransactionMetadataTasks2.getTimeoutService();
ControllerService controllerService2 = new ControllerService(kvtStore, kvtMetadataTasks, streamStore2, bucketStore, streamMetadataTasks2, streamTransactionMetadataTasks2, helperMock, executor, null, requestTracker);
UUID txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE, 9L).thenApply(x -> x.getKey()).join();
VersionedTransactionData txnData = streamStore.getTransactionData(SCOPE, STREAM, txnId, null, executor).join();
Assert.assertEquals(txnData.getVersion(), getVersion(0));
Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS);
Assert.assertNull(result);
TxnState txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId, 9L).join();
Assert.assertEquals(TxnState.State.OPEN, txnState.getState());
// increasing lease -> total effective lease = 3 * LEASE
PingTxnStatus pingStatus = controllerService2.pingTransaction(SCOPE, STREAM, txnId, 2 * LEASE, 9L).join();
Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus());
txnData = streamStore.getTransactionData(SCOPE, STREAM, txnId, null, executor).join();
Assert.assertEquals(txnData.getVersion(), getVersion(1));
// timeoutService1 should believe that LEASE has expired and should get non empty completion tasks
result = timeoutService.getTaskCompletionQueue().poll((long) (1.3 * LEASE + RETRY_DELAY), TimeUnit.MILLISECONDS);
Assert.assertNotNull(result);
// the txn may have been attempted to be aborted by timeoutService1 but would have failed. So txn to remain open
txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId, 9L).join();
Assert.assertEquals(TxnState.State.OPEN, txnState.getState());
// timeoutService2 should continue to wait on lease expiry and should get empty completion tasks
result = timeoutService2.getTaskCompletionQueue().poll(0L, TimeUnit.MILLISECONDS);
Assert.assertNull(result);
result = timeoutService2.getTaskCompletionQueue().poll(2 * LEASE + RETRY_DELAY, TimeUnit.MILLISECONDS);
Assert.assertNotNull(result);
// now txn should have moved to aborting because timeoutservice2 has initiated abort
txnState = controllerService.checkTransactionStatus(SCOPE, STREAM, txnId, 9L).join();
Assert.assertEquals(TxnState.State.ABORTING, txnState.getState());
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.TxnId in project pravega by pravega.
the class TimeoutServiceTest method testControllerPingSuccess.
@Test(timeout = 10000)
public void testControllerPingSuccess() throws InterruptedException {
UUID txnId = controllerService.createTransaction(SCOPE, STREAM, LEASE, 9L).thenApply(x -> 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, 9L).join();
Assert.assertEquals(TxnState.State.OPEN, txnState.getState());
PingTxnStatus pingStatus = controllerService.pingTransaction(SCOPE, STREAM, txnId, LEASE, 9L).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, 9L).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, 9L).join();
Assert.assertEquals(TxnState.State.ABORTING, txnState.getState());
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.TxnId in project pravega by pravega.
the class TimeoutServiceTest method testPingFailureDisconnected.
@Test(timeout = 10000)
public void testPingFailureDisconnected() throws InterruptedException {
UUID txnId = streamStore.generateTransactionId(SCOPE, STREAM, null, executor).join();
VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txnId, LEASE, 10 * LEASE, null, executor).join();
timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime());
Optional<Throwable> result = timeoutService.getTaskCompletionQueue().poll((long) (0.75 * LEASE), TimeUnit.MILLISECONDS);
Assert.assertNull(result);
TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
Assert.assertEquals(TxnStatus.OPEN, status);
// Stop timeoutService, and then try pinging the transaction.
timeoutService.stopAsync();
PingTxnStatus pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE);
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 = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
Assert.assertEquals(TxnStatus.OPEN, status);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.TxnId in project pravega by pravega.
the class TimeoutServiceTest method testUnknownTxnPingSuccess.
@Test(timeout = 10000)
public void testUnknownTxnPingSuccess() throws InterruptedException {
UUID txnId = streamStore.generateTransactionId(SCOPE, STREAM, null, executor).join();
VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txnId, LEASE, 10 * LEASE, null, executor).join();
controllerService.pingTransaction(SCOPE, STREAM, txnId, LEASE, 0L).join();
TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
Assert.assertEquals(TxnStatus.OPEN, status);
}
Aggregations