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
}
}
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());
}
}
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());
}
}
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();
}
}
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);
}
}
Aggregations