Search in sources :

Example 1 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class ValueFileTest method testConstructor.

@Test
public void testConstructor() throws IOException {
    int bufferCapacity = 13;
    File dir = createTempDir();
    try {
        try (ValueFileOutput output = new ValueFileOutput(CONFIG, dir, bufferCapacity)) {
            Assert.assertEquals(0, output.position());
        }
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            new ValueFileOutput(CONFIG, dir, 1);
        }, e -> {
            Assert.assertContains("bufferCapacity must be >= 8", e.getMessage());
        });
        try (ValueFileInput input = new ValueFileInput(CONFIG, dir, bufferCapacity)) {
            Assert.assertEquals(0, input.position());
        }
        Assert.assertThrows(IllegalArgumentException.class, () -> {
            new ValueFileInput(CONFIG, dir, 1);
        }, e -> {
            Assert.assertContains("The parameter bufferSize must be >= 8", e.getMessage());
        });
        Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.VALUE_FILE_MAX_SEGMENT_SIZE, String.valueOf(Integer.MAX_VALUE));
        try (ValueFileOutput output = new ValueFileOutput(config, dir)) {
            Assert.assertEquals(0, output.position());
        }
        try (ValueFileInput input = new ValueFileInput(config, dir)) {
            Assert.assertEquals(0, input.position());
        }
    } finally {
        FileUtils.deleteQuietly(dir);
    }
}
Also used : ValueFileInput(com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileInput) Config(com.baidu.hugegraph.computer.core.config.Config) File(java.io.File) ValueFileOutput(com.baidu.hugegraph.computer.core.store.file.seqfile.ValueFileOutput) Test(org.junit.Test)

Example 2 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class WorkerServiceTest method testFailToConnectEtcd.

@Test
public void testFailToConnectEtcd() {
    Config config = UnitTestBase.updateWithRequiredOptions(RpcOptions.RPC_REMOTE_URL, "127.0.0.1:8090", // Unavailable etcd endpoints
    ComputerOptions.BSP_ETCD_ENDPOINTS, "http://abc:8098", ComputerOptions.JOB_ID, "local_004", ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.BSP_LOG_INTERVAL, "30000", ComputerOptions.BSP_MAX_SUPER_STEP, "2", ComputerOptions.WORKER_COMPUTATION_CLASS, MockComputation.class.getName());
    WorkerService workerService = new MockWorkerService();
    Assert.assertThrows(ComputerException.class, () -> {
        workerService.init(config);
        try {
            workerService.execute();
        } finally {
            workerService.close();
        }
    }, e -> {
        Assert.assertContains("Error while getting with " + "key='BSP_MASTER_INIT_DONE'", e.getMessage());
        Assert.assertContains("UNAVAILABLE: unresolved address", e.getCause().getMessage());
    });
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) Test(org.junit.Test)

Example 3 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class WorkerServiceTest method testServiceWith1Worker.

@Test
public void testServiceWith1Worker() throws InterruptedException {
    ExecutorService pool = Executors.newFixedThreadPool(2);
    CountDownLatch countDownLatch = new CountDownLatch(2);
    Throwable[] exceptions = new Throwable[2];
    pool.submit(() -> {
        Config config = UnitTestBase.updateWithRequiredOptions(RpcOptions.RPC_REMOTE_URL, "127.0.0.1:8090", ComputerOptions.JOB_ID, "local_002", ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.TRANSPORT_SERVER_PORT, "8086", ComputerOptions.BSP_REGISTER_TIMEOUT, "100000", ComputerOptions.BSP_LOG_INTERVAL, "30000", ComputerOptions.BSP_MAX_SUPER_STEP, "2", ComputerOptions.WORKER_COMPUTATION_CLASS, MockComputation.class.getName(), ComputerOptions.ALGORITHM_RESULT_CLASS, DoubleValue.class.getName(), ComputerOptions.ALGORITHM_MESSAGE_CLASS, DoubleValue.class.getName(), ComputerOptions.OUTPUT_CLASS, LimitedLogOutput.class.getName());
        WorkerService workerService = new MockWorkerService();
        try {
            workerService.init(config);
            workerService.execute();
        } catch (Throwable e) {
            LOG.error("Failed to start worker", e);
            exceptions[0] = e;
        } finally {
            workerService.close();
            try {
                workerService.close();
            } catch (Throwable e) {
                Assert.fail(e.getMessage());
            }
            countDownLatch.countDown();
        }
    });
    pool.submit(() -> {
        Config config = UnitTestBase.updateWithRequiredOptions(RpcOptions.RPC_SERVER_HOST, "localhost", RpcOptions.RPC_SERVER_PORT, "8090", ComputerOptions.JOB_ID, "local_002", ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.BSP_REGISTER_TIMEOUT, "100000", ComputerOptions.BSP_LOG_INTERVAL, "30000", ComputerOptions.BSP_MAX_SUPER_STEP, "2", ComputerOptions.MASTER_COMPUTATION_CLASS, MockMasterComputation.class.getName(), ComputerOptions.ALGORITHM_RESULT_CLASS, DoubleValue.class.getName(), ComputerOptions.ALGORITHM_MESSAGE_CLASS, DoubleValue.class.getName());
        MasterService masterService = new MasterService();
        try {
            masterService.init(config);
            masterService.execute();
        } catch (Throwable e) {
            LOG.error("Failed to start master", e);
            exceptions[1] = e;
        } finally {
            /*
                 * It must close the service first. The pool will be shutdown
                 * if count down is executed first, and the server thread in
                 * master service will not be closed.
                 */
            masterService.close();
            try {
                masterService.close();
            } catch (Throwable e) {
                Assert.fail(e.getMessage());
            }
            countDownLatch.countDown();
        }
    });
    countDownLatch.await();
    pool.shutdownNow();
    Assert.assertFalse(Arrays.asList(exceptions).toString(), existError(exceptions));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Config(com.baidu.hugegraph.computer.core.config.Config) LimitedLogOutput(com.baidu.hugegraph.computer.core.output.LimitedLogOutput) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) MasterService(com.baidu.hugegraph.computer.core.master.MasterService) Test(org.junit.Test)

Example 4 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class WorkerServiceTest method testServiceWith2Workers.

@Test
public void testServiceWith2Workers() throws InterruptedException {
    ExecutorService pool = Executors.newFixedThreadPool(3);
    CountDownLatch countDownLatch = new CountDownLatch(3);
    Throwable[] exceptions = new Throwable[3];
    pool.submit(() -> {
        Config config = UnitTestBase.updateWithRequiredOptions(RpcOptions.RPC_REMOTE_URL, "127.0.0.1:8090", ComputerOptions.JOB_ID, "local_003", ComputerOptions.JOB_WORKERS_COUNT, "2", ComputerOptions.JOB_PARTITIONS_COUNT, "2", ComputerOptions.TRANSPORT_SERVER_PORT, "8086", ComputerOptions.WORKER_DATA_DIRS, "[job_8086]", ComputerOptions.BSP_REGISTER_TIMEOUT, "30000", ComputerOptions.BSP_LOG_INTERVAL, "10000", ComputerOptions.BSP_MAX_SUPER_STEP, "2", ComputerOptions.WORKER_COMPUTATION_CLASS, MockComputation2.class.getName(), ComputerOptions.ALGORITHM_RESULT_CLASS, DoubleValue.class.getName(), ComputerOptions.ALGORITHM_MESSAGE_CLASS, DoubleValue.class.getName());
        WorkerService workerService = new MockWorkerService();
        try {
            workerService.init(config);
            workerService.execute();
        } catch (Throwable e) {
            LOG.error("Failed to start worker", e);
            exceptions[0] = e;
        } finally {
            workerService.close();
            countDownLatch.countDown();
        }
    });
    pool.submit(() -> {
        Config config = UnitTestBase.updateWithRequiredOptions(RpcOptions.RPC_REMOTE_URL, "127.0.0.1:8090", ComputerOptions.JOB_ID, "local_003", ComputerOptions.JOB_WORKERS_COUNT, "2", ComputerOptions.JOB_PARTITIONS_COUNT, "2", ComputerOptions.TRANSPORT_SERVER_PORT, "8087", ComputerOptions.WORKER_DATA_DIRS, "[job_8087]", ComputerOptions.BSP_REGISTER_TIMEOUT, "30000", ComputerOptions.BSP_LOG_INTERVAL, "10000", ComputerOptions.BSP_MAX_SUPER_STEP, "2", ComputerOptions.WORKER_COMPUTATION_CLASS, MockComputation2.class.getName(), ComputerOptions.ALGORITHM_RESULT_CLASS, DoubleValue.class.getName(), ComputerOptions.ALGORITHM_MESSAGE_CLASS, DoubleValue.class.getName());
        WorkerService workerService = new MockWorkerService();
        try {
            workerService.init(config);
            workerService.execute();
        } catch (Throwable e) {
            LOG.error("Failed to start worker", e);
            exceptions[1] = e;
        } finally {
            workerService.close();
            countDownLatch.countDown();
        }
    });
    pool.submit(() -> {
        Config config = UnitTestBase.updateWithRequiredOptions(RpcOptions.RPC_SERVER_HOST, "localhost", RpcOptions.RPC_SERVER_PORT, "8090", ComputerOptions.JOB_ID, "local_003", ComputerOptions.JOB_WORKERS_COUNT, "2", ComputerOptions.JOB_PARTITIONS_COUNT, "2", ComputerOptions.BSP_REGISTER_TIMEOUT, "30000", ComputerOptions.BSP_LOG_INTERVAL, "10000", ComputerOptions.BSP_MAX_SUPER_STEP, "2", ComputerOptions.MASTER_COMPUTATION_CLASS, MockMasterComputation2.class.getName(), ComputerOptions.ALGORITHM_RESULT_CLASS, DoubleValue.class.getName(), ComputerOptions.ALGORITHM_MESSAGE_CLASS, DoubleValue.class.getName());
        MasterService masterService = new MasterService();
        try {
            masterService.init(config);
            masterService.execute();
        } catch (Throwable e) {
            LOG.error("Failed to start master", e);
            exceptions[2] = e;
        } finally {
            masterService.close();
            countDownLatch.countDown();
        }
    });
    countDownLatch.await();
    pool.shutdownNow();
    Assert.assertFalse(Arrays.asList(exceptions).toString(), existError(exceptions));
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Config(com.baidu.hugegraph.computer.core.config.Config) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) MasterService(com.baidu.hugegraph.computer.core.master.MasterService) Test(org.junit.Test)

Example 5 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class SenderIntegrateTest method initWorker.

private WorkerService initWorker(String[] args) {
    Config config = ComputerContextUtil.initContext(ComputerContextUtil.convertToMap(args));
    WorkerService service = new WorkerService();
    service.init(config);
    return service;
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) WorkerService(com.baidu.hugegraph.computer.core.worker.WorkerService)

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