Search in sources :

Example 1 with TxnFailedException

use of io.pravega.client.stream.TxnFailedException in project pravega by pravega.

the class EventStreamWriterTest method testTxnFailed.

@Test
public void testTxnFailed() {
    String scope = "scope";
    String streamName = "stream";
    StreamImpl stream = new StreamImpl(scope, streamName);
    Segment segment = new Segment(scope, streamName, 0);
    UUID txid = UUID.randomUUID();
    EventWriterConfig config = EventWriterConfig.builder().transactionTimeoutTime(0).transactionTimeoutScaleGracePeriod(0).build();
    SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
    Controller controller = Mockito.mock(Controller.class);
    Mockito.when(controller.getCurrentSegments(scope, streamName)).thenReturn(getSegmentsFuture(segment));
    FakeSegmentOutputStream outputStream = new FakeSegmentOutputStream(segment);
    FakeSegmentOutputStream bad = new FakeSegmentOutputStream(segment);
    Mockito.when(controller.createTransaction(stream, 0, 0)).thenReturn(CompletableFuture.completedFuture(new TxnSegments(getSegments(segment), txid)));
    Mockito.when(streamFactory.createOutputStreamForTransaction(eq(segment), eq(txid), any(), any(), any())).thenReturn(outputStream);
    Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment), any(), any(), any())).thenReturn(bad);
    JavaSerializer<String> serializer = new JavaSerializer<>();
    @Cleanup EventStreamWriter<String> writer = new EventStreamWriterImpl<>(stream, controller, streamFactory, serializer, config, new InlineExecutor());
    Transaction<String> txn = writer.beginTxn();
    outputStream.invokeSealedCallBack();
    try {
        txn.writeEvent("Foo");
    } catch (TxnFailedException e) {
    // Expected
    }
    Mockito.verify(controller).getCurrentSegments(any(), any());
    assertTrue(bad.getUnackedEventsOnSeal().isEmpty());
    assertEquals(1, outputStream.getUnackedEventsOnSeal().size());
}
Also used : Cleanup(lombok.Cleanup) Segment(io.pravega.client.segment.impl.Segment) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) SegmentOutputStreamFactory(io.pravega.client.segment.impl.SegmentOutputStreamFactory) InlineExecutor(io.pravega.test.common.InlineExecutor) TxnFailedException(io.pravega.client.stream.TxnFailedException) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with TxnFailedException

use of io.pravega.client.stream.TxnFailedException in project pravega by pravega.

the class MockController method commitTxSegment.

private CompletableFuture<Void> commitTxSegment(UUID txId, Segment segment) {
    CompletableFuture<Void> result = new CompletableFuture<>();
    FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            result.completeExceptionally(new ConnectionClosedException());
        }

        @Override
        public void wrongHost(WrongHost wrongHost) {
            result.completeExceptionally(new UnsupportedOperationException());
        }

        @Override
        public void transactionCommitted(TransactionCommitted transactionCommitted) {
            result.complete(null);
        }

        @Override
        public void transactionAborted(TransactionAborted transactionAborted) {
            result.completeExceptionally(new TxnFailedException("Transaction already aborted."));
        }

        @Override
        public void processingFailure(Exception error) {
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
        }
    };
    sendRequestOverNewConnection(new CommitTransaction(idGenerator.get(), segment.getScopedName(), txId, ""), replyProcessor, result);
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) TransactionAborted(io.pravega.shared.protocol.netty.WireCommands.TransactionAborted) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) AuthenticationException(io.pravega.common.auth.AuthenticationException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) TransactionCommitted(io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted) CommitTransaction(io.pravega.shared.protocol.netty.WireCommands.CommitTransaction) CompletableFuture(java.util.concurrent.CompletableFuture) TxnFailedException(io.pravega.client.stream.TxnFailedException)

Example 3 with TxnFailedException

use of io.pravega.client.stream.TxnFailedException in project pravega by pravega.

the class ClientAdapterBase method mergeTransaction.

@Override
public CompletableFuture<Void> mergeTransaction(String transactionName, Duration timeout) {
    ensureRunning();
    String parentStream = StreamSegmentNameUtils.getParentStreamSegmentName(transactionName);
    return CompletableFuture.runAsync(() -> {
        try {
            EventStreamWriter<byte[]> writer = getDefaultWriter(parentStream);
            UUID txnId = getTransactionId(transactionName);
            Transaction<byte[]> txn = writer.getTxn(txnId);
            txn.commit();
        } catch (TxnFailedException ex) {
            throw new CompletionException(ex);
        } finally {
            this.transactionIds.remove(transactionName);
        }
    }, this.testExecutor);
}
Also used : CompletionException(java.util.concurrent.CompletionException) TxnFailedException(io.pravega.client.stream.TxnFailedException) UUID(java.util.UUID)

Example 4 with TxnFailedException

use of io.pravega.client.stream.TxnFailedException in project pravega by pravega.

the class SegmentTransactionImpl method flush.

@Override
public void flush() throws TxnFailedException {
    checkFailed();
    try {
        out.flush();
        synchronized (lock) {
            removeCompleted();
            checkFailed();
        }
    } catch (SegmentSealedException e) {
        throw new TxnFailedException(e);
    }
}
Also used : TxnFailedException(io.pravega.client.stream.TxnFailedException) SegmentSealedException(io.pravega.client.segment.impl.SegmentSealedException)

Aggregations

TxnFailedException (io.pravega.client.stream.TxnFailedException)4 UUID (java.util.UUID)2 Segment (io.pravega.client.segment.impl.Segment)1 SegmentOutputStreamFactory (io.pravega.client.segment.impl.SegmentOutputStreamFactory)1 SegmentSealedException (io.pravega.client.segment.impl.SegmentSealedException)1 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)1 ConnectionClosedException (io.pravega.client.stream.impl.ConnectionClosedException)1 AuthenticationException (io.pravega.common.auth.AuthenticationException)1 FailingReplyProcessor (io.pravega.shared.protocol.netty.FailingReplyProcessor)1 CommitTransaction (io.pravega.shared.protocol.netty.WireCommands.CommitTransaction)1 TransactionAborted (io.pravega.shared.protocol.netty.WireCommands.TransactionAborted)1 TransactionCommitted (io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted)1 WrongHost (io.pravega.shared.protocol.netty.WireCommands.WrongHost)1 InlineExecutor (io.pravega.test.common.InlineExecutor)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Cleanup (lombok.Cleanup)1 Test (org.junit.Test)1