Skip to content

Commit

Permalink
Add support for org.apache.curator:curator-client:5.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian committed Sep 4, 2023
1 parent 939d438 commit 5de2eac
Show file tree
Hide file tree
Showing 14 changed files with 527 additions and 0 deletions.
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,34 @@
[
{
"condition":{"typeReachable":"org.apache.curator.retry.RetryForever"},
"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":[] }
]
},
{
"condition":{"typeReachable":"org.apache.curator.utils.DefaultZookeeperFactory"},
"name":"org.apache.zookeeper.ClientCnxnSocketNIO",
"methods":[{"name":"<init>","parameterTypes":["org.apache.zookeeper.client.ZKClientConfig"] }]
}
]
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
4 changes: 4 additions & 0 deletions tests/src/org.apache.curator/curator-client/5.5.0/.gitignore
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/
13 changes: 13 additions & 0 deletions tests/src/org.apache.curator/curator-client/5.5.0/settings.gradle
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,128 @@
/*
* 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.*;

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

0 comments on commit 5de2eac

Please sign in to comment.