Skip to content

Commit

Permalink
Fix procedure compiler wrong version and close leftovers of default f…
Browse files Browse the repository at this point in the history
…ile system abstraction.
  • Loading branch information
MishaDemianenko committed Nov 21, 2016
1 parent 2ecafb7 commit bc935b1
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 58 deletions.
Expand Up @@ -126,7 +126,7 @@ public GraphStoreFixture( String formatName )
protected void after( boolean success )
{
super.after( success );
if (fileSystem != null)
if ( fileSystem != null )
{
try
{
Expand Down
Expand Up @@ -103,6 +103,7 @@ public void verifyInterruptionAndChannelState() throws IOException
// This is good. What we expect to see.
}
}
fs.close();
}

private StoreChannel chan( boolean channelShouldBeClosed ) throws IOException
Expand Down
35 changes: 18 additions & 17 deletions community/kernel/src/test/java/org/neo4j/kernel/RecoveryTest.java
Expand Up @@ -30,8 +30,6 @@

import org.neo4j.helpers.collection.Pair;
import org.neo4j.helpers.collection.Visitor;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation;
import org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository;
import org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore;
Expand Down Expand Up @@ -63,6 +61,7 @@
import org.neo4j.kernel.recovery.Recovery;
import org.neo4j.storageengine.api.StorageEngine;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand All @@ -78,8 +77,9 @@

public class RecoveryTest
{
private final FileSystemAbstraction fs = new DefaultFileSystemAbstraction();

@Rule
public final DefaultFileSystemRule fileSystemRule = new DefaultFileSystemRule();
@Rule
public final TestDirectory directory = TestDirectory.testDirectory();
private final LogVersionRepository logVersionRepository = new DeadSimpleLogVersionRepository( 1L );
Expand All @@ -93,10 +93,11 @@ public class RecoveryTest
private LogEntry expectedCommitEntry;
private LogEntry expectedCheckPointEntry;


@Test
public void shouldRecoverExistingData() throws Exception
{
final PhysicalLogFiles logFiles = new PhysicalLogFiles( directory.directory(), "log", fs );
final PhysicalLogFiles logFiles = new PhysicalLogFiles( directory.directory(), "log", fileSystemRule.get() );
File file = logFiles.getLogFileForVersion( logVersion );

writeSomeData( file, new Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>,IOException>()
Expand Down Expand Up @@ -139,17 +140,17 @@ public boolean visit( Pair<LogEntryWriter,Consumer<LogPositionMarker>> pair ) th
{
StorageEngine storageEngine = mock( StorageEngine.class );
final LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
LatestCheckPointFinder finder = new LatestCheckPointFinder( logFiles, fs, reader );
LatestCheckPointFinder finder = new LatestCheckPointFinder( logFiles, fileSystemRule.get(), reader );

LogHeaderCache logHeaderCache = new LogHeaderCache( 10 );
TransactionMetadataCache metadataCache = new TransactionMetadataCache( 100 );
LogFile logFile = life.add( new PhysicalLogFile( fs, logFiles, 50,
LogFile logFile = life.add( new PhysicalLogFile( fileSystemRule.get(), logFiles, 50,
() -> transactionIdStore.getLastCommittedTransactionId(), logVersionRepository,
mock( PhysicalLogFile.Monitor.class ), logHeaderCache ) );
LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore( logFile, metadataCache, reader );

life.add( new Recovery( new DefaultRecoverySPI( storageEngine,
logFiles, fs, logVersionRepository, finder, transactionIdStore, txStore )
logFiles, fileSystemRule.get(), logVersionRepository, finder, transactionIdStore, txStore )
{
private int nr = 0;

Expand Down Expand Up @@ -198,7 +199,7 @@ public boolean visit( CommittedTransactionRepresentation tx ) throws Exception
@Test
public void shouldSeeThatACleanDatabaseShouldNotRequireRecovery() throws Exception
{
final PhysicalLogFiles logFiles = new PhysicalLogFiles( directory.directory(), "log", fs );
final PhysicalLogFiles logFiles = new PhysicalLogFiles( directory.directory(), "log", fileSystemRule.get() );
File file = logFiles.getLogFileForVersion( logVersion );

writeSomeData( file, new Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>,IOException>()
Expand Down Expand Up @@ -229,17 +230,17 @@ public boolean visit( Pair<LogEntryWriter,Consumer<LogPositionMarker>> pair ) th
{
StorageEngine storageEngine = mock( StorageEngine.class );
final LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
LatestCheckPointFinder finder = new LatestCheckPointFinder( logFiles, fs, reader );
LatestCheckPointFinder finder = new LatestCheckPointFinder( logFiles, fileSystemRule.get(), reader );

TransactionMetadataCache metadataCache = new TransactionMetadataCache( 100 );
LogHeaderCache logHeaderCache = new LogHeaderCache( 10 );
LogFile logFile = life.add( new PhysicalLogFile( fs, logFiles, 50,
LogFile logFile = life.add( new PhysicalLogFile( fileSystemRule.get(), logFiles, 50,
() -> transactionIdStore.getLastCommittedTransactionId(), logVersionRepository,
mock( PhysicalLogFile.Monitor.class ), logHeaderCache ) );
LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore( logFile, metadataCache, reader );

life.add( new Recovery( new DefaultRecoverySPI( storageEngine,
logFiles, fs, logVersionRepository, finder, transactionIdStore, txStore )
logFiles, fileSystemRule.get(), logVersionRepository, finder, transactionIdStore, txStore )
{
@Override
public Visitor<CommittedTransactionRepresentation,Exception> startRecovery()
Expand All @@ -263,7 +264,7 @@ public Visitor<CommittedTransactionRepresentation,Exception> startRecovery()
public void shouldTruncateLogAfterLastCompleteTransactionAfterSuccessfullRecovery() throws Exception
{
// GIVEN
final PhysicalLogFiles logFiles = new PhysicalLogFiles( directory.directory(), "log", fs );
final PhysicalLogFiles logFiles = new PhysicalLogFiles( directory.directory(), "log", fileSystemRule.get() );
File file = logFiles.getLogFileForVersion( logVersion );
final LogPositionMarker marker = new LogPositionMarker();

Expand Down Expand Up @@ -299,7 +300,7 @@ public boolean visit( Pair<LogEntryWriter,Consumer<LogPositionMarker>> pair ) th
public void shouldTellTransactionIdStoreAfterSuccessfullRecovery() throws Exception
{
// GIVEN
final PhysicalLogFiles logFiles = new PhysicalLogFiles( directory.directory(), "log", fs );
final PhysicalLogFiles logFiles = new PhysicalLogFiles( directory.directory(), "log", fileSystemRule.get() );
File file = logFiles.getLogFileForVersion( logVersion );
final LogPositionMarker marker = new LogPositionMarker();

Expand Down Expand Up @@ -348,17 +349,17 @@ private boolean recover( PhysicalLogFiles logFiles )
{
StorageEngine storageEngine = mock( StorageEngine.class );
final LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
LatestCheckPointFinder finder = new LatestCheckPointFinder( logFiles, fs, reader );
LatestCheckPointFinder finder = new LatestCheckPointFinder( logFiles, fileSystemRule.get(), reader );

TransactionMetadataCache metadataCache = new TransactionMetadataCache( 100 );
LogHeaderCache logHeaderCache = new LogHeaderCache( 10 );
LogFile logFile = life.add( new PhysicalLogFile( fs, logFiles, 50,
LogFile logFile = life.add( new PhysicalLogFile( fileSystemRule.get(), logFiles, 50,
() -> transactionIdStore.getLastCommittedTransactionId(), logVersionRepository,
mock( PhysicalLogFile.Monitor.class ), logHeaderCache ) );
LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore( logFile, metadataCache, reader );

life.add( new Recovery( new DefaultRecoverySPI( storageEngine,
logFiles, fs, logVersionRepository, finder, transactionIdStore, txStore )
logFiles, fileSystemRule.get(), logVersionRepository, finder, transactionIdStore, txStore )
{
@Override
public Visitor<CommittedTransactionRepresentation,Exception> startRecovery()
Expand All @@ -381,7 +382,7 @@ private void writeSomeData( File file, Visitor<Pair<LogEntryWriter,Consumer<LogP
{

try ( LogVersionedStoreChannel versionedStoreChannel =
new PhysicalLogVersionedStoreChannel( fs.open( file, "rw" ), logVersion, CURRENT_LOG_VERSION );
new PhysicalLogVersionedStoreChannel( fileSystemRule.get().open( file, "rw" ), logVersion, CURRENT_LOG_VERSION );
final PositionAwarePhysicalFlushableChannel writableLogChannel = new PositionAwarePhysicalFlushableChannel( versionedStoreChannel ) )
{
writeLogHeader( writableLogChannel, logVersion, 2L );
Expand Down
Expand Up @@ -129,7 +129,7 @@ public static void truncateToFixedLength( FileSystemAbstraction fileSystem, File
public static void prepareSampleLegacyDatabase( String version, EphemeralFileSystemAbstraction workingFs,
File workingDirectory, File realDirForPreparingDatabase ) throws IOException
{
try (DefaultFileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction())
try ( DefaultFileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction() )
{
File resourceDirectory = findFormatStoreDirectoryForVersion( version, realDirForPreparingDatabase );
workingFs.copyRecursivelyFromOtherFs( resourceDirectory, fileSystemAbstraction,
Expand Down
Expand Up @@ -73,7 +73,8 @@ public EmbeddedDatabaseRule( final Class<?> testClass )
{
this.temp = new TempDirectory()
{
private final TestDirectory testDirectory = TestDirectory.testDirectory( testClass, new DefaultFileSystemAbstraction() );
private final DefaultFileSystemAbstraction fs = new DefaultFileSystemAbstraction();
private final TestDirectory testDirectory = TestDirectory.testDirectory( testClass, fs );
private File dbDir;

@Override
Expand All @@ -86,6 +87,7 @@ public File root()
public void delete() throws IOException
{
testDirectory.cleanup();
fs.close();
}

@Override
Expand Down
Expand Up @@ -44,23 +44,4 @@ public DefaultFileSystemAbstraction get()
{
return fs;
}

public DefaultFileSystemAbstraction snapshot( Runnable action )
{
DefaultFileSystemAbstraction snapshot = fs;
try
{
action.run();
}
finally
{
fs = snapshot;
}
return fs;
}

public void clear()
{
fs = new DefaultFileSystemAbstraction();
}
}
Expand Up @@ -33,7 +33,6 @@
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.graphdb.index.IndexManager;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.index.IndexEntityType;
Expand Down Expand Up @@ -64,7 +63,7 @@ public class LuceneDataSourceTest
@Before
public void setUp()
{
indexStore = new IndexConfigStore( directory.directory(), new DefaultFileSystemAbstraction() );
indexStore = new IndexConfigStore( directory.directory(), fileSystemRule.get() );
addIndex( "foo" );
}

Expand Down
Expand Up @@ -164,7 +164,7 @@ private BackupOutcome fullBackup( FileSystemAbstraction fileSystem, String sourc
try ( PageCache pageCache = createPageCache( fileSystem, tuningConfiguration ) )
{
StoreCopyClient storeCopier = new StoreCopyClient( targetDirectory, tuningConfiguration,
loadKernelExtensions(), logProvider, new DefaultFileSystemAbstraction(), pageCache,
loadKernelExtensions(), logProvider, fileSystem, pageCache,
monitors.newMonitor( StoreCopyClient.Monitor.class, getClass() ), forensics );
FullBackupStoreCopyRequester storeCopyRequester =
new FullBackupStoreCopyRequester( sourceHostNameOrIp, sourcePort, timeout, forensics, monitors );
Expand Down
Expand Up @@ -24,6 +24,11 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.File;
import java.io.PrintStream;
import java.nio.file.Path;

import org.neo4j.helpers.HostnamePort;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
Expand All @@ -34,10 +39,6 @@
import org.neo4j.test.rule.EmbeddedDatabaseRule;
import org.neo4j.test.rule.TestDirectory;

import java.io.File;
import java.io.PrintStream;
import java.nio.file.Path;

import static org.mockito.Mockito.mock;
import static org.neo4j.kernel.impl.store.MetaDataStore.Position.STORE_VERSION;

Expand Down Expand Up @@ -70,6 +71,7 @@ public void setUp() throws Exception
public void teardown() throws Exception
{
pageCache.close();
fs.close();
}

@Test
Expand Down
Expand Up @@ -26,14 +26,12 @@
import java.util.Set;

import org.neo4j.causalclustering.identity.StoreId;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.impl.pagecache.StandalonePageCacheFactory;
import org.neo4j.kernel.impl.store.MetaDataStore;

import static org.junit.Assert.assertEquals;

import static org.neo4j.kernel.impl.store.MetaDataStore.Position.RANDOM_NUMBER;
import static org.neo4j.kernel.impl.store.MetaDataStore.Position.TIME;
import static org.neo4j.kernel.impl.store.MetaDataStore.Position.UPGRADE_TIME;
Expand All @@ -55,14 +53,6 @@ public static void assertAllStoresHaveTheSameStoreId( List<File> coreStoreDirs,
assertEquals( "Store Ids " + storeIds, 1, storeIds.size() );
}

public static StoreId readStoreId( File coreStoreDir, DefaultFileSystemAbstraction fs ) throws IOException
{
try ( PageCache pageCache = StandalonePageCacheFactory.createPageCache( fs ) )
{
return doReadStoreId( coreStoreDir, pageCache );
}
}

private static StoreId doReadStoreId( File coreStoreDir, PageCache pageCache ) throws IOException
{
File metadataStore = new File( coreStoreDir, MetaDataStore.DEFAULT_NAME );
Expand Down
Expand Up @@ -171,8 +171,8 @@ private void shouldPrint( String command, String... expectedResultContaining ) t

private long lastAppliedTx( File storeDir )
{
try ( FileSystemAbstraction fileSyste = new DefaultFileSystemAbstraction();
PageCache pageCache = createPageCache( new DefaultFileSystemAbstraction() ) )
try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = createPageCache( fileSystem ) )
{
return MetaDataStore.getRecord( pageCache, new File( storeDir, MetaDataStore.DEFAULT_NAME ),
MetaDataStore.Position.LAST_TRANSACTION_ID );
Expand Down

0 comments on commit bc935b1

Please sign in to comment.