@Test public void testSend() throws Exception { WaitForAsyncUtils.async( () -> { handleAllocationRequest(); handleCreatePermissionRequest(); handleChannelBindRequest(); return null; }); instance.connect().get(5, TimeUnit.SECONDS); InetSocketAddress remotePeerAddress = new InetSocketAddress("93.184.216.34", 1234); CreatePermissionMessage createPermissionMessage = new CreatePermissionMessage(); createPermissionMessage.setAddress(remotePeerAddress); verify(lobbyServerAccessor) .addOnMessageListener( eq(CreatePermissionMessage.class), createPermissionListenerCaptor.capture()); createPermissionListenerCaptor.getValue().accept(createPermissionMessage); byte[] bytes = new byte[1024]; DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length); datagramPacket.setSocketAddress(remotePeerAddress); instance.send(datagramPacket); }
@Test public void testConnect() throws Exception { WaitForAsyncUtils.async( () -> { handleAllocationRequest(); return null; }); InetSocketAddress socketAddress = (InetSocketAddress) instance.connect().get(); assertThat( socketAddress.getAddress().getHostAddress(), is(turnServerSocket.getLocalAddress().getHostAddress())); assertThat(socketAddress.getPort(), is(2222)); verify(scheduledExecutorService).scheduleWithFixedDelay(any(), anyLong(), anyLong(), any()); }
@Test public void testGetRelayAddress() throws Exception { assertThat(instance.getRelayAddress(), nullValue()); WaitForAsyncUtils.async( () -> { handleAllocationRequest(); handleCreatePermissionRequest(); handleChannelBindRequest(); return null; }); instance.connect().get(5, TimeUnit.SECONDS); InetSocketAddress relayAddress = instance.getRelayAddress(); assertThat( relayAddress.getAddress().getHostAddress(), is(turnServerSocket.getLocalAddress().getHostAddress())); assertThat(relayAddress.getPort(), is(2222)); }