river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1173728 - in /river/jtsk/skunk/peterConcurrentPolicy/test/src: org/apache/river/impl/security/policy/util/ org/apache/river/impl/util/ tests/support/
Date Wed, 21 Sep 2011 15:43:22 GMT
Author: peter_firmstone
Date: Wed Sep 21 15:43:22 2011
New Revision: 1173728

URL: http://svn.apache.org/viewvc?rev=1173728&view=rev
Log:
Reference Collection Utilities

Added:
    river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/SegmentTest.java
  (with props)
    river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/
    river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java
  (with props)
    river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceCollectionTest.java
  (with props)
    river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceListTest.java
  (with props)
    river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceMapTest.java
  (with props)
    river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/ArrayListOverflow.java 
 (with props)
    river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/PrintTask.java   (with props)
    river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/StackOverflowTask.java 
 (with props)

Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/SegmentTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/SegmentTest.java?rev=1173728&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/SegmentTest.java
(added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/SegmentTest.java
Wed Sep 21 15:43:22 2011
@@ -0,0 +1,48 @@
+/*
+ * 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.security.policy.util;
+
+import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author peter
+ */
+public class SegmentTest {
+    Properties p;
+    public SegmentTest() {
+    }
+    
+    @Before
+    public void setup(){
+       p = new Properties();
+       p.setProperty("java.ext.dirs", "tests:foo:bar:cat");
+    }
+    
+    @Test
+    public void divideAndReplace(){
+        System.out.println("Test divideAndReplace");
+        String policyGrantln = "file:${{java.ext.dirs}}/*";
+    }
+            
+    
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/SegmentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java?rev=1173728&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java
(added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java
Wed Sep 21 15:43:22 2011
@@ -0,0 +1,126 @@
+/*
+ * 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.concurrent.ConcurrentHashMap;
+import java.lang.ref.Reference;
+import java.util.concurrent.ConcurrentMap;
+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 Firmstone.
+ */
+public class ConcurrentReferenceMapTest {
+    private ConcurrentMap<Integer, String> instance;
+    // strong references
+    private Integer i1, i2, i3, i4, i5;
+    
+    public ConcurrentReferenceMapTest() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+    }
+    
+    @Before
+    public void setUp() {
+        ConcurrentMap<Reference<Integer>, Reference<String>> internal 
+                = new ConcurrentHashMap<Reference<Integer>, Reference<String>>(5);
+        instance = RC.concurrentMap(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 putIfAbsent method, of class ConcurrentReferenceMap.
+     */
+    @Test
+    public void testPutIfAbsent() {
+        System.out.println("putIfAbsent");
+        Integer key = 5;
+        String value = "Five";
+        Object expResult = "5";
+        Object result = instance.putIfAbsent(key, value);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of remove method, of class ConcurrentReferenceMap.
+     */
+    @Test
+    public void testRemove() {
+        System.out.println("remove");
+        Integer key = 4;
+        String value = "4";
+        boolean expResult = true;
+        boolean result = instance.remove(key, value);
+        assertEquals(expResult, result);
+        assertFalse(instance.containsValue(value));
+    }
+
+    /**
+     * Test of replace method, of class ConcurrentReferenceMap.
+     */
+    @Test
+    public void testReplace_3args() {
+        System.out.println("replace");
+        Integer key = 3;
+        String oldValue = "3";
+        String newValue = "Three";
+        boolean expResult = true;
+        boolean result = instance.replace(key, oldValue, newValue);
+        assertEquals(expResult, result);
+        assertFalse(instance.containsValue(oldValue));
+    }
+
+    /**
+     * Test of replace method, of class ConcurrentReferenceMap.
+     */
+    @Test
+    public void testReplace_GenericType_GenericType() {
+        System.out.println("replace");
+        Integer key = 2;
+        String value = "Two";
+        String expResult = "2";
+        String result = instance.replace(key, value);
+        assertEquals(expResult, result);
+    }
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceCollectionTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceCollectionTest.java?rev=1173728&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceCollectionTest.java
(added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceCollectionTest.java
Wed Sep 21 15:43:22 2011
@@ -0,0 +1,273 @@
+/*
+ * 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.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Arrays;
+import java.util.Collection;
+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.*;
+
+/**
+ * This test also validates ReferenceSet and most of ReferenceList.
+ * 
+ * @author peter
+ */
+public class ReferenceCollectionTest {
+    
+    private ReferenceCollection<String> instance;
+    private String truck = "truck";
+    private String shovel = "shovel";
+    private String grader = "grader";
+    private String waterTruck = "water truck";
+    private String roller = "roller";
+    
+    public ReferenceCollectionTest() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+    }
+    
+    @Before
+    public void setUp() {
+        instance = new ReferenceCollection<String>(new ArrayList<Reference<String>>(),
Ref.WEAK_IDENTITY);
+        instance.add(truck);
+        instance.add(shovel);
+        instance.add(grader);
+        instance.add(waterTruck);
+        instance.add(roller);
+    }
+    
+    @After
+    public void tearDown() {
+    }
+
+    /**
+     * Test of getQueue method, of class ReferenceCollection.
+     */
+    @Test
+    public void testGetQueue() {
+        System.out.println("getQueue");
+        ReferenceQueue result = instance.getQueue();
+        assertTrue(result instanceof ReferenceQueue);
+    }
+
+    /**
+     * Test of getType method, of class ReferenceCollection.
+     */
+    @Test
+    public void testGetType() {
+        System.out.println("getType");
+        Ref expResult = Ref.WEAK_IDENTITY;
+        Ref result = instance.getType();
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of size method, of class ReferenceCollection.
+     */
+    @Test
+    public void testSize() {
+        System.out.println("size");
+        int expResult = 5;
+        int result = instance.size();
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of isEmpty method, of class ReferenceCollection.
+     */
+    @Test
+    public void testIsEmpty() {
+        System.out.println("isEmpty");
+        boolean expResult = false;
+        boolean result = instance.isEmpty();
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of contains method, of class ReferenceCollection.
+     */
+    @Test
+    public void testContains() {
+        System.out.println("contains");
+        String o = "truck";
+        boolean expResult = true;
+        boolean result = instance.contains(o);
+        // This only passes because String uses object pooling. 
+        // For other objects this would fail when identity and equality
+        // are not the same.
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of iterator method, of class ReferenceCollection.
+     */
+    @Test
+    public void testIterator() {
+        System.out.println("iterator");
+        Collection<String> expResult = new ArrayList<String>(5);
+        expResult.add(truck);
+        expResult.add(shovel);
+        expResult.add(waterTruck);
+        expResult.add(grader);
+        expResult.add(roller);
+        Collection<String> result = new ArrayList<String>(5);
+        Iterator<String> it = instance.iterator();
+        while (it.hasNext()){
+            result.add(it.next());
+        }
+        assertTrue(expResult.containsAll(result));
+    }
+
+    /**
+     * Test of toArray method, of class ReferenceCollection.
+     */
+    @Test
+    public void testToArray_0args() {
+        System.out.println("toArray");
+        Object[] expResult = {truck, shovel, waterTruck, grader, roller};
+        Object[] result = instance.toArray();
+        assertTrue(expResult.length == result.length);
+        Collection res = Arrays.asList(result);
+        Collection exp = Arrays.asList(expResult);
+        assertTrue(exp.containsAll(res));
+    }
+
+    /**
+     * Test of toArray method, of class ReferenceCollection.
+     */
+    @Test
+    public void testToArray_GenericType() {
+        System.out.println("toArray");
+        String[] a = new String [5];
+        String[] expResult = {truck, shovel, waterTruck, grader, roller};
+        String[] result = instance.toArray(a);
+        assertTrue(expResult.length == result.length);
+        Collection<String> res = Arrays.asList(result);
+        Collection<String> exp = Arrays.asList(expResult);
+        assertTrue(exp.containsAll(res));
+    }
+
+    /**
+     * Test of add method, of class ReferenceCollection.
+     */
+    @Test
+    public void testAdd() {
+        System.out.println("add");
+        truck = "cat797";
+        boolean expResult = true;
+        boolean result = instance.add(truck);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of remove method, of class ReferenceCollection.
+     */
+    @Test
+    public void testRemove() {
+        System.out.println("remove");
+        boolean expResult = true;
+        boolean result = instance.remove(shovel);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of containsAll method, of class ReferenceCollection.
+     */
+    @Test
+    public void testContainsAll() {
+        System.out.println("containsAll");
+        Collection<String> c = new ArrayList<String>(4);
+        c.add(truck);
+        c.add(grader);
+        c.add(waterTruck);
+        c.add(roller);
+        boolean expResult = true;
+        boolean result = instance.containsAll(c);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of addAll method, of class ReferenceCollection.
+     */
+    @Test
+    public void testAddAll() {
+        System.out.println("addAll");
+        Collection<String> c = new ArrayList<String>(2);
+        c.add("Kress");
+        c.add("Bucyrus");
+        boolean expResult = true;
+        boolean result = instance.addAll(c);
+        assertEquals(expResult, result);
+        assertTrue(instance.containsAll(c));
+    }
+
+    /**
+     * Test of removeAll method, of class ReferenceCollection.
+     */
+    @Test
+    public void testRemoveAll() {
+        System.out.println("removeAll");
+        Collection<String> c = new ArrayList<String>(2);
+        c.add(grader);
+        c.add(roller);
+        boolean expResult = true;
+        boolean result = instance.removeAll(c);
+        assertEquals(expResult, result);
+        assertFalse(instance.containsAll(c));
+    }
+
+    /**
+     * Test of retainAll method, of class ReferenceCollection.
+     */
+    @Test
+    public void testRetainAll() {
+        System.out.println("retainAll");
+        Collection<String> c = new ArrayList<String>(2);
+        c.add(truck);
+        c.add(waterTruck);
+        boolean expResult = true;
+        boolean result = instance.retainAll(c);
+        assertEquals(expResult, result);
+        assertTrue( instance.size() == 2);
+    }
+
+    /**
+     * Test of clear method, of class ReferenceCollection.
+     */
+    @Test
+    public void testClear() {
+        System.out.println("clear");
+        instance.clear();
+        assertTrue( instance.isEmpty() );
+    }
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceCollectionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceListTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceListTest.java?rev=1173728&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceListTest.java
(added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceListTest.java
Wed Sep 21 15:43:22 2011
@@ -0,0 +1,219 @@
+/*
+ * 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.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.ListIterator;
+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 ReferenceListTest {
+    private List<String> instance;
+    private String truck = "truck";
+    private String shovel = "shovel";
+    private String grader = "grader";
+    private String waterTruck = "water truck";
+    private String roller = "roller";
+    
+    public ReferenceListTest() {
+    }
+
+    @BeforeClass
+    public static void setUpClass() throws Exception {
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+    }
+    
+    @Before
+    public void setUp() {
+        instance = new ReferenceList<String>(new ArrayList<Reference<String>>(),
Ref.WEAK_IDENTITY);
+        instance.add(truck);
+        instance.add(shovel);
+        instance.add(grader);
+        instance.add(waterTruck);
+        instance.add(roller);
+    }
+    
+    @After
+    public void tearDown() {
+    }
+
+    /**
+     * Test of addAll method, of class ReferenceList.
+     */
+    @Test
+    public void testAddAll() {
+        System.out.println("addAll");
+        int index = 5;
+        String [] list = {"Bucyrus", "Marion", "Page"};
+        Collection<String> c = Arrays.asList(list);
+        boolean expResult = true;
+        boolean result = instance.addAll(index, c);
+        System.out.println(instance);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of get method, of class ReferenceList.
+     */
+    @Test
+    public void testGet() {
+        System.out.println("get");
+        int index = 2;
+        String expResult = grader;
+        Object result = instance.get(index);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of set method, of class ReferenceList.
+     */
+    @Test
+    public void testSet() {
+        System.out.println("set");
+        int index = 2;
+        String element = "dozer";
+        String expResult = grader;
+        String result = instance.set(index, element);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of add method, of class ReferenceList.
+     */
+    @Test
+    public void testAdd() {
+        System.out.println("add");
+        int index = 4;
+        String element = "drill";
+        instance.add(index, element);
+        String result = instance.get(index);
+        assertEquals(element , result);
+    }
+
+    /**
+     * Test of remove method, of class ReferenceList.
+     */
+    @Test
+    public void testRemove() {
+        System.out.println("remove");
+        int index = 3;
+        String expResult = waterTruck;
+        String result = instance.remove(index);
+        assertEquals(expResult, result);
+    }
+
+       /**
+     * Test of indexOf method, of class ReferenceList.
+     */
+    @Test
+    public void testGC() {
+        System.out.println("test Garbage collection");
+        String o = "drill";
+        int expResult = -1;
+        int result = instance.indexOf(o);
+        System.out.println(instance);
+        assertEquals(expResult, result);
+    }
+    
+    /**
+     * Test of indexOf method, of class ReferenceList.
+     */
+    @Test
+    public void testIndexOf() {
+        System.out.println("indexOf");
+        String o = "shovel";
+        int expResult = 1;
+        int result = instance.indexOf(o);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of lastIndexOf method, of class ReferenceList.
+     */
+    @Test
+    public void testLastIndexOf() {
+        System.out.println("lastIndexOf");
+        String o = roller;
+        int expResult = 4;
+        int result = instance.lastIndexOf(o);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of listIterator method, of class ReferenceList.
+     */
+    @Test
+    public void testListIterator_0args() {
+        System.out.println("listIterator");
+        List<String> expResult = new ArrayList<String>();
+        ListIterator<String> i = instance.listIterator();
+        while( i.hasNext()){
+            expResult.add(i.next());
+        }
+        assertTrue(expResult.containsAll(instance));
+    }
+
+    /**
+     * Test of listIterator method, of class ReferenceList.
+     */
+    @Test
+    public void testListIterator_int() {
+        System.out.println("listIterator");
+        int index = 3;
+        Collection<String> expResult = new ArrayList<String>(3);
+        expResult.add(waterTruck);
+        expResult.add(roller);
+        Collection<String> result = new ArrayList<String>();
+        ListIterator<String> i = instance.listIterator(index);
+        while (i.hasNext()){
+            result.add(i.next());
+        }
+        System.out.println(result);
+        assertTrue(expResult.containsAll(result));
+    }
+
+    /**
+     * Test of subList method, of class ReferenceList.
+     */
+    @Test
+    public void testSubList() {
+        System.out.println("subList");
+        int fromIndex = 0;
+        int toIndex = 1;
+        List<String> expResult = new ArrayList<String>();
+        expResult.add(truck);
+        List<String> result = instance.subList(fromIndex, toIndex);
+        assertTrue(result.containsAll(expResult));
+    }
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceListTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceMapTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceMapTest.java?rev=1173728&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceMapTest.java
(added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceMapTest.java
Wed Sep 21 15:43:22 2011
@@ -0,0 +1,232 @@
+/*
+ * 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.Iterator;
+import java.util.Map.Entry;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.lang.ref.Reference;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author Peter Firmstone.
+ */
+public class ReferenceMapTest {
+    private Map<Integer, String> instance;
+    // strong references
+    private Integer i1, i2, i3, i4, i5;
+    private String s1, s2, s3, s4, s5;
+    
+    public ReferenceMapTest() {
+    }
+
+    @Before
+    public void setUp() {
+        Map<Reference<Integer>, Reference<String>> internal 
+                = new HashMap<Reference<Integer>, Reference<String>>(5);
+        instance = new ReferenceMap<Integer, String>(internal, Ref.WEAK, Ref.STRONG);
+        i1 = 1;
+        i2 = 2;
+        i3 = 3;
+        i4 = 4;
+        i5 = 5;
+        s1 = "One";
+        s2 = "Two";
+        s3 = "Three";
+        s4 = "Four";
+        s5 = "Five";
+        instance.put(i1, s1);
+        instance.put(i2, s2);
+        instance.put(i3, s3);
+        instance.put(i4, s4);
+        instance.put(i5, s5);
+    }
+    
+    @After
+    public void tearDown() {
+    }
+
+    /**
+     * Test of containsKey method, of class ReferenceMap.
+     */
+    @Test
+    public void testContainsKey() {
+        System.out.println("containsKey");
+        instance.put(i1, s1);
+        Integer key = i1;
+        boolean expResult = true;
+        boolean result = instance.containsKey(key);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of containsValue method, of class ReferenceMap.
+     */
+    @Test
+    public void testContainsValue() {
+        System.out.println("containsValue");
+        Object value = "One";
+        boolean expResult = true;
+        boolean result = instance.containsValue(value);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of entrySet method, of class ReferenceMap.
+     * Tests the entry set iterator and the keySet and values methods too.
+     */
+    @Test
+    public void testEntrySet() {
+        System.out.println("entrySet");
+        List<Integer> keys = new ArrayList<Integer>(5);
+        List<String> values = new ArrayList<String>(5);
+        Set<Entry<Integer, String>> result = instance.entrySet();
+        Iterator<Entry<Integer, String>> i = result.iterator();
+        while (i.hasNext()){
+            Entry<Integer, String> e = i.next();
+            keys.add(e.getKey());
+            values.add(e.getValue());
+        }
+        Collection<Integer> k = instance.keySet();
+        Collection<String> v = instance.values();
+        System.out.println(k);
+        System.out.println(v);
+        assertTrue(k.containsAll(keys));
+        assertTrue(v.containsAll(values));
+    }
+    
+    @Test
+    public void testEntrySetMutation(){
+        instance.put(i1, s1);
+        instance.put(i2, s2);
+        instance.put(i3, s3);
+        instance.put(i4, s4);
+        instance.put(i5, s5);
+        Set<Entry<Integer, String>> result = instance.entrySet();
+        Iterator<Entry<Integer, String>> i = result.iterator();
+        while (i.hasNext()){
+            Entry<Integer, String> e = i.next();
+            if (e.getKey().equals(i1)){
+                e.setValue("Big One");
+            }
+        }
+        assertTrue( instance.get(i1).equals("Big One"));
+    }
+
+    /**
+     * Test of get method, of class ReferenceMap.
+     */
+    @Test
+    public void testGet() {
+        System.out.println("get");
+        Object key = 1;
+        Object expResult = "One";
+        Object result = instance.get(key);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of isEmpty method, of class ReferenceMap.
+     */
+    @Test
+    public void testIsEmpty() {
+        System.out.println("isEmpty");
+        boolean expResult = false;
+        boolean result = instance.isEmpty();
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of put method, of class ReferenceMap.
+     */
+    @Test
+    public void testPut() {
+        System.out.println("put");
+        Integer key = 5;
+        String value = "5";
+        Object expResult = "Five";
+        Object result = instance.put(key, value);
+        assertEquals(expResult, result);
+    }
+
+    /**
+     * Test of putAll method, of class ReferenceMap.
+     */
+    @Test
+    public void testPutAll() {
+        System.out.println("putAll");
+        Map<Integer,String> m = new HashMap<Integer, String>();
+        Integer i6 = 6, i7 = 7, i8 = 8;
+        m.put(6,"Six");
+        m.put(7, "Seven");
+        m.put(8, "Eight");
+        instance.putAll(m);
+        assertTrue( instance.containsKey(8));
+        assertTrue( instance.containsValue("Seven"));
+    }
+
+    /**
+     * Test of remove method, of class ReferenceMap.
+     */
+    @Test
+    public void testRemove() {
+        System.out.println("remove");
+        Integer key = 4;
+        Object expResult = "Four";
+        String result = instance.remove(key);
+        assertEquals(expResult, result);
+        assertFalse(instance.containsKey(4));
+        assertFalse(instance.containsValue("Four"));
+    }
+
+    /**
+     * Test of size method, of class ReferenceMap.
+     */
+    @Test
+    public void testSize() {
+        System.out.println("size");
+        Collection<Integer> keys = instance.keySet();
+        int expResult = keys.size();
+        int result = instance.size();
+        System.out.println(instance);
+        assertEquals(expResult, result);
+    }
+
+
+
+     /**
+     * Test of clear method, of class ReferenceMap.
+     */
+    @Test
+    public void testClear() {
+        System.out.println("clear");
+        instance.clear();
+        assertTrue(instance.size() == 0);
+        instance.put(i1, s1);
+    }
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceMapTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/ArrayListOverflow.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/ArrayListOverflow.java?rev=1173728&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/ArrayListOverflow.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/ArrayListOverflow.java Wed
Sep 21 15:43:22 2011
@@ -0,0 +1,38 @@
+/*
+ * 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 tests.support;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+/**
+ *
+ * @author peter
+ */
+public class ArrayListOverflow implements Callable {
+    
+    public Object call() throws Exception {
+        List overflow = new ArrayList(5000);
+        while (true){
+            overflow.add(new ArrayList(100));
+        }
+    }
+    
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/ArrayListOverflow.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/PrintTask.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/PrintTask.java?rev=1173728&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/PrintTask.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/PrintTask.java Wed Sep 21
15:43:22 2011
@@ -0,0 +1,35 @@
+/*
+ * 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 tests.support;
+
+import java.util.concurrent.Callable;
+
+/**
+ *
+ * @author peter
+ */
+public class PrintTask implements Callable<Boolean>{
+
+
+    public Boolean call() throws Exception {
+        System.out.println("Print Task successful");
+        return Boolean.TRUE;
+    }
+    
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/PrintTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/StackOverflowTask.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/StackOverflowTask.java?rev=1173728&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/StackOverflowTask.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/StackOverflowTask.java Wed
Sep 21 15:43:22 2011
@@ -0,0 +1,36 @@
+/*
+ * 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 tests.support;
+
+import java.util.concurrent.Callable;
+
+/**
+ *
+ * @author peter
+ */
+public class StackOverflowTask implements Callable{
+
+    public Object call() throws Exception {
+        return callAgain();
+    }
+    
+    public Object callAgain() throws Exception{
+        return call();
+    }
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/tests/support/StackOverflowTask.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message