use of com.alibaba.graphscope.groot.schema.request.CreateVertexTypeRequest 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.schema.request.CreateVertexTypeRequest in project GraphScope by alibaba.
the class DdlExecutorTest method testExecutor.
@Test
void testExecutor() throws InvalidProtocolBufferException {
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 vertexTypeDef = TypeDef.newBuilder().setLabel("vertex1").addPropertyDef(propertyDef).setTypeEnum(TypeEnum.VERTEX).build();
TypeDef edgeTypeDef = TypeDef.newBuilder().setLabel("edge1").addPropertyDef(propertyDef).setTypeEnum(TypeEnum.EDGE).build();
EdgeKind edgeKind = EdgeKind.newBuilder().setEdgeLabel("edge1").setDstVertexLabel("vertex1").setSrcVertexLabel("vertex1").build();
GraphDef graphDef = GraphDef.newBuilder().build();
DdlExecutors ddlExecutors = new DdlExecutors();
DdlRequestBatch.Builder requestBatchBuilder = DdlRequestBatch.newBuilder();
requestBatchBuilder.addDdlRequest(new CreateVertexTypeRequest(vertexTypeDef));
requestBatchBuilder.addDdlRequest(new CreateEdgeTypeRequest(edgeTypeDef));
requestBatchBuilder.addDdlRequest(new AddEdgeKindRequest(edgeKind));
DdlRequestBatch ddlRequestBatch = requestBatchBuilder.build();
// Test serde
ByteString bytes = ddlRequestBatch.toProto().toByteString();
assertEquals(DdlRequestBatch.parseProto(DdlRequestBatchPb.parseFrom(bytes)), ddlRequestBatch);
DdlResult ddlResult = ddlExecutors.executeDdlRequestBatch(ddlRequestBatch, graphDef, 1);
LabelId vertexLabelId = new LabelId(1);
LabelId edgeLabelId = new LabelId(2);
EdgeKind edgeKindWithId = EdgeKind.newBuilder(edgeKind).setEdgeLabelId(edgeLabelId).setSrcVertexLabelId(vertexLabelId).setDstVertexLabelId(vertexLabelId).build();
TypeDef vertexTypeWithId = TypeDef.newBuilder(vertexTypeDef).setLabelId(vertexLabelId).build();
TypeDef edgeTypeWithId = TypeDef.newBuilder(edgeTypeDef).setLabelId(edgeLabelId).build();
graphDef = GraphDef.newBuilder(graphDef).setVersion(3).setLabelIdx(2).setPropertyIdx(1).putPropertyNameToId("p1", 1).addTypeDef(vertexTypeWithId).putVertexTableId(vertexTypeWithId.getTypeLabelId(), 1L).addTypeDef(edgeTypeWithId).addEdgeKind(edgeKindWithId).putEdgeTableId(edgeKindWithId, 2L).setTableIdx(2L).build();
assertEquals(graphDef, ddlResult.getGraphDef());
List<Operation> ddlOperations = ddlResult.getDdlOperations();
assertEquals(ddlOperations.size(), 3);
assertEquals(ddlOperations.get(0).toBlob().toProto(), new CreateVertexTypeOperation(0, 1L, vertexTypeWithId, 1L).toBlob().toProto());
assertEquals(ddlOperations.get(1).toBlob().toProto(), new CreateEdgeTypeOperation(0, 2L, edgeTypeWithId).toBlob().toProto());
assertEquals(ddlOperations.get(2).toBlob().toProto(), new AddEdgeKindOperation(0, 3L, edgeKindWithId, 2L).toBlob().toProto());
assertEquals(GraphDef.parseProto(GraphDefPb.parseFrom(graphDef.toProto().toByteString())), graphDef);
requestBatchBuilder = DdlRequestBatch.newBuilder();
requestBatchBuilder.addDdlRequest(new RemoveEdgeKindRequest(edgeKind));
requestBatchBuilder.addDdlRequest(new DropEdgeTypeRequest(edgeTypeDef.getLabel()));
requestBatchBuilder.addDdlRequest(new DropVertexTypeRequest(vertexTypeDef.getLabel()));
ddlResult = ddlExecutors.executeDdlRequestBatch(requestBatchBuilder.build(), graphDef, 1);
graphDef = GraphDef.newBuilder(graphDef).setVersion(6).removeEdgeKind(edgeKindWithId).removeTypeDef(edgeTypeDef.getLabel()).removeTypeDef(vertexTypeDef.getLabel()).clearUnusedPropertyName(Collections.emptySet()).build();
assertEquals(graphDef, ddlResult.getGraphDef());
ddlOperations = ddlResult.getDdlOperations();
assertEquals(ddlOperations.size(), 3);
assertEquals(ddlOperations.get(0).toBlob().toProto(), new RemoveEdgeKindOperation(0, 4L, edgeKindWithId).toBlob().toProto());
assertEquals(ddlOperations.get(1).toBlob().toProto(), new DropEdgeTypeOperation(0, 5L, edgeLabelId).toBlob().toProto());
assertEquals(ddlOperations.get(2).toBlob().toProto(), new DropVertexTypeOperation(0, 6L, vertexLabelId).toBlob().toProto());
}
Aggregations