use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.
the class HashPartitionerTest method test1Worker2Partition.
@Test
public void test1Worker2Partition() {
Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.JOB_PARTITIONS_COUNT, "2");
Partitioner partitioner = config.createObject(ComputerOptions.WORKER_PARTITIONER);
partitioner.init(config);
Id vertexId1 = BytesId.of(1L);
Id vertexId2 = BytesId.of(2L);
Id vertexId3 = BytesId.of(-1L);
Id vertexId4 = BytesId.of(-100L);
Id vertexId5 = BytesId.of(Long.MIN_VALUE);
Id vertexId6 = BytesId.of(Long.MAX_VALUE);
int partition1 = partitioner.partitionId(vertexId1);
int partition2 = partitioner.partitionId(vertexId2);
int partition3 = partitioner.partitionId(vertexId3);
int partition4 = partitioner.partitionId(vertexId4);
int partition5 = partitioner.partitionId(vertexId5);
int partition6 = partitioner.partitionId(vertexId6);
Assert.assertTrue(partition1 < 2);
Assert.assertTrue(partition2 < 2);
Assert.assertTrue(partition3 < 2);
Assert.assertTrue(partition4 < 2);
Assert.assertTrue(partition5 < 2);
Assert.assertTrue(partition6 < 2);
int workerId1 = partitioner.workerId(partition1);
int workerId2 = partitioner.workerId(partition2);
int workerId3 = partitioner.workerId(partition3);
int workerId4 = partitioner.workerId(partition4);
int workerId5 = partitioner.workerId(partition5);
int workerId6 = partitioner.workerId(partition6);
Assert.assertEquals(1, workerId1);
Assert.assertEquals(1, workerId2);
Assert.assertEquals(1, workerId3);
Assert.assertEquals(1, workerId4);
Assert.assertEquals(1, workerId5);
Assert.assertEquals(1, workerId6);
}
use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.
the class HashPartitionerTest method test1Worker3Partition.
@Test
public void test1Worker3Partition() {
Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.JOB_PARTITIONS_COUNT, "3");
Partitioner partitioner = config.createObject(ComputerOptions.WORKER_PARTITIONER);
partitioner.init(config);
Id vertexId1 = BytesId.of(1L);
Id vertexId2 = BytesId.of(2L);
Id vertexId3 = BytesId.of(-1L);
Id vertexId4 = BytesId.of(-100L);
Id vertexId5 = BytesId.of(Long.MIN_VALUE);
Id vertexId6 = BytesId.of(Long.MAX_VALUE);
int partition1 = partitioner.partitionId(vertexId1);
int partition2 = partitioner.partitionId(vertexId2);
int partition3 = partitioner.partitionId(vertexId3);
int partition4 = partitioner.partitionId(vertexId4);
int partition5 = partitioner.partitionId(vertexId5);
int partition6 = partitioner.partitionId(vertexId6);
Assert.assertTrue(partition1 < 3);
Assert.assertTrue(partition2 < 3);
Assert.assertTrue(partition3 < 3);
Assert.assertTrue(partition4 < 3);
Assert.assertTrue(partition5 < 3);
Assert.assertTrue(partition6 < 3);
int workerId1 = partitioner.workerId(partition1);
int workerId2 = partitioner.workerId(partition2);
int workerId3 = partitioner.workerId(partition3);
int workerId4 = partitioner.workerId(partition4);
int workerId5 = partitioner.workerId(partition5);
int workerId6 = partitioner.workerId(partition6);
Assert.assertEquals(1, workerId1);
Assert.assertEquals(1, workerId2);
Assert.assertEquals(1, workerId3);
Assert.assertEquals(1, workerId4);
Assert.assertEquals(1, workerId5);
Assert.assertEquals(1, workerId6);
}
use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.
the class ComputerContextUtil method initContext.
public static Config initContext(Map<String, String> params) {
// Set algorithm's parameters
String algorithmParamsName = params.get(ComputerOptions.ALGORITHM_PARAMS_CLASS.name());
AlgorithmParams algorithmParams;
try {
algorithmParams = (AlgorithmParams) Class.forName(algorithmParamsName).newInstance();
} catch (Exception e) {
throw new ComputerException("Can't create algorithmParams, " + "algorithmParamsName = {}", algorithmParamsName);
}
algorithmParams.setAlgorithmParameters(params);
Config config = new DefaultConfig(params);
GraphFactory graphFactory = new BuiltinGraphFactory();
Allocator allocator = new DefaultAllocator(config, graphFactory);
ComputerContext.initContext(config, graphFactory, allocator);
return config;
}
use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.
the class ConnectionManagerTest method setup.
@Before
public void setup() {
Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.TRANSPORT_SERVER_HOST, "127.0.0.1", ComputerOptions.TRANSPORT_IO_MODE, "NIO");
MessageHandler serverHandler = new MockMessageHandler();
ClientHandler clientHandler = new MockClientHandler();
connectionManager = new TransportConnectionManager();
port = connectionManager.startServer(config, serverHandler);
connectionManager.initClientManager(config, clientHandler);
}
use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.
the class DataServerManagerTest method test.
@Test
public void test() {
Config config = UnitTestBase.updateWithRequiredOptions(RpcOptions.RPC_REMOTE_URL, "127.0.0.1:8090", ComputerOptions.JOB_ID, "local_001", ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.BSP_LOG_INTERVAL, "30000", ComputerOptions.BSP_MAX_SUPER_STEP, "2", ComputerOptions.WORKER_COMPUTATION_CLASS, MockComputation.class.getName(), ComputerOptions.MASTER_COMPUTATION_CLASS, MockMasterComputation.class.getName());
FileManager fileManager = new FileManager();
fileManager.init(config);
SortManager sortManager = new RecvSortManager(context());
sortManager.init(config);
MessageRecvManager recvManager = new MessageRecvManager(context(), fileManager, sortManager);
recvManager.init(config);
ConnectionManager connManager = new TransportConnectionManager();
DataServerManager serverManager = new DataServerManager(connManager, recvManager);
serverManager.init(config);
Assert.assertEquals(DataServerManager.NAME, serverManager.name());
InetSocketAddress address = serverManager.address();
Assert.assertNotEquals(0, address.getPort());
ConnectionId connectionId = ConnectionId.parseConnectionId(address.getHostName(), address.getPort());
recvManager.onChannelActive(connectionId);
recvManager.onChannelInactive(connectionId);
TransportException e = new TransportException("test transport " + "exception");
recvManager.exceptionCaught(e, connectionId);
serverManager.close(config);
fileManager.close(config);
sortManager.close(config);
}
Aggregations