@Before public void init() { new Expectations(CseContext.getInstance()) { { netSocket.remoteAddress(); result = new SocketAddressImpl(new InetSocketAddress("127.0.0.1", 80)); } }; connection = new HighwayServerConnection(); connection.init(netSocket); header = new RequestHeader(); }
@Test public void test() { MetricsServer .create(vertx()) .apply(CollectorRegistry.defaultRegistry, ExpositionFormat.Text) .apply(new SocketAddressImpl(new InetSocketAddress(PORT))); await(response(body -> context().assertTrue(body.length() > 0, "Response is empty"))); }
@Test public void shouldDelegateGetRemoteAddress() { when(httpServerRequest.remoteAddress()) .thenReturn(null) .thenReturn(new SocketAddressImpl(8080, "10.3.100.108")); assertThat(vaadinRequest.getRemoteAddr()).isNull(); assertThat(vaadinRequest.getRemoteAddr()).isEqualTo("10.3.100.108"); }
@Override public SocketAddress connected(SocketAddress remoteAddress, String remoteName) { SocketAddress key = new SocketAddressImpl(remoteAddress.port(), remoteName); HttpClientConnectionsMeasurements measurements = connectionsMeasurements.get(key); if (measurements == null) { measurements = connectionsMeasurements.computeIfAbsent(key, address -> new HttpClientConnectionsMeasurements()); } measurements.incrementConnections(); return key; }
@Test public void testSocketAddressEquality() { SocketAddress address1 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest")); SocketAddress address2 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest")); assertNotSame(address1, address2); assertEquals(address1, address2); }
@Override public void listening(@NotNull String localName, @NotNull SocketAddress localAddress) { this.namedLocalAddress = new SocketAddressImpl(localAddress.port(), localName); }
@Test public void shouldDelegateGetRemoteHost() { when(httpServerRequest.remoteAddress()).thenReturn(null, new SocketAddressImpl(5555, "10.1.1.1")); assertThat(vaadinRequest.getRemoteAddr()).isNull(); assertThat(vaadinRequest.getRemoteAddr()).isEqualTo("10.1.1.1"); }
@Test public void shouldDelegateGetRemotePort() { when(httpServerRequest.remoteAddress()).thenReturn(null, new SocketAddressImpl(5555, "10.1.1.1")); assertThat(vaadinRequest.getRemotePort()).isEqualTo(-1); assertThat(vaadinRequest.getRemotePort()).isEqualTo(5555); }
@Override public void listening(String localName, SocketAddress localAddress) { this.localAddress = new SocketAddressImpl(localAddress.port(), localName); }
@Override public SocketAddress connected(SocketAddress remoteAddress, String remoteName) { SocketAddress key = new SocketAddressImpl(remoteAddress.port(), remoteName); connectionsMeasurements.computeIfAbsent(key, address -> new NetClientConnectionsMeasurements()).incrementConnections(); return key; }
@Test public void testSocketAddressToString() { io.vertx.core.net.SocketAddress socketAddress = new SocketAddressImpl(8888, "guest"); SocketAddress rxSocketAddress = SocketAddress.newInstance(socketAddress); assertEquals(socketAddress.toString(), rxSocketAddress.toString()); }
@Test public void testSocketAddressSet() { SocketAddress address1 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest")); SocketAddress address2 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest")); assertEquals(1, Stream.of(address1, address2).collect(toSet()).size()); }
/** * Prometheus Metrics server address. * * @return server address */ public @NotNull SocketAddress getAddress() { return new SocketAddressImpl(port, host); }