use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class ReadTest method testReceivingReadCall.
@Test
public void testReceivingReadCall() throws Exception {
String segmentName = "testReceivingReadCall";
int entries = 10;
byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
UUID clientId = UUID.randomUUID();
StreamSegmentStore segmentStore = serviceBuilder.createStreamSegmentService();
fillStoreForSegment(segmentName, clientId, data, entries, segmentStore);
@Cleanup EmbeddedChannel channel = AppendTest.createChannel(segmentStore);
SegmentRead result = (SegmentRead) AppendTest.sendRequest(channel, new ReadSegment(segmentName, 0, 10000, ""));
assertEquals(result.getSegment(), segmentName);
assertEquals(result.getOffset(), 0);
assertTrue(result.isAtTail());
assertFalse(result.isEndOfSegment());
ByteBuffer expected = ByteBuffer.allocate(entries * data.length);
for (int i = 0; i < entries; i++) {
expected.put(data);
}
expected.rewind();
assertEquals(expected, result.getData());
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class ReadTest method readThroughStreamClient.
@Test
public void readThroughStreamClient() throws ReinitializationRequiredException {
String endpoint = "localhost";
String streamName = "abc";
String readerName = "reader";
String readerGroup = "group";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
String scope = "Scope1";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager(scope, endpoint, port);
MockClientFactory clientFactory = streamManager.getClientFactory();
ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().stream(Stream.of(scope, streamName)).build();
streamManager.createScope(scope);
streamManager.createStream(scope, streamName, null);
streamManager.createReaderGroup(readerGroup, groupConfig);
JavaSerializer<String> serializer = new JavaSerializer<>();
EventStreamWriter<String> producer = clientFactory.createEventWriter(streamName, serializer, EventWriterConfig.builder().build());
producer.writeEvent(testString);
producer.flush();
@Cleanup EventStreamReader<String> reader = clientFactory.createReader(readerName, readerGroup, serializer, ReaderConfig.builder().build());
String read = reader.readNextEvent(5000).getEvent();
assertEquals(testString, read);
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class ReadTest method readThroughSegmentClient.
@Test
public void readThroughSegmentClient() throws SegmentSealedException, EndOfSegmentException, SegmentTruncatedException {
String endpoint = "localhost";
String scope = "scope";
String stream = "stream";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world\n";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
server.startListening();
ConnectionFactory clientCF = new ConnectionFactoryImpl(ClientConfig.builder().build());
Controller controller = new MockController(endpoint, port, clientCF);
controller.createScope(scope);
controller.createStream(StreamConfiguration.builder().scope(scope).streamName(stream).build());
SegmentOutputStreamFactoryImpl segmentproducerClient = new SegmentOutputStreamFactoryImpl(controller, clientCF);
SegmentInputStreamFactoryImpl segmentConsumerClient = new SegmentInputStreamFactoryImpl(controller, clientCF);
Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
@Cleanup("close") SegmentOutputStream out = segmentproducerClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), "");
out.write(new PendingEvent(null, ByteBuffer.wrap(testString.getBytes()), new CompletableFuture<>()));
out.flush();
@Cleanup("close") SegmentInputStream in = segmentConsumerClient.createInputStreamForSegment(segment);
ByteBuffer result = in.read();
assertEquals(ByteBuffer.wrap(testString.getBytes()), result);
// Test large write followed by read
out.write(new PendingEvent(null, ByteBuffer.wrap(new byte[15]), new CompletableFuture<>()));
out.write(new PendingEvent(null, ByteBuffer.wrap(new byte[15]), new CompletableFuture<>()));
out.write(new PendingEvent(null, ByteBuffer.wrap(new byte[150000]), new CompletableFuture<>()));
assertEquals(in.read().capacity(), 15);
assertEquals(in.read().capacity(), 15);
assertEquals(in.read().capacity(), 150000);
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class ReaderGroupTest method testEventHandoff.
@Test(timeout = 20000)
public void testEventHandoff() throws Exception {
String endpoint = "localhost";
int servicePort = TestUtils.getAvailableListenPort();
@Cleanup ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
serviceBuilder.initialize();
StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, servicePort, store);
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager(SCOPE, endpoint, servicePort);
streamManager.createScope(SCOPE);
streamManager.createStream(SCOPE, STREAM_NAME, StreamConfiguration.builder().scope(SCOPE).streamName(STREAM_NAME).scalingPolicy(ScalingPolicy.fixed(2)).build());
@Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
ReaderGroupConfig groupConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(-1).stream(Stream.of(SCOPE, STREAM_NAME)).build();
streamManager.createReaderGroup(READER_GROUP, groupConfig);
writeEvents(100, clientFactory);
ReaderThread r1 = new ReaderThread(20, "Reader1", clientFactory);
ReaderThread r2 = new ReaderThread(80, "Reader2", clientFactory);
Thread reader1Thread = new Thread(r1);
Thread reader2Thread = new Thread(r2);
reader1Thread.start();
reader2Thread.start();
reader1Thread.join();
reader2Thread.join();
if (r1.exception.get() != null) {
throw r1.exception.get();
}
if (r2.exception.get() != null) {
throw r2.exception.get();
}
streamManager.deleteReaderGroup(READER_GROUP);
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class StateSynchronizerTest method testReadsAllAvailable.
@Test(timeout = 20000)
public void testReadsAllAvailable() {
String endpoint = "localhost";
String stateName = "abc";
int port = TestUtils.getAvailableListenPort();
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store);
server.startListening();
@Cleanup MockStreamManager streamManager = new MockStreamManager("scope", endpoint, port);
streamManager.createScope("scope");
streamManager.createStream("scope", stateName, null);
SetSynchronizer<String> setA = SetSynchronizer.createNewSet(stateName, streamManager.getClientFactory());
for (int i = 0; i < 10; i++) {
setA.add("Append: " + i);
}
SetSynchronizer<String> setB = SetSynchronizer.createNewSet(stateName, streamManager.getClientFactory());
assertEquals(10, setB.getCurrentSize());
for (int i = 10; i < 20; i++) {
setA.add("Append: " + i);
}
setB.update();
assertEquals(20, setB.getCurrentSize());
}
Aggregations