This is an automated email from the ASF dual-hosted git repository. kenhuuu pushed a commit to branch v4-io-test in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit dc947b1f177f7ef0cb324d65296be0bb0581ffd8 Author: Ken Hu <[email protected]> AuthorDate: Fri Jul 26 09:43:45 2024 -0700 generators --- .../structure/graphbinary/GraphBinaryAccess.java | 22 ++++++ .../gremlin/structure/graphson/GraphSONAccess.java | 22 ++++++ .../structure/io/GenerateGraphsonTestFiles.java | 91 ++++++++++++++++++++++ .../gremlin/structure/io/GenerateTestFiles.java | 78 +++++++++++++++++++ .../graphson/GraphSONUntypedCompatibilityTest.java | 20 ----- 5 files changed, 213 insertions(+), 20 deletions(-) diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/graphbinary/GraphBinaryAccess.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/graphbinary/GraphBinaryAccess.java new file mode 100644 index 0000000000..1eb973eab8 --- /dev/null +++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/graphbinary/GraphBinaryAccess.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.structure.graphbinary; + +public class GraphBinaryAccess { +} diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/graphson/GraphSONAccess.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/graphson/GraphSONAccess.java new file mode 100644 index 0000000000..7414abaa56 --- /dev/null +++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/graphson/GraphSONAccess.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.structure.graphson; + +public class GraphSONAccess { +} diff --git a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/GenerateGraphsonTestFiles.java b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/GenerateGraphsonTestFiles.java new file mode 100644 index 0000000000..d92bc14e6b --- /dev/null +++ b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/GenerateGraphsonTestFiles.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.structure.io; + +import io.netty.buffer.ByteBufAllocator; +import org.apache.commons.configuration2.BaseConfiguration; +import org.apache.commons.configuration2.Configuration; +import org.apache.tinkerpop.gremlin.process.traversal.P; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.VertexProperty; +import org.apache.tinkerpop.gremlin.structure.io.binary.GraphBinaryWriter; +import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper; +import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion; +import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV3; +import org.apache.tinkerpop.gremlin.structure.io.graphson.TypeInfo; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV3; +import org.apache.tinkerpop.gremlin.util.ser.AbstractGraphSONMessageSerializerV4; +import org.apache.tinkerpop.gremlin.util.ser.NettyBufferFactory; +import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; + +/** + * Generates the test files that are associated with the Model. This class uses relative paths so it is intended to be + * run from the IDE and not from a JAR. + */ +public class GenerateGraphsonTestFiles { + private static ObjectMapper typedGraphSonMapper = GraphSONMapper.build(). + addRegistry(TinkerIoRegistryV3.instance()). + addCustomModule(GraphSONXModuleV3.build()). + version(GraphSONVersion.V4_0).typeInfo(TypeInfo.PARTIAL_TYPES).create().createMapper(); + +// private static ObjectMapper untypedGraphSonMapper = GraphSONMapper.build(). +// addRegistry(TinkerIoRegistryV3.instance()). +// typeInfo(TypeInfo.NO_TYPES). +// addCustomModule(GraphSONXModuleV3.build()). +// version(GraphSONVersion.V4_0).create().createMapper(); + public static void main(String[] args) { + String basePath = "./test-case-data/io/graphson"; + final File testDir = new File(basePath); + + if (testDir.exists() || testDir.mkdirs()) { + Configuration conf = new BaseConfiguration(); + conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name()); + TinkerGraph graph = TinkerGraph.open(conf); + TinkerFactory.generateTheCrew(graph); + + final Model model = Model.instance(); + + PrintWriter printer = null; + for (Model.Entry modelEntry : model.entries()) { + try { + File fileToWriteTo = new File(basePath + "/" + modelEntry.getTitle().toLowerCase().replace(" ","") + "-" + "v4" + ".json"); + System.out.println("Writing " + modelEntry.getTitle()); + if (fileToWriteTo.exists()) fileToWriteTo.delete(); + printer = new PrintWriter(fileToWriteTo); + + String json = typedGraphSonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(modelEntry.getObject()); + printer.print(json); + + printer.close(); + } catch (Exception ex) { + System.out.println("Exception occurred"); + ex.printStackTrace(); + } + } + } + } + + +} \ No newline at end of file diff --git a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/GenerateTestFiles.java b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/GenerateTestFiles.java new file mode 100644 index 0000000000..b5f6d98c2d --- /dev/null +++ b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/GenerateTestFiles.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.structure.io; + +import io.netty.buffer.ByteBufAllocator; +import org.apache.commons.configuration2.BaseConfiguration; +import org.apache.commons.configuration2.Configuration; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.VertexProperty; +import org.apache.tinkerpop.gremlin.structure.io.binary.GraphBinaryWriter; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.apache.tinkerpop.gremlin.util.ser.NettyBufferFactory; + +import java.io.File; +import java.io.FileOutputStream; + +/** + * Generates the test files that are associated with the Model. This class uses relative paths so it is intended to be + * run from the IDE and not from a JAR. + */ +public class GenerateTestFiles { + private static GraphBinaryWriter graphBinaryWriter = new GraphBinaryWriter(); + public static void main(String[] args) { + String basePath = "./test-case-data/io/graphbinary"; + final File testDir = new File(basePath); + + if (testDir.exists() || testDir.mkdirs()) { + Configuration conf = new BaseConfiguration(); + conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name()); + TinkerGraph graph = TinkerGraph.open(conf); + TinkerFactory.generateTheCrew(graph); + + final Model model = Model.instance(); + + ByteBufAllocator allocator = ByteBufAllocator.DEFAULT; + NettyBufferFactory factory = new NettyBufferFactory(); + FileOutputStream filestream = null; + Buffer buffer = null; + for (Model.Entry modelEntry : model.entries()) { + try { + File fileToWriteTo = new File(basePath + "/" + modelEntry.getTitle().toLowerCase().replace(" ","") + "-" + "v4" + ".gbin"); + System.out.println("Writing " + modelEntry.getTitle()); + if (fileToWriteTo.exists()) fileToWriteTo.delete(); + filestream = new FileOutputStream(fileToWriteTo); + + buffer = factory.create(allocator.buffer()); + graphBinaryWriter.write(modelEntry.getObject(), buffer); + buffer.readerIndex(0); + buffer.readBytes(filestream, buffer.readableBytes()); + filestream.close(); + buffer.release(); + } catch (Exception ex) { + System.out.println("Exception occurred"); + ex.printStackTrace(); + } + } + } + } + + +} \ No newline at end of file diff --git a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONUntypedCompatibilityTest.java b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONUntypedCompatibilityTest.java index 48f2e741a1..82b8dfa648 100644 --- a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONUntypedCompatibilityTest.java +++ b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONUntypedCompatibilityTest.java @@ -39,23 +39,6 @@ import java.util.Arrays; @RunWith(Parameterized.class) public class GraphSONUntypedCompatibilityTest extends AbstractUntypedCompatibilityTest { - private static final ObjectMapper mapperV1 = GraphSONMapper.build(). - addRegistry(TinkerIoRegistryV1.instance()). - typeInfo(TypeInfo.NO_TYPES). - version(GraphSONVersion.V1_0).create().createMapper(); - - private static final ObjectMapper mapperV2 = GraphSONMapper.build(). - addRegistry(TinkerIoRegistryV2.instance()). - typeInfo(TypeInfo.NO_TYPES). - addCustomModule(GraphSONXModuleV2.build()). - version(GraphSONVersion.V2_0).create().createMapper(); - - private static final ObjectMapper mapperV3 = GraphSONMapper.build(). - addRegistry(TinkerIoRegistryV3.instance()). - typeInfo(TypeInfo.NO_TYPES). - addCustomModule(GraphSONXModuleV3.build()). - version(GraphSONVersion.V3_0).create().createMapper(); - private static final ObjectMapper mapperV4 = GraphSONMapper.build(). addRegistry(TinkerIoRegistryV3.instance()). typeInfo(TypeInfo.NO_TYPES). @@ -73,9 +56,6 @@ public class GraphSONUntypedCompatibilityTest extends AbstractUntypedCompatibili @Parameterized.Parameters(name = "expect({0})") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ - {"v1-no-types", mapperV1 }, - {"v2-no-types", mapperV2 }, - {"v3-no-types", mapperV3 }, {"v4-no-types", mapperV4 }, }); }
