private void createSimpleNodesIndex() { db.execute( format( NODE_CREATE, "nodes", array( LABEL.name() ), array( PROP ) ) ).close(); } }
private void createSimpleRelationshipIndex() { db.execute( format( RELATIONSHIP_CREATE, "rels", array( REL.name() ), array( PROP ) ) ).close(); }
@Test public void mustNotBeAbleToCreateTwoIndexesWithSameName() { db = createDatabase(); db.execute( format( NODE_CREATE, "node", array( "Label1", "Label2" ), array( "prop1", "prop2" ) ) ).close(); expectedException.expectMessage( "already exists" ); db.execute( format( NODE_CREATE, "node", array( "Label1", "Label2" ), array( "prop3", "prop4" ) ) ).close(); }
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(); }
private long nodesInDatabase() { Result r = graphdb().execute( "MATCH (n) RETURN count(n) AS c" ); Long nodes = (Long) r.columnAs( "c" ).next(); r.close(); return nodes; }
@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 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 nodeIndexesMustHaveLabels() { db = createDatabase(); expectedException.expect( QueryExecutionException.class ); db.execute( format( NODE_CREATE, "nodeIndex", array(), array( PROP ) ) ).close(); }
@Test public void nodeIndexesMustHaveProperties() { db = createDatabase(); expectedException.expect( QueryExecutionException.class ); db.execute( format( NODE_CREATE, "nodeIndex", array( "Label" ), array() ) ).close(); }
@Test public void queryingIndexInTransactionItWasCreatedInMustThrow() { db = createDatabase(); try ( Transaction ignore = db.beginTx() ) { createSimpleNodesIndex(); expectedException.expect( QueryExecutionException.class ); db.execute( format( QUERY_NODES, "nodes", "value" ) ).close(); } }
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(); }
@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 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 queryingDroppedIndexForRelationshipsInDroppingTransactionMustThrow() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleRelationshipIndex(); tx.success(); } awaitIndexesOnline(); try ( Transaction tx = db.beginTx() ) { db.execute( format( DROP, "rels" ) ).close(); expectedException.expect( QueryExecutionException.class ); db.execute( format( QUERY_RELS, "rels", "blabla" ) ); } }
@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(); }
@Test public void queryNodesMustThrowWhenQueryingRelationshipIndex() { db = createDatabase(); try ( Transaction tx = db.beginTx() ) { createSimpleRelationshipIndex(); tx.success(); } awaitIndexesOnline(); try ( Transaction tx = db.beginTx() ) { expectedException.expect( Exception.class ); db.execute( format( QUERY_NODES, "rels", "bla bla" ) ).close(); tx.success(); } }