Search in sources :

Example 91 with FileSystemAbstraction

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

the class PhysicalLogFileTest method shouldWriteSomeDataIntoTheLog.

@Test
public void shouldWriteSomeDataIntoTheLog() throws Exception {
    // GIVEN
    String name = "log";
    LifeSupport life = new LifeSupport();
    FileSystemAbstraction fs = fileSystemRule.get();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
    Monitor monitor = mock(Monitor.class);
    LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, monitor, new LogHeaderCache(10)));
    // WHEN
    try {
        life.start();
        FlushablePositionAwareChannel writer = logFile.getWriter();
        LogPositionMarker positionMarker = new LogPositionMarker();
        writer.getCurrentPosition(positionMarker);
        int intValue = 45;
        long longValue = 4854587;
        writer.putInt(intValue);
        writer.putLong(longValue);
        writer.prepareForFlush().flush();
        // THEN
        try (ReadableClosableChannel reader = logFile.getReader(positionMarker.newPosition())) {
            assertEquals(intValue, reader.getInt());
            assertEquals(longValue, reader.getLong());
        }
    } finally {
        life.shutdown();
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Matchers.anyString(org.mockito.Matchers.anyString) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Example 92 with FileSystemAbstraction

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

the class PhysicalLogFileTest method shouldReadOlderLogs.

@Test
public void shouldReadOlderLogs() throws Exception {
    // GIVEN
    String name = "log";
    LifeSupport life = new LifeSupport();
    FileSystemAbstraction fs = fileSystemRule.get();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
    LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 50, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
    // WHEN
    life.start();
    try {
        FlushablePositionAwareChannel writer = logFile.getWriter();
        LogPositionMarker positionMarker = new LogPositionMarker();
        writer.getCurrentPosition(positionMarker);
        LogPosition position1 = positionMarker.newPosition();
        int intValue = 45;
        long longValue = 4854587;
        byte[] someBytes = someBytes(40);
        writer.putInt(intValue);
        writer.putLong(longValue);
        writer.put(someBytes, someBytes.length);
        writer.prepareForFlush().flush();
        writer.getCurrentPosition(positionMarker);
        LogPosition position2 = positionMarker.newPosition();
        long longValue2 = 123456789L;
        writer.putLong(longValue2);
        writer.put(someBytes, someBytes.length);
        writer.prepareForFlush().flush();
        // THEN
        try (ReadableClosableChannel reader = logFile.getReader(position1)) {
            assertEquals(intValue, reader.getInt());
            assertEquals(longValue, reader.getLong());
            assertArrayEquals(someBytes, readBytes(reader, 40));
        }
        try (ReadableClosableChannel reader = logFile.getReader(position2)) {
            assertEquals(longValue2, reader.getLong());
            assertArrayEquals(someBytes, readBytes(reader, 40));
        }
    } finally {
        life.shutdown();
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Matchers.anyString(org.mockito.Matchers.anyString) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Example 93 with FileSystemAbstraction

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

the class PhysicalLogFileTest method shouldVisitLogFile.

@Test
public void shouldVisitLogFile() throws Exception {
    // GIVEN
    String name = "log";
    LifeSupport life = new LifeSupport();
    FileSystemAbstraction fs = fileSystemRule.get();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
    LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 50, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
    life.start();
    FlushablePositionAwareChannel writer = logFile.getWriter();
    LogPositionMarker mark = new LogPositionMarker();
    writer.getCurrentPosition(mark);
    for (int i = 0; i < 5; i++) {
        writer.put((byte) i);
    }
    writer.prepareForFlush();
    // WHEN/THEN
    final AtomicBoolean called = new AtomicBoolean();
    logFile.accept((position, channel) -> {
        for (int i = 0; i < 5; i++) {
            assertEquals((byte) i, channel.get());
        }
        called.set(true);
        return true;
    }, mark.newPosition());
    assertTrue(called.get());
    life.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 94 with FileSystemAbstraction

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

the class ApplyRecoveredTransactionsTest method before.

@Before
public void before() {
    FileSystemAbstraction fs = fsr.get();
    File storeDir = new File("dir");
    StoreFactory storeFactory = new StoreFactory(storeDir, Config.empty(), new DefaultIdGeneratorFactory(fs), pageCacheRule.getPageCache(fs), fs, NullLogProvider.getInstance());
    neoStores = storeFactory.openAllNeoStores(true);
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) File(java.io.File) Before(org.junit.Before)

Example 95 with FileSystemAbstraction

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

the class StoreLockerTest method shouldNotObtainLockWhenStoreAlreadyInUse.

@Test
public void shouldNotObtainLockWhenStoreAlreadyInUse() throws Exception {
    FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {

        @Override
        public boolean fileExists(File fileName) {
            return false;
        }

        @Override
        public StoreChannel open(File fileName, String mode) throws IOException {
            return new DelegatingStoreChannel(super.open(fileName, mode)) {

                @Override
                public FileLock tryLock() throws IOException {
                    // 'null' implies that the file has been externally locked
                    return null;
                }
            };
        }
    };
    try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
        storeLocker.checkLock(target.directory("unused"));
        fail();
    } catch (StoreLockException e) {
        assertThat(e.getMessage(), containsString("Store and its lock file has been locked by another process"));
    }
}
Also used : DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreLockException(org.neo4j.kernel.StoreLockException) DelegatingStoreChannel(org.neo4j.graphdb.mockfs.DelegatingStoreChannel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) File(java.io.File) 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