|
20 | 20 | import static org.junit.jupiter.api.Assertions.assertNull; |
21 | 21 | import static org.junit.jupiter.api.Assertions.assertSame; |
22 | 22 |
|
| 23 | +import java.util.ArrayList; |
23 | 24 | import java.util.Arrays; |
24 | 25 | import java.util.Collections; |
25 | 26 | import java.util.HashSet; |
| 27 | +import java.util.List; |
26 | 28 | import java.util.Set; |
| 29 | +import java.util.concurrent.ExecutionException; |
| 30 | +import java.util.concurrent.ExecutorService; |
| 31 | +import java.util.concurrent.Executors; |
| 32 | +import java.util.concurrent.Future; |
| 33 | +import java.util.concurrent.TimeUnit; |
27 | 34 |
|
| 35 | +import org.apache.commons.jxpath.DynamicPropertyHandler; |
28 | 36 | import org.junit.jupiter.api.Test; |
29 | 37 |
|
30 | 38 | class ValueUtilsTest { |
@@ -87,4 +95,41 @@ void testGetValueFromSetNegativeIndex() { |
87 | 95 | void testGetValueFromSetTooSmall() { |
88 | 96 | assertNull(ValueUtils.getValue(Collections.EMPTY_SET, 2)); |
89 | 97 | } |
| 98 | + |
| 99 | + @Test |
| 100 | + void testGetDynamicPropertyHandlerConcurrently() throws InterruptedException, ExecutionException { |
| 101 | + // This test ensures that ValueUtils::getDynamicPropertyHandler can be accessed concurrently |
| 102 | + // It does not assert any specific behavior, but rather ensures that no exceptions are thrown on concurrent access |
| 103 | + int nThreads = 200; // Number of threads to simulate concurrent access |
| 104 | + List<Future<?>> futures = new ArrayList<>(); |
| 105 | + ExecutorService threadPool = Executors.newFixedThreadPool(nThreads); |
| 106 | + for (int i = 0; i < nThreads; i++) { |
| 107 | + futures.add(threadPool.submit(() -> ValueUtils.getDynamicPropertyHandler(DummyHandler.class))); |
| 108 | + } |
| 109 | + |
| 110 | + threadPool.shutdown(); |
| 111 | + threadPool.awaitTermination(1, TimeUnit.SECONDS); |
| 112 | + |
| 113 | + for (Future<?> future : futures) { |
| 114 | + future.get(); // This will throw if any thread threw |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + public static class DummyHandler implements DynamicPropertyHandler { |
| 119 | + |
| 120 | + @Override |
| 121 | + public Object getProperty(Object object, String propertyName) { |
| 122 | + return null; |
| 123 | + } |
| 124 | + |
| 125 | + @Override |
| 126 | + public String[] getPropertyNames(Object object) { |
| 127 | + return new String[0]; |
| 128 | + } |
| 129 | + |
| 130 | + @Override |
| 131 | + public void setProperty(Object object, String propertyName, Object value) { |
| 132 | + |
| 133 | + } |
| 134 | + } |
90 | 135 | } |
0 commit comments