Skip to content

Commit

Permalink
Add support for org.apache.curator:curator-framework:5.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian committed Sep 6, 2023
1 parent 939d438 commit 5952616
Show file tree
Hide file tree
Showing 15 changed files with 608 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 @@ -164,6 +164,10 @@
"allowed-packages" : [ "javax.cache" ],
"directory" : "javax.cache/cache-api",
"module" : "javax.cache:cache-api"
}, {
"allowed-packages" : [ "org.apache.curator" ],
"directory" : "org.apache.curator/curator-framework",
"module" : "org.apache.curator:curator-framework"
}, {
"allowed-packages" : [ "com.sun.mail", "jakarta" ],
"directory" : "com.sun.mail/jakarta.mail",
Expand Down
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,84 @@
[
{
"condition":{"typeReachable":"org.apache.curator.framework.schema.SchemaSetLoader"},
"name":"com.fasterxml.jackson.databind.ext.Java7SupportImpl",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.NamespaceWatcher"},
"name":"java.lang.Object",
"methods":[{"name":"toString","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.NamespaceWatcher"},
"name":"java.lang.StackWalker",
"methods":[
{"name":"getInstance","parameterTypes":["java.util.Set","int"] },
{"name":"walk","parameterTypes":["java.util.function.Function"] }
]
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.NamespaceWatcher"},
"name":"java.lang.StackWalker$Option"
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.NamespaceWatcher"},
"name":"java.lang.StackWalker$StackFrame",
"methods":[
{"name":"getClassName","parameterTypes":[] },
{"name":"getFileName","parameterTypes":[] },
{"name":"getLineNumber","parameterTypes":[] },
{"name":"getMethodName","parameterTypes":[] }
]
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.CuratorFrameworkImpl"},
"name":"java.lang.Throwable",
"methods":[{"name":"getSuppressed","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.ProtectedMode"},
"name":"java.security.SecureRandomParameters"
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.NamespaceFacadeCache"},
"name":"org.apache.curator.shaded.com.google.common.util.concurrent.AbstractFuture",
"fields":[
{"name":"listeners"},
{"name":"value"},
{"name":"waiters"}
]
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.NamespaceFacadeCache"},
"name":"org.apache.curator.shaded.com.google.common.util.concurrent.AbstractFuture$Waiter",
"fields":[
{"name":"next"},
{"name":"thread"}
]
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.EnsembleTracker"},
"name":"org.apache.zookeeper.AddWatchMode"
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.EnsembleTracker"},
"name":"org.apache.zookeeper.server.quorum.MultipleAddresses",
"methods":[{"name":"getReachableOrOne","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.EnsembleTracker"},
"name":"org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer",
"fields":[{"name":"addr"}]
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.NamespaceFacadeCache"},
"name":"sun.misc.Unsafe",
"allDeclaredFields":true
},
{
"condition":{"typeReachable":"org.apache.curator.framework.imps.ProtectedMode"},
"name":"sun.security.provider.NativePRNG",
"methods":[{"name":"<init>","parameterTypes":[] }]
}
]
10 changes: 10 additions & 0 deletions metadata/org.apache.curator/curator-framework/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-framework",
"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 @@ -250,6 +250,12 @@
"name" : "javax.cache:cache-api",
"versions" : [ "1.1.1" ]
} ]
}, {
"test-project-path" : "org.apache.curator/curator-framework/5.5.0",
"libraries" : [ {
"name" : "org.apache.curator:curator-framework",
"versions" : [ "5.5.0" ]
} ]
}, {
"test-project-path" : "com.sun.mail/jakarta.mail/2.0.1",
"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-framework/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-framework:$libraryVersion"
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation "org.apache.curator:curator-test:$libraryVersion"
testImplementation 'org.awaitility:awaitility:4.2.0'
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-framework")
}
}
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-framework/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-framework_tests'
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* 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_framework;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.api.transaction.CuratorOp;
import org.apache.curator.framework.api.transaction.CuratorTransactionResult;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class CuratorFrameworkTest {

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

@Test
void testCreateClient() {
try (CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectString(),
new ExponentialBackoffRetry(1000, 3))) {
client.start();
assertDoesNotThrow(() -> client.blockUntilConnected());
}
try (CuratorFramework client = getCuratorFramework()) {
client.start();
assertDoesNotThrow(() -> client.blockUntilConnected());
}
}

@Test
void testCRUD() {
try (CuratorFramework client = getCuratorFramework()) {
client.start();
assertDoesNotThrow(() -> client.blockUntilConnected());
client.create().forPath("/testCreate", new byte[0]);
client.create().withMode(CreateMode.EPHEMERAL).forPath("/testCreateEphemeral", new byte[0]);
client.create().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/testCreateEphemeralSequential", new byte[0]);
client.create().idempotent().forPath("/testCreateIdempotent", new byte[0]);
assertThat(client.getChildren().watched().forPath("/testCreate")).isEmpty();
assertThat(client.getChildren().watched().forPath("/testCreateEphemeral")).isEmpty();
assertThrows(KeeperException.NoNodeException.class, () -> client.getChildren().watched().forPath("/testCreateEphemeralSequential"));
assertThat(client.getChildren().watched().forPath("/testCreateIdempotent")).isEmpty();
client.setData().forPath("/testCreate", "firstTestWord".getBytes(StandardCharsets.UTF_8));
assertThat(client.getChildren().watched().forPath("/testCreate")).isEmpty();
client.getCuratorListenable().addListener((client1, event) -> {
});
client.setData().inBackground().forPath("/testCreate", "secondTestWord".getBytes(StandardCharsets.UTF_8));
assertThat(client.getChildren().watched().forPath("/testCreate")).isEmpty();
client.setData().idempotent().withVersion(2).forPath("/testCreate", "thirdTestWord".getBytes(StandardCharsets.UTF_8));
assertThat(client.getChildren().watched().forPath("/testCreate")).isEmpty();
client.delete().forPath("/testCreate");
assertThrows(KeeperException.NoNodeException.class, () -> client.getChildren().watched().forPath("/testCreate"));
client.delete().guaranteed().forPath("/testCreateEphemeral");
assertThrows(KeeperException.NoNodeException.class, () -> client.getChildren().watched().forPath("/testCreateEphemeral"));
client.delete().idempotent().withVersion(0).forPath("/testCreateIdempotent");
assertThrows(KeeperException.NoNodeException.class, () -> client.getChildren().watched().forPath("/testCreateIdempotent"));
client.create().forPath("/deleteIdempotentFirst", new byte[0]);
client.create().forPath("/deleteIdempotentSecond", new byte[0]);
client.create().forPath("/deleteIdempotentThird", new byte[0]);
client.delete().idempotent().forPath("/deleteIdempotentFirst");
client.delete().quietly().withVersion(0).forPath("/deleteIdempotentSecond");
client.delete().quietly().forPath("/deleteIdempotentThird");
assertThrows(KeeperException.NoNodeException.class, () -> client.getChildren().watched().forPath("/deleteIdempotentFirst"));
assertThrows(KeeperException.NoNodeException.class, () -> client.getChildren().watched().forPath("/deleteIdempotentSecond"));
assertThrows(KeeperException.NoNodeException.class, () -> client.getChildren().watched().forPath("/deleteIdempotentThird"));
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Test
void testTransaction() {
try (CuratorFramework client = getCuratorFramework()) {
client.start();
assertDoesNotThrow(() -> client.blockUntilConnected());
client.create().forPath("/testFirst", new byte[0]);
client.create().forPath("/testSecond", new byte[0]);
client.create().forPath("/testSecond/path", new byte[0]);
client.create().forPath("/testThird", new byte[0]);
client.create().forPath("/testThird/testSagittarius", new byte[0]);
client.create().forPath("/testThird/testSagittarius/path", new byte[0]);
CuratorOp createOp = client.transactionOp().create().forPath("/testFirst/path", "some data".getBytes());
CuratorOp setDataOp = client.transactionOp().setData().forPath("/testSecond/path", "other data".getBytes());
CuratorOp deleteOp = client.transactionOp().delete().forPath("/testThird/testSagittarius/path");
List<CuratorTransactionResult> results = client.transaction().forOperations(createOp, setDataOp, deleteOp);
assertThat(results.get(0).getForPath()).isEqualTo("/testFirst/path");
assertThat(results.get(1).getForPath()).isEqualTo("/testSecond/path");
assertThat(results.get(2).getForPath()).isEqualTo("/testThird/testSagittarius/path");
assertThat(results.get(0).getForPath()).isEqualTo("/testFirst/path");
assertThat(results.get(1).getForPath()).isEqualTo("/testSecond/path");
assertThat(results.get(2).getForPath()).isEqualTo("/testThird/testSagittarius/path");
for (CuratorTransactionResult result : results) {
System.out.println(result.getForPath() + " - " + result.getType());

}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private CuratorFramework getCuratorFramework() {
return CuratorFrameworkFactory.builder()
.connectString(EmbedTestingServer.getConnectString())
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.connectionTimeoutMs(10000)
.sessionTimeoutMs(10000)
.build();
}
}
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_framework;

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 = 3192;
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;
}
}
Loading

0 comments on commit 5952616

Please sign in to comment.