use of io.pravega.client.stream.mock.MockConnectionFactoryImpl 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));
}
use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.
the class BatchClientImplTest method testGetSegmentsWithStreamCut.
@Test(timeout = 5000)
public void testGetSegmentsWithStreamCut() throws Exception {
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
MockConnectionFactoryImpl connectionFactory = getMockConnectionFactory(location);
MockController mockController = new MockController(location.getEndpoint(), location.getPort(), connectionFactory, false);
Stream stream = createStream(SCOPE, STREAM, 3, mockController);
@Cleanup BatchClientFactoryImpl client = new BatchClientFactoryImpl(mockController, ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
Iterator<SegmentRange> boundedSegments = client.getSegments(stream, getStreamCut(5L, 0, 1, 2), getStreamCut(15L, 0, 1, 2)).getIterator();
assertTrue(boundedSegments.hasNext());
assertEquals(0L, boundedSegments.next().asImpl().getSegment().getSegmentId());
assertTrue(boundedSegments.hasNext());
assertEquals(1L, boundedSegments.next().asImpl().getSegment().getSegmentId());
assertTrue(boundedSegments.hasNext());
assertEquals(2L, boundedSegments.next().asImpl().getSegment().getSegmentId());
assertFalse(boundedSegments.hasNext());
}
use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.
the class BatchClientImplTest method testGetSegmentsWithMultipleSegments.
@Test(timeout = 5000)
public void testGetSegmentsWithMultipleSegments() throws Exception {
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
@Cleanup MockConnectionFactoryImpl connectionFactory = getMockConnectionFactory(location);
MockController mockController = new MockController(location.getEndpoint(), location.getPort(), connectionFactory, false);
MockController stubbedController = spy(mockController);
Stream stream = createStream(SCOPE, STREAM, 2, stubbedController);
Set<Segment> segments = ImmutableSet.<Segment>builder().add(new Segment(SCOPE, STREAM, 0L), new Segment(SCOPE, STREAM, 1L), new Segment(SCOPE, STREAM, 2L)).build();
// Setup mock.
doReturn(CompletableFuture.completedFuture(new StreamSegmentSuccessors(segments, ""))).when(stubbedController).getSegments(any(StreamCut.class), any(StreamCut.class));
@Cleanup BatchClientFactoryImpl client = new BatchClientFactoryImpl(stubbedController, ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
Iterator<SegmentRange> segmentIterator = client.getSegments(stream, null, null).getIterator();
assertTrue(segmentIterator.hasNext());
assertEquals(0L, segmentIterator.next().asImpl().getSegment().getSegmentId());
assertTrue(segmentIterator.hasNext());
assertEquals(1L, segmentIterator.next().asImpl().getSegment().getSegmentId());
assertTrue(segmentIterator.hasNext());
assertEquals(2L, segmentIterator.next().asImpl().getSegment().getSegmentId());
assertFalse(segmentIterator.hasNext());
}
use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.
the class BatchClientImplTest method testGetSegmentsWithNullStreamCut.
@Test(timeout = 5000)
public void testGetSegmentsWithNullStreamCut() throws Exception {
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
@Cleanup MockConnectionFactoryImpl connectionFactory = getMockConnectionFactory(location);
MockController mockController = new MockController(location.getEndpoint(), location.getPort(), connectionFactory, false);
Stream stream = createStream(SCOPE, STREAM, 3, mockController);
@Cleanup BatchClientFactoryImpl client = new BatchClientFactoryImpl(mockController, ClientConfig.builder().maxConnectionsPerSegmentStore(1).build(), connectionFactory);
Iterator<SegmentRange> segments = client.getSegments(stream, null, null).getIterator();
assertTrue(segments.hasNext());
assertEquals(0L, segments.next().asImpl().getSegment().getSegmentId());
assertTrue(segments.hasNext());
assertEquals(1L, segments.next().asImpl().getSegment().getSegmentId());
assertTrue(segments.hasNext());
assertEquals(2L, segments.next().asImpl().getSegment().getSegmentId());
assertFalse(segments.hasNext());
}
use of io.pravega.client.stream.mock.MockConnectionFactoryImpl in project pravega by pravega.
the class ByteStreamWriterTest 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();
clientFactory = new ByteStreamClientImpl(SCOPE, controller, connectionFactory, streamFactory, streamFactory, streamFactory);
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");
}
Aggregations