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();
}
Aggregations