use of org.neo4j.kernel.impl.api.CountsVisitor in project neo4j by neo4j.
the class CountsRotationTest method allRecords.
private Collection<Pair<? extends CountsKey, Long>> allRecords(CountsVisitor.Visitable store) {
final Collection<Pair<? extends CountsKey, Long>> records = new ArrayList<>();
store.accept(new CountsVisitor() {
@Override
public void visitNodeCount(int labelId, long count) {
records.add(Pair.of(CountsKeyFactory.nodeKey(labelId), count));
}
@Override
public void visitRelationshipCount(int startLabelId, int typeId, int endLabelId, long count) {
records.add(Pair.of(CountsKeyFactory.relationshipKey(startLabelId, typeId, endLabelId), count));
}
@Override
public void visitIndexStatistics(long indexId, long updates, long size) {
records.add(Pair.of(CountsKeyFactory.indexStatisticsKey(indexId), size));
}
@Override
public void visitIndexSample(long indexId, long unique, long size) {
records.add(Pair.of(CountsKeyFactory.indexSampleKey(indexId), size));
}
});
return records;
}
use of org.neo4j.kernel.impl.api.CountsVisitor in project neo4j by neo4j.
the class CountsTrackerTest method shouldSupportTransactionsAppliedOutOfOrderOnRotation.
@Test
@Resources.Life(STARTED)
public void shouldSupportTransactionsAppliedOutOfOrderOnRotation() throws Exception {
// given
final CountsTracker tracker = resourceManager.managed(newTracker());
try (CountsAccessor.Updater tx = tracker.apply(2).get()) {
tx.incrementNodeCount(1, 1);
}
try (CountsAccessor.Updater tx = tracker.apply(4).get()) {
tx.incrementNodeCount(1, 1);
}
// when
Future<Long> rotated = threading.executeAndAwait(new Rotation(2), tracker, thread -> {
switch(thread.getState()) {
case BLOCKED:
case WAITING:
case TIMED_WAITING:
case TERMINATED:
return true;
default:
return false;
}
}, 10, SECONDS);
try (CountsAccessor.Updater tx = tracker.apply(5).get()) {
tx.incrementNodeCount(1, 1);
}
try (CountsAccessor.Updater tx = tracker.apply(3).get()) {
tx.incrementNodeCount(1, 1);
}
// then
assertEquals("rotated transaction", 4, rotated.get().longValue());
assertEquals("stored transaction", 4, tracker.txId());
// the value in memory
assertEquals("count", 4, tracker.nodeCount(1, Registers.newDoubleLongRegister()).readSecond());
// the value in the store
CountsVisitor visitor = mock(CountsVisitor.class);
tracker.visitFile(tracker.currentFile(), visitor);
verify(visitor).visitNodeCount(1, 3);
verifyNoMoreInteractions(visitor);
assertEquals("final rotation", 5, tracker.rotate(5));
}
use of org.neo4j.kernel.impl.api.CountsVisitor in project neo4j by neo4j.
the class CountsOracle method verify.
public <Tracker extends CountsVisitor.Visitable & CountsAccessor> void verify(final Tracker tracker) {
CountsRecordState seenState = new CountsRecordState();
final CountsAccessor.Initializer initializer = new CountsAccessor.Initializer(seenState, seenState);
List<CountsRecordState.Difference> differences = state.verify(new CountsVisitor.Visitable() {
@Override
public void accept(final CountsVisitor verifier) {
tracker.accept(CountsVisitor.Adapter.multiplex(initializer, verifier));
}
});
seenState.accept(new CountsVisitor() {
@Override
public void visitNodeCount(int labelId, long count) {
long expected = tracker.nodeCount(labelId, newDoubleLongRegister()).readSecond();
assertEquals("Should be able to read visited state.", expected, count);
}
@Override
public void visitRelationshipCount(int startLabelId, int typeId, int endLabelId, long count) {
long expected = tracker.relationshipCount(startLabelId, typeId, endLabelId, newDoubleLongRegister()).readSecond();
assertEquals("Should be able to read visited state.", expected, count);
}
@Override
public void visitIndexStatistics(long indexId, long updates, long size) {
Register.DoubleLongRegister output = tracker.indexUpdatesAndSize(indexId, newDoubleLongRegister());
assertEquals("Should be able to read visited state.", output.readFirst(), updates);
assertEquals("Should be able to read visited state.", output.readSecond(), size);
}
@Override
public void visitIndexSample(long indexId, long unique, long size) {
Register.DoubleLongRegister output = tracker.indexSample(indexId, newDoubleLongRegister());
assertEquals("Should be able to read visited state.", output.readFirst(), unique);
assertEquals("Should be able to read visited state.", output.readSecond(), size);
}
});
if (!differences.isEmpty()) {
StringBuilder errors = new StringBuilder().append("Counts differ in ").append(differences.size()).append(" places...");
for (CountsRecordState.Difference difference : differences) {
errors.append("\n\t").append(difference);
}
throw new AssertionError(errors.toString());
}
}
Aggregations