BUG-8156 : conflicting listener fix 26/62526/4
authorDana Kutenicsova <dana.kutenics@gmail.com>
Sun, 6 Aug 2017 10:18:35 +0000 (12:18 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 28 Sep 2017 20:39:16 +0000 (20:39 +0000)
In case another session listener is in conflict
with the existing one, close the new listener.

Change-Id: I1a594c3876eb1d28133dcc08b31f38deb5ceb27a
Signed-off-by: Dana Kutenicsova <dana.kutenics@gmail.com>
(cherry picked from commit e8c3219416917322b69c473b9498dfd60ccad352)

pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/ServerSessionManager.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListenerTest.java

index 4cb9c6e27f946ce483cb999ba44f400d6255f2fa..e9d7f37f955e2cb9d94b998e1f03d8c5e4852358 100755 (executable)
@@ -146,8 +146,12 @@ final class ServerSessionManager implements PCEPSessionListenerFactory, Topology
             LOG.debug("Created topology node {} for id {} at {}", ret, id, ret.getNodeId());
             this.state.put(id, ret);
         }
-        // FIXME: else check for conflicting session
-
+        // if another listener requests the same session, close it
+        final TopologySessionListener existingSessionListener = this.nodes.get(id);
+        if (existingSessionListener != null && !sessionListener.equals(existingSessionListener)) {
+            LOG.error("New session listener {} is in conflict with existing session listener {} on node {}, closing the existing one.", existingSessionListener, sessionListener, id);
+            existingSessionListener.close();
+        }
         ret.taken(retrieveNode);
         this.nodes.put(id, sessionListener);
         LOG.debug("Node {} bound to listener {}", id, sessionListener);
index 37a5840edb08e60113216680410cc3d766f2b6a8..24c9888cd4d04d56a2d8998e631a65eb9aec2400 100755 (executable)
@@ -450,6 +450,15 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         assertTrue(this.receivedMsgs.get(this.receivedMsgs.size() - 1) instanceof Close);
     }
 
+    @Test
+    public void testConflictingListeners() throws Exception {
+        this.listener.onSessionUp(this.session);
+        assertFalse(this.session.isClosed());
+        Stateful07TopologySessionListener conflictingListener = (Stateful07TopologySessionListener) getSessionListener();
+        conflictingListener.onSessionUp(this.session);
+        assertTrue(this.session.isClosed());
+    }
+
     @Test
     public void testOnSessionTermination() throws Exception {
         this.listener.onSessionUp(this.session);