diff --git a/zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt b/zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt index 6349356..594e9f2 100644 --- a/zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt +++ b/zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt @@ -276,7 +276,7 @@ internal class JNISession { getViaJNI( selector.keyExpr.jniKeyExpr?.ptr ?: 0, selector.keyExpr.keyExpr, - selector.parameters.toString(), + selector.parameters?.toString(), sessionPtr.get(), getCallback, fun() {}, @@ -338,7 +338,7 @@ internal class JNISession { getViaJNI( selector.keyExpr.jniKeyExpr?.ptr ?: 0, selector.keyExpr.keyExpr, - selector.parameters.toString(), + selector.parameters?.toString(), sessionPtr.get(), getCallback, handler::onClose, diff --git a/zenoh-java/src/jvmTest/java/io/zenoh/SelectorTest.java b/zenoh-java/src/jvmTest/java/io/zenoh/SelectorTest.java index 9252dd3..134a487 100644 --- a/zenoh-java/src/jvmTest/java/io/zenoh/SelectorTest.java +++ b/zenoh-java/src/jvmTest/java/io/zenoh/SelectorTest.java @@ -15,6 +15,7 @@ package io.zenoh; import io.zenoh.exceptions.ZError; +import io.zenoh.keyexpr.KeyExpr; import io.zenoh.query.Parameters; import io.zenoh.query.Selector; import org.junit.Test; @@ -47,4 +48,35 @@ public void parametersTest() { var parameters = Parameters.from("a=1;b=2;c=1|2|3"); assertEquals(List.of("1", "2", "3"), parameters.values("c")); } + + /** + * Check the queryable properly receives the query's selector with and without parameters. + */ + @Test + public void selectorQueryTest() throws ZError, InterruptedException { + var session = Zenoh.open(Config.loadDefault()); + var queryableKeyExpr = KeyExpr.tryFrom("a/b/**"); + + Selector[] receivedQuerySelector = new Selector[1]; + var queryable = session.declareQueryable(queryableKeyExpr, query -> { + receivedQuerySelector[0] = query.getSelector(); + query.close(); + } + ); + + var querySelector = Selector.tryFrom("a/b/c"); + session.get(querySelector, reply -> { + }); + Thread.sleep(1000); + assertEquals(querySelector, receivedQuerySelector[0]); + + var querySelector2 = Selector.tryFrom("a/b/c?key=value"); + session.get(querySelector2, reply -> { + }); + Thread.sleep(1000); + assertEquals(querySelector2, receivedQuerySelector[0]); + + queryable.close(); + session.close(); + } }