Search in sources :

Example 11 with ClusterWrapper

use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.

the class DelegationTokenTest method writeAnEvent.

private void writeAnEvent(int tokenTtlInSeconds) throws ExecutionException, InterruptedException {
    ClusterWrapper pravegaCluster = ClusterWrapper.builder().authEnabled(true).tokenTtlInSeconds(600).build();
    try {
        pravegaCluster.start();
        String scope = "testscope";
        String streamName = "teststream";
        int numSegments = 1;
        String message = "test message";
        ClientConfig clientConfig = ClientConfig.builder().controllerURI(URI.create(pravegaCluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "admin")).build();
        log.debug("Done creating client config.");
        createScopeStream(scope, streamName, numSegments, clientConfig);
        @Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(scope, clientConfig);
        @Cleanup EventStreamWriter<String> writer = clientFactory.createEventWriter(streamName, new JavaSerializer<String>(), EventWriterConfig.builder().build());
        // Note: A TokenException is thrown here if token verification fails on the server.
        writer.writeEvent(message).get();
        log.debug("Done writing message '{}' to stream '{} / {}'", message, scope, streamName);
    } finally {
        pravegaCluster.close();
    }
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ClusterWrapper(io.pravega.test.integration.demo.ClusterWrapper) EventStreamClientFactory(io.pravega.client.EventStreamClientFactory) ClientConfig(io.pravega.client.ClientConfig) Cleanup(lombok.Cleanup)

Example 12 with ClusterWrapper

use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.

the class ClusterWrapperTest method writeAndReadBackAMessageWithSecurityOff.

@Test
public void writeAndReadBackAMessageWithSecurityOff() {
    String scopeName = "testScope";
    String streamName = "testStream";
    String readerGroupName = "testReaderGroup";
    String testMessage = "test message";
    // Instantiate and run the cluster. By default, TLS and Auth are off. Also, by default Controller REST
    // interface is disabled.
    @Cleanup ClusterWrapper cluster = ClusterWrapper.builder().build();
    // Checking that the cluster has default settings.
    assertFalse(cluster.isAuthEnabled());
    assertTrue(cluster.isRgWritesWithReadPermEnabled());
    assertEquals(600, cluster.getTokenTtlInSeconds());
    assertEquals(4, cluster.getContainerCount());
    assertTrue(cluster.getTokenSigningKeyBasis().length() > 0);
    assertEquals(-1, cluster.getControllerRestPort());
    cluster.start();
    // Write an event to the stream
    final ClientConfig writerClientConfig = ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).build();
    TestUtils.createScopeAndStreams(writerClientConfig, scopeName, Arrays.asList(streamName));
    TestUtils.writeDataToStream(scopeName, streamName, testMessage, writerClientConfig);
    // Read back the event from the stream and verify it is the same as what was written
    final ClientConfig readerClientConfig = ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).build();
    String readMessage = TestUtils.readNextEventMessage(scopeName, streamName, readerClientConfig, readerGroupName);
    assertEquals(testMessage, readMessage);
}
Also used : ClusterWrapper(io.pravega.test.integration.demo.ClusterWrapper) ClientConfig(io.pravega.client.ClientConfig) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Aggregations

ClusterWrapper (io.pravega.test.integration.demo.ClusterWrapper)12 Cleanup (lombok.Cleanup)11 ClientConfig (io.pravega.client.ClientConfig)10 Test (org.junit.Test)10 DefaultCredentials (io.pravega.shared.security.auth.DefaultCredentials)9 Stream (io.pravega.client.stream.Stream)4 HashMap (java.util.HashMap)4 EventStreamClientFactory (io.pravega.client.EventStreamClientFactory)3 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)2 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)2 SneakyThrows (lombok.SneakyThrows)2 BatchClientFactory (io.pravega.client.BatchClientFactory)1 SegmentRange (io.pravega.client.batch.SegmentRange)1 EventStreamWriter (io.pravega.client.stream.EventStreamWriter)1 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)1 KeyStore (java.security.KeyStore)1 SSLContext (javax.net.ssl.SSLContext)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1 Invocation (javax.ws.rs.client.Invocation)1 WebTarget (javax.ws.rs.client.WebTarget)1