use of org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class NodeStoreTest method shouldCloseStoreFileOnFailureToOpen.
@Test
public void shouldCloseStoreFileOnFailureToOpen() throws Exception {
// GIVEN
final AtomicBoolean fired = new AtomicBoolean();
FileSystemAbstraction fs = new DelegatingFileSystemAbstraction(efs.get()) {
@Override
public StoreChannel open(File fileName, String mode) throws IOException {
return new DelegatingStoreChannel(super.open(fileName, mode)) {
@Override
public int read(ByteBuffer dst) throws IOException {
Exception stack = new Exception();
if (containsStackTraceElement(stack, item -> item.getMethodName().equals("initGenerator")) && !containsStackTraceElement(stack, item -> item.getMethodName().equals("createNodeStore"))) {
fired.set(true);
throw new IOException("Proving a point here");
}
return super.read(dst);
}
};
}
};
// WHEN
try (PageCache pageCache = pageCacheRule.getPageCache(fs)) {
newNodeStore(fs);
fail("Should fail");
}// Close the page cache here so that we can see failure to close (due to still mapped files)
catch (Exception e) {
// THEN
assertTrue(contains(e, IOException.class));
assertTrue(fired.get());
}
}
use of org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class StoreLockerTest method shouldNotObtainLockWhenUnableToOpenLockFile.
@Test
public void shouldNotObtainLockWhenUnableToOpenLockFile() throws Exception {
FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {
@Override
public StoreChannel open(File fileName, String mode) throws IOException {
throw new IOException("cannot open lock file");
}
@Override
public boolean fileExists(File fileName) {
return false;
}
};
File storeDir = target.directory("unused");
try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
storeLocker.checkLock(storeDir);
fail();
} catch (StoreLockException e) {
String msg = format("Unable to obtain lock on store lock file: %s. " + "Please ensure no other process is using this database, and that the " + "directory is writable (required even for read-only access)", new File(storeDir, STORE_LOCK_FILENAME));
assertThat(e.getMessage(), is(msg));
}
}
use of org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class StoreLockerTest method shouldNotObtainLockWhenStoreDirCannotBeCreated.
@Test
public void shouldNotObtainLockWhenStoreDirCannotBeCreated() throws Exception {
FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {
@Override
public void mkdirs(File fileName) throws IOException {
throw new IOException("store dir could not be created");
}
@Override
public boolean fileExists(File fileName) {
return false;
}
};
File storeDir = target.directory("unused");
try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
storeLocker.checkLock(storeDir);
fail();
} catch (StoreLockException e) {
String msg = format("Unable to create path for store dir: %s. " + "Please ensure no other process is using this database, and that " + "the directory is writable (required even for read-only access)", storeDir);
assertThat(e.getMessage(), is(msg));
}
}
use of org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction in project neo4j by neo4j.
the class FileRoleRepositoryTest 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 (roleFile.getName().equals(newLocation.getName())) {
throw exception;
}
super.renameFile(oldLocation, newLocation, copyOptions);
}
};
roleRepository = new FileRoleRepository(craschingFileSystem, roleFile, logProvider);
roleRepository.start();
RoleRecord role = new RoleRecord("admin", "jake");
// When
try {
roleRepository.create(role);
fail("Expected an IOException");
} catch (IOException e) {
assertSame(exception, e);
}
// Then
assertFalse(craschingFileSystem.fileExists(roleFile));
assertThat(craschingFileSystem.listFiles(roleFile.getParentFile()).length, equalTo(0));
}
use of org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction 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));
}
Aggregations