Skip to content

Commit

Permalink
Fix/selector params (#168)
Browse files Browse the repository at this point in the history
* Fix ZGet example

* fix(selector): fix selector "null" param

When performing a query to "a/b/c", the queryable received a selector of "a/b/c?null=". Caused by a missing null check.
  • Loading branch information
DariusIMP authored Jan 6, 2025
1 parent 0df5dc7 commit 03f6446
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {},
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions zenoh-java/src/jvmTest/java/io/zenoh/SelectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 03f6446

Please sign in to comment.