Search in sources :

Example 16 with ClientFactoryImpl

use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.

the class RetentionTest method retentionTest.

private CompletableFuture<Void> retentionTest(String streamName, boolean sizeBased) throws Exception {
    return CompletableFuture.runAsync(() -> {
        final ClientConfig clientConfig = Utils.buildClientConfig(controllerURI);
        @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(clientConfig);
        ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(clientConfig).build(), connectionFactory.getInternalExecutor());
        @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(SCOPE, controller, connectionFactory);
        log.info("Invoking Writer test with Controller URI: {}", controllerURI);
        // create a writer
        @Cleanup EventStreamWriter<Serializable> writer = clientFactory.createEventWriter(streamName, new JavaSerializer<>(), EventWriterConfig.builder().build());
        // write an event
        String writeEvent = "event";
        writer.writeEvent(writeEvent);
        if (sizeBased) {
            // since truncation always happens at an event boundary, for size based, we will write two events,
            // so that truncation can happen at the first event.
            writer.writeEvent(writeEvent);
        }
        writer.flush();
        log.debug("Writing event: {} ", writeEvent);
        // sleep for 5 mins -- retention frequency is set to 2 minutes. So in 5 minutes we should definitely have
        // 2 retention cycles, with a stream cut being computed in first cycle and truncation happening on the
        // previously computed streamcut in second cycle.
        // for time based retention, we wrote one event, which would get truncated.
        // for size based retention we wrote two events such that stream would retain at least 1 byte as prescribed by
        // the policy
        Exceptions.handleInterrupted(() -> Thread.sleep(5 * 60 * 1000));
        // create a reader
        ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, clientConfig);
        String groupName = READER_GROUP + streamName;
        groupManager.createReaderGroup(groupName, ReaderGroupConfig.builder().disableAutomaticCheckpoints().stream(Stream.of(SCOPE, streamName)).build());
        EventStreamReader<String> reader = clientFactory.createReader(UUID.randomUUID().toString(), groupName, new JavaSerializer<>(), ReaderConfig.builder().build());
        if (sizeBased) {
            // we should read one write event back from the stream.
            String event = reader.readNextEvent(6000).getEvent();
            assertEquals(event, writeEvent);
        }
        // verify reader functionality is unaffected post truncation
        String event = "newEvent";
        writer.writeEvent(event);
        log.info("Writing event: {}", event);
        Assert.assertEquals(event, reader.readNextEvent(6000).getEvent());
        log.debug("The stream is already truncated.Simple retention test passed.");
    });
}
Also used : ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) Serializable(java.io.Serializable) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) ClientConfig(io.pravega.client.ClientConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup)

Example 17 with ClientFactoryImpl

use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.

the class AutoScaleTest method scaleUpTest.

/**
 * Invoke the simple scale up Test, produce traffic from multiple writers in parallel.
 * The test will periodically check if a scale event has occurred by talking to controller via
 * controller client.
 *
 * @throws InterruptedException if interrupted
 * @throws URISyntaxException   If URI is invalid
 */
private CompletableFuture<Void> scaleUpTest() {
    ClientFactoryImpl clientFactory = getClientFactory();
    ControllerImpl controller = getController();
    final AtomicBoolean exit = new AtomicBoolean(false);
    createWriters(clientFactory, 6, SCOPE, SCALE_UP_STREAM_NAME);
    // overall wait for test to complete in 260 seconds (4.2 minutes) or scale up, whichever happens first.
    return Retry.withExpBackoff(10, 10, 30, Duration.ofSeconds(10).toMillis()).retryingOn(ScaleOperationNotDoneException.class).throwingOn(RuntimeException.class).runAsync(() -> controller.getCurrentSegments(SCOPE, SCALE_UP_STREAM_NAME).thenAccept(x -> {
        log.debug("size ==" + x.getSegments().size());
        if (x.getSegments().size() == 1) {
            throw new ScaleOperationNotDoneException();
        } else {
            log.info("scale up done successfully");
            exit.set(true);
        }
    }), scaleExecutorService);
}
Also used : StreamImpl(io.pravega.client.stream.impl.StreamImpl) Retry(io.pravega.common.util.Retry) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) JavaSerializer(io.pravega.client.stream.impl.JavaSerializer) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) Duration(java.time.Duration) Map(java.util.Map) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Timeout(org.junit.rules.Timeout) URI(java.net.URI) Before(org.junit.Before) EventWriterConfig(io.pravega.client.stream.EventWriterConfig) Environment(io.pravega.test.system.framework.Environment) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) Slf4j(lombok.extern.slf4j.Slf4j) Rule(org.junit.Rule) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) Collections(java.util.Collections) Controller(io.pravega.client.control.impl.Controller) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Futures(io.pravega.common.concurrent.Futures) SystemTestRunner(io.pravega.test.system.framework.SystemTestRunner) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ControllerImpl(io.pravega.client.control.impl.ControllerImpl)

Example 18 with ClientFactoryImpl

use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.

the class MultiReaderTxnWriterWithFailoverTest method setup.

@Before
public void setup() {
    // Get zk details to verify if controller, SSS are running
    Service zkService = Utils.createZookeeperService();
    List<URI> zkUris = zkService.getServiceDetails();
    log.debug("Zookeeper service details: {}", zkUris);
    // get the zk ip details and pass it to  host, controller
    URI zkUri = zkUris.get(0);
    // Verify controller is running.
    controllerInstance = Utils.createPravegaControllerService(zkUri);
    assertTrue(controllerInstance.isRunning());
    List<URI> conURIs = controllerInstance.getServiceDetails();
    log.info("Pravega Controller service instance details: {}", conURIs);
    // Fetch all the RPC endpoints and construct the client URIs.
    final List<String> uris = conURIs.stream().filter(ISGRPC).map(URI::getAuthority).collect(Collectors.toList());
    controllerURIDirect = URI.create((Utils.TLS_AND_AUTH_ENABLED ? TLS : TCP) + String.join(",", uris));
    log.info("Controller Service direct URI: {}", controllerURIDirect);
    // Verify segment store is running.
    segmentStoreInstance = Utils.createPravegaSegmentStoreService(zkUri, controllerURIDirect);
    assertTrue(segmentStoreInstance.isRunning());
    log.info("Pravega Segmentstore service instance details: {}", segmentStoreInstance.getServiceDetails());
    // executor service
    executorService = ExecutorServiceHelpers.newScheduledThreadPool(NUM_READERS + NUM_WRITERS + 2, "MultiReaderTxnWriterWithFailoverTest-main");
    controllerExecutorService = ExecutorServiceHelpers.newScheduledThreadPool(2, "MultiReaderTxnWriterWithFailoverTest-controller");
    final ClientConfig clientConfig = Utils.buildClientConfig(controllerURIDirect);
    // get Controller Uri
    controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(clientConfig).maxBackoffMillis(5000).build(), controllerExecutorService);
    testState = new TestState(true);
    // read and write count variables
    streamManager = new StreamManagerImpl(clientConfig);
    createScopeAndStream(scope, STREAM_NAME, config, streamManager);
    log.info("Scope passed to client factory {}", scope);
    clientFactory = new ClientFactoryImpl(scope, controller, new SocketConnectionFactoryImpl(clientConfig));
    readerGroupManager = ReaderGroupManager.withScope(scope, clientConfig);
}
Also used : ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) Service(io.pravega.test.system.framework.services.Service) StreamManagerImpl(io.pravega.client.admin.impl.StreamManagerImpl) ClientConfig(io.pravega.client.ClientConfig) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) URI(java.net.URI) Before(org.junit.Before)

Example 19 with ClientFactoryImpl

use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.

the class OffsetTruncationTest method offsetTruncationTest.

/**
 * This test verifies that truncation works specifying an offset that applies to multiple segments. To this end,
 * the test first writes a set of events on a Stream (with multiple segments) and truncates it at a specified offset
 * (truncatedEvents). The tests asserts that readers first get a TruncatedDataException as they are attempting to
 * read a truncated segment, and then they only read the remaining events that have not been truncated.
 */
@Test
public void offsetTruncationTest() {
    final int totalEvents = 200;
    final int truncatedEvents = 50;
    final ClientConfig clientConfig = Utils.buildClientConfig(controllerURI);
    @Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(clientConfig);
    ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(clientConfig).build(), connectionFactory.getInternalExecutor());
    @Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(SCOPE, controller, connectionFactory);
    log.info("Invoking offsetTruncationTest test with Controller URI: {}", controllerURI);
    @Cleanup ReaderGroupManager groupManager = ReaderGroupManager.withScope(SCOPE, clientConfig);
    groupManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().stream(Stream.of(SCOPE, STREAM)).build());
    @Cleanup ReaderGroup readerGroup = groupManager.getReaderGroup(READER_GROUP);
    // Write events to the Stream.
    writeEvents(clientFactory, STREAM, totalEvents);
    // Instantiate readers to consume from Stream up to truncatedEvents.
    List<CompletableFuture<Integer>> futures = readEventFutures(clientFactory, READER_GROUP, PARALLELISM, truncatedEvents);
    Futures.allOf(futures).join();
    // Ensure that we have read all the events required before initiating the checkpoint.
    assertEquals("Number of events read is not the expected one.", (Integer) truncatedEvents, futures.stream().map(f -> Futures.getAndHandleExceptions(f, RuntimeException::new)).reduce(Integer::sum).get());
    // Perform truncation on stream segment.
    Checkpoint cp = readerGroup.initiateCheckpoint("truncationCheckpoint", executor).join();
    StreamCut streamCut = cp.asImpl().getPositions().values().iterator().next();
    StreamCut alternativeStreamCut = readerGroup.generateStreamCuts(executor).join().get(Stream.of(SCOPE, STREAM));
    assertEquals("StreamCuts for reader group differ depending on how they are generated.", streamCut, alternativeStreamCut);
    assertTrue(streamManager.truncateStream(SCOPE, STREAM, streamCut));
    // Just after the truncation, read events from the offset defined in truncate call onwards.
    final String newGroupName = READER_GROUP + "new";
    groupManager.createReaderGroup(newGroupName, ReaderGroupConfig.builder().stream(Stream.of(SCOPE, STREAM)).build());
    futures = readEventFutures(clientFactory, newGroupName, PARALLELISM);
    Futures.allOf(futures).join();
    assertEquals("Expected read events: ", totalEvents - truncatedEvents, (int) futures.stream().map(CompletableFuture::join).reduce(Integer::sum).get());
    log.debug("The stream has been successfully truncated at event {}. Offset truncation test passed.", truncatedEvents);
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) MarathonException(mesosphere.marathon.client.MarathonException) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) StreamManager(io.pravega.client.admin.StreamManager) RunWith(org.junit.runner.RunWith) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) ReaderGroup(io.pravega.client.stream.ReaderGroup) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Service(io.pravega.test.system.framework.services.Service) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) Stream(io.pravega.client.stream.Stream) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Timeout(org.junit.rules.Timeout) Checkpoint(io.pravega.client.stream.Checkpoint) URI(java.net.URI) Utils(io.pravega.test.system.framework.Utils) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) Before(org.junit.Before) Environment(io.pravega.test.system.framework.Environment) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ControllerImplConfig(io.pravega.client.control.impl.ControllerImplConfig) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Rule(org.junit.Rule) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) RandomFactory(io.pravega.common.hash.RandomFactory) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) Futures(io.pravega.common.concurrent.Futures) SystemTestRunner(io.pravega.test.system.framework.SystemTestRunner) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConfig(io.pravega.client.ClientConfig) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) StreamCut(io.pravega.client.stream.StreamCut) ReaderGroup(io.pravega.client.stream.ReaderGroup) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) Cleanup(lombok.Cleanup) Checkpoint(io.pravega.client.stream.Checkpoint) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) CompletableFuture(java.util.concurrent.CompletableFuture) Checkpoint(io.pravega.client.stream.Checkpoint) ClientConfig(io.pravega.client.ClientConfig) Test(org.junit.Test)

Example 20 with ClientFactoryImpl

use of io.pravega.client.stream.impl.ClientFactoryImpl in project pravega by pravega.

the class ReadTxnWriteScaleWithFailoverTest method setup.

@Before
public void setup() {
    // Get zk details to verify if controller, segmentstore are running
    Service zkService = Utils.createZookeeperService();
    List<URI> zkUris = zkService.getServiceDetails();
    log.debug("Zookeeper service details: {}", zkUris);
    // get the zk ip details and pass it to  host, controller
    URI zkUri = zkUris.get(0);
    // Verify controller is running.
    controllerInstance = Utils.createPravegaControllerService(zkUri);
    assertTrue(controllerInstance.isRunning());
    List<URI> conURIs = controllerInstance.getServiceDetails();
    log.info("Pravega Controller service instance details: {}", conURIs);
    // Fetch all the RPC endpoints and construct the client URIs.
    final List<String> uris = conURIs.stream().filter(ISGRPC).map(URI::getAuthority).collect(Collectors.toList());
    controllerURIDirect = URI.create((Utils.TLS_AND_AUTH_ENABLED ? TLS : TCP) + String.join(",", uris));
    log.info("Controller Service direct URI: {}", controllerURIDirect);
    // Verify segment store is running.
    segmentStoreInstance = Utils.createPravegaSegmentStoreService(zkUri, controllerURIDirect);
    assertTrue(segmentStoreInstance.isRunning());
    log.info("Pravega Segmentstore service instance details: {}", segmentStoreInstance.getServiceDetails());
    // num. of readers + num. of writers + 1 to run checkScale operation
    executorService = ExecutorServiceHelpers.newScheduledThreadPool(NUM_READERS + NUM_WRITERS + 1, "ReadTxnWriteScaleWithFailoverTest-main");
    controllerExecutorService = ExecutorServiceHelpers.newScheduledThreadPool(2, "ReadTxnWriteScaleWithFailoverTest-controller");
    ClientConfig clientConfig = Utils.buildClientConfig(controllerURIDirect);
    // get Controller Uri
    controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(clientConfig).maxBackoffMillis(5000).build(), controllerExecutorService);
    testState = new TestState(true);
    streamManager = new StreamManagerImpl(clientConfig);
    createScopeAndStream(scope, stream, config, streamManager);
    log.info("Scope passed to client factory {}", scope);
    clientFactory = new ClientFactoryImpl(scope, controller, clientConfig);
    readerGroupManager = ReaderGroupManager.withScope(scope, clientConfig);
}
Also used : ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) Service(io.pravega.test.system.framework.services.Service) StreamManagerImpl(io.pravega.client.admin.impl.StreamManagerImpl) ClientConfig(io.pravega.client.ClientConfig) URI(java.net.URI) Before(org.junit.Before)

Aggregations

ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)80 Test (org.junit.Test)63 Cleanup (lombok.Cleanup)59 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)54 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)50 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)44 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)40 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)39 ClientConfig (io.pravega.client.ClientConfig)37 Stream (io.pravega.client.stream.Stream)27 Controller (io.pravega.client.control.impl.Controller)25 StreamImpl (io.pravega.client.stream.impl.StreamImpl)24 HashMap (java.util.HashMap)23 ReaderGroup (io.pravega.client.stream.ReaderGroup)19 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)19 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)19 EventWriterConfig (io.pravega.client.stream.EventWriterConfig)18 URI (java.net.URI)18 CompletableFuture (java.util.concurrent.CompletableFuture)18 ControllerImpl (io.pravega.client.control.impl.ControllerImpl)17