+ this.droppingBGPSessionRegistry.getPeer(remoteIp, to, to, as);
+ } catch (final BGPDocumentedException e) {
+ assertEquals(BGPError.CEASE, e.getError());
+ return;
+ }
+
+ fail("Same peer cannot be connected twice");
+ }
+
+ @Test
+ public void testDuplicateHigerAs() throws Exception {
+ final Ipv4Address from = new Ipv4Address("0.0.0.1");
+ final IpAddress remoteIp = new IpAddress(from);
+ final Ipv4Address to = new Ipv4Address("255.255.255.255");
+ final AsNumber as1 = new AsNumber(1L);
+ final AsNumber as2 = new AsNumber(3L);
+
+ final ReusableBGPPeer session1 = getMockSession();
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
+
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as1);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2);
+ Mockito.verify(session1).releaseConnection();
+ }
+
+ @Test
+ public void testDuplicateLowerAs() throws Exception {
+ final Ipv4Address from = new Ipv4Address("0.0.0.1");
+ final IpAddress remoteIp = new IpAddress(from);
+ final Ipv4Address to = new Ipv4Address("255.255.255.255");
+ final AsNumber as1 = new AsNumber(10L);
+ final AsNumber as2 = new AsNumber(3L);
+
+ final ReusableBGPPeer session1 = getMockSession();
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
+
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as1);
+ try {
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to, as2);