use of io.pravega.shared.protocol.netty.WireCommands.TransactionInfo in project pravega by pravega.
the class PravegaRequestProcessorTest method testTransaction.
@Test(timeout = 20000)
public void testTransaction() throws Exception {
String streamSegmentName = "testTxn";
UUID txnid = UUID.randomUUID();
@Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
ServerConnection connection = mock(ServerConnection.class);
InOrder order = inOrder(connection);
PravegaRequestProcessor processor = new PravegaRequestProcessor(store, connection);
processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, ""));
order.verify(connection).send(new WireCommands.SegmentCreated(0, streamSegmentName));
processor.createTransaction(new WireCommands.CreateTransaction(1, streamSegmentName, txnid, ""));
assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 1, store));
processor.getTransactionInfo(new WireCommands.GetTransactionInfo(2, streamSegmentName, txnid, ""));
assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 2, store));
order.verify(connection).send(new WireCommands.TransactionCreated(1, streamSegmentName, txnid));
order.verify(connection).send(Mockito.argThat(t -> {
return t instanceof TransactionInfo && ((TransactionInfo) t).exists();
}));
processor.commitTransaction(new WireCommands.CommitTransaction(3, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.TransactionCommitted(3, streamSegmentName, txnid));
processor.getTransactionInfo(new WireCommands.GetTransactionInfo(4, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.NoSuchSegment(4, StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid)));
txnid = UUID.randomUUID();
processor.createTransaction(new WireCommands.CreateTransaction(1, streamSegmentName, txnid, ""));
assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 1, store));
order.verify(connection).send(new WireCommands.TransactionCreated(1, streamSegmentName, txnid));
processor.getTransactionInfo(new WireCommands.GetTransactionInfo(2, streamSegmentName, txnid, ""));
order.verify(connection).send(Mockito.argThat(t -> {
return t instanceof TransactionInfo && ((TransactionInfo) t).exists();
}));
processor.abortTransaction(new WireCommands.AbortTransaction(3, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.TransactionAborted(3, streamSegmentName, txnid));
processor.getTransactionInfo(new WireCommands.GetTransactionInfo(4, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.NoSuchSegment(4, StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid)));
// Verify the case when the transaction segment is already sealed. This simulates the case when the process
// crashed after sealing, but before issuing the merge.
txnid = UUID.randomUUID();
processor.createTransaction(new WireCommands.CreateTransaction(1, streamSegmentName, txnid, ""));
assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 1, store));
processor.getTransactionInfo(new WireCommands.GetTransactionInfo(2, streamSegmentName, txnid, ""));
assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 2, store));
// Seal the transaction in the SegmentStore.
String txnName = StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid);
store.sealStreamSegment(txnName, Duration.ZERO).join();
processor.commitTransaction(new WireCommands.CommitTransaction(3, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.TransactionCommitted(3, streamSegmentName, txnid));
processor.getTransactionInfo(new WireCommands.GetTransactionInfo(4, streamSegmentName, txnid, ""));
order.verify(connection).send(new WireCommands.NoSuchSegment(4, StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid)));
order.verifyNoMoreInteractions();
}
use of io.pravega.shared.protocol.netty.WireCommands.TransactionInfo in project pravega by pravega.
the class PravegaRequestProcessor method getTransactionInfo.
@Override
public void getTransactionInfo(GetTransactionInfo request) {
String transactionName = StreamSegmentNameUtils.getTransactionNameFromId(request.getSegment(), request.getTxid());
if (!verifyToken(request.getSegment(), request.getRequestId(), request.getDelegationToken(), READ, "Get Transaction Info")) {
return;
}
segmentStore.getStreamSegmentInfo(transactionName, false, TIMEOUT).thenAccept(properties -> {
if (properties != null) {
TransactionInfo result = new TransactionInfo(request.getRequestId(), request.getSegment(), request.getTxid(), transactionName, !properties.isDeleted(), properties.isSealed(), properties.getLastModified().getTime(), properties.getLength());
log.trace("Read transaction segment info: {}", result);
connection.send(result);
} else {
log.trace("getTransactionInfo could not find segment {}", transactionName);
connection.send(new TransactionInfo(request.getRequestId(), request.getSegment(), request.getTxid(), transactionName, false, true, 0, 0));
}
}).exceptionally(e -> handleException(request.getRequestId(), transactionName, "Get transaction info", e));
}
Aggregations