Search in sources :

Example 6 with TxnStatus

use of io.pravega.controller.store.stream.TxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testPingSuccess.

@Test(timeout = 10000)
public void testPingSuccess() throws InterruptedException {
    UUID txnId = UUID.randomUUID();
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txnId, LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
    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);
    PingTxnStatus pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE);
    Assert.assertEquals(PingTxnStatus.Status.OK, pingStatus.getStatus());
    result = timeoutService.getTaskCompletionQueue().poll((long) (0.5 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNull(result);
    status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
    result = timeoutService.getTaskCompletionQueue().poll((long) (0.8 * LEASE), TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result);
    status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.ABORTING, status);
}
Also used : PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) UUID(java.util.UUID) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 7 with TxnStatus

use of io.pravega.controller.store.stream.TxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testPingFailureMaxExecutionTimeExceeded.

@Test(timeout = 10000)
public void testPingFailureMaxExecutionTimeExceeded() throws InterruptedException {
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, UUID.randomUUID(), LEASE, 2 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
    TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
    // 3 * LEASE > 2 * LEASE
    PingTxnStatus pingStatus = timeoutService.pingTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), 3 * LEASE);
    Assert.assertEquals(PingTxnStatus.Status.MAX_EXECUTION_TIME_EXCEEDED, pingStatus.getStatus());
    status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
}
Also used : PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 8 with TxnStatus

use of io.pravega.controller.store.stream.TxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testPingFailureDisconnected.

@Test(timeout = 10000)
public void testPingFailureDisconnected() throws InterruptedException {
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, UUID.randomUUID(), LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
    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);
}
Also used : PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 9 with TxnStatus

use of io.pravega.controller.store.stream.TxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testUnknownTxnPingSuccess.

@Test(timeout = 10000)
public void testUnknownTxnPingSuccess() throws InterruptedException {
    UUID txnId = UUID.randomUUID();
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txnId, LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    TxnId tx = TxnId.newBuilder().setHighBits(txnId.getMostSignificantBits()).setLowBits(txnId.getLeastSignificantBits()).build();
    controllerService.pingTransaction(SCOPE, STREAM, tx, LEASE);
    TxnStatus status = streamStore.transactionStatus(SCOPE, STREAM, txData.getId(), null, executor).join();
    Assert.assertEquals(TxnStatus.OPEN, status);
}
Also used : TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) UUID(java.util.UUID) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 10 with TxnStatus

use of io.pravega.controller.store.stream.TxnStatus in project pravega by pravega.

the class TimeoutServiceTest method testTimeout.

@Test(timeout = 10000)
public void testTimeout() throws InterruptedException {
    UUID txnId = UUID.randomUUID();
    VersionedTransactionData txData = streamStore.createTransaction(SCOPE, STREAM, txnId, LEASE, 10 * LEASE, SCALE_GRACE_PERIOD, null, executor).join();
    long begin = System.currentTimeMillis();
    timeoutService.addTxn(SCOPE, STREAM, txData.getId(), txData.getVersion(), LEASE, txData.getMaxExecutionExpiryTime(), txData.getScaleGracePeriod());
    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);
}
Also used : UUID(java.util.UUID) VersionedTransactionData(io.pravega.controller.store.stream.VersionedTransactionData) TxnStatus(io.pravega.controller.store.stream.TxnStatus) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Aggregations

TxnStatus (io.pravega.controller.store.stream.TxnStatus)12 VersionedTransactionData (io.pravega.controller.store.stream.VersionedTransactionData)9 PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)9 Test (org.junit.Test)8 UUID (java.util.UUID)4 ClientFactory (io.pravega.client.ClientFactory)2 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)2 EventStreamWriter (io.pravega.client.stream.EventStreamWriter)2 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)2 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)2 Futures (io.pravega.common.concurrent.Futures)2 ControllerService (io.pravega.controller.server.ControllerService)2 SegmentHelper (io.pravega.controller.server.SegmentHelper)2 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)2 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)2 AbortEvent (io.pravega.shared.controller.event.AbortEvent)2 CommitEvent (io.pravega.shared.controller.event.CommitEvent)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)1