Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for org.apache.curator:curator-client:5.5.0 #381

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions metadata/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@
"allowed-packages" : [ "io.opentelemetry" ],
"directory" : "io.opentelemetry/opentelemetry-sdk-trace",
"module" : "io.opentelemetry:opentelemetry-sdk-trace"
}, {
"allowed-packages" : [ "org.apache.curator" ],
"directory" : "org.apache.curator/curator-client",
"module" : "org.apache.curator:curator-client"
}, {
"allowed-packages" : [ "jakarta.servlet" ],
"directory" : "jakarta.servlet/jakarta.servlet-api",
Expand Down
3 changes: 3 additions & 0 deletions metadata/org.apache.curator/curator-client/5.5.0/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"reflect-config.json"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"condition":{"typeReachable":"org.apache.curator.retry.RetryForever"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't contain any curator client metadata. It contains only java.lang related metadata which don't have to be added to this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"name":"java.lang.Object",
"methods":[{"name":"toString","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.curator.retry.RetryForever"},
"name":"java.lang.StackWalker",
"methods":[
{"name":"getInstance","parameterTypes":["java.util.Set","int"] },
{"name":"walk","parameterTypes":["java.util.function.Function"] }
]
},
{
"condition":{"typeReachable":"org.apache.curator.retry.RetryForever"},
"name":"java.lang.StackWalker$Option"
},
{
"condition":{"typeReachable":"org.apache.curator.retry.RetryForever"},
"name":"java.lang.StackWalker$StackFrame",
"methods":[
{"name":"getClassName","parameterTypes":[] },
{"name":"getFileName","parameterTypes":[] },
{"name":"getLineNumber","parameterTypes":[] },
{"name":"getMethodName","parameterTypes":[] }
]
}
]
10 changes: 10 additions & 0 deletions metadata/org.apache.curator/curator-client/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"latest": true,
"metadata-version": "5.5.0",
"module": "org.apache.curator:curator-client",
"tested-versions": [
"5.5.0"
]
}
]
6 changes: 6 additions & 0 deletions tests/src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@
"name" : "io.opentelemetry:opentelemetry-sdk-trace",
"versions" : [ "1.19.0" ]
} ]
},
{"test-project-path" : "org.apache.curator/curator-client/5.5.0",
"libraries" : [ {
"name" : "org.apache.curator:curator-client",
"versions" : [ "5.5.0" ]
} ]
}, {
"test-project-path" : "jakarta.servlet/jakarta.servlet-api/5.0.0",
"libraries" : [ {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gradlew.bat
gradlew
gradle/
build/
39 changes: 39 additions & 0 deletions tests/src/org.apache.curator/curator-client/5.5.0/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

plugins {
id "org.graalvm.internal.tck"
}

String libraryVersion = tck.testedLibraryVersion.get()

dependencies {
testImplementation "org.apache.curator:curator-client:$libraryVersion"
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'org.awaitility:awaitility:4.2.0'
testImplementation "org.apache.curator:curator-test:$libraryVersion"
testImplementation 'org.apache.zookeeper:zookeeper:3.9.0'
}

graalvmNative {
agent {
defaultMode = "conditional"
modes {
conditional {
userCodeFilterPath = "user-code-filter.json"
}
}
metadataCopy {
mergeWithExisting = true
inputTaskNames.add("test")
outputDirectories.add("src/test/resources/META-INF/native-image/org.apache.curator/curator-client")
}
}
metadataRepository {
enabled = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library.version = 5.5.0
metadata.dir = org.apache.curator/curator-client/5.5.0/
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pluginManagement {
def tckPath = Objects.requireNonNullElse(
System.getenv("GVM_TCK_TCKDIR"),
"../../../../tck-build-logic"
)
includeBuild(tckPath)
}

plugins {
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT"
}

rootProject.name = 'org.apache.curator.curator-client_tests'
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package org_apache_curator.curator_client;

import org.apache.curator.CuratorZookeeperClient;
import org.apache.curator.RetryLoop;
import org.apache.curator.RetryPolicy;
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryNTimes;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.retry.RetryUntilElapsed;
import org.apache.curator.utils.DefaultZookeeperFactory;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.time.Duration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class CuratorClientTest {

@BeforeAll
static void beforeAll() {
EmbedTestingServer.start();
}

@Test
void testConstructor() throws Exception {
try (CuratorZookeeperClient client = getCuratorZookeeperClient()) {
client.start();
client.blockUntilConnectedOrTimedOut();
String path = client.getZooKeeper().create("/testConstructor", new byte[]{1, 2, 3}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
assertEquals(path, "/testConstructor");
}
}

@Test
void testGetZooKeeper() throws Exception {
try (CuratorZookeeperClient client = getCuratorZookeeperClient()) {
client.start();
assertThat(client.getZooKeeper()).isNotNull();
}
}

@Test
void testIsConnected() throws Exception {
try (CuratorZookeeperClient client = getCuratorZookeeperClient()) {
client.start();
Awaitility.await()
.atMost(Duration.ofMillis(4000))
.untilAsserted(() -> assertTrue(client.isConnected()));
}
}

@Test
void testBlockUntilConnectedOrTimedOut() throws Exception {
try (CuratorZookeeperClient client = getCuratorZookeeperClient()) {
client.start();
client.blockUntilConnectedOrTimedOut();
String path = client.getZooKeeper().create("/testBlockUntilConnectedOrTimedOut", new byte[]{1, 2, 3}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
assertEquals(path, "/testBlockUntilConnectedOrTimedOut");
}
}

@Test
void testClose() {
assertDoesNotThrow(() -> {
CuratorZookeeperClient client = getCuratorZookeeperClient();
client.start();
client.blockUntilConnectedOrTimedOut();
client.close();
});
}

@Test
void testSetRetryPolicy() throws Exception {
try (CuratorZookeeperClient client = getCuratorZookeeperClient()) {
client.start();
client.blockUntilConnectedOrTimedOut();
RetryPolicy originRetryPolicy = client.getRetryPolicy();
client.setRetryPolicy(new ExponentialBackoffRetry(1, 1));
client.setRetryPolicy(new RetryNTimes(1, 1));
client.setRetryPolicy(new RetryOneTime(1));
client.setRetryPolicy(new RetryUntilElapsed(1, 1));
client.setRetryPolicy(originRetryPolicy);
String path = client.getZooKeeper().create("/testSetRetryPolicy", new byte[]{1, 2, 3}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
assertEquals(path, "/testSetRetryPolicy");
}
}

@Test
void testNewRetryLoop() throws Exception {
try (CuratorZookeeperClient client = getCuratorZookeeperClient()) {
client.start();
int loopCount = 0;
RetryLoop retryLoop = client.newRetryLoop();
while (retryLoop.shouldContinue()) {
++loopCount;
if (loopCount > 2) {
fail();
break;
}
try {
client.getZooKeeper().create("/testNewRetryLoop", new byte[]{1, 2, 3}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
retryLoop.markComplete();
} catch (Exception e) {
retryLoop.takeException(e);
}
}
assertTrue(loopCount > 0);
}
}

private CuratorZookeeperClient getCuratorZookeeperClient() {
return new CuratorZookeeperClient(new DefaultZookeeperFactory(),
new FixedEnsembleProvider(EmbedTestingServer.getConnectString()),
10000, 10000, null, new RetryOneTime(1), false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package org_apache_curator.curator_client;

import org.apache.curator.CuratorZookeeperClient;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.test.TestingServer;
import org.apache.zookeeper.KeeperException.ConnectionLossException;
import org.apache.zookeeper.KeeperException.NoNodeException;
import org.apache.zookeeper.KeeperException.NodeExistsException;
import org.awaitility.Awaitility;

import java.io.IOException;
import java.time.Duration;

import static org.junit.jupiter.api.Assertions.assertTrue;

public final class EmbedTestingServer {
private static final int PORT = 3191;
private static volatile TestingServer testingServer;
private static final Object INIT_LOCK = new Object();

private EmbedTestingServer() {
}

public static void start() {
if (null != testingServer) {
return;
}
synchronized (INIT_LOCK) {
if (null != testingServer) {
return;
}
try {
testingServer = new TestingServer(PORT, true);
} catch (final Exception ex) {
if (!(ex instanceof ConnectionLossException || ex instanceof NoNodeException || ex instanceof NodeExistsException)) {
throw new RuntimeException(ex);
}
} finally {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
testingServer.close();
} catch (final IOException ignored) {
}
}));
}
try (CuratorZookeeperClient client = new CuratorZookeeperClient(getConnectString(),
60 * 1000, 500, null,
new ExponentialBackoffRetry(500, 3, 500 * 3))) {
client.start();
Awaitility.await()
.atMost(Duration.ofMillis(500 * 60))
.untilAsserted(() -> assertTrue(client.isConnected()));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

public static String getConnectString() {
return "localhost:" + PORT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"condition":{"typeReachable":"org.apache.zookeeper.jmx.MBeanRegistry"},
"name":"java.util.Arrays",
"methods":[{"name":"asList","parameterTypes":["java.lang.Object[]"] }]
}
]
Loading