Skip to content

Commit

Permalink
chore(deps): bump plugin dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Oct 18, 2023
1 parent 542eb4b commit 2ebc1a8
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 6 deletions.
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ guava = "32.1.3-jre"
assertj = "3.24.2"
junit = "5.10.0"
testcontainers = "1.19.1"
protoc = "3.23.2"
protoc = "3.24.4"
failsafe = "3.3.2"
awaitility = "4.2.0"
commonsIo = "2.14.0"
Expand All @@ -18,15 +18,15 @@ vertx = "4.4.6"
picocli = "4.7.5"
restAssured = "5.3.2"

versionsPlugin = "0.47.0"
versionsPlugin = "0.49.0"
errorPronePlugin = "3.1.0"
spotlessPlugin = "6.19.0"
spotlessPlugin = "6.22.0"
shadowPlugin = "8.1.1"
testLoggerPlugin = "3.2.0"
testLoggerPlugin = "4.0.0"
protobufPlugin = "0.9.4"
nexusPublishPlugin = "1.3.0"
axionReleasePlugin = "1.15.3"
testRetryPlugin = "1.5.3"
axionReleasePlugin = "1.15.5"
testRetryPlugin = "1.5.6"

[libraries]
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
Expand Down
148 changes: 148 additions & 0 deletions jetcd-core/src/test/java/io/etcd/jetcd/impl/LeaseOnceErrorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright 2016-2021 The jetcd authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.etcd.jetcd.impl;

import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.assertj.core.data.Percentage;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.Client;
import io.etcd.jetcd.KV;
import io.etcd.jetcd.Lease;
import io.etcd.jetcd.options.PutOption;
import io.etcd.jetcd.test.EtcdClusterExtension;
import io.restassured.RestAssured;

import static org.assertj.core.api.Assertions.assertThat;

@Timeout(value = 45, unit = TimeUnit.SECONDS)
public class LeaseMemoryLeakTest {

@RegisterExtension
public static final EtcdClusterExtension CLUSTER = EtcdClusterExtension.builder()
.withNodes(1)
.build();

private Client client;
private KV kvClient;
private Lease leaseClient;

private static final Logger LOGGER = LoggerFactory.getLogger(LeaseMemoryLeakTest.class);
private static final long TTL = 10;
private static final int ITERATIONS = 5;
private static final Pattern GO_ROUTINES_EXTRACT_PATTERN = Pattern.compile("go_goroutines (\\d+)");
private static final ByteSequence KEY = ByteSequence.from("foo", StandardCharsets.UTF_8);
private static final ByteSequence VALUE = ByteSequence.from("bar", StandardCharsets.UTF_8);

@BeforeEach
public void setUp() {
client = TestUtil.client(CLUSTER).build();
kvClient = client.getKVClient();
leaseClient = client.getLeaseClient();
}

@AfterEach
public void tearDown() {
if (client != null) {
client.close();
}
}

// https://github.com/etcd-io/jetcd/issues/1236
@Test
@Disabled("Flaky test, must be investigated")
public void testKeepAliveOnceMemoryLeak() throws Exception {
final long leaseID = leaseClient.grant(TTL).get(1, TimeUnit.SECONDS).getID();
final URI uri = CLUSTER.cluster().clientEndpoints().get(0);
final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();

try {
LOGGER.info("Put K/V with lease id {}", leaseID);
kvClient.put(KEY, VALUE, PutOption.builder().withLeaseId(leaseID).build()).get(1, TimeUnit.SECONDS);

AtomicInteger max = new AtomicInteger();
CountDownLatch latch = new CountDownLatch(ITERATIONS);

int start = extractGoRoutinesCount(uri);
assertThat(start).isGreaterThan(0);

scheduler.scheduleAtFixedRate(() -> {
try {
if (latch.getCount() == 0) {
return;
}

LOGGER.info("Keep alive {} once for lease id {}", ITERATIONS - latch.getCount(), leaseID);
leaseClient.keepAliveOnce(leaseID).get(5, TimeUnit.SECONDS);

int count = extractGoRoutinesCount(uri);
max.set(Math.max(max.get(), count));

LOGGER.info("go-routines:{}, max: {}, start: {}", count, max.get(), start);

latch.countDown();
} catch (Exception e) {
throw new RuntimeException(e);
}
}, 0, 1, TimeUnit.SECONDS);

assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(max.get()).isGreaterThan(0);
assertThat(max.get()).isGreaterThanOrEqualTo(start);

if (max.get() != start) {
assertThat(max.get() - start).isCloseTo(5, Percentage.withPercentage(80));
}
} finally {
scheduler.shutdownNow();
}
}

private int extractGoRoutinesCount(URI uri) {
var metrics = RestAssured.given()
.baseUri(uri.toString())
.when()
.get("/metrics")
.then()
.statusCode(200)
.extract().asString();

final Matcher matcher = GO_ROUTINES_EXTRACT_PATTERN.matcher(metrics);
if (matcher.find()) {
return Integer.parseInt(matcher.group(1));
}

return -1;
}
}

0 comments on commit 2ebc1a8

Please sign in to comment.