Search in sources :

Example 26 with Config

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

the class ComputeMessageRecvPartitionTest method testCombineMessageRecvPartition.

@Test
public void testCombineMessageRecvPartition() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.JOB_ID, "local_001", ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.JOB_PARTITIONS_COUNT, "1", // Make sure all buffers within this limit.
    ComputerOptions.WORKER_RECEIVED_BUFFERS_BYTES_LIMIT, "1000", ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName(), ComputerOptions.WORKER_DATA_DIRS, "[data_dir1, data_dir2]", ComputerOptions.WORKER_RECEIVED_BUFFERS_BYTES_LIMIT, "10", ComputerOptions.ALGORITHM_MESSAGE_CLASS, DoubleValue.class.getName(), ComputerOptions.TRANSPORT_RECV_FILE_MODE, "false");
    FileUtils.deleteQuietly(new File("data_dir1"));
    FileUtils.deleteQuietly(new File("data_dir2"));
    FileManager fileManager = new FileManager();
    fileManager.init(config);
    SortManager sortManager = new RecvSortManager(context());
    sortManager.init(config);
    SuperstepFileGenerator fileGenerator = new SuperstepFileGenerator(fileManager, 0);
    ComputeMessageRecvPartition partition = new ComputeMessageRecvPartition(context(), fileGenerator, sortManager);
    Assert.assertEquals("msg", partition.type());
    addTwentyCombineMessageBuffer(partition::addBuffer);
    checkTenCombineMessages(partition.iterator());
    fileManager.close(config);
    sortManager.close(config);
}
Also used : SuperstepFileGenerator(com.baidu.hugegraph.computer.core.store.SuperstepFileGenerator) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Config(com.baidu.hugegraph.computer.core.config.Config) DoubleValueSumCombiner(com.baidu.hugegraph.computer.core.combiner.DoubleValueSumCombiner) File(java.io.File) 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) RecvSortManager(com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager) Test(org.junit.Test)

Example 27 with Config

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

the class SorterTest method testMergeSubKvFiles.

@Test
public void testMergeSubKvFiles() throws Exception {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.INPUT_MAX_EDGES_IN_ONE_VERTEX, "2", ComputerOptions.TRANSPORT_RECV_FILE_MODE, "false");
    this.testMergeSubKvFiles(config);
    config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.INPUT_MAX_EDGES_IN_ONE_VERTEX, "2", ComputerOptions.TRANSPORT_RECV_FILE_MODE, "true");
    this.testMergeSubKvFiles(config);
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) Test(org.junit.Test)

Example 28 with Config

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

the class SortLargeDataTest method testDiffNumEntriesFileMerge.

@Test
public void testDiffNumEntriesFileMerge() throws Exception {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.HGKV_MERGE_FILES_NUM, "3", ComputerOptions.TRANSPORT_RECV_FILE_MODE, "false");
    List<Integer> sizeList = ImmutableList.of(200, 500, 20, 50, 300, 250, 10, 33, 900, 89, 20);
    List<String> inputs = new ArrayList<>();
    for (int j = 0; j < sizeList.size(); j++) {
        String file = StoreTestUtil.availablePathById(j + 10);
        inputs.add(file);
        try (KvEntryFileWriter builder = new HgkvDirBuilderImpl(config, file)) {
            for (int i = 0; i < sizeList.get(j); i++) {
                byte[] keyBytes = StoreTestUtil.intToByteArray(i);
                byte[] valueBytes = StoreTestUtil.intToByteArray(1);
                Pointer key = new InlinePointer(keyBytes);
                Pointer value = new InlinePointer(valueBytes);
                KvEntry entry = new DefaultKvEntry(key, value);
                builder.write(entry);
            }
        }
    }
    List<String> outputs = ImmutableList.of(StoreTestUtil.availablePathById(0), StoreTestUtil.availablePathById(1), StoreTestUtil.availablePathById(2), StoreTestUtil.availablePathById(3));
    Sorter sorter = SorterTestUtil.createSorter(config);
    sorter.mergeInputs(inputs, new KvOuterSortFlusher(), outputs, false);
    int total = sizeList.stream().mapToInt(i -> i).sum();
    int mergeTotal = 0;
    for (String output : outputs) {
        mergeTotal += HgkvDirImpl.open(output).numEntries();
    }
    Assert.assertEquals(total, mergeTotal);
}
Also used : ComputerOptions(com.baidu.hugegraph.computer.core.config.ComputerOptions) BeforeClass(org.junit.BeforeClass) Random(java.util.Random) EntriesUtil(com.baidu.hugegraph.computer.core.store.entry.EntriesUtil) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) ArrayList(java.util.ArrayList) IntValueSumCombiner(com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner) IOFactory(com.baidu.hugegraph.computer.core.io.IOFactory) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) After(org.junit.After) StoreTestUtil(com.baidu.hugegraph.computer.core.store.StoreTestUtil) UnitTestBase(com.baidu.hugegraph.computer.suite.unit.UnitTestBase) Before(org.junit.Before) Logger(org.slf4j.Logger) OuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.OuterSortFlusher) Constants(com.baidu.hugegraph.computer.core.common.Constants) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) HgkvDir(com.baidu.hugegraph.computer.core.store.file.hgkvfile.HgkvDir) StopWatch(org.apache.commons.lang3.time.StopWatch) CombineKvInnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher) HgkvDirImpl(com.baidu.hugegraph.computer.core.store.file.hgkvfile.HgkvDirImpl) DefaultKvEntry(com.baidu.hugegraph.computer.core.store.entry.DefaultKvEntry) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) File(java.io.File) Config(com.baidu.hugegraph.computer.core.config.Config) KvOuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.KvOuterSortFlusher) Bytes(com.baidu.hugegraph.util.Bytes) List(java.util.List) Log(com.baidu.hugegraph.util.Log) CombineKvOuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvOuterSortFlusher) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) HgkvDirBuilderImpl(com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvDirBuilderImpl) PointerCombiner(com.baidu.hugegraph.computer.core.combiner.PointerCombiner) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) SorterTestUtil(com.baidu.hugegraph.computer.core.sort.SorterTestUtil) KvEntryFileWriter(com.baidu.hugegraph.computer.core.store.KvEntryFileWriter) Sorter(com.baidu.hugegraph.computer.core.sort.Sorter) Assert(com.baidu.hugegraph.testutil.Assert) PeekableIterator(com.baidu.hugegraph.computer.core.sort.flusher.PeekableIterator) RandomAccessInput(com.baidu.hugegraph.computer.core.io.RandomAccessInput) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) InnerSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.InnerSortFlusher) KvOuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.KvOuterSortFlusher) CombineKvOuterSortFlusher(com.baidu.hugegraph.computer.core.sort.flusher.CombineKvOuterSortFlusher) Config(com.baidu.hugegraph.computer.core.config.Config) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) ArrayList(java.util.ArrayList) DefaultKvEntry(com.baidu.hugegraph.computer.core.store.entry.DefaultKvEntry) KvEntry(com.baidu.hugegraph.computer.core.store.entry.KvEntry) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) DefaultKvEntry(com.baidu.hugegraph.computer.core.store.entry.DefaultKvEntry) Sorter(com.baidu.hugegraph.computer.core.sort.Sorter) KvEntryFileWriter(com.baidu.hugegraph.computer.core.store.KvEntryFileWriter) HgkvDirBuilderImpl(com.baidu.hugegraph.computer.core.store.file.hgkvfile.builder.HgkvDirBuilderImpl) Test(org.junit.Test)

Example 29 with Config

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

the class FileManagerTest method testInitWithFile.

@Test
public void testInitWithFile() throws IOException {
    File file = new File("exist");
    file.createNewFile();
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.JOB_ID, "local_001", ComputerOptions.WORKER_DATA_DIRS, "[" + file.getAbsolutePath() + "]");
    FileManager dataFileManager = new FileManager();
    Assert.assertEquals(FileManager.NAME, dataFileManager.name());
    Assert.assertThrows(ComputerException.class, () -> {
        dataFileManager.init(config);
    }, e -> {
        Assert.assertContains("Can't create dir ", e.getMessage());
    });
    file.delete();
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) File(java.io.File) Test(org.junit.Test)

Example 30 with Config

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

the class FileManagerTest method testInitWithReadOnlyDir.

@Test
public void testInitWithReadOnlyDir() {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.JOB_ID, "local_001", ComputerOptions.WORKER_DATA_DIRS, "[/etc]");
    FileManager dataFileManager = new FileManager();
    Assert.assertThrows(ComputerException.class, () -> {
        dataFileManager.init(config);
    }, e -> {
        Assert.assertContains("Can't create dir", e.getMessage());
    });
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) 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