Search in sources :

Example 16 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class MessageInputTest method checkMessages.

private void checkMessages(Map<Id, List<IdList>> expectedMessages, MessageInput<IdList> input) throws IOException {
    for (long i = 0L; i < 200L; i++) {
        List<IdList> messages = expectedMessages.get(BytesId.of(i));
        Id id = BytesId.of(i);
        ReusablePointer idPointer = EdgesInputTest.idToReusablePointer(id);
        Iterator<IdList> mit = input.iterator(idPointer);
        if (messages == null) {
            Assert.assertFalse(mit.hasNext());
        } else {
            for (int j = 0; j < messages.size(); j++) {
                Assert.assertTrue(mit.hasNext());
                Assert.assertTrue(messages.contains(mit.next()));
            }
        }
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 17 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class BuiltinGraphFactoryTest method testCreateUuidId.

@Test
public void testCreateUuidId() {
    UUID uuid = UUID.randomUUID();
    GraphFactory graphFactory = graphFactory();
    Id id = graphFactory.createId(uuid);
    Assert.assertEquals(IdType.UUID, id.idType());
    Assert.assertEquals(BytesId.of(uuid), id);
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) UUID(java.util.UUID) Test(org.junit.Test)

Example 18 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class BuiltinGraphFactoryTest method testCreateUtf8Id.

@Test
public void testCreateUtf8Id() {
    String value = "John";
    GraphFactory graphFactory = graphFactory();
    Id id = graphFactory.createId(value);
    Assert.assertEquals(IdType.UTF8, id.idType());
    Assert.assertEquals(BytesId.of(value), id);
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) Test(org.junit.Test)

Example 19 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.

the class HashPartitionerTest method test1Worker1Partition.

@Test
public void test1Worker1Partition() {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.JOB_PARTITIONS_COUNT, "1");
    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.assertEquals(0, partition1);
    Assert.assertEquals(0, partition2);
    Assert.assertEquals(0, partition3);
    Assert.assertEquals(0, partition4);
    Assert.assertEquals(0, partition5);
    Assert.assertEquals(0, partition6);
    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 20 with Id

use of com.baidu.hugegraph.computer.core.graph.id.Id 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)

Aggregations

Id (com.baidu.hugegraph.computer.core.graph.id.Id)74 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)51 Test (org.junit.Test)29 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)18 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)12 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)12 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)12 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)12 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)11 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)10 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)9 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)8 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)7 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)6 File (java.io.File)6 Value (com.baidu.hugegraph.computer.core.graph.value.Value)5 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)5 Config (com.baidu.hugegraph.computer.core.config.Config)4 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)4