use of alluxio.hub.proto.HubNodeAddress 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.hub.proto.HubNodeAddress in project alluxio by Alluxio.
the class HubClusterTest method testRemove.
@Test
public void testRemove() {
HubNodeAddress a = generateNodeAddress();
mCluster.add(a);
assertEquals(1, mCluster.size());
mCluster.remove(a);
assertEquals(0, mCluster.size());
mCluster.add(a);
assertEquals(1, mCluster.size());
}
use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.
the class HubClusterTest method testAdd.
@Test
public void testAdd() {
HubNodeAddress s = HubNodeAddress.newBuilder().setHostname("test-host").setRpcPort(1234).build();
mCluster.add(s);
assertEquals(1, mCluster.size());
HubNodeAddress s2 = HubNodeAddress.newBuilder().setHostname("test-host").setRpcPort(12345).build();
mCluster.add(s2);
assertEquals(2, mCluster.size());
}
use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.
the class HubClusterTest method testLostThenAlive.
@Test
public void testLostThenAlive() throws InterruptedException {
HubNodeAddress addr = generateNodeAddress();
mCluster = new HubCluster(mSvc, 100, 400);
mCluster.heartbeat(addr);
assertEquals(1, mCluster.size());
// wait until the lost time has passed
Thread.sleep(105);
// scan over the nodes
mCluster.scanNodes();
assertEquals(1, mCluster.size());
assertEquals(HubNodeState.LOST, mCluster.toProto().getNode(0).getState());
mCluster.heartbeat(addr);
// scan over the nodes again
mCluster.scanNodes();
// the node should be deleted
assertEquals(1, mCluster.size());
assertEquals(HubNodeState.ALIVE, mCluster.toProto().getNode(0).getState());
}
use of alluxio.hub.proto.HubNodeAddress in project alluxio by Alluxio.
the class ManagerProcessContext method execOnHub.
/**
* Execute a function across a set of Alluxio nodes on the cluster.
*
* @param action a function that supplies a Hub agent client
* @param type the hostname it should run on
* @param executionType parallel or serial
* @param <T> the response type that is returned from the client action
* @return a mapping of responses from each hub agent the action was executed on to the
* agent's address
*/
public <T> Map<HubNodeAddress, T> execOnHub(Function<AgentManagerServiceGrpc.AgentManagerServiceBlockingStub, T> action, AlluxioNodeType type, ExecutionType executionType) {
Set<HubNodeAddress> nodes = mHubCluster.nodesFromAlluxio(mAlluxioCluster, type);
ExecutorService executorService = executionType == ExecutionType.PARALLEL ? mSvc : Executors.newSingleThreadExecutor();
return mHubCluster.exec(nodes, mConf, action, executorService);
}
Aggregations