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
{
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 )
{
database.shutdown();
database = null;
statementSupplier = null;
}
shutdown( false );
}

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

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

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

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

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

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

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,
Second,
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();
}

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

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

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

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

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

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

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

This file was deleted.

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

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

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

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

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

public class LuceneRecoveryIT
{

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


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


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

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

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

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.