Skip to content

Commit

Permalink
Update to vertx builder changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 20, 2023
1 parent 6832aac commit 22ea1b5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public class RedisClientMetricsTest {

@Before
public void setup() {
vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(
new MetricsOptions().setEnabled(true).setFactory(ignored -> new VertxMetrics() {
vertx = Vertx.builder()
.withMetrics(ignored -> new VertxMetrics() {
@Override
public ClientMetrics<?, ?, ?, ?> createClientMetrics(SocketAddress remoteAddress, String type, String namespace) {
return metrics;
}
}))
);
})
.build();
client = Redis.createClient(vertx, new RedisOptions().setConnectionString("redis://" + redis.getHost() + ":" + redis.getFirstMappedPort()));
}

Expand Down
40 changes: 20 additions & 20 deletions src/test/java/io/vertx/redis/client/test/RedisPoolMetricsTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.vertx.redis.client.test;

import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.metrics.MetricsOptions;
import io.vertx.core.metrics.impl.DummyVertxMetrics;
import io.vertx.core.spi.VertxMetricsFactory;
import io.vertx.core.spi.metrics.PoolMetrics;
Expand All @@ -27,29 +27,29 @@ public class RedisPoolMetricsTest {

private static final AtomicReference<String> POOL_NAME = new AtomicReference<>();

private static VertxOptions getOptions() {
MetricsOptions options = new MetricsOptions().setEnabled(true);
options.setFactory(new VertxMetricsFactory() {
@Override
public VertxMetrics metrics(VertxOptions options) {
return new DummyVertxMetrics() {
@Override
public PoolMetrics<?> createPoolMetrics(String poolType, String poolName, int maxPoolSize) {
if (poolType.equals("redis")) {
POOL_NAME.set(poolName);
return new FakePoolMetrics(poolName, maxPoolSize);
} else {
return super.createPoolMetrics(poolType, poolName, maxPoolSize);
private static Vertx getVertx() {
return Vertx.builder()
.withMetrics(new VertxMetricsFactory() {
@Override
public VertxMetrics metrics(VertxOptions options) {
return new DummyVertxMetrics() {
@Override
public PoolMetrics<?> createPoolMetrics(String poolType, String poolName, int maxPoolSize) {
if (poolType.equals("redis")) {
POOL_NAME.set(poolName);
return new FakePoolMetrics(poolName, maxPoolSize);
} else {
return super.createPoolMetrics(poolType, poolName, maxPoolSize);
}
}
}
};
}
});
return new VertxOptions().setMetricsOptions(options);
};
}
})
.build();
}

@Rule
public final RunTestOnContext rule = new RunTestOnContext(getOptions());
public final RunTestOnContext rule = new RunTestOnContext(RedisPoolMetricsTest::getVertx);

@ClassRule
public static final GenericContainer<?> redis = new GenericContainer<>("redis:7")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class RedisTracingTest {

@Before
public void setup() {
vertx = Vertx.vertx(new VertxOptions().setTracingOptions(
new TracingOptions().setFactory(ignored -> new VertxTracer() {
vertx = Vertx.builder()
.withTracer(ignored -> new VertxTracer() {
@Override
public Object sendRequest(Context context, SpanKind kind, TracingPolicy tracingPolicy, Object request, String operation, BiConsumer headers, TagExtractor tagExtractor) {
return tracer.sendRequest(context, kind, tracingPolicy, request, operation, headers, tagExtractor);
Expand All @@ -52,8 +52,7 @@ public Object sendRequest(Context context, SpanKind kind, TracingPolicy tracingP
public void receiveResponse(Context context, Object response, Object payload, Throwable failure, TagExtractor tagExtractor) {
tracer.receiveResponse(context, response, payload, failure, tagExtractor);
}
}))
);
}).build();
client = Redis.createClient(vertx, new RedisOptions().setConnectionString("redis://" + redis.getHost() + ":" + redis.getFirstMappedPort()));
}

Expand Down

0 comments on commit 22ea1b5

Please sign in to comment.