Coverage Summary for Class: TinkerpopTest (org.umlg.sqlg.test)
Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
TinkerpopTest |
0%
(0/1)
|
0%
(0/7)
|
0%
(0/30)
|
0%
(0/62)
|
package org.umlg.sqlg.test;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.MapHelper;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
import org.junit.Assert;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
import static org.junit.Assert.assertEquals;
/**
* Date: 2014/07/13
* Time: 6:32 PM
*/
public class TinkerpopTest extends BaseTest {
private static final String partition = "gremlin.partitionGraphStrategy.partition";
//This no longer works on jdk 17
// @Test
public void testTail() throws IOException {
Graph graph = this.sqlgGraph;
final GraphReader reader = GryoReader.build()
.mapper(graph.io(GryoIo.build()).mapper().create())
.create();
try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/tinkerpop-modern.kryo")) {
reader.readGraph(stream, graph);
}
assertModernGraph(graph, true, false);
GraphTraversalSource g = graph.traversal();
int tail = 0;
for (int i = 1; i < 72; i++) {
tail = i;
List<Vertex> vertices = g.V().repeat(both()).times(3).tail(tail).toList();
if (tail != vertices.size()) {
System.out.println("expected " + tail + " found " + vertices.size());
}
}
}
// @Test
public void g_V_chooseXlabel_eq_person__unionX__out_lang__out_nameX__in_labelX() throws IOException {
Graph graph = this.sqlgGraph;
final GraphReader reader = GryoReader.build()
.mapper(graph.io(GryoIo.build()).mapper().create())
.create();
try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/tinkerpop-modern.kryo")) {
reader.readGraph(stream, graph);
}
assertModernGraph(graph, true, false);
GraphTraversalSource g = graph.traversal();
List<Vertex> traversala2 = g.V().hasId(convertToVertexId("marko")).toList();
Assert.assertEquals(1, traversala2.size());
Assert.assertEquals(convertToVertex(graph, "marko"), traversala2.get(0));
}
public static <T> void checkResults(final Map<T, Long> expectedResults, final Traversal<?, T> traversal) {
final List<T> list = new ArrayList<>();
expectedResults.forEach((k, v) -> {
for (int i = 0; i < v; i++) {
list.add(k);
}
});
checkResults(list, traversal);
}
protected static <T> void checkResults(final List<T> expectedResults, final Traversal<?, T> traversal) {
final List<T> results = traversal.toList();
Assert.assertFalse(traversal.hasNext());
if(expectedResults.size() != results.size()) {
System.err.println("Expected results: " + expectedResults);
System.err.println("Actual results: " + results);
assertEquals("Checking result size", expectedResults.size(), results.size());
}
for (T t : results) {
if (t instanceof Map) {
//noinspection unchecked
Assert.assertTrue("Checking map result existence: " + t, expectedResults.stream().filter(e -> e instanceof Map).anyMatch(e -> checkMap((Map) e, (Map) t)));
} else {
Assert.assertTrue("Checking result existence: " + t, expectedResults.contains(t));
}
}
final Map<T, Long> expectedResultsCount = new HashMap<>();
final Map<T, Long> resultsCount = new HashMap<>();
assertEquals("Checking indexing is equivalent", expectedResultsCount.size(), resultsCount.size());
expectedResults.forEach(t -> MapHelper.incr(expectedResultsCount, t, 1L));
results.forEach(t -> MapHelper.incr(resultsCount, t, 1L));
expectedResultsCount.forEach((k, v) -> assertEquals("Checking result group counts", v, resultsCount.get(k)));
Assert.assertFalse(traversal.hasNext());
}
private static <A, B> boolean checkMap(final Map<A, B> expectedMap, final Map<A, B> actualMap) {
final List<Map.Entry<A, B>> actualList = actualMap.entrySet().stream().sorted((a, b) -> a.getKey().toString().compareTo(b.getKey().toString())).collect(Collectors.toList());
final List<Map.Entry<A, B>> expectedList = expectedMap.entrySet().stream().sorted((a, b) -> a.getKey().toString().compareTo(b.getKey().toString())).collect(Collectors.toList());
if (expectedList.size() > actualList.size()) {
return false;
} else if (actualList.size() > expectedList.size()) {
return false;
}
for (int i = 0; i < actualList.size(); i++) {
if (!actualList.get(i).getKey().equals(expectedList.get(i).getKey())) {
return false;
}
if (!actualList.get(i).getValue().equals(expectedList.get(i).getValue())) {
return false;
}
}
return true;
}
}