Skip to content

Commit

Permalink
Shuffle lucene-index tests move rules, fields, junit hook methors on …
Browse files Browse the repository at this point in the history
…top.

Remove IsEmpty, switch to standard matcher instead.
Remove separate process from RecoveryTest.
  • Loading branch information
MishaDemianenko committed Dec 5, 2015
1 parent e3210c0 commit 3cf4c8e
Show file tree
Hide file tree
Showing 27 changed files with 409 additions and 549 deletions.
Expand Up @@ -104,7 +104,7 @@ private void createDbIfNecessary()
} }
finally finally
{ {
dbRule.stopAndKeepFiles(); dbRule.shutdownAndKeepStore();
} }
} }
} }
Expand Down
Expand Up @@ -333,14 +333,9 @@ private void shutdown( boolean deleteResources )
} }
} }


public void stopAndKeepFiles() public void shutdownAndKeepStore()
{ {
if ( database != null ) shutdown( false );
{
database.shutdown();
database = null;
statementSupplier = null;
}
} }


public <T> T resolveDependency( Class<T> type ) public <T> T resolveDependency( Class<T> type )
Expand Down
Expand Up @@ -52,6 +52,11 @@
*/ */
public class LuceneLabelScanStoreChaosIT public class LuceneLabelScanStoreChaosIT
{ {

@Rule
public final DatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() );
private final Random random = new Random();

@Test @Test
public void shouldRebuildDeletedLabelScanStoreOnStartup() throws Exception public void shouldRebuildDeletedLabelScanStoreOnStartup() throws Exception
{ {
Expand Down Expand Up @@ -97,55 +102,44 @@ public void shouldPreventCorruptedLabelScanStoreToStartup() throws Exception


private RestartAction corruptTheLabelScanStoreIndex() private RestartAction corruptTheLabelScanStoreIndex()
{ {
return new RestartAction() return ( fs, storeDirectory ) -> {
{ try
@Override
public void run( FileSystemAbstraction fs, File storeDirectory )
{ {
try int filesCorrupted = 0;
for ( File file : labelScanStoreIndexDirectory( storeDirectory ).listFiles() )
{ {
int filesCorrupted = 0; scrambleFile( file );
for ( File file : labelScanStoreIndexDirectory( storeDirectory ).listFiles() ) filesCorrupted++;
{
scrambleFile( file );
filesCorrupted++;
}
assertTrue( "No files found to corrupt", filesCorrupted > 0 );
}
catch ( IOException e )
{
throw new RuntimeException( e );
} }
assertTrue( "No files found to corrupt", filesCorrupted > 0 );
}
catch ( IOException e )
{
throw new RuntimeException( e );
} }
}; };
} }


private RestartAction deleteTheLabelScanStoreIndex() private RestartAction deleteTheLabelScanStoreIndex()
{ {
return new RestartAction() return ( fs, storeDirectory ) -> {
{ try
@Override
public void run( FileSystemAbstraction fs, File storeDirectory )
{ {
try File directory = labelScanStoreIndexDirectory( storeDirectory );
{ assertTrue( "We seem to want to delete the wrong directory here", directory.exists() );
File directory = labelScanStoreIndexDirectory( storeDirectory ); assertTrue( "No index files to delete", directory.listFiles().length > 0 );
assertTrue( "We seem to want to delete the wrong directory here", directory.exists() ); deleteRecursively( directory );
assertTrue( "No index files to delete", directory.listFiles().length > 0 ); }
deleteRecursively( directory ); catch ( IOException e )
} {
catch ( IOException e ) throw new RuntimeException( e );
{
throw new RuntimeException( e );
}
} }
}; };
} }


private File labelScanStoreIndexDirectory( File storeDirectory ) private File labelScanStoreIndexDirectory( File storeDirectory )
{ {
File directory = new File( new File( new File( storeDirectory, "schema" ), "label" ), "lucene" ); return new File( new File( new File( storeDirectory, "schema" ), "label" ), "lucene" );
return directory;
} }


private Node createLabeledNode( Label... labels ) private Node createLabeledNode( Label... labels )
Expand Down Expand Up @@ -197,13 +191,10 @@ private void putRandomBytes( byte[] bytes )
} }
} }


private static enum Labels implements Label private enum Labels implements Label
{ {
First, First,
Second, Second,
Third; Third;
} }

public final @Rule DatabaseRule dbRule = new EmbeddedDatabaseRule( getClass() );
private final Random random = new Random();
} }
Expand Up @@ -48,6 +48,12 @@ public static void setUpDb() throws Exception
{ {
graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase(); graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
} }

@AfterClass
public static void tearDownDb() throws Exception
{
graphDb.shutdown();
}


@Before @Before
public void setUpTest() public void setUpTest()
Expand Down Expand Up @@ -93,12 +99,6 @@ protected Transaction beginTx()
return tx; return tx;
} }


@AfterClass
public static void tearDownDb() throws Exception
{
graphDb.shutdown();
}

public static void deleteFileOrDirectory( File file ) public static void deleteFileOrDirectory( File file )
{ {
if ( !file.exists() ) if ( !file.exists() )
Expand Down
Expand Up @@ -41,9 +41,10 @@


public abstract class AbstractLuceneIndexTest public abstract class AbstractLuceneIndexTest
{ {
@Rule
public final TestName testname = new TestName();
protected static GraphDatabaseService graphDb; protected static GraphDatabaseService graphDb;
protected Transaction tx; protected Transaction tx;
public final @Rule TestName testname = new TestName();


@BeforeClass @BeforeClass
public static void setUpStuff() public static void setUpStuff()
Expand Down
Expand Up @@ -42,7 +42,8 @@


public class AutoIndexerTest public class AutoIndexerTest
{ {
public final @Rule DatabaseRule db = new EmbeddedDatabaseRule() @Rule
public final DatabaseRule db = new EmbeddedDatabaseRule()
{ {
@Override @Override
protected void configure( GraphDatabaseBuilder builder ) protected void configure( GraphDatabaseBuilder builder )
Expand Down

This file was deleted.

Expand Up @@ -45,8 +45,10 @@


public class LuceneCommandApplierTest public class LuceneCommandApplierTest
{ {
public final @Rule EphemeralFileSystemRule fs = new EphemeralFileSystemRule(); @Rule
public final @Rule LifeRule life = new LifeRule( true ); public final EphemeralFileSystemRule fs = new EphemeralFileSystemRule();
@Rule
public final LifeRule life = new LifeRule( true );
private final File dir = new File( "dir" ); private final File dir = new File( "dir" );


@Test @Test
Expand Down
Expand Up @@ -46,8 +46,10 @@


public class LuceneDataSourceTest public class LuceneDataSourceTest
{ {
public final @Rule LifeRule life = new LifeRule( true ); @Rule
public final @Rule TestDirectory directory = TargetDirectory.testDirForTest( getClass() ); public final LifeRule life = new LifeRule( true );
@Rule
public final TestDirectory directory = TargetDirectory.testDirForTest( getClass() );
private IndexConfigStore indexStore; private IndexConfigStore indexStore;
private LuceneDataSource dataSource; private LuceneDataSource dataSource;


Expand Down
Expand Up @@ -37,16 +37,20 @@


public class LuceneRecoveryIT public class LuceneRecoveryIT
{ {

@Test @Test
public void testHardCoreRecovery() throws Exception public void testHardCoreRecovery() throws Exception
{ {
String path = "target/hcdb"; String path = "target/hcdb";
FileUtils.deleteRecursively( new File( path ) ); FileUtils.deleteRecursively( new File( path ) );


Process process = Runtime.getRuntime().exec( new String[]{ Process process = Runtime.getRuntime().exec( new String[]{
ProcessUtil.getJavaExecutable().toString(), "-cp", ProcessUtil.getClassPath(), ProcessUtil.getJavaExecutable().toString(), "-cp", ProcessUtil.getClassPath(),
Inserter.class.getName(), path Inserter.class.getName(), path
} ); } );



// Let it run for a while and then kill it, and wait for it to die // Let it run for a while and then kill it, and wait for it to die
awaitFile( new File( path, "started" ) ); awaitFile( new File( path, "started" ) );
Thread.sleep( 5000 ); Thread.sleep( 5000 );
Expand Down
Expand Up @@ -54,6 +54,9 @@


public class PerformanceAndSanityIT extends AbstractLuceneIndexTest public class PerformanceAndSanityIT extends AbstractLuceneIndexTest
{ {
@Rule
public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() );

@Ignore @Ignore
@Test @Test
public void testNodeInsertionSpeed() public void testNodeInsertionSpeed()
Expand Down Expand Up @@ -288,7 +291,4 @@ public void run()


System.out.println( t1 + ", " + (double)t1/(double)count ); System.out.println( t1 + ", " + (double)t1/(double)count );
} }

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

0 comments on commit 3cf4c8e

Please sign in to comment.