use of java.net.DatagramPacket in project pinpoint by naver.
the class NetworkAvailabilityCheckPacketFilterTest method testFilter.
@Test
public void testFilter() throws Exception {
SocketAddress localSocketAddress = senderSocket.getLocalSocketAddress();
logger.debug("localSocket:{}", localSocketAddress);
NetworkAvailabilityCheckPacket packet = new NetworkAvailabilityCheckPacket();
boolean skipResult = filter.filter(receiverSocket, packet, new InetSocketAddress("localhost", senderSocket.getLocalPort()));
Assert.assertEquals(skipResult, TBaseFilter.BREAK);
DatagramPacket receivePacket = new DatagramPacket(new byte[100], 100);
senderSocket.receive(receivePacket);
Assert.assertEquals(receivePacket.getLength(), NetworkAvailabilityCheckPacket.DATA_OK.length);
Assert.assertArrayEquals(Arrays.copyOf(receivePacket.getData(), NetworkAvailabilityCheckPacket.DATA_OK.length), NetworkAvailabilityCheckPacket.DATA_OK);
}
use of java.net.DatagramPacket in project pinpoint by naver.
the class PacketUtilsTest method testSliceData1.
@Test
public void testSliceData1() throws Exception {
DatagramPacket packet = createPacket(10);
packet.setLength(5);
byte[] bytes1 = PacketUtils.sliceData(packet, 0);
Assert.assertEquals(bytes1.length, 5);
}
use of java.net.DatagramPacket in project pinpoint by naver.
the class UdpSocketTest method testDatagramMaxSend.
@Test
public void testDatagramMaxSend() throws IOException {
DatagramPacket packet1 = newDatagramPacket(AcceptedSize);
sender.send(packet1);
DatagramPacket r1 = newDatagramPacket(AcceptedSize);
receiver.receive(r1);
Assert.assertEquals(r1.getLength(), AcceptedSize);
}
use of java.net.DatagramPacket in project pinpoint by naver.
the class UdpSocketTest method testRemoteReceive.
// uncomment when remote test
// @Test
public void testRemoteReceive() {
while (true) {
DatagramPacket datagramPacket = newDatagramPacket(70000);
try {
receiver.receive(datagramPacket);
logger.debug("data size:{}", datagramPacket.getLength());
} catch (IOException e) {
logger.warn("receive error:{}", e.getMessage(), e);
}
}
}
use of java.net.DatagramPacket in project pinpoint by naver.
the class UdpSocketTest method createUdpSocket.
// @Test
public void createUdpSocket() throws IOException {
DatagramSocket so = new DatagramSocket();
// so.bind(new InetSocketAddress("localhost", 8081));
// DatagramSocket receiver = new DatagramSocket(new InetSocketAddress("localhost", 8082));
// receiver.bind(new InetSocketAddress("localhost", 8082));
so.connect(new InetSocketAddress("localhost", 8082));
so.send(new DatagramPacket(new byte[10], 10));
// receiver.receive(newDatagramPacket(1000));
so.close();
}
Aggregations