Search in sources :

Example 31 with DatagramPacket

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);
}
Also used : NetworkAvailabilityCheckPacket(com.navercorp.pinpoint.thrift.io.NetworkAvailabilityCheckPacket) InetSocketAddress(java.net.InetSocketAddress) DatagramPacket(java.net.DatagramPacket) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Example 32 with DatagramPacket

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);
}
Also used : DatagramPacket(java.net.DatagramPacket) Test(org.junit.Test)

Example 33 with DatagramPacket

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);
}
Also used : DatagramPacket(java.net.DatagramPacket)

Example 34 with DatagramPacket

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);
        }
    }
}
Also used : DatagramPacket(java.net.DatagramPacket) IOException(java.io.IOException)

Example 35 with DatagramPacket

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();
}
Also used : DatagramSocket(java.net.DatagramSocket) InetSocketAddress(java.net.InetSocketAddress) DatagramPacket(java.net.DatagramPacket)

Aggregations

DatagramPacket (java.net.DatagramPacket)302 IOException (java.io.IOException)126 DatagramSocket (java.net.DatagramSocket)121 InetAddress (java.net.InetAddress)69 SocketException (java.net.SocketException)43 Test (org.junit.Test)35 InetSocketAddress (java.net.InetSocketAddress)34 SocketTimeoutException (java.net.SocketTimeoutException)30 UnknownHostException (java.net.UnknownHostException)21 MulticastSocket (java.net.MulticastSocket)18 InterruptedIOException (java.io.InterruptedIOException)17 SocketAddress (java.net.SocketAddress)15 ByteBuffer (java.nio.ByteBuffer)11 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 SyslogConnection (org.opennms.netmgt.syslogd.api.SyslogConnection)11 PortUnreachableException (java.net.PortUnreachableException)9 ArrayList (java.util.ArrayList)9 SyslogMessageLogDTO (org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO)8 BindException (java.net.BindException)7 Transactional (org.springframework.transaction.annotation.Transactional)7