use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.
the class DelegationTokenTest method testBatchClientDelegationTokenRenewal.
/**
* This test verifies that a batch client continues to read events as a result of automatic delegation token
* renewal, after the initial delegation token it uses expires.
* <p>
* We use an extraordinarily high test timeout and read timeouts to account for any inordinate delays that may be
* encountered in testing environments.
*/
@Test(timeout = 50000)
public void testBatchClientDelegationTokenRenewal() throws InterruptedException {
// Delegation token renewal threshold is 5 seconds, so we are using 6 seconds as Token TTL so that token doesn't
// get renewed before each use.
@Cleanup ClusterWrapper pravegaCluster = ClusterWrapper.builder().authEnabled(true).tokenTtlInSeconds(6).build();
pravegaCluster.start();
final String scope = "testscope";
final String streamName = "teststream";
final ClientConfig clientConfig = ClientConfig.builder().controllerURI(URI.create(pravegaCluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "admin")).build();
log.debug("Done creating client config.");
// Create Scope and Stream.
createScopeStream(scope, streamName, 1, clientConfig);
// write ten Events.
writeTenEvents(scope, streamName, clientConfig);
// Now, read the events from the stream using Batch client.
@Cleanup BatchClientFactory batchClientFactory = BatchClientFactory.withScope(scope, clientConfig);
List<SegmentRange> segmentRanges = Lists.newArrayList(batchClientFactory.getSegments(Stream.of(scope, streamName), StreamCut.UNBOUNDED, StreamCut.UNBOUNDED).getIterator());
assertEquals("The number of segments in the stream is 1", 1, segmentRanges.size());
SegmentIterator<String> segmentIterator = batchClientFactory.readSegment(segmentRanges.get(0), new JavaSerializer<>());
int eventReadCount = 0;
while (segmentIterator.hasNext()) {
// We are keeping sleep time relatively large, just to make sure that the delegation token expires
// midway.
Thread.sleep(500);
String event = segmentIterator.next();
log.debug("Done reading event {}", event);
eventReadCount++;
}
// Assert that we end up reading 10 events even though delegation token must have expired midway.
//
// To look for evidence of delegation token renewal check the logs for the following message:
// - "Token is nearing expiry, so refreshing it"
assertEquals(10, eventReadCount);
}
use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.
the class ControllerGrpcListStreamsTest method testListStreamsReturnsAuthorizedStreamsOnly.
@Test
public void testListStreamsReturnsAuthorizedStreamsOnly() {
// Arrange
Map<String, String> passwordInputFileEntries = new HashMap<>();
passwordInputFileEntries.put("admin", "prn::*,READ_UPDATE");
passwordInputFileEntries.put("user", "prn::/scope:scope1,READ;prn::/scope:scope1/stream:stream1,READ");
@Cleanup ClusterWrapper cluster = ClusterWrapper.builder().authEnabled(true).passwordAuthHandlerEntries(this.preparePasswordInputFileEntries(passwordInputFileEntries)).build();
cluster.start();
String scopeName = "scope1";
this.createStreams(ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "admin")).build(), scopeName, Arrays.asList("stream1", "stream2", "stream3"));
// Act
Set<Stream> streams = listStreams(ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "user")).build(), scopeName);
// Assert
assertEquals(1, streams.size());
}
use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.
the class ControllerGrpcListStreamsTest method testListStreamsReturnsAllStreamsWhenAuthIsDisabled.
@Test
public void testListStreamsReturnsAllStreamsWhenAuthIsDisabled() {
// Arrange
@Cleanup ClusterWrapper cluster = ClusterWrapper.builder().build();
cluster.start();
String scopeName = "test-scope";
ClientConfig clientConfig = ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).build();
this.createStreams(clientConfig, scopeName, Arrays.asList("stream1", "stream2"));
// Act
Set<Stream> streams = listStreams(clientConfig, scopeName);
// Assert
assertEquals(4, streams.size());
}
use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.
the class ControllerGrpcListStreamsTest method testListStreamsReturnsAuthorizedStreamsForCustomPlugin.
@Test
public void testListStreamsReturnsAuthorizedStreamsForCustomPlugin() {
ClusterWrapper cluster = null;
try {
// Arrange
cluster = ClusterWrapper.builder().authEnabled(true).build();
cluster.start();
String scopeName = "test-scope";
this.createStreams(ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "admin")).build(), scopeName, Arrays.asList("stream1", "stream2"));
// Act
System.setProperty("pravega.client.auth.loadDynamic", "true");
System.setProperty("pravega.client.auth.method", TestAuthHandler.METHOD);
System.setProperty("pravega.client.auth.token", TestAuthHandler.TOKEN);
Set<Stream> streams = listStreams(ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).build(), scopeName);
// Assert
assertEquals(4, streams.size());
} finally {
System.clearProperty("pravega.client.auth.loadDynamic");
System.clearProperty("pravega.client.auth.method");
System.clearProperty("pravega.client.auth.token");
if (cluster != null) {
cluster.close();
}
}
}
use of io.pravega.test.integration.demo.ClusterWrapper in project pravega by pravega.
the class ControllerGrpcListStreamsTest method testListStreamsReturnsAllStreamsForPrivilegedUserWhenAuthIsEnabled.
@Test
public void testListStreamsReturnsAllStreamsForPrivilegedUserWhenAuthIsEnabled() {
// Arrange
@Cleanup ClusterWrapper cluster = ClusterWrapper.builder().authEnabled(true).tokenTtlInSeconds(600).build();
cluster.start();
String scopeName = "test-scope";
ClientConfig clientConfig = ClientConfig.builder().controllerURI(URI.create(cluster.controllerUri())).credentials(new DefaultCredentials("1111_aaaa", "admin")).build();
this.createStreams(clientConfig, scopeName, Arrays.asList("stream1", "stream2"));
// Act
Set<Stream> streams = listStreams(clientConfig, scopeName);
// Assert
assertEquals(4, streams.size());
}
Aggregations