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

fix(tests): fix jvmTest task being stuck #69

Merged
merged 1 commit into from
Apr 26, 2024
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
75 changes: 0 additions & 75 deletions zenoh-java/src/commonTest/kotlin/io/zenoh/ConfigTest.kt

This file was deleted.

15 changes: 6 additions & 9 deletions zenoh-java/src/commonTest/kotlin/io/zenoh/DeleteTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,16 @@ import kotlin.test.assertNotNull

class DeleteTest {

companion object {
val TEST_KEY_EXP = "example/testing/keyexpr".intoKeyExpr()
}

@Test
fun subscriber_receivesDelete() {
fun delete_isProperlyReceivedBySubscriber() {
val session = Session.open()
var receivedSample: Sample? = null
val subscriber = session.declareSubscriber(TEST_KEY_EXP).with { sample -> receivedSample = sample }.res()
session.delete(TEST_KEY_EXP).res()
subscriber.undeclare()
val keyExpr = "example/testing/keyexpr".intoKeyExpr()
val subscriber = session.declareSubscriber(keyExpr).with { sample -> receivedSample = sample }.res()
session.delete(keyExpr).res()
subscriber.close()
keyExpr.close()
session.close()

assertNotNull(receivedSample)
assertEquals(receivedSample!!.kind, SampleKind.DELETE)
}
Expand Down
182 changes: 44 additions & 138 deletions zenoh-java/src/commonTest/kotlin/io/zenoh/GetTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,117 +20,63 @@ import io.zenoh.keyexpr.intoKeyExpr
import io.zenoh.prelude.SampleKind
import io.zenoh.query.Reply
import io.zenoh.queryable.Queryable
import io.zenoh.sample.Sample
import io.zenoh.selector.Selector
import io.zenoh.value.Value
import org.apache.commons.net.ntp.TimeStamp
import java.time.Duration
import java.util.*
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.test.Test
import kotlin.test.*

class GetTest {

companion object {
const val TEST_KEY_EXP = "example/testing/keyexpr"
const val TEST_KEY_EXP_WILD = "example/testing/*"
const val TEST_PAYLOAD = "Hello"
val value = Value("Test")
val timestamp = TimeStamp.getCurrentTime()
val kind = SampleKind.PUT
}

@Test
fun get_runsWithCallback() {
val sessionA = Session.open()
private lateinit var session: Session
private lateinit var keyExpr: KeyExpr
private lateinit var queryable: Queryable<Unit>

val value = Value(TEST_PAYLOAD)
val timeStamp = TimeStamp.getCurrentTime()
val kind = SampleKind.PUT
val keyExpr = TEST_KEY_EXP.intoKeyExpr()
val queryable = sessionA.declareQueryable(keyExpr).with { query ->
query.reply(keyExpr)
@BeforeTest
fun setUp() {
session = Session.open()
keyExpr = "example/testing/keyexpr".intoKeyExpr()
queryable = session.declareQueryable(keyExpr).with { query ->
query.reply(query.keyExpr)
.success(value)
.withTimeStamp(timeStamp)
.withTimeStamp(timestamp)
.withKind(kind)
.res()
}.res()

val sessionB = Session.open()

sessionB.get(keyExpr).with { reply: Reply ->
assertTrue(reply is Reply.Success)
assertEquals(value, reply.sample.value)
assertEquals(kind, reply.sample.kind)
assertEquals(keyExpr, reply.sample.keyExpr)
assertEquals(timeStamp, reply.sample.timestamp)
}.timeout(Duration.ofMillis(1000)).res()

Thread.sleep(1000)

queryable.undeclare()
sessionA.close()
sessionB.close()
}

@Test
fun getWithSelectorParamsTest() {
val session = Session.open()

var receivedParams = ""
val keyExpr = TEST_KEY_EXP.intoKeyExpr()
val queryable = session.declareQueryable(keyExpr).with { it.use { query ->
receivedParams = query.parameters
}}.res()

val params = "arg1=val1,arg2=val2"
val selector = Selector(keyExpr, params)
session.get(selector).res()

@AfterTest
fun tearDown() {
keyExpr.close()
queryable.close()
session.close()
}

assertEquals(params, receivedParams)
@Test
fun get_runsWithCallback() {
var reply: Reply? = null
session.get(keyExpr).with { reply = it }.timeout(Duration.ofMillis(1000)).res()

assertTrue(reply is Reply.Success)
val sample = (reply as Reply.Success).sample
assertEquals(value, sample.value)
assertEquals(kind, sample.kind)
assertEquals(keyExpr, sample.keyExpr)
assertEquals(timestamp, sample.timestamp)
}

@Test
fun get_runsWithHandler() {
val sessionA = Session.open()
val repliedSamples: ArrayList<Sample> = ArrayList()
val queryablesAmount = 3
val declaredQueryables: ArrayList<Queryable<Unit>> = ArrayList()

val value = Value(TEST_PAYLOAD)
val timestamp = TimeStamp.getCurrentTime()
val kind = SampleKind.PUT

for (i in 1..queryablesAmount) {
val keyExpr = KeyExpr.tryFrom(TEST_KEY_EXP + i.toString())
val queryable = sessionA.declareQueryable(keyExpr).with { it.use { query ->
query.reply(keyExpr)
.success(value)
.withTimeStamp(timestamp)
.withKind(kind)
.res()
}
}
.res()

declaredQueryables.add(queryable)
repliedSamples.add(Sample(keyExpr, value, kind, timestamp))
}

val sessionB = Session.open()
val receiver: ArrayList<Reply> =
sessionB.get(TEST_KEY_EXP_WILD.intoKeyExpr())
.with(GetHandler())
.timeout(Duration.ofMillis(1000))
.res()!!
val receiver: ArrayList<Reply> = session.get(keyExpr).with(TestHandler())
.timeout(Duration.ofMillis(1000)).res()!!

Thread.sleep(1000)
declaredQueryables.forEach { queryable -> queryable.undeclare() }
sessionA.close()
sessionB.close()

assertEquals(queryablesAmount, receiver.size)
for (reply in receiver) {
reply as Reply.Success
val receivedSample = reply.sample
Expand All @@ -141,66 +87,26 @@ class GetTest {
}

@Test
fun get_runsWithBlockingQueue() {
val sessionA = Session.open()

val queryablesAmount = 3
val declaredQueryables: ArrayList<Queryable<Unit>> = ArrayList()

val value = Value(TEST_PAYLOAD)
val timestamp = TimeStamp.getCurrentTime()
val kind = SampleKind.PUT

for (i in 1..queryablesAmount) {
val keyExpr = (TEST_KEY_EXP + i.toString()).intoKeyExpr()
val queryable = sessionA.declareQueryable(keyExpr).with { it.use { query ->
query.reply(keyExpr)
.success(value)
.withTimeStamp(timestamp)
.withKind(kind)
.res()
}
}
.res()

declaredQueryables.add(queryable)
}

val receivedReplies = ArrayList<Reply>(0)

val sessionB = Session.open()
val receiver = sessionB.get(TEST_KEY_EXP_WILD.intoKeyExpr()).res()!!

Thread.sleep(1000)

val iterator = receiver.iterator()
while (iterator.hasNext()) {
try {
val reply = iterator.next().get()
receivedReplies.add(reply)
} catch (e: Exception) {
break
fun getWithSelectorParamsTest() {
var receivedParams = String()
val queryable = session.declareQueryable(keyExpr).with {
it.use { query ->
receivedParams = query.parameters
}
}

sessionB.close()
}.res()

declaredQueryables.forEach { queryable -> queryable.undeclare() }
sessionA.close()
val params = "arg1=val1,arg2=val2"
val selector = Selector(keyExpr, params)
session.get(selector).with {}.timeout(Duration.ofMillis(1000)).res()
Thread.sleep(1000)

assertEquals(queryablesAmount, receivedReplies.size)
for (reply in receivedReplies) {
assert(reply is Reply.Success)
val receivedSample = (reply as Reply.Success).sample
assertEquals(value, receivedSample.value)
assertEquals(SampleKind.PUT, receivedSample.kind)
assertEquals(timestamp, receivedSample.timestamp)
}
queryable.close()
assertEquals(params, receivedParams)
}
}

/** A dummy handler for get operations. */
private class GetHandler : Handler<Reply, ArrayList<Reply>> {
private class TestHandler : Handler<Reply, ArrayList<Reply>> {

val performedReplies: ArrayList<Reply> = ArrayList()

Expand Down
Loading
Loading