use of com.alibaba.graphscope.groot.store.SnapshotSortQueue in project GraphScope by alibaba.
the class SnapshotSortQueueTest method testQueue.
@Test
void testQueue() throws InterruptedException {
Configs configs = Configs.newBuilder().build();
MetaService mockMetaService = mock(MetaService.class);
when(mockMetaService.getQueueCount()).thenReturn(2);
SnapshotSortQueue snapshotSortQueue = new SnapshotSortQueue(configs, mockMetaService);
/**
* Q1: 4, 5, 7, 7 Q0: 4, 5, 6, 7
*
* <p>(Q1, 4) (Q0, 4) (Q1, 5) (Q0, 5) (Q0, 6) (Q1, 7) (Q1, 7) (Q0, 7)
*/
snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(4L).queueId(1).build());
snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(5L).queueId(1).build());
snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(7L).queueId(1).build());
snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(7L).queueId(1).build());
// For end snapshot 7
snapshotSortQueue.offerQueue(1, StoreDataBatch.newBuilder().snapshotId(100L).queueId(1).build());
snapshotSortQueue.offerQueue(0, StoreDataBatch.newBuilder().snapshotId(4L).queueId(0).build());
snapshotSortQueue.offerQueue(0, StoreDataBatch.newBuilder().snapshotId(5L).queueId(0).build());
snapshotSortQueue.offerQueue(0, StoreDataBatch.newBuilder().snapshotId(6L).queueId(0).build());
snapshotSortQueue.offerQueue(0, StoreDataBatch.newBuilder().snapshotId(7L).queueId(0).build());
StoreDataBatch entry = snapshotSortQueue.poll();
assertEquals(entry.getQueueId(), 1);
assertEquals(entry.getSnapshotId(), 4L);
entry = snapshotSortQueue.poll();
assertEquals(entry.getQueueId(), 0);
assertEquals(entry.getSnapshotId(), 4L);
entry = snapshotSortQueue.poll();
assertEquals(entry.getQueueId(), 1);
assertEquals(entry.getSnapshotId(), 5L);
entry = snapshotSortQueue.poll();
assertEquals(entry.getQueueId(), 0);
assertEquals(entry.getSnapshotId(), 5L);
entry = snapshotSortQueue.poll();
assertEquals(entry.getQueueId(), 0);
assertEquals(entry.getSnapshotId(), 6L);
entry = snapshotSortQueue.poll();
assertEquals(entry.getQueueId(), 1);
assertEquals(entry.getSnapshotId(), 7L);
entry = snapshotSortQueue.poll();
assertEquals(entry.getQueueId(), 1);
assertEquals(entry.getSnapshotId(), 7L);
entry = snapshotSortQueue.poll();
assertEquals(entry.getQueueId(), 0);
assertEquals(entry.getSnapshotId(), 7L);
}
Aggregations