Search in sources :

Example 86 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class StoreMigratorTest method shouldNotDoActualStoreMigrationBetween3_0_5_and_next.

@Test
public void shouldNotDoActualStoreMigrationBetween3_0_5_and_next() throws Exception {
    // GIVEN a store in vE.H.0 format
    File storeDir = directory.directory();
    new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.record_format, HighLimitV3_0_0.NAME).newGraphDatabase().shutdown();
    Config config = Config.embeddedDefaults(stringMap(pagecache_memory.name(), "8m"));
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
        PageCache pageCache = new ConfiguringPageCacheFactory(fs, config, NULL, PageCursorTracerSupplier.NULL, NullLog.getInstance()).getOrCreatePageCache()) {
        // For test code sanity
        String fromStoreVersion = StoreVersion.HIGH_LIMIT_V3_0_0.versionString();
        Result hasVersionResult = new StoreVersionCheck(pageCache).hasVersion(new File(storeDir, NEO_STORE.fileName(STORE)), fromStoreVersion);
        assertTrue(hasVersionResult.actualVersion, hasVersionResult.outcome.isSuccessful());
        // WHEN
        StoreMigrator migrator = new StoreMigrator(fs, pageCache, config, NullLogService.getInstance(), NO_INDEX_PROVIDER);
        MigrationProgressMonitor.Section monitor = mock(MigrationProgressMonitor.Section.class);
        File migrationDir = new File(storeDir, "migration");
        fs.mkdirs(migrationDir);
        migrator.migrate(storeDir, migrationDir, monitor, fromStoreVersion, StoreVersion.HIGH_LIMIT_V3_0_6.versionString());
        // THEN
        verifyNoMoreInteractions(monitor);
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) MigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 87 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class BatchingNeoStoresIT method startBatchingNeoStoreWithMetricsPluginEnabled.

@Test
public void startBatchingNeoStoreWithMetricsPluginEnabled() throws Exception {
    FileSystemAbstraction fileSystem = fileSystemRule.get();
    File storeDir = testDirectory.graphDbDir();
    Config config = Config.defaults().with(MapUtil.stringMap(MetricsSettings.metricsEnabled.name(), "true"));
    AssertableLogProvider provider = new AssertableLogProvider();
    SimpleLogService logService = new SimpleLogService(provider, provider);
    try (BatchingNeoStores batchingNeoStores = BatchingNeoStores.batchingNeoStores(fileSystem, storeDir, RecordFormatSelector.defaultFormat(), Configuration.DEFAULT, logService, AdditionalInitialIds.EMPTY, config)) {
    // empty block
    }
    provider.assertNone(AssertableLogProvider.inLog(MetricsExtension.class).any());
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) SimpleLogService(org.neo4j.kernel.impl.logging.SimpleLogService) Config(org.neo4j.kernel.configuration.Config) File(java.io.File) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 88 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class ReadAheadChannelTest method shouldReturnValueIfSufficientBytesAreBufferedEvenIfEOFHasBeenEncountered.

@Test
public void shouldReturnValueIfSufficientBytesAreBufferedEvenIfEOFHasBeenEncountered() throws Exception {
    // Given
    FileSystemAbstraction fileSystem = fileSystemRule.get();
    StoreChannel storeChannel = fileSystem.open(new File("foo.txt"), "rw");
    ByteBuffer buffer = ByteBuffer.allocate(1);
    buffer.put((byte) 1);
    buffer.flip();
    storeChannel.writeAll(buffer);
    storeChannel.force(false);
    storeChannel.close();
    storeChannel = fileSystem.open(new File("foo.txt"), "r");
    ReadAheadChannel<StoreChannel> channel = new ReadAheadChannel<>(storeChannel);
    try {
        channel.getShort();
        fail("Should have thrown exception signalling end of file reached");
    } catch (ReadPastEndException endOfFile) {
    // outstanding
    }
    assertEquals((byte) 1, channel.get());
    try {
        channel.get();
        fail("Should have thrown exception signalling end of file reached");
    } catch (ReadPastEndException endOfFile) {
    // outstanding
    }
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) ReadPastEndException(org.neo4j.storageengine.api.ReadPastEndException) Test(org.junit.Test)

Example 89 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class ReadAheadChannelTest method shouldHandleRunningOutOfBytesWhenRequestSpansMultipleFiles.

@Test
public void shouldHandleRunningOutOfBytesWhenRequestSpansMultipleFiles() throws Exception {
    // Given
    FileSystemAbstraction fileSystem = fileSystemRule.get();
    StoreChannel storeChannel1 = fileSystem.open(new File("foo.1"), "rw");
    ByteBuffer buffer = ByteBuffer.allocate(2);
    buffer.put((byte) 0);
    buffer.put((byte) 0);
    buffer.flip();
    storeChannel1.writeAll(buffer);
    storeChannel1.force(false);
    storeChannel1.close();
    buffer.flip();
    StoreChannel storeChannel2 = fileSystem.open(new File("foo.2"), "r");
    buffer.put((byte) 0);
    buffer.put((byte) 1);
    buffer.flip();
    storeChannel2.writeAll(buffer);
    storeChannel2.force(false);
    storeChannel2.close();
    storeChannel1 = fileSystem.open(new File("foo.1"), "r");
    final StoreChannel storeChannel2Copy = fileSystem.open(new File("foo.2"), "r");
    ReadAheadChannel<StoreChannel> channel = new ReadAheadChannel<StoreChannel>(storeChannel1) {

        @Override
        protected StoreChannel next(StoreChannel channel) throws IOException {
            return storeChannel2Copy;
        }
    };
    try {
        channel.getLong();
        fail("Should have thrown exception signalling end of file reached");
    } catch (ReadPastEndException endOfFile) {
    // outstanding
    }
    assertEquals(1, channel.getInt());
    try {
        channel.get();
        fail("Should have thrown exception signalling end of file reached");
    } catch (ReadPastEndException endOfFile) {
    // outstanding
    }
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) ReadPastEndException(org.neo4j.storageengine.api.ReadPastEndException) Test(org.junit.Test)

Example 90 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class PhysicalLogFileTest method shouldOpenInFreshDirectoryAndFinallyAddHeader.

@Test
public void shouldOpenInFreshDirectoryAndFinallyAddHeader() throws Exception {
    // GIVEN
    String name = "log";
    LifeSupport life = new LifeSupport();
    FileSystemAbstraction fs = fileSystemRule.get();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
    life.add(new PhysicalLogFile(fs, logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
    // WHEN
    life.start();
    life.shutdown();
    // THEN
    File file = new PhysicalLogFiles(directory.directory(), name, fs).getLogFileForVersion(1L);
    LogHeader header = readLogHeader(fs, file);
    assertEquals(1L, header.logVersion);
    assertEquals(5L, header.lastCommittedTxId);
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.Test)

Aggregations

FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)125 File (java.io.File)88 Test (org.junit.Test)82 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)34 IOException (java.io.IOException)28 Config (org.neo4j.kernel.configuration.Config)23 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)22 PageCache (org.neo4j.io.pagecache.PageCache)22 DelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction)20 ByteBuffer (java.nio.ByteBuffer)13 StoreChannel (org.neo4j.io.fs.StoreChannel)11 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)10 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)9 DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)9 OutputStream (java.io.OutputStream)8 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)8 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)8 Map (java.util.Map)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)7