use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.
the class TaskWorkerServiceTest method testPeriodicRestartWithInflightRequest.
@Test
public void testPeriodicRestartWithInflightRequest() throws IOException {
CConfiguration cConf = createCConf();
SConfiguration sConf = createSConf();
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 10);
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_DURATION_SECOND, 2);
TaskWorkerService taskWorkerService = new TaskWorkerService(cConf, sConf, new InMemoryDiscoveryService(), (namespaceId, retryStrategy) -> null, metricsCollectionService, new CommonNettyHttpServiceFactory(cConf, metricsCollectionService));
serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService);
// start the service
taskWorkerService.startAndWait();
InetSocketAddress addr = taskWorkerService.getBindAddress();
URI uri = URI.create(String.format("http://%s:%s", addr.getHostName(), addr.getPort()));
// Post valid request
String want = "5000";
RunnableTaskRequest req = RunnableTaskRequest.getBuilder(TestRunnableClass.class.getName()).withParam(want).build();
String reqBody = GSON.toJson(req);
HttpResponse response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
Assert.assertEquals(want, response.getResponseBodyAsString());
TaskWorkerTestUtil.waitForServiceCompletion(serviceCompletionFuture);
Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state());
}
use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.
the class TaskWorkerServiceTest method testPeriodicRestart.
@Test
public void testPeriodicRestart() {
CConfiguration cConf = createCConf();
SConfiguration sConf = createSConf();
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 1);
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_DURATION_SECOND, 5);
TaskWorkerService taskWorkerService = new TaskWorkerService(cConf, sConf, new InMemoryDiscoveryService(), (namespaceId, retryStrategy) -> null, metricsCollectionService, new CommonNettyHttpServiceFactory(cConf, metricsCollectionService));
serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService);
// start the service
taskWorkerService.startAndWait();
TaskWorkerTestUtil.waitForServiceCompletion(serviceCompletionFuture);
Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state());
}
use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.
the class AppFabricServerTest method testSSL.
@Test
public void testSSL() throws IOException {
CConfiguration cConf = CConfiguration.create();
cConf.setBoolean(Constants.Security.SSL.INTERNAL_ENABLED, true);
SConfiguration sConf = SConfiguration.create();
final Injector injector = AppFabricTestHelper.getInjector(cConf, sConf);
try {
final DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
AppFabricServer appFabricServer = injector.getInstance(AppFabricServer.class);
appFabricServer.startAndWait();
Assert.assertTrue(appFabricServer.isRunning());
Supplier<EndpointStrategy> endpointStrategySupplier = Suppliers.memoize(() -> new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP)))::get;
Discoverable discoverable = endpointStrategySupplier.get().pick(3, TimeUnit.SECONDS);
Assert.assertNotNull(discoverable);
Assert.assertTrue(URIScheme.HTTPS.isMatch(discoverable));
InetSocketAddress addr = discoverable.getSocketAddress();
// Since the server uses a self signed certificate we need a client that trusts all certificates
SSLSocket socket = (SSLSocket) LDAPLoginModule.TrustAllSSLSocketFactory.getDefault().createSocket(addr.getHostName(), addr.getPort());
// in millis
socket.setSoTimeout(5000);
// Would throw exception if the server does not support ssl.
// "javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?"
socket.startHandshake();
appFabricServer.stopAndWait();
} finally {
AppFabricTestHelper.shutdown();
}
}
use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.
the class DefaultSecureStoreServiceTest method setup.
@BeforeClass
public static void setup() throws Exception {
SConfiguration sConf = SConfiguration.create();
sConf.set(Constants.Security.Store.FILE_PASSWORD, "secret");
CConfiguration cConf = createCConf();
final Injector injector = AppFabricTestHelper.getInjector(cConf, sConf);
discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
appFabricServer = injector.getInstance(AppFabricServer.class);
appFabricServer.startAndWait();
waitForService(Constants.Service.DATASET_MANAGER);
secureStore = injector.getInstance(SecureStore.class);
secureStoreManager = injector.getInstance(SecureStoreManager.class);
accessController = injector.getInstance(AccessControllerInstantiator.class).get();
// Wait for the default namespace creation
String user = AuthorizationUtil.getEffectiveMasterUser(cConf);
accessController.grant(Authorizable.fromEntityId(NamespaceId.DEFAULT), new Principal(user, Principal.PrincipalType.USER), EnumSet.allOf(StandardPermission.class));
// Starting the Appfabric server will create the default namespace
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return injector.getInstance(NamespaceAdmin.class).exists(NamespaceId.DEFAULT);
}
}, 5, TimeUnit.SECONDS);
accessController.revoke(Authorizable.fromEntityId(NamespaceId.DEFAULT), new Principal(user, Principal.PrincipalType.USER), Collections.singleton(StandardPermission.UPDATE));
}
use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.
the class TinkCipherTest method testEncryptionAndDecryption.
@Test
public void testEncryptionAndDecryption() throws CipherException, IOException, GeneralSecurityException {
SConfiguration sConf = SConfiguration.create();
sConf.set(Constants.Security.Authentication.USER_CREDENTIAL_ENCRYPTION_KEYSET, generateKeySet());
TinkCipher cipher = new TinkCipher(sConf);
byte[] plainData = generateRandomBytes(2 * 1024);
byte[] associatedData = generateRandomBytes(64);
byte[] cipherData = cipher.encrypt(plainData, associatedData);
byte[] decryptedData = cipher.decrypt(cipherData, associatedData);
Assert.assertArrayEquals(plainData, decryptedData);
String cipherDataBase64Encoded = cipher.encryptToBase64(plainData, associatedData);
decryptedData = cipher.decryptFromBase64(cipherDataBase64Encoded, associatedData);
Assert.assertArrayEquals(plainData, decryptedData);
}
Aggregations