use of org.apache.twill.discovery.InMemoryDiscoveryService in project hive by apache.
the class TephraHBaseConnection method connect.
@Override
public void connect() throws IOException {
super.connect();
if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_IN_TEST)) {
LOG.debug("Using an in memory client transaction system for testing");
TransactionManager txnMgr = new TransactionManager(conf);
txnMgr.startAndWait();
txnClient = new InMemoryTxSystemClient(txnMgr);
} else {
// TODO should enable use of ZKDiscoveryService if users want it
LOG.debug("Using real client transaction system for production");
txnClient = new TransactionServiceClient(conf, new ThreadLocalClientProvider(conf, new InMemoryDiscoveryService()));
}
for (String tableName : HBaseReadWrite.tableNames) {
txnTables.put(tableName, new TransactionAwareHTable(super.getHBaseTable(tableName, true)));
}
txn = new TransactionContext(txnClient, txnTables.values());
}
use of org.apache.twill.discovery.InMemoryDiscoveryService in project cdap by caskdata.
the class UGIProviderTest method testRemoteUGIProvider.
@Test
public void testRemoteUGIProvider() throws Exception {
// Starts a mock server to handle remote UGI requests
final NettyHttpService httpService = NettyHttpService.builder("remoteUGITest").addHttpHandlers(Collections.singleton(new UGIProviderTestHandler())).build();
httpService.startAndWait();
setKeytabDir(localKeytabDirPath.getAbsolutePath());
OwnerAdmin ownerAdmin = getOwnerAdmin();
// add an owner for stream
ownerAdmin.add(aliceEntity, aliceKerberosPrincipalId);
try {
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
discoveryService.register(new Discoverable(Constants.Service.APP_FABRIC_HTTP, httpService.getBindAddress()));
RemoteUGIProvider ugiProvider = new RemoteUGIProvider(cConf, discoveryService, locationFactory);
ImpersonationRequest aliceImpRequest = new ImpersonationRequest(aliceEntity, ImpersonatedOpType.OTHER);
UGIWithPrincipal aliceUGIWithPrincipal = ugiProvider.getConfiguredUGI(aliceImpRequest);
// Shouldn't be a kerberos UGI
Assert.assertFalse(aliceUGIWithPrincipal.getUGI().hasKerberosCredentials());
// Validate the credentials
Token<? extends TokenIdentifier> token = aliceUGIWithPrincipal.getUGI().getCredentials().getToken(new Text("entity"));
Assert.assertArrayEquals(aliceEntity.toString().getBytes(StandardCharsets.UTF_8), token.getIdentifier());
Assert.assertArrayEquals(aliceEntity.toString().getBytes(StandardCharsets.UTF_8), token.getPassword());
Assert.assertEquals(new Text("entity"), token.getKind());
Assert.assertEquals(new Text("service"), token.getService());
token = aliceUGIWithPrincipal.getUGI().getCredentials().getToken(new Text("opType"));
Assert.assertArrayEquals(aliceImpRequest.getImpersonatedOpType().toString().getBytes(StandardCharsets.UTF_8), token.getIdentifier());
Assert.assertArrayEquals(aliceImpRequest.getImpersonatedOpType().toString().getBytes(StandardCharsets.UTF_8), token.getPassword());
Assert.assertEquals(new Text("opType"), token.getKind());
Assert.assertEquals(new Text("service"), token.getService());
// Fetch it again, it should return the same UGI due to caching
Assert.assertSame(aliceUGIWithPrincipal, ugiProvider.getConfiguredUGI(aliceImpRequest));
// Invalid the cache and fetch it again. A different UGI should be returned
ugiProvider.invalidCache();
Assert.assertNotSame(aliceUGIWithPrincipal, ugiProvider.getConfiguredUGI(aliceImpRequest));
} finally {
httpService.stopAndWait();
}
// cleanup
ownerAdmin.delete(aliceEntity);
}
Aggregations