Skip to content

Commit

Permalink
KernelIntegrationTest retain db on restart
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Jun 29, 2017
1 parent 8d9ebe7 commit 397e1a3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
Expand Up @@ -21,9 +21,11 @@

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.RuleChain;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.kernel.api.DataWriteOperations;
import org.neo4j.kernel.api.KernelAPI;
import org.neo4j.kernel.api.KernelTransaction;
Expand All @@ -40,13 +42,19 @@
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.test.TestGraphDatabaseBuilder;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;

import static org.neo4j.kernel.api.security.SecurityContext.AUTH_DISABLED;

public abstract class KernelIntegrationTest
{
protected final TestDirectory testDir = TestDirectory.testDirectory();
protected final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();

@Rule
public RuleChain ruleChain = RuleChain.outerRule( testDir ).around( fileSystemRule );
@SuppressWarnings( "deprecation" )
protected GraphDatabaseAPI db;
ThreadToStatementContextBridge statementContextSupplier;
Expand All @@ -55,7 +63,6 @@ public abstract class KernelIntegrationTest

private KernelTransaction transaction;
private Statement statement;
private EphemeralFileSystemAbstraction fs;
private DbmsOperations dbmsOperations;

protected Statement statementInNewTransaction( SecurityContext securityContext ) throws KernelException
Expand Down Expand Up @@ -138,35 +145,32 @@ protected void rollback() throws TransactionFailureException
@Before
public void setup()
{
fs = new EphemeralFileSystemAbstraction();
startDb();
}

@After
public void cleanup() throws Exception
{
stopDb();
fs.close();
}

protected void startDb()
{
db = (GraphDatabaseAPI) createGraphDatabase( fs );
db = (GraphDatabaseAPI) createGraphDatabase();
kernel = db.getDependencyResolver().resolveDependency( KernelAPI.class );
indexingService = db.getDependencyResolver().resolveDependency( IndexingService.class );
statementContextSupplier = db.getDependencyResolver().resolveDependency( ThreadToStatementContextBridge.class );
dbmsOperations = db.getDependencyResolver().resolveDependency( DbmsOperations.class );
}

protected GraphDatabaseService createGraphDatabase( EphemeralFileSystemAbstraction fs )
protected GraphDatabaseService createGraphDatabase()
{
TestGraphDatabaseBuilder graphDatabaseBuilder = (TestGraphDatabaseBuilder) new TestGraphDatabaseFactory()
.setFileSystem( fs )
.newImpermanentDatabaseBuilder();
GraphDatabaseBuilder graphDatabaseBuilder = new TestGraphDatabaseFactory().setFileSystem( fileSystemRule.get() )
.newEmbeddedDatabaseBuilder( testDir.graphDbDir() );
return configure( graphDatabaseBuilder ).newGraphDatabase();
}

protected TestGraphDatabaseBuilder configure( TestGraphDatabaseBuilder graphDatabaseBuilder )
protected GraphDatabaseBuilder configure( GraphDatabaseBuilder graphDatabaseBuilder )
{
return graphDatabaseBuilder;
}
Expand Down
Expand Up @@ -103,12 +103,10 @@ public void createKeys() throws Exception
}

@Override
protected GraphDatabaseService createGraphDatabase( EphemeralFileSystemAbstraction fs )
protected GraphDatabaseService createGraphDatabase()
{
return new TestEnterpriseGraphDatabaseFactory()
.setFileSystem( fs )
.newImpermanentDatabaseBuilder()
.newGraphDatabase();
return new TestEnterpriseGraphDatabaseFactory().setFileSystem( fileSystemRule.get() )
.newEmbeddedDatabase( testDir.graphDbDir() );
}

@Test
Expand All @@ -134,6 +132,30 @@ public void shouldBeAbleToStoreAndRetrieveConstraint() throws Exception
assertEquals( constraint, single( constraints ) );
}

@Test
public void shouldBeAbleToStoreAndRetrieveConstraintAfterRestart() throws Exception
{
// given
Statement statement = statementInNewTransaction( SecurityContext.AUTH_DISABLED );

// when
ConstraintDescriptor constraint = createConstraint( statement.schemaWriteOperations(), descriptor );

// then
assertEquals( constraint, single( statement.readOperations().constraintsGetAll() ) );

// given
commit();
restartDb();
ReadOperations readOperations = readOperationsInNewTransaction();

// when
Iterator<?> constraints = readOperations.constraintsGetAll();

// then
assertEquals( constraint, single( constraints ) );
}

@Test
public void shouldNotPersistConstraintCreatedInAbortedTransaction() throws Exception
{
Expand Down
Expand Up @@ -33,7 +33,6 @@
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.kernel.api.DataWriteOperations;
import org.neo4j.kernel.api.ReadOperations;
import org.neo4j.kernel.api.SchemaWriteOperations;
Expand All @@ -56,8 +55,10 @@
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forRelType;
import static org.neo4j.kernel.impl.api.integrationtest.PropertyConstraintValidationIT.NodeKeyConstraintValidationIT;
import static org.neo4j.kernel.impl.api.integrationtest.PropertyConstraintValidationIT.NodePropertyExistenceConstraintValidationIT;
import static org.neo4j.kernel.impl.api.integrationtest.PropertyConstraintValidationIT.RelationshipPropertyExistenceConstraintValidationIT;
import static org.neo4j.kernel.impl.api.integrationtest.PropertyConstraintValidationIT
.NodePropertyExistenceConstraintValidationIT;
import static org.neo4j.kernel.impl.api.integrationtest.PropertyConstraintValidationIT
.RelationshipPropertyExistenceConstraintValidationIT;

@RunWith( Suite.class )
@SuiteClasses( {
Expand Down Expand Up @@ -321,11 +322,10 @@ abstract void setProperty( DataWriteOperations writeOps, long entityId, int prop
abstract int entityCount() throws TransactionFailureException;

@Override
protected GraphDatabaseService createGraphDatabase( EphemeralFileSystemAbstraction fs )
protected GraphDatabaseService createGraphDatabase()
{
return new TestEnterpriseGraphDatabaseFactory()
.setFileSystem( fs )
.newImpermanentDatabaseBuilder()
return new TestEnterpriseGraphDatabaseFactory().setFileSystem( fileSystemRule.get() )
.newEmbeddedDatabaseBuilder( testDir.graphDbDir() )
.newGraphDatabase();
}

Expand Down

0 comments on commit 397e1a3

Please sign in to comment.