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