shvachko commented on a change in pull request #3197: URL: https://github.com/apache/hadoop/pull/3197#discussion_r669894193
########## File path: hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestPartitionedGSet.java ########## @@ -0,0 +1,234 @@ +/** + * 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.hadoop.util; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.Random; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.hadoop.util.LightWeightGSet.LinkedElement; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** Testing {@link PartitionedGSet} */ +public class TestPartitionedGSet { + public static final Logger LOG = + LoggerFactory.getLogger(TestPartitionedGSet.class); + private static final int ELEMENT_NUM = 100; + + /** + * Generate positive random numbers for testing. We want to use only positive numbers because the smallest Review comment: Long line. Should be 80 symbols ########## File path: hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestPartitionedGSet.java ########## @@ -0,0 +1,234 @@ +/** + * 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.hadoop.util; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.Random; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.hadoop.util.LightWeightGSet.LinkedElement; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** Testing {@link PartitionedGSet} */ +public class TestPartitionedGSet { + public static final Logger LOG = + LoggerFactory.getLogger(TestPartitionedGSet.class); + private static final int ELEMENT_NUM = 100; + + /** + * Generate positive random numbers for testing. We want to use only positive numbers because the smallest + * partition used in testing is 0. + * + * @param length + * number of random numbers to be generated. + * + * @param randomSeed + * seed to be used for random number generator. + * + * @return + * An array of Integers + */ + private static ArrayList<Integer> getRandomList(int length, int randomSeed) { + Random random = new Random(randomSeed); + ArrayList<Integer> list = new ArrayList<Integer>(length); + for (int i = 0; i < length; i++) { + list.add(random.nextInt(Integer.MAX_VALUE)); + } + return list; + } + + private static class TestElement implements LinkedElement { + private final int val; + private LinkedElement next; + + TestElement(int val) { + this.val = val; + this.next = null; + } + + public int getVal() { + return val; + } + + @Override + public void setNext(LinkedElement next) { + this.next = next; + } + + @Override + public LinkedElement getNext() { + return next; + } + } + + private static class TestElementComparator implements Comparator<TestElement> { Review comment: Long line. Should be 80 symbols. Please check the rest of the code for long lines. ########## File path: hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/PartitionedGSet.java ########## @@ -280,12 +279,22 @@ private void printStats() { public EntryIterator() { keyIterator = partitions.keySet().iterator(); - K curKey = partitions.firstKey(); - partitionIterator = getPartition(curKey).iterator(); + + if (!keyIterator.hasNext()) { + partitionIterator = null; + return; + } + + K firstKey = keyIterator.next(); + partitionIterator = partitions.get(firstKey).iterator(); } @Override public boolean hasNext() { + + if (partitionIterator == null) Review comment: So if somebody adds a partition after `EntryIterator()` for the empty `PartitionedGSet` was created, it will never be picked up. Should we try to set `partitionIterator` if it is null. ########## File path: hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestPartitionedGSet.java ########## @@ -0,0 +1,234 @@ +/** + * 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.hadoop.util; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.Random; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.hadoop.util.LightWeightGSet.LinkedElement; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + Review comment: Remove blank line. Don't need 2. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
