|
37 | 37 |
|
38 | 38 | class ValueUtilsTest { |
39 | 39 |
|
| 40 | + public static class DummyHandler implements DynamicPropertyHandler { |
| 41 | + |
| 42 | + @Override |
| 43 | + public Object getProperty(final Object object, final String propertyName) { |
| 44 | + return null; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public String[] getPropertyNames(final Object object) { |
| 49 | + return new String[0]; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public void setProperty(final Object object, final String propertyName, final Object value) { |
| 54 | + |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void testGetDynamicPropertyHandlerConcurrently() throws InterruptedException, ExecutionException { |
| 60 | + // This test ensures that ValueUtils::getDynamicPropertyHandler can be accessed concurrently |
| 61 | + // It does not assert any specific behavior, but rather ensures that no exceptions are thrown on concurrent access |
| 62 | + final int nThreads = 200; // Number of threads to simulate concurrent access |
| 63 | + final List<Future<?>> futures = new ArrayList<>(); |
| 64 | + final ExecutorService threadPool = Executors.newFixedThreadPool(nThreads); |
| 65 | + for (int i = 0; i < nThreads; i++) { |
| 66 | + futures.add(threadPool.submit(() -> ValueUtils.getDynamicPropertyHandler(DummyHandler.class))); |
| 67 | + } |
| 68 | + |
| 69 | + threadPool.shutdown(); |
| 70 | + threadPool.awaitTermination(1, TimeUnit.SECONDS); |
| 71 | + |
| 72 | + for (final Future<?> future : futures) { |
| 73 | + future.get(); // This will throw if any thread threw |
| 74 | + } |
| 75 | + } |
| 76 | + |
40 | 77 | @Test |
41 | 78 | void testGetValueFromArray() { |
42 | 79 | final Object data = new Object(); |
@@ -95,41 +132,4 @@ void testGetValueFromSetNegativeIndex() { |
95 | 132 | void testGetValueFromSetTooSmall() { |
96 | 133 | assertNull(ValueUtils.getValue(Collections.EMPTY_SET, 2)); |
97 | 134 | } |
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 | | - } |
135 | 135 | } |
0 commit comments