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());
}
use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class IdRangeIteratorTest method shouldNotHaveAnyGaps.
@Test
public void shouldNotHaveAnyGaps() throws Exception {
// given
int rangeLength = 1024;
IdRangeIterator iterator = new IdRangeIterator(new IdRange(new long[] {}, 0, rangeLength));
// when
Set<Long> seenIds = new HashSet<>();
for (int i = 0; i < rangeLength; i++) {
seenIds.add(iterator.next());
if (i > 0) {
// then
assertTrue("Missing id " + (i - 1), seenIds.contains((long) i - 1));
}
}
}
use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class HaIdGeneratorFactoryTest method slaveShouldNeverAllowReducingHighId.
@Test
public void slaveShouldNeverAllowReducingHighId() throws Exception {
// GIVEN
final int highIdFromAllocation = 123;
IdAllocation firstResult = new IdAllocation(new IdRange(new long[] {}, 42, highIdFromAllocation), highIdFromAllocation, 0);
Response<IdAllocation> response = response(firstResult);
when(master.allocateIds(any(RequestContext.class), any(IdType.class))).thenReturn(response);
// WHEN
IdGenerator gen = switchToSlave();
final int highIdFromUpdatedRecord = highIdFromAllocation + 1;
// Assume this is from a received transaction
gen.setHighId(highIdFromUpdatedRecord);
// that will ask the master for an IdRange
gen.nextId();
// THEN
assertEquals(highIdFromUpdatedRecord, gen.getHighId());
}
use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class HaIdGeneratorFactoryTest method shouldUseDefraggedIfPresent.
@Test
public void shouldUseDefraggedIfPresent() throws Exception {
// GIVEN
long[] defragIds = { 42, 27172828, 314159 };
IdAllocation firstResult = new IdAllocation(new IdRange(defragIds, 0, 0), 0, 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 slaveIdGeneratorShouldAskForMoreWhenRangeIsOver.
@Test
public void slaveIdGeneratorShouldAskForMoreWhenRangeIsOver() throws Exception {
// GIVEN
IdAllocation firstResult = new IdAllocation(new IdRange(new long[] {}, 42, 123), 42 + 123, 0);
IdAllocation secondResult = new IdAllocation(new IdRange(new long[] {}, 1042, 223), 1042 + 223, 0);
Response<IdAllocation> response = response(firstResult, secondResult);
when(master.allocateIds(any(RequestContext.class), any(IdType.class))).thenReturn(response);
// WHEN
IdGenerator gen = switchToSlave();
// THEN
long startAt = firstResult.getIdRange().getRangeStart();
long forThatMany = firstResult.getIdRange().getRangeLength();
for (long i = startAt; i < startAt + forThatMany; i++) {
assertEquals(i, gen.nextId());
}
verify(master, times(1)).allocateIds(any(RequestContext.class), eq(IdType.NODE));
startAt = secondResult.getIdRange().getRangeStart();
forThatMany = secondResult.getIdRange().getRangeLength();
for (long i = startAt; i < startAt + forThatMany; i++) {
assertEquals(i, gen.nextId());
}
verify(master, times(2)).allocateIds(any(RequestContext.class), eq(IdType.NODE));
}
Aggregations