Search in sources :

Example 16 with Config

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);
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Example 17 with Config

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);
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Example 18 with Config

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;
}
Also used : BuiltinGraphFactory(com.baidu.hugegraph.computer.core.graph.BuiltinGraphFactory) Allocator(com.baidu.hugegraph.computer.core.allocator.Allocator) DefaultAllocator(com.baidu.hugegraph.computer.core.allocator.DefaultAllocator) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) BuiltinGraphFactory(com.baidu.hugegraph.computer.core.graph.BuiltinGraphFactory) AlgorithmParams(com.baidu.hugegraph.computer.algorithm.AlgorithmParams) Config(com.baidu.hugegraph.computer.core.config.Config) DefaultConfig(com.baidu.hugegraph.computer.core.config.DefaultConfig) DefaultConfig(com.baidu.hugegraph.computer.core.config.DefaultConfig) DefaultAllocator(com.baidu.hugegraph.computer.core.allocator.DefaultAllocator) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 19 with 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);
}
Also used : MockMessageHandler(com.baidu.hugegraph.computer.core.network.MockMessageHandler) MockMessageHandler(com.baidu.hugegraph.computer.core.network.MockMessageHandler) MessageHandler(com.baidu.hugegraph.computer.core.network.MessageHandler) Config(com.baidu.hugegraph.computer.core.config.Config) MockClientHandler(com.baidu.hugegraph.computer.core.network.MockClientHandler) ClientHandler(com.baidu.hugegraph.computer.core.network.ClientHandler) MockClientHandler(com.baidu.hugegraph.computer.core.network.MockClientHandler) Before(org.junit.Before)

Example 20 with Config

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);
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) InetSocketAddress(java.net.InetSocketAddress) MockMasterComputation(com.baidu.hugegraph.computer.core.worker.MockMasterComputation) TransportException(com.baidu.hugegraph.computer.core.common.exception.TransportException) FileManager(com.baidu.hugegraph.computer.core.store.FileManager) RecvSortManager(com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager) SortManager(com.baidu.hugegraph.computer.core.sort.sorting.SortManager) MessageRecvManager(com.baidu.hugegraph.computer.core.receiver.MessageRecvManager) ConnectionManager(com.baidu.hugegraph.computer.core.network.connection.ConnectionManager) TransportConnectionManager(com.baidu.hugegraph.computer.core.network.connection.TransportConnectionManager) MockComputation(com.baidu.hugegraph.computer.core.worker.MockComputation) RecvSortManager(com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager) TransportConnectionManager(com.baidu.hugegraph.computer.core.network.connection.TransportConnectionManager) Test(org.junit.Test)

Aggregations

Config (com.baidu.hugegraph.computer.core.config.Config)33 Test (org.junit.Test)25 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)6 File (java.io.File)6 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)5 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)5 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)4 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)4 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)4 MasterService (com.baidu.hugegraph.computer.core.master.MasterService)4 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)4 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)3 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)3 Id (com.baidu.hugegraph.computer.core.graph.id.Id)3 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)3 CombineKvOuterSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvOuterSortFlusher)3 RecvSortManager (com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager)3 SortManager (com.baidu.hugegraph.computer.core.sort.sorting.SortManager)3 InlinePointer (com.baidu.hugegraph.computer.core.store.entry.InlinePointer)3 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)3