You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2022/10/21 13:26:31 UTC

svn commit: r1904762 - in /jackrabbit/trunk/jackrabbit-jcr2spi: pom.xml src/test/java/org/apache/jackrabbit/jcr2spi/hierarchy/ src/test/java/org/apache/jackrabbit/jcr2spi/hierarchy/LinkedEntriesTest.java

Author: reschke
Date: Fri Oct 21 13:26:31 2022
New Revision: 1904762

URL: http://svn.apache.org/viewvc?rev=1904762&view=rev
Log:
JCR-4859: jcr2spi: add test coverage for LinkedEntries

Added:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/hierarchy/
    jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/hierarchy/LinkedEntriesTest.java
Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/pom.xml

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/pom.xml?rev=1904762&r1=1904761&r2=1904762&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/pom.xml Fri Oct 21 13:26:31 2022
@@ -157,6 +157,11 @@
       <artifactId>logback-classic</artifactId>
       <scope>test</scope>
     </dependency>    
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 </project>

Added: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/hierarchy/LinkedEntriesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/hierarchy/LinkedEntriesTest.java?rev=1904762&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/hierarchy/LinkedEntriesTest.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/hierarchy/LinkedEntriesTest.java Fri Oct 21 13:26:31 2022
@@ -0,0 +1,67 @@
+/*
+ * 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.jackrabbit.jcr2spi.hierarchy;
+
+import static org.mockito.Mockito.mock;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.ConcurrentModificationException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import junit.framework.TestCase;
+
+public class LinkedEntriesTest extends TestCase {
+
+    public void testConccurentModification() throws Throwable {
+        try {
+            internalTestConcurrentModification();
+            fail("ConcurrentModificationException expected");
+        } catch (ConcurrentModificationException expected) {
+        }
+    }
+
+    private void internalTestConcurrentModification() throws Throwable {
+        ExecutorService executorService = null;
+        try {
+            executorService = Executors.newFixedThreadPool(100);
+
+            LinkedEntries entries = new LinkedEntries(null, null);
+            Collection<Callable<Object>> futures = new ArrayList<>();
+            for (int i = 0; i < 10000; i++) {
+                NodeEntry nodeEntry = mock(NodeEntry.class);
+                futures.add(() -> entries.getLinkNode(nodeEntry));
+                futures.add(() -> {
+                    entries.add(nodeEntry);
+                    return null;
+                });
+            }
+            for (Future<?> future : executorService.invokeAll(futures)) {
+                try {
+                    future.get();
+                } catch (Exception e) {
+                    throw e.getCause();
+                }
+            }
+        } finally {
+            executorService.shutdown();
+        }
+    }
+}