use of com.alibaba.graphscope.groot.coordinator.SchemaManager in project GraphScope by alibaba.
the class NotifyFrontendListenerTest method testListener.
@Test
void testListener() {
FrontendSnapshotClient frontendSnapshotClient = mock(FrontendSnapshotClient.class);
SchemaManager schemaManager = mock(SchemaManager.class);
GraphDef graphDef = GraphDef.newBuilder().setVersion(3L).build();
when(schemaManager.getGraphDef()).thenReturn(graphDef);
doAnswer(invocationOnMock -> {
long snapshotId = invocationOnMock.getArgument(0);
CompletionCallback<Long> callback = invocationOnMock.getArgument(2);
callback.onCompleted(snapshotId - 1);
return null;
}).when(frontendSnapshotClient).advanceQuerySnapshot(anyLong(), any(), any());
NotifyFrontendListener listener = new NotifyFrontendListener(0, frontendSnapshotClient, schemaManager);
listener.snapshotAdvanced(10L, 10L);
verify(frontendSnapshotClient).advanceQuerySnapshot(eq(10L), eq(graphDef), any());
listener.snapshotAdvanced(20L, 10L);
verify(frontendSnapshotClient).advanceQuerySnapshot(eq(20L), isNull(), any());
}
use of com.alibaba.graphscope.groot.coordinator.SchemaManager 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.coordinator.SchemaManager in project GraphScope by alibaba.
the class LocalSnapshotListenerTest method testListener.
@Test
void testListener() {
SchemaManager schemaManager = mock(SchemaManager.class);
GraphDef graphDef = GraphDef.newBuilder().setVersion(3L).build();
when(schemaManager.getGraphDef()).thenReturn(graphDef);
SnapshotCache snapshotCache = mock(SnapshotCache.class);
LocalSnapshotListener listener = new LocalSnapshotListener(schemaManager, snapshotCache);
listener.snapshotAdvanced(10L, 10L);
verify(snapshotCache).advanceQuerySnapshotId(eq(10L), eq(graphDef));
listener.snapshotAdvanced(20L, 10L);
verify(snapshotCache).advanceQuerySnapshotId(eq(20L), isNull());
}
Aggregations