use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.
the class IndexedIdGeneratorRecoverabilityTest method simpleCrashTest.
@Test
void simpleCrashTest() throws Exception {
final EphemeralFileSystemAbstraction snapshot;
final long id1;
final long id2;
try (IdGenerator freelist = instantiateFreelist()) {
id1 = freelist.nextId(NULL);
id2 = freelist.nextId(NULL);
markUsed(freelist, id1, id2);
freelist.checkpoint(NULL);
markDeleted(freelist, id1, id2);
pageCache.flushAndForce();
snapshot = fs.snapshot();
}
try (PageCache newPageCache = getPageCache(snapshot);
IdGenerator freelist = instantiateFreelist()) {
markDeleted(freelist, id1, id2);
// Recovery is completed ^^^
freelist.start(NO_FREE_IDS, NULL);
markFree(freelist, id1, id2);
final ImmutableLongSet reused = LongSets.immutable.of(freelist.nextId(NULL), freelist.nextId(NULL));
assertEquals(LongSets.immutable.of(id1, id2), reused, "IDs are not reused");
} finally {
snapshot.close();
}
}
use of org.neo4j.internal.id.IdGenerator in project neo4j by neo4j.
the class IdGeneratorMigratorTest method assertIdGeneratorContainsIds.
private void assertIdGeneratorContainsIds(Path idFilePath, IdType idType, int rounds, int numDeleted, int numCreated, long startingId) throws IOException {
try (IdGenerator idGenerator = new IndexedIdGenerator(pageCache, idFilePath, immediate(), idType, false, () -> -1, Long.MAX_VALUE, writable(), Config.defaults(), DEFAULT_DATABASE_NAME, CursorContext.NULL)) {
idGenerator.start(ignored -> {
throw new RuntimeException("Should not ask for free ids");
}, CursorContext.NULL);
long nextExpectedId = startingId;
for (int i = 0; i < rounds; i++) {
for (int d = 0; d < numDeleted; d++) {
assertEquals(nextExpectedId++, idGenerator.nextId(CursorContext.NULL));
}
nextExpectedId += numCreated;
}
}
}
Aggregations