Skip to content

Commit

Permalink
Merge #3237 into 1.1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed May 13, 2024
2 parents 982eb5c + dca81cb commit 99e319e
Showing 1 changed file with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,23 @@ void testDisposeInactivePoolsInBackground(boolean enableEvictInBackground, boole
}

MeterRegistrarImpl meterRegistrar;
String metricsName = "";
CountDownLatch meterRemoved = new CountDownLatch(2);
String pendingTime = isHttp2 ? ".pending.streams.time" : ".pending.connections.time";
String metricsName1 = CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS;
String metricsName2 = CONNECTION_PROVIDER_PREFIX + pendingTime;
String metricsTagName = "";
if (isBuiltInMetrics) {
meterRegistrar = null;
builder.metrics(true);

metricsName = isHttp2 ? "http2.testDisposeInactivePoolsInBackground" : "testDisposeInactivePoolsInBackground";
metricsTagName = isHttp2 ? "http2.testDisposeInactivePoolsInBackground" : "testDisposeInactivePoolsInBackground";

registry.config().onMeterRemoved(meter -> {
if (metricsName1.equals(meter.getId().getName()) ||
metricsName2.equals(meter.getId().getName())) {
meterRemoved.countDown();
}
});
}
else {
meterRegistrar = new MeterRegistrarImpl();
Expand Down Expand Up @@ -711,18 +722,15 @@ void testDisposeInactivePoolsInBackground(boolean enableEvictInBackground, boole

InetSocketAddress sa = (InetSocketAddress) serverAddress.get();
String address = sa.getHostString() + ":" + sa.getPort();
String pendingTime = isHttp2 ? ".pending.streams.time" : ".pending.connections.time";

assertThat(provider.channelPools.size()).isEqualTo(1);
if (meterRegistrar != null) {
assertThat(meterRegistrar.registered.get()).isTrue();
}
else {
assertGauge(registry, CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS,
REMOTE_ADDRESS, address, NAME, metricsName).isNotNull();
assertGauge(registry, metricsName1, REMOTE_ADDRESS, address, NAME, metricsTagName).isNotNull();

assertTimer(registry, CONNECTION_PROVIDER_PREFIX + pendingTime,
REMOTE_ADDRESS, address, NAME, metricsName).isNotNull();
assertTimer(registry, metricsName2, REMOTE_ADDRESS, address, NAME, metricsTagName).isNotNull();
}

if (enableEvictInBackground) {
Expand All @@ -737,22 +745,23 @@ void testDisposeInactivePoolsInBackground(boolean enableEvictInBackground, boole

assertThat(provider.isDisposed()).isEqualTo(enableEvictInBackground);
if (meterRegistrar != null) {
if (enableEvictInBackground) {
assertThat(meterRegistrar.latch.await(30, TimeUnit.SECONDS)).isTrue();
}
assertThat(meterRegistrar.deRegistered.get()).isEqualTo(enableEvictInBackground);
}
else {
if (enableEvictInBackground) {
assertGauge(registry, CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS,
REMOTE_ADDRESS, address, NAME, metricsName).isNull();
assertThat(meterRemoved.await(30, TimeUnit.SECONDS)).isTrue();

assertGauge(registry, metricsName1, REMOTE_ADDRESS, address, NAME, metricsTagName).isNull();

assertTimer(registry, CONNECTION_PROVIDER_PREFIX + pendingTime,
REMOTE_ADDRESS, address, NAME, metricsName).isNull();
assertTimer(registry, metricsName2, REMOTE_ADDRESS, address, NAME, metricsTagName).isNull();
}
else {
assertGauge(registry, CONNECTION_PROVIDER_PREFIX + ACTIVE_CONNECTIONS,
REMOTE_ADDRESS, address, NAME, metricsName).isNotNull();
assertGauge(registry, metricsName1, REMOTE_ADDRESS, address, NAME, metricsTagName).isNotNull();

assertTimer(registry, CONNECTION_PROVIDER_PREFIX + pendingTime,
REMOTE_ADDRESS, address, NAME, metricsName).isNotNull();
assertTimer(registry, metricsName2, REMOTE_ADDRESS, address, NAME, metricsTagName).isNotNull();
}
}
}
Expand Down Expand Up @@ -888,6 +897,7 @@ void testHttp2PoolAndGoAway() {
static final class MeterRegistrarImpl implements ConnectionProvider.MeterRegistrar {
AtomicBoolean registered = new AtomicBoolean();
AtomicBoolean deRegistered = new AtomicBoolean();
final CountDownLatch latch = new CountDownLatch(1);

MeterRegistrarImpl() {
}
Expand All @@ -900,6 +910,7 @@ public void registerMetrics(String poolName, String id, SocketAddress remoteAddr
@Override
public void deRegisterMetrics(String poolName, String id, SocketAddress remoteAddress) {
deRegistered.compareAndSet(false, true);
latch.countDown();
}
}
}

0 comments on commit 99e319e

Please sign in to comment.