Search in sources :

Example 81 with BindException

use of java.net.BindException in project roboguice by roboguice.

the class CheckedProviderMethodsModuleTest method testWithThrownException.

public void testWithThrownException() {
    TestModule testModule = new TestModule();
    Injector injector = Guice.createInjector(testModule);
    RpcProvider<Float> provider = injector.getInstance(Key.get(rpcProviderOfFloat));
    try {
        provider.get();
        fail();
    } catch (RemoteException e) {
        fail();
    } catch (BindException e) {
    // good
    }
}
Also used : Injector(com.google.inject.Injector) BindException(java.net.BindException) RemoteException(java.rmi.RemoteException)

Example 82 with BindException

use of java.net.BindException in project roboguice by roboguice.

the class CheckedProviderTest method tExceptionsThrown.

private void tExceptionsThrown(Injector injector) throws Exception {
    RemoteProvider<Foo> remoteProvider = injector.getInstance(Key.get(remoteProviderOfFoo));
    mockRemoteProvider.throwOnNextGet(new BindException("kaboom!"));
    MockFoo.nextToThrow = new BindException("kaboom!");
    try {
        remoteProvider.get();
        fail();
    } catch (BindException expected) {
        assertEquals("kaboom!", expected.getMessage());
    }
}
Also used : BindException(java.net.BindException)

Example 83 with BindException

use of java.net.BindException in project roboguice by roboguice.

the class CheckedProviderTest method testProviderMethodWithManyExceptions.

public void testProviderMethodWithManyExceptions() {
    try {
        Guice.createInjector(new AbstractModule() {

            @Override
            protected void configure() {
                install(ThrowingProviderBinder.forModule(this));
            }

            @SuppressWarnings("unused")
            @CheckedProvides(RemoteProvider.class)
            String foo() throws InterruptedException, RuntimeException, RemoteException, AccessException, TooManyListenersException, BindException, SubBindException {
                return null;
            }
        });
        fail();
    } catch (CreationException ce) {
        // The only two that should fail are Interrupted & TooManyListeners.. the rest are OK.
        List<Message> errors = ImmutableList.copyOf(ce.getErrorMessages());
        assertEquals(InterruptedException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + ", " + BindException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(0).getMessage());
        assertEquals(TooManyListenersException.class.getName() + " is not compatible with the exceptions ([" + RemoteException.class + ", " + BindException.class + "]) declared in the CheckedProvider interface (" + RemoteProvider.class.getName() + ")", errors.get(1).getMessage());
        assertEquals(2, errors.size());
    }
}
Also used : BindException(java.net.BindException) CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule) TooManyListenersException(java.util.TooManyListenersException) AccessException(java.rmi.AccessException) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RemoteException(java.rmi.RemoteException)

Example 84 with BindException

use of java.net.BindException in project geode by apache.

the class AcceptorImplJUnitTest method testConstructor.

/*
   * Test method for 'org.apache.geode.internal.cache.tier.sockets.AcceptorImpl(int, int, boolean,
   * int, Cache)'
   */
@Ignore
@Test
public void testConstructor() throws CacheException, IOException {
    AcceptorImpl a1 = null, a2 = null, a3 = null;
    try {
        final int[] freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
        int port1 = freeTCPPorts[0];
        int port2 = freeTCPPorts[1];
        try {
            new AcceptorImpl(port1, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, AcceptorImpl.MINIMUM_MAX_CONNECTIONS - 1, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
            fail("Expected an IllegalArgumentExcption due to max conns < min pool size");
        } catch (IllegalArgumentException expected) {
        }
        try {
            new AcceptorImpl(port2, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, 0, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
            fail("Expected an IllegalArgumentExcption due to max conns of zero");
        } catch (IllegalArgumentException expected) {
        }
        try {
            a1 = new AcceptorImpl(port1, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, AcceptorImpl.MINIMUM_MAX_CONNECTIONS, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
            a2 = new AcceptorImpl(port1, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, AcceptorImpl.MINIMUM_MAX_CONNECTIONS, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
            fail("Expecetd a BindException while attaching to the same port");
        } catch (BindException expected) {
        }
        a3 = new AcceptorImpl(port2, null, false, CacheServer.DEFAULT_SOCKET_BUFFER_SIZE, CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS, this.cache, AcceptorImpl.MINIMUM_MAX_CONNECTIONS, CacheServer.DEFAULT_MAX_THREADS, CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT, CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE, null, null, false, Collections.EMPTY_LIST, CacheServer.DEFAULT_TCP_NO_DELAY);
        assertEquals(port2, a3.getPort());
        InternalDistributedSystem isystem = (InternalDistributedSystem) this.cache.getDistributedSystem();
        DistributionConfig config = isystem.getConfig();
        String bindAddress = config.getBindAddress();
        if (bindAddress == null || bindAddress.length() <= 0) {
            assertTrue(a3.getServerInetAddr().isAnyLocalAddress());
        }
    } finally {
        if (a1 != null)
            a1.close();
        if (a2 != null)
            a2.close();
        if (a3 != null)
            a3.close();
    }
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) BindException(java.net.BindException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Ignore(org.junit.Ignore) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 85 with BindException

use of java.net.BindException in project voltdb by VoltDB.

the class MiscUtils method isBindable.

public static synchronized boolean isBindable(int port) {
    try {
        ServerSocket ss = new ServerSocket(port);
        ss.close();
        ss = null;
        return true;
    } catch (BindException be) {
        return false;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : BindException(java.net.BindException) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException)

Aggregations

BindException (java.net.BindException)104 IOException (java.io.IOException)34 InetSocketAddress (java.net.InetSocketAddress)25 ServerSocket (java.net.ServerSocket)22 Test (org.junit.Test)22 File (java.io.File)12 SocketException (java.net.SocketException)10 Configuration (org.apache.hadoop.conf.Configuration)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 InterruptedIOException (java.io.InterruptedIOException)5 MiniDFSNNTopology (org.apache.hadoop.hdfs.MiniDFSNNTopology)5 InetAddress (java.net.InetAddress)4 UnknownHostException (java.net.UnknownHostException)4 RemoteException (java.rmi.RemoteException)4 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)4 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)4 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)3 Socket (java.net.Socket)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3