Skip to content

Commit

Permalink
Uses real FS in StoreVersionCheckTest
Browse files Browse the repository at this point in the history
in an attempt to remove flakiness, since the ephemeral file system
is known to be different in behaviour sometimes.
  • Loading branch information
tinwelint committed Sep 13, 2016
1 parent 0cacd84 commit 49fdc3f
Showing 1 changed file with 16 additions and 12 deletions.
Expand Up @@ -26,30 +26,34 @@
import java.io.IOException;
import java.io.OutputStream;

import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.string.UTF8;
import org.neo4j.test.EphemeralFileSystemRule;
import org.neo4j.test.PageCacheRule;
import org.neo4j.test.TargetDirectory;
import org.neo4j.test.TargetDirectory.TestDirectory;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class StoreVersionCheckTest
{
private final FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
@Rule
public final EphemeralFileSystemRule fs = new EphemeralFileSystemRule();
public final TestDirectory directory = TargetDirectory.testDirForTest( getClass() );
@Rule
public final PageCacheRule pageCacheRule = new PageCacheRule();

@Test
public void shouldFailIfFileDoesNotExist()
{
// given
File missingFile = new File("/you/will/never/find/me");
PageCache pageCache = pageCacheRule.getPageCache( fs.get() );
File missingFile = new File( directory.directory(), "missing-file" );
PageCache pageCache = pageCacheRule.getPageCache( fs );
StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache );

// when
Expand All @@ -65,8 +69,8 @@ public void shouldFailIfFileDoesNotExist()
public void shouldReportShortFileDoesNotHaveSpecifiedVersion() throws IOException
{
// given
File shortFile = fileContaining( fs.get(), "nothing interesting" );
StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCacheRule.getPageCache( fs.get() ) );
File shortFile = fileContaining( fs, "nothing interesting" );
StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCacheRule.getPageCache( fs ) );

// when
StoreVersionCheck.Result result = storeVersionCheck.hasVersion( shortFile, "version" );
Expand All @@ -81,9 +85,9 @@ public void shouldReportShortFileDoesNotHaveSpecifiedVersion() throws IOExceptio
public void shouldReportFileWithIncorrectVersion() throws IOException
{
// given
File neoStore = emptyFile( fs.get() );
File neoStore = emptyFile( fs );
long v1 = MetaDataStore.versionStringToLong( "V1" );
PageCache pageCache = pageCacheRule.getPageCache( fs.get() );
PageCache pageCache = pageCacheRule.getPageCache( fs );
MetaDataStore.setRecord( pageCache, neoStore, MetaDataStore.Position.STORE_VERSION, v1 );
StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache );

Expand All @@ -100,9 +104,9 @@ public void shouldReportFileWithIncorrectVersion() throws IOException
public void shouldReportFileWithCorrectVersion() throws IOException
{
// given
File neoStore = emptyFile( fs.get() );
File neoStore = emptyFile( fs );
long v1 = MetaDataStore.versionStringToLong( "V1" );
PageCache pageCache = pageCacheRule.getPageCache( fs.get() );
PageCache pageCache = pageCacheRule.getPageCache( fs );
MetaDataStore.setRecord( pageCache, neoStore, MetaDataStore.Position.STORE_VERSION, v1 );
StoreVersionCheck storeVersionCheck = new StoreVersionCheck( pageCache );

Expand All @@ -117,15 +121,15 @@ public void shouldReportFileWithCorrectVersion() throws IOException

private File emptyFile( FileSystemAbstraction fs ) throws IOException
{
File shortFile = new File( "shortFile" );
File shortFile = directory.file( "empty" );
fs.deleteFile( shortFile );
fs.create( shortFile );
return shortFile;
}

private File fileContaining( FileSystemAbstraction fs, String content ) throws IOException
{
File shortFile = new File( "shortFile" );
File shortFile = directory.file( "file" );
fs.deleteFile( shortFile );
try ( OutputStream outputStream = fs.openAsOutputStream( shortFile, false ) )
{
Expand Down

0 comments on commit 49fdc3f

Please sign in to comment.