use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class JwtTokenProviderImplTest method testRetrievesNewTokenIfSignalledOfTokenExpiry.
@Test
public void testRetrievesNewTokenIfSignalledOfTokenExpiry() {
final String token = String.format("newtokenheader.%s.signature", toCompact(JwtBody.builder().expirationTime(Instant.now().plusSeconds(100000).getEpochSecond()).build()));
// Setup mock
Controller mockController = mock(Controller.class);
CompletableFuture<String> future = CompletableFuture.supplyAsync(new Supplier<String>() {
@Override
public String get() {
return token + System.currentTimeMillis();
}
});
when(mockController.getOrRefreshDelegationTokenFor("somescope", "somestream", AccessOperation.ANY)).thenReturn(future);
// Setup the object under test
DelegationTokenProvider objectUnderTest = new JwtTokenProviderImpl(mockController, "somescope", "somestream", AccessOperation.ANY);
String firstToken = objectUnderTest.retrieveToken().join();
String secondToken = objectUnderTest.retrieveToken().join();
assertEquals(firstToken, secondToken);
objectUnderTest.signalTokenExpired();
assertEquals(firstToken, objectUnderTest.retrieveToken().join());
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class JwtTokenProviderImplTest method testRefreshTokenCompletesUponFailure.
@Test(expected = CompletionException.class)
public void testRefreshTokenCompletesUponFailure() {
ClientConfig config = ClientConfig.builder().controllerURI(URI.create("tcp://non-existent-cluster:9090")).build();
@Cleanup("shutdownNow") val executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
@Cleanup Controller controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(config).retryAttempts(1).build(), executor);
DelegationTokenProvider tokenProvider = DelegationTokenProviderFactory.create(controllerClient, "bob-0", "bob-0", AccessOperation.ANY);
try {
tokenProvider.retrieveToken().join();
} catch (CompletionException e) {
assertEquals(RetriesExhaustedException.class.getName(), e.getCause().getClass().getName());
throw e;
}
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class JwtTokenProviderImplTest method testRetrievesSameTokenOutsideOfTokenRefreshThresholdWhenTokenIsNull.
@Test
public void testRetrievesSameTokenOutsideOfTokenRefreshThresholdWhenTokenIsNull() {
final String token = String.format("newtokenheader.%s.signature", toCompact(JwtBody.builder().expirationTime(Instant.now().plusSeconds(10000).getEpochSecond()).build()));
// Setup mock
Controller mockController = mock(Controller.class);
CompletableFuture<String> future = CompletableFuture.supplyAsync(new Supplier<String>() {
@Override
public String get() {
return token;
}
});
when(mockController.getOrRefreshDelegationTokenFor("somescope", "somestream", AccessOperation.ANY)).thenReturn(future);
// Setup the object under test
DelegationTokenProvider objectUnderTest = new JwtTokenProviderImpl(mockController, "somescope", "somestream", AccessOperation.ANY);
assertEquals(token, objectUnderTest.retrieveToken().join());
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class KeyValueTableFactory method withScope.
/**
* Creates a new instance of {@link KeyValueTableFactory}.
*
* @param scope The Key-Value Table scope.
* @param config Configuration for the client.
* @return Instance of {@link KeyValueTableFactory} implementation.
*/
static KeyValueTableFactory withScope(String scope, ClientConfig config) {
ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(config);
ConnectionPool connectionPool = new ConnectionPoolImpl(config, connectionFactory);
Controller controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(config).build(), connectionFactory.getInternalExecutor());
return new KeyValueTableFactoryImpl(scope, controller, connectionPool);
}
use of io.pravega.client.control.impl.Controller in project pravega by pravega.
the class ReaderGroupImpl method resetReaderGroup.
@Override
public void resetReaderGroup(ReaderGroupConfig config) {
log.info("Reset ReaderGroup {} to {}", getGroupName(), config);
synchronizer.fetchUpdates();
while (true) {
val currentConfig = synchronizer.getState().getConfig();
// We only move into the block if the state transition has happened successfully.
if (stateTransition(currentConfig, new UpdatingConfig(true))) {
if (currentConfig.getReaderGroupId() == ReaderGroupConfig.DEFAULT_UUID && currentConfig.getGeneration() == ReaderGroupConfig.DEFAULT_GENERATION) {
// Migration code path, for moving a ReaderGroup from version < 0.9 to 0.9+
final ReaderGroupConfig updateConfig = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
final long nextGen = Futures.getThrowingException(controller.createReaderGroup(scope, getGroupName(), updateConfig).thenCompose(conf -> {
if (!conf.getReaderGroupId().equals(updateConfig.getReaderGroupId())) {
return controller.updateReaderGroup(scope, groupName, ReaderGroupConfig.cloneConfig(updateConfig, conf.getReaderGroupId(), conf.getGeneration()));
} else {
// ReaderGroup IDs matched so our create was updated on Controller
return CompletableFuture.completedFuture(conf.getGeneration());
}
}));
updateConfigInStateSynchronizer(updateConfig, nextGen);
} else {
// normal code path
// Use the latest generation and reader group Id.
ReaderGroupConfig newConfig = ReaderGroupConfig.cloneConfig(config, currentConfig.getReaderGroupId(), currentConfig.getGeneration());
long newGen = Futures.exceptionallyExpecting(controller.updateReaderGroup(scope, groupName, newConfig), e -> Exceptions.unwrap(e) instanceof ReaderGroupConfigRejectedException, -1L).join();
if (newGen == -1) {
log.debug("Synchronize reader group with the one present on controller.");
synchronizeReaderGroupConfig();
continue;
}
updateConfigInStateSynchronizer(newConfig, newGen);
}
return;
}
}
}
Aggregations