Skip to content

Commit

Permalink
Extracted CursorsClosedPostCondition into its own utility
Browse files Browse the repository at this point in the history
  • Loading branch information
SaschaPeukert committed Dec 14, 2017
1 parent 3aa3d4c commit c236b30
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 55 deletions.
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.neo4j.internal.kernel.api;

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

public class CursorsClosedPostCondition implements TestRule
{
private ManagedTestCursors cursors;

CursorsClosedPostCondition( ManagedTestCursors c )
{
this.cursors = c;
}

public Statement apply( Statement base, Description description )
{
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
base.evaluate();
cursors.assertAllClosedAndReset(); // only done if test succeeds
}
};
}
}
Expand Up @@ -48,27 +48,6 @@
@SuppressWarnings( "WeakerAccess" )
public abstract class KernelAPIReadTestBase<ReadSupport extends KernelAPIReadTestSupport>
{
public class ConditionalTeardown implements TestRule
{
public Statement apply( Statement base, Description description )
{
return statement( base, description );
}

private Statement statement( final Statement base, final Description description )
{
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
base.evaluate();
checkCursors(); // only done if test succeeds
}
};
}
}

protected static final TemporaryFolder folder = new TemporaryFolder();
protected static KernelAPIReadTestSupport testSupport;
private Session session;
Expand Down Expand Up @@ -112,7 +91,7 @@ public void setupGraph() throws IOException, KernelException
}

@Rule
public ConditionalTeardown conditionalTeardown = new ConditionalTeardown();
public CursorsClosedPostCondition cursorsClosedPostCondition = new CursorsClosedPostCondition( cursors );

@After
public void closeTransaction() throws Exception
Expand All @@ -122,11 +101,6 @@ public void closeTransaction() throws Exception
session.close();
}

public void checkCursors()
{
cursors.assertAllClosedAndReset();
}

@AfterClass
public static void tearDown() throws Exception
{
Expand Down
Expand Up @@ -47,35 +47,14 @@
@SuppressWarnings( "WeakerAccess" )
public abstract class KernelAPIWriteTestBase<WriteSupport extends KernelAPIWriteTestSupport>
{
public class ConditionalTeardown implements TestRule
{
public Statement apply( Statement base, Description description )
{
return statement( base, description );
}

private Statement statement( final Statement base, final Description description )
{
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
base.evaluate();
checkCursors(); // only done if test succeeds
}
};
}
}

protected static final TemporaryFolder folder = new TemporaryFolder();
protected static KernelAPIWriteTestSupport testSupport;
protected Session session;
protected ManagedTestCursors cursors;
protected static GraphDatabaseService graphDb;

@Rule
public ConditionalTeardown conditionalTeardown = new ConditionalTeardown();
public CursorsClosedPostCondition conditionalTeardown = new CursorsClosedPostCondition( cursors );

/**
* Creates a new instance of WriteSupport, which will be used to execute the concrete test
Expand Down Expand Up @@ -104,11 +83,6 @@ public void closeSession()
session.close();
}

public void checkCursors()
{
cursors.assertAllClosedAndReset();
}

@AfterClass
public static void tearDown() throws Exception
{
Expand Down
Expand Up @@ -108,7 +108,7 @@ public String toString()
else
{
return "NodeExplicitIndexCursor[node=" + node + ", expectedSize=" + expectedSize + ", score=" + score +
" ,underlying record=" + super.toString() + " ]";
", underlying record=" + super.toString() + " ]";
}
}
}

0 comments on commit c236b30

Please sign in to comment.