@Override public CompletableFuture<TxnSegments> createTransaction(final Stream stream, final long lease) { Exceptions.checkNotClosed(closed.get(), this); Preconditions.checkNotNull(stream, "stream"); long traceId = LoggerHelpers.traceEnter(log, "createTransaction", stream, lease); final CompletableFuture<CreateTxnResponse> result = this.retryConfig.runAsync(() -> { RPCAsyncCallback<CreateTxnResponse> callback = new RPCAsyncCallback<>(traceId, "createTransaction"); client.createTransaction( CreateTxnRequest.newBuilder() .setStreamInfo(ModelHelper.createStreamInfo(stream.getScope(), stream.getStreamName())) .setLease(lease) .build(), callback); return callback.getFuture(); }, this.executor); return result.thenApply(this::convert) .whenComplete((x, e) -> { if (e != null) { log.warn("createTransaction failed: ", e); } LoggerHelpers.traceLeave(log, "createTransaction", traceId); }); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
@Test public void createTransactionFailureTest() { createScopeAndStream(SCOPE1, STREAM1, ScalingPolicy.fixed(4)); StreamInfo streamInfo = ModelHelper.createStreamInfo(SCOPE1, STREAM1); // Invalid lease CreateTxnRequest request = CreateTxnRequest.newBuilder() .setStreamInfo(streamInfo) .setLease(-1) .build(); ResultObserver<CreateTxnResponse> resultObserver = new ResultObserver<>(); this.controllerService.createTransaction(request, resultObserver); AssertExtensions.assertThrows("Lease lower bound violated ", resultObserver::get, e -> checkGRPCException(e, IllegalArgumentException.class)); }
private Controller.CreateTxnResponse createTransaction(final String scope, final String stream, final long lease) { Controller.StreamInfo streamInfo = ModelHelper.createStreamInfo(scope, stream); Controller.CreateTxnRequest request = Controller.CreateTxnRequest.newBuilder() .setStreamInfo(streamInfo) .setLease(lease) .build(); ResultObserver<Controller.CreateTxnResponse> resultObserver = new ResultObserver<>(); this.controllerService.createTransaction(request, resultObserver); Controller.CreateTxnResponse response = resultObserver.get(); Assert.assertTrue(response != null); return response; } }