use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class CoreBootstrapperTest method shouldSetAllCoreState.
@Test
public void shouldSetAllCoreState() throws Exception {
// given
int nodeCount = 100;
FileSystemAbstraction fileSystem = fileSystemRule.get();
File classicNeo4jStore = RestoreClusterUtils.createClassicNeo4jStore(testDirectory.directory(), fileSystem, nodeCount, Standard.LATEST_NAME);
PageCache pageCache = pageCacheRule.getPageCache(fileSystem);
CoreBootstrapper bootstrapper = new CoreBootstrapper(classicNeo4jStore, pageCache, fileSystem, Config.defaults(), NullLogProvider.getInstance());
// when
Set<MemberId> membership = asSet(randomMember(), randomMember(), randomMember());
CoreSnapshot snapshot = bootstrapper.bootstrap(membership);
// then
assertEquals(nodeCount, ((IdAllocationState) snapshot.get(CoreStateType.ID_ALLOCATION)).firstUnallocated(IdType.NODE));
/* Bootstrapped state is created in RAFT land at index -1 and term -1. */
assertEquals(0, snapshot.prevIndex());
assertEquals(0, snapshot.prevTerm());
/* Lock is initially not taken. */
assertEquals(new ReplicatedLockTokenState(), snapshot.get(CoreStateType.LOCK_TOKEN));
/* Raft has the bootstrapped set of members initially. */
assertEquals(membership, ((RaftCoreState) snapshot.get(CoreStateType.RAFT_CORE_STATE)).committed().members());
/* The session state is initially empty. */
assertEquals(new GlobalSessionTrackerState(), snapshot.get(CoreStateType.SESSION_TRACKER));
LastCommittedIndexFinder lastCommittedIndexFinder = new LastCommittedIndexFinder(new ReadOnlyTransactionIdStore(pageCache, classicNeo4jStore), new ReadOnlyTransactionStore(pageCache, fileSystem, classicNeo4jStore, new Monitors()), NullLogProvider.getInstance());
long lastCommittedIndex = lastCommittedIndexFinder.getLastCommittedIndex();
assertEquals(-1, lastCommittedIndex);
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class ResponsePackerIT method shouldPackTheHighestTxCommittedAsObligation.
@Test
public void shouldPackTheHighestTxCommittedAsObligation() throws Exception {
// GIVEN
LogicalTransactionStore transactionStore = mock(LogicalTransactionStore.class);
FileSystemAbstraction fs = fsRule.get();
PageCache pageCache = pageCacheRule.getPageCache(fs);
try (NeoStores neoStore = createNeoStore(fs, pageCache)) {
MetaDataStore store = neoStore.getMetaDataStore();
store.transactionCommitted(2, 111, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(3, 222, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(4, 333, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(5, 444, BASE_TX_COMMIT_TIMESTAMP);
store.transactionCommitted(6, 555, BASE_TX_COMMIT_TIMESTAMP);
// skip 7 to emulate the fact we have an hole in the committed tx ids list
final long expectedTxId = 8L;
store.transactionCommitted(expectedTxId, 777, BASE_TX_COMMIT_TIMESTAMP);
ResponsePacker packer = new ResponsePacker(transactionStore, store, Suppliers.singleton(newStoreIdForCurrentVersion()));
// WHEN
Response<Object> response = packer.packTransactionObligationResponse(new RequestContext(0, 0, 0, 0, 0), new Object());
// THEN
assertTrue(response instanceof TransactionObligationResponse);
((TransactionObligationResponse) response).accept(new Response.Handler() {
@Override
public void obligation(long txId) throws IOException {
assertEquals(expectedTxId, txId);
}
@Override
public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
throw new UnsupportedOperationException("not expected");
}
});
}
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class SecurityLogTest method shouldRotateLog.
@Test
public void shouldRotateLog() throws IOException {
SecurityLog securityLog = new SecurityLog(config, fileSystemRule.get(), Runnable::run);
securityLog.info("line 1");
securityLog.info("line 2");
FileSystemAbstraction fs = fileSystemRule.get();
File activeLogFile = config.get(SecuritySettings.security_log_filename);
assertThat(fs.fileExists(activeLogFile), equalTo(true));
assertThat(fs.fileExists(archive(1)), equalTo(true));
assertThat(fs.fileExists(archive(2)), equalTo(false));
String[] activeLines = readLogFile(fs, activeLogFile);
assertThat(activeLines, array(containsString("line 2")));
String[] archiveLines = readLogFile(fs, archive(1));
assertThat(archiveLines, array(containsString("line 1")));
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class RestoreDatabaseCommandTest method forceShouldRespectStoreLock.
@Test
public void forceShouldRespectStoreLock() throws Exception {
String databaseName = "to";
Config config = configWith(Config.empty(), databaseName, directory.absolutePath().getAbsolutePath());
File fromPath = new File(directory.absolutePath(), "from");
File toPath = config.get(DatabaseManagementSystemSettings.database_path);
int fromNodeCount = 10;
int toNodeCount = 20;
createDbAt(fromPath, fromNodeCount);
createDbAt(toPath, toNodeCount);
FileSystemAbstraction fs = fileSystemRule.get();
try (StoreLocker storeLocker = new StoreLocker(fs)) {
storeLocker.checkLock(toPath);
new RestoreDatabaseCommand(fs, fromPath, config, databaseName, true).execute();
fail("expected exception");
} catch (Exception e) {
assertThat(e.getMessage(), equalTo("the database is in use -- stop Neo4j and try again"));
}
}
use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.
the class StoreMigrationIT method shouldMigrate.
@Test
public void shouldMigrate() throws Exception {
File db = testDir.directory(baseDirName(to, from));
FileSystemAbstraction fs = fileSystemRule.get();
fs.deleteRecursively(db);
GraphDatabaseService database = getGraphDatabaseService(db, from.storeVersion());
database.execute("CREATE INDEX ON :Person(name)");
database.execute("CREATE INDEX ON :Person(born)");
database.execute("CREATE CONSTRAINT ON (person:Person) ASSERT exists(person.name)");
database.execute(CREATE_QUERY);
long beforeNodes;
long beforeLabels;
long beforeKeys;
long beforeRels;
long beforeRelTypes;
long beforeIndexes;
long beforeConstraints;
try (Transaction ignore = database.beginTx()) {
beforeNodes = database.getAllNodes().stream().count();
beforeLabels = database.getAllLabels().stream().count();
beforeKeys = database.getAllPropertyKeys().stream().count();
beforeRels = database.getAllRelationships().stream().count();
beforeRelTypes = database.getAllRelationshipTypes().stream().count();
beforeIndexes = stream(database.schema().getIndexes()).count();
beforeConstraints = stream(database.schema().getConstraints()).count();
}
database.shutdown();
database = getGraphDatabaseService(db, to.storeVersion());
long afterNodes;
long afterLabels;
long afterKeys;
long afterRels;
long afterRelTypes;
long afterIndexes;
long afterConstraints;
try (Transaction ignore = database.beginTx()) {
afterNodes = database.getAllNodes().stream().count();
afterLabels = database.getAllLabels().stream().count();
afterKeys = database.getAllPropertyKeys().stream().count();
afterRels = database.getAllRelationships().stream().count();
afterRelTypes = database.getAllRelationshipTypes().stream().count();
afterIndexes = stream(database.schema().getIndexes()).count();
afterConstraints = stream(database.schema().getConstraints()).count();
}
database.shutdown();
//171
assertEquals(beforeNodes, afterNodes);
//2
assertEquals(beforeLabels, afterLabels);
//8
assertEquals(beforeKeys, afterKeys);
//253
assertEquals(beforeRels, afterRels);
//6
assertEquals(beforeRelTypes, afterRelTypes);
//2
assertEquals(beforeIndexes, afterIndexes);
//1
assertEquals(beforeConstraints, afterConstraints);
ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();
ConsistencyCheckService.Result result = runConsistencyChecker(db, fs, consistencyCheckService, to.storeVersion());
if (!result.isSuccessful()) {
fail("Database is inconsistent after migration.");
}
}
Aggregations