private Node createLabeledNode( Label... labels ) { try ( Transaction tx = dbRule.beginTx() ) { Node node = dbRule.createNode( labels ); tx.success(); return node; } }
@Test( timeout = 10000 ) public void logRotationMustNotObstructStartingWriteTransaction() { try ( Transaction tx = db.beginTx() ) { db.createNode(); tx.success(); completeLogRotationLatch.countDown(); } } }
@Test public void shouldThrowHumaneExceptionsWhenPropertyDoesNotExist() { // Given a database without PROPERTY_KEY in it // When try ( Transaction ignored = db.beginTx() ) { Node node = db.createNode(); node.getProperty( PROPERTY_KEY ); } // Then catch ( NotFoundException exception ) { assertThat( exception.getMessage(), containsString( PROPERTY_KEY ) ); } }
@Test( expected = NotFoundException.class ) public void deletionOfAlreadyDeletedNodeShouldThrow() { // Given Node node; try ( Transaction tx = db.beginTx() ) { node = db.createNode(); tx.success(); } try ( Transaction tx = db.beginTx() ) { node.delete(); tx.success(); } // When try ( Transaction tx = db.beginTx() ) { node.delete(); // should throw NotFoundException as this node is already deleted tx.success(); } }
@Test public void shouldThrowHumaneExceptionsWhenPropertyDoesNotExistOnNode() { // Given a database with PROPERTY_KEY in it createNodeWith( PROPERTY_KEY ); // When trying to get property from node without it try ( Transaction ignored = db.beginTx() ) { Node node = db.createNode(); node.getProperty( PROPERTY_KEY ); fail( "Expected exception to have been thrown" ); } // Then catch ( NotFoundException exception ) { assertThat( exception.getMessage(), containsString( PROPERTY_KEY ) ); } }
private Node createTree( int depth, int width ) { try ( Transaction tx = dbRule.beginTx() ) { Node root = dbRule.createNode( TestLabels.LABEL_ONE ); createTree( root, depth, width, 0 ); tx.success(); return root; } }
@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(); } }
@Test public void shouldExecuteCypher() { // given final long before; final long after; try ( Transaction tx = graphDb.beginTx() ) { before = Iterables.count( graphDb.getAllNodes() ); tx.success(); } // when graphDb.execute( "CREATE (n:Foo{bar:\"baz\"})" ); // then try ( Transaction tx = graphDb.beginTx() ) { after = Iterables.count( graphDb.getAllNodes() ); tx.success(); } assertEquals( before + 1, after ); }
@Test public void lookupWithinTransaction() { try ( Transaction tx = db.beginTx() ) { // when db.createNode( label( "Node" ) ).setProperty( "prop", store ); // then assertEquals( 1, count( db.findNodes( label( "Node" ), "prop", lookup ) ) ); // no need to actually commit this node } }
private void createNodeWith( String key ) { try ( Transaction tx = db.beginTx() ) { Node node = db.createNode(); node.setProperty( key, 1 ); tx.success(); } } }
@Test public void shouldBeAbleToForceTypeChangeOfProperty() { // Given Node node; try ( Transaction tx = db.beginTx() ) { node = db.createNode(); node.setProperty( "prop", 1337 ); tx.success(); } // When try ( Transaction tx = db.beginTx() ) { node.setProperty( "prop", 1337.0 ); tx.success(); } // Then try ( Transaction ignore = db.beginTx() ) { assertThat( node.getProperty( "prop" ), instanceOf( Double.class ) ); } }
@Test public void concurrentCreatingAndAwaitingIndexesOnline() throws Exception { ExecutorService executor = cleanupRule.add( Executors.newSingleThreadExecutor() ); Future<?> indexCreate = executor.submit( () -> { try ( Transaction tx = db.beginTx() ) { db.schema().indexFor( label( 0 ) ).on( KEY ).create(); tx.success(); } } ); while ( !indexCreate.isDone() ) { try ( Transaction tx = db.beginTx() ) { db.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); tx.success(); } } indexCreate.get(); }
@Test public void lookupWithinTransactionWithCacheEviction() { try ( Transaction tx = db.beginTx() ) { // when db.createNode( label( "Node" ) ).setProperty( "prop", store ); // then assertEquals( 1, count( db.findNodes( label( "Node" ), "prop", lookup ) ) ); // no need to actually commit this node } }
private void createNamed( Label label, String name ) { try ( Transaction tx = db.beginTx() ) { db.createNode( label ).setProperty( "name", name ); tx.success(); } } }