Skip to content

Commit

Permalink
DatabaseRule keeps resources from failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Mar 2, 2015
1 parent 4444022 commit 5039269
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
16 changes: 11 additions & 5 deletions community/kernel/src/test/java/org/neo4j/test/DatabaseRule.java
Expand Up @@ -19,8 +19,6 @@
*/
package org.neo4j.test;

import org.junit.rules.ExternalResource;

import java.io.File;
import java.io.IOException;
import java.util.Map;
Expand Down Expand Up @@ -133,9 +131,9 @@ protected void before() throws Throwable
}

@Override
protected void after()
protected void after( boolean success )
{
shutdown();
shutdown( success );
}

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -245,6 +243,11 @@ public GraphDatabaseAPI restartDatabase( RestartAction action ) throws IOExcepti
}

public void shutdown()
{
shutdown( true );
}

private void shutdown( boolean deleteResources )
{
statementProvider = null;
try
Expand All @@ -256,7 +259,10 @@ public void shutdown()
}
finally
{
deleteResources();
if ( deleteResources )
{
deleteResources();
}
database = null;
}
}
Expand Down
Expand Up @@ -50,7 +50,7 @@ public void evaluate() throws Throwable
{
try
{
after();
after( failure == null );
}
catch ( Throwable e )
{
Expand Down Expand Up @@ -85,7 +85,7 @@ protected void before() throws Throwable
/**
* Override to tear down your specific external resource.
*/
protected void after() throws Throwable
protected void after( boolean successful ) throws Throwable
{
// do nothing
}
Expand Down
Expand Up @@ -29,11 +29,11 @@
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.tracing.PageCacheTracer;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.io.pagecache.PageSwapperFactory;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory;
import org.neo4j.io.pagecache.tracing.PageCacheTracer;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.pagecache.LifecycledPageCache;
import org.neo4j.kernel.impl.util.Neo4jJobScheduler;
Expand All @@ -42,7 +42,7 @@ public class PageCacheRule extends ExternalResource
{
private Neo4jJobScheduler jobScheduler;
private LifecycledPageCache pageCache;
private boolean automaticallyProduceInconsistentReads;
private final boolean automaticallyProduceInconsistentReads;

public PageCacheRule()
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public PageCache getPageCache( FileSystemAbstraction fs, Config config )
}

@Override
protected void after()
protected void after( boolean success )
{
if ( pageCache != null )
{
Expand Down
Expand Up @@ -19,12 +19,12 @@
*/
package org.neo4j.test;

import java.io.File;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.io.File;

import org.neo4j.helpers.Provider;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
Expand Down Expand Up @@ -86,7 +86,7 @@ protected PageCache createResource( Description description )
@Override
protected void destroyResource( PageCache done, Throwable failure )
{
pageCache.after();
pageCache.after( failure == null );
}
};
}
Expand Down
Expand Up @@ -20,8 +20,6 @@
package org.neo4j.kernel.impl.query;

import java.io.File;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.neo4j.function.Factory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
Expand Down

0 comments on commit 5039269

Please sign in to comment.