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());
}
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;
}
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);
}
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);
}
}
Aggregations