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

Added metadata for io.nats:jnats:2.16.11 #311

Merged
merged 3 commits into from
Jun 29, 2023
Merged
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
7 changes: 7 additions & 0 deletions metadata/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@
"io.netty"
]
},
{
"directory" : "io.nats/jnats",
"module" : "io.nats:jnats",
"allowed-packages" : [
"io.nats"
]
},
{
"directory": "mysql/mysql-connector-java",
"module": "mysql:mysql-connector-java",
Expand Down
3 changes: 3 additions & 0 deletions metadata/io.nats/jnats/2.16.11/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"reflect-config.json"
]
16 changes: 16 additions & 0 deletions metadata/io.nats/jnats/2.16.11/reflect-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"name": "io.nats.client.impl.SocketDataPort",
"condition": {
"typeReachable": "io.nats.client.Options$Builder"
},
"methods": [
{
"name": "<init>",
"parameterTypes": [

]
}
]
}
]
10 changes: 10 additions & 0 deletions metadata/io.nats/jnats/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"latest": true,
"metadata-version": "2.16.11",
"module": "io.nats:jnats",
"tested-versions": [
"2.16.11"
]
}
]
11 changes: 11 additions & 0 deletions tests/src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@
}
]
},
{
"test-project-path" : "io.nats/jnats/2.16.11",
"libraries" : [
{
"name" : "io.nats:jnats",
"versions" : [
"2.16.11"
]
}
]
},
{
"test-project-path": "mysql/mysql-connector-java/8.0.29",
"libraries": [
Expand Down
4 changes: 4 additions & 0 deletions tests/src/io.nats/jnats/2.16.11/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gradlew.bat
gradlew
gradle/
build/
29 changes: 29 additions & 0 deletions tests/src/io.nats/jnats/2.16.11/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 "io.nats:jnats:$libraryVersion"
testImplementation 'org.assertj:assertj-core:3.22.0'
}

graalvmNative {
agent {
defaultMode = "conditional"
modes {
conditional {
userCodeFilterPath = "metadata-user-code-filter.json"
extraFilterPath = "metadata-extra-filter.json"
}
}
}
}
2 changes: 2 additions & 0 deletions tests/src/io.nats/jnats/2.16.11/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library.version = 2.16.11
metadata.dir = io.nats/jnats/2.16.11/
5 changes: 5 additions & 0 deletions tests/src/io.nats/jnats/2.16.11/metadata-extra-filter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": [
{"includeClasses": "io.nats.**"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": [
{"includeClasses": "io.nats.**"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nats:2.9.19
13 changes: 13 additions & 0 deletions tests/src/io.nats/jnats/2.16.11/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 = 'io.nats.jnats_tests'
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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 io_nats.jnats;

import io.nats.client.Connection;
import io.nats.client.Dispatcher;
import io.nats.client.Nats;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

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

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class JnatsTest {

private Process process;

@BeforeAll
public void init() throws IOException {
System.out.println("Starting NATS ...");
process = new ProcessBuilder("docker", "run", "--rm", "-p", "4222:4222", "nats:2.9.19").inheritIO().start();

waitUntil(() -> {
openConnection().close();
return true;
}, 120, 1);

System.out.println("NATS started");
}

@AfterAll
public void close() {
if (process != null && process.isAlive()) {
System.out.println("Shutting down NATS");
process.destroy();
}
}

// not using Awaitility library because of `com.oracle.svm.core.jdk.UnsupportedFeatureError: ThreadMXBean methods` issue
// which happens if a condition is not fulfilled when a test is running in a native image
private void waitUntil(Callable<Boolean> conditionEvaluator, int timeoutSeconds, int sleepTimeSeconds) {
Exception lastException = null;

long end = System.currentTimeMillis() + timeoutSeconds * 1000L;
while (System.currentTimeMillis() < end) {
try {
Thread.sleep(sleepTimeSeconds * 1000L);
} catch (InterruptedException e) {
// continue
}
try {
if (conditionEvaluator.call()) {
return;
}
} catch (Exception e) {
lastException = e;
}
}
String errorMessage = "Condition was not fulfilled within " + timeoutSeconds + " seconds";
throw lastException == null ? new IllegalStateException(errorMessage) : new IllegalStateException(errorMessage, lastException);
}

private Connection openConnection() throws Exception {
return Nats.connect();
}

@Test
void test() throws Exception {
try (Connection connection = openConnection()) {
final List<String> receivedMessages = new ArrayList<>();
Dispatcher dispatcher = connection.createDispatcher((msg) -> receivedMessages.add(new String(msg.getData(), StandardCharsets.UTF_8)));
dispatcher.subscribe("test-subject");

connection.publish("test-subject", "test-message".getBytes(StandardCharsets.UTF_8));

waitUntil(() -> !receivedMessages.isEmpty(), 10, 1);

assertThat(receivedMessages)
.hasSize(1)
.containsExactly("test-message");
}
}
}
Loading