use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.
the class IdGeneratorTest method testRandomTest.
@Test
public void testRandomTest() {
java.util.Random random = new java.util.Random(System.currentTimeMillis());
int capacity = random.nextInt(1024) + 1024;
int grabSize = random.nextInt(128) + 128;
IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
IdGenerator idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), grabSize, capacity * 2, false, 0);
List<Long> idsTaken = new ArrayList<>();
float releaseIndex = 0.25f;
float closeIndex = 0.05f;
int currentIdCount = 0;
try {
while (currentIdCount < capacity) {
float rIndex = random.nextFloat();
if (rIndex < releaseIndex && currentIdCount > 0) {
idGenerator.freeId(idsTaken.remove(random.nextInt(currentIdCount)).intValue());
currentIdCount--;
} else {
idsTaken.add(idGenerator.nextId());
currentIdCount++;
}
if (rIndex > (1.0f - closeIndex) || rIndex < closeIndex) {
closeIdGenerator(idGenerator);
grabSize = random.nextInt(128) + 128;
idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), grabSize, capacity * 2, false, 0);
}
}
closeIdGenerator(idGenerator);
} 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 makeSureIdCapacityCannotBeExceeded.
private void makeSureIdCapacityCannotBeExceeded(RecordFormat format) {
deleteIdGeneratorFile();
IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
long maxValue = format.getMaxId();
IdGenerator idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), 1, maxValue - 1, false, 0);
long id = maxValue - 2;
idGenerator.setHighId(id);
assertEquals(id, idGenerator.nextId());
assertEquals(id + 1, idGenerator.nextId());
try {
idGenerator.nextId();
fail("Id capacity shouldn't be able to be exceeded for " + format);
} catch (StoreFailureException e) {
// Good
}
closeIdGenerator(idGenerator);
}
use of org.neo4j.kernel.impl.store.id.IdGeneratorImpl in project neo4j by neo4j.
the class IdGeneratorTest method testChurnIdBatchAtGrabSize.
@Test
public void testChurnIdBatchAtGrabSize() {
IdGenerator idGenerator = null;
try {
IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
final int grabSize = 10, rounds = 10;
idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), grabSize, 1000, true, 0);
for (int i = 0; i < rounds; i++) {
Set<Long> ids = new HashSet<>();
for (int j = 0; j < grabSize; j++) {
ids.add(idGenerator.nextId());
}
for (Long id : ids) {
idGenerator.freeId(id);
}
}
long newId = idGenerator.nextId();
assertTrue("Expected IDs to be reused (" + grabSize + " at a time). high ID was: " + newId, newId < grabSize * rounds);
} finally {
if (idGenerator != null) {
closeIdGenerator(idGenerator);
}
File file = idGeneratorFile();
if (file.exists()) {
assertTrue(file.delete());
}
}
}
Aggregations