Github user joshelser commented on a diff in the pull request: https://github.com/apache/accumulo/pull/260#discussion_r119116912 --- Diff: test/src/main/java/org/apache/accumulo/test/functional/YieldingIterator.java --- @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.test.functional; + +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.accumulo.core.data.ByteSequence; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.iterators.IteratorEnvironment; +import org.apache.accumulo.core.iterators.SortedKeyValueIterator; +import org.apache.accumulo.core.iterators.WrappingIterator; +import org.apache.accumulo.core.iterators.user.ScanYieldException; + +import java.io.IOException; +import java.util.Collection; +import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This iterator will throw a ScanYieldException every other key + */ +public class YieldingIterator extends WrappingIterator { + private static final Logger log = LoggerFactory.getLogger(YieldingIterator.class); + private static final AtomicInteger yieldNexts = new AtomicInteger(0); + private static final AtomicInteger yieldSeeks = new AtomicInteger(0); + private static final AtomicInteger rebuilds = new AtomicInteger(0); + + private static final AtomicBoolean yieldNextKey = new AtomicBoolean(false); + private static final AtomicBoolean yieldSeekKey = new AtomicBoolean(false); + + @Override + public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) { + YieldingIterator it = new YieldingIterator(); + it.setSource(it.getSource().deepCopy(env)); + return it; + } + + @Override + public void next() throws IOException { + log.info("start YieldingIterator.next: " + getTopValue()); + yieldNextKey.set(!yieldNextKey.get()); + if (yieldNextKey.get()) { + log.info("YieldingIterator.next yielding: " + getTopValue()); + yieldNexts.incrementAndGet(); + throw new ScanYieldException(getTopKey()); + } + super.next(); + log.info("end YieldingIterator.next: " + (hasTop() ? getTopKey() + " " + getTopValue() : "no top")); + } + + @Override + public Value getTopValue() { + String value = Integer.toString(yieldNexts.get()) + ',' + Integer.toString(yieldSeeks.get()) + ',' + Integer.toString(rebuilds.get()); --- End diff -- Tricky :) Could you add a quick sentence to the class-level javadoc describing this? Would help when the next person comes along to this Iterator.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---