Search in sources :

Example 1 with IClusterInfoCollector

use of org.apache.hyracks.api.client.IClusterInfoCollector in project asterixdb by apache.

the class APIFrameworkTest method testChooseLocations.

@Test
public void testChooseLocations() throws Exception {
    // Mocks cluster info collector.
    IClusterInfoCollector clusterInfoCollector = mock(IClusterInfoCollector.class);
    // Constructs mocked cluster nodes.
    Map<String, NodeControllerInfo> map = new HashMap<>();
    NodeControllerInfo nc1Info = mock(NodeControllerInfo.class);
    when(nc1Info.getNumAvailableCores()).thenReturn(1);
    NodeControllerInfo nc2Info = mock(NodeControllerInfo.class);
    when(nc2Info.getNumAvailableCores()).thenReturn(1);
    String nc1 = "nc1";
    String nc2 = "nc2";
    map.put(nc1, nc1Info);
    map.put(nc2, nc2Info);
    when(clusterInfoCollector.getNodeControllerInfos()).thenReturn(map);
    // Creates an APIFramework.
    APIFramework apiFramework = new APIFramework(mock(ILangCompilationProvider.class));
    // Tests large storage locations.
    AlgebricksAbsolutePartitionConstraint storageLocations = new AlgebricksAbsolutePartitionConstraint(new String[] { "node1", "node1", "node2" });
    AlgebricksAbsolutePartitionConstraint computationLocations = (AlgebricksAbsolutePartitionConstraint) PA.invokeMethod(apiFramework, "chooseLocations(" + IClusterInfoCollector.class.getName() + ",int," + AlgebricksAbsolutePartitionConstraint.class.getName() + ")", clusterInfoCollector, CompilerProperties.COMPILER_PARALLELISM_AS_STORAGE, storageLocations);
    Assert.assertTrue(computationLocations.getLocations().length == 2);
    // Tests suitable storage locations.
    storageLocations = new AlgebricksAbsolutePartitionConstraint(new String[] { "node1", "node2" });
    computationLocations = (AlgebricksAbsolutePartitionConstraint) PA.invokeMethod(apiFramework, "chooseLocations(" + IClusterInfoCollector.class.getName() + ",int," + AlgebricksAbsolutePartitionConstraint.class.getName() + ")", clusterInfoCollector, CompilerProperties.COMPILER_PARALLELISM_AS_STORAGE, storageLocations);
    Assert.assertTrue(computationLocations.getLocations().length == 2);
    // Tests small storage locations.
    storageLocations = new AlgebricksAbsolutePartitionConstraint(new String[] { "node1" });
    computationLocations = (AlgebricksAbsolutePartitionConstraint) PA.invokeMethod(apiFramework, "chooseLocations(" + IClusterInfoCollector.class.getName() + ",int," + AlgebricksAbsolutePartitionConstraint.class.getName() + ")", clusterInfoCollector, CompilerProperties.COMPILER_PARALLELISM_AS_STORAGE, storageLocations);
    Assert.assertTrue(computationLocations.getLocations().length == 1);
    // Verifies the number of calls on clusterInfoCollector.getNodeControllerInfos() in
    // APIFramework.chooseLocations(...).
    verify(clusterInfoCollector, times(3)).getNodeControllerInfos();
}
Also used : HashMap(java.util.HashMap) AlgebricksAbsolutePartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint) NodeControllerInfo(org.apache.hyracks.api.client.NodeControllerInfo) ILangCompilationProvider(org.apache.asterix.compiler.provider.ILangCompilationProvider) IClusterInfoCollector(org.apache.hyracks.api.client.IClusterInfoCollector) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 ILangCompilationProvider (org.apache.asterix.compiler.provider.ILangCompilationProvider)1 AlgebricksAbsolutePartitionConstraint (org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint)1 IClusterInfoCollector (org.apache.hyracks.api.client.IClusterInfoCollector)1 NodeControllerInfo (org.apache.hyracks.api.client.NodeControllerInfo)1 Test (org.junit.Test)1