@Override protected PropertyContainer lookupPropertyContainer( long id ) { return db.getNodeById( id ); }
private Node getNodeById( long id ) { try ( Transaction ignored = dbRule.beginTx() ) { return dbRule.getNodeById( id ); } }
long createRelationshipWithProperty( long firstNodeId, long secondNodeId, String propertyKey, Object propertyValue ) { Node first = db.getNodeById( firstNodeId ); Node second = db.getNodeById( secondNodeId ); Relationship relationship = first.createRelationshipTo( second, RELTYPE ); relationship.setProperty( propertyKey, propertyValue ); return relationship.getId(); }
private Runnable startAnotherTransaction() { return () -> { try ( InternalTransaction ignored = database .beginTransaction( KernelTransaction.Type.implicit, LoginContext.AUTH_DISABLED, 1, TimeUnit.SECONDS ) ) { Node node = database.getNodeById( NODE_ID ); node.setProperty( "c", "d" ); } }; } }
@Test( timeout = 10000 ) public void logRotationMustNotObstructStartingReadTransaction() { try ( Transaction tx = db.beginTx() ) { db.getNodeById( 0 ); tx.success(); completeLogRotationLatch.countDown(); } }
void setNodeProp( long nodeId, String propertyKey, String value ) { try ( Transaction tx = db.beginTx() ) { Node node = db.getNodeById( nodeId ); node.setProperty( propertyKey, value ); tx.success(); } }
@Test public void shouldHandleDeleteNodeConcurrentlyWithIndexDrop() throws Throwable { shouldHandleIndexDropConcurrentlyWithOperation( nodeId -> db.getNodeById( nodeId ).delete() ); }
@Test public void shouldHandleRemovePropertyConcurrentlyWithIndexDrop() throws Throwable { shouldHandleIndexDropConcurrentlyWithOperation( nodeId -> db.getNodeById( nodeId ).removeProperty( KEY ) ); }
@Test public void shouldHandleUpdateRemovalOfLabelConcurrentlyWithIndexDrop() throws Throwable { shouldHandleIndexDropConcurrentlyWithOperation( nodeId -> db.getNodeById( nodeId ).removeLabel( LABEL ) ); }
private void raceContestantsAndVerifyResults( SchemaDescriptor newDescriptor, Runnable aliceWork, Runnable changeConfig, Runnable bobWork ) throws Throwable { race.addContestants( aliceThreads, aliceWork ); race.addContestant( changeConfig ); race.addContestants( bobThreads, bobWork ); race.go(); await( IndexDescriptorFactory.forSchema( newDescriptor, Optional.of( "nodes" ), FulltextIndexProviderFactory.DESCRIPTOR ) ); try ( Transaction tx = db.beginTx() ) { KernelTransaction ktx = kernelTransaction( tx ); ScoreEntityIterator bob = fulltextAdapter.query( ktx, "nodes", "bob" ); List<ScoreEntityIterator.ScoreEntry> list = bob.stream().collect( Collectors.toList() ); try { assertEquals( bobThreads * nodesCreatedPerThread, list.size() ); } catch ( Throwable e ) { StringBuilder sb = new StringBuilder( e.getMessage() ).append( System.lineSeparator() ).append( "Nodes found in query for bob:" ); for ( ScoreEntityIterator.ScoreEntry entry : list ) { sb.append( System.lineSeparator() ).append( "\t" ).append( db.getNodeById( entry.entityId() ) ); } throw e; } ScoreEntityIterator alice = fulltextAdapter.query( ktx, "nodes", "alice" ); assertEquals( 0, alice.stream().count() ); } }
@Test( timeout = 30_000 ) public void terminateExpiredTransaction() throws Exception { try ( Transaction transaction = database.beginTx() ) { database.createNode(); transaction.success(); } expectedException.expectMessage( "The transaction has been terminated." ); try ( Transaction transaction = database.beginTx() ) { Node nodeById = database.getNodeById( NODE_ID ); nodeById.setProperty( "a", "b" ); executor.submit( startAnotherTransaction() ).get(); } }
Node node = database.getNodeById( nodeId ); tx.acquireReadLock( node ); nodeLockAcquired.set( true ); tx.acquireWriteLock( database.getNodeById( nodeId ) ); tx.success();
@Test public void labelledNodesCoreAPI() throws Throwable { String[] entityTokens = {LABEL.name()}; SchemaDescriptor descriptor = getExistingDescriptor( entityTokens ); SchemaDescriptor newDescriptor = getNewDescriptor( entityTokens ); IndexReference initialIndex = createInitialIndex( descriptor ); Runnable aliceWork = work( nodesCreatedPerThread, () -> { db.getNodeById( createNodeIndexableByPropertyValue( LABEL, "alice" ) ); aliceLatch.countDown(); } ); Runnable bobWork = work( nodesCreatedPerThread, () -> { db.getNodeById( createNodeWithProperty( LABEL, "otherProp", "bob" ) ); bobLatch.countDown(); } ); Runnable changeConfig = work( 1, dropAndReCreateIndex( initialIndex, newDescriptor ) ); raceContestantsAndVerifyResults( newDescriptor, aliceWork, changeConfig, bobWork ); }
db.getNodeById( node.getId() ); // should throw NotFoundException tx.success();
Node node = db.getNodeById( firstID ); Node node2 = db.getNodeById( secondID ); Node node3 = db.getNodeById( thirdID );
db.getNodeById( firstID ).delete(); db.getNodeById( secondID ).delete();
@Test public void shouldThrowIllegalArgumentChangingTypeOfFieldOnNodeIndex() { String indexName = "index"; createNodeExplicitIndexWithSingleNode( db, indexName ); long nodeId; try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); nodeId = node.getId(); Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.add( node, "key", "otherValue" ); tx.success(); } try ( Transaction tx = db.beginTx() ) { Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.remove( db.getNodeById( nodeId ), "key" ); tx.success(); } expectedException.expect( IllegalArgumentException.class ); try ( Transaction tx = db.beginTx() ) { Index<Node> nodeIndex = db.index().forNodes( indexName ); nodeIndex.add( db.getNodeById( nodeId ), "key", ValueContext.numeric( 52 ) ); tx.success(); } }
Node node1b = db.getNodeById( node1.getId() );
Node start = db.getNodeById( startId ); Node end = db.getNodeById( endId ); IndexHits<Relationship> hits = autoRelationshipIndex.get( "Type", type.name(), start, end ); assertEquals( 1, count( hits ) );
nodeIndex.remove( db.getNodeById( nodeId ), "keydelete" ); tx.success();