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();
}
}
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);
}
Aggregations