@Test public void testKeepAliveTimerTask() throws Exception { ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); when(sxpConnection.getChannelHandlerContext(SxpConnection.ChannelHandlerContextType.SPEAKER_CNTXT)).thenReturn( ctx); KeepAliveTimerTask timerTask = new KeepAliveTimerTask(sxpConnection, 0); when(sxpConnection.getTimestampUpdateOrKeepAliveMessage()).thenReturn(0l); timerTask.call(); verify(ctx).writeAndFlush(any()); verify(sxpConnection).setTimer(TimerType.KeepAliveTimer, timerTask.getPeriod()); when(sxpConnection.getTimestampUpdateOrKeepAliveMessage()).thenReturn(2 * System.currentTimeMillis()); timerTask.call(); verify(ctx, times(2)).writeAndFlush(any()); verify(sxpConnection, times(2)).setTimer(TimerType.KeepAliveTimer, timerTask.getPeriod()); when(sxpConnection.isVersion4()).thenReturn(false); timerTask.call(); verifyNoMoreInteractions(ctx); verify(sxpConnection, times(2)).setTimer(TimerType.KeepAliveTimer, timerTask.getPeriod()); when(sxpConnection.isVersion4()).thenReturn(true); when(sxpConnection.isStateOn(SxpConnection.ChannelHandlerContextType.SPEAKER_CNTXT)).thenReturn(false); timerTask.call(); verifyNoMoreInteractions(ctx); verify(sxpConnection, times(2)).setTimer(TimerType.KeepAliveTimer, timerTask.getPeriod()); when(sxpConnection.isStateOn(SxpConnection.ChannelHandlerContextType.SPEAKER_CNTXT)).thenReturn(true); when(sxpConnection.isModeSpeaker()).thenReturn(Boolean.FALSE); timerTask.call(); verifyNoMoreInteractions(ctx); verify(sxpConnection, times(2)).setTimer(TimerType.KeepAliveTimer, timerTask.getPeriod()); when(sxpConnection.isVersion4()).thenReturn(Boolean.FALSE); timerTask.call(); verifyNoMoreInteractions(ctx); verify(sxpConnection, times(2)).setTimer(TimerType.KeepAliveTimer, timerTask.getPeriod()); }
public int getPeriod() { return period; }
SxpTimerTask implements Callable<T> { public int getPeriod() { return period; } }
SxpTimerTask implements Callable<T> { public int getPeriod() { return period; } protected  SxpTimerTask(int period); }
SxpTimerTask implements Callable<T> { public int getPeriod() { return period; } protected  SxpTimerTask(int period); int getPeriod(); }
SxpTimerTask implements Callable<T> { public int getPeriod() { return period; } protected  SxpTimerTask(int period); int getPeriod();  }