Search in sources :

Example 11 with ReinitializationRequiredException

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();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ReinitializationRequiredException(io.pravega.client.stream.ReinitializationRequiredException) SegmentOutputStream(io.pravega.client.segment.impl.SegmentOutputStream) MockSegmentStreamFactory(io.pravega.client.stream.mock.MockSegmentStreamFactory) ByteBuffer(java.nio.ByteBuffer) Segment(io.pravega.client.segment.impl.Segment) Test(org.junit.Test)

Example 12 with ReinitializationRequiredException

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);
}
Also used : Serializable(java.io.Serializable) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) ClientFactory(io.pravega.client.ClientFactory) Service(io.pravega.test.system.framework.services.Service) URI(java.net.URI) Cleanup(lombok.Cleanup) ReinitializationRequiredException(io.pravega.client.stream.ReinitializationRequiredException) Test(org.junit.Test)

Example 13 with ReinitializationRequiredException

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;
}
Also used : EventRead(io.pravega.client.stream.EventRead) ReinitializationRequiredException(io.pravega.client.stream.ReinitializationRequiredException) ArrayList(java.util.ArrayList) ClientFactory(io.pravega.client.ClientFactory)

Example 14 with ReinitializationRequiredException

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();
}
Also used : Checkpoint(io.pravega.client.stream.Checkpoint) ReinitializationRequiredException(io.pravega.client.stream.ReinitializationRequiredException) ClientFactory(io.pravega.client.ClientFactory)

Example 15 with ReinitializationRequiredException

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.");
}
Also used : ConnectionFactory(io.pravega.client.netty.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) Serializable(java.io.Serializable) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) ReinitializationRequiredException(io.pravega.client.stream.ReinitializationRequiredException) ControllerImpl(io.pravega.client.stream.impl.ControllerImpl) ClientFactory(io.pravega.client.ClientFactory) ConnectionFactoryImpl(io.pravega.client.netty.impl.ConnectionFactoryImpl) Test(org.junit.Test)

Aggregations

ReinitializationRequiredException (io.pravega.client.stream.ReinitializationRequiredException)15 ClientFactory (io.pravega.client.ClientFactory)5 ArrayList (java.util.ArrayList)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 Cleanup (lombok.Cleanup)4 Test (org.junit.Test)4 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)3 Segment (io.pravega.client.segment.impl.Segment)3 Serializable (java.io.Serializable)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Checkpoint (io.pravega.client.stream.Checkpoint)2 AcquireSegment (io.pravega.client.stream.impl.ReaderGroupState.AcquireSegment)2 CreateCheckpoint (io.pravega.client.stream.impl.ReaderGroupState.CreateCheckpoint)2 ReaderGroupStateUpdate (io.pravega.client.stream.impl.ReaderGroupState.ReaderGroupStateUpdate)2 ReleaseSegment (io.pravega.client.stream.impl.ReaderGroupState.ReleaseSegment)2 UpdateDistanceToTail (io.pravega.client.stream.impl.ReaderGroupState.UpdateDistanceToTail)2 URI (java.net.URI)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 StreamManager (io.pravega.client.admin.StreamManager)1 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)1