Skip to content

Commit

Permalink
test(VPack): Adds tests for ArngVPackVertexProperty.
Browse files Browse the repository at this point in the history
#52 Work in progress
  • Loading branch information
arcanefoam committed Jun 26, 2019
1 parent d7d4abc commit ca18196
Show file tree
Hide file tree
Showing 21 changed files with 1,078 additions and 847 deletions.
450 changes: 236 additions & 214 deletions pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public EdgeLoader(ArangoDBGraph graph) {

@Override
public Edge load(String key) {
return graph.getDatabaseClient().getDocument(key, ArangoDBEdge.class);
//return graph.getDatabaseClient().getDocument(key, ArangoDBEdge.class);
return null;
}

@Override
public Map<String, Edge> loadAll(Iterable<? extends String> keys) {
Map<String, Edge> result = new HashMap<>();
ArangoDBIterator<Edge> it = new ArangoDBIterator<>(graph, graph.getDatabaseClient().getGraphEdges(Lists.newArrayList(), Collections.emptyList()));
it.forEachRemaining(e -> result.put((String) e.id(), e));
//ArangoDBIterator<Edge> it = new ArangoDBIterator<>(graph, graph.getDatabaseClient().getGraphEdges(Lists.newArrayList(), Collections.emptyList()));
//it.forEachRemaining(e -> result.put((String) e.id(), e));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public VertexLoader(ArangoDBGraph graph) {

@Override
public Vertex load(String key) {
return graph.getDatabaseClient().getVertex(key, ArangoDBVertex.class);
//return graph.getDatabaseClient().getVertex(key, ArangoDBVertex.class);
return null;
}

@Override
public Map<String, Vertex> loadAll(Iterable<? extends String> keys) {
Map<String, Vertex> result = new HashMap<>();
ArangoDBIterator<Vertex> it = new ArangoDBIterator<>(graph, graph.getDatabaseClient().getGraphVertices(Lists.newArrayList(), Collections.emptyList()));
it.forEachRemaining(v -> result.put((String) v.id(), v));
//ArangoDBIterator<Vertex> it = new ArangoDBIterator<>(graph, graph.getDatabaseClient().getGraphVertices(Lists.newArrayList(), Collections.emptyList()));
//it.forEachRemaining(v -> result.put((String) v.id(), v));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public boolean hasNext() {
@Override
public IType next() {
BaseArngDocument next = (BaseArngDocument) delegate.next();
next.graph(graph);
next.label(graph.getPrefixedCollectioName(next.label));
next.setPaired(true);
//next.graph(graph);
//next.label(graph.getPrefixedCollectioName(next.label));
//next.setPaired(true);
return (IType) next;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class ArangoDBPage<EType extends BaseArngDocument> implements Iterator<ET
final private String startId;
final private int pageSize;
final private String collection;
final private LoadingCache<String, EType> vertices;
final private Class<EType> eType;
//final private LoadingCache<String, EType> vertices;
//final private Class<EType> eType;

public ArangoDBPage(String startId, int pageSize, String collection) {
this.startId = startId;
Expand Down Expand Up @@ -49,7 +49,8 @@ public EType load(String key) {
"and the document primaryKey separated by /.");
}
assert keyInfo[1].equals(collection);
return graph.getDatabaseClient().getElement(keyInfo[0], keyInfo[1], eType);
//return graph.getDatabaseClient().getElement(keyInfo[0], keyInfo[1], eType);
return null;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.*;
import java.util.stream.Collectors;

import static com.arangodb.tinkerpop.gremlin.utils.ArangoDBUtil.edgeDefinitionString;

/**
* An implementaiton of {@link GraphConfiguration} for an ArngGraph.
Expand Down Expand Up @@ -95,8 +94,8 @@ public ArangoDB buildDriver() {
return new ArangoDB.Builder().loadProperties(targetStream)
.registerDeserializer(ArangoDBVertex.class, vertexVpack)
.registerSerializer(ArangoDBVertex.class, vertexVpack)
.registerDeserializer(ArangoDBEdge.class, edgeVPack)
.registerSerializer(ArangoDBEdge.class, edgeVPack)
//.registerDeserializer(ArangoDBEdge.class, edgeVPack)
//.registerSerializer(ArangoDBEdge.class, edgeVPack)
.build();
} catch (IOException e) {
throw new IllegalStateException("Error writing to the output stream when creating drivier.", e);
Expand Down Expand Up @@ -190,7 +189,7 @@ private void checkGraphForErrors(
throw new ArangoDBGraphException(String.format("The 'to' collections dont match for edge definition %s", existing.getCollection()));
}
} else {
throw new ArangoDBGraphException(String.format("The graph has a surplus edge definition %s", edgeDefinitionString(existing)));
throw new ArangoDBGraphException(String.format("The graph has a surplus edge definition")); // TODO %s", edgeDefinitionString(existing)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.arangodb.ArangoCursor;
import com.arangodb.ArangoDBException;
import com.arangodb.tinkerpop.gremlin.structure.ArangoDBGraphVariables;
import com.arangodb.tinkerpop.gremlin.structure.ArngDocument;
import com.google.common.base.Throwables;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
Expand Down Expand Up @@ -136,7 +137,11 @@ public void updateGraphVariables(ArangoDBGraphVariables variables) throws GraphV
}
variables.revision(newRev);
cache.put("variables", variables);
logger.info("ArngDocument updated, new revision {}", variables.revision());
try {
logger.info("ArngDocument updated, new revision {}", variables.revision());
} catch (ArngDocument.ElementNotPairedException e) {
// pass
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public interface GraphConfiguration {

Collection<String> dbEdgeCollections();

void checkGraphForErrors(ArangoGraph databaseGraph, GraphCreateOptions options) throws EdgeDefinitions.MalformedRelationException, ArngGraphConfiguration.MalformedRelationException;
void checkGraphForErrors(ArangoGraph databaseGraph, GraphCreateOptions options) throws ArngGraphConfiguration.MalformedRelationException;

void createGraph(String graphName, GraphCreateOptions options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public class ArangoDBGremlinPlugin extends AbstractGremlinPlugin {
ArangoDBGraphException.class,
ArangoDBIterator.class,
ArangoDBPropertyFilter.class,
ArangoDBPropertyIterator.class,
//ArangoDBPropertyIterator.class,
ArangoDBQueryBuilder.class,
ArangoDBEdge.class,
ArangoDBEdgeProperty.class,
//ArangoDBEdgeProperty.class,
ArngElementProperty.class,
ArangoDBGraph.class,
ArangoDBGraphVariables.class,
ArangoDBPropertyProperty.class,
//ArangoDBPropertyProperty.class,
ArangoDBVertex.class,
ArngVertexProperty.class,
ArangoDBUtil.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import com.arangodb.ArangoDatabase;
Expand Down Expand Up @@ -111,13 +112,13 @@
* <p>
* The list of allowed settings is:
* <ul>
* <li> graphClient.db // The name of the databaseClient
* <li> graphClient.db.create // Create the DB if not found
* <li> graphClient.name // The name of the graphClient
* <li> graphClient.vertex // The name of a vertices label
* <li> graphClient.edge // The name of an edges label
* <li> graphClient.relation // The allowed from/to relations for edges
* <li> graphClient.shouldPrefixCollectionNames // Boolean flag, true if Vertex and Edge collections will be prefixed with graphClient name
* <li> graph.db // The name of the databaseClient
* <li> graph.db.create // Create the DB if not found
* <li> graph.name // The name of the graphClient
* <li> graph.vertex // The name of a vertices label
* <li> graph.edge // The name of an edges label
* <li> graph.relation // The allowed from/to relations for edges
* <li> graph.shouldPrefixCollectionNames // Boolean flag, true if Vertex and Edge collections will be prefixed with graphClient name
* <li> arangodb.hosts
* <li> arangodb.timeout
* <li> arangodb.user
Expand Down Expand Up @@ -631,6 +632,9 @@ public Variables variables() {
}
}

// TODO Move to ONE place
private static final Pattern DOCUMENT_KEY = Pattern.compile("^[A-Za-z0-9_:\\.@()\\+,=;\\$!\\*'%-]*");

@Override
public Vertex addVertex(Object... keyValues) {
logger.info("Creating vertex in graphClient with keyValues: {}", keyValues);
Expand Down Expand Up @@ -661,7 +665,7 @@ public Vertex addVertex(Object... keyValues) {

}
}
Matcher m = ArangoDBUtil.DOCUMENT_KEY.matcher((String)id);
Matcher m = DOCUMENT_KEY.matcher((String)id);
if (!m.matches()) {
throw new ArangoDBGraphException(String.format("Given id (%s) has unsupported characters.", id));
}
Expand Down Expand Up @@ -709,7 +713,8 @@ public Iterator<Vertex> vertices(Object... vertexIds) {
logger.error("Error computing vertices", e);
throw new IllegalStateException(e);
}
return new ArangoDBIterator<Vertex>(this, getDatabaseClient().getGraphVertices(ids, collections));
//return new ArangoDBIterator<Vertex>(this, getDatabaseClient().getGraphVertices(ids, collections));
return null;
}


Expand All @@ -730,7 +735,8 @@ public Iterator<Edge> edges(Object... edgeIds) {
})
.map(id -> id == null ? (String)id : id.toString())
.collect(Collectors.toList());
return new ArangoDBIterator<Edge>(this, getDatabaseClient().getGraphEdges(ids, collections));
//return new ArangoDBIterator<Edge>(this, getDatabaseClient().getGraphEdges(ids, collections));
return null;
}


Expand Down Expand Up @@ -784,7 +790,7 @@ public String name() {

@Override
public Collection<String> vertexCollections() {
return vertexCollections.stream().map(arangoConfig::getDBCollectionName).collect(Collectors.toList();
return vertexCollections.stream().map(arangoConfig::getDBCollectionName).collect(Collectors.toList());
}

/**
Expand All @@ -795,7 +801,7 @@ public Collection<String> vertexCollections() {

@Override
public Collection<String> edgeCollections() {
return edgeCollections.stream().map(arangoConfig::getDBCollectionName).collect(Collectors.toList();
return edgeCollections.stream().map(arangoConfig::getDBCollectionName).collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Iterator;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
Expand Down Expand Up @@ -52,6 +53,9 @@ public CantRemoveValueFromSinglePropertyException(String message) {

private static final Logger logger = LoggerFactory.getLogger(ArangoDBVertex.class);

// TODO Move to ONE place
private static final Pattern DOCUMENT_KEY = Pattern.compile("^[A-Za-z0-9_:\\.@()\\+,=;\\$!\\*'%-]*");

/** All property access is delegated to the property manager */

protected VertexProperties properties;
Expand Down Expand Up @@ -161,7 +165,7 @@ public Edge addEdge(String label, Vertex inVertex, Object... keyValues) {
if (ElementHelper.getIdValue(keyValues).isPresent()) {
Object id = ElementHelper.getIdValue(keyValues).get();
if (graph().features().edge().willAllowId(id)) {
Matcher m = ArangoDBUtil.DOCUMENT_KEY.matcher((String)id);
Matcher m = DOCUMENT_KEY.matcher((String)id);
if (!m.matches()) {
throw new ArangoDBGraphException(String.format("Given id (%s) has unsupported characters.", id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

import java.util.*;


/**
* An implementation of {@link VertexPropertyValue} to be used with {@link ArangoDBVertex}.
* @param <V>
*/
public class ArngVertexPropertyValue<V> implements VertexPropertyValue<V> {

private final VertexProperty.Cardinality cardinality;
Expand Down Expand Up @@ -121,7 +124,7 @@ public VPackVertexProperty preSerialize() {
result = new ArngVPackVertexProperty(cardinality, singleValue);
}
else {
result = result.addPropertyInformation(p);
result = result.addVertexProperty(p);
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public class ArangoDBConfigurationBuilder {
private static final String PROPERTY_KEY_LOAD_BALANCING_STRATEGY = "arangodb.loadBalancingStrategy";
private static final String PROPERTY_KEY_PROTOCOL = "arangodb.protocol";
private static final String PROPERTY_KEY_SHOULD_PREFIX_COLLECTION_NAMES = "arangodb.shouldPrefixCollectionNames";
private static final String PROPERTY_KEY_DB_NAME = "graph.db";
private static final String PROPERTY_KEY_CREATE_DB = "graph.db.create";
private static final String PROPERTY_KEY_GRAPH_NAME = "graph.name";
private static final String PROPERTY_KEY_VERTEX_LABEL = "graph.vertex";
private static final String PROPERTY_KEY_EDGE_LABEL = "graph.edge";
private static final String PROPERTY_KEY_RELATIONS = "graph.relation";
private static final String PROPERTY_KEY_PREFIX_COLLECTIONS = "graph.shouldPrefixCollectionNames";

/** The db name. */
private String dbName = "tinkerpop";
Expand Down Expand Up @@ -130,10 +137,10 @@ public ArangoDBConfigurationBuilder() {
public BaseConfiguration build() {
BaseConfiguration config = new BaseConfiguration();
config.setListDelimiter('/');
config.addProperty(fullPropertyKey(ArangoDBGraph.PROPERTY_KEY_DB_NAME), dbName);
config.addProperty(fullPropertyKey(ArangoDBGraph.PROPERTY_KEY_GRAPH_NAME), graphName);
config.addProperty(fullPropertyKey(ArangoDBGraph.PROPERTY_KEY_VERTICES), vertices);
config.addProperty(fullPropertyKey(ArangoDBGraph.PROPERTY_KEY_EDGES), edges);
config.addProperty(fullPropertyKey(PROPERTY_KEY_DB_NAME), dbName);
config.addProperty(fullPropertyKey(PROPERTY_KEY_GRAPH_NAME), graphName);
config.addProperty(fullPropertyKey(PROPERTY_KEY_VERTEX_LABEL), vertices);
config.addProperty(fullPropertyKey(PROPERTY_KEY_EDGE_LABEL), edges);
List<String> rels = new ArrayList<>();
for (Triple<String, Set<String>, Set<String>> r : relations) {
// Make sure edge and vertex collections have been added
Expand Down Expand Up @@ -163,7 +170,7 @@ public BaseConfiguration build() {

}
if (!rels.isEmpty()) {
config.addProperty(fullPropertyKey(ArangoDBGraph.PROPERTY_KEY_RELATIONS), rels.stream().collect(Collectors.joining("/")));
config.addProperty(fullPropertyKey(PROPERTY_KEY_RELATIONS), rels.stream().collect(Collectors.joining("/")));
}
config.addProperty(fullPropertyKey(PROPERTY_KEY_USER), user);
config.addProperty(fullPropertyKey(PROPERTY_KEY_PASSWORD), password);
Expand Down Expand Up @@ -203,7 +210,7 @@ public BaseConfiguration build() {
}

private String fullPropertyKey(String key) {
return ArangoDBGraph.PROPERTY_KEY_PREFIX + "." + key;
return PROPERTY_KEY_PREFIX_COLLECTIONS + "." + key;
}

/**
Expand Down
Loading

0 comments on commit ca18196

Please sign in to comment.