ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1572907 - in /ace/trunk/org.apache.ace.client.repository: src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java test/org/apache/ace/client/repository/impl/ModelTest.java
Date Fri, 28 Feb 2014 10:28:12 GMT
Author: marrs
Date: Fri Feb 28 10:28:11 2014
New Revision: 1572907

URL: http://svn.apache.org/r1572907
Log:
ACE-464 Improved the code, added a test to ensure we did not introduce concurrency issues.

Modified:
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
    ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ModelTest.java

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java?rev=1572907&r1=1572906&r2=1572907&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
Fri Feb 28 10:28:11 2014
@@ -19,11 +19,10 @@
 package org.apache.ace.client.repository.impl;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -55,8 +54,8 @@ abstract class ObjectRepositoryImpl<I ex
     // for thread-safety
     protected final ReadWriteLock m_lock = new ReentrantReadWriteLock();
 
-    private final List<T> m_repo = new CopyOnWriteArrayList<T>();
-    private final Map<String, T> m_index = new ConcurrentHashMap<String, T>();
+    private final List<T> m_repo = new ArrayList<T>();
+    private final Map<String, T> m_index = new HashMap<String, T>();
     private final ChangeNotifier m_notifier;
     private final String m_xmlNode;
     private final RepositoryConfiguration m_repoConfig;

Modified: ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ModelTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ModelTest.java?rev=1572907&r1=1572906&r2=1572907&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ModelTest.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ModelTest.java
Fri Feb 28 10:28:11 2014
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -65,7 +66,7 @@ import org.testng.annotations.BeforeMeth
 import org.testng.annotations.Test;
 
 /**
- * Test class for the object model used </code>org.apache.ace.client.repository<code>.
+ * Test class for the object model used <code>org.apache.ace.client.repository</code>.
  */
 public class ModelTest {
 
@@ -701,6 +702,33 @@ public class ModelTest {
         assertTrue(repo.contains(target2_v1));
         assertTrue(repo.contains(target2_v2));
     }
+    
+    @Test(groups = { TestUtils.UNIT })
+    public void testConcurrentAccessToObjectRepository() throws Exception {
+        initializeRepositoryAdmin();
+        // adds 10 features
+        for (int i = 0; i < 10; i++) {
+            createBasicFeatureObject("feature-" + i);
+        }
+        // asks for a list
+        List<FeatureObject> list = m_featureRepository.get();
+        // then adds another feature
+        createBasicFeatureObject("feature-X");
+        // and makes sure the returned list still has 10 features, not 11, and not
+        // throwing any concurrent modification exceptions
+        assertEquals(list.size(), 10);
+        Iterator<FeatureObject> iterator = list.iterator();
+        for (int i = 0; i < 10; i++) {
+            assertTrue(iterator.hasNext());
+            assertTrue(iterator.next() != null);
+        }
+        assertFalse(iterator.hasNext());
+        // remove item from the list
+        list.remove(0);
+        // get a new list, ensure there are still 11 features
+        list = m_featureRepository.get();
+        assertEquals(list.size(), 11);
+    }
 
     private ArtifactObject createBasicArtifactObject(String symbolicName) {
         return createBasicArtifactObject(symbolicName, null);



Mime
View raw message