|
31 | 31 | import java.util.Enumeration;
|
32 | 32 | import java.util.HashMap;
|
33 | 33 | import java.util.Map;
|
| 34 | +import java.util.concurrent.ExecutorService; |
| 35 | +import java.util.concurrent.Executors; |
| 36 | +import java.util.concurrent.TimeUnit; |
34 | 37 | import java.util.concurrent.atomic.AtomicReference;
|
35 | 38 |
|
36 | 39 | import static org.mockito.Mockito.mock;
|
|
40 | 43 | import static org.testng.Assert.assertNotNull;
|
41 | 44 | import static org.testng.Assert.assertNull;
|
42 | 45 | import static org.testng.Assert.assertTrue;
|
| 46 | +import static org.testng.AssertJUnit.fail; |
43 | 47 |
|
44 | 48 | public class AtmosphereRequestTest {
|
45 | 49 | private AtmosphereFramework framework;
|
@@ -351,5 +355,41 @@ public void testWrapMethodWithNullAttributeValue() throws IOException, ServletEx
|
351 | 355 | assertNull(wrappedRequest.getAttribute("org.eclipse.jetty.multipartConfig"), "Attribute value should be null");
|
352 | 356 | }
|
353 | 357 |
|
| 358 | + public class AtmosphereRequestImplTest { |
| 359 | + |
| 360 | + @Test |
| 361 | + public void testGetParameterRaceCondition() throws InterruptedException { |
| 362 | + final Map<String, String[]> queryStrings = Collections.synchronizedMap(new HashMap<>()); |
| 363 | + queryStrings.put("testParam", new String[]{"testValue"}); |
| 364 | + |
| 365 | + AtmosphereRequestImpl.Builder builder = new AtmosphereRequestImpl.Builder(); |
| 366 | + builder.queryStrings(queryStrings); |
| 367 | + |
| 368 | + final AtmosphereRequest request = builder.build(); |
| 369 | + |
| 370 | + Runnable addAndRemove = () -> { |
| 371 | + queryStrings.put("testParam", new String[]{"testValue"}); |
| 372 | + queryStrings.remove("testParam"); |
| 373 | + }; |
| 374 | + |
| 375 | + Runnable getParameter = () -> { |
| 376 | + try { |
| 377 | + request.getParameter("testParam"); |
| 378 | + } catch (NullPointerException e) { |
| 379 | + fail("NullPointerException occurred"); |
| 380 | + } |
| 381 | + }; |
| 382 | + |
| 383 | + ExecutorService executor = Executors.newFixedThreadPool(2); |
| 384 | + for (int i = 0; i < 10000; i++) { |
| 385 | + executor.execute(addAndRemove); |
| 386 | + executor.execute(getParameter); |
| 387 | + } |
| 388 | + |
| 389 | + executor.shutdown(); |
| 390 | + executor.awaitTermination(1, TimeUnit.MINUTES); |
| 391 | + } |
| 392 | + } |
| 393 | + |
354 | 394 |
|
355 | 395 | }
|
0 commit comments