Search in sources :

Example 1 with HubNodeAddress

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());
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Random(java.util.Random) HashSet(java.util.HashSet) AlluxioNodeType(alluxio.hub.proto.AlluxioNodeType) HubNodeState(alluxio.hub.proto.HubNodeState) GrpcChannel(alluxio.grpc.GrpcChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HubNodeAddress(alluxio.hub.proto.HubNodeAddress) After(org.junit.After) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) HubTestUtils.generateNodeAddress(alluxio.hub.manager.util.HubTestUtils.generateNodeAddress) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) HubTestUtils.hubStatusToAlluxioStatus(alluxio.hub.manager.util.HubTestUtils.hubStatusToAlluxioStatus) AlluxioNodeStatus(alluxio.hub.proto.AlluxioNodeStatus) Executors(java.util.concurrent.Executors) BaseHubTest(alluxio.hub.test.BaseHubTest) Mockito(org.mockito.Mockito) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) MockedStatic(org.mockito.MockedStatic) List(java.util.List) Rule(org.junit.Rule) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) TestLoggerRule(alluxio.TestLoggerRule) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HubNodeAddress(alluxio.hub.proto.HubNodeAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GrpcChannelBuilder(alluxio.grpc.GrpcChannelBuilder) GrpcChannel(alluxio.grpc.GrpcChannel) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 2 with HubNodeAddress

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());
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 3 with HubNodeAddress

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());
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 4 with HubNodeAddress

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());
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) Test(org.junit.Test) BaseHubTest(alluxio.hub.test.BaseHubTest)

Example 5 with HubNodeAddress

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);
}
Also used : HubNodeAddress(alluxio.hub.proto.HubNodeAddress) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

HubNodeAddress (alluxio.hub.proto.HubNodeAddress)17 BaseHubTest (alluxio.hub.test.BaseHubTest)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)6 Map (java.util.Map)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 Pair (alluxio.collections.Pair)2 AgentFileUploadResponse (alluxio.hub.proto.AgentFileUploadResponse)2 AgentListCatalogResponse (alluxio.hub.proto.AgentListCatalogResponse)2 AlluxioConfigurationSet (alluxio.hub.proto.AlluxioConfigurationSet)2 AlluxioNodeType (alluxio.hub.proto.AlluxioNodeType)2 PrestoCatalogListing (alluxio.hub.proto.PrestoCatalogListing)2 UploadFile (alluxio.hub.proto.UploadFile)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Collections (java.util.Collections)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 After (org.junit.After)2 Assert.assertEquals (org.junit.Assert.assertEquals)2