private Runnable createNodeWithLabel( Label label ) { return () -> { try ( Transaction transaction = database.beginTx() ) { database.createNode( label ); transaction.success(); } }; }
private void createSomeData( Label label, String propertyKey ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( label ); node.setProperty( propertyKey, "yeah" ); tx.success(); } } }
void setProperty( String nodeName, String propertyName, Object propertyValue ) { Node i = this.getNode( nodeName ); GraphDatabaseService db = i.getGraphDatabase(); try ( Transaction tx = db.beginTx() ) { i.setProperty( propertyName, propertyValue ); tx.success(); } }
@Test public void getNonExistentGraphPropertyWithDefaultValue() { GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); PropertyContainer graphProperties = properties( db ); Transaction tx = db.beginTx(); assertEquals( "default", graphProperties.getProperty( "test", "default" ) ); tx.success(); tx.close(); db.shutdown(); }
@Test public void lookupWithoutTransaction() { // when Node node; try ( Transaction tx = db.beginTx() ) { (node = db.createNode( label( "Node" ) )).setProperty( "prop", store ); tx.success(); } // then try ( Transaction tx = db.beginTx() ) { assertEquals( 1, count( db.findNodes( label( "Node" ), "prop", lookup ) ) ); tx.success(); } deleteNode( node ); }
private void makeSureFirstAndLastAreReturnedCorrectly( EntityCreator<PropertyContainer> creator, TimelineIndex<PropertyContainer> timeline ) { LinkedList<Pair<PropertyContainer, Long>> timestamps = createTimestamps( creator, timeline, 223456, 12345, 432234 ); try ( Transaction tx = db.beginTx() ) { assertEquals( timestamps.get( 1 ).first(), timeline.getFirst() ); assertEquals( timestamps.getLast().first(), timeline.getLast() ); tx.success(); } }
@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(); } }
private void assertOrder( Iterator<Node> itr, String... names ) { try ( Transaction tx = beginTx() ) { for ( String name : names ) { Node node = itr.next(); assertEquals( "expected " + name + ", was " + node.getProperty( "name" ), getNodeWithName( name ), node ); } assertFalse( itr.hasNext() ); tx.success(); } } }
@Before public void createTokens() { try ( Transaction tx = db.beginTx() ) { for ( int i = 0; i < threads; i++ ) { db.createNode( label( i ) ).setProperty( KEY, i ); } tx.success(); } }
private static Node createNodeWithProperty( GraphDatabaseService db, String key, Object value ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.setProperty( key, value ); tx.success(); return node; } }
@Test public void shouldBeAbleToRemoveNodeProperty() throws Exception { Map<String, Object> properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "number", 15 ); long nodeId = createNode( properties ); actions.removeNodeProperty( nodeId, "foo" ); try ( Transaction tx = database.getGraph().beginTx() ) { Node node = database.getGraph().getNodeById( nodeId ); assertEquals( 15, node.getProperty( "number" ) ); assertFalse( node.hasProperty( "foo" ) ); tx.success(); } }
@Test public void lookupWithoutTransactionWithCacheEviction() { // when Node node; try ( Transaction tx = db.beginTx() ) { (node = db.createNode( label( "Node" ) )).setProperty( "prop", store ); tx.success(); } // then try ( Transaction tx = db.beginTx() ) { assertEquals( 1, count( db.findNodes( label( "Node" ), "prop", lookup ) ) ); tx.success(); } deleteNode( node ); } }
private void makeSureWeCanQueryLowerDefaultThan1970( EntityCreator<PropertyContainer> creator, TimelineIndex<PropertyContainer> timeline ) { LinkedList<Pair<PropertyContainer,Long>> timestamps = createTimestamps( creator, timeline, -10000, 0, 10000 ); try ( Transaction tx = db.beginTx() ) { assertEquals( sortedEntities( timestamps, true ), asCollection( timeline.getBetween( null, 10000L, true ).iterator() ) ); tx.success(); } }
@Test public void testPropertyStoreReferencesOnWrite() throws Throwable { // Given GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI(); // and Given the cache contains a LazyProperty long nId = ensurePropertyIsCachedLazyProperty( db, "some" ); // When restartNeoDataSource( db ); // Then it should still be possible to manipulate properties on this node try ( Transaction tx = db.beginTx() ) { db.getNodeById( nId ).setProperty( "some", new long[]{-1, 2, 2, 3, 4, 5, 5} ); tx.success(); } }
private void assertReadNode( String propValue, long expectedNodeId ) { try ( Transaction tx = db.beginTx() ) { Node node = db.findNode( LABEL_ONE, propKey, propValue ); assertNotNull( node ); assertEquals( "node id", expectedNodeId, node.getId() ); tx.success(); } } }
private void createNode() { try ( Transaction tx = db.beginTx() ) { db.createNode(); tx.success(); } } }
private Node createNode( GraphDatabaseService db, String key, Object value, Label label ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode( label ); node.setProperty( key, value ); tx.success(); return node; } } }
@Test public void shouldCreatePropertyUniquenessConstraint() { // GIVEN String labelName = "person"; String propertyKey = "name"; // WHEN actions.createPropertyUniquenessConstraint( labelName, asList( propertyKey ) ); // THEN try ( Transaction tx = graph.beginTx() ) { Iterable<ConstraintDefinition> defs = graphdbHelper.getPropertyUniquenessConstraints( labelName, propertyKey ); assertEquals( asSet( propertyKey ), Iterables.asSet( single( defs ).getPropertyKeys() ) ); tx.success(); } }