Search in sources :

Example 1 with CreateTxnResponse

use of io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse in project pravega by pravega.

the class ControllerImpl method convert.

private TxnSegments convert(CreateTxnResponse response) {
    NavigableMap<Double, Segment> rangeMap = new TreeMap<>();
    for (SegmentRange r : response.getActiveSegmentsList()) {
        rangeMap.put(r.getMaxKey(), ModelHelper.encode(r.getSegmentId()));
    }
    StreamSegments segments = new StreamSegments(rangeMap, response.getDelegationToken());
    return new TxnSegments(segments, ModelHelper.encode(response.getTxnId()));
}
Also used : SegmentRange(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange) TreeMap(java.util.TreeMap) Segment(io.pravega.client.segment.impl.Segment)

Example 2 with CreateTxnResponse

use of io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse in project pravega by pravega.

the class ControllerServiceImplTest method createTransactionFailureTest.

@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));
}
Also used : CreateTxnResponse(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse) CreateTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest) StreamInfo(io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo) Test(org.junit.Test)

Example 3 with CreateTxnResponse

use of io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse in project pravega by pravega.

the class ControllerServiceImplTest method createTransactionFailureTest.

@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).setScaleGracePeriod(10000).build();
    ResultObserver<CreateTxnResponse> resultObserver = new ResultObserver<>();
    this.controllerService.createTransaction(request, resultObserver);
    AssertExtensions.assertThrows("Lease lower bound violated ", resultObserver::get, e -> checkGRPCException(e, IllegalArgumentException.class));
    // Invalid ScaleGracePeriod
    request = CreateTxnRequest.newBuilder().setStreamInfo(streamInfo).setLease(10000).setScaleGracePeriod(-1).build();
    ResultObserver<CreateTxnResponse> resultObserver3 = new ResultObserver<>();
    this.controllerService.createTransaction(request, resultObserver3);
    AssertExtensions.assertThrows("Lease lower bound violated ", resultObserver3::get, e -> checkGRPCException(e, IllegalArgumentException.class));
}
Also used : CreateTxnResponse(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse) CreateTxnRequest(io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest) StreamInfo(io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo) Test(org.junit.Test)

Example 4 with CreateTxnResponse

use of io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse in project pravega by pravega.

the class ControllerImpl method convert.

private TxnSegments convert(CreateTxnResponse response) {
    NavigableMap<Double, SegmentWithRange> rangeMap = new TreeMap<>();
    for (SegmentRange r : response.getActiveSegmentsList()) {
        Preconditions.checkState(r.getMinKey() <= r.getMaxKey());
        rangeMap.put(r.getMaxKey(), new SegmentWithRange(encode(r.getSegmentId()), r.getMinKey(), r.getMaxKey()));
    }
    StreamSegments segments = new StreamSegments(rangeMap);
    return new TxnSegments(segments, encode(response.getTxnId()));
}
Also used : SegmentRange(io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange) TxnSegments(io.pravega.client.stream.impl.TxnSegments) SegmentWithRange(io.pravega.client.stream.impl.SegmentWithRange) TreeMap(java.util.TreeMap) StreamSegments(io.pravega.client.stream.impl.StreamSegments)

Aggregations

CreateTxnRequest (io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnRequest)2 CreateTxnResponse (io.pravega.controller.stream.api.grpc.v1.Controller.CreateTxnResponse)2 SegmentRange (io.pravega.controller.stream.api.grpc.v1.Controller.SegmentRange)2 StreamInfo (io.pravega.controller.stream.api.grpc.v1.Controller.StreamInfo)2 TreeMap (java.util.TreeMap)2 Test (org.junit.Test)2 Segment (io.pravega.client.segment.impl.Segment)1 SegmentWithRange (io.pravega.client.stream.impl.SegmentWithRange)1 StreamSegments (io.pravega.client.stream.impl.StreamSegments)1 TxnSegments (io.pravega.client.stream.impl.TxnSegments)1