use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class LabelsAcceptanceTest method beansAPIWithNoMoreLabelIds.
@SuppressWarnings("deprecation")
private GraphDatabaseService beansAPIWithNoMoreLabelIds() {
final EphemeralIdGenerator.Factory idFactory = new EphemeralIdGenerator.Factory() {
private IdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
@Override
public IdGenerator open(File fileName, int grabSize, IdType idType, long highId, long maxId) {
if (idType == IdType.LABEL_TOKEN) {
IdGenerator generator = generators.get(idType);
if (generator == null) {
IdTypeConfiguration idTypeConfiguration = idTypeConfigurationProvider.getIdTypeConfiguration(idType);
generator = new EphemeralIdGenerator(idType, idTypeConfiguration) {
@Override
public long nextId() {
// Same exception as the one thrown by IdGeneratorImpl
throw new UnderlyingStorageException("Id capacity exceeded");
}
};
generators.put(idType, generator);
}
return generator;
}
return super.open(fileName, grabSize, idType, Long.MAX_VALUE, Long.MAX_VALUE);
}
};
TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory() {
@Override
protected GraphDatabaseBuilder.DatabaseCreator createImpermanentDatabaseCreator(final File storeDir, final TestGraphDatabaseFactoryState state) {
return new GraphDatabaseBuilder.DatabaseCreator() {
@Override
public GraphDatabaseService newDatabase(Map<String, String> config) {
return newDatabase(Config.embeddedDefaults(config));
}
@Override
public GraphDatabaseService newDatabase(@Nonnull Config config) {
return new ImpermanentGraphDatabase(storeDir, config, GraphDatabaseDependencies.newDependencies(state.databaseDependencies())) {
@Override
protected void create(File storeDir, Config config, GraphDatabaseFacadeFactory.Dependencies dependencies) {
Function<PlatformModule, EditionModule> factory = (platformModule) -> new CommunityEditionModule(platformModule) {
@Override
protected IdGeneratorFactory createIdGeneratorFactory(FileSystemAbstraction fs, IdTypeConfigurationProvider idTypeConfigurationProvider) {
return idFactory;
}
};
new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, factory) {
@Override
protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
return new ImpermanentPlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade);
}
}.initFacade(storeDir, config, dependencies, this);
}
};
}
};
}
};
return dbFactory.newImpermanentDatabase();
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class NeoStoreDataSourceTest method shouldAlwaysShutdownLifeEvenWhenCheckPointingFails.
@Test
public void shouldAlwaysShutdownLifeEvenWhenCheckPointingFails() throws Exception {
// Given
File storeDir = dir.graphDbDir();
FileSystemAbstraction fs = this.fs.get();
PageCache pageCache = pageCacheRule.getPageCache(fs);
DatabaseHealth databaseHealth = mock(DatabaseHealth.class);
when(databaseHealth.isHealthy()).thenReturn(true);
IOException ex = new IOException("boom!");
doThrow(ex).when(databaseHealth).assertHealthy(// <- this is a trick to simulate a failure during checkpointing
IOException.class);
NeoStoreDataSource dataSource = dsRule.getDataSource(storeDir, fs, pageCache, emptyMap(), databaseHealth);
dataSource.start();
try {
// When
dataSource.stop();
fail("it should have thrown");
} catch (LifecycleException e) {
// Then
assertEquals(ex, e.getCause());
}
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class TestIndexProviderStore method shouldThrowWhenTryingToCreateFileThatAlreadyExists.
@Test(expected = IllegalArgumentException.class)
public void shouldThrowWhenTryingToCreateFileThatAlreadyExists() {
// Given
FileSystemAbstraction fs = mock(FileSystemAbstraction.class);
when(fs.fileExists(file)).thenReturn(false).thenReturn(true);
when(fs.getFileSize(file)).thenReturn(42L);
// When
new IndexProviderStore(file, fs, MetaDataStore.versionStringToLong("3.5"), false);
// Then
// exception is thrown
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class LegacyLogsTest method transactionInformationRetrievedFromCommitEntries.
@Test
@SuppressWarnings("unchecked")
public void transactionInformationRetrievedFromCommitEntries() throws IOException {
FileSystemAbstraction fs = mock(FileSystemAbstraction.class);
File logFile = new File(LegacyLogFilenames.getLegacyLogFilename(1));
when(fs.listFiles(any(File.class), any(FilenameFilter.class))).thenReturn(new File[] { logFile });
LegacyLogEntryReader reader = mock(LegacyLogEntryReader.class);
LogEntry[] entries = new LogEntry[] { start(1), createNode(1), createNode(2), commit(1), start(2), createNode(3), createNode(4), commit(2), start(3), createNode(5), commit(3) };
when(reader.openReadableChannel(any(File.class))).thenReturn(readableChannel(entries), readableChannel(entries), readableChannel(entries));
LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs);
LegacyLogs legacyLogs = new LegacyLogs(fs, reader, writer);
assertEquals(newTransactionId(1), getTransactionInformation(legacyLogs, 1));
assertEquals(newTransactionId(2), getTransactionInformation(legacyLogs, 2));
assertEquals(newTransactionId(3), getTransactionInformation(legacyLogs, 3));
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class PartialTransactionFailureIT method concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction.
@Test
public void concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction() throws Exception {
final ClassGuardedAdversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, false), Command.RelationshipCommand.class);
adversary.disable();
File storeDir = dir.graphDbDir();
final Map<String, String> params = stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8m");
final EmbeddedGraphDatabase db = new TestEmbeddedGraphDatabase(storeDir, params) {
@Override
protected void create(File storeDir, Map<String, String> params, GraphDatabaseFacadeFactory.Dependencies dependencies) {
new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, CommunityEditionModule::new) {
@Override
protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
return new PlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade) {
@Override
protected FileSystemAbstraction createFileSystemAbstraction() {
return new AdversarialFileSystemAbstraction(adversary);
}
};
}
}.initFacade(storeDir, params, dependencies, this);
}
};
Node a, b, c, d;
try (Transaction tx = db.beginTx()) {
a = db.createNode();
b = db.createNode();
c = db.createNode();
d = db.createNode();
tx.success();
}
adversary.enable();
CountDownLatch latch = new CountDownLatch(1);
Thread t1 = new Thread(createRelationship(db, a, b, latch), "T1");
Thread t2 = new Thread(createRelationship(db, c, d, latch), "T2");
t1.start();
t2.start();
// Wait for both threads to get going
t1.join(10);
t2.join(10);
latch.countDown();
// Wait for the transactions to finish
t1.join(25000);
t2.join(25000);
db.shutdown();
// We should observe the store in a consistent state
EmbeddedGraphDatabase db2 = new TestEmbeddedGraphDatabase(storeDir, params);
try (Transaction tx = db2.beginTx()) {
Node x = db2.getNodeById(a.getId());
Node y = db2.getNodeById(b.getId());
Node z = db2.getNodeById(c.getId());
Node w = db2.getNodeById(d.getId());
Iterator<Relationship> itrRelX = x.getRelationships().iterator();
Iterator<Relationship> itrRelY = y.getRelationships().iterator();
Iterator<Relationship> itrRelZ = z.getRelationships().iterator();
Iterator<Relationship> itrRelW = w.getRelationships().iterator();
if (itrRelX.hasNext() != itrRelY.hasNext()) {
fail("Node x and y have inconsistent relationship counts");
} else if (itrRelX.hasNext()) {
Relationship rel = itrRelX.next();
assertEquals(rel, itrRelY.next());
assertFalse(itrRelX.hasNext());
assertFalse(itrRelY.hasNext());
}
if (itrRelZ.hasNext() != itrRelW.hasNext()) {
fail("Node z and w have inconsistent relationship counts");
} else if (itrRelZ.hasNext()) {
Relationship rel = itrRelZ.next();
assertEquals(rel, itrRelW.next());
assertFalse(itrRelZ.hasNext());
assertFalse(itrRelW.hasNext());
}
} finally {
db2.shutdown();
}
}
Aggregations