Repository: cassandra Updated Branches: refs/heads/trunk 9510eb0f3 -> 178d7b6f8
Fix Accumulator.isEmpty method patch by slebresne; reviewed by benedict for CASSANDRA-7873 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/178d7b6f Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/178d7b6f Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/178d7b6f Branch: refs/heads/trunk Commit: 178d7b6f8837e8f5cdd5f9c4661f3a3c3a0c4c0a Parents: 9510eb0 Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Tue Dec 9 20:08:38 2014 +0100 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Tue Dec 9 20:08:38 2014 +0100 ---------------------------------------------------------------------- .../cassandra/utils/concurrent/Accumulator.java | 2 +- .../utils/concurrent/AccumulatorTest.java | 106 +++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/178d7b6f/src/java/org/apache/cassandra/utils/concurrent/Accumulator.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/concurrent/Accumulator.java b/src/java/org/apache/cassandra/utils/concurrent/Accumulator.java index 3b5e5c9..baecb34 100644 --- a/src/java/org/apache/cassandra/utils/concurrent/Accumulator.java +++ b/src/java/org/apache/cassandra/utils/concurrent/Accumulator.java @@ -89,7 +89,7 @@ public class Accumulator<E> implements Iterable<E> public boolean isEmpty() { - return presentCount != 0; + return presentCount == 0; } /** http://git-wip-us.apache.org/repos/asf/cassandra/blob/178d7b6f/test/unit/org/apache/cassandra/utils/concurrent/AccumulatorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/utils/concurrent/AccumulatorTest.java b/test/unit/org/apache/cassandra/utils/concurrent/AccumulatorTest.java new file mode 100644 index 0000000..2842374 --- /dev/null +++ b/test/unit/org/apache/cassandra/utils/concurrent/AccumulatorTest.java @@ -0,0 +1,106 @@ +/* +* 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.cassandra.utils.concurrent; + +import java.util.Iterator; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class AccumulatorTest +{ + @Test + public void testAddMoreThanCapacity() + { + Accumulator<Integer> accu = new Accumulator(4); + + accu.add(1); + accu.add(2); + accu.add(3); + accu.add(4); + + try + { + accu.add(5); + fail(); + } + catch (IllegalStateException e) + { + // Expected + } + } + + @Test + public void testIsEmptyAndSize() + { + Accumulator<Integer> accu = new Accumulator(4); + + assertTrue(accu.isEmpty()); + assertEquals(0, accu.size()); + + accu.add(1); + accu.add(2); + + assertTrue(!accu.isEmpty()); + assertEquals(2, accu.size()); + + accu.add(3); + accu.add(4); + + assertTrue(!accu.isEmpty()); + assertEquals(4, accu.size()); + } + + @Test + public void testGetAndIterator() + { + Accumulator<String> accu = new Accumulator(4); + + accu.add("3"); + accu.add("2"); + accu.add("4"); + + assertEquals("3", accu.get(0)); + assertEquals("2", accu.get(1)); + assertEquals("4", accu.get(2)); + + try + { + assertEquals(null, accu.get(3)); + fail(); + } + catch (IndexOutOfBoundsException e) + { + // Expected + } + + accu.add("0"); + + assertEquals("0", accu.get(3)); + + Iterator<String> iter = accu.iterator(); + + assertEquals("3", iter.next()); + assertEquals("2", iter.next()); + assertEquals("4", iter.next()); + assertEquals("0", iter.next()); + assertFalse(iter.hasNext()); + } +}