Skip to content

Commit

Permalink
fix(selector): "null" parameter (#333)
Browse files Browse the repository at this point in the history
When sending query to "a/b/c" selector (for instance), the queryable was receiving "a/b/c?null" as selector. Bug caused by missing '?' null check.
  • Loading branch information
DariusIMP authored Jan 9, 2025
1 parent f2f9896 commit 64593b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ internal class JNISession {
getViaJNI(
selector.keyExpr.jniKeyExpr?.ptr ?: 0,
selector.keyExpr.keyExpr,
selector.parameters.toString(),
selector.parameters?.toString(),
sessionPtr.get(),
getCallback,
onClose,
Expand Down
31 changes: 31 additions & 0 deletions zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SelectorTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.zenoh

import io.zenoh.exceptions.ZError
import io.zenoh.keyexpr.intoKeyExpr
import io.zenoh.query.Selector
import io.zenoh.query.intoSelector
import org.junit.jupiter.api.Assertions.assertNull
Expand Down Expand Up @@ -35,4 +36,34 @@ class SelectorTest {
assertEquals("a/b/c", selector.toString())
}
}

/**
* Check the queryable properly receives the query's selector with and without parameters.
*/
@Test
fun `selector query test`() {
val session = Zenoh.open(Config.default()).getOrThrow()
val queryableKeyExpr = "a/b/**".intoKeyExpr().getOrThrow()

var receivedQuerySelector: Selector? = null
val queryable = session.declareQueryable(queryableKeyExpr, callback = { query ->
receivedQuerySelector = query.selector
query.close()
}
).getOrThrow()

val querySelector = "a/b/c".intoSelector().getOrThrow()
session.get(querySelector, callback = {}).getOrThrow()
Thread.sleep(1000)
assertEquals(querySelector, receivedQuerySelector)


val querySelector2 = "a/b/c?key=value".intoSelector().getOrThrow()
session.get(querySelector2, callback = {}).getOrThrow()
Thread.sleep(1000)
assertEquals(querySelector2, receivedQuerySelector)

queryable.close()
session.close()
}
}

0 comments on commit 64593b7

Please sign in to comment.