use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.
the class HubClusterTest method testExecAllNodes.
@Test
public void testExecAllNodes() throws Exception {
List<HubNodeAddress> nodes = Stream.of(1, 2, 3, 4, 5).map(i -> generateNodeAddress()).collect(Collectors.toList());
nodes.forEach(mCluster::add);
try (MockedStatic<GrpcChannelBuilder> mock = Mockito.mockStatic(GrpcChannelBuilder.class)) {
GrpcChannelBuilder mockBuilder = mock(GrpcChannelBuilder.class);
doReturn(mockBuilder).when(mockBuilder).setSubject(any());
doReturn(mock(GrpcChannel.class)).when(mockBuilder).build();
mock.when(() -> GrpcChannelBuilder.newBuilder(any(), any())).thenReturn(mockBuilder);
AtomicInteger i = new AtomicInteger(0);
// Test node single exec
mCluster.exec(Collections.singleton(nodes.get(0)), getTestConfig(), (client) -> i.incrementAndGet(), mSvc);
assertEquals(1, i.get());
i.set(0);
// Test multiple node exec
mCluster.exec(new HashSet<>(nodes.subList(0, 3)), getTestConfig(), (client) -> i.incrementAndGet(), mSvc);
assertEquals(3, i.get());
i.set(0);
// Test 0 node exec
mCluster.exec(Collections.emptySet(), getTestConfig(), (client) -> i.incrementAndGet(), mSvc);
assertEquals(0, i.get());
i.set(0);
// test non existing node exec
mCluster.exec(Collections.singleton(generateNodeAddress()), getTestConfig(), (client) -> i.incrementAndGet(), mSvc);
assertEquals(0, i.get());
}
}
use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.
the class RpcClient method createChannel.
/**
* Creates a gRPC channel that uses NOSASL for security authentication type.
*
* @param addr the address to connect to
* @param conf the configuration used to make the connection
* @return new instance of {@link GrpcChannel}
* @throws AlluxioStatusException
*/
public static GrpcChannel createChannel(InetSocketAddress addr, AlluxioConfiguration conf) throws AlluxioStatusException {
InstancedConfiguration modifiedConfig = InstancedConfiguration.defaults();
Map<String, Object> properties = new HashMap<>(conf.toMap());
properties.put(PropertyKey.SECURITY_AUTHENTICATION_TYPE.getName(), AuthType.NOSASL.toString());
modifiedConfig.merge(properties, Source.RUNTIME);
LOG.info("Auth type = {}", modifiedConfig.get(PropertyKey.SECURITY_AUTHENTICATION_TYPE));
GrpcChannelBuilder builder = GrpcChannelBuilder.newBuilder(GrpcServerAddress.create(addr), modifiedConfig);
return builder.setSubject(ServerUserState.global().getSubject()).build();
}
use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.
the class GrpcSecurityTest method testSimpleAuthentication.
@Test
public void testSimpleAuthentication() throws Exception {
GrpcServer server = createServer(AuthType.SIMPLE);
try {
server.start();
UserState us = UserState.Factory.create(mConfiguration);
GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration).setSubject(us.getSubject());
channelBuilder.build();
} finally {
server.shutdown();
}
}
use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.
the class GrpcSecurityTest method testDisabledAuthentication.
@Test
public void testDisabledAuthentication() throws Exception {
GrpcServer server = createServer(AuthType.SIMPLE);
try {
server.start();
GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration);
channelBuilder.disableAuthentication().build();
} finally {
server.shutdown();
}
}
use of alluxio.grpc.GrpcChannelBuilder in project alluxio by Alluxio.
the class GrpcSecurityTest method testCustomAuthentication.
@Test
public void testCustomAuthentication() throws Exception {
mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.CUSTOM.getAuthName());
mConfiguration.set(PropertyKey.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER_CLASS, ExactlyMatchAuthenticationProvider.class.getName());
GrpcServer server = createServer(AuthType.CUSTOM);
try {
server.start();
GrpcChannelBuilder channelBuilder = GrpcChannelBuilder.newBuilder(getServerConnectAddress(server), mConfiguration);
channelBuilder.setSubject(createSubject(ExactlyMatchAuthenticationProvider.USERNAME, ExactlyMatchAuthenticationProvider.PASSWORD)).build();
} finally {
server.shutdown();
}
}
Aggregations