@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2014 the original author or authors .
* Copyright 2002 - 2015 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -18,6 +18,7 @@ package org.springframework.messaging.simp.broker;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.Iterator ;
import java.util.List ;
import org.junit.Before ;
@ -31,6 +32,7 @@ import org.springframework.util.MultiValueMap;
import static org.junit.Assert.* ;
/ * *
* Test fixture for { @link org . springframework . messaging . simp . broker . DefaultSubscriptionRegistry } .
*
@ -326,6 +328,23 @@ public class DefaultSubscriptionRegistryTests {
assertEquals ( "Expected no elements " + actual , 0 , actual . size ( ) ) ;
}
// SPR-12665
@Test
public void findSubscriptionsReturnsMapSafeToIterate ( ) throws Exception {
this . registry . registerSubscription ( subscribeMessage ( "sess1" , "1" , "/foo" ) ) ;
this . registry . registerSubscription ( subscribeMessage ( "sess2" , "1" , "/foo" ) ) ;
MultiValueMap < String , String > subscriptions = this . registry . findSubscriptions ( message ( "/foo" ) ) ;
assertEquals ( 2 , subscriptions . size ( ) ) ;
Iterator iterator = subscriptions . entrySet ( ) . iterator ( ) ;
iterator . next ( ) ;
this . registry . registerSubscription ( subscribeMessage ( "sess3" , "1" , "/foo" ) ) ;
iterator . next ( ) ;
// no ConcurrentModificationException
}
private Message < ? > subscribeMessage ( String sessionId , String subscriptionId , String destination ) {
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor . create ( SimpMessageType . SUBSCRIBE ) ;