@Override public Iterable<Notification> getNotifications() { return originalResult.getNotifications(); }
@Override public Iterable<Notification> getNotifications() { return originalResult.getNotifications(); }
@Test public void version2_3ShouldWarnAboutBareNodes() { Result res = db().execute("EXPLAIN CYPHER 2.3 MATCH n RETURN n"); assert res.getNotifications().iterator().hasNext(); }
@SafeVarargs private static Result mockExecutionResult( ExecutionPlanDescription planDescription, Iterable<Notification> notifications, Map<String, Object>... rows ) { Set<String> keys = new TreeSet<>(); for ( Map<String, Object> row : rows ) { keys.addAll( row.keySet() ); } Result executionResult = mock( Result.class ); when( executionResult.columns() ).thenReturn( new ArrayList<>( keys ) ); final Iterator<Map<String, Object>> inner = asList( rows ).iterator(); when( executionResult.hasNext() ).thenAnswer( invocation -> inner.hasNext() ); when( executionResult.next() ).thenAnswer( invocation -> inner.next() ); when( executionResult.getQueryExecutionType() ) .thenReturn( null != planDescription ? QueryExecutionType.profiled( QueryExecutionType.QueryType.READ_WRITE ) : QueryExecutionType.query( QueryExecutionType.QueryType.READ_WRITE ) ); if ( executionResult.getQueryExecutionType().requestedExecutionPlanDescription() ) { when( executionResult.getExecutionPlanDescription() ).thenReturn( planDescription ); } mockAccept( executionResult ); when( executionResult.getNotifications() ).thenReturn( notifications ); return executionResult; }
protected void assertNotifications( String query, Matcher<Iterable<Notification>> matchesExpectation ) { try ( Result result = db().execute( query ) ) { assertThat( result.getNotifications(), matchesExpectation ); } }
void shouldNotNotifyInStream( String version, String query ) { // when Result result = db().execute( version + query ); // then assertThat( Iterables.asList( result.getNotifications() ), empty() ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( version ) ); result.close(); }
@Test public void shouldNotifyWhenUsingCypher3_1ForTheRulePlannerWhenCypherVersionIsTheDefault() { // when Result result = db().execute( "CYPHER planner=rule RETURN 1" ); InputPosition position = InputPosition.empty; // then assertThat( result.getNotifications(), containsItem( rulePlannerUnavailable ) ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( "CYPHER 3.1" ) ); assertThat( arguments.get( "planner" ), equalTo( "RULE" ) ); result.close(); }
@Test public void eagerResultHaveNotifications() { Result result = database.execute( " CYPHER planner=rule MATCH (n) RETURN n.c" ); assertEquals( 1, testCursorContext.getAdditionalAttempts() ); assertThat( Iterables.count( result.getNotifications() ), greaterThan( 0L ) ); }
void shouldNotifyInStream( String version, String query, InputPosition pos, NotificationCode code ) { //when Result result = db().execute( version + query ); //then NotificationCode.Notification notification = code.notification( pos ); assertThat( Iterables.asList( result.getNotifications() ), Matchers.hasItems( notification ) ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( version ) ); result.close(); }
void shouldNotifyInStreamWithDetail( String version, String query, InputPosition pos, NotificationCode code, NotificationDetail detail ) { //when Result result = db().execute( version + query ); //then NotificationCode.Notification notification = code.notification( pos, detail ); assertThat( Iterables.asList( result.getNotifications() ), Matchers.hasItems( notification ) ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( version ) ); result.close(); }
@Test public void deprecatedRulePlanner() { // when Result result = db().execute( "EXPLAIN CYPHER planner=rule RETURN 1" ); // then assertThat( result.getNotifications(), containsItem( deprecatedRulePlanner ) ); result.close(); }
@Test public void deprecatedCompiledRuntime() { // when Result result = db().execute( "EXPLAIN CYPHER runtime=compiled RETURN 1" ); // then assertThat( result.getNotifications(), containsItem( deprecatedCompiledRuntime ) ); result.close(); }
@Test public void shouldNotifyWhenUsingCreateUniqueWhenCypherVersionIsDefault() { // when Result result = db().execute( "MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()" ); // then assertThat( result.getNotifications(), containsItem( deprecatedCreateUnique ) ); result.close(); }
Result result = safelyExecute( statement, hasPeriodicCommit, tc ); output.statementResult( result, statement.includeStats(), statement.resultDataContents() ); output.notifications( result.getNotifications() );
@Test public void shouldNotifyWhenUsingCreateUniqueWhenCypherVersionIs3_5() { // when Result result = db().execute( "EXPLAIN CYPHER 3.5 MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()" ); InputPosition position = new InputPosition( 44, 1, 45 ); // then assertThat( result.getNotifications(), containsNotification( CREATE_UNIQUE_UNAVAILABLE_FALLBACK.notification( position ) ) ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( "CYPHER 3.1" ) ); result.close(); }
@Test public void shouldNotifyWhenUsingCreateUniqueWhenCypherVersionIsDefault() { // when Result result = db().execute( "EXPLAIN MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()" ); InputPosition position = new InputPosition( 33, 1, 34 ); // then assertThat( result.getNotifications(), containsNotification( CREATE_UNIQUE_UNAVAILABLE_FALLBACK.notification( position ) ) ); Map<String,Object> arguments = result.getExecutionPlanDescription().getArguments(); assertThat( arguments.get( "version" ), equalTo( "CYPHER 3.1" ) ); result.close(); }
@Test public void shouldGiveCorrectPositionWhetherFromCacheOrNot() { // Given String cachedQuery = "MATCH (a:L1) RETURN a"; String nonCachedQuery = "MATCH (a:L2) RETURN a"; //make sure we cache the query GraphDatabaseAPI db = db(); int limit = db.getDependencyResolver().resolveDependency( Config.class ) .get( GraphDatabaseSettings.cypher_expression_recompilation_limit ); for ( int i = 0; i < limit + 1; i++ ) { db.execute( cachedQuery ).resultAsString(); } // When Notification cachedNotification = Iterables.asList( db.execute( "EXPLAIN " + cachedQuery ).getNotifications() ).get( 0 ); Notification nonCachedNotication = Iterables.asList( db.execute( "EXPLAIN " + nonCachedQuery ).getNotifications() ).get( 0 ); // Then assertThat( cachedNotification.getPosition(), equalTo( new InputPosition( 17, 1, 18 ) ) ); assertThat( nonCachedNotication.getPosition(), equalTo( new InputPosition( 17, 1, 18 ) ) ); } }
@Test public void shouldNotifyWhenUsingCreateUniqueWhenCypherVersionIs3_5() { // when Result result = db().execute( "CYPHER 3.5 MATCH (b) WITH b LIMIT 1 CREATE UNIQUE (b)-[:REL]->()" ); InputPosition position = new InputPosition( 36, 1, 37 ); // then assertThat( result.getNotifications(), containsItem( deprecatedCreateUnique ) ); result.close(); }
@Override public Iterable<Notification> getNotifications() { return originalResult.getNotifications(); }
@Override public Iterable<Notification> getNotifications() { return originalResult.getNotifications(); }