use of java.util.HashSet in project blueprints by tinkerpop.
the class EventTransactionalGraphTest method testWrappedElementUniqueness.
public void testWrappedElementUniqueness() {
graph.addListener(new ConsoleGraphChangedListener(graph));
assertEquals(graph.getVertex(1), graph.getVertex(1));
Set<Vertex> set = new HashSet<Vertex>();
set.add(graph.getVertex(2));
set.add(graph.getVertex(2));
assertEquals(set.size(), 1);
assertEquals(graph.getEdge(7).hashCode(), graph.getEdge(7).hashCode());
assertEquals(graph.getEdge(8), graph.getEdge(8));
}
use of java.util.HashSet in project blueprints by tinkerpop.
the class Neo4jBatchGraphTest method testAddingVerticesEdgesWithIndices.
public void testAddingVerticesEdgesWithIndices() {
final String directory = this.getWorkingDirectory();
final Neo4jBatchGraph batch = new Neo4jBatchGraph(directory);
assertEquals(0, count(batch.getIndices()));
batch.createKeyIndex("name", Vertex.class);
batch.createKeyIndex("age", Vertex.class);
Index<Edge> edgeIndex = batch.createIndex("edgeIdx", Edge.class);
assertEquals(1, count(batch.getIndices()));
for (final Index index : batch.getIndices()) {
if (index.getIndexName().equals("edgeIdx")) {
assertEquals(index.getIndexClass(), Edge.class);
} else {
throw new RuntimeException("There should not be another index.");
}
}
final List<Long> ids = new ArrayList<Long>();
for (int i = 0; i < 10; i++) {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("name", i + "");
map.put("age", i * 10);
map.put("nothing", 0);
ids.add((Long) batch.addVertex(map).getId());
}
for (int i = 1; i < ids.size(); i++) {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("weight", 0.5f);
long idA = ids.get(i - 1);
long idB = ids.get(i);
final Edge edge = batch.addEdge(map, batch.getVertex(idA), batch.getVertex(idB), idA + "-" + idB);
edgeIndex.put("unique", idA + "-" + idB, edge);
edgeIndex.put("full", "blah", edge);
}
batch.flushIndices();
batch.shutdown();
// native neo4j graph load
final Neo4jGraph graph = new Neo4jGraph(directory);
assertEquals(count(graph.getIndices()), 1);
assertEquals(graph.getIndexedKeys(Vertex.class).size(), 2);
assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));
assertTrue(graph.getIndexedKeys(Vertex.class).contains("age"));
edgeIndex = graph.getIndex("edgeIdx", Edge.class);
assertEquals(edgeIndex.getIndexClass(), Edge.class);
assertEquals(count(graph.getVertices()), 10);
assertTrue(graph.getVertices("nothing", 0) instanceof PropertyFilteredIterable);
assertTrue(graph.getVertices("blah", "blop") instanceof PropertyFilteredIterable);
// key index used
assertFalse(graph.getVertices("name", "marko") instanceof PropertyFilteredIterable);
// key indexed used
assertFalse(graph.getVertices("age", 32) instanceof PropertyFilteredIterable);
for (final Vertex vertex : graph.getVertices()) {
int age = (Integer) vertex.getProperty("age");
assertEquals(vertex.getProperty("name"), (age / 10) + "");
assertTrue(graph.getVertices("nothing", 0).iterator().hasNext());
assertEquals(count(graph.getVertices("age", age)), 1);
assertEquals(graph.getVertices("age", age).iterator().next(), vertex);
assertEquals(count(graph.getVertices("name", (age / 10) + "")), 1);
assertEquals(graph.getVertices("name", (age / 10) + "").iterator().next(), vertex);
assertEquals(vertex.getPropertyKeys().size(), 3);
vertex.setProperty("NEW", age);
assertEquals(vertex.getPropertyKeys().size(), 4);
}
for (final Vertex vertex : graph.getVertices()) {
int age = (Integer) vertex.getProperty("age");
assertEquals(vertex.getProperty("NEW"), age);
assertEquals(vertex.getPropertyKeys().size(), 4);
vertex.removeProperty("NEW");
}
for (final Vertex vertex : graph.getVertices()) {
assertNull(vertex.getProperty("NEW"));
assertEquals(vertex.getPropertyKeys().size(), 3);
}
assertEquals(count(graph.getEdges()), 9);
assertEquals(count(edgeIndex.get("full", "blah")), 9);
Set<Edge> edges = new HashSet<Edge>();
for (Edge edge : edgeIndex.get("full", "blah")) {
edges.add(edge);
}
assertEquals(edges.size(), 9);
for (final Edge edge : graph.getEdges()) {
long idA = (Long) edge.getVertex(Direction.OUT).getId();
long idB = (Long) edge.getVertex(Direction.IN).getId();
assertEquals(idA + 1, idB);
assertEquals(edge.getLabel(), idA + "-" + idB);
assertEquals(edge.getPropertyKeys().size(), 1);
assertEquals(edge.getProperty("weight"), 0.5f);
assertEquals(edgeIndex.count("weight", 0.5f), 0);
assertEquals(edgeIndex.count("unique", idA + "-" + idB), 1);
assertEquals(edgeIndex.get("unique", idA + "-" + idB).iterator().next(), edge);
assertTrue(edges.contains(edge));
}
graph.shutdown();
}
use of java.util.HashSet in project blueprints by tinkerpop.
the class SailGraphSpecificTestSuite method testAddManyVertexProperties.
public void testAddManyVertexProperties() {
SailGraph graph = (SailGraph) graphTest.generateGraph();
Set<Vertex> vertices = new HashSet<Vertex>();
this.stopWatch();
for (int i = 0; i < 50; i++) {
Vertex vertex = graph.addVertex("\"" + UUID.randomUUID().toString() + "\"");
for (int j = 0; j < 15; j++) {
vertex.setProperty(SailTokens.DATATYPE, "http://www.w3.org/2001/XMLSchema#anyURI");
}
vertices.add(vertex);
}
printPerformance(graph.toString(), 15 * 50, "vertex properties added (with vertices being added too)", this.stopWatch());
if (graph.getFeatures().supportsVertexIteration)
assertEquals(count(graph.getVertices()), 50);
assertEquals(vertices.size(), 50);
for (Vertex vertex : vertices) {
assertEquals(3, vertex.getPropertyKeys().size());
assertTrue(vertex.getPropertyKeys().contains(SailTokens.DATATYPE));
assertEquals("http://www.w3.org/2001/XMLSchema#anyURI", vertex.getProperty(SailTokens.DATATYPE));
assertTrue(vertex.getPropertyKeys().contains(SailTokens.VALUE));
assertEquals("literal", vertex.getProperty(SailTokens.KIND));
}
graph.shutdown();
}
use of java.util.HashSet in project blueprints by tinkerpop.
the class TransactionalGraphTestSuite method untestSimulateRexsterIntegrationTests.
public void untestSimulateRexsterIntegrationTests() throws Exception {
// this test simulates the flow of rexster integration test. integration tests requests are generally not made
// in parallel, but it is expected each request they may be processed by different threads from a thread pool
// for each request. this test fails for orientdb given it's optimnisitc locking strategy.
final TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();
if (graph.getFeatures().supportsKeyIndices) {
final String id = "_ID";
((KeyIndexableGraph) graph).createKeyIndex(id, Vertex.class);
final int numberOfVerticesToCreate = 100;
final Random rand = new Random(12356);
final List<String> graphAssignedIds = new ArrayList<String>();
final ExecutorService executorService = Executors.newFixedThreadPool(4);
for (int ix = 0; ix < numberOfVerticesToCreate; ix++) {
final int id1 = ix;
final int id2 = ix + numberOfVerticesToCreate + rand.nextInt();
// add a vertex and block for the thread to complete
executorService.submit(new Runnable() {
@Override
public void run() {
final Vertex v = graph.addVertex(null);
v.setProperty(id, id1);
graph.commit();
graphAssignedIds.add(v.getId().toString());
}
}).get();
if (ix > 0) {
// add a vertex and block for the thread to complete
executorService.submit(new Runnable() {
@Override
public void run() {
final Vertex v = graph.addVertex(null);
v.setProperty(id, id2);
graph.commit();
graphAssignedIds.add(v.getId().toString());
}
}).get();
// add an edge to two randomly selected vertices and block for the thread to complete. integration
// tests tend to fail here, so the code is replicated pretty closely to what is in rexster
// (i.e. serialization to JSON) even though that may have nothing to do with failures.
executorService.submit(new Runnable() {
@Override
public void run() {
final Vertex vActual1 = graph.getVertex(graphAssignedIds.get(rand.nextInt(graphAssignedIds.size())));
final Vertex vActual2 = graph.getVertex(graphAssignedIds.get(rand.nextInt(graphAssignedIds.size())));
final Edge e = graph.addEdge(null, vActual1, vActual2, "knows");
e.setProperty("weight", rand.nextFloat());
JSONObject elementJson = null;
try {
// just replicating rexster
elementJson = GraphSONUtility.jsonFromElement(e, null, GraphSONMode.NORMAL);
} catch (Exception ex) {
fail();
}
graph.commit();
try {
if (elementJson != null) {
// just replicating rexster
elementJson.put("_ID", e.getId());
}
} catch (Exception ex) {
fail();
}
}
}).get();
}
}
final Set<String> ids = new HashSet<String>();
for (final Vertex v : graph.getVertices()) {
ids.add(v.getId().toString());
}
for (final String idToRemove : ids) {
executorService.submit(new Runnable() {
@Override
public void run() {
final Vertex toRemove = graph.getVertex(idToRemove);
graph.removeVertex(toRemove);
graph.commit();
}
});
}
executorService.shutdown();
executorService.awaitTermination(10, TimeUnit.SECONDS);
}
graph.shutdown();
}
use of java.util.HashSet in project blueprints by tinkerpop.
the class GMLReaderTestSuite method testReadingTinkerGraphExample3MappingAll.
public void testReadingTinkerGraphExample3MappingAll() throws Exception {
Graph graph = graphTest.generateGraph();
if (graph.getFeatures().supportsEdgeIteration && graph.getFeatures().supportsVertexIteration) {
this.stopWatch();
GMLReader r = new GMLReader(graph);
r.setVertexIdKey("id2");
r.setEdgeIdKey("id2");
r.setEdgeLabelKey("label2");
r.inputGraph(GMLReader.class.getResourceAsStream("graph-example-3.gml"), 1000);
printPerformance(graph.toString(), null, "graph-example-3 loaded", this.stopWatch());
Set<String> vertexIds = new HashSet<String>();
Set<String> vertexKeys = new HashSet<String>();
Set<String> vertexNames = new HashSet<String>();
int vertexCount = 0;
for (Vertex v : graph.getVertices()) {
vertexCount++;
vertexIds.add(v.getId().toString());
vertexNames.add(v.getProperty("name").toString());
for (String key : v.getPropertyKeys()) {
vertexKeys.add(key);
}
}
Set<String> edgeIds = new HashSet<String>();
Set<String> edgeKeys = new HashSet<String>();
Set<String> edgeLabels = new HashSet<String>();
int edgeCount = 0;
for (Edge e : graph.getEdges()) {
edgeCount++;
edgeIds.add(e.getId().toString());
edgeLabels.add(e.getLabel());
for (String key : e.getPropertyKeys()) {
edgeKeys.add(key);
}
}
assertEquals(vertexCount, 6);
assertEquals(vertexIds.size(), 6);
assertEquals(vertexKeys.contains("name"), true);
assertEquals(vertexKeys.contains("age"), true);
assertEquals(vertexKeys.contains("lang"), true);
assertEquals(vertexKeys.contains("id2"), false);
assertEquals(vertexKeys.size(), 3);
assertTrue(vertexNames.contains("marko"));
assertTrue(vertexNames.contains("josh"));
assertTrue(vertexNames.contains("peter"));
assertTrue(vertexNames.contains("vadas"));
assertTrue(vertexNames.contains("ripple"));
assertTrue(vertexNames.contains("lop"));
assertEquals(edgeCount, 6);
assertEquals(edgeIds.size(), 6);
assertEquals(edgeKeys.contains("weight"), true);
assertEquals(edgeKeys.contains("id2"), false);
assertEquals(edgeKeys.contains("label2"), false);
assertEquals(edgeKeys.size(), 1);
assertEquals(edgeLabels.size(), 2);
assertEquals(edgeLabels.contains("has high fived"), true);
assertEquals(edgeLabels.contains("knows"), false);
assertEquals(edgeLabels.contains("created"), true);
}
graph.shutdown();
}
Aggregations