Skip to content

Commit

Permalink
Adjustemnt to make all metrics test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Apr 8, 2016
1 parent 50f353f commit 25fbed8
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 20 deletions.
Expand Up @@ -194,7 +194,7 @@ private DatagramSocket listen(SocketAddress local, Handler<AsyncResult<DatagramS
ChannelFuture future = channel().bind(new InetSocketAddress(res.result(), local.port()));
addListener(future, ar -> {
if (ar.succeeded()) {
((DatagramSocketMetrics) metrics).listening(localAddress());
((DatagramSocketMetrics) metrics).listening(local.host(), localAddress());
}
handler.handle(ar);
});
Expand Down
Expand Up @@ -44,11 +44,11 @@
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.core.net.impl.AsyncResolveBindConnectHelper;
import io.vertx.core.net.impl.PartialPooledByteBufAllocator;
import io.vertx.core.net.impl.SSLHelper;

import javax.net.ssl.SSLHandshakeException;
import java.net.InetSocketAddress;
import java.util.ArrayDeque;
import java.util.Map;
import java.util.Queue;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/vertx/core/impl/VertxImpl.java
Expand Up @@ -661,12 +661,12 @@ public File resolveFile(String fileName) {
}

@Override
public void resolveAsync(String host, Handler<AsyncResult<String>> resultHandler) {
public void resolveAsync(String host, Handler<AsyncResult<InetAddress>> resultHandler) {
// For now just do a blocking resolve
// When Netty 4.1 is released we can use async DNS resolution
executeBlockingInternal(() -> {
try {
return InetAddress.getByName(host).getHostAddress();
return InetAddress.getByName(host);
} catch (UnknownHostException e) {
throw new VertxException(e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/vertx/core/impl/VertxInternal.java
Expand Up @@ -29,6 +29,7 @@
import io.vertx.core.spi.metrics.VertxMetrics;

import java.io.File;
import java.net.InetAddress;
import java.util.Map;
import java.util.concurrent.ExecutorService;

Expand Down Expand Up @@ -90,6 +91,6 @@ public interface VertxInternal extends Vertx {

ClusterManager getClusterManager();

void resolveAsync(String host, Handler<AsyncResult<String>> resultHandler);
void resolveAsync(String host, Handler<AsyncResult<InetAddress>> resultHandler);

}
Expand Up @@ -319,7 +319,7 @@ public boolean isEnabled() {
protected class DummyDatagramMetrics implements DatagramSocketMetrics {

@Override
public void listening(SocketAddress localAddress) {
public void listening(String localName, SocketAddress localAddress) {
}

@Override
Expand Down
@@ -1,20 +1,20 @@
/*
* Copyright 2014 Red Hat, Inc.
*
* Copyright (c) 2011-2013 The original author or authors
* ------------------------------------------------------
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
* The Apache License v2.0 is available at
* http://www.opensource.org/licenses/apache2.0.php
*
* You may elect to redistribute this code under either of these licenses.
*/

package io.vertx.core.http.impl;
package io.vertx.core.net.impl;

import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
Expand Down Expand Up @@ -83,7 +83,8 @@ private static AsyncResolveBindConnectHelper<ChannelFuture> doBindConnect(VertxI
vertx.resolveAsync(host, res -> {
if (res.succeeded()) {
// At this point the name is an IP address so there will be no resolve hit
ChannelFuture future = cfProducer.apply(new InetSocketAddress(res.result(), port));
InetSocketAddress t = new InetSocketAddress(res.result(), port);
ChannelFuture future = cfProducer.apply(t);
future.addListener(f -> {
if (f.isSuccess()) {
asyncResolveBindConnectHelper.handle(Future.succeededFuture(future));
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/vertx/core/net/impl/NetClientImpl.java
Expand Up @@ -26,7 +26,6 @@
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Closeable;
import io.vertx.core.http.impl.AsyncResolveBindConnectHelper;
import io.vertx.core.impl.ContextImpl;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.logging.Logger;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/vertx/core/net/impl/NetServerImpl.java
Expand Up @@ -31,7 +31,6 @@
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Closeable;
import io.vertx.core.http.impl.AsyncResolveBindConnectHelper;
import io.vertx.core.impl.ContextImpl;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.logging.Logger;
Expand Down
Expand Up @@ -43,8 +43,9 @@ public interface DatagramSocketMetrics extends NetworkMetrics<Void> {
* Called when a socket is listening. For example, this is called when an http or net server
* has been created and is listening on a specific host/port.
*
* @param localName
* @param localAddress the local address the net socket is listening on.
*/
void listening(SocketAddress localAddress);
void listening(String localName, SocketAddress localAddress);

}
2 changes: 1 addition & 1 deletion src/test/java/io/vertx/test/core/MetricsContextTest.java
Expand Up @@ -707,7 +707,7 @@ private void testDatagram(Function<Vertx, Context> contextFactory, BiConsumer<Th
public DatagramSocketMetrics createMetrics(DatagramSocket socket, DatagramSocketOptions options) {
return new DummyDatagramMetrics() {
@Override
public void listening(SocketAddress localAddress) {
public void listening(String localName, SocketAddress localAddress) {
listening.set(true);
checker.accept(expectedThread.get(), expectedContext.get());
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/io/vertx/test/core/MetricsTest.java
Expand Up @@ -661,7 +661,8 @@ private void testDatagram(String host, Consumer<PacketMetric> checker) throws Ex
peer1.handler(packet -> {
FakeDatagramSocketMetrics peer1Metrics = FakeMetricsBase.getMetrics(peer1);
FakeDatagramSocketMetrics peer2Metrics = FakeMetricsBase.getMetrics(peer2);
assertEquals(host, peer1Metrics.getLocalAddress().host());
assertEquals(host, peer1Metrics.getLocalName());
assertEquals("127.0.0.1", peer1Metrics.getLocalAddress().host());
assertNull(peer2Metrics.getLocalAddress());
assertEquals(1, peer1Metrics.getReads().size());
PacketMetric read = peer1Metrics.getReads().get(0);
Expand Down
Expand Up @@ -29,6 +29,7 @@
*/
public class FakeDatagramSocketMetrics extends FakeMetricsBase implements DatagramSocketMetrics {

private volatile String localName;
private volatile SocketAddress localAddress;
private final List<PacketMetric> reads = Collections.synchronizedList(new ArrayList<>());
private final List<PacketMetric> writes = Collections.synchronizedList(new ArrayList<>());
Expand All @@ -37,6 +38,10 @@ public FakeDatagramSocketMetrics(Measured measured) {
super(measured);
}

public String getLocalName() {
return localName;
}

public SocketAddress getLocalAddress() {
return localAddress;
}
Expand All @@ -50,7 +55,8 @@ public List<PacketMetric> getWrites() {
}

@Override
public void listening(SocketAddress localAddress) {
public void listening(String localName, SocketAddress localAddress) {
this.localName = localName;
this.localAddress = localAddress;
}

Expand Down

0 comments on commit 25fbed8

Please sign in to comment.