use of com.alibaba.graphscope.groot.meta.MetaService in project GraphScope by alibaba.
the class SchemaManagerTest method testSchemaManager.
@Test
void testSchemaManager() throws IOException, InterruptedException {
SnapshotManager mockSnapshotManager = mock(SnapshotManager.class);
doAnswer(invocationOnMock -> {
SnapshotListener listener = invocationOnMock.getArgument(1);
listener.onSnapshotAvailable();
return null;
}).when(mockSnapshotManager).addSnapshotListener(anyLong(), any());
when(mockSnapshotManager.increaseWriteSnapshotId()).thenReturn(1L);
when(mockSnapshotManager.getCurrentWriteSnapshotId()).thenReturn(1L);
DdlExecutors ddlExecutors = new DdlExecutors();
DdlWriter mockDdlWriter = mock(DdlWriter.class);
when(mockDdlWriter.writeOperations(anyString(), any())).thenReturn(new BatchId(1L));
MetaService mockMetaService = mock(MetaService.class);
GraphDefFetcher mockGraphDefFetcher = mock(GraphDefFetcher.class);
GraphDef initialGraphDef = GraphDef.newBuilder().build();
when(mockGraphDefFetcher.fetchGraphDef()).thenReturn(initialGraphDef);
SchemaManager schemaManager = new SchemaManager(mockSnapshotManager, ddlExecutors, mockDdlWriter, mockMetaService, mockGraphDefFetcher);
schemaManager.start();
assertEquals(initialGraphDef, schemaManager.getGraphDef());
PropertyValue defaultValue = new PropertyValue(DataType.INT, ByteBuffer.allocate(Integer.BYTES).putInt(1).array());
PropertyDef propertyDef = new PropertyDef(1, 1, "p1", DataType.INT, defaultValue, true, "property_1");
TypeDef typeDef = TypeDef.newBuilder().setLabel("vertex1").addPropertyDef(propertyDef).setTypeEnum(TypeEnum.VERTEX).build();
DdlRequestBatch ddlRequestBatch = DdlRequestBatch.newBuilder().addDdlRequest(new CreateVertexTypeRequest(typeDef)).build();
CountDownLatch latch = new CountDownLatch(1);
schemaManager.submitBatchDdl("requestId", "sessionId", ddlRequestBatch, new CompletionCallback<Long>() {
@Override
public void onCompleted(Long res) {
latch.countDown();
}
@Override
public void onError(Throwable t) {
}
});
assertTrue(latch.await(5L, TimeUnit.SECONDS));
schemaManager.stop();
}
use of com.alibaba.graphscope.groot.meta.MetaService in project GraphScope by alibaba.
the class DefaultMetaServiceTest method testMeta.
@Test
void testMeta() {
Configs configs = Configs.newBuilder().put("partition.count", "10").put("ingestor.queue.count", "3").put("store.node.count", "4").build();
/**
* Partitions assignment
*
* <p>| storeID | Partitions | | 0 | 0, 1, 2 | | 1 | 3, 4, 5 | | 2 | 6, 7 | | 3 | 8, 9 |
*/
MetaService metaService = new DefaultMetaService(configs);
metaService.start();
Assertions.assertAll(() -> assertEquals(metaService.getPartitionCount(), 10), () -> assertEquals(metaService.getStoreIdByPartition(0), 0), () -> assertEquals(metaService.getStoreIdByPartition(5), 1), () -> assertEquals(metaService.getStoreIdByPartition(6), 2), () -> assertEquals(metaService.getStoreIdByPartition(8), 3), () -> assertEquals(metaService.getPartitionsByStoreId(2), Arrays.asList(6, 7)), () -> assertEquals(metaService.getQueueCount(), 3), () -> assertEquals(metaService.getQueueIdsForIngestor(2), Arrays.asList(2)), () -> assertEquals(metaService.getIngestorIdForQueue(1), 1));
metaService.stop();
}
use of com.alibaba.graphscope.groot.meta.MetaService 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);
}
use of com.alibaba.graphscope.groot.meta.MetaService in project GraphScope by alibaba.
the class StoreServiceTest method testStoreService.
@Test
void testStoreService() throws IOException, InterruptedException, ExecutionException {
Configs configs = Configs.newBuilder().put(CommonConfig.NODE_IDX.getKey(), "0").build();
MetaService mockMetaService = mock(MetaService.class);
when(mockMetaService.getPartitionsByStoreId(0)).thenReturn(Arrays.asList(0));
StoreService spyStoreService = spy(new StoreService(configs, mockMetaService, new MetricsCollector(configs)));
GraphPartition mockGraphPartition = mock(GraphPartition.class);
when(mockGraphPartition.recover()).thenReturn(10L);
doReturn(mockGraphPartition).when(spyStoreService).makeGraphPartition(any(), eq(0));
spyStoreService.start();
assertEquals(spyStoreService.recover(), 10L);
StoreDataBatch storeDataBatch = StoreDataBatch.newBuilder().snapshotId(20L).addOperation(0, OperationBlob.MARKER_OPERATION_BLOB).build();
spyStoreService.batchWrite(storeDataBatch);
verify(mockGraphPartition, timeout(100L)).writeBatch(20L, OperationBatch.newBuilder().addOperationBlob(OperationBlob.MARKER_OPERATION_BLOB).build());
spyStoreService.stop();
verify(mockGraphPartition).close();
}
use of com.alibaba.graphscope.groot.meta.MetaService in project GraphScope by alibaba.
the class WriterAgentTest method testWriterAgent.
@Test
void testWriterAgent() throws InterruptedException, ExecutionException {
Configs configs = Configs.newBuilder().put(CommonConfig.NODE_IDX.getKey(), "0").put(StoreConfig.STORE_COMMIT_INTERVAL_MS.getKey(), "10").build();
StoreService mockStoreService = mock(StoreService.class);
MetaService mockMetaService = mock(MetaService.class);
when(mockMetaService.getQueueCount()).thenReturn(1);
SnapshotCommitter mockSnapshotCommitter = mock(SnapshotCommitter.class);
WriterAgent writerAgent = new WriterAgent(configs, mockStoreService, mockMetaService, mockSnapshotCommitter, new MetricsCollector(configs));
writerAgent.init(0L);
writerAgent.start();
StoreDataBatch storeDataBatch = StoreDataBatch.newBuilder().snapshotId(2L).queueId(0).offset(10L).build();
writerAgent.writeStore(storeDataBatch);
verify(mockStoreService, timeout(5000L).times(1)).batchWrite(storeDataBatch);
verify(mockSnapshotCommitter, timeout(5000L).times(1)).commitSnapshotId(0, 1L, 0L, Collections.singletonList(10L));
writerAgent.stop();
}
Aggregations