river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1173631 [2/2] - in /river/jtsk/skunk/peterConcurrentPolicy: src/com/sun/jini/collection/ src/com/sun/jini/thread/ src/net/jini/loader/pref/ src/net/jini/security/ src/net/jini/security/policy/ src/org/apache/river/api/delegates/ src/org/ap...
Date Wed, 21 Sep 2011 13:35:30 GMT
Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ConcurrentWeakIdentityMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ConcurrentWeakIdentityMap.java?rev=1173631&r1=1173630&r2=1173631&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ConcurrentWeakIdentityMap.java
(original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ConcurrentWeakIdentityMap.java
Wed Sep 21 13:35:29 2011
@@ -1,231 +0,0 @@
-/*
- * 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.ReferenceQueue;
-import java.lang.ref.WeakReference;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * Identity-based weak hash map, safe for concurrent threads.
- * 
- * Based on an underlying ConcurrentHashMap, it doesn't accept null keys.
- *
- *
- * @param K - key
- * @param V - value
- * @author Peter Firmstone.
- *
- * @since 2.3
- */
-public class ConcurrentWeakIdentityMap<K, V> implements ConcurrentMap<K, V> {
-    // ConcurrentHashMap must be protected from null values;
-    private final ConcurrentHashMap<Key, V> map;
-    private final ReferenceQueue queue;
-    
-    public ConcurrentWeakIdentityMap(int initialCapacity, float loadFactor, int concurrencyLevel
){
-	map = new ConcurrentHashMap<Key, V>(initialCapacity, loadFactor, concurrencyLevel);
-	queue = new ReferenceQueue();
-    }
-    
-    public ConcurrentWeakIdentityMap(int initialCapacity, float loadFactor){
-	this(initialCapacity, loadFactor, 16);
-    }
-    
-    public ConcurrentWeakIdentityMap(int initialCapacity ){
-	this(initialCapacity, 0.75F, 16);
-    }
-    
-    public ConcurrentWeakIdentityMap(){
-	this(16, 0.75F, 16);
-    }
-
-    /**
-     * Associates value with given key, returning value previously associated
-     * with key, or null if none.
-     * @param key - Key
-     * @param value - Value
-     * @return previous value or null
-     */
-    public V put(K key, V value) {
-	processQueue();
-        if (key == null){return null;}
-	return map.put(Key.create(key, queue), value);
-    }
-
-    /**
-     * Returns value associated with given key, or null if none.
-     */
-    public V get(Object key) {
-	processQueue();
-        if (key == null) { return null;}
-	return map.get(Key.create(key, null));
-    }
-
-    /**
-     * Removes association for given key, returning value previously associated
-     * with key, or null if none.
-     */
-    public V remove(Object key) {
-	processQueue();
-        if (key == null) {return null;}
-	return map.remove(Key.create(key, null));
-    }
-
-    /**
-     * Returns collection containing all values currently held in this map.
-     */
-    public Collection<V> values() {
-	processQueue();
-	return map.values();
-    }
-
-    /**
-     * Removes all associations from this map.
-     */
-    public void clear() {
-	processQueue();
-	map.clear();
-    }
-
-    private void processQueue() {
-	Key k;
-	while ((k = (Key) queue.poll()) != null) {
-	    map.remove(k);
-	}
-    }
-
-    private static class Key<T> extends WeakReference<T> {
-	private final int hash;
-
-        @SuppressWarnings("unchecked")
-	static Key create(Object k, ReferenceQueue q) {
-            //if (k == null) {return null;} // Perhaps this is incorrect
-	    if (q == null) {return new Key(k);}
-	    return new Key(k, q);	  
-	}
-
-	private Key(T k) {
-	    super(k);
-	    hash = System.identityHashCode(k);
-	}
-
-	private Key(T k, ReferenceQueue<? super T> q) {
-	    super(k, q);
-	    hash = System.identityHashCode(k);
-	}
-
-        @Override
-	public boolean equals(Object o) {
-	    if (this == o) {
-		return true;
-	    } else if (!(o instanceof Key)) {
-		return false;
-	    }
-	    Object k1 = get(), k2 = ((Key) o).get();
-	    return (k1 != null && k2 != null && k1 == k2);
-	}
-
-        @Override
-	public int hashCode() {
-	    return hash;
-	}
-    }
-
-    public int size() {
-        processQueue();
-        return map.size();
-    }
-
-    public boolean isEmpty() {
-        processQueue();
-        return map.isEmpty();
-    }
-
-    @SuppressWarnings("unchecked")
-    public boolean containsKey(Object key) {
-        processQueue();
-        if (key == null) {return false;}
-        return map.containsKey(new Key(key));
-    }
-
-    public boolean containsValue(Object value) {
-        processQueue();
-        if (value == null) {return false;}
-        return map.containsValue(value);
-    }
-    
-    /**
-     * Unsupported method
-     * @param m
-     */
-    public void putAll(Map<? extends K, ? extends V> m) {
-        throw new UnsupportedOperationException("Not supported yet.");
-    }
-    
-    @SuppressWarnings("unchecked")
-    public Set<K> keySet() {
-        processQueue();
-        Enumeration<Key> keys = map.keys(); //Defensive copy by ConcurrentHashMap
-        Set<K> keySet = new HashSet<K>();
-        while (keys.hasMoreElements()){
-            keySet.add( (K) keys.nextElement().get());
-        }
-        return keySet;
-    }
-    
-    /**
-     * Unsupported method
-     * @return
-     */
-    public Set<Map.Entry<K, V>> entrySet() {
-        throw new UnsupportedOperationException("Not supported yet, ever?");
-    }
-
-    @SuppressWarnings("unchecked")
-    public V putIfAbsent(K key, V value) {
-        processQueue();  //may be a slight delay before atomic putIfAbsent
-        return map.putIfAbsent(new Key(key), value);       
-    }
-
-    @SuppressWarnings("unchecked")
-    public boolean remove(Object key, Object value) {
-        return map.remove(new Key(key), value);
-    }
-
-    @SuppressWarnings("unchecked")
-    public boolean replace(K key, V oldValue, V newValue) {
-        processQueue();
-        return map.replace(new Key(key), oldValue, newValue);
-    }
-
-    @SuppressWarnings("unchecked")
-    public V replace(K key, V value) {
-        processQueue();
-        return map.replace(new Key(key), value);
-    }
-}

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ConcurrentWeakMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ConcurrentWeakMap.java?rev=1173631&r1=1173630&r2=1173631&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ConcurrentWeakMap.java
(original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ConcurrentWeakMap.java
Wed Sep 21 13:35:29 2011
@@ -1,236 +0,0 @@
-/*
- * 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.ReferenceQueue;
-import java.lang.ref.SoftReference;
-import java.lang.ref.WeakReference;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * A Sofly referenced hash map, safe for concurrent threads.
- * 
- * Based on an underlying ConcurrentHashMap, it doesn't accept null keys.
- *
- * Key's must not be mutated, soing so will cause strange results.
- *
- * @param K - key
- * @param V - value
- * @author Peter Firmstone.
- *
- * @since 2.3
- */
-public class ConcurrentWeakMap<K, V> implements ConcurrentMap<K, V> {
-    // ConcurrentHashMap must be protected from null values;
-    private final ConcurrentHashMap<Key, V> map;
-    private final ReferenceQueue queue;
-    
-    public ConcurrentWeakMap(int initialCapacity, float loadFactor, int concurrencyLevel
){
-	map = new ConcurrentHashMap<Key, V>(initialCapacity, loadFactor, concurrencyLevel);
-	queue = new ReferenceQueue();
-    }
-    
-    public ConcurrentWeakMap(int initialCapacity, float loadFactor){
-	this(initialCapacity, loadFactor, 16);
-    }
-    
-    public ConcurrentWeakMap(int initialCapacity ){
-	this(initialCapacity, 0.75F, 16);
-    }
-    
-    public ConcurrentWeakMap(){
-	this(16, 0.75F, 16);
-    }
-    
-    /**
-     * Associates value with given key, returning value previously associated
-     * with key, or null if none.
-     * @param key - Key
-     * @param value - Value
-     * @return previous value or null
-     */
-    public V put(K key, V value) {
-	processQueue();
-        if (key == null){return null;}
-	return map.put(Key.create(key, queue), value);
-    }
-
-    /**
-     * Returns value associated with given key, or null if none.
-     */
-    public V get(Object key) {
-	processQueue();
-        if (key == null) { return null;}
-	return map.get(Key.create(key, null));
-    }
-
-    /**
-     * Removes association for given key, returning value previously associated
-     * with key, or null if none.
-     */
-    public V remove(Object key) {
-	processQueue();
-        if (key == null) {return null;}
-	return map.remove(Key.create(key, null));
-    }
-
-    /**
-     * Returns collection containing all values currently held in this map.
-     */
-    public Collection<V> values() {
-	processQueue();
-	return map.values();
-    }
-
-    /**
-     * Removes all associations from this map.
-     */
-    public void clear() {
-	processQueue();
-	map.clear();
-    }
-
-    private void processQueue() {
-	Key k;
-	while ((k = (Key) queue.poll()) != null) {
-	    map.remove(k);
-	}
-    }
-
-    private static class Key<T> extends WeakReference<T> {
-	private final int hash;
-
-        @SuppressWarnings("unchecked")
-	static Key create(Object k, ReferenceQueue q) {
-            if (k == null) throw new IllegalArgumentException("Null key prohibited");
-	    if (q == null) {return new Key(k);} //retrieval key only.
-	    return new Key(k, q);	  
-	}
-	
-	private Key(T k) {
-	    super(k);
-	    hash = k.hashCode();
-	}
-
-	private Key(T k, ReferenceQueue<? super T> q) {
-	    super(k, q);
-	    hash = k.hashCode();
-	}
-	
-	/* ReferenceQueue is not compared, because a lookup key is used to locate
-	 * an existing key and ReferenceQueue is null in lookup key's.
-	 * 
-	 * ReferenceQueue is not part of hashCode or equals.
-	 */ 
-        @Override
-	public boolean equals(Object o) {
-	    if (this == o) return true;
-	    // Don't worry about hashcode because they're already equal.
-	    if (!(o instanceof Key)) return false;    
-	    Object k1 = get(), k2 = ((Key) o).get();
-	    return (k1 != null && k1.equals(k2));
-	}
-
-        @Override
-	public int hashCode() {
-	    return hash;
-	}
-    }
-
-    public int size() {
-        processQueue();
-        return map.size();
-    }
-
-    public boolean isEmpty() {
-        processQueue();
-        return map.isEmpty();
-    }
-
-    @SuppressWarnings("unchecked")
-    public boolean containsKey(Object key) {
-        processQueue();
-        if (key == null) {return false;}
-        return map.containsKey(new Key(key));
-    }
-
-    public boolean containsValue(Object value) {
-        processQueue();
-        if (value == null) {return false;}
-        return map.containsValue(value);
-    }
-    
-    /**
-     * Unsupported method
-     * @param m
-     */
-    public void putAll(Map<? extends K, ? extends V> m) {
-        throw new UnsupportedOperationException("Not supported yet.");
-    }
-    
-    @SuppressWarnings("unchecked")
-    public Set<K> keySet() {
-        processQueue();
-        Enumeration<Key> keys = map.keys(); //Defensive copy by ConcurrentHashMap
-        Set<K> keySet = new HashSet<K>(map.size()); //Optimise resizing
-        while (keys.hasMoreElements()){
-            keySet.add( (K) keys.nextElement().get());
-        }
-        return keySet;
-    }
-    
-    /**
-     * Unsupported method
-     * @return
-     */
-    public Set<Map.Entry<K, V>> entrySet() {
-        throw new UnsupportedOperationException("Not supported yet, ever?");
-    }
-
-    @SuppressWarnings("unchecked")
-    public V putIfAbsent(K key, V value) {
-        processQueue();  //may be a slight delay before atomic putIfAbsent
-        return map.putIfAbsent(new Key(key), value);       
-    }
-
-    @SuppressWarnings("unchecked")
-    public boolean remove(Object key, Object value) {
-        return map.remove(new Key(key), value);
-    }
-
-    @SuppressWarnings("unchecked")
-    public boolean replace(K key, V oldValue, V newValue) {
-        processQueue();
-        return map.replace(new Key(key), oldValue, newValue);
-    }
-
-    @SuppressWarnings("unchecked")
-    public V replace(K key, V value) {
-        processQueue();
-        return map.replace(new Key(key), value);
-    }
-}

Modified: river/jtsk/skunk/peterConcurrentPolicy/test/src/net/jini/security/policy/ConcurrentPolicyFileTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/net/jini/security/policy/ConcurrentPolicyFileTest.java?rev=1173631&r1=1173630&r2=1173631&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/net/jini/security/policy/ConcurrentPolicyFileTest.java
(original)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/net/jini/security/policy/ConcurrentPolicyFileTest.java
Wed Sep 21 13:35:29 2011
@@ -71,7 +71,7 @@ public class ConcurrentPolicyFileTest ex
     /**
      * Tests that policy is really resetted on refresh(). 
      */
-    public void testRefresh() {
+    public void testRefresh() throws PolicyInitializationException {
         Permission sp = new SecurityPermission("sdf");
         PermissionGrantBuilder pgb = PermissionGrantBuilder.newBuilder();
         PermissionGrant[] pe = new PermissionGrant[] { 
@@ -97,7 +97,7 @@ public class ConcurrentPolicyFileTest ex
     /**
      * Tests that refresh() does not fail on failing parser.
      */
-    public void testRefresh_Failure() {
+    public void testRefresh_Failure() throws PolicyInitializationException {
         CodeSource cs = new CodeSource(null, (Certificate[])null);
         ConcurrentPolicyFile policy = new ConcurrentPolicyFile(new TestParser(null));
         policy.refresh();

Modified: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/api/security/PermissionGrantTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/api/security/PermissionGrantTest.java?rev=1173631&r1=1173630&r2=1173631&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/api/security/PermissionGrantTest.java
(original)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/api/security/PermissionGrantTest.java
Wed Sep 21 13:35:29 2011
@@ -105,7 +105,7 @@ public class PermissionGrantTest {
     
     @Test
     public void test1() {
-        assertTrue (pe0.implies( (CodeSource) null, (Principal[])null ));
+        assertFalse (pe0.implies( (CodeSource) null, (Principal[])null )); // Originally
was assert true.
     }
 
     @Test

Modified: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java?rev=1173631&r1=1173630&r2=1173631&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java
(original)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java
Wed Sep 21 13:35:29 2011
@@ -18,6 +18,14 @@
 
 package org.apache.river.impl.security.dos;
 
+import tests.support.StackOverflowTask;
+import java.util.concurrent.Future;
+import java.util.concurrent.ExecutionException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import tests.support.PrintTask;
+import org.junit.After;
+import tests.support.ArrayListOverflow;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
@@ -34,6 +42,7 @@ import static org.junit.Assert.*;
  */
 public class IsolateTest {
 
+    IsolatedExecutor executor;
     public IsolateTest() {
     }
 

Modified: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/PolicyEntryTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/PolicyEntryTest.java?rev=1173631&r1=1173630&r2=1173631&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/PolicyEntryTest.java
(original)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/PolicyEntryTest.java
Wed Sep 21 13:35:29 2011
@@ -101,18 +101,18 @@ public class PolicyEntryTest extends Tes
             new UnresolvedPrincipal("e.f.g", "ZZZ") };
 
         assertFalse(pe.implies( (CodeSource) null, (Principal[]) null));
-        assertTrue(pe.implies( (CodeSource) null, pp1));
+        assertFalse(pe.implies( (CodeSource) null, pp1)); //originally  assert true.
 
 //        pe = new PolicyEntry((CodeSource)null, new HashSet<Principal>(),
 //                (Collection<Permission>) null);
         pe = pgb.principals(new Principal[0]).permissions(new Permission[0]).build();
-        assertTrue(pe.implies( (CodeSource) null, pp3));
+        assertFalse(pe.implies( (CodeSource) null, pp3)); //originally assert true.
 
 //        pe = new PolicyEntry((CodeSource) null, Arrays.asList(pp2),
 //                (Collection<Permission>) null);
         pe = pgb.principals(pp2).build(); //Builder still contains empty Permission[]
         assertFalse(pe.implies( (CodeSource) null, (Principal[]) null));
         assertFalse(pe.implies( (CodeSource) null, pp1));
-        assertTrue(pe.implies( (CodeSource) null, pp3));
+        assertFalse(pe.implies( (CodeSource) null, pp3)); //originally assert true.
     }
 }

Modified: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/PolicyUtilsTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/PolicyUtilsTest.java?rev=1173631&r1=1173630&r2=1173631&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/PolicyUtilsTest.java
(original)
+++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/policy/util/PolicyUtilsTest.java
Wed Sep 21 13:35:29 2011
@@ -38,6 +38,10 @@ import java.util.HashSet;
 import java.util.Properties;
 
 import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
 
 
 /**
@@ -46,6 +50,28 @@ import junit.framework.TestCase;
  */
 
 public class PolicyUtilsTest extends TestCase {
+    private static Properties system;
+
+        @BeforeClass
+    public static void setUpClass() throws Exception {
+        system = new Properties(System.getProperties());
+    }
+
+    @AfterClass
+    public static void tearDownClass() throws Exception {
+        System.setProperties(system);
+        system = null;
+    }
+//       @Before
+//    public void setUp() {
+//           system = new Properties(System.getProperties());
+//    }
+//    
+//    @After
+//    public void tearDown() {
+//        System.setProperties(system);
+//        system = null;
+//    }
 
     /** Tests valid expansion of ${key} entries. */
     public void testExpand() throws Exception {
@@ -198,7 +224,11 @@ public class PolicyUtilsTest extends Tes
             URL[] result = PolicyUtils.getPolicyURLs(new Properties(), "",
                     PREFIX);
             assertNotNull(result);
-            assertEquals(2, result.length);
+            assertEquals(2, result.length);  //Fails, result contains "http://foo4.bar.com"
+            int l = result.length;
+            for (int i = 0; i < l; i++){
+                System.out.println(result[i].toString());
+            }
             assertEquals(new URL("http://foo1.bar.com"), result[0]);
             assertEquals(new URL("http://foo2.bar.com"), result[1]);
 
@@ -276,7 +306,7 @@ public class PolicyUtilsTest extends Tes
     public void testToPermissionCollection() {
         Permission p1 = new SecurityPermission("abc");
         Permission p2 = new AllPermission();
-        Collection c1 = Arrays.asList(new Permission[] { p1, p2, });
+        Collection c1 = Arrays.asList(new Permission[] { p1, p2 });
 
         PermissionCollection pc = PolicyUtils.toPermissionCollection(null);
         assertNotNull(pc);
@@ -290,8 +320,9 @@ public class PolicyUtilsTest extends Tes
         assertNotNull(pc);
         Enumeration en = pc.elements();
         Collection c2 = new HashSet();
+        while (en.hasMoreElements()){
         c2.add(en.nextElement());
-        c2.add(en.nextElement());
+        }
         assertFalse(en.hasMoreElements());
         assertTrue(c2.contains(p1));
         assertTrue(c2.contains(p2));



Mime
View raw message