Search in sources :

Example 21 with Id

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

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

the class IdListListTest method testReadWrite.

@Test
public void testReadWrite() throws IOException {
    Id longId1 = BytesId.of(100L);
    Id longId2 = BytesId.of(200L);
    IdList listValue = new IdList();
    listValue.add(longId1);
    listValue.add(longId2);
    IdListList oldValue = new IdListList();
    oldValue.add(listValue);
    assertValueEqualAfterWriteAndRead(oldValue);
}
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 23 with Id

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

the class IdListListTest method test.

@Test
public void test() {
    Id longId1 = BytesId.of(100L);
    Id longId2 = BytesId.of(200L);
    IdList listValue1 = new IdList();
    IdList listValue2 = new IdList();
    IdListList listListValue1 = new IdListList();
    IdListList listListValue2 = new IdListList();
    listValue1.add(longId1);
    listValue2.add(longId2);
    listListValue1.add(listValue1);
    listListValue2.add(listValue1);
    Assert.assertEquals(ValueType.ID_LIST_LIST, listListValue1.valueType());
    Assert.assertEquals(ValueType.ID_LIST, listListValue1.elemType());
    Assert.assertTrue(ListUtils.isEqualList(Lists.newArrayList(listValue1), listListValue1.values()));
    Assert.assertEquals(listListValue1, listListValue2);
    listValue2.add(longId2);
    listListValue2.add(listValue2);
    Assert.assertTrue(ListUtils.isEqualList(Lists.newArrayList(listValue1, listValue2), listListValue2.values()));
    Assert.assertNotEquals(listListValue1, listListValue2);
    Assert.assertEquals(ListUtils.hashCodeForList(Lists.newArrayList(listValue1)), listListValue1.hashCode());
}
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 24 with Id

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

the class IdValueListTest method testCompare.

@Test
public void testCompare() {
    Id longId1 = BytesId.of(100L);
    Id longId2 = BytesId.of(200L);
    IdList value1 = new IdList();
    value1.add(longId1);
    IdList value2 = new IdList();
    value2.add(longId1);
    IdList value3 = new IdList();
    value3.add(longId1);
    value3.add(longId2);
    Assert.assertEquals(0, value1.compareTo(value2));
    Assert.assertLt(0, value1.compareTo(value3));
    Assert.assertGt(0, value3.compareTo(value1));
}
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 25 with Id

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

the class IdValueListTest method testReadWrite.

@Test
public void testReadWrite() throws IOException {
    Id longId1 = BytesId.of(100L);
    Id longId2 = BytesId.of(200L);
    IdList oldValue = new IdList();
    oldValue.add(longId1);
    oldValue.add(longId2);
    assertValueEqualAfterWriteAndRead(oldValue);
}
Also used : 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