in hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java [85:207]
public void testCopySchemaWithMultiGraphs() {
// FIXME: skip this test for hstore
Assume.assumeTrue("skip this test for hstore",
Objects.equals("hstore", System.getProperty("backend")));
List<HugeGraph> graphs = openGraphs("schema_g1", "schema_g2");
for (HugeGraph graph : graphs) {
graph.initBackend();
}
HugeGraph g1 = graphs.get(0);
g1.serverStarted(GlobalMasterInfo.master("server-g2"));
HugeGraph g2 = graphs.get(1);
g2.serverStarted(GlobalMasterInfo.master("server-g3"));
SchemaManager schema = g1.schema();
schema.propertyKey("id").asInt().checkExist(false).create();
schema.propertyKey("name").asText().checkExist(false).create();
schema.propertyKey("age").asInt().valueSingle().checkExist(false).create();
schema.propertyKey("city").asText().checkExist(false).create();
schema.propertyKey("weight").asDouble().valueList().checkExist(false).create();
schema.propertyKey("born").asDate().ifNotExist().create();
schema.propertyKey("time").asDate().ifNotExist().create();
schema.vertexLabel("person")
.properties("id", "name", "age", "city", "weight", "born")
.primaryKeys("id").create();
schema.vertexLabel("person2")
.properties("id", "name", "age", "city")
.primaryKeys("id").create();
schema.edgeLabel("friend").sourceLabel("person").targetLabel("person")
.properties("time").create();
schema.indexLabel("personByName").onV("person").secondary()
.by("name").create();
schema.indexLabel("personByCity").onV("person").search()
.by("city").create();
schema.indexLabel("personByAge").onV("person").range()
.by("age").create();
schema.indexLabel("friendByTime").onE("friend").range()
.by("time").create();
Assert.assertFalse(g2.existsPropertyKey("id"));
Assert.assertFalse(g2.existsPropertyKey("name"));
Assert.assertFalse(g2.existsPropertyKey("age"));
Assert.assertFalse(g2.existsPropertyKey("city"));
Assert.assertFalse(g2.existsPropertyKey("weight"));
Assert.assertFalse(g2.existsPropertyKey("born"));
Assert.assertFalse(g2.existsPropertyKey("time"));
Assert.assertFalse(g2.existsVertexLabel("person"));
Assert.assertFalse(g2.existsVertexLabel("person2"));
Assert.assertFalse(g2.existsEdgeLabel("friend"));
Assert.assertFalse(g2.existsIndexLabel("personByName"));
Assert.assertFalse(g2.existsIndexLabel("personByCity"));
Assert.assertFalse(g2.existsIndexLabel("personByAge"));
Assert.assertFalse(g2.existsIndexLabel("friendByTime"));
// Copy schema from g1 to g2
g2.schema().copyFrom(g1.schema());
Assert.assertTrue(g2.existsPropertyKey("id"));
Assert.assertTrue(g2.existsPropertyKey("name"));
Assert.assertTrue(g2.existsPropertyKey("age"));
Assert.assertTrue(g2.existsPropertyKey("city"));
Assert.assertTrue(g2.existsPropertyKey("weight"));
Assert.assertTrue(g2.existsPropertyKey("born"));
Assert.assertTrue(g2.existsPropertyKey("time"));
Assert.assertTrue(g2.existsVertexLabel("person"));
Assert.assertTrue(g2.existsVertexLabel("person2"));
Assert.assertTrue(g2.existsEdgeLabel("friend"));
Assert.assertTrue(g2.existsIndexLabel("personByName"));
Assert.assertTrue(g2.existsIndexLabel("personByCity"));
Assert.assertTrue(g2.existsIndexLabel("personByAge"));
Assert.assertTrue(g2.existsIndexLabel("friendByTime"));
for (PropertyKey copied : g2.schema().getPropertyKeys()) {
PropertyKey origin = g1.schema().getPropertyKey(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (VertexLabel copied : schema.getVertexLabels()) {
VertexLabel origin = g1.schema().getVertexLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (EdgeLabel copied : schema.getEdgeLabels()) {
EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (IndexLabel copied : schema.getIndexLabels()) {
IndexLabel origin = g1.schema().getIndexLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
// Copy schema again from g1 to g2 (ignore identical content)
g2.schema().copyFrom(g1.schema());
for (PropertyKey copied : g2.schema().getPropertyKeys()) {
PropertyKey origin = g1.schema().getPropertyKey(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (VertexLabel copied : schema.getVertexLabels()) {
VertexLabel origin = g1.schema().getVertexLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (EdgeLabel copied : schema.getEdgeLabels()) {
EdgeLabel origin = g1.schema().getEdgeLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (IndexLabel copied : schema.getIndexLabels()) {
IndexLabel origin = g1.schema().getIndexLabel(copied.name());
Assert.assertTrue(origin.hasSameContent(copied));
}
for (HugeGraph graph : graphs) {
graph.clearBackend();
}
destroyGraphs(graphs);
}