private Future executeInThread( final String query ) { return executorService.submit( () -> db.execute( query ).resultAsString() ); } }
private Future executeInThread( final String query ) { return executorService.submit( () -> db.execute( query ).resultAsString() ); } }
@Test public void shouldHandleListsOfPointsAsInput() { // Given Point point1 = (Point) db.execute( "RETURN point({latitude: 12.78, longitude: 56.7}) as point" ).next().get( "point" ); Point point2 = (Point) db.execute( "RETURN point({latitude: 12.18, longitude: 56.2}) as point" ).next().get( "point" ); // When double distance = (double) db.execute( "RETURN distance({points}[0], {points}[1]) as dist", map( "points", asList( point1, point2 ) ) ).next().get( "dist" ); // Then assertThat( Math.round( distance ), equalTo( 86107L ) ); }
@Test public void shouldHandleMapWithPointsAsInput() { // Given Point point1 = (Point) db.execute( "RETURN point({latitude: 12.78, longitude: 56.7}) as point" ).next().get( "point" ); Point point2 = (Point) db.execute( "RETURN point({latitude: 12.18, longitude: 56.2}) as point" ).next().get( "point" ); // When double distance = (double) db.execute( "RETURN distance({points}['p1'], {points}['p2']) as dist", map( "points", map("p1", point1, "p2", point2) ) ).next().get( "dist" ); // Then assertThat(Math.round( distance ), equalTo(86107L)); }
@Test( expected = ArithmeticException.class ) public void shouldThrowAppropriateExceptionAlsoWhenVisiting() { db.execute( "RETURN rand()/0" ).accept( row -> true ); }
@Test public void shouldThrowAppropriateException() { try { db.execute( "RETURN rand()/0" ).next(); } catch ( QueryExecutionException ex ) { assertThat( ex.getCause(), instanceOf( QueryExecutionKernelException.class ) ); assertThat( ex.getCause().getCause(), instanceOf( ArithmeticException.class ) ); } }
@Test public void shouldHandleColumnAsWithNull() { assertThat( db.execute( "RETURN toLower(null) AS lower" ).<String>columnAs( "lower" ).next(), nullValue() ); }
@Test public void shouldCloseTransactionsWhenIteratingResults() { // Given an execution result that has been started but not exhausted createNode(); createNode(); Result executionResult = db.execute( "CYPHER runtime=interpreted MATCH (n) RETURN n" ); executionResult.next(); assertThat( activeTransaction(), is( notNullValue() ) ); // When executionResult.close(); // Then assertThat( activeTransaction(), is( nullValue() ) ); }
@Test public void shouldCloseTransactionsWhenIteratingOverSingleColumn() { // Given an execution result that has been started but not exhausted createNode(); createNode(); Result executionResult = db.execute( "CYPHER runtime=interpreted MATCH (n) RETURN n" ); ResourceIterator<Node> resultIterator = executionResult.columnAs( "n" ); resultIterator.next(); assertThat( activeTransaction(), is( notNullValue() ) ); // When resultIterator.close(); // Then assertThat( activeTransaction(), is( nullValue() ) ); }