|
21 | 21 | import java.util.Iterator;
|
22 | 22 | import java.util.List;
|
23 | 23 | import java.util.Map;
|
24 |
| -import java.util.concurrent.CountDownLatch; |
25 |
| -import java.util.concurrent.TimeUnit; |
26 |
| -import java.util.concurrent.atomic.AtomicReference; |
27 | 24 |
|
28 | 25 | import org.junit.Test;
|
29 | 26 |
|
30 | 27 | import org.springframework.messaging.Message;
|
31 | 28 | import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
32 | 29 | import org.springframework.messaging.simp.SimpMessageType;
|
33 | 30 | import org.springframework.messaging.support.MessageBuilder;
|
34 |
| -import org.springframework.util.AntPathMatcher; |
35 | 31 | import org.springframework.util.MultiValueMap;
|
36 |
| -import org.springframework.util.PathMatcher; |
37 | 32 |
|
38 |
| -import static org.junit.Assert.*; |
| 33 | +import static org.junit.Assert.assertEquals; |
| 34 | +import static org.junit.Assert.assertNotNull; |
39 | 35 |
|
40 | 36 | /**
|
41 | 37 | * Test fixture for
|
@@ -402,37 +398,22 @@ public void findSubscriptionsReturnsMapSafeToIterateIncludingValues() throws Exc
|
402 | 398 | // no ConcurrentModificationException
|
403 | 399 | }
|
404 | 400 |
|
405 |
| - @Test // SPR-13204 |
406 |
| - public void findSubscriptionsWithConcurrentUnregisterAllSubscriptions() throws Exception { |
407 |
| - final CountDownLatch iterationPausedLatch = new CountDownLatch(1); |
408 |
| - final CountDownLatch iterationResumeLatch = new CountDownLatch(1); |
409 |
| - final CountDownLatch iterationDoneLatch = new CountDownLatch(1); |
410 |
| - |
411 |
| - PathMatcher pathMatcher = new PausingPathMatcher(iterationPausedLatch, iterationResumeLatch); |
412 |
| - this.registry.setPathMatcher(pathMatcher); |
| 401 | + @Test // SPR-13555 |
| 402 | + public void cacheLimitExceeded() throws Exception { |
| 403 | + this.registry.setCacheLimit(1); |
413 | 404 | this.registry.registerSubscription(subscribeMessage("sess1", "1", "/foo"));
|
414 |
| - this.registry.registerSubscription(subscribeMessage("sess2", "1", "/foo")); |
415 |
| - |
416 |
| - AtomicReference<MultiValueMap<String, String>> subscriptions = new AtomicReference<>(); |
417 |
| - new Thread(() -> { |
418 |
| - subscriptions.set(registry.findSubscriptions(createMessage("/foo"))); |
419 |
| - iterationDoneLatch.countDown(); |
420 |
| - }).start(); |
| 405 | + this.registry.registerSubscription(subscribeMessage("sess1", "2", "/bar")); |
421 | 406 |
|
422 |
| - assertTrue(iterationPausedLatch.await(10, TimeUnit.SECONDS)); |
| 407 | + assertEquals(1, this.registry.findSubscriptions(createMessage("/foo")).size()); |
| 408 | + assertEquals(1, this.registry.findSubscriptions(createMessage("/bar")).size()); |
423 | 409 |
|
424 |
| - this.registry.unregisterAllSubscriptions("sess1"); |
425 |
| - this.registry.unregisterAllSubscriptions("sess2"); |
426 |
| - |
427 |
| - iterationResumeLatch.countDown(); |
428 |
| - assertTrue(iterationDoneLatch.await(10, TimeUnit.SECONDS)); |
| 410 | + this.registry.registerSubscription(subscribeMessage("sess2", "1", "/foo")); |
| 411 | + this.registry.registerSubscription(subscribeMessage("sess2", "2", "/bar")); |
429 | 412 |
|
430 |
| - MultiValueMap<String, String> result = subscriptions.get(); |
431 |
| - assertNotNull(result); |
432 |
| - assertEquals(0, result.size()); |
| 413 | + assertEquals(2, this.registry.findSubscriptions(createMessage("/foo")).size()); |
| 414 | + assertEquals(2, this.registry.findSubscriptions(createMessage("/bar")).size()); |
433 | 415 | }
|
434 | 416 |
|
435 |
| - |
436 | 417 | private Message<?> createMessage(String destination) {
|
437 | 418 | SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
|
438 | 419 | accessor.setDestination(destination);
|
@@ -468,35 +449,4 @@ private List<String> sort(List<String> list) {
|
468 | 449 | return list;
|
469 | 450 | }
|
470 | 451 |
|
471 |
| - |
472 |
| - /** |
473 |
| - * An extension of AntPathMatcher with a pair of CountDownLatches to pause |
474 |
| - * while matching, allowing another thread to something, and resume when the |
475 |
| - * other thread signals it's okay to do so. |
476 |
| - */ |
477 |
| - private static class PausingPathMatcher extends AntPathMatcher { |
478 |
| - |
479 |
| - private final CountDownLatch iterationPausedLatch; |
480 |
| - |
481 |
| - private final CountDownLatch iterationResumeLatch; |
482 |
| - |
483 |
| - public PausingPathMatcher(CountDownLatch iterationPausedLatch, CountDownLatch iterationResumeLatch) { |
484 |
| - this.iterationPausedLatch = iterationPausedLatch; |
485 |
| - this.iterationResumeLatch = iterationResumeLatch; |
486 |
| - } |
487 |
| - |
488 |
| - @Override |
489 |
| - public boolean match(String pattern, String path) { |
490 |
| - try { |
491 |
| - this.iterationPausedLatch.countDown(); |
492 |
| - assertTrue(this.iterationResumeLatch.await(10, TimeUnit.SECONDS)); |
493 |
| - return super.match(pattern, path); |
494 |
| - } |
495 |
| - catch (InterruptedException ex) { |
496 |
| - ex.printStackTrace(); |
497 |
| - return false; |
498 |
| - } |
499 |
| - } |
500 |
| - } |
501 |
| - |
502 | 452 | }
|
0 commit comments