use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.
the class SecondaryUnitPrepareIdSequenceTest method shouldReturnIdImmediatelyAfterRecordIdOnlyOnce.
@Test
void shouldReturnIdImmediatelyAfterRecordIdOnlyOnce() {
// given
PrepareIdSequence idSequence = new SecondaryUnitPrepareIdSequence();
IdSequence actual = mock(IdSequence.class);
// when
long recordId = 10;
IdSequence prepared = idSequence.apply(actual).apply(recordId);
long nextRecordId = prepared.nextId(NULL);
assertEquals(10 + 1, nextRecordId);
verifyNoMoreInteractions(actual);
try {
prepared.nextId(NULL);
fail("Should've failed");
} catch (IllegalStateException e) {
// good
}
// and when
recordId = 20;
prepared = idSequence.apply(actual).apply(recordId);
nextRecordId = prepared.nextId(NULL);
// then
assertEquals(20 + 1, nextRecordId);
verifyNoMoreInteractions(actual);
}
use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.
the class SecondaryUnitPrepareIdSequenceTest method shouldReturnIdImmediatelyAfterRecordId.
@Test
void shouldReturnIdImmediatelyAfterRecordId() {
// given
PrepareIdSequence idSequence = new SecondaryUnitPrepareIdSequence();
IdSequence actual = mock(IdSequence.class);
// when
long recordId = 10;
IdSequence prepared = idSequence.apply(actual).apply(recordId);
long nextRecordId = prepared.nextId(NULL);
// then
assertEquals(10 + 1, nextRecordId);
verifyNoMoreInteractions(actual);
}
use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.
the class NodeRecordTest method shouldToStringBothUsedAndUnusedDynamicLabelRecords.
@Test
void shouldToStringBothUsedAndUnusedDynamicLabelRecords() {
// GIVEN
IdSequence ids = mock(IdSequence.class);
when(ids.nextId(NULL)).thenReturn(1L, 2L);
ReusableRecordsAllocator recordAllocator = new ReusableRecordsAllocator(30, new DynamicRecord(1), new DynamicRecord(2));
NodeRecord node = newUsedNodeRecord(0);
long labelId = 10_123;
// A dynamic label record
Collection<DynamicRecord> existing = allocateRecordsForDynamicLabels(node.getId(), new long[] { labelId }, recordAllocator, NULL, INSTANCE);
// and a deleted one as well (simulating some deleted labels)
DynamicRecord unused = newDeletedDynamicRecord(ids.nextId(NULL));
unused.setInUse(false);
existing.add(unused);
node.setLabelField(dynamicPointer(existing), existing);
// WHEN
String toString = node.toString();
// THEN
assertThat(toString).contains(String.valueOf(labelId));
assertThat(toString).contains(unused.toString());
}
use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.
the class UpdateRecordsStep method process.
@Override
protected void process(RECORD[] batch, BatchSender sender, CursorContext cursorContext) {
LongFunction<IdSequence> idSequence = prepareIdSequence.apply(store);
int recordsUpdatedInThisBatch = 0;
try (PageCursor cursor = store.openPageCursorForWriting(0, cursorContext)) {
for (RECORD record : batch) {
if (record != null && record.inUse() && !IdValidator.isReservedId(record.getId())) {
store.prepareForCommit(record, idSequence.apply(record.getId()), cursorContext);
// Don't update id generators because at the time of writing this they require special handling for multi-threaded updates
// instead just note the highId. It will be mostly correct in the end.
store.updateRecord(record, IGNORE, cursor, cursorContext);
recordsUpdatedInThisBatch++;
}
}
}
recordsUpdated.add(recordsUpdatedInThisBatch);
}
use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.
the class RelationshipModifierTest method setUp.
@BeforeEach
void setUp() {
RelationshipGroupGetter relationshipGroupGetter = new RelationshipGroupGetter(idSequence(), CursorContext.NULL);
PropertyDeleter propertyDeleter = new PropertyDeleter(new PropertyTraverser(CursorContext.NULL), null, null, NullLogProvider.nullLogProvider(), Config.defaults(), CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
modifier = new RelationshipModifier(relationshipGroupGetter, propertyDeleter, DENSE_THRESHOLD - 1, /*because the trigger happens on > */
true, CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
monitors = new Monitors(null, (t, m) -> {
Exceptions.throwIfUnchecked(t);
throw new RuntimeException(t);
});
locks = new TrackingResourceLocker(random, monitors.newMonitor(TrackingResourceLocker.LockAcquisitionMonitor.class));
txState = mock(ReadableTransactionState.class);
store = new MapRecordStore();
monitors.addMonitorListener(new LockVerificationMonitor(locks, txState, store));
groupUpdater = new GroupUpdater(store);
}
Aggregations