Search in sources :

Example 61 with FileSystemAbstraction

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

the class RotatingFileOutputStreamSupplierTest method shouldNotifyListenerOnRotationErrorDuringRotationIO.

@Test
public void shouldNotifyListenerOnRotationErrorDuringRotationIO() throws Exception {
    RotationListener rotationListener = mock(RotationListener.class);
    FileSystemAbstraction fs = spy(fileSystem);
    RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier(fs, logFile, 10, 0, 10, DIRECT_EXECUTOR, rotationListener);
    OutputStream outputStream = supplier.get();
    IOException exception = new IOException("text exception");
    doThrow(exception).when(fs).renameFile(any(File.class), any(File.class));
    write(supplier, "A string longer than 10 bytes");
    assertThat(supplier.get(), is(outputStream));
    verify(rotationListener).rotationError(eq(exception), any(OutputStream.class));
}
Also used : AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) RotationListener(org.neo4j.logging.RotatingFileOutputStreamSupplier.RotationListener) AdversarialOutputStream(org.neo4j.adversaries.fs.AdversarialOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 62 with FileSystemAbstraction

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

the class CommunitySecurityModule method setup.

@Override
public void setup(Dependencies dependencies) throws KernelException {
    Config config = dependencies.config();
    Procedures procedures = dependencies.procedures();
    LogProvider logProvider = dependencies.logService().getUserLogProvider();
    FileSystemAbstraction fileSystem = dependencies.fileSystem();
    final UserRepository userRepository = getUserRepository(config, logProvider, fileSystem);
    final UserRepository initialUserRepository = getInitialUserRepository(config, logProvider, fileSystem);
    final PasswordPolicy passwordPolicy = new BasicPasswordPolicy();
    procedures.writerCreateToken(true);
    BasicAuthManager authManager = new BasicAuthManager(userRepository, passwordPolicy, Clocks.systemClock(), initialUserRepository);
    dependencies.lifeSupport().add(dependencies.dependencySatisfier().satisfyDependency(authManager));
    procedures.registerComponent(UserManager.class, ctx -> authManager, false);
    procedures.registerProcedure(AuthProcedures.class);
}
Also used : LogProvider(org.neo4j.logging.LogProvider) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) PasswordPolicy(org.neo4j.kernel.api.security.PasswordPolicy) Procedures(org.neo4j.kernel.impl.proc.Procedures)

Example 63 with FileSystemAbstraction

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

the class FileUserRepositoryTest method shouldRecoverIfCrashedDuringMove.

@Test
public void shouldRecoverIfCrashedDuringMove() throws Throwable {
    // Given
    final IOException exception = new IOException("simulated IO Exception on create");
    FileSystemAbstraction craschingFileSystem = new DelegatingFileSystemAbstraction(fs) {

        @Override
        public void renameFile(File oldLocation, File newLocation, CopyOption... copyOptions) throws IOException {
            if (authFile.getName().equals(newLocation.getName())) {
                throw exception;
            }
            super.renameFile(oldLocation, newLocation, copyOptions);
        }
    };
    FileUserRepository users = new FileUserRepository(craschingFileSystem, authFile, logProvider);
    users.start();
    User user = new User.Builder("jake", Credential.INACCESSIBLE).withRequiredPasswordChange(true).build();
    // When
    try {
        users.create(user);
        fail("Expected an IOException");
    } catch (IOException e) {
        assertSame(exception, e);
    }
    // Then
    assertFalse(craschingFileSystem.fileExists(authFile));
    assertThat(craschingFileSystem.listFiles(authFile.getParentFile()).length, equalTo(0));
}
Also used : DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) DelegateFileSystemAbstraction(org.neo4j.io.fs.DelegateFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) CopyOption(java.nio.file.CopyOption) User(org.neo4j.kernel.impl.security.User) IOException(java.io.IOException) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) File(java.io.File) Test(org.junit.Test)

Example 64 with FileSystemAbstraction

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

the class CheckPointingLogRotationStressTesting method shouldBehaveCorrectlyUnderStress.

@Test
public void shouldBehaveCorrectlyUnderStress() throws Throwable {
    long durationInMinutes = parseLong(fromEnv("CHECK_POINT_LOG_ROTATION_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
    File storeDir = new File(fromEnv("CHECK_POINT_LOG_ROTATION_STORE_DIRECTORY", DEFAULT_STORE_DIR));
    long nodeCount = parseLong(fromEnv("CHECK_POINT_LOG_ROTATION_NODE_COUNT", DEFAULT_NODE_COUNT));
    int threads = parseInt(fromEnv("CHECK_POINT_LOG_ROTATION_WORKER_THREADS", DEFAULT_WORKER_THREADS));
    String pageCacheMemory = fromEnv("CHECK_POINT_LOG_ROTATION_PAGE_CACHE_MEMORY", DEFAULT_PAGE_CACHE_MEMORY);
    System.out.println("1/6\tBuilding initial store...");
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        new ParallelBatchImporter(ensureExistsAndEmpty(storeDir), fileSystem, DEFAULT, NullLogService.getInstance(), ExecutionMonitors.defaultVisible(), Config.defaults()).doImport(new NodeCountInputs(nodeCount));
    }
    System.out.println("2/6\tStarting database...");
    GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir);
    GraphDatabaseService db = builder.setConfig(GraphDatabaseSettings.pagecache_memory, pageCacheMemory).setConfig(GraphDatabaseSettings.keep_logical_logs, Settings.FALSE).setConfig(GraphDatabaseSettings.check_point_interval_time, CHECK_POINT_INTERVAL_MINUTES + "m").setConfig(GraphDatabaseFacadeFactory.Configuration.tracer, "timer").newGraphDatabase();
    System.out.println("3/6\tWarm up db...");
    try (Workload workload = new Workload(db, defaultRandomMutation(nodeCount, db), threads)) {
        // make sure to run at least one checkpoint during warmup
        long warmUpTimeMillis = TimeUnit.SECONDS.toMillis(CHECK_POINT_INTERVAL_MINUTES * 2);
        workload.run(warmUpTimeMillis, Workload.TransactionThroughput.NONE);
    }
    System.out.println("4/6\tStarting workload...");
    TransactionThroughputChecker throughput = new TransactionThroughputChecker();
    try (Workload workload = new Workload(db, defaultRandomMutation(nodeCount, db), threads)) {
        workload.run(TimeUnit.MINUTES.toMillis(durationInMinutes), throughput);
    }
    System.out.println("5/6\tShutting down...");
    db.shutdown();
    try {
        System.out.println("6/6\tPrinting stats and recorded timings...");
        TimerTransactionTracer.printStats(System.out);
        throughput.assertThroughput(System.out);
    } finally {
        System.out.println("Done.");
    }
    // let's cleanup disk space when everything went well
    FileUtils.deleteRecursively(storeDir);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Workload(org.neo4j.kernel.stresstests.transaction.checkpoint.workload.Workload) ParallelBatchImporter(org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Example 65 with FileSystemAbstraction

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

the class DumpCountsStore method main.

public static void main(String... args) throws IOException {
    if (args.length != 1) {
        System.err.println("Expecting exactly one argument describing the path to the store");
        System.exit(1);
    }
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        dumpCountsStore(fileSystem, new File(args[0]), System.out);
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) File(java.io.File)

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