@Override public void acquireLock(LockType lockType, PropertyContainer element) { TransactionImpl tx = getCurrentTransaction(); switch (lockType) { case READ: invoke(lockManager, "getReadLock", Pair.<Class,Object>of(Object.class,element), Pair.<Class,Object>of(Transaction.class,tx)); invoke(lockReleaser, "addLockToTransaction", Pair.<Class,Object>of(Object.class,element),Pair.<Class,Object>of(LockType.class,LockType.READ), Pair.<Class,Object>of(Transaction.class,tx)); break; case WRITE: invoke(lockManager, "getWriteLock", Pair.<Class,Object>of(Object.class,element), Pair.<Class,Object>of(Transaction.class,tx)); invoke(lockReleaser, "addLockToTransaction", Pair.<Class,Object>of(Object.class,element),Pair.<Class,Object>of(LockType.class,LockType.WRITE), Pair.<Class,Object>of(Transaction.class,tx)); break; default: throw new IllegalStateException("Unknown lock type "+lockType); } }
private Object invoke(Object target, String methodName,Pair<Class,?>...params) { try { Class[] types=new Class[params.length]; Object[] values=new Object[params.length]; for (int i = 0; i < params.length; i++) { types[i] = params[i].first(); values[i] = params[i].other(); } Method method = target.getClass().getMethod(methodName,types); return method.invoke(target,values); } catch(Exception e) { System.out.println(target); System.out.println(target.getClass()); throw new RuntimeException(e); } }
@Test public void canCreateNodesAndEdgesInGremlinLand() { String result = session.evaluate( "g.addVertex(null)" ).first(); assertEquals( "v[1]" + NEWLINE, result ); result = session.evaluate( "g.V.next(2)" ).first(); assertEquals( "v[0]" + NEWLINE+"v[1]" + NEWLINE, result ); result = session.evaluate( "g.addVertex(null)" ).first(); assertEquals( "v[2]" + NEWLINE, result ); result = session.evaluate( "g.addEdge(g.v(1), g.v(2), 'knows')" ).first(); assertEquals( "e[0][1-knows->2]" + NEWLINE, result ); result = session.evaluate( "g.v(1).out" ).first(); assertEquals( "v[2]" + NEWLINE, result ); }
return Pair.of(NODES_VISITED.size(), timeElapsed);
@Override protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next ) { NodeRecord node = new NodeRecord( 42, false, -1, -1 ); node.setInUse( true ); List<DynamicRecord> dynamicRecords; dynamicRecords = pair.first(); labels.addAll( pair.other() ); node.setLabelField( dynamicPointer( dynamicRecords ), dynamicRecords ); tx.create( node ); } } );
@Test public void retrievesTheReferenceNode() { String result = session.evaluate( "g" ).first(); assertEquals( String.format( "neo4jgraph[%s]" + NEWLINE, database.getGraph().toString() ), result ); }
public Pair<Integer, Long> depthFirstFindOne(Node startNode, final int depth, final int internalId) { try (Transaction tx = graphDb.beginTx()) { NODES_VISITED = new HashSet<Long>();; TraversalDescription traversalDescription = Traversal.description() .relationships(CHILD) .evaluator(new Evaluator() { @Override public Evaluation evaluate(Path path) { if (((Integer) path.endNode().getProperty(LEVEL_ID)).equals(internalId) && ((Integer) path.endNode().getProperty("depthLevel")).equals(depth)) { // if (((Integer) path.endNode().getProperty(NODE_ID)).equals(internalId)) { return Evaluation.INCLUDE_AND_PRUNE; } NODES_VISITED.add(path.endNode().getId()); return Evaluation.EXCLUDE_AND_CONTINUE; } }) .depthFirst().uniqueness(Uniqueness.NODE_GLOBAL); Iterable<Node> nodes = traversalDescription.traverse(startNode).nodes(); long startTime = System.currentTimeMillis(); if (!nodes.iterator().hasNext()) { throw new IllegalArgumentException("Not found:" + internalId + " on level:" + depth); } Node node = nodes.iterator().next(); long timeElapsed = System.currentTimeMillis() - startTime; // logger.info("DEPTH FIRST find by internal id " + internalId + " returned " + node.getId() + " node, took " + timeElapsed + " millis." + "nodes visited:" + NODES_VISITED); return Pair.of(NODES_VISITED.size(), timeElapsed); } }
@Test public void testGremlinVersion() { String result = session.evaluate( "Gremlin.version()" ).first(); assertEquals( "1.5" + NEWLINE, result ); }
result = ex.getMessage(); return Pair.of( result, null );
@Test public void shouldNotReportAnythingForNodeWithConsistentChainOfDynamicRecordsWithLabels() throws Exception { // given assertEquals( 3, chainOfDynamicRecordsWithLabelsForANode( 130 ).first().size() ); // when ConsistencySummaryStatistics stats = check(); // then assertTrue( "should be consistent", stats.isConsistent() ); }
public Node createNodeWithChildren(int childrenPerNode, int nodeDepthLevel, int maxDepthLevel) { Node node = graphDb.createNode(); node.setProperty("depthLevel", nodeDepthLevel); node.setProperty(NODE_ID, nodecnt); nodecnt++; Integer id = this.ids.get(nodeDepthLevel); if (id == null) { id = 0; } id++; this.ids.put(nodeDepthLevel, id); node.setProperty(LEVEL_ID, id); if (nodeDepthLevel == maxDepthLevel) { return node; } for (int i = 0; i < childrenPerNode; i++) { Node child = createNodeWithChildren(childrenPerNode, nodeDepthLevel + 1, maxDepthLevel); relationshipsToCreate.add(Pair.of(node.getId(), child.getId())); } if(relationshipsToCreate.size() % 10000 == 0){ tx.success(); tx.finish(); tx = graphDb.beginTx(); } return node; }
final List<DynamicRecord> chain = chainOfDynamicRecordsWithLabelsForANode( 176/*3 full records*/ ).first(); assertEquals( "number of records in chain", 3, chain.size() ); assertEquals( "all records full", chain.get( 0 ).getLength(), chain.get( 2 ).getLength() );
return Pair.of( chain, createdLabels );
final List<DynamicRecord> chain = chainOfDynamicRecordsWithLabelsForANode( 130 ).first(); assertEquals( 3, chain.size() ); fixture.apply( new GraphStoreFixture.Transaction()
/** * Send a Gremlin Script, as JSON payload and additional parameters */ @Test @Title( "Send a Gremlin Script with variables in a JSON Map" ) @Documented @Graph( value = { "I know you" } ) public void testGremlinPostWithVariablesAsJson() throws UnsupportedEncodingException { String response = doRestCall( "g.v(me).out", OK, Pair.of( "me", data.get().get( "I" ).getId() + "" ) ); assertTrue( response.contains( "you" ) ); }