Skip to content

Commit

Permalink
Enforce node-key startup semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
craigtaverner committed Mar 21, 2017
1 parent 14d135c commit 0abbe45
Showing 1 changed file with 50 additions and 2 deletions.
Expand Up @@ -40,12 +40,60 @@ public class StartupConstraintSemanticsTest

@Test
public void shouldNotAllowOpeningADatabaseWithPECInCommunityEdition() throws Exception
{
assertThatCommunityCannotStartOnEnterpriseOnlyConstraint( "CREATE CONSTRAINT ON (n:Draconian) ASSERT exists(n.required)",
StandardConstraintSemantics.ERROR_MESSAGE_EXISTS );
}

@Test
public void shouldNotAllowOpeningADatabaseWithNodeKeyInCommunityEdition() throws Exception
{
assertThatCommunityCannotStartOnEnterpriseOnlyConstraint( "CREATE CONSTRAINT ON (n:Draconian) ASSERT (n.required) IS NODE KEY",
StandardConstraintSemantics.ERROR_MESSAGE_NODE_KEY );
}

@Test
public void shouldAllowOpeningADatabaseWithUniqueConstraintInCommunityEdition() throws Exception
{
assertThatCommunityCanStartOnNormalConstraint( "CREATE CONSTRAINT ON (n:Draconian) ASSERT (n.required) IS UNIQUE" );
}

private void assertThatCommunityCanStartOnNormalConstraint( String constraintCreationQuery )
{
// given
GraphDatabaseService graphDb = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabase( dir.graphDbDir() );
try
{
graphDb.execute( constraintCreationQuery );
}
finally
{
graphDb.shutdown();
}
graphDb = null;

// when
try
{
graphDb = new TestGraphDatabaseFactory().newEmbeddedDatabase( dir.graphDbDir() );
// Should not get exception
}
finally
{
if ( graphDb != null )
{
graphDb.shutdown();
}
}
}

private void assertThatCommunityCannotStartOnEnterpriseOnlyConstraint( String constraintCreationQuery, String errorMessage )
{
// given
GraphDatabaseService graphDb = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabase( dir.graphDbDir() );
try
{
graphDb.execute( "CREATE CONSTRAINT ON (n:Draconian) ASSERT exists(n.required)" );
graphDb.execute( constraintCreationQuery );
}
finally
{
Expand All @@ -64,7 +112,7 @@ public void shouldNotAllowOpeningADatabaseWithPECInCommunityEdition() throws Exc
{
Throwable error = Exceptions.rootCause( e );
assertThat( error, instanceOf( IllegalStateException.class ) );
assertEquals( StandardConstraintSemantics.ERROR_MESSAGE_EXISTS, error.getMessage() );
assertEquals( errorMessage, error.getMessage() );
}
finally
{
Expand Down

0 comments on commit 0abbe45

Please sign in to comment.