Search in sources :

Example 26 with UnknownHostException

use of java.net.UnknownHostException in project sharding-jdbc by dangdangdotcom.

the class IPIdGenerator method initWorkerId.

static void initWorkerId() {
    InetAddress address;
    try {
        address = InetAddress.getLocalHost();
    } catch (final UnknownHostException e) {
        throw new IllegalStateException("Cannot get LocalHost InetAddress, please check your network!");
    }
    byte[] ipAddressByteArray = address.getAddress();
    CommonSelfIdGenerator.setWorkerId((long) (((ipAddressByteArray[ipAddressByteArray.length - 2] & 0B11) << Byte.SIZE) + (ipAddressByteArray[ipAddressByteArray.length - 1] & 0xFF)));
}
Also used : UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress)

Example 27 with UnknownHostException

use of java.net.UnknownHostException in project sharding-jdbc by dangdangdotcom.

the class HostNameIdGeneratorTest method testUnknownHost.

@Test
public void testUnknownHost() throws UnknownHostException {
    PowerMockito.mockStatic(InetAddress.class);
    PowerMockito.when(InetAddress.getLocalHost()).thenThrow(new UnknownHostException());
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Cannot get LocalHost InetAddress, please check your network!");
    HostNameIdGenerator.initWorkerId();
}
Also used : UnknownHostException(java.net.UnknownHostException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 28 with UnknownHostException

use of java.net.UnknownHostException in project sharding-jdbc by dangdangdotcom.

the class IPIdGeneratorTest method testUnknownHost.

@Test
public void testUnknownHost() throws UnknownHostException {
    PowerMockito.mockStatic(InetAddress.class);
    PowerMockito.when(InetAddress.getLocalHost()).thenThrow(new UnknownHostException());
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Cannot get LocalHost InetAddress, please check your network!");
    IPIdGenerator.initWorkerId();
}
Also used : UnknownHostException(java.net.UnknownHostException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 with UnknownHostException

use of java.net.UnknownHostException in project che by eclipse.

the class JavaDebugger method connect.

/**
     * Attach to a JVM that is already running at specified host.
     *
     * @throws DebuggerException
     *         when connection to Java VM is not established
     */
private void connect() throws DebuggerException {
    final String connectorName = "com.sun.jdi.SocketAttach";
    AttachingConnector connector = connector(connectorName);
    if (connector == null) {
        throw new DebuggerException(String.format("Unable connect to target Java VM. Requested connector '%s' not found. ", connectorName));
    }
    Map<String, Connector.Argument> arguments = connector.defaultArguments();
    arguments.get("hostname").setValue(host);
    ((Connector.IntegerArgument) arguments.get("port")).setValue(port);
    int attempt = 0;
    for (; ; ) {
        try {
            Thread.sleep(2000);
            vm = connector.attach(arguments);
            vm.suspend();
            break;
        } catch (UnknownHostException | IllegalConnectorArgumentsException e) {
            throw new DebuggerException(e.getMessage(), e);
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
            if (++attempt > 10) {
                throw new DebuggerException(e.getMessage(), e);
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ignored) {
            }
        } catch (InterruptedException ignored) {
        }
    }
    eventsCollector = new EventsCollector(vm.eventQueue(), this);
    LOG.debug("Connect {}:{}", host, port);
}
Also used : IllegalConnectorArgumentsException(com.sun.jdi.connect.IllegalConnectorArgumentsException) UnknownHostException(java.net.UnknownHostException) DebuggerException(org.eclipse.che.api.debugger.server.exceptions.DebuggerException) AttachingConnector(com.sun.jdi.connect.AttachingConnector) IOException(java.io.IOException) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint)

Example 30 with UnknownHostException

use of java.net.UnknownHostException in project vert.x by eclipse.

the class HostnameResolutionTest method testMultipleSearchDomain.

@Test
public void testMultipleSearchDomain() throws Exception {
    Map<String, String> records = new HashMap<>();
    records.put("host1.foo.com", "127.0.0.1");
    records.put("host2.bar.com", "127.0.0.2");
    records.put("host3.bar.com", "127.0.0.3");
    records.put("host3.foo.com", "127.0.0.4");
    dnsServer.stop();
    dnsServer = FakeDNSServer.testResolveA(records);
    dnsServer.start();
    VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false).addSearchDomain("foo.com").addSearchDomain("bar.com")));
    // "host1" resolves via the "foo.com" search path
    CountDownLatch latch1 = new CountDownLatch(1);
    vertx.resolveAddress("host1", onSuccess(resolved -> {
        assertEquals("127.0.0.1", resolved.getHostAddress());
        latch1.countDown();
    }));
    awaitLatch(latch1);
    // "host2" resolves via the "bar.com" search path
    CountDownLatch latch2 = new CountDownLatch(1);
    vertx.resolveAddress("host2", onSuccess(resolved -> {
        assertEquals("127.0.0.2", resolved.getHostAddress());
        latch2.countDown();
    }));
    awaitLatch(latch2);
    // "host3" resolves via the the "foo.com" search path as it is the first one
    CountDownLatch latch3 = new CountDownLatch(1);
    vertx.resolveAddress("host3", onSuccess(resolved -> {
        assertEquals("127.0.0.4", resolved.getHostAddress());
        latch3.countDown();
    }));
    awaitLatch(latch3);
    // "host4" does not resolve
    vertx.resolveAddress("host4", onFailure(cause -> {
        assertTrue(cause instanceof UnknownHostException);
        testComplete();
    }));
    await();
}
Also used : AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) VertxException(io.vertx.core.VertxException) Arrays(java.util.Arrays) HttpServer(io.vertx.core.http.HttpServer) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Locale(java.util.Locale) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) FakeDNSServer(io.vertx.test.fakedns.FakeDNSServer) NetClient(io.vertx.core.net.NetClient) VertxImpl(io.vertx.core.impl.VertxImpl) VertxInternal(io.vertx.core.impl.VertxInternal) ChannelInitializer(io.netty.channel.ChannelInitializer) AddressResolver(io.vertx.core.impl.AddressResolver) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) File(java.io.File) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Bootstrap(io.netty.bootstrap.Bootstrap) CountDownLatch(java.util.concurrent.CountDownLatch) NetServerOptions(io.vertx.core.net.NetServerOptions) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) Collections(java.util.Collections) HttpClient(io.vertx.core.http.HttpClient) VertxInternal(io.vertx.core.impl.VertxInternal) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Aggregations

UnknownHostException (java.net.UnknownHostException)780 InetAddress (java.net.InetAddress)319 IOException (java.io.IOException)229 InetSocketAddress (java.net.InetSocketAddress)88 Test (org.junit.Test)74 SocketException (java.net.SocketException)61 ArrayList (java.util.ArrayList)59 Socket (java.net.Socket)48 SocketTimeoutException (java.net.SocketTimeoutException)38 File (java.io.File)34 URL (java.net.URL)32 HashMap (java.util.HashMap)31 MalformedURLException (java.net.MalformedURLException)30 ConnectException (java.net.ConnectException)27 NetworkInterface (java.net.NetworkInterface)25 Properties (java.util.Properties)24 Inet4Address (java.net.Inet4Address)22 InputStream (java.io.InputStream)20 HttpURLConnection (java.net.HttpURLConnection)20 URI (java.net.URI)20