Search in sources :

Example 6 with IdRange

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());
    }
}
Also used : RequestContext(org.neo4j.com.RequestContext) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) IdRange(org.neo4j.kernel.impl.store.id.IdRange) IdType(org.neo4j.kernel.impl.store.id.IdType) Test(org.junit.Test)

Example 7 with IdRange

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));
}
Also used : RequestContext(org.neo4j.com.RequestContext) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) IdRange(org.neo4j.kernel.impl.store.id.IdRange) IdType(org.neo4j.kernel.impl.store.id.IdType) Test(org.junit.Test)

Example 8 with IdRange

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());
}
Also used : IdRange(org.neo4j.kernel.impl.store.id.IdRange) Test(org.junit.Test)

Example 9 with IdRange

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());
}
Also used : IdRange(org.neo4j.kernel.impl.store.id.IdRange) Test(org.junit.Test)

Example 10 with IdRange

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());
}
Also used : IdRange(org.neo4j.kernel.impl.store.id.IdRange) Test(org.junit.Test)

Aggregations

IdRange (org.neo4j.kernel.impl.store.id.IdRange)14 Test (org.junit.Test)12 RequestContext (org.neo4j.com.RequestContext)5 IdGenerator (org.neo4j.kernel.impl.store.id.IdGenerator)5 IdType (org.neo4j.kernel.impl.store.id.IdType)5 HashSet (java.util.HashSet)2 IdAllocation (org.neo4j.kernel.ha.id.IdAllocation)1