Skip to content

Commit

Permalink
FileMoveAction fixup
Browse files Browse the repository at this point in the history
Favour PageCacheRule > manual PageCache configuration
Explicit check and IOException instead of assert in production
Removed assert from VoidPipelineWrapper
  • Loading branch information
phughk committed Jul 30, 2018
1 parent 5a8468e commit 037e0f8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Expand Up @@ -67,6 +67,9 @@ public PipelineWrapper forClient( Config config, Dependencies dependencies, LogP


private static void verifyNoEncryption( Config config, Setting<String> policyName ) private static void verifyNoEncryption( Config config, Setting<String> policyName )
{ {
assert config.get( policyName ) == null : "Unexpected SSL policy " + policyName; if ( config.get( policyName ) != null )
{
throw new IllegalArgumentException( "Unexpected SSL policy " + policyName );
}
} }
} }
Expand Up @@ -47,7 +47,7 @@ public void cannotCreateClusterWithSslPolicyForNonCommercialUse()
} }
catch ( Exception e ) catch ( Exception e )
{ {
AssertionError cause = (AssertionError) e.getCause(); IllegalArgumentException cause = (IllegalArgumentException) e.getCause();
Assert.assertThat( cause.getMessage(), containsString( CausalClusteringSettings.ssl_policy.name() ) ); Assert.assertThat( cause.getMessage(), containsString( CausalClusteringSettings.ssl_policy.name() ) );
} }
} }
Expand Down
Expand Up @@ -92,7 +92,10 @@ static FileMoveAction moveViaFileSystem( File sourceFile, File sourceDirectory )
public void move( File toDir, CopyOption... copyOptions ) throws IOException public void move( File toDir, CopyOption... copyOptions ) throws IOException
{ {
copyViaFileSystem( sourceFile, sourceDirectory ).move( toDir, copyOptions ); copyViaFileSystem( sourceFile, sourceDirectory ).move( toDir, copyOptions );
assert sourceFile.delete() : sourceFile; if ( !sourceFile.delete() )
{
throw new IOException( "Unable to delete source file after copying " + sourceFile );
}
} }


@Override @Override
Expand Down
Expand Up @@ -33,8 +33,7 @@
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.PagedFile; import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.kernel.configuration.Config; import org.neo4j.test.rule.PageCacheRule;
import org.neo4j.kernel.impl.pagecache.ConfigurableStandalonePageCacheFactory;
import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.TestDirectory;


import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
Expand All @@ -45,14 +44,16 @@ public class FileMoveActionTest
@Rule @Rule
public final TestDirectory testDirectory = TestDirectory.testDirectory(); public final TestDirectory testDirectory = TestDirectory.testDirectory();


@Rule
public final PageCacheRule pageCacheRule = new PageCacheRule();

private FileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction(); private FileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction();
private Config config = Config.defaults();


@Test @Test
public void pageCacheFilesMovedDoNotLeaveOriginal() throws IOException public void pageCacheFilesMovedDoNotLeaveOriginal() throws IOException
{ {
// given // given
PageCache pageCache = aPageCache(); PageCache pageCache = pageCacheRule.getPageCache( fileSystemAbstraction );


// and // and
File pageCacheFile = testDirectory.file( "page-cache-file" ); File pageCacheFile = testDirectory.file( "page-cache-file" );
Expand Down Expand Up @@ -118,9 +119,4 @@ public void nonPageCacheFilesCopiedLeaveOriginal() throws IOException
assertTrue( targetFile.exists() ); assertTrue( targetFile.exists() );
assertTrue( sourceFile.exists() ); assertTrue( sourceFile.exists() );
} }

private PageCache aPageCache()
{
return ConfigurableStandalonePageCacheFactory.createPageCache( fileSystemAbstraction, config );
}
} }

0 comments on commit 037e0f8

Please sign in to comment.