From 9b6e16499a91540c165d0954fa8f2600c0785406 Mon Sep 17 00:00:00 2001 From: jqin Date: Wed, 4 Feb 2015 21:32:05 -0800 Subject: [PATCH] patch for KAFKA-1922. Move test for DoublyLinkedList out of UtilTests.scala --- .../unit/kafka/utils/DoublyLinkedListTest.scala | 72 ++++++++++++++++++++++ .../test/scala/unit/kafka/utils/UtilsTest.scala | 49 --------------- 2 files changed, 72 insertions(+), 49 deletions(-) create mode 100644 core/src/test/scala/unit/kafka/utils/DoublyLinkedListTest.scala diff --git a/core/src/test/scala/unit/kafka/utils/DoublyLinkedListTest.scala b/core/src/test/scala/unit/kafka/utils/DoublyLinkedListTest.scala new file mode 100644 index 0000000..b9ac003 --- /dev/null +++ b/core/src/test/scala/unit/kafka/utils/DoublyLinkedListTest.scala @@ -0,0 +1,72 @@ +/** + * 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 unit.kafka.utils + +import kafka.utils.{DoublyLinkedListNode, DoublyLinkedList} +import org.junit.Test + +class DoublyLinkedListTest { + @Test + def testDoublyLinkedList() { + val list = new DoublyLinkedList[Int] + + // test remove from a single-entry list. + list.add(new DoublyLinkedListNode[Int](0)) + list.remove() + assert(list.size == 0) + assert(list.peek() == null) + + // test add + for (i <- 0 to 2) { + list.add(new DoublyLinkedListNode[Int](i)) + } + val toBeRemoved1 = new DoublyLinkedListNode[Int](3) + list.add(toBeRemoved1) + for (i <- 4 to 6) { + list.add(new DoublyLinkedListNode[Int](i)) + } + val toBeRemoved2 = new DoublyLinkedListNode[Int](7) + list.add(toBeRemoved2) + + // test iterator + val iter = list.iterator + for (i <- 0 to 7) { + assert(iter.hasNext) + assert(iter.next().element == i) + } + assert(!iter.hasNext) + + // remove from head + list.remove() + assert(list.peek().element == 1) + // remove from middle + list.remove(toBeRemoved1) + // remove from tail + list.remove(toBeRemoved2) + + // List = [1,2,4,5,6] + val iter2 = list.iterator + for (i <- Array[Int](1,2,4,5,6)) { + assert(iter2.hasNext) + assert(iter2.next().element == i) + } + + // test size + assert(list.size == 5) + } +} diff --git a/core/src/test/scala/unit/kafka/utils/UtilsTest.scala b/core/src/test/scala/unit/kafka/utils/UtilsTest.scala index 8c3797a..298709b 100644 --- a/core/src/test/scala/unit/kafka/utils/UtilsTest.scala +++ b/core/src/test/scala/unit/kafka/utils/UtilsTest.scala @@ -151,53 +151,4 @@ class UtilsTest extends JUnitSuite { assertFalse("Should be unlocked", lock.isLocked) } - @Test - def testDoublyLinkedList() { - val list = new DoublyLinkedList[Int] - - // test remove from a single-entry list. - list.add(new DoublyLinkedListNode[Int](0)) - list.remove() - assert(list.size == 0) - assert(list.peek() == null) - - // test add - for (i <- 0 to 2) { - list.add(new DoublyLinkedListNode[Int](i)) - } - val toBeRemoved1 = new DoublyLinkedListNode[Int](3) - list.add(toBeRemoved1) - for (i <- 4 to 6) { - list.add(new DoublyLinkedListNode[Int](i)) - } - val toBeRemoved2 = new DoublyLinkedListNode[Int](7) - list.add(toBeRemoved2) - - // test iterator - val iter = list.iterator - for (i <- 0 to 7) { - assert(iter.hasNext) - assert(iter.next().element == i) - } - assert(!iter.hasNext) - - // remove from head - list.remove() - assert(list.peek().element == 1) - // remove from middle - list.remove(toBeRemoved1) - // remove from tail - list.remove(toBeRemoved2) - - // List = [1,2,4,5,6] - val iter2 = list.iterator - for (i <- Array[Int](1,2,4,5,6)) { - assert(iter2.hasNext) - assert(iter2.next().element == i) - } - - // test size - assert(list.size == 5) - } - } -- 1.8.3.4 (Apple Git-47)