Skip to content

Commit

Permalink
Simplify definition and usage of TestDirectory test rule.
Browse files Browse the repository at this point in the history
Remove outer TargetDirectory class, let users avoid specifying class under test.

With this PR typical definition of TestDirectory look like:
@rule
public TestDirectory dir = TestDirectory.testDirectory();
  • Loading branch information
MishaDemianenko committed Aug 15, 2016
1 parent 63f4167 commit 30a30a4
Show file tree
Hide file tree
Showing 370 changed files with 1,044 additions and 1,173 deletions.
Expand Up @@ -31,7 +31,7 @@
import org.neo4j.kernel.impl.util.Validators;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.EmbeddedDatabaseRule;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.core.IsNot.not;
Expand All @@ -41,7 +41,7 @@

public class ImportCommandTest
{
private TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( getClass() );
private TestDirectory testDir = TestDirectory.testDirectory();

@Rule
public final DatabaseRule db = new EmbeddedDatabaseRule();
Expand Down
Expand Up @@ -48,7 +48,7 @@
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -75,7 +75,7 @@ protected void generateInitialData( GraphDatabaseService graphDb )
}
};

private final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() );
private final TestDirectory testDirectory = TestDirectory.testDirectory();

@Rule
public final RuleChain chain = RuleChain.outerRule( testDirectory ).around( fixture );
Expand Down
Expand Up @@ -38,9 +38,8 @@
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.logging.LogProvider;

import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;

import static org.hamcrest.CoreMatchers.containsString;
Expand All @@ -60,7 +59,7 @@

public class ConsistencyCheckToolTest
{
private TargetDirectory.TestDirectory storeDirectory = TargetDirectory.testDirForTest( getClass() );
private TestDirectory storeDirectory = TestDirectory.testDirectory();
private EphemeralFileSystemRule fs = new EphemeralFileSystemRule();

@Rule
Expand Down
Expand Up @@ -79,7 +79,7 @@
import org.neo4j.storageengine.api.schema.SchemaRule;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.PageCacheRule;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static java.lang.System.currentTimeMillis;
import static org.neo4j.consistency.ConsistencyCheckService.defaultConsistencyCheckThreadsNumber;
Expand Down Expand Up @@ -491,7 +491,7 @@ private void generateInitialData()
@Override
public Statement apply( final Statement base, Description description )
{
final TargetDirectory.TestDirectory directory = TargetDirectory.testDirForTest( description.getTestClass() );
final TestDirectory directory = TestDirectory.testDirectory( description.getTestClass() );
return super.apply( directory.apply( new Statement()
{
@Override
Expand Down
Expand Up @@ -53,15 +53,15 @@
import org.neo4j.logging.AssertableLogProvider;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.test.rule.RandomRule;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertTrue;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.helpers.collection.MapUtil.stringMap;

public class DetectAllRelationshipInconsistenciesIT
{
private final TargetDirectory.TestDirectory directory = TargetDirectory.testDirForTest( getClass() );
private final TestDirectory directory = TestDirectory.testDirectory();
private final RandomRule random = new RandomRule();
private final DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();

Expand Down
Expand Up @@ -41,7 +41,7 @@
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.PageCacheRule;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertEquals;
import static org.neo4j.kernel.impl.store.record.RecordLoad.NORMAL;
Expand All @@ -53,7 +53,7 @@ public class RelationshipChainExplorerTest
@ClassRule
public static PageCacheRule pageCacheRule = new PageCacheRule();
@Rule
public TargetDirectory.TestDirectory storeLocation = TargetDirectory.testDirForTest( getClass() );
public TestDirectory storeLocation = TestDirectory.testDirectory();
private StoreAccess store;

@Before
Expand Down
Expand Up @@ -62,7 +62,7 @@
import org.neo4j.test.Randoms;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.RandomRule;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdGenerator;
import org.neo4j.unsafe.impl.batchimport.cache.idmapping.IdMapper;
import org.neo4j.unsafe.impl.batchimport.input.Group;
Expand All @@ -77,7 +77,6 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import static org.neo4j.helpers.collection.Iterables.count;
import static org.neo4j.helpers.collection.Iterators.asSet;
import static org.neo4j.helpers.collection.MapUtil.stringMap;
Expand All @@ -94,7 +93,7 @@
public class ParallelBatchImporterTest
{
@Rule
public final TargetDirectory.TestDirectory directory = TargetDirectory.testDirForTest( getClass() );
public final TestDirectory directory = TestDirectory.testDirectory();

@Rule
public final RandomRule random = new RandomRule();
Expand Down
Expand Up @@ -32,7 +32,7 @@
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static java.lang.System.currentTimeMillis;
import static org.neo4j.graphalgo.CommonEvaluators.doubleCostEvaluator;
Expand All @@ -45,7 +45,7 @@ public class AStarPerformanceIT
private File directory;

@Rule
public TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() );
public TestDirectory testDirectory = TestDirectory.testDirectory();

@Before
public void setup()
Expand Down
Expand Up @@ -40,7 +40,7 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.io.fs.FileUtils;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static java.lang.System.currentTimeMillis;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void shortestPathShouldFinishWithinToleratedDuration() throws IOException
}

@Rule
public TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( getClass() );
public TestDirectory testDir = TestDirectory.testDirectory();

void assertPathFinderCompletesWithinToleratedDuration( long toleratedRuntime, PathFinder<? extends Path> pathFinder )
throws IOException
Expand Down
Expand Up @@ -45,7 +45,7 @@
import org.neo4j.graphmatching.PatternNode;
import org.neo4j.helpers.collection.IteratorWrapper;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -291,6 +291,5 @@ public static void stopGraphdb()
}

@ClassRule
public static TargetDirectory.TestDirectory testDirectory =
TargetDirectory.testDirForTest( TestMatchingOfCircularPattern.class );
public static TestDirectory testDirectory = TestDirectory.testDirectory();
}
Expand Up @@ -52,7 +52,7 @@
import org.neo4j.test.ProcessStreamHandler;
import org.neo4j.test.TestData;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
Expand All @@ -68,8 +68,7 @@ public GraphDatabaseService graphdb()
}

@ClassRule
public static TargetDirectory.TestDirectory testDirectory =
TargetDirectory.testDirForTest( TestPatternMatching.class );
public static TestDirectory testDirectory = TestDirectory.testDirectory();

@Rule
public TestData<Map<String,Node>> data = TestData.producedThrough( GraphDescription.createGraphFor( this, true ) );
Expand Down
Expand Up @@ -35,7 +35,7 @@

import org.neo4j.function.Factory;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
Expand All @@ -45,23 +45,8 @@
@RunWith( Parameterized.class )
public class FileSystemAbstractionInterruptionTest
{
private static final Factory<FileSystemAbstraction> ephemeral = new Factory<FileSystemAbstraction>()
{
@Override
public FileSystemAbstraction newInstance()
{
return new EphemeralFileSystemAbstraction();
}
};

private static final Factory<FileSystemAbstraction> real = new Factory<FileSystemAbstraction>()
{
@Override
public FileSystemAbstraction newInstance()
{
return new DefaultFileSystemAbstraction();
}
};
private static final Factory<FileSystemAbstraction> ephemeral = EphemeralFileSystemAbstraction::new;
private static final Factory<FileSystemAbstraction> real = DefaultFileSystemAbstraction::new;

@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> dataPoints()
Expand All @@ -73,8 +58,7 @@ public static Iterable<Object[]> dataPoints()
}

@Rule
public final TargetDirectory.TestDirectory testdir =
TargetDirectory.testDirForTest( FileSystemAbstractionInterruptionTest.class );
public final TestDirectory testdir = TestDirectory.testDirectory();

private FileSystemAbstraction fs;
private File file;
Expand Down
Expand Up @@ -43,7 +43,7 @@
import java.util.concurrent.atomic.AtomicReference;

import org.neo4j.io.pagecache.impl.ByteBufferPage;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isOneOf;
Expand Down Expand Up @@ -110,15 +110,16 @@ private File file( String filename ) throws IOException
}

@Rule
public final TargetDirectory.TestDirectory testDir = TargetDirectory.testDirForTest( getClass() );
public final TestDirectory testDir = TestDirectory.testDirectory();

private final ConcurrentLinkedQueue<PageSwapper> openedSwappers = new ConcurrentLinkedQueue<>();

@Before
@After
public void clearStrayInterrupts()
public void clearStrayInterrupts() throws IOException
{
Thread.interrupted();
testDir.cleanup();
}

@After
Expand Down
Expand Up @@ -23,12 +23,12 @@

import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.pagecache.impl.muninn.MuninnPageCache;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

public class MuninnPageCacheHarnessWithRealFileSystemIT extends MuninnPageCacheHarnessTest
{
@Rule
public TargetDirectory.TestDirectory directory = TargetDirectory.testDirForTest( getClass() );
public TestDirectory directory = TestDirectory.testDirectory();

@Override
protected Fixture<MuninnPageCache> createFixture()
Expand Down
Expand Up @@ -19,15 +19,24 @@
*/
package org.neo4j.io.pagecache.impl.muninn;

import org.junit.After;
import org.junit.Rule;

import java.io.IOException;

import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

public class MuninnPageCacheSlowTestWithRealFileSystemIT extends MuninnPageCacheSlowIT
{
@Rule
public TargetDirectory.TestDirectory directory = TargetDirectory.testDirForTest( getClass() );
public TestDirectory directory = TestDirectory.testDirectory();

@After
public void tearDown() throws IOException
{
directory.cleanup();
}

@Override
protected Fixture<MuninnPageCache> createFixture()
Expand Down
Expand Up @@ -19,15 +19,24 @@
*/
package org.neo4j.io.pagecache.impl.muninn;

import org.junit.After;
import org.junit.Rule;

import java.io.IOException;

import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.test.rule.TargetDirectory;
import org.neo4j.test.rule.TestDirectory;

public class MuninnPageCacheWithRealFileSystemIT extends MuninnPageCacheTest
{
@Rule
public TargetDirectory.TestDirectory directory = TargetDirectory.testDirForTest( getClass() );
public TestDirectory directory = TestDirectory.testDirectory();

@After
public void tearDown() throws IOException
{
directory.cleanup();
}

@Override
protected Fixture<MuninnPageCache> createFixture()
Expand Down
18 changes: 3 additions & 15 deletions community/io/src/test/java/org/neo4j/test/Digests.java
Expand Up @@ -22,6 +22,8 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.neo4j.string.HexString;

public class Digests
{
public static String md5Hex( String message )
Expand All @@ -30,25 +32,11 @@ public static String md5Hex( String message )
{
MessageDigest m = MessageDigest.getInstance( "MD5" );
m.update( message.getBytes(), 0, message.getBytes().length);
return hex(m.digest());
return HexString.encodeHexString( m.digest() );
}
catch ( NoSuchAlgorithmException e )
{
throw new RuntimeException( "MD5 hash algorithm is not available on this platform: " + e.getMessage(),e );
}
}

protected static final char[] hexArray = "0123456789ABCDEF".toCharArray();

// TODO: Replace with BytePrinter#compactHex once auth work is merged
private static String hex(byte[] bytes)
{
char[] hexChars = new char[bytes.length * 2];
for ( int j = 0; j < bytes.length; j++ ) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
}

0 comments on commit 30a30a4

Please sign in to comment.