use of io.pravega.client.stream.impl.StreamSegments in project pravega by pravega.
the class StreamManagerImplTest method testSealedStream.
@Test(timeout = 10000)
public void testSealedStream() throws ConnectionFailedException {
final String streamName = "stream";
final Stream stream = new StreamImpl(defaultScope, streamName);
// Setup Mocks
ClientConnection connection = mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.CreateSegment request = (WireCommands.CreateSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.CreateSegment.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.GetStreamSegmentInfo request = (WireCommands.GetStreamSegmentInfo) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new WireCommands.StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
return null;
}
}).when(connection).send(Mockito.any(WireCommands.GetStreamSegmentInfo.class));
connectionFactory.provideConnection(location, connection);
MockController mockController = spy(new MockController(location.getEndpoint(), location.getPort(), connectionFactory, true));
doReturn(CompletableFuture.completedFuture(true)).when(mockController).sealStream(defaultScope, streamName);
StreamSegments empty = new StreamSegments(new TreeMap<>());
doReturn(CompletableFuture.completedFuture(empty)).when(mockController).getCurrentSegments(defaultScope, streamName);
ConnectionPoolImpl pool = new ConnectionPoolImpl(ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
// Create a StreamManager
@Cleanup final StreamManager streamManager = new StreamManagerImpl(mockController, pool);
// Create a scope and stream and seal it.
streamManager.createScope(defaultScope);
streamManager.createStream(defaultScope, streamName, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(3)).build());
streamManager.sealStream(defaultScope, streamName);
// Fetch StreamInfo
StreamInfo info = streamManager.getStreamInfo(defaultScope, streamName);
// validate results.
assertEquals(defaultScope, info.getScope());
assertEquals(streamName, info.getStreamName());
assertNotNull(info.getTailStreamCut());
assertEquals(stream, info.getTailStreamCut().asImpl().getStream());
assertEquals(0, info.getTailStreamCut().asImpl().getPositions().size());
assertNotNull(info.getHeadStreamCut());
assertEquals(stream, info.getHeadStreamCut().asImpl().getStream());
assertEquals(3, info.getHeadStreamCut().asImpl().getPositions().size());
assertTrue(info.isSealed());
}
use of io.pravega.client.stream.impl.StreamSegments in project pravega by pravega.
the class MockController method createTransaction.
@Override
public CompletableFuture<TxnSegments> createTransaction(final Stream stream, final long lease) {
UUID txId = UUID.randomUUID();
List<CompletableFuture<Void>> futures = new ArrayList<>();
StreamSegments currentSegments = getCurrentSegments(stream);
for (Segment segment : currentSegments.getSegments()) {
futures.add(createSegmentTx(txId, segment));
}
return Futures.allOf(futures).thenApply(v -> new TxnSegments(currentSegments, txId));
}
use of io.pravega.client.stream.impl.StreamSegments in project pravega by pravega.
the class MockController method getCurrentSegments.
private StreamSegments getCurrentSegments(Stream stream) {
if (isStreamSealed(stream)) {
return new StreamSegments(new TreeMap<>());
} else {
List<Segment> segmentsInStream = getSegmentsForStream(stream);
TreeMap<Double, SegmentWithRange> segments = new TreeMap<>();
for (int i = 0; i < segmentsInStream.size(); i++) {
SegmentWithRange s = createRange(stream.getScope(), stream.getStreamName(), segmentsInStream.size(), i);
segments.put(s.getRange().getHigh(), s);
}
return new StreamSegments(segments);
}
}
use of io.pravega.client.stream.impl.StreamSegments in project pravega by pravega.
the class LocalControllerTest method testGetCurrentSegments.
@Test(timeout = 10000)
public void testGetCurrentSegments() {
Controller.StreamInfo info = Controller.StreamInfo.newBuilder().setScope("scope").setStream("stream").build();
Controller.SegmentId segment1 = Controller.SegmentId.newBuilder().setSegmentId(1).setStreamInfo(info).build();
Controller.SegmentId segment2 = Controller.SegmentId.newBuilder().setSegmentId(2).setStreamInfo(info).build();
Controller.SegmentId segment3 = Controller.SegmentId.newBuilder().setSegmentId(3).setStreamInfo(info).build();
Controller.SegmentRange segmentRange1 = Controller.SegmentRange.newBuilder().setSegmentId(segment1).setMinKey(0.1).setMaxKey(0.3).build();
Controller.SegmentRange segmentRange2 = Controller.SegmentRange.newBuilder().setSegmentId(segment2).setMinKey(0.4).setMaxKey(0.6).build();
Controller.SegmentRange segmentRange3 = Controller.SegmentRange.newBuilder().setSegmentId(segment3).setMinKey(0.7).setMaxKey(1.0).build();
List<Controller.SegmentRange> segmentsList = new ArrayList<Controller.SegmentRange>(3);
segmentsList.add(segmentRange1);
segmentsList.add(segmentRange2);
segmentsList.add(segmentRange3);
when(this.mockControllerService.getCurrentSegments(eq("scope"), eq("stream"), anyLong())).thenReturn(CompletableFuture.completedFuture(segmentsList));
StreamSegments currentSegments = this.testController.getCurrentSegments("scope", "stream").join();
assertEquals(3, currentSegments.getSegments().size());
assertEquals(new Segment("scope", "stream", 1), currentSegments.getSegmentForKey(0.2));
assertEquals(new Segment("scope", "stream", 3), currentSegments.getSegmentForKey(0.9));
}
use of io.pravega.client.stream.impl.StreamSegments in project pravega by pravega.
the class ByteStreanWriterImplTest method setup.
@Before
public void setup() {
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
connectionFactory = new MockConnectionFactoryImpl();
ClientConnection connection = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, connection);
controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, false);
controller.createScope(SCOPE);
controller.createStream(SCOPE, STREAM, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
StreamSegments segments = Futures.getThrowingException(controller.getCurrentSegments(SCOPE, STREAM));
Preconditions.checkState(segments.getNumberOfSegments() > 0, "Stream is sealed");
Preconditions.checkState(segments.getNumberOfSegments() == 1, "Stream is configured with more than one segment");
Segment segment = segments.getSegments().iterator().next();
EventWriterConfig config = EventWriterConfig.builder().retryAttempts(Integer.MAX_VALUE).build();
DelegationTokenProvider tokenProvider = DelegationTokenProviderFactory.create(controller, segment, AccessOperation.WRITE);
mockWriter = new ByteStreamWriterImpl(streamFactory.createOutputStreamForSegment(segment, config, tokenProvider), streamFactory.createSegmentMetadataClient(segment, tokenProvider));
}
Aggregations