Search in sources :

Example 11 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class EtcdBspTest method testIterate.

@Test
public void testIterate() throws InterruptedException {
    // If both two threads reach countDown, it means no exception is thrown.
    WorkerStat workerStat = new WorkerStat();
    workerStat.add(new PartitionStat(0, 100L, 200L, 0L));
    workerStat.add(new PartitionStat(1, 200L, 300L, 0L));
    CountDownLatch countDownLatch = new CountDownLatch(2);
    this.executorService.submit(() -> {
        for (int i = 0; i < this.maxSuperStep; i++) {
            this.bsp4Master.waitWorkersStepPrepareDone(i);
            this.bsp4Master.masterStepPrepareDone(i);
            this.bsp4Master.waitWorkersStepComputeDone(i);
            this.bsp4Master.masterStepComputeDone(i);
            List<WorkerStat> list = this.bsp4Master.waitWorkersStepDone(i);
            SuperstepStat superstepStat = new SuperstepStat();
            for (WorkerStat workerStat1 : list) {
                superstepStat.increase(workerStat1);
            }
            if (i == this.maxSuperStep - 1) {
                superstepStat.inactivate();
            }
            this.bsp4Master.masterStepDone(i, superstepStat);
        }
        countDownLatch.countDown();
    });
    this.executorService.submit(() -> {
        int superstep = -1;
        SuperstepStat superstepStat = null;
        while (superstepStat == null || superstepStat.active()) {
            superstep++;
            this.bsp4Worker.workerStepPrepareDone(superstep);
            this.bsp4Worker.waitMasterStepPrepareDone(superstep);
            this.bsp4Worker.workerStepComputeDone(superstep);
            this.bsp4Worker.waitMasterStepComputeDone(superstep);
            PartitionStat stat1 = new PartitionStat(0, 100L, 200L, 50L);
            PartitionStat stat2 = new PartitionStat(1, 200L, 300L, 80L);
            WorkerStat workerStatInSuperstep = new WorkerStat();
            workerStatInSuperstep.add(stat1);
            workerStatInSuperstep.add(stat2);
            // Sleep some time to simulate the worker do computation.
            UnitTestBase.sleep(100L);
            this.bsp4Worker.workerStepDone(superstep, workerStatInSuperstep);
            superstepStat = this.bsp4Worker.waitMasterStepDone(superstep);
        }
        countDownLatch.countDown();
    });
    countDownLatch.await();
}
Also used : PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) SuperstepStat(com.baidu.hugegraph.computer.core.graph.SuperstepStat) WorkerStat(com.baidu.hugegraph.computer.core.worker.WorkerStat) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 12 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class WorkerStatTest method testToString.

@Test
public void testToString() {
    PartitionStat stat1 = new PartitionStat(0, 1L, 2L, 0L);
    PartitionStat stat2 = new PartitionStat(1, 4L, 3L, 2L);
    stat2.mergeSendMessageStat(new MessageStat(5L, 6L));
    stat2.mergeRecvMessageStat(new MessageStat(7L, 8L));
    WorkerStat workerStat = new WorkerStat();
    workerStat.add(stat1);
    workerStat.add(stat2);
    String str = "WorkerStat{\"workerId\":0," + "\"partitionStats\":[{\"partitionId\":0," + "\"vertexCount\":1,\"edgeCount\":2,\"" + "finishedVertexCount\":0," + "\"messageSendCount\":0,\"messageSendBytes\":0," + "\"messageRecvCount\":0,\"messageRecvBytes\":0}," + "{\"partitionId\":1,\"vertexCount\":4," + "\"edgeCount\":3,\"finishedVertexCount\":2," + "\"messageSendCount\":5,\"messageSendBytes\":6," + "\"messageRecvCount\":7,\"messageRecvBytes\":8}]}";
    Assert.assertEquals(str, workerStat.toString());
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) Test(org.junit.Test)

Example 13 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class WorkerStatTest method testReadWrite.

@Test
public void testReadWrite() throws IOException {
    WorkerStat workerStat = new WorkerStat(1);
    PartitionStat stat1 = new PartitionStat(0, 1L, 2L, 0L);
    PartitionStat stat2 = new PartitionStat(1, 4L, 3L, 2L);
    workerStat.add(stat1);
    workerStat.add(stat2);
    WorkerStat stats1ReadObj = new WorkerStat();
    UnitTestBase.assertEqualAfterWriteAndRead(workerStat, stats1ReadObj);
}
Also used : PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) Test(org.junit.Test)

Example 14 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class JsonUtilTest method testNull.

@Test
public void testNull() {
    String json = JsonUtil.toJson(null);
    PartitionStat partitionStat1 = JsonUtil.fromJson(json, PartitionStat.class);
    Assert.assertEquals(null, partitionStat1);
}
Also used : PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) Test(org.junit.Test)

Example 15 with PartitionStat

use of com.baidu.hugegraph.computer.core.graph.partition.PartitionStat in project hugegraph-computer by hugegraph.

the class SuperstepStatTest method testEquals.

@Test
public void testEquals() {
    SuperstepStat stat1 = new SuperstepStat();
    PartitionStat partitionStat = new PartitionStat(1, 4L, 3L, 2L);
    partitionStat.mergeSendMessageStat(new MessageStat(5L, 6L));
    partitionStat.mergeRecvMessageStat(new MessageStat(7L, 8L));
    stat1.increase(partitionStat);
    stat1.increase(partitionStat);
    SuperstepStat stat2 = new SuperstepStat();
    stat2.increase(partitionStat);
    stat2.increase(partitionStat);
    SuperstepStat stat3 = new SuperstepStat();
    Assert.assertEquals(stat1, stat2);
    Assert.assertNotEquals(stat1, stat3);
    Assert.assertNotEquals(stat1, new Object());
    stat1.inactivate();
    Assert.assertFalse(stat1.active());
    Assert.assertNotEquals(stat1, stat2);
}
Also used : MessageStat(com.baidu.hugegraph.computer.core.receiver.MessageStat) PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) Test(org.junit.Test)

Aggregations

PartitionStat (com.baidu.hugegraph.computer.core.graph.partition.PartitionStat)24 Test (org.junit.Test)15 MessageStat (com.baidu.hugegraph.computer.core.receiver.MessageStat)10 WorkerStat (com.baidu.hugegraph.computer.core.worker.WorkerStat)6 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)5 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 SuperstepStat (com.baidu.hugegraph.computer.core.graph.SuperstepStat)1 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)1 Value (com.baidu.hugegraph.computer.core.graph.value.Value)1 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)1 BufferedFileOutput (com.baidu.hugegraph.computer.core.io.BufferedFileOutput)1 ComputerOutput (com.baidu.hugegraph.computer.core.output.ComputerOutput)1 PeekableIterator (com.baidu.hugegraph.computer.core.sort.flusher.PeekableIterator)1 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)1 Consumers (com.baidu.hugegraph.computer.core.util.Consumers)1