Search in sources :

Example 1 with NodeStoreScan

use of org.neo4j.kernel.impl.transaction.state.storeview.NodeStoreScan in project neo4j by neo4j.

the class NodeStoreScanTest method shouldGiveBackCompletionPercentage.

@Test
public void shouldGiveBackCompletionPercentage() throws Throwable {
    // given
    final int total = 10;
    when(nodeStore.getHighId()).thenReturn((long) total);
    NodeRecord inUseRecord = new NodeRecord(42);
    inUseRecord.setInUse(true);
    when(nodeStore.getRecord(anyLong(), any(NodeRecord.class), any(RecordLoad.class))).thenReturn(inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord);
    final PercentageSupplier percentageSupplier = new PercentageSupplier();
    final NodeStoreScan scan = new NodeStoreScan(nodeStore, locks, total) {

        private int read = 0;

        @Override
        public void acceptUpdate(MultipleIndexPopulator.MultipleIndexUpdater updater, IndexEntryUpdate update, long currentlyIndexedNodeId) {
        // no-op
        }

        @Override
        public void configure(List list) {
        // no-op
        }

        @Override
        public void process(NodeRecord node) {
            // then
            read++;
            float expected = (float) read / total;
            float actual = percentageSupplier.get();
            assertEquals(String.format("%f==%f", expected, actual), expected, actual, 0.0);
        }
    };
    percentageSupplier.setStoreScan(scan);
    // when
    scan.run();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStoreScan(org.neo4j.kernel.impl.transaction.state.storeview.NodeStoreScan) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) List(java.util.List) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) Test(org.junit.Test)

Aggregations

List (java.util.List)1 Test (org.junit.Test)1 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)1 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)1 RecordLoad (org.neo4j.kernel.impl.store.record.RecordLoad)1 NodeStoreScan (org.neo4j.kernel.impl.transaction.state.storeview.NodeStoreScan)1