Search in sources :

Example 16 with SocketFactory

use of javax.net.SocketFactory in project java-apns by notnoop.

the class ApnsFeedbackConnectionTest method feedbackWithClosedSocket.

/** Check error recover **/
@Test
public void feedbackWithClosedSocket() {
    SocketFactory sf = mockClosedThenOpenSocket(null, simpleStream, true, 1);
    ApnsFeedbackConnection connection = new ApnsFeedbackConnection(sf, "localhost", 80);
    connection.DELAY_IN_MS = 0;
    checkParsedSimple(connection.getInactiveDevices());
}
Also used : SocketFactory(javax.net.SocketFactory) Test(org.junit.Test)

Example 17 with SocketFactory

use of javax.net.SocketFactory in project robovm by robovm.

the class MySocketFactory method test_createSocket_05.

/**
     * javax.net.SocketFactory#createSocket(String host, int port,
     *                                             InetAddress localHost, int localPort)
     */
public final void test_createSocket_05() throws Exception {
    SocketFactory sf = SocketFactory.getDefault();
    int sport = new ServerSocket(0).getLocalPort();
    int[] invalidPorts = { Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE };
    Socket s = sf.createSocket(InetAddress.getLocalHost().getHostName(), sport, InetAddress.getLocalHost(), 0);
    assertNotNull(s);
    assertTrue("1: Failed to create socket", s.getPort() == sport);
    try {
        sf.createSocket("bla-bla", sport, InetAddress.getLocalHost(), 0);
        fail("UnknownHostException wasn't thrown");
    } catch (UnknownHostException expected) {
    }
    for (int i = 0; i < invalidPorts.length; i++) {
        try {
            sf.createSocket(InetAddress.getLocalHost().getHostName(), invalidPorts[i], InetAddress.getLocalHost(), 0);
            fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
        } catch (IllegalArgumentException expected) {
        }
        try {
            sf.createSocket(InetAddress.getLocalHost().getHostName(), sport, InetAddress.getLocalHost(), invalidPorts[i]);
            fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
        } catch (IllegalArgumentException expected) {
        }
    }
    try {
        sf.createSocket(InetAddress.getLocalHost().getHostName(), 8081, InetAddress.getLocalHost(), 8082);
        fail("IOException wasn't thrown ...");
    } catch (IOException expected) {
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) SocketFactory(javax.net.SocketFactory) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Example 18 with SocketFactory

use of javax.net.SocketFactory in project robovm by robovm.

the class MySocketFactory method test_createSocket.

public final void test_createSocket() throws Exception {
    SocketFactory sf = SocketFactory.getDefault();
    Socket s = sf.createSocket();
    assertNotNull(s);
    assertEquals(-1, s.getLocalPort());
    assertEquals(0, s.getPort());
    MySocketFactory msf = new MySocketFactory();
    try {
        msf.createSocket();
        fail("No expected SocketException");
    } catch (SocketException expected) {
    }
}
Also used : SocketException(java.net.SocketException) SocketFactory(javax.net.SocketFactory) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Example 19 with SocketFactory

use of javax.net.SocketFactory in project robovm by robovm.

the class MySocketFactory method test_createSocket_InetAddressIInetAddressI.

public final void test_createSocket_InetAddressIInetAddressI() throws Exception {
    SocketFactory sf = SocketFactory.getDefault();
    int sport = new ServerSocket(0).getLocalPort();
    int[] invalidPorts = { Integer.MIN_VALUE, -1, 65536, Integer.MAX_VALUE };
    Socket s = sf.createSocket(InetAddress.getLocalHost(), sport, InetAddress.getLocalHost(), 0);
    assertNotNull(s);
    assertTrue("1: Failed to create socket", s.getPort() == sport);
    int portNumber = s.getLocalPort();
    for (int i = 0; i < invalidPorts.length; i++) {
        try {
            sf.createSocket(InetAddress.getLocalHost(), invalidPorts[i], InetAddress.getLocalHost(), portNumber);
            fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
        } catch (IllegalArgumentException expected) {
        }
        try {
            sf.createSocket(InetAddress.getLocalHost(), sport, InetAddress.getLocalHost(), invalidPorts[i]);
            fail("IllegalArgumentException wasn't thrown for " + invalidPorts[i]);
        } catch (IllegalArgumentException expected) {
        }
    }
    try {
        sf.createSocket(InetAddress.getLocalHost(), sport, InetAddress.getLocalHost(), portNumber);
        fail("IOException wasn't thrown");
    } catch (IOException expected) {
    }
    SocketFactory f = SocketFactory.getDefault();
    try {
        f.createSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
        fail("IOException wasn't thrown ...");
    } catch (IOException expected) {
    }
}
Also used : SocketFactory(javax.net.SocketFactory) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Example 20 with SocketFactory

use of javax.net.SocketFactory in project robovm by robovm.

the class MySocketFactory method test_getDefault.

/**
     * javax.net.SocketFactory#getDefault()
     */
public final void test_getDefault() {
    SocketFactory sf = SocketFactory.getDefault();
    Socket s;
    try {
        s = sf.createSocket(InetAddress.getLocalHost().getHostName(), 8082);
        s.close();
    } catch (IOException e) {
    }
    try {
        s = sf.createSocket(InetAddress.getLocalHost().getHostName(), 8081, InetAddress.getLocalHost(), 8082);
        s.close();
    } catch (IOException e) {
    }
    try {
        s = sf.createSocket(InetAddress.getLocalHost(), 8081);
        s.close();
    } catch (IOException e) {
    }
    try {
        s = sf.createSocket(InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082);
        s.close();
    } catch (IOException e) {
    }
}
Also used : SocketFactory(javax.net.SocketFactory) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Aggregations

SocketFactory (javax.net.SocketFactory)66 Socket (java.net.Socket)25 Test (org.junit.Test)25 IOException (java.io.IOException)18 InetSocketAddress (java.net.InetSocketAddress)14 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 SSLSocket (javax.net.ssl.SSLSocket)10 OutputStream (java.io.OutputStream)9 ServerSocket (java.net.ServerSocket)9 SocketAddress (java.net.SocketAddress)6 Configuration (org.apache.hadoop.conf.Configuration)5 ServerSocketFactory (javax.net.ServerSocketFactory)4 InputStream (java.io.InputStream)3 InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3 ProtocolSocketFactory (org.apache.commons.httpclient.protocol.ProtocolSocketFactory)3 StandardSocketFactory (org.apache.hadoop.net.StandardSocketFactory)3 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)3 SocketException (java.net.SocketException)2