You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2011/09/26 07:02:34 UTC
svn commit: r1175671 - in /river/jtsk/skunk/peterConcurrentPolicy/test/src:
org/apache/river/impl/util/ tests/support/
Author: peter_firmstone
Date: Mon Sep 26 05:02:33 2011
New Revision: 1175671
URL: http://svn.apache.org/viewvc?rev=1175671&view=rev
Log:
Reference Collection unit tests and refactor
Added:
river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueTest.java (with props)
river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMapTest.java (with props)
river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceDequeTest.java (with props)
river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableMapTest.java (with props)
river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableSetTest.java (with props)
river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSetTest.java (with props)
river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedMapTest.java (with props)
river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedSetTest.java (with props)
river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferencedQueueTest.java (with props)
river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/MutableMap.java (with props)
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueTest.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueTest.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueTest.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,160 @@
+/*
+ * 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.river.impl.util;
+
+import java.util.ArrayList;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.Executor;
+import java.lang.ref.Reference;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.Collection;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceBlockingQueueTest {
+ private BlockingQueue<String> instance;
+ public ReferenceBlockingQueueTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ instance = RC.blockingQueue(new ArrayBlockingQueue<Reference<String>>(30), Ref.SOFT);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of put method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testPut() throws Exception {
+ System.out.println("put");
+ String e = "put";
+ instance.put(e);
+ String r = instance.take();
+ assertEquals(e, r);
+ }
+
+ /**
+ * Test of offer method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testOffer() throws Exception {
+ System.out.println("offer");
+ String e = "offer";
+ long timeout = 2L;
+ TimeUnit unit = TimeUnit.MILLISECONDS;
+ boolean expResult = true;
+ boolean result = instance.offer(e, timeout, unit);
+ assertEquals(expResult, result);
+ result = instance.remove(e);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of take method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testTake() throws Exception {
+ System.out.println("take");
+ String expResult = "take";
+ instance.add(expResult);
+ Object result = instance.take();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of poll method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testPoll() throws Exception {
+ System.out.println("poll");
+ long timeout = 10L;
+ TimeUnit unit = TimeUnit.MILLISECONDS;
+ String expResult = "poll";
+ instance.add(expResult);
+ Object result = instance.poll(timeout, unit);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of remainingCapacity method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testRemainingCapacity() {
+ System.out.println("remainingCapacity");
+ int expResult = 30;
+ int result = instance.remainingCapacity();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of drainTo method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testDrainTo_Collection() {
+ System.out.println("drainTo");
+ Collection<String> c = new ArrayList<String>();
+ instance.add("drain");
+ instance.add("two");
+ int expResult = 2;
+ int result = instance.drainTo(c);
+ assertEquals(expResult, result);
+ assertTrue(c.contains("drain"));
+ assertTrue(c.contains("two"));
+ }
+
+ /**
+ * Test of drainTo method, of class ReferenceBlockingQueue.
+ */
+ @Test
+ public void testDrainTo_Collection_int() {
+ System.out.println("drainTo");
+ Collection<String> c = new ArrayList<String>();
+ instance.add("drain");
+ instance.add("too");
+ int maxElements = 1;
+ int expResult = 1;
+ int result = instance.drainTo(c, maxElements);
+ assertEquals(expResult, result);
+ }
+
+
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMapTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMapTest.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMapTest.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMapTest.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,361 @@
+/*
+ * 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.river.impl.util;
+
+import java.util.TreeSet;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.lang.ref.Reference;
+import java.util.concurrent.ConcurrentSkipListMap;
+import java.util.Comparator;
+import java.util.Map.Entry;
+import java.util.NavigableSet;
+import java.util.concurrent.ConcurrentNavigableMap;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceConcurrentNavigableMapTest {
+ private ConcurrentNavigableMap<Integer, String> instance;
+ // strong references
+ private Integer i1, i2, i3, i4, i5;
+ private Comparator<Integer> comparator;
+ public ReferenceConcurrentNavigableMapTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ comparator = new Comparator<Integer>(){
+
+ @Override
+ public int compare(Integer o1, Integer o2) {
+ return o1.compareTo(o2);
+ }
+
+ };
+ Comparator<Reference<Integer>> ci = RC.comparator(comparator);
+ ConcurrentNavigableMap<Reference<Integer>, Reference<String>> internal
+ = new ConcurrentSkipListMap<Reference<Integer>, Reference<String>>(ci);
+ instance = RC.concurrentNavigableMap(internal, Ref.WEAK, Ref.STRONG);
+ i1 = 1;
+ i2 = 2;
+ i3 = 3;
+ i4 = 4;
+ i5 = 5;
+ instance.put(i1, "1");
+ instance.put(i2, "2");
+ instance.put(i3, "3");
+ instance.put(i4, "4");
+ instance.put(i5, "5");
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of comparator method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testComparator() {
+ System.out.println("comparator");
+ Comparator<Integer> expResult = comparator;
+ Comparator<? super Integer> result = instance.comparator();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of subMap method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testSubMap() {
+ System.out.println("subMap");
+ Integer fromKey = 2;
+ Integer toKey = 4;
+ SortedMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(2, "2");
+ expResult.put(3, "3");
+ SortedMap<Integer, String> result = instance.subMap(fromKey, toKey);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of headMap method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testHeadMap() {
+ System.out.println("headMap");
+ Integer toKey = 3;
+ SortedMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(1, "1");
+ expResult.put(2, "2");
+ SortedMap<Integer, String> result = instance.headMap(toKey);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of tailMap method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testTailMap() {
+ System.out.println("tailMap");
+ Integer fromKey = 3;
+ SortedMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(3, "3");
+ expResult.put(4, "4");
+ expResult.put(5, "5");
+ SortedMap<Integer, String> result = instance.tailMap(fromKey);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of firstKey method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testFirstKey() {
+ System.out.println("firstKey");
+ Object expResult = 1;
+ Object result = instance.firstKey();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lastKey method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testLastKey() {
+ System.out.println("lastKey");
+ Object expResult = 5;
+ Object result = instance.lastKey();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lowerEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testLowerEntry() {
+ System.out.println("lowerEntry");
+ Integer key = 2;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(1, "1");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.lowerEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lowerKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testLowerKey() {
+ System.out.println("lowerKey");
+ Integer key = 3;
+ Object expResult = 2;
+ Object result = instance.lowerKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of floorEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testFloorEntry() {
+ System.out.println("floorEntry");
+ Integer key = 4;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(4, "4");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.floorEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of floorKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testFloorKey() {
+ System.out.println("floorKey");
+ Integer key = 3;
+ Object expResult = 3;
+ Object result = instance.floorKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of ceilingEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testCeilingEntry() {
+ System.out.println("ceilingEntry");
+ Integer key = 3;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(3, "3");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.ceilingEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of ceilingKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testCeilingKey() {
+ System.out.println("ceilingKey");
+ Integer key = 2;
+ Object expResult = 2;
+ Object result = instance.ceilingKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of higherEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testHigherEntry() {
+ System.out.println("higherEntry");
+ Integer key = 4;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(5, "5");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.higherEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of higherKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testHigherKey() {
+ System.out.println("higherKey");
+ Integer key = 3;
+ Object expResult = 4;
+ Object result = instance.higherKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of firstEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testFirstEntry() {
+ System.out.println("firstEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(1, "1");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.firstEntry();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lastEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testLastEntry() {
+ System.out.println("lastEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(5, "5");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.lastEntry();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollFirstEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testPollFirstEntry() {
+ System.out.println("pollFirstEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(1, "1");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.pollFirstEntry();
+ instance.put(1, "1"); // For other tests.
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollLastEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testPollLastEntry() {
+ System.out.println("pollLastEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(5, "5");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.pollLastEntry();
+ instance.put(5, "5"); // For other tests.
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of descendingMap method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testDescendingMap() {
+ System.out.println("descendingMap");
+ NavigableMap<Integer, String> result = instance.descendingMap();
+ assertTrue(result.firstKey().equals(5));
+ assertTrue(result.lastKey().equals(1));
+ }
+
+ /**
+ * Test of navigableKeySet method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testNavigableKeySet() {
+ System.out.println("navigableKeySet");
+ NavigableSet<Integer> expResult = new TreeSet<Integer>();
+ expResult.add(1);
+ expResult.add(2);
+ expResult.add(3);
+ expResult.add(4);
+ expResult.add(5);
+ NavigableSet<Integer> result = instance.navigableKeySet();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of descendingKeySet method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testDescendingKeySet() {
+ System.out.println("descendingKeySet");
+ NavigableSet<Integer> result = instance.descendingKeySet();
+ assertTrue(result.first().equals(5));
+ assertTrue(result.last().equals(1));
+ }
+
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMapTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceDequeTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceDequeTest.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceDequeTest.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceDequeTest.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,281 @@
+/*
+ * 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.river.impl.util;
+
+import java.util.LinkedList;
+import java.lang.ref.Reference;
+import java.util.Deque;
+import java.util.Iterator;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceDequeTest {
+ private Deque<String> instance;
+ public ReferenceDequeTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ instance = RC.deque(new LinkedList<Reference<String>>(), Ref.WEAK);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of addFirst method, of class ReferenceDeque.
+ */
+ @Test
+ public void testAddFirst() {
+ System.out.println("addFirst");
+ String e = "addFirst";
+ instance.addFirst(e);
+ String result = instance.peekFirst();
+ assertEquals(e, result);
+ }
+
+ /**
+ * Test of addLast method, of class ReferenceDeque.
+ */
+ @Test
+ public void testAddLast() {
+ System.out.println("addLast");
+ String e = "addLast";
+ instance.addLast(e);
+ String result = instance.peekLast();
+ assertEquals(e, result);
+ }
+
+ /**
+ * Test of offerFirst method, of class ReferenceDeque.
+ */
+ @Test
+ public void testOfferFirst() {
+ System.out.println("offerFirst");
+ String e = "offerFirst";
+ boolean expResult = true;
+ boolean result = instance.offerFirst(e);
+ assertEquals(expResult, result);
+ String r = instance.pollFirst();
+ assertEquals(e, r);
+ }
+
+ /**
+ * Test of offerLast method, of class ReferenceDeque.
+ */
+ @Test
+ public void testOfferLast() {
+ System.out.println("offerLast");
+ String e = "offerLast";
+ boolean expResult = true;
+ boolean result = instance.offerLast(e);
+ assertEquals(expResult, result);
+ String r = instance.peekLast();
+ assertEquals(e, r);
+ }
+
+ /**
+ * Test of removeFirst method, of class ReferenceDeque.
+ */
+ @Test
+ public void testRemoveFirst() {
+ System.out.println("removeFirst");
+ String expResult = "removeFirst";
+ instance.offerFirst(expResult);
+ Object result = instance.removeFirst();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of removeLast method, of class ReferenceDeque.
+ */
+ @Test
+ public void testRemoveLast() {
+ System.out.println("removeLast");
+ String expResult = "removeLast";
+ instance.offerLast(expResult);
+ Object result = instance.removeLast();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollFirst method, of class ReferenceDeque.
+ */
+ @Test
+ public void testPollFirst() {
+ System.out.println("pollFirst");
+ String expResult = "pollFirst";
+ instance.offerFirst(expResult);
+ Object result = instance.pollFirst();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollLast method, of class ReferenceDeque.
+ */
+ @Test
+ public void testPollLast() {
+ System.out.println("pollLast");
+ String expResult = "pollLast";
+ instance.offerLast(expResult);
+ Object result = instance.pollLast();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of getFirst method, of class ReferenceDeque.
+ */
+ @Test
+ public void testGetFirst() {
+ System.out.println("getFirst");
+ String expResult = "getFirst";
+ instance.offerFirst(expResult);
+ Object result = instance.getFirst();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of getLast method, of class ReferenceDeque.
+ */
+ @Test
+ public void testGetLast() {
+ System.out.println("getLast");
+ String expResult = "getLast";
+ instance.offerLast(expResult);
+ Object result = instance.getLast();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of peekFirst method, of class ReferenceDeque.
+ */
+ @Test
+ public void testPeekFirst() {
+ System.out.println("peekFirst");
+ String expResult = "peekFirst";
+ instance.offerFirst(expResult);
+ Object result = instance.peekFirst();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of peekLast method, of class ReferenceDeque.
+ */
+ @Test
+ public void testPeekLast() {
+ System.out.println("peekLast");
+ String expResult = "peekLast";
+ instance.offerLast(expResult);
+ Object result = instance.peekLast();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of removeFirstOccurrence method, of class ReferenceDeque.
+ */
+ @Test
+ public void testRemoveFirstOccurrence() {
+ System.out.println("removeFirstOccurrence");
+ String o = "removeFirstOccurrence";
+ instance.offerLast(o);
+ boolean expResult = true;
+ boolean result = instance.removeFirstOccurrence(o);
+ assertEquals(expResult, result);
+ expResult = false;
+ result = instance.removeFirstOccurrence(o);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of removeLastOccurrence method, of class ReferenceDeque.
+ */
+ @Test
+ public void testRemoveLastOccurrence() {
+ System.out.println("removeLastOccurrence");
+ String o = "removeLastOccurrence";
+ instance.offerFirst(o);
+ boolean expResult = true;
+ boolean result = instance.removeLastOccurrence(o);
+ assertEquals(expResult, result);
+ expResult = false;
+ result = instance.removeLastOccurrence(o);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of push method, of class ReferenceDeque.
+ */
+ @Test
+ public void testPush() {
+ System.out.println("push");
+ String e = "push";
+ instance.push(e);
+ String result = instance.poll();
+ assertEquals(e, result);
+ }
+
+ /**
+ * Test of pop method, of class ReferenceDeque.
+ */
+ @Test
+ public void testPop() {
+ System.out.println("pop");
+ String expResult = "pop";
+ instance.push(expResult);
+ Object result = instance.pop();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of descendingIterator method, of class ReferenceDeque.
+ */
+ @Test
+ public void testDescendingIterator() {
+ System.out.println("descendingIterator");
+ String [] e = {"1", "2", "3", "4"};
+ for ( int i = 0; i < e.length; i++){
+ instance.offer(e[i]);
+ }
+ Iterator<String> it = instance.descendingIterator();
+ int i = 3;
+ while (it.hasNext()){
+ String r = it.next();
+ assertEquals(e[i], r);
+ if (i == 0) break;
+ i--;
+ }
+ }
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceDequeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableMapTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableMapTest.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableMapTest.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableMapTest.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,317 @@
+/*
+ * 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.river.impl.util;
+
+import java.util.TreeSet;
+import java.util.TreeMap;
+import java.lang.ref.Reference;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+import java.util.NavigableSet;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceNavigableMapTest {
+ private NavigableMap<Integer, String> instance;
+ // strong references
+ private Integer i1, i2, i3, i4, i5;
+
+ public ReferenceNavigableMapTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ NavigableMap<Reference<Integer>, Reference<String>> internal
+ = new TreeMap<Reference<Integer>, Reference<String>>();
+ instance = RC.navigableMap(internal, Ref.WEAK, Ref.STRONG);
+ i1 = 1;
+ i2 = 2;
+ i3 = 3;
+ i4 = 4;
+ i5 = 5;
+ instance.put(i1, "1");
+ instance.put(i2, "2");
+ instance.put(i3, "3");
+ instance.put(i4, "4");
+ instance.put(i5, "5");
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of lowerEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testLowerEntry() {
+ System.out.println("lowerEntry");
+ Integer key = 2;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(1, "1");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.lowerEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lowerKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testLowerKey() {
+ System.out.println("lowerKey");
+ Integer key = 3;
+ Object expResult = 2;
+ Object result = instance.lowerKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of floorEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testFloorEntry() {
+ System.out.println("floorEntry");
+ Integer key = 4;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(4, "4");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.floorEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of floorKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testFloorKey() {
+ System.out.println("floorKey");
+ Integer key = 3;
+ Object expResult = 3;
+ Object result = instance.floorKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of ceilingEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testCeilingEntry() {
+ System.out.println("ceilingEntry");
+ Integer key = 3;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(3, "3");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.ceilingEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of ceilingKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testCeilingKey() {
+ System.out.println("ceilingKey");
+ Integer key = 2;
+ Object expResult = 2;
+ Object result = instance.ceilingKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of higherEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testHigherEntry() {
+ System.out.println("higherEntry");
+ Integer key = 4;
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(5, "5");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.higherEntry(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of higherKey method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testHigherKey() {
+ System.out.println("higherKey");
+ Integer key = 3;
+ Object expResult = 4;
+ Object result = instance.higherKey(key);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of firstEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testFirstEntry() {
+ System.out.println("firstEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(1, "1");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.firstEntry();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lastEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testLastEntry() {
+ System.out.println("lastEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(5, "5");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.lastEntry();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollFirstEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testPollFirstEntry() {
+ System.out.println("pollFirstEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(1, "1");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.pollFirstEntry();
+ instance.put(1, "1"); // For other tests.
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollLastEntry method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testPollLastEntry() {
+ System.out.println("pollLastEntry");
+ NavigableMap<Integer, String> r = new TreeMap<Integer, String>();
+ r.put(5, "5");
+ Entry<Integer, String> expResult = r.pollFirstEntry();
+ Entry<Integer, String> result = instance.pollLastEntry();
+ instance.put(5, "5"); // For other tests.
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of descendingMap method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testDescendingMap() {
+ System.out.println("descendingMap");
+ NavigableMap<Integer, String> result = instance.descendingMap();
+ assertTrue(result.firstKey().equals(5));
+ assertTrue(result.lastKey().equals(1));
+ }
+
+ /**
+ * Test of navigableKeySet method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testNavigableKeySet() {
+ System.out.println("navigableKeySet");
+ NavigableSet<Integer> expResult = new TreeSet<Integer>();
+ expResult.add(1);
+ expResult.add(2);
+ expResult.add(3);
+ expResult.add(4);
+ expResult.add(5);
+ NavigableSet<Integer> result = instance.navigableKeySet();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of descendingKeySet method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testDescendingKeySet() {
+ System.out.println("descendingKeySet");
+ NavigableSet<Integer> result = instance.descendingKeySet();
+ assertTrue(result.first().equals(5));
+ assertTrue(result.last().equals(1));
+ }
+
+ /**
+ * Test of subMap method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testSubMap() {
+ System.out.println("subMap");
+ Integer fromKey = 2;
+ boolean fromInclusive = false;
+ Integer toKey = 5;
+ boolean toInclusive = false;
+ NavigableMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(3, "3");
+ expResult.put(4, "4");
+ NavigableMap<Integer, String> result = instance.subMap(fromKey, fromInclusive, toKey, toInclusive);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of headMap method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testHeadMap() {
+ System.out.println("headMap");
+ Integer toKey = 3;
+ boolean inclusive = false;
+ NavigableMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(1, "1");
+ expResult.put(2, "2");
+ NavigableMap<Integer, String> result = instance.headMap(toKey, inclusive);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of tailMap method, of class ReferenceNavigableMap.
+ */
+ @Test
+ public void testTailMap() {
+ System.out.println("tailMap");
+ Integer fromKey = 3;
+ boolean inclusive = false;
+ NavigableMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(4, "4");
+ expResult.put(5, "5");
+ NavigableMap<Integer, String> result = instance.tailMap(fromKey, inclusive);
+ assertEquals(expResult, result);
+ }
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableMapTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableSetTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableSetTest.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableSetTest.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableSetTest.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,209 @@
+/*
+ * 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.river.impl.util;
+
+import java.lang.ref.Reference;
+import java.util.TreeSet;
+import java.util.Iterator;
+import java.util.NavigableSet;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceNavigableSetTest {
+ private NavigableSet<String> instance;
+ public ReferenceNavigableSetTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ instance = RC.navigableSet(new TreeSet<Reference<String>>(), Ref.STRONG);
+ instance.add("eee");
+ instance.add("bbb");
+ instance.add("aaa");
+ instance.add("ccc");
+ instance.add("ddd");
+ instance.add("fff");
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of lower method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testLower() {
+ System.out.println("lower");
+ String e = "ccc";
+ String expResult = "bbb";
+ String result = instance.lower(e);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of floor method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testFloor() {
+ System.out.println("floor");
+ String e = "ccc";
+ Object expResult = "ccc";
+ Object result = instance.floor(e);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of ceiling method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testCeiling() {
+ System.out.println("ceiling");
+ String e = "ddd";
+ Object expResult = "ddd";
+ Object result = instance.ceiling(e);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of higher method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testHigher() {
+ System.out.println("higher");
+ String e = "bbb";
+ Object expResult = "ccc";
+ Object result = instance.higher(e);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollFirst method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testPollFirst() {
+ System.out.println("pollFirst");
+ Object expResult = "aaa";
+ String result = instance.pollFirst();
+ instance.add(result);// put it back for other tests.
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of pollLast method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testPollLast() {
+ System.out.println("pollLast");
+ Object expResult = "fff";
+ String result = instance.pollLast();
+ instance.add(result);// Put it back for other tests.
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of descendingSet method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testDescendingSet() {
+ System.out.println("descendingSet");
+ NavigableSet<String> result = instance.descendingSet();
+ assertTrue(!result.isEmpty()); // We only want to check the method works.
+ assertTrue(result.first() instanceof String); // And the Set contains Strings, not references.
+ }
+
+ /**
+ * Test of descendingIterator method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testDescendingIterator() {
+ System.out.println("descendingIterator");
+ NavigableSet<String> e = new TreeSet<String>();
+ Iterator<String> i = instance.descendingIterator();
+ while (i.hasNext()){
+ e.add(i.next());
+ }
+ assertTrue(!e.isEmpty()); // Make sure we received strings.
+ assertTrue(e.contains("ccc"));
+ }
+
+ /**
+ * Test of subSet method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testSubSet() {
+ System.out.println("subSet");
+ String fromElement = "bbb";
+ boolean fromInclusive = false;
+ String toElement = "eee";
+ boolean toInclusive = false;
+ NavigableSet<String> expResult = new TreeSet<String>();
+ expResult.add("ccc");
+ expResult.add("ddd");
+ NavigableSet<String> result = instance.subSet(fromElement, fromInclusive, toElement, toInclusive);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of headSet method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testHeadSet() {
+ System.out.println("headSet");
+ String toElement = "ccc";
+ boolean inclusive = false;
+ NavigableSet<String> expResult = new TreeSet<String>();
+ expResult.add("aaa");
+ expResult.add("bbb");
+ NavigableSet<String> result = instance.headSet(toElement, inclusive);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of tailSet method, of class ReferenceNavigableSet.
+ */
+ @Test
+ public void testTailSet() {
+ System.out.println("tailSet");
+ String fromElement = "ccc";
+ boolean inclusive = false;
+ NavigableSet<String> expResult = new TreeSet<String>();
+ expResult.add("ddd");
+ expResult.add("eee");
+ expResult.add("fff");
+ NavigableSet<String> result = instance.tailSet(fromElement, inclusive);
+ assertEquals(expResult, result);
+ }
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceNavigableSetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSetTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSetTest.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSetTest.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSetTest.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,59 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.apache.river.impl.util;
+
+import java.util.TreeSet;
+import java.lang.ref.Reference;
+import java.util.Set;
+import java.util.HashSet;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceSetTest {
+
+ public ReferenceSetTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testEquals() {
+ System.out.println("testEquals");
+ Set<String> set1 = new HashSet<String>(3);
+ Set<String> set2 = RC.set(new TreeSet<Reference<String>>(), Ref.SOFT);
+ String s1 = "1", s2 = "2", s3 = "3";
+ set1.add(s1);
+ set1.add(s2);
+ set1.add(s3);
+ set2.add(s1);
+ set2.add(s2);
+ set2.add(s3);
+ assertTrue(set1.equals(set2));
+ assertTrue(set2.equals(set1));
+ assertTrue(set1.hashCode() == set2.hashCode());
+ }
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedMapTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedMapTest.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedMapTest.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedMapTest.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,159 @@
+/*
+ * 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.river.impl.util;
+
+import java.util.TreeMap;
+import java.lang.ref.Reference;
+import java.util.Comparator;
+import java.util.SortedMap;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceSortedMapTest {
+ private SortedMap<Integer, String> instance;
+ // strong references
+ private Integer i1, i2, i3, i4, i5;
+ private Comparator<Integer> comparator;
+
+ public ReferenceSortedMapTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ comparator = new Comparator<Integer>(){
+
+ @Override
+ public int compare(Integer o1, Integer o2) {
+ return o1.compareTo(o2);
+ }
+
+ };
+ Comparator<Reference<Integer>> ci = RC.comparator(comparator);
+ SortedMap<Reference<Integer>, Reference<String>> internal
+ = new TreeMap<Reference<Integer>, Reference<String>>(ci);
+ instance = RC.sortedMap(internal, Ref.WEAK, Ref.STRONG);
+ i1 = 1;
+ i2 = 2;
+ i3 = 3;
+ i4 = 4;
+ i5 = 5;
+ instance.put(i1, "1");
+ instance.put(i2, "2");
+ instance.put(i3, "3");
+ instance.put(i4, "4");
+ instance.put(i5, "5");
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of comparator method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testComparator() {
+ System.out.println("comparator");
+ Comparator<Integer> expResult = comparator;
+ Comparator<? super Integer> result = instance.comparator();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of subMap method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testSubMap() {
+ System.out.println("subMap");
+ Integer fromKey = 2;
+ Integer toKey = 4;
+ SortedMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(2, "2");
+ expResult.put(3, "3");
+ SortedMap<Integer, String> result = instance.subMap(fromKey, toKey);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of headMap method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testHeadMap() {
+ System.out.println("headMap");
+ Integer toKey = 3;
+ SortedMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(1, "1");
+ expResult.put(2, "2");
+ SortedMap<Integer, String> result = instance.headMap(toKey);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of tailMap method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testTailMap() {
+ System.out.println("tailMap");
+ Integer fromKey = 3;
+ SortedMap<Integer, String> expResult = new TreeMap<Integer, String>();
+ expResult.put(3, "3");
+ expResult.put(4, "4");
+ expResult.put(5, "5");
+ SortedMap<Integer, String> result = instance.tailMap(fromKey);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of firstKey method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testFirstKey() {
+ System.out.println("firstKey");
+ Object expResult = 1;
+ Object result = instance.firstKey();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of lastKey method, of class ReferenceSortedMap.
+ */
+ @Test
+ public void testLastKey() {
+ System.out.println("lastKey");
+ Object expResult = 5;
+ Object result = instance.lastKey();
+ assertEquals(expResult, result);
+ }
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedMapTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedSetTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedSetTest.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedSetTest.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedSetTest.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,150 @@
+/*
+ * 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.river.impl.util;
+
+import java.util.TreeSet;
+import java.lang.ref.Reference;
+import java.util.Comparator;
+import java.util.SortedSet;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferenceSortedSetTest {
+ private SortedSet<String> instance;
+ private Comparator<String> comparator;
+ public ReferenceSortedSetTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+
+ comparator = new Comparator<String>(){
+
+ @Override
+ public int compare(String o1, String o2) {
+ return o1.compareTo(o2);
+ }
+
+ };
+ Comparator<Reference<String>> rc = RC.comparator(comparator);
+ instance = RC.sortedSet(new TreeSet<Reference<String>>(rc), Ref.STRONG);
+ instance.add("eee");
+ instance.add("bbb");
+ instance.add("aaa");
+ instance.add("ccc");
+ instance.add("ddd");
+ instance.add("fff");
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of comparator method, of class ReferenceSortedSet.
+ */
+ @Test
+ public void testComparator() {
+ System.out.println("comparator");
+ Comparator<String> expResult = comparator;
+ Comparator<String> result = (Comparator<String>) instance.comparator();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of subSet method, of class ReferenceSortedSet.
+ */
+ @Test
+ public void testSubSet() {
+ System.out.println("subSet");
+ String fromElement = "ccc";
+ String toElement = "eee";
+ SortedSet<String> expResult = new TreeSet<String>();
+ expResult.add("ccc");
+ expResult.add("ddd");
+ SortedSet<String> result = instance.subSet(fromElement, toElement);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of headSet method, of class ReferenceSortedSet.
+ */
+ @Test
+ public void testHeadSet() {
+ System.out.println("headSet");
+ String toElement = "ccc";
+ SortedSet<String> expResult = new TreeSet<String>();
+ expResult.add("aaa");
+ expResult.add("bbb");
+ SortedSet<String> result = instance.headSet(toElement);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of tailSet method, of class ReferenceSortedSet.
+ */
+ @Test
+ public void testTailSet() {
+ System.out.println("tailSet");
+ String fromElement = "eee";
+ SortedSet<String> expResult = new TreeSet<String>();
+ expResult.add("eee");
+ expResult.add("fff");
+ SortedSet<String> result = instance.tailSet(fromElement);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of first method, of class ReferenceSortedSet.
+ */
+ @Test
+ public void testFirst() {
+ System.out.println("first");
+ String expResult = "aaa";
+ Object result = instance.first();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of last method, of class ReferenceSortedSet.
+ */
+ @Test
+ public void testLast() {
+ System.out.println("last");
+ Object expResult = "fff";
+ Object result = instance.last();
+ assertEquals(expResult, result);
+ }
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceSortedSetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferencedQueueTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferencedQueueTest.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferencedQueueTest.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferencedQueueTest.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,116 @@
+/*
+ * 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.river.impl.util;
+
+import java.util.LinkedList;
+import java.lang.ref.Reference;
+import java.util.Queue;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class ReferencedQueueTest {
+ Queue<String> instance;
+ public ReferencedQueueTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() {
+ instance = RC.queue(new LinkedList<Reference<String>>(), Ref.SOFT);
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of offer method, of class ReferencedQueue.
+ */
+ @Test
+ public void testOffer() {
+ System.out.println("offer");
+ String e = "offer";
+ boolean expResult = true;
+ boolean result = instance.offer(e);
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of remove method, of class ReferencedQueue.
+ */
+ @Test
+ public void testRemove() {
+ String expResult = "remove";
+ System.out.println(expResult);
+ instance.add(expResult);
+ Object result = instance.remove();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of poll method, of class ReferencedQueue.
+ */
+ @Test
+ public void testPoll() {
+ String expResult = "poll";
+ System.out.println(expResult);
+ instance.add(expResult);
+ String result = instance.poll();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of element method, of class ReferencedQueue.
+ */
+ @Test
+ public void testElement() {
+ String expResult = "element";
+ System.out.println(expResult);
+ instance.add(expResult);
+ Object result = instance.element();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of peek method, of class ReferencedQueue.
+ */
+ @Test
+ public void testPeek() {
+ String expResult = "peek";
+ System.out.println(expResult);
+ instance.add(expResult);
+ Object result = instance.peek();
+ assertEquals(expResult, result);
+ }
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferencedQueueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/MutableMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/MutableMap.java?rev=1175671&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/MutableMap.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/MutableMap.java Mon Sep 26 05:02:33 2011
@@ -0,0 +1,68 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package tests.support;
+
+import java.util.AbstractMap;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ *
+ * @author Peter Firmstone.
+ */
+public class MutableMap<K,V> extends AbstractMap<K,V> {
+ private Set<Entry<K,V>> entrySet;
+ public MutableMap(){
+ entrySet = new TreeSet<Entry<K,V>>(new Compare<K,V>());
+ }
+
+ @Override
+ public Set<Entry<K, V>> entrySet() {
+ return entrySet;
+ }
+
+ public V put(K key, V value) {
+ Entry<K,V> e = new SimpleEntry<K,V>(key, value);
+ V oldVal = null;
+ Iterator<Entry<K,V>> i = entrySet.iterator();
+ while (i.hasNext()){
+ Entry<K,V> en = i.next();
+ if ( e.getKey().equals(key)){
+ i.remove();
+ oldVal = e.getValue();
+ break;
+ }
+ }
+ entrySet.add(e);
+ return oldVal;
+ }
+
+ /**
+ * This class prevents duplicate keys from being added to the underlying
+ * set.
+ * @param <K>
+ * @param <V>
+ */
+ private static class Compare<K,V> implements Comparator<Entry<K,V>> {
+
+ @Override
+ public int compare(Entry<K, V> o1, Entry<K, V> o2) {
+ K key1 = o1.getKey();
+ K key2 = o2.getKey();
+ if (key1 instanceof Comparable && key2 instanceof Comparable){
+ return ((Comparable) key1).compareTo(key2);
+ }
+ if ( key1.hashCode() < key2.hashCode()) return -1;
+ if ( key1.hashCode() == key2.hashCode()) return 0;
+ return 1;
+ }
+
+
+ }
+}
Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/MutableMap.java
------------------------------------------------------------------------------
svn:eol-style = native