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();
}
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());
}
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);
}
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);
}
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);
}
Aggregations