use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.
the class ReplicatedIdGeneratorFactory method openGenerator.
private IdGenerator openGenerator(File fileName, int grabSize, IdType idType, long highId, long maxId, boolean aggressiveReuse) {
SwitchableRaftIdGenerator previous = generators.remove(idType);
if (previous != null) {
previous.close();
}
IdGenerator initialIdGenerator = new IdGeneratorImpl(fs, fileName, grabSize, maxId, aggressiveReuse, highId);
SwitchableRaftIdGenerator switchableIdGenerator = new SwitchableRaftIdGenerator(initialIdGenerator, idType, idRangeAcquirer, logProvider);
if (replicatedMode) {
switchableIdGenerator.switchToRaft();
}
generators.put(idType, switchableIdGenerator);
return switchableIdGenerator;
}
use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.
the class IdGeneratorTest method grabSizeCannotBeZero.
@Test(expected = IllegalArgumentException.class)
public void grabSizeCannotBeZero() throws Exception {
IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
new IdGeneratorImpl(fs, idGeneratorFile(), 0, 100, false, 0).close();
}
use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.
the class IdGeneratorTest method testClose.
@Test
public void testClose() {
try {
IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
IdGenerator idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 2, 1000, false, 0);
closeIdGenerator(idGenerator);
try {
idGenerator.nextId();
fail("nextId after close should throw exception");
} catch (IllegalStateException e) {
// good
}
try {
idGenerator.freeId(0);
fail("freeId after close should throw exception");
} catch (IllegalStateException e) {
// good
}
idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 2, 1000, false, 0);
assertEquals(0L, idGenerator.nextId());
assertEquals(1L, idGenerator.nextId());
assertEquals(2L, idGenerator.nextId());
closeIdGenerator(idGenerator);
try {
idGenerator.nextId();
fail("nextId after close should throw exception");
} catch (IllegalStateException e) {
// good
}
try {
idGenerator.freeId(0);
fail("freeId after close should throw exception");
} catch (IllegalStateException e) {
// good
}
} finally {
File file = idGeneratorFile();
if (file.exists()) {
assertTrue(file.delete());
}
}
}
use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.
the class IdGeneratorTest method makeSureMagicMinusOneIsSkipped.
private void makeSureMagicMinusOneIsSkipped(RecordFormat format) {
deleteIdGeneratorFile();
IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
IdGenerator idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 1, format.getMaxId(), false, 0);
long id = (long) Math.pow(2, 32) - 3;
idGenerator.setHighId(id);
assertEquals(id, idGenerator.nextId());
assertEquals(id + 1, idGenerator.nextId());
// Here we make sure that id+2 (integer -1) is skipped
assertEquals(id + 3, idGenerator.nextId());
assertEquals(id + 4, idGenerator.nextId());
assertEquals(id + 5, idGenerator.nextId());
closeIdGenerator(idGenerator);
}
use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.
the class IdGeneratorTest method delete.
@Test
public void delete() throws Exception {
IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
IdGeneratorImpl idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 10, 1000, false, 0);
long id = idGenerator.nextId();
idGenerator.nextId();
idGenerator.freeId(id);
idGenerator.close();
idGenerator.delete();
assertFalse(idGeneratorFile().exists());
IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 10, 1000, false, 0);
assertEquals(id, idGenerator.nextId());
idGenerator.close();
}
Aggregations