use of io.pravega.client.segment.impl.NoSuchEventException in project pravega by pravega.
the class ReadTest method testEventPointer.
@Test(timeout = 10000)
public void testEventPointer() throws ReinitializationRequiredException {
String endpoint = "localhost";
String streamName = "abc";
String readerName = "reader";
String readerGroup = "group";
int port = TestUtils.getAvailableListenPort();
String testString = "Hello world ";
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().disableAutomaticCheckpoints().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());
for (int i = 0; i < 100; i++) {
producer.writeEvent(testString + i);
}
producer.flush();
@Cleanup EventStreamReader<String> reader = clientFactory.createReader(readerName, readerGroup, serializer, ReaderConfig.builder().build());
try {
EventPointer pointer;
String read;
for (int i = 0; i < 100; i++) {
pointer = reader.readNextEvent(5000).getEventPointer();
read = reader.fetchEvent(pointer);
assertEquals(testString + i, read);
}
} catch (NoSuchEventException e) {
fail("Failed to read event using event pointer");
}
}
use of io.pravega.client.segment.impl.NoSuchEventException in project pravega by pravega.
the class EventStreamReaderImpl method fetchEvent.
@Override
public Type fetchEvent(EventPointer pointer) throws NoSuchEventException {
Preconditions.checkNotNull(pointer);
// Create SegmentInputStream
@Cleanup SegmentInputStream inputStream = inputStreamFactory.createInputStreamForSegment(pointer.asImpl().getSegment(), pointer.asImpl().getEventLength());
inputStream.setOffset(pointer.asImpl().getEventStartOffset());
// Read event
try {
ByteBuffer buffer = inputStream.read();
Type result = deserializer.deserialize(buffer);
return result;
} catch (EndOfSegmentException e) {
throw new NoSuchEventException(e.getMessage());
} catch (NoSuchSegmentException | SegmentTruncatedException e) {
throw new NoSuchEventException("Event no longer exists.");
}
}
Aggregations