MgcpLocalConnection extends AbstractMgcpConnection { @Override public String halfOpen(LocalConnectionOptions options) throws MgcpConnectionException { synchronized (this.stateLock) { switch (this.state) { case CLOSED: this.state = MgcpConnectionState.HALF_OPEN; if(log.isDebugEnabled()) { log.debug("Connection " + getHexIdentifier() + " state is " + this.state.name()); } if (this.halfOpenTimeout > 0) { expireIn(this.halfOpenTimeout); } break; default: throw new MgcpConnectionException("Cannot half-open connection " + this.getHexIdentifier() + " because state is " + this.state.name()); } } return null; } MgcpLocalConnection(int identifier, int callId, int halfOpenTimeout, int openTimeout, MgcpEventProvider eventProvider, ChannelsManager channelProvider, ListeningScheduledExecutorService executor);  MgcpLocalConnection(int identifier, int callId, int timeout, MgcpEventProvider eventProvider, ChannelsManager channelProvider, ListeningScheduledExecutorService executor);  MgcpLocalConnection(int identifier, int callId, MgcpEventProvider eventProvider, ChannelsManager channelProvider, ListeningScheduledExecutorService executor); @Override boolean isLocal(); @Override String halfOpen(LocalConnectionOptions options); @Override String open(String sdp); @Override String renegotiate(String sdp); void join(MgcpLocalConnection otherConnection); @Override void close(); @Override void setMode(ConnectionMode mode); @Override AudioComponent getAudioComponent(); @Override OOBComponent getOutOfBandComponent();  }
@Test public void testMaxDurationTimerWhenHalfOpen() throws MgcpConnectionException, InterruptedException { final int callId = 1; final int identifier = 1; final int halfOpenTimeout = 2; final int openTimeout = 3; final MgcpEventObserver observer = mock(MgcpEventObserver.class); final ArgumentCaptor<RtpTimeoutEvent> timeoutCaptor = ArgumentCaptor.forClass(RtpTimeoutEvent.class); final LocalDataChannel dataChannel = mock(LocalDataChannel.class); final MgcpEventProvider eventProvider = mock(MgcpEventProvider.class); final ChannelsManager channelProvider = mock(ChannelsManager.class); when(channelProvider.getLocalChannel()).thenReturn(dataChannel); final MgcpLocalConnection connection = new MgcpLocalConnection(identifier, callId, halfOpenTimeout, openTimeout, eventProvider, channelProvider, this.executor); connection.observe(observer); connection.halfOpen(new LocalConnectionOptions()); Thread.sleep(halfOpenTimeout * 1000 + 200); assertEquals(MgcpConnectionState.CLOSED, connection.state); verify(observer, only()).onEvent(eq(connection), timeoutCaptor.capture()); assertNotNull(timeoutCaptor.getValue()); assertEquals(halfOpenTimeout, timeoutCaptor.getValue().getTimeout()); }
@Test public void testInactiveHalfOpenTimer() throws MgcpConnectionException, InterruptedException { final int identifier = 1; final int halfOpenTimeout = 0; final int openTimeout = 4; final MgcpEventObserver observer = mock(MgcpEventObserver.class); final ArgumentCaptor<RtpTimeoutEvent> timeoutCaptor = ArgumentCaptor.forClass(RtpTimeoutEvent.class); final LocalDataChannel dataChannel = mock(LocalDataChannel.class); final ChannelsManager channelProvider = mock(ChannelsManager.class); final MgcpEventProvider eventProvider = mock(MgcpEventProvider.class); when(channelProvider.getLocalChannel()).thenReturn(dataChannel); final MgcpLocalConnection connection = new MgcpLocalConnection(identifier, halfOpenTimeout, openTimeout, eventProvider, channelProvider, this.executor); connection.observe(observer); connection.halfOpen(new LocalConnectionOptions()); Thread.sleep(openTimeout * 1000); assertEquals(MgcpConnectionState.HALF_OPEN, connection.state); verify(observer, never()).onEvent(eq(connection), timeoutCaptor.capture()); }