use of org.apache.hadoop.hive.accumulo.HiveAccumuloHelper in project hive by apache.
the class TestHiveAccumuloTableOutputFormat method testSaslConfiguration.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSaslConfiguration() throws IOException, AccumuloException, AccumuloSecurityException {
final HiveAccumuloTableOutputFormat outputFormat = Mockito.mock(HiveAccumuloTableOutputFormat.class);
final AuthenticationToken authToken = Mockito.mock(AuthenticationToken.class);
final Token hadoopToken = Mockito.mock(Token.class);
final HiveAccumuloHelper helper = Mockito.mock(HiveAccumuloHelper.class);
final AccumuloConnectionParameters cnxnParams = Mockito.mock(AccumuloConnectionParameters.class);
final Connector connector = Mockito.mock(Connector.class);
// Set UGI to use Kerberos
// Have to use the string constant to support hadoop 1
conf.set("hadoop.security.authentication", "kerberos");
UserGroupInformation.setConfiguration(conf);
// Set the current UGI to a fake user
UserGroupInformation user1 = UserGroupInformation.createUserForTesting(user, new String[0]);
// Use that as the "current user"
Mockito.when(outputFormat.getCurrentUser()).thenReturn(user1);
// Turn off passwords, enable sasl and set a keytab
conf.unset(AccumuloConnectionParameters.USER_PASS);
// Call the real method instead of the mock
Mockito.doCallRealMethod().when(outputFormat).configureAccumuloOutputFormat(conf);
// Return our mocked objects
Mockito.when(outputFormat.getHelper()).thenReturn(helper);
Mockito.when(outputFormat.getConnectionParams(conf)).thenReturn(cnxnParams);
Mockito.when(cnxnParams.getConnector()).thenReturn(connector);
Mockito.when(helper.getDelegationToken(connector)).thenReturn(authToken);
Mockito.when(helper.getHadoopToken(authToken)).thenReturn(hadoopToken);
// Stub AccumuloConnectionParameters actions
Mockito.when(cnxnParams.useSasl()).thenReturn(true);
Mockito.when(cnxnParams.getAccumuloUserName()).thenReturn(user);
Mockito.when(cnxnParams.getAccumuloInstanceName()).thenReturn(instanceName);
Mockito.when(cnxnParams.getZooKeepers()).thenReturn(zookeepers);
// Stub OutputFormat actions
Mockito.when(outputFormat.hasKerberosCredentials(user1)).thenReturn(true);
// Invoke the method
outputFormat.configureAccumuloOutputFormat(conf);
// The AccumuloInputFormat methods
Mockito.verify(outputFormat).setZooKeeperInstanceWithErrorChecking(conf, instanceName, zookeepers, true);
Mockito.verify(outputFormat).setConnectorInfoWithErrorChecking(conf, user, authToken);
Mockito.verify(outputFormat).setDefaultAccumuloTableName(conf, outputTable);
// Other methods we expect
Mockito.verify(helper).mergeTokenIntoJobConf(conf, hadoopToken);
// Make sure the token made it into the UGI
Collection<Token<? extends TokenIdentifier>> tokens = user1.getTokens();
Assert.assertEquals(1, tokens.size());
Assert.assertEquals(hadoopToken, tokens.iterator().next());
}
Aggregations