use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class PhysicalLogFileTest method shouldSuppressFailueToCloseChannelInFailedAttemptToReadHeaderAfterOpen.
@Test
public void shouldSuppressFailueToCloseChannelInFailedAttemptToReadHeaderAfterOpen() throws Exception {
// GIVEN a file which returns 1/2 log header size worth of bytes
File directory = new File("/dir");
FileSystemAbstraction fs = mock(FileSystemAbstraction.class);
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory, fs);
int logVersion = 0;
File logFile = logFiles.getLogFileForVersion(logVersion);
StoreChannel channel = mock(StoreChannel.class);
when(channel.read(any(ByteBuffer.class))).thenReturn(LogHeader.LOG_HEADER_SIZE / 2);
when(fs.fileExists(logFile)).thenReturn(true);
when(fs.open(eq(logFile), anyString())).thenReturn(channel);
doThrow(IOException.class).when(channel).close();
// WHEN
try {
PhysicalLogFile.openForVersion(logFiles, fs, logVersion, false);
fail("Should have failed");
} catch (IncompleteLogHeaderException e) {
// THEN good
verify(channel).close();
assertEquals(1, e.getSuppressed().length);
assertTrue(e.getSuppressed()[0] instanceof IOException);
}
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class Runner method call.
@Override
public Long call() throws Exception {
long lastCommittedTransactionId;
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
Lifespan life = new Lifespan()) {
TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache(100_000);
LogHeaderCache logHeaderCache = new LogHeaderCache(1000);
LogFile logFile = life.add(createPhysicalLogFile(transactionIdStore, logHeaderCache, fileSystem));
TransactionAppender transactionAppender = life.add(createBatchingTransactionAppender(transactionIdStore, transactionMetadataCache, logFile));
ExecutorService executorService = Executors.newFixedThreadPool(threads);
try {
Future<?>[] handlers = new Future[threads];
for (int i = 0; i < threads; i++) {
TransactionRepresentationFactory factory = new TransactionRepresentationFactory();
Worker task = new Worker(transactionAppender, factory, condition);
handlers[i] = executorService.submit(task);
}
// wait for all the workers to complete
for (Future<?> handle : handlers) {
handle.get();
}
} finally {
executorService.shutdown();
}
lastCommittedTransactionId = transactionIdStore.getLastCommittedTransactionId();
}
return lastCommittedTransactionId;
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class LogPruneStrategyFactoryTest method testLogPruneThresholdsByType.
@Test
public void testLogPruneThresholdsByType() throws Exception {
FileSystemAbstraction fsa = Mockito.mock(FileSystemAbstraction.class);
assertThat(getThresholdByType(fsa, new ThresholdConfigValue("files", 25), ""), instanceOf(FileCountThreshold.class));
assertThat(getThresholdByType(fsa, new ThresholdConfigValue("size", 16000), ""), instanceOf(FileSizeThreshold.class));
assertThat(getThresholdByType(fsa, new ThresholdConfigValue("txs", 4000), ""), instanceOf(EntryCountThreshold.class));
assertThat(getThresholdByType(fsa, new ThresholdConfigValue("entries", 4000), ""), instanceOf(EntryCountThreshold.class));
assertThat(getThresholdByType(fsa, new ThresholdConfigValue("hours", 100), ""), instanceOf(EntryTimespanThreshold.class));
assertThat(getThresholdByType(fsa, new ThresholdConfigValue("days", 100_000), ""), instanceOf(EntryTimespanThreshold.class));
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class EnterpriseSecurityModule method setup.
@Override
public void setup(Dependencies dependencies) throws KernelException {
Config config = dependencies.config();
Procedures procedures = dependencies.procedures();
LogProvider logProvider = dependencies.logService().getUserLogProvider();
JobScheduler jobScheduler = dependencies.scheduler();
FileSystemAbstraction fileSystem = dependencies.fileSystem();
LifeSupport life = dependencies.lifeSupport();
SecurityLog securityLog = SecurityLog.create(config, dependencies.logService().getInternalLog(GraphDatabaseFacade.class), fileSystem, jobScheduler);
life.add(securityLog);
boolean allowTokenCreate = config.get(SecuritySettings.allow_publisher_create_token);
PredefinedRolesBuilder.setAllowPublisherTokenCreate(allowTokenCreate);
procedures.writerCreateToken(allowTokenCreate);
EnterpriseAuthAndUserManager authManager = newAuthManager(config, logProvider, securityLog, fileSystem, jobScheduler);
life.add(dependencies.dependencySatisfier().satisfyDependency(authManager));
// Register procedures
procedures.registerComponent(SecurityLog.class, (ctx) -> securityLog, false);
procedures.registerComponent(EnterpriseAuthManager.class, ctx -> authManager, false);
procedures.registerComponent(EnterpriseSecurityContext.class, ctx -> asEnterprise(ctx.get(SECURITY_CONTEXT)), true);
if (config.get(SecuritySettings.native_authentication_enabled) || config.get(SecuritySettings.native_authorization_enabled)) {
procedures.registerComponent(EnterpriseUserManager.class, ctx -> authManager.getUserManager(asEnterprise(ctx.get(SECURITY_CONTEXT))), true);
if (config.get(SecuritySettings.auth_providers).size() > 1) {
procedures.registerProcedure(UserManagementProcedures.class, true, Optional.of("%s only applies to native users."));
} else {
procedures.registerProcedure(UserManagementProcedures.class, true);
}
} else {
procedures.registerComponent(EnterpriseUserManager.class, ctx -> EnterpriseUserManager.NOOP, true);
}
procedures.registerProcedure(SecurityProcedures.class, true);
}
use of org.neo4j.io.fs.FileSystemAbstraction 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));
}
Aggregations