This is an automated email from the ASF dual-hosted git repository.
lixueclaire pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-graphar.git
The following commit(s) were added to refs/heads/main by this push:
new 3a161084 feat(java-info): add java unit test for loading graph (#683)
3a161084 is described below
commit 3a1610848759c447f425535f0105ee44d228311a
Author: Xiaokang Yang <[email protected]>
AuthorDate: Mon Jun 9 09:52:08 2025 +0800
feat(java-info): add java unit test for loading graph (#683)
* feat(java, info): complete unit test for loading graph
* feat(java,info): Enable GitHub CI workflow
* fix(java,info): Format code with Spotless
* update ci dependencies
* update ci host ubuntu version
* update ci yml
* refactored test code into multiple test methods
* format code
* format code
* allow running CI for WIP
---
.github/workflows/java-info.yml | 70 ++++++
maven-projects/info/pom.xml | 2 +-
.../graphar/info/loader/LocalYamlGraphLoader.java | 18 +-
.../graphar/info/saver/LocalYamlGraphSaver.java | 37 +--
.../org/apache/graphar/info/GraphInfoTest.java | 252 +++++++++++++++++++++
5 files changed, 355 insertions(+), 24 deletions(-)
diff --git a/.github/workflows/java-info.yml b/.github/workflows/java-info.yml
new file mode 100644
index 00000000..7463a129
--- /dev/null
+++ b/.github/workflows/java-info.yml
@@ -0,0 +1,70 @@
+# 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.
+
+name: GraphAr Java-Info CI
+
+on:
+ # Trigger the workflow on push or pull request,
+ # but only for the main branch
+ push:
+ branches:
+ - main
+ paths:
+ - 'maven-projects/info/**'
+ - '.github/workflows/java-info.yml'
+ pull_request:
+ branches:
+ - main
+ paths:
+ - 'maven-projects/info/**'
+ - '.github/workflows/java-info.yml'
+
+concurrency:
+ group: ${{ github.repository }}-${{ github.event.number || github.head_ref
|| github.sha }}-${{ github.workflow }}
+ cancel-in-progress: true
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ env:
+ GAR_TEST_DATA: ${{ github.workspace }}/graphar-testing/
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ submodules: true
+
+ - name: Install dependencies
+ run: |
+ git clone https://github.com/apache/incubator-graphar-testing.git
$GAR_TEST_DATA --depth 1
+
+ - name: Code Format Check
+ working-directory: maven-projects/info
+ run: |
+ export JAVA_HOME=${JAVA_HOME_11_X64}
+ mvn --no-transfer-progress spotless:check
+
+ - name: Build Java Docs
+ working-directory: maven-projects/info
+ run: |
+ export JAVA_HOME=${JAVA_HOME_11_X64}
+ mvn --no-transfer-progress javadoc:javadoc
+
+ - name: Run test
+ working-directory: maven-projects/info
+ run: |
+ export JAVA_HOME=${JAVA_HOME_11_X64}
+ mvn --no-transfer-progress clean test -Dspotless.check.skip=true
diff --git a/maven-projects/info/pom.xml b/maven-projects/info/pom.xml
index 2bc9db5f..3df2b5ba 100644
--- a/maven-projects/info/pom.xml
+++ b/maven-projects/info/pom.xml
@@ -94,7 +94,7 @@
<configuration>
<java>
<googleJavaFormat>
- <version>11</version>
+ <version>1.7</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/loader/LocalYamlGraphLoader.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/loader/LocalYamlGraphLoader.java
index 939b1836..6ca462ed 100644
---
a/maven-projects/info/src/main/java/org/apache/graphar/info/loader/LocalYamlGraphLoader.java
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/loader/LocalYamlGraphLoader.java
@@ -19,6 +19,13 @@
package org.apache.graphar.info.loader;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.graphar.info.EdgeInfo;
import org.apache.graphar.info.GraphInfo;
import org.apache.graphar.info.VertexInfo;
@@ -29,17 +36,8 @@ import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-
public class LocalYamlGraphLoader implements GraphLoader {
- public LocalYamlGraphLoader() {
- }
+ public LocalYamlGraphLoader() {}
@Override
public GraphInfo load(String graphYamlPath) throws IOException {
diff --git
a/maven-projects/info/src/main/java/org/apache/graphar/info/saver/LocalYamlGraphSaver.java
b/maven-projects/info/src/main/java/org/apache/graphar/info/saver/LocalYamlGraphSaver.java
index 7e464c1e..7038fbb3 100644
---
a/maven-projects/info/src/main/java/org/apache/graphar/info/saver/LocalYamlGraphSaver.java
+++
b/maven-projects/info/src/main/java/org/apache/graphar/info/saver/LocalYamlGraphSaver.java
@@ -19,23 +19,26 @@
package org.apache.graphar.info.saver;
-import org.apache.graphar.info.EdgeInfo;
-import org.apache.graphar.info.GraphInfo;
-import org.apache.graphar.info.VertexInfo;
-
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
+import org.apache.graphar.info.EdgeInfo;
+import org.apache.graphar.info.GraphInfo;
+import org.apache.graphar.info.VertexInfo;
public class LocalYamlGraphSaver implements GraphSaver {
@Override
public void save(String path, GraphInfo graphInfo) throws IOException {
- final Path outputPath = FileSystems
- .getDefault()
- .getPath(path + FileSystems.getDefault().getSeparator() +
graphInfo.getName() + ".graph.yaml");
+ final Path outputPath =
+ FileSystems.getDefault()
+ .getPath(
+ path
+ +
FileSystems.getDefault().getSeparator()
+ + graphInfo.getName()
+ + ".graph.yaml");
Files.createDirectories(outputPath.getParent());
Files.createFile(outputPath);
final BufferedWriter writer = Files.newBufferedWriter(outputPath);
@@ -51,9 +54,13 @@ public class LocalYamlGraphSaver implements GraphSaver {
}
private void saveVertex(String path, VertexInfo vertexInfo) throws
IOException {
- final Path outputPath = FileSystems
- .getDefault()
- .getPath(path + FileSystems.getDefault().getSeparator() +
vertexInfo.getType() + ".vertex.yaml");
+ final Path outputPath =
+ FileSystems.getDefault()
+ .getPath(
+ path
+ +
FileSystems.getDefault().getSeparator()
+ + vertexInfo.getType()
+ + ".vertex.yaml");
Files.createDirectories(outputPath.getParent());
Files.createFile(outputPath);
final BufferedWriter writer = Files.newBufferedWriter(outputPath);
@@ -62,9 +69,13 @@ public class LocalYamlGraphSaver implements GraphSaver {
}
private void saveEdge(String path, EdgeInfo edgeInfo) throws IOException {
- final Path outputPath = FileSystems
- .getDefault()
- .getPath(path + FileSystems.getDefault().getSeparator() +
edgeInfo.getConcat() + ".edge.yaml");
+ final Path outputPath =
+ FileSystems.getDefault()
+ .getPath(
+ path
+ +
FileSystems.getDefault().getSeparator()
+ + edgeInfo.getConcat()
+ + ".edge.yaml");
Files.createDirectories(outputPath.getParent());
Files.createFile(outputPath);
final BufferedWriter writer = Files.newBufferedWriter(outputPath);
diff --git
a/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoTest.java
b/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoTest.java
new file mode 100644
index 00000000..55ca737d
--- /dev/null
+++
b/maven-projects/info/src/test/java/org/apache/graphar/info/GraphInfoTest.java
@@ -0,0 +1,252 @@
+/*
+ * 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.graphar.info;
+
+import java.io.IOException;
+import org.apache.graphar.info.loader.GraphLoader;
+import org.apache.graphar.info.loader.LocalYamlGraphLoader;
+import org.apache.graphar.proto.AdjListType;
+import org.apache.graphar.proto.DataType;
+import org.apache.graphar.proto.FileType;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class GraphInfoTest {
+
+ private static GraphInfo graphInfo;
+ private static VertexInfo personVertexInfo;
+ private static EdgeInfo knowsEdgeInfo;
+
+ @BeforeClass
+ public static void setUp() {
+ TestUtil.checkTestData();
+ final GraphLoader graphLoader = new LocalYamlGraphLoader();
+ final String GRAPH_PATH = TestUtil.getLdbcSampleGraphPath();
+ try {
+ graphInfo = graphLoader.load(GRAPH_PATH);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ personVertexInfo = graphInfo.getVertexInfos().get(0);
+ knowsEdgeInfo = graphInfo.getEdgeInfos().get(0);
+ }
+
+ @AfterClass
+ public static void clean() {}
+
+ @Test
+ public void testGraphInfoBasics() {
+ Assert.assertNotNull(graphInfo);
+ Assert.assertEquals("ldbc_sample", graphInfo.getName());
+ Assert.assertEquals("", graphInfo.getPrefix());
+ Assert.assertNotNull(graphInfo.getEdgeInfos());
+ Assert.assertEquals(1, graphInfo.getEdgeInfos().size());
+ Assert.assertNotNull(graphInfo.getVertexInfos());
+ Assert.assertEquals(1, graphInfo.getVertexInfos().size());
+ }
+
+ @Test
+ public void testPersonVertexInfoBasics() {
+ VertexInfo personVertexInfo = graphInfo.getVertexInfos().get(0);
+ Assert.assertEquals("person", personVertexInfo.getType());
+ Assert.assertEquals(100, personVertexInfo.getChunkSize());
+ Assert.assertEquals("vertex/person/", personVertexInfo.getPrefix());
+ Assert.assertEquals(
+ "vertex/person//vertex_count",
+ personVertexInfo.getVerticesNumFilePath()); // TODO remove
extra '/' issue#698
+ Assert.assertEquals("vertex/person//person.vertex.yaml",
personVertexInfo.getVertexPath());
+ Assert.assertNotNull(personVertexInfo.getPropertyGroups());
+ Assert.assertEquals(2, personVertexInfo.getPropertyGroups().size());
+ }
+
+ @Test
+ public void testPersonVertexPropertyGroup() {
+ // group1 id
+ PropertyGroup idPropertyGroup =
personVertexInfo.getPropertyGroups().get(0);
+ Assert.assertEquals("id/", idPropertyGroup.getPrefix());
+ Assert.assertEquals(FileType.CSV, idPropertyGroup.getFileType());
+ Assert.assertEquals(
+ "vertex/person//id/",
personVertexInfo.getPropertyGroupPrefix(idPropertyGroup));
+ Assert.assertEquals(
+ "vertex/person//id//chunk0",
+ personVertexInfo.getPropertyGroupChunkPath(idPropertyGroup,
0));
+ Assert.assertEquals(
+ "vertex/person//id//chunk4",
+ personVertexInfo.getPropertyGroupChunkPath(idPropertyGroup,
4));
+ Assert.assertNotNull(idPropertyGroup.getPropertyList());
+ Assert.assertEquals(1, idPropertyGroup.getPropertyList().size());
+ Property idProperty = idPropertyGroup.getPropertyList().get(0);
+ Assert.assertTrue(personVertexInfo.hasProperty("id"));
+ Assert.assertEquals("id", idProperty.getName());
+ Assert.assertEquals(DataType.INT64, idProperty.getDataType());
+ Assert.assertTrue(idProperty.isPrimary());
+ Assert.assertFalse(idProperty.isNullable());
+ // group2 firstName_lastName_gender
+ PropertyGroup firstName_lastName_gender =
personVertexInfo.getPropertyGroups().get(1);
+ Assert.assertEquals("firstName_lastName_gender/",
firstName_lastName_gender.getPrefix());
+ Assert.assertEquals(FileType.CSV,
firstName_lastName_gender.getFileType());
+ Assert.assertEquals(
+ "vertex/person//firstName_lastName_gender/",
+
personVertexInfo.getPropertyGroupPrefix(firstName_lastName_gender));
+ Assert.assertEquals(
+ "vertex/person//firstName_lastName_gender//chunk0",
+
personVertexInfo.getPropertyGroupChunkPath(firstName_lastName_gender, 0));
+ Assert.assertEquals(
+ "vertex/person//firstName_lastName_gender//chunk4",
+
personVertexInfo.getPropertyGroupChunkPath(firstName_lastName_gender, 4));
+ Assert.assertNotNull(firstName_lastName_gender.getPropertyList());
+ Assert.assertEquals(3,
firstName_lastName_gender.getPropertyList().size());
+ Property firstNameProperty =
firstName_lastName_gender.getPropertyList().get(0);
+ Assert.assertTrue(personVertexInfo.hasProperty("firstName"));
+ Assert.assertEquals("firstName", firstNameProperty.getName());
+ Assert.assertEquals(DataType.STRING, firstNameProperty.getDataType());
+ Assert.assertFalse(firstNameProperty.isPrimary());
+ Assert.assertTrue(firstNameProperty.isNullable());
+ Property lastNameProperty =
firstName_lastName_gender.getPropertyList().get(1);
+ Assert.assertTrue(personVertexInfo.hasProperty("lastName"));
+ Assert.assertEquals("lastName", lastNameProperty.getName());
+ Assert.assertEquals(DataType.STRING, lastNameProperty.getDataType());
+ Assert.assertFalse(lastNameProperty.isPrimary());
+ Assert.assertTrue(lastNameProperty.isNullable());
+ Property genderProperty =
firstName_lastName_gender.getPropertyList().get(2);
+ Assert.assertTrue(personVertexInfo.hasProperty("gender"));
+ Assert.assertEquals("gender", genderProperty.getName());
+ Assert.assertEquals(DataType.STRING, genderProperty.getDataType());
+ Assert.assertFalse(genderProperty.isPrimary());
+ Assert.assertTrue(genderProperty.isNullable());
+ }
+
+ @Test
+ public void testKnowEdgeInfoBasic() {
+ Assert.assertEquals("knows", knowsEdgeInfo.getEdgeLabel());
+ Assert.assertEquals(1024, knowsEdgeInfo.getChunkSize());
+ Assert.assertEquals("person", knowsEdgeInfo.getSrcLabel());
+ Assert.assertEquals(100, knowsEdgeInfo.getSrcChunkSize());
+ Assert.assertEquals("person", knowsEdgeInfo.getDstLabel());
+ Assert.assertEquals(100, knowsEdgeInfo.getDstChunkSize());
+ Assert.assertFalse(knowsEdgeInfo.isDirected());
+ Assert.assertEquals("person_knows_person", knowsEdgeInfo.getConcat());
+ Assert.assertEquals("edge/person_knows_person/",
knowsEdgeInfo.getPrefix());
+ Assert.assertEquals(
+ "edge/person_knows_person//person_knows_person.edge.yaml",
+ knowsEdgeInfo.getEdgePath());
+ }
+
+ @Test
+ public void testKnowsEdgeAdjacencyLists() {
+ Assert.assertEquals(2, knowsEdgeInfo.getAdjacentLists().size());
+ // test ordered by source adjacency list
+ AdjacentList adjOrderBySource =
+ knowsEdgeInfo.getAdjacentList(AdjListType.ORDERED_BY_SOURCE);
+ Assert.assertEquals(FileType.CSV, adjOrderBySource.getFileType());
+ Assert.assertEquals(AdjListType.ORDERED_BY_SOURCE,
adjOrderBySource.getType());
+ Assert.assertEquals("ordered_by_source/",
adjOrderBySource.getPrefix());
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_source//adj_list/vertex_count",
+
knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ORDERED_BY_SOURCE));
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_source//adj_list/edge_count0",
+
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_SOURCE, 0));
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_source//adj_list/edge_count4",
+
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_SOURCE, 4));
+ Assert.assertEquals(
+ "edge/person_knows_person//ordered_by_source//adj_list",
+
knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ORDERED_BY_SOURCE));
+ Assert.assertEquals(
+ "edge/person_knows_person//ordered_by_source//adj_list/chunk0",
+
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_SOURCE, 0));
+ Assert.assertEquals(
+ "edge/person_knows_person//ordered_by_source//adj_list/chunk4",
+
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_SOURCE, 4));
+ Assert.assertEquals(
+ "edge/person_knows_person//ordered_by_source//adj_list/offset",
+ knowsEdgeInfo.getOffsetPrefix(AdjListType.ORDERED_BY_SOURCE));
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_source//adj_list/offset/chunk0",
+
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_SOURCE, 0));
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_source//adj_list/offset/chunk4",
+
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_SOURCE, 4));
+
+ // test ordered by destination adjacency list
+ AdjacentList adjOrderByDestination =
+
knowsEdgeInfo.getAdjacentList(AdjListType.ORDERED_BY_DESTINATION);
+ Assert.assertEquals(FileType.CSV, adjOrderByDestination.getFileType());
+ Assert.assertEquals(AdjListType.ORDERED_BY_DESTINATION,
adjOrderByDestination.getType());
+ Assert.assertEquals("ordered_by_dest/",
adjOrderByDestination.getPrefix());
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_dest//adj_list/vertex_count",
+
knowsEdgeInfo.getVerticesNumFilePath(AdjListType.ORDERED_BY_DESTINATION));
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_dest//adj_list/edge_count0",
+
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_DESTINATION, 0));
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_dest//adj_list/edge_count4",
+
knowsEdgeInfo.getEdgesNumFilePath(AdjListType.ORDERED_BY_DESTINATION, 4));
+ Assert.assertEquals(
+ "edge/person_knows_person//ordered_by_dest//adj_list",
+
knowsEdgeInfo.getAdjacentListPrefix(AdjListType.ORDERED_BY_DESTINATION));
+ Assert.assertEquals(
+ "edge/person_knows_person//ordered_by_dest//adj_list/chunk0",
+
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_DESTINATION, 0));
+ Assert.assertEquals(
+ "edge/person_knows_person//ordered_by_dest//adj_list/chunk4",
+
knowsEdgeInfo.getAdjacentListChunkPath(AdjListType.ORDERED_BY_DESTINATION, 4));
+ Assert.assertEquals(
+ "edge/person_knows_person//ordered_by_dest//adj_list/offset",
+
knowsEdgeInfo.getOffsetPrefix(AdjListType.ORDERED_BY_DESTINATION));
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_dest//adj_list/offset/chunk0",
+
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_DESTINATION, 0));
+ Assert.assertEquals(
+
"edge/person_knows_person//ordered_by_dest//adj_list/offset/chunk4",
+
knowsEdgeInfo.getOffsetChunkPath(AdjListType.ORDERED_BY_DESTINATION, 4));
+ }
+
+ @Test
+ public void testKnowsEdgePropertyGroup() {
+ Assert.assertEquals(1, knowsEdgeInfo.getPropertyGroupNum());
+ // edge properties group 1
+ PropertyGroup propertyGroup = knowsEdgeInfo.getPropertyGroups().get(0);
+ Assert.assertEquals("creationDate/", propertyGroup.getPrefix());
+ Assert.assertEquals(FileType.CSV, propertyGroup.getFileType());
+ Assert.assertEquals(
+ "edge/person_knows_person//creationDate/",
+ knowsEdgeInfo.getPropertyGroupPrefix(propertyGroup));
+ Assert.assertEquals(
+ "edge/person_knows_person//creationDate//chunk0",
+ knowsEdgeInfo.getPropertyGroupChunkPath(propertyGroup, 0));
+ Assert.assertEquals(
+ "edge/person_knows_person//creationDate//chunk4",
+ knowsEdgeInfo.getPropertyGroupChunkPath(propertyGroup, 4));
+ // edge properties in group 1
+ Assert.assertNotNull(propertyGroup.getPropertyList());
+ Assert.assertEquals(1, propertyGroup.getPropertyList().size());
+ Property property = propertyGroup.getPropertyList().get(0);
+ Assert.assertTrue(knowsEdgeInfo.hasProperty("creationDate"));
+ Assert.assertEquals("creationDate", property.getName());
+ Assert.assertEquals(DataType.STRING, property.getDataType());
+ Assert.assertFalse(property.isPrimary());
+ Assert.assertTrue(property.isNullable());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]