use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class HaIdGeneratorFactoryTest method shouldMoveFromDefraggedToRange.
@Test
public void shouldMoveFromDefraggedToRange() throws Exception {
// GIVEN
long[] defragIds = { 42, 27172828, 314159 };
IdAllocation firstResult = new IdAllocation(new IdRange(defragIds, 0, 10), 100, defragIds.length);
Response<IdAllocation> response = response(firstResult);
when(master.allocateIds(any(RequestContext.class), any(IdType.class))).thenReturn(response);
// WHEN
IdGenerator gen = switchToSlave();
// THEN
for (long defragId : defragIds) {
assertEquals(defragId, gen.nextId());
}
}
use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class HaIdGeneratorFactoryTest method slaveIdGeneratorShouldReturnFromAssignedRange.
@Test
public void slaveIdGeneratorShouldReturnFromAssignedRange() throws Exception {
// GIVEN
IdAllocation firstResult = new IdAllocation(new IdRange(new long[] {}, 42, 123), 123, 0);
Response<IdAllocation> response = response(firstResult);
when(master.allocateIds(any(RequestContext.class), any(IdType.class))).thenReturn(response);
// WHEN
IdGenerator gen = switchToSlave();
// THEN
for (long i = firstResult.getIdRange().getRangeStart(); i < firstResult.getIdRange().getRangeLength(); i++) {
assertEquals(i, gen.nextId());
}
verify(master, times(1)).allocateIds(any(RequestContext.class), eq(IdType.NODE));
}
use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class HaIdGeneratorFactoryTest method shouldNotUseForbiddenMinusOneIdFromIdBatches.
@Test
public void shouldNotUseForbiddenMinusOneIdFromIdBatches() throws Exception {
// GIVEN
long[] defragIds = { 3, 5 };
int size = 10;
long low = IdGeneratorImpl.INTEGER_MINUS_ONE - size / 2;
IdRange idRange = new IdRange(defragIds, low, size);
// WHEN
IdRangeIterator iterartor = new IdRangeIterator(idRange);
// THEN
for (long id : defragIds) {
assertEquals(id, iterartor.next());
}
// due to the forbidden id
int expectedRangeSize = size - 1;
for (long i = 0, expectedId = low; i < expectedRangeSize; i++, expectedId++) {
if (expectedId == IdGeneratorImpl.INTEGER_MINUS_ONE) {
expectedId++;
}
long id = iterartor.next();
assertNotEquals(IdGeneratorImpl.INTEGER_MINUS_ONE, id);
assertEquals(expectedId, id);
}
assertEquals(VALUE_REPRESENTING_NULL, iterartor.next());
}
use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class IdRangeIteratorTest method shouldReturnValueRepresentingNullIfWeExhaustIdRange.
@Test
public void shouldReturnValueRepresentingNullIfWeExhaustIdRange() throws Exception {
// given
int rangeLength = 1024;
IdRangeIterator iterator = new IdRangeIterator(new IdRange(new long[] {}, 0, rangeLength));
// when
for (int i = 0; i < rangeLength; i++) {
iterator.next();
}
// then
assertEquals(IdRangeIterator.VALUE_REPRESENTING_NULL, iterator.next());
}
use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class IdRangeIteratorTest method shouldUseDefragIdsFirst.
@Test
public void shouldUseDefragIdsFirst() throws Exception {
// given
int rangeLength = 1024;
IdRangeIterator iterator = new IdRangeIterator(new IdRange(new long[] { 7, 8, 9 }, 1024, rangeLength));
// then
assertEquals(7, iterator.next());
assertEquals(8, iterator.next());
assertEquals(9, iterator.next());
assertEquals(1024, iterator.next());
}
Aggregations