Skip to content

Commit

Permalink
Split NotificationAcceptanceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Oct 9, 2018
1 parent 99b3e7b commit 1ba199a
Show file tree
Hide file tree
Showing 2 changed files with 277 additions and 228 deletions.
Expand Up @@ -67,15 +67,8 @@
import static org.neo4j.graphdb.impl.notification.NotificationCode.UNBOUNDED_SHORTEST_PATH; import static org.neo4j.graphdb.impl.notification.NotificationCode.UNBOUNDED_SHORTEST_PATH;
import static org.neo4j.graphdb.impl.notification.NotificationDetail.Factory.index; import static org.neo4j.graphdb.impl.notification.NotificationDetail.Factory.index;


public class NotificationAcceptanceTest public class NotificationAcceptanceTest extends NotificationTestSupport
{ {

@Rule
public final ImpermanentDatabaseRule rule = new ImpermanentDatabaseRule();

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test @Test
public void shouldNotifyWhenUsingCypher3_1ForTheRulePlannerWhenCypherVersionIsTheDefault() public void shouldNotifyWhenUsingCypher3_1ForTheRulePlannerWhenCypherVersionIsTheDefault()
{ {
Expand Down Expand Up @@ -842,224 +835,4 @@ public void shouldGiveCorrectPositionWhetherFromCacheOrNot()
assertThat( cachedNotification.getPosition(), equalTo( new InputPosition( 17, 1, 18 ) ) ); assertThat( cachedNotification.getPosition(), equalTo( new InputPosition( 17, 1, 18 ) ) );
assertThat( nonCachedNotication.getPosition(), equalTo( new InputPosition( 17, 1, 18 ) ) ); assertThat( nonCachedNotication.getPosition(), equalTo( new InputPosition( 17, 1, 18 ) ) );
} }

private void assertNotifications( String query, Matcher<Iterable<Notification>> matchesExpectation )
{
try ( Result result = db().execute( query ) )
{
assertThat( result.getNotifications(), matchesExpectation );
}
}

private Matcher<Notification> notification(
String code,
Matcher<String> description,
Matcher<InputPosition> position,
SeverityLevel severity )
{
return new TypeSafeMatcher<Notification>()
{
@Override
protected boolean matchesSafely( Notification item )
{
return code.equals( item.getCode() ) &&
description.matches( item.getDescription() ) &&
position.matches( item.getPosition() ) &&
severity.equals( item.getSeverity() );
}

@Override
public void describeTo( Description target )
{
target.appendText( "Notification{code=" ).appendValue( code )
.appendText( ", description=[" ).appendDescriptionOf( description )
.appendText( "], position=[" ).appendDescriptionOf( position )
.appendText( "], severity=" ).appendValue( severity )
.appendText( "}" );
}
};
}

private GraphDatabaseAPI db()
{
return rule.getGraphDatabaseAPI();
}

private <T> Matcher<Iterable<T>> containsItem( Matcher<T> itemMatcher )
{
return new TypeSafeMatcher<Iterable<T>>()
{
@Override
protected boolean matchesSafely( Iterable<T> items )
{
for ( T item : items )
{
if ( itemMatcher.matches( item ) )
{
return true;
}
}
return false;
}

@Override
public void describeTo( Description description )
{
description.appendText( "an iterable containing " ).appendDescriptionOf( itemMatcher );
}
};
}

private <T> Matcher<Iterable<T>> containsNoItem( Matcher<T> itemMatcher )
{
return new TypeSafeMatcher<Iterable<T>>()
{
@Override
protected boolean matchesSafely( Iterable<T> items )
{
for ( T item : items )
{
if ( itemMatcher.matches( item ) )
{
return false;
}
}
return true;
}

@Override
public void describeTo( Description description )
{
description.appendText( "an iterable not containing " ).appendDescriptionOf( itemMatcher );
}
};
}

private 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();
}

private 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();
}

private 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();
}

public static class ChangedResults
{
@Deprecated
public final String oldField = "deprecated";
public final String newField = "use this";
}

public static class TestProcedures
{

@Procedure( "newProc" )
public void newProc()
{
}

@Deprecated
@Procedure( name = "oldProc", deprecatedBy = "newProc" )
public void oldProc()
{
}

@Procedure( "changedProc" )
public Stream<ChangedResults> changedProc()
{
return Stream.of( new ChangedResults() );
}
}

private Matcher<Notification> cartesianProductWarning = notification( "Neo.ClientNotification.Statement.CartesianProductWarning", containsString(
"If a part of a query contains multiple disconnected patterns, this will build a " +
"cartesian product between all those parts. This may produce a large amount of data and slow down" + " query processing. " +
"While occasionally intended, it may often be possible to reformulate the query that avoids the " + "use of this cross " +
"product, perhaps by adding a relationship between the different parts or by using OPTIONAL MATCH" ), any( InputPosition.class ),
SeverityLevel.WARNING );

private Matcher<Notification> largeLabelCSVWarning = notification( "Neo.ClientNotification.Statement.NoApplicableIndexWarning", containsString(
"Using LOAD CSV with a large data set in a query where the execution plan contains the " +
"Using LOAD CSV followed by a MATCH or MERGE that matches a non-indexed label will most likely " +
"not perform well on large data sets. Please consider using a schema index." ), any( InputPosition.class ), SeverityLevel.WARNING );

private Matcher<Notification> deprecatedFeatureWarning =
notification( "Neo.ClientNotification.Statement.FeatureDeprecationWarning", containsString( "The query used a deprecated function." ),
any( InputPosition.class ), SeverityLevel.WARNING );

private Matcher<Notification> deprecatedStartWarning = notification( "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
containsString( "START has been deprecated and will be removed in a future version. " ), any( InputPosition.class ), SeverityLevel.WARNING );

private Matcher<Notification> deprecatedProcedureWarning =
notification( "Neo.ClientNotification.Statement.FeatureDeprecationWarning", containsString( "The query used a deprecated procedure." ),
any( InputPosition.class ), SeverityLevel.WARNING );

private Matcher<Notification> deprecatedProcedureReturnFieldWarning =
notification( "Neo.ClientNotification.Statement.FeatureDeprecationWarning", containsString( "The query used a deprecated field from a procedure." ),
any( InputPosition.class ), SeverityLevel.WARNING );

private Matcher<Notification> deprecatedBindingWarning = notification( "Neo.ClientNotification.Statement.FeatureDeprecationWarning",
containsString( "Binding relationships to a list in a variable length pattern is deprecated." ), any( InputPosition.class ),
SeverityLevel.WARNING );

private Matcher<Notification> deprecatedSeparatorWarning = notification( "Neo.ClientNotification.Statement.FeatureDeprecationWarning", containsString(
"The semantics of using colon in the separation of alternative relationship " +
"types in conjunction with the use of variable binding, inlined property " +
"predicates, or variable length will change in a future version." ), any( InputPosition.class ), SeverityLevel.WARNING );

private Matcher<Notification> eagerOperatorWarning = notification( "Neo.ClientNotification.Statement.EagerOperatorWarning", containsString(
"Using LOAD CSV with a large data set in a query where the execution plan contains the " +
"Eager operator could potentially consume a lot of memory and is likely to not perform well. " +
"See the Neo4j Manual entry on the Eager operator for more information and hints on " + "how problems could be avoided." ),
any( InputPosition.class ), SeverityLevel.WARNING );

private Matcher<Notification> unknownPropertyKeyWarning =
notification( "Neo.ClientNotification.Statement.UnknownPropertyKeyWarning", containsString( "the missing property name is" ),
any( InputPosition.class ), SeverityLevel.WARNING );

private Matcher<Notification> unknownRelationshipWarning =
notification( "Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning", containsString( "the missing relationship type is" ),
any( InputPosition.class ), SeverityLevel.WARNING );

private Matcher<Notification> unknownLabelWarning =
notification( "Neo.ClientNotification.Statement.UnknownLabelWarning", containsString( "the missing label name is" ), any( InputPosition.class ),
SeverityLevel.WARNING );

private Matcher<Notification> dynamicPropertyWarning = notification( "Neo.ClientNotification.Statement.DynamicPropertyWarning",
containsString( "Using a dynamic property makes it impossible to use an index lookup for this query" ), any( InputPosition.class ),
SeverityLevel.WARNING );

private Matcher<Notification> joinHintUnsupportedWarning = notification( "Neo.Status.Statement.JoinHintUnsupportedWarning",
containsString( "Using RULE planner is unsupported for queries with join hints, please use COST planner instead" ), any( InputPosition.class ),
SeverityLevel.WARNING );
} }

0 comments on commit 1ba199a

Please sign in to comment.