use of io.pravega.client.stream.ReinitializationRequiredException in project pravega by pravega.
the class EventStreamReaderTest method testRestore.
@Test(timeout = 10000)
public void testRestore() throws SegmentSealedException, ReinitializationRequiredException {
AtomicLong clock = new AtomicLong();
MockSegmentStreamFactory segmentStreamFactory = new MockSegmentStreamFactory();
Orderer orderer = new Orderer();
ReaderGroupStateManager groupState = Mockito.mock(ReaderGroupStateManager.class);
EventStreamReaderImpl<byte[]> reader = new EventStreamReaderImpl<>(segmentStreamFactory, segmentStreamFactory, new ByteArraySerializer(), groupState, orderer, clock::get, ReaderConfig.builder().build());
Segment segment = Segment.fromScopedName("Foo/Bar/0");
Mockito.when(groupState.acquireNewSegmentsIfNeeded(0L)).thenReturn(ImmutableMap.of(segment, 0L)).thenReturn(Collections.emptyMap());
SegmentOutputStream stream = segmentStreamFactory.createOutputStreamForSegment(segment, segmentSealedCallback, writerConfig, "");
ByteBuffer buffer = writeInt(stream, 1);
Mockito.when(groupState.getCheckpoint()).thenThrow(new ReinitializationRequiredException());
try {
reader.readNextEvent(0);
fail();
} catch (ReinitializationRequiredException e) {
// expected
}
assertTrue(reader.getReaders().isEmpty());
reader.close();
}
use of io.pravega.client.stream.ReinitializationRequiredException in project pravega by pravega.
the class PravegaTest method simpleTest.
/**
* Invoke the simpleTest, ensure we are able to produce events.
* The test fails incase of exceptions while writing to the stream.
*
* @throws InterruptedException if interrupted
* @throws URISyntaxException If URI is invalid
*/
@Test(timeout = 10 * 60 * 1000)
public void simpleTest() throws InterruptedException {
Service conService = Utils.createPravegaControllerService(null);
List<URI> ctlURIs = conService.getServiceDetails();
URI controllerUri = ctlURIs.get(0);
@Cleanup ClientFactory clientFactory = ClientFactory.withScope(STREAM_SCOPE, ClientConfig.builder().controllerURI(controllerUri).build());
log.info("Invoking Writer test with Controller URI: {}", controllerUri);
@Cleanup EventStreamWriter<Serializable> writer = clientFactory.createEventWriter(STREAM_NAME, new JavaSerializer<>(), EventWriterConfig.builder().build());
for (int i = 0; i < NUM_EVENTS; i++) {
String event = "Publish " + i + "\n";
log.debug("Producing event: {} ", event);
writer.writeEvent("", event);
writer.flush();
Thread.sleep(500);
}
log.info("Invoking Reader test.");
ReaderGroupManager groupManager = ReaderGroupManager.withScope(STREAM_SCOPE, ClientConfig.builder().controllerURI(controllerUri).build());
groupManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().stream(Stream.of(STREAM_SCOPE, STREAM_NAME)).build());
EventStreamReader<String> reader = clientFactory.createReader(UUID.randomUUID().toString(), READER_GROUP, new JavaSerializer<>(), ReaderConfig.builder().build());
for (int i = 0; i < NUM_EVENTS; i++) {
try {
String event = reader.readNextEvent(6000).getEvent();
if (event != null) {
log.debug("Read event: {} ", event);
}
} catch (ReinitializationRequiredException e) {
log.error("Unexpected request to reinitialize {}", e);
System.exit(0);
}
}
reader.close();
groupManager.deleteReaderGroup(READER_GROUP);
}
use of io.pravega.client.stream.ReinitializationRequiredException in project pravega by pravega.
the class ReaderCheckpointTest method readEvents.
private <T extends Serializable> List<EventRead<T>> readEvents(final String readerId) {
List<EventRead<T>> events = new ArrayList<>();
try (ClientFactory clientFactory = ClientFactory.withScope(SCOPE, controllerURI);
EventStreamReader<T> reader = clientFactory.createReader(readerId, READER_GROUP_NAME, new JavaSerializer<T>(), readerConfig)) {
log.info("Reading events from {}/{} with readerId: {}", SCOPE, STREAM, readerId);
EventRead<T> event = null;
do {
try {
event = reader.readNextEvent(READ_TIMEOUT);
if (event.getEvent() != null) {
log.info("Read event {}", event.getEvent());
events.add(event);
}
if (event.isCheckpoint()) {
log.info("Read a check point event, checkpointName: {}", event.getCheckpointName());
}
} catch (ReinitializationRequiredException e) {
log.error("Exception while reading event using readerId: {}", readerId, e);
fail("Reinitialization Exception is not expected");
}
} while (event.isCheckpoint() || event.getEvent() != null);
// stop reading if event read(non-checkpoint) is null.
log.info("No more events from {}/{} for readerId: {}", SCOPE, STREAM, readerId);
}
// reader.close() will automatically invoke ReaderGroup#readerOffline(String, Position)
return events;
}
use of io.pravega.client.stream.ReinitializationRequiredException in project pravega by pravega.
the class ReaderCheckpointTest method createCheckPointAndVerify.
private Checkpoint createCheckPointAndVerify(final ReaderGroup readerGroup, final String checkPointName) {
log.info("Create and verify check point {}", checkPointName);
String readerId = "checkPointReader";
CompletableFuture<Checkpoint> checkpoint = null;
try (ClientFactory clientFactory = ClientFactory.withScope(SCOPE, controllerURI);
EventStreamReader<Integer> reader = clientFactory.createReader(readerId, READER_GROUP_NAME, new JavaSerializer<Integer>(), readerConfig)) {
// create checkpoint
checkpoint = readerGroup.initiateCheckpoint(checkPointName, executor);
// verify checkpoint event.
EventRead<Integer> event = reader.readNextEvent(READ_TIMEOUT);
assertTrue("Read for Checkpoint event", (event != null) && (event.isCheckpoint()));
assertEquals("CheckPoint Name", checkPointName, event.getCheckpointName());
} catch (ReinitializationRequiredException e) {
log.error("Exception while reading event using readerId: {}", readerId, e);
fail("Reinitialization Exception is not expected");
}
return checkpoint.join();
}
use of io.pravega.client.stream.ReinitializationRequiredException in project pravega by pravega.
the class RetentionTest method retentionTest.
@Test
public void retentionTest() throws Exception {
ConnectionFactory connectionFactory = new ConnectionFactoryImpl(ClientConfig.builder().build());
ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(controllerURI).build()).build(), connectionFactory.getInternalExecutor());
ClientFactory clientFactory = new ClientFactoryImpl(SCOPE, controller);
log.info("Invoking Writer test with Controller URI: {}", controllerURI);
// create a writer
EventStreamWriter<Serializable> writer = clientFactory.createEventWriter(STREAM, new JavaSerializer<>(), EventWriterConfig.builder().build());
// write an event
String writeEvent = "event";
writer.writeEvent(writeEvent);
writer.flush();
log.debug("Writing event: {} ", writeEvent);
// sleep for 4 mins
Exceptions.handleInterrupted(() -> Thread.sleep(5 * 60 * 1000));
// create a reader
ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, controllerURI);
groupManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(SCOPE, STREAM)).build());
EventStreamReader<String> reader = clientFactory.createReader(UUID.randomUUID().toString(), READER_GROUP, new JavaSerializer<>(), ReaderConfig.builder().build());
// expectation is it should have been truncated and we should find stream to be empty
try {
String readEvent = reader.readNextEvent(6000).getEvent();
log.debug("Reading event: {} ", readEvent);
assertEquals(null, readEvent);
} catch (ReinitializationRequiredException e) {
log.error("Unexpected request to reinitialize {}", e);
Assert.fail("Unexpected request to reinitialize.Test failed.");
}
log.debug("The stream is already truncated.Simple retention test passed.");
}
Aggregations