Author: peter_firmstone Date: Sun Oct 16 11:31:55 2011 New Revision: 1184796
URL: http://svn.apache.org/viewvc?rev=1184796&view=rev Log: Adding concurrency tests and new concurrency test library IMUnit. More work on serialisation of ReferenceMap Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Factory.java (with props) river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixCollectionCircularReferences.java - copied, changed from r1182211, river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixForMapCircularReferences.java (with props) river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMapSerialData.java (with props) river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceMap.java (with props) river/jtsk/skunk/peterConcurrentPolicy/test/lib/imunit-1.3.jar (with props) river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueConcurrencyTest.java (with props) river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapConcurrencyTest.java (with props) river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapTest.java - copied, changed from r1180519, river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java Removed: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java river/jtsk/skunk/peterConcurrentPolicy/test/lib/MultithreadedTC-1.01.jar river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/security/dos/IsolateTest.java Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Factory.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Factory.java?rev=1184796&view=auto ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Factory.java (added) +++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Factory.java Sun Oct 16 11:31:55 2011 @@ -0,0 +1,34 @@ +/* + * 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; + +/** + * An interface to be considered to enable a reference collection to use to + * create the underlying reference collection of the client's preferred + * choice. + * + * This could be used for defensive copying during de-serialisation or for + * supporting multiple platforms, where your preferred collection isn't + * available on earlier platforms, enabling you to substitute something else. + * + * @author peter + */ +public interface Factory<C> { + public C create(); +} Propchange: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Factory.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java?rev=1184796&r1=1184795&r2=1184796&view=diff ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java (original) +++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java Sun Oct 16 11:31:55 2011 @@ -167,9 +167,21 @@ public class RC { */ public static <T> Collection<T> collection(Collection<Referrer<T>> internal, Ref type){ return new ReferenceCollection<T>(internal, type); - } - + } +// /** +// * The general idea here is, create a factory that produces a the underlying +// * reference collection, then it can be used again later to defensively +// * produce a new copy of the original collection after de-serialisation. +// * +// * @param <T> +// * @param factory +// * @param type +// * @return +// */ +// public static <T> Collection<T> collection(CollectionFactory<Collection<Referrer<T>>> factory, Ref type){ +// return new ReferenceCollection<T>(factory.create(), type); +// } /** * Wrap a List for holding references so it appears as a List Copied: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixCollectionCircularReferences.java (from r1182211, river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java) URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixCollectionCircularReferences.java?p2=river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixCollectionCircularReferences.java&p1=river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java&r1=1182211&r2=1184796&rev=1184796&view=diff ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java (original) +++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixCollectionCircularReferences.java Sun Oct 16 11:31:55 2011 @@ -45,7 +45,7 @@ import java.util.concurrent.TimeUnit; * * @author Peter Firmstone. */ -abstract class ReadResolveCircularReferencesFix<T> extends SerializationOfReferenceCollection<T> +abstract class ReadResolveFixCollectionCircularReferences<T> extends SerializationOfReferenceCollection<T> implements List<T>, Set<T>, SortedSet<T>, NavigableSet<T> , Queue<T>, Deque<T>, BlockingQueue<T>, BlockingDeque<T>{ @@ -55,7 +55,7 @@ Queue<T>, Deque<T>, BlockingQueue<T>, Bl private volatile Collection<T> serialBuilt = null; private volatile boolean built = false; - ReadResolveCircularReferencesFix(){} + ReadResolveFixCollectionCircularReferences(){} @Override Collection<T> build() throws InstantiationException, IllegalAccessException, Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixForMapCircularReferences.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixForMapCircularReferences.java?rev=1184796&view=auto ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixForMapCircularReferences.java (added) +++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixForMapCircularReferences.java Sun Oct 16 11:31:55 2011 @@ -0,0 +1,319 @@ +/* + * 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.io.ObjectStreamException; +import java.util.Collection; +import java.util.Comparator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NavigableMap; +import java.util.NavigableSet; +import java.util.Set; +import java.util.SortedMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentNavigableMap; + +/** + * + * @author peter + */ +abstract class ReadResolveFixForMapCircularReferences<K,V> + extends SerializationOfReferenceMap<K,V> + implements Map<K,V>, SortedMap<K,V>, NavigableMap<K,V>, ConcurrentMap<K,V>, + ConcurrentNavigableMap<K,V>{ + + // Builder created Map on deserialization + private volatile Map<K,V> map = null; + private volatile boolean built = false; + + @Override + public Comparator<? super K> comparator() { + if (getMap() instanceof SortedMap) return ((SortedMap<K,V>) getMap()).comparator(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public ConcurrentNavigableMap<K, V> subMap(K fromKey, K toKey) { + if (getMap() instanceof SortedMap) return ((ConcurrentNavigableMap<K,V>) getMap()).subMap(fromKey, toKey); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public ConcurrentNavigableMap<K, V> headMap(K toKey) { + if (getMap() instanceof SortedMap) return ((ConcurrentNavigableMap<K,V>) getMap()).headMap(toKey); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + public ConcurrentNavigableMap<K, V> tailMap(K fromKey) { + if (getMap() instanceof SortedMap) return ((ConcurrentNavigableMap<K,V>) getMap()).tailMap(fromKey); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public K firstKey() { + if (getMap() instanceof SortedMap) return ((SortedMap<K,V>) getMap()).firstKey(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public K lastKey() { + if (getMap() instanceof SortedMap) return ((SortedMap<K,V>) getMap()).lastKey(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + public NavigableSet<K> keySet() { + if (getMap() instanceof SortedMap) return ((ConcurrentNavigableMap<K,V>) getMap()).keySet(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public Collection<V> values() { + if (getMap() instanceof SortedMap) return ((SortedMap<K,V>) getMap()).values(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public Set<Entry<K, V>> entrySet() { + if (getMap() instanceof SortedMap) return ((SortedMap<K,V>) getMap()).entrySet(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public int size() { + return getMap().size(); + } + + @Override + public boolean isEmpty() { + return getMap().isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return getMap().containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return getMap().containsValue(value); + } + + @Override + public V get(Object key) { + return getMap().get(key); + } + + @Override + public V put(K key, V value) { + return getMap().put(key, value); + } + + @Override + public V remove(Object key) { + return getMap().remove(key); + } + + @Override + public void putAll(Map<? extends K, ? extends V> m) { + getMap().putAll(m); + } + + @Override + public void clear() { + getMap().clear(); + } + + @Override + public Entry<K, V> lowerEntry(K key) { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).lowerEntry(key); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public K lowerKey(K key) { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).lowerKey(key); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public Entry<K, V> floorEntry(K key) { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).floorEntry(key); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public K floorKey(K key) { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).floorKey(key); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public Entry<K, V> ceilingEntry(K key) { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).ceilingEntry(key); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public K ceilingKey(K key) { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).ceilingKey(key); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public Entry<K, V> higherEntry(K key) { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).higherEntry(key); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public K higherKey(K key) { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).higherKey(key); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public Entry<K, V> firstEntry() { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).firstEntry(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public Entry<K, V> lastEntry() { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).lastEntry(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public Entry<K, V> pollFirstEntry() { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).pollFirstEntry(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public Entry<K, V> pollLastEntry() { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).pollLastEntry(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public ConcurrentNavigableMap<K, V> descendingMap() { + if (getMap() instanceof NavigableMap) return ((ConcurrentNavigableMap<K,V>) getMap()).descendingMap(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public NavigableSet<K> navigableKeySet() { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).navigableKeySet(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public NavigableSet<K> descendingKeySet() { + if (getMap() instanceof NavigableMap) return ((NavigableMap<K,V>) getMap()).descendingKeySet(); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public ConcurrentNavigableMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { + if (getMap() instanceof NavigableMap) + return ((ConcurrentNavigableMap<K,V>) getMap()).subMap(fromKey, fromInclusive, toKey, toInclusive); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public ConcurrentNavigableMap<K, V> headMap(K toKey, boolean inclusive) { + if (getMap() instanceof NavigableMap) + return ((ConcurrentNavigableMap<K,V>) getMap()).headMap(toKey, inclusive); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public ConcurrentNavigableMap<K, V> tailMap(K fromKey, boolean inclusive) { + if (getMap() instanceof NavigableMap) + return ((ConcurrentNavigableMap<K,V>) getMap()).tailMap(fromKey, inclusive); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public V putIfAbsent(K key, V value) { + if (getMap() instanceof ConcurrentMap) + return ((ConcurrentMap<K,V>) getMap()).putIfAbsent(key, value); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public boolean remove(Object key, Object value) { + if (getMap() instanceof ConcurrentMap) + return ((ConcurrentMap<K,V>) getMap()).remove(key, value); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public boolean replace(K key, V oldValue, V newValue) { + if (getMap() instanceof ConcurrentMap) + return ((ConcurrentMap<K,V>) getMap()).replace(key, oldValue, newValue); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + @Override + public V replace(K key, V value) { + if (getMap() instanceof ConcurrentMap) + return ((ConcurrentMap<K,V>) getMap()).replace(key, value); + throw new UnsupportedOperationException("Unsupported Interface Method."); + } + + /** + * @return the map + */ + public Map<K,V> getMap() { + return map; + } + + /** + * @return the built + */ + public boolean isBuilt() { + return built; + } + + @Override + Map<K, V> build() throws InstantiationException, IllegalAccessException, ObjectStreamException { + throw new UnsupportedOperationException("Not supported yet."); + } + + /** + * @serialData + * @return the type + */ + abstract Ref getType(); + + /** + * @serialData + * @return the collection + */ + abstract Map<Referrer<K>,Referrer<V>> getRefMap(); + + /** + * @serialData + * @return the class + */ + abstract Class getClazz(); + +} Propchange: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveFixForMapCircularReferences.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java?rev=1184796&r1=1184795&r2=1184796&view=diff ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java (original) +++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java Sun Oct 16 11:31:55 2011 @@ -28,7 +28,7 @@ import java.util.Iterator; * @author peter */ abstract class ReferenceCollectionRefreshAfterSerialization<T> - extends ReadResolveCircularReferencesFix<T> { + extends ReadResolveFixCollectionCircularReferences<T> { ReferenceCollectionRefreshAfterSerialization() { } Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java?rev=1184796&r1=1184795&r2=1184796&view=diff ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java (original) +++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java Sun Oct 16 11:31:55 2011 @@ -20,7 +20,10 @@ package org.apache.river.impl.util; import java.lang.ref.Reference; +import java.util.Random; import java.util.concurrent.ConcurrentMap; +import java.util.logging.Level; +import java.util.logging.Logger; /** * A referenced hash map, that encapsulates and utilises any ConcurrentMap Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMapSerialData.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMapSerialData.java?rev=1184796&view=auto ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMapSerialData.java (added) +++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMapSerialData.java Sun Oct 16 11:31:55 2011 @@ -0,0 +1,27 @@ +/* + * 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; + +/** + * + * @author peter + */ +public class ReferenceMapSerialData<K,V> { + +} Propchange: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMapSerialData.java ------------------------------------------------------------------------------ svn:eol-style = native Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceMap.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceMap.java?rev=1184796&view=auto ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceMap.java (added) +++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceMap.java Sun Oct 16 11:31:55 2011 @@ -0,0 +1,41 @@ +/* + * 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.io.ObjectStreamException; +import java.util.AbstractMap; +import java.util.Map; + +/** + * + * @author peter + */ +abstract class SerializationOfReferenceMap<K,V> extends AbstractMap<K,V>{ + + static <K,V> SerializationOfReferenceMap<K,V> create( + Class clazz, + Map<Referrer<K>, Referrer<V>> refmap, + Ref type) throws InstantiationException, IllegalAccessException{ + return null; + // return new ReferenceMapSerialData<K,V>(clazz, refmap, type); + } + + abstract Map<K,V> build() throws InstantiationException, + IllegalAccessException, ObjectStreamException; +} Propchange: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceMap.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java?rev=1184796&r1=1184795&r2=1184796&view=diff ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java (original) +++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java Sun Oct 16 11:31:55 2011 @@ -23,7 +23,6 @@ import java.io.ObjectInputStream; import java.io.ObjectStreamException; import java.io.Serializable; import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; /** * Implemented as per Ref.STRONG Added: river/jtsk/skunk/peterConcurrentPolicy/test/lib/imunit-1.3.jar URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/lib/imunit-1.3.jar?rev=1184796&view=auto ============================================================================== Binary file - no diff available. Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/lib/imunit-1.3.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream 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=1184796&r1=1184795&r2=1184796&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 Sun Oct 16 11:31:55 2011 @@ -64,62 +64,67 @@ public class IsolateTest { executor.shutdownNow(); executor = null; } + + @Test + public void dummy(){ + System.out.println("IsolateTest disabled"); + } /** * Test of process method, of class IsolatedExecutor. * This test leaves stale threads consuming CPU. */ - @Test - public void stackOverflow() { - System.out.println("Stack overflow"); - Callable<Object> task = new StackOverflowTask(); - long timeout = 10L; - Exception e = null; - Future result = executor.submit(task); - try { - result.get(); - } catch ( Exception ex ){ - e = ex; - ex.printStackTrace(System.out); - } - assertTrue((e instanceof Exception)); - // TODO review the generated test code and remove the default call to fail. - } - - /** - * Test of process method, of class IsolatedExecutor. - */ - @Test - public void arrayListOverflow() { - System.out.println("ArrayList overflow"); -// This leaves stale threads consuming CPU. - Callable<Object> task = new ArrayListOverflow(); - long timeout = 120L; - Exception e = null; - try { - executor.process(task, timeout, TimeUnit.SECONDS); - } catch ( Exception ex ){ - e = ex; - ex.printStackTrace(System.out); - if (ex instanceof ExecutionException){ - Throwable t = ((ExecutionException)ex).getCause(); - if (t instanceof Error) executor = new IsolatedExecutor(); - } - } - assertTrue((e instanceof Exception)); - Callable<Boolean> task2 = new PrintTask(); - Boolean result = Boolean.FALSE; - try { - result = (Boolean) executor.process(task2, timeout, TimeUnit.MINUTES); - } catch (ExecutionException ex) { - - } catch (InterruptedException ex) { - - } catch (TimeoutException ex) { - - } - assertTrue(result); +// @Test +// public void stackOverflow() { +// System.out.println("Stack overflow"); +// Callable<Object> task = new StackOverflowTask(); +// long timeout = 10L; +// Exception e = null; +// Future result = executor.submit(task); +// try { +// result.get(); +// } catch ( Exception ex ){ +// e = ex; +// ex.printStackTrace(System.out); +// } +// assertTrue((e instanceof Exception)); // // TODO review the generated test code and remove the default call to fail. - } +// } +// +// /** +// * Test of process method, of class IsolatedExecutor. +// */ +// @Test +// public void arrayListOverflow() { +// System.out.println("ArrayList overflow"); +//// This leaves stale threads consuming CPU. +// Callable<Object> task = new ArrayListOverflow(); +// long timeout = 120L; +// Exception e = null; +// try { +// executor.process(task, timeout, TimeUnit.SECONDS); +// } catch ( Exception ex ){ +// e = ex; +// ex.printStackTrace(System.out); +// if (ex instanceof ExecutionException){ +// Throwable t = ((ExecutionException)ex).getCause(); +// if (t instanceof Error) executor = new IsolatedExecutor(); +// } +// } +// assertTrue((e instanceof Exception)); +// Callable<Boolean> task2 = new PrintTask(); +// Boolean result = Boolean.FALSE; +// try { +// result = (Boolean) executor.process(task2, timeout, TimeUnit.MINUTES); +// } catch (ExecutionException ex) { +// +// } catch (InterruptedException ex) { +// +// } catch (TimeoutException ex) { +// +// } +// assertTrue(result); +//// // TODO review the generated test code and remove the default call to fail. +// } } \ No newline at end of file Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueConcurrencyTest.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueConcurrencyTest.java?rev=1184796&view=auto ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueConcurrencyTest.java (added) +++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueConcurrencyTest.java Sun Oct 16 11:31:55 2011 @@ -0,0 +1,134 @@ +/* + * University of Illinois/NCSA + * Open Source License + * + * Copyright (c) 2011, University of Illinois at Urbana-Champaign. + * All rights reserved. + * + * Developed by: + * + * The IMUnit Project Team: + * Vilas Jagannath ([email protected]) + * Milos Gligoric ([email protected]) + * Dongyun Jin ([email protected]) + * Qingzhou Luo ([email protected]) + * Grigore Rosu ([email protected]) + * Darko Marinov ([email protected]) + * University of Illinois at Urbana-Champaign + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal with the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimers. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimers in the documentation and/or other materials provided + * with the distribution. + * + * * Neither the names of the IMUnit project team, the University of + * Illinois at Urbana-Champaign, nor the names of its contributors + * may be used to endorse or promote products derived from this + * Software without specific prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. + */ + +package org.apache.river.impl.util; + +import static edu.illinois.imunit.IMUnit.fireEvent; +import static edu.illinois.imunit.IMUnit.schAssertEquals; +import edu.illinois.imunit.IMUnitRunner; +import edu.illinois.imunit.Schedule; +import edu.illinois.imunit.Schedules; +import static org.junit.Assert.assertEquals; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * This class demonstrates how multithreaded unit tests can be written using IMUnit. + * The original demonstration class was suitable, with some minor modification + * to test ReferenceBlockingQueue + * + * @author Vilas Jagannath <[email protected]> + * + */ +@RunWith(IMUnitRunner.class) +public class ReferenceBlockingQueueConcurrencyTest{ + + private BlockingQueue<Integer> queue; + + @Before + public void setup() { + queue = RC.blockingQueue(new ArrayBlockingQueue<Referrer<Integer>>(1), Ref.SOFT); + } + + @Test + @Schedule("finishOffer2->startingTake") + public void testOfferOfferTake() throws InterruptedException { + performParallelOfferssAndTake(); + assertEquals(0, queue.size()); + } + + @Test + @Schedule("finishOffer1->startingTake,finishTake->startingOffer2") + public void testOfferTakeOffer() throws InterruptedException { + performParallelOfferssAndTake(); + assertEquals(1, queue.size()); + } + + @Test + @Schedule("[startingTake]->startingOffer1,finishTake->startingOffer2") + public void testTakeBlockOfferTakeFinishOffer() throws InterruptedException { + performParallelOfferssAndTake(); + assertEquals(1, queue.size()); + } + + @Test + @Schedules({ @Schedule(name = "offer-offer-take", value = "finishOffer2->startingTake"), + @Schedule(name = "offer-take-offer", value = "finishOffer1->startingTake,finishTake->startingOffer2"), + @Schedule(name = "takeBlock-offer-takeFinish-offer", value = "[startingTake]->startingOffer1,finishTake->startingOffer2") }) + public void testAllThreeSchedules() throws InterruptedException { + performParallelOfferssAndTake(); + schAssertEquals("offer-offer-take", 0, queue.size()); + schAssertEquals("offer-take-offer", 1, queue.size()); + schAssertEquals("takeBlock-offer-takeFinish-offer", 1, queue.size()); + } + + private void performParallelOfferssAndTake() throws InterruptedException { + Thread offerThread = new Thread(new Runnable() { + @Override + public void run() { + fireEvent("startingOffer1"); + queue.offer(42); + fireEvent("finishOffer1"); + fireEvent("startingOffer2"); + queue.offer(47); + fireEvent("finishOffer2"); + } + }); + offerThread.start(); + fireEvent("startingTake"); + assertEquals(42, (int) queue.take()); + fireEvent("finishTake"); + offerThread.join(); + } + +} Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceBlockingQueueConcurrencyTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapConcurrencyTest.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapConcurrencyTest.java?rev=1184796&view=auto ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapConcurrencyTest.java (added) +++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapConcurrencyTest.java Sun Oct 16 11:31:55 2011 @@ -0,0 +1,168 @@ +/* + * 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 edu.illinois.imunit.Schedules; +import edu.illinois.imunit.Schedule; +import org.junit.Test; +import java.util.concurrent.ConcurrentHashMap; +import org.junit.Before; +import java.util.concurrent.ConcurrentMap; +import edu.illinois.imunit.IMUnitRunner; +import org.junit.runner.RunWith; +import static edu.illinois.imunit.IMUnit.fireEvent; +import static edu.illinois.imunit.IMUnit.schAssertEquals; +import static edu.illinois.imunit.IMUnit.schAssertNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * + * @author Peter Firmstone. + */ +@RunWith(IMUnitRunner.class) +public class ReferenceConcurrentMapConcurrencyTest { + private ConcurrentMap<Integer,String> map; + private ConcurrentMap<Referrer<Integer>,Referrer<String>> internal; + private String t1, t2, t3, t4; + @Before + public void setup() { + internal = new ConcurrentHashMap<Referrer<Integer>, Referrer<String>>(); + map = RC.concurrentMap( internal, Ref.STRONG, Ref.STRONG); + t1 = null; + t2 = null; + t3 = null; + t4 = null; + } + + @Test + @Schedule("startingPutIfAbsent1->finishPutIfAbsent1,finishPutIfAbsent1->startingPutIfAbsent2,finishPutIfAbsent1->startingPutIfAbsent3") + public void testPut() throws InterruptedException { + System.out.println("test putIfAbsent"); + performParallelPutIfAbsent(); + assertEquals("Forty-two", map.get(42)); + } + + @Test + @Schedule("startingPut1->finishPut1,finishPut1->startingClear1,startingClear1->finishClear1,finishClear1->startingPut2,finishClear1->startingPut3,finishClear1->startingPut4") + public void testPutClearPut() throws InterruptedException { + String exp = "Forty-seven"; + System.out.println("test put Clear put"); + putClearMultiPut(); + assertEquals(exp, map.get(new Integer(42))); + assertNull(t1); + boolean success = t2 == null? t3.equals(exp) && t4.equals(exp) : + t3 == null ? t2.equals(exp) && t4.equals(exp): + t4 == null ? t2.equals(t3) && t3.equals(exp): false; + assertTrue(success); + } + + private void performParallelPutIfAbsent() throws InterruptedException { + Thread putIfAbsentThread1 = new Thread(new Runnable() { + @Override + public void run() { + fireEvent("startingPutIfAbsent1"); + map.putIfAbsent(42, "Forty-two"); + fireEvent("finishPutIfAbsent1"); + } + }); + Thread putIfAbsentThread2 = new Thread(new Runnable() { + @Override + public void run() { + fireEvent("startingPutIfAbsent2"); + map.putIfAbsent(42, "Forty-seven"); + fireEvent("finishPutIfAbsent2"); + } + }); + Thread putIfAbsentThread3 = new Thread(new Runnable() { + @Override + public void run() { + fireEvent("startingPutIfAbsent3"); + map.putIfAbsent(42, "Fifty-one"); + fireEvent("finishPutIfAbsent3"); + } + }); + putIfAbsentThread1.start(); + putIfAbsentThread2.start(); + putIfAbsentThread3.start(); + putIfAbsentThread1.join(); + putIfAbsentThread2.join(); + putIfAbsentThread3.join(); + } + + private void putClearMultiPut() throws InterruptedException { + Thread thread1 = new Thread(new Runnable() { + @Override + public void run() { + fireEvent("startingPut1"); + t1 = map.putIfAbsent(new Integer(42), "Forty-two"); + fireEvent("finishPut1"); + } + }); + Thread thread2 = new Thread(new Runnable() { + @Override + public void run() { + fireEvent("startingPut2"); + t2 = map.putIfAbsent(new Integer(42), "Forty-seven"); + fireEvent("finishPut2"); + } + }); + Thread thread3 = new Thread(new Runnable() { + @Override + public void run() { + fireEvent("startingPut3"); + t3 = map.putIfAbsent(new Integer(42), "Forty-seven"); + fireEvent("finishPut3"); + } + }); + Thread thread4 = new Thread(new Runnable() { + @Override + public void run() { + fireEvent("startingPut4"); + t4 = map.putIfAbsent(new Integer(42), "Forty-seven"); + fireEvent("finishPut4"); + } + }); + Thread thread5 = new Thread(new Runnable() { + @Override + public void run() { + fireEvent("startingClear1"); + System.out.println("staring clear"); + Referrer<String> ref = internal.get(ReferenceFactory.singleUseForLookup(new Integer(42), Ref.STRONG)); + assertNotNull( ref); + ref.clear(); + assertNull( ref.get()); + fireEvent("finishClear1"); + } + }); + thread1.start(); + thread2.start(); + thread3.start(); + thread4.start(); + thread5.start(); + thread1.join(); + thread2.join(); + thread3.join(); + thread4.join(); + thread5.join(); + } + +} Propchange: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapConcurrencyTest.java ------------------------------------------------------------------------------ svn:eol-style = native Copied: river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapTest.java (from r1180519, 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/ReferenceConcurrentMapTest.java?p2=river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapTest.java&p1=river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java&r1=1180519&r2=1184796&rev=1184796&view=diff ============================================================================== --- river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ConcurrentReferenceMapTest.java (original) +++ river/jtsk/skunk/peterConcurrentPolicy/test/src/org/apache/river/impl/util/ReferenceConcurrentMapTest.java Sun Oct 16 11:31:55 2011 @@ -32,12 +32,12 @@ import static org.junit.Assert.*; * * @author Peter Firmstone. */ -public class ConcurrentReferenceMapTest { +public class ReferenceConcurrentMapTest { private ConcurrentMap<Integer, String> instance; // strong references private Integer i1, i2, i3, i4, i5; - public ConcurrentReferenceMapTest() { + public ReferenceConcurrentMapTest() { } @BeforeClass
