Skip to content

Commit

Permalink
issue(publisher write): Removing write from Publisher since it was re…
Browse files Browse the repository at this point in the history
…moved on the Rust API. (#57)
  • Loading branch information
DariusIMP authored Apr 12, 2024
1 parent 352a2f6 commit 2e654c9
Show file tree
Hide file tree
Showing 6 changed files with 825 additions and 698 deletions.
24 changes: 0 additions & 24 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNIPublisher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package io.zenoh.jni

import io.zenoh.*
import io.zenoh.exceptions.ZenohException
import io.zenoh.prelude.SampleKind
import io.zenoh.publication.CongestionControl
import io.zenoh.publication.Priority
import io.zenoh.sample.Attachment
Expand All @@ -40,24 +39,6 @@ internal class JNIPublisher(private val ptr: Long) {
putViaJNI(value.payload, value.encoding.knownEncoding.ordinal, attachment?.let { encodeAttachment(it) }, ptr)
}

/**
* Write operation.
*
* @param kind The [SampleKind].
* @param value The [Value] to be written.
* @param attachment Optional [Attachment].
*/
@Throws(ZenohException::class)
fun write(kind: SampleKind, value: Value, attachment: Attachment?) {
writeViaJNI(
value.payload,
value.encoding.knownEncoding.ordinal,
kind.ordinal,
attachment?.let { encodeAttachment(it) },
ptr
)
}

/**
* Delete operation.
*
Expand Down Expand Up @@ -130,11 +111,6 @@ internal class JNIPublisher(private val ptr: Long) {
valuePayload: ByteArray, valueEncoding: Int, encodedAttachment: ByteArray?, ptr: Long
)

@Throws(ZenohException::class)
private external fun writeViaJNI(
payload: ByteArray, encoding: Int, sampleKind: Int, encodedAttachment: ByteArray?, ptr: Long
)

@Throws(ZenohException::class)
private external fun deleteViaJNI(encodedAttachment: ByteArray?, ptr: Long)

Expand Down
25 changes: 0 additions & 25 deletions zenoh-java/src/commonMain/kotlin/io/zenoh/publication/Publisher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,6 @@ class Publisher internal constructor(
/** Performs a PUT operation on the specified [keyExpr] with the specified string [value]. */
fun put(value: String) = Put(jniPublisher, Value(value))

/**
* Performs a WRITE operation on the specified [keyExpr]
*
* @param kind The [SampleKind] of the data.
* @param value The [Value] to send.
* @return A [Resolvable] operation.
*/
fun write(kind: SampleKind, value: Value) = Write(jniPublisher, value, kind)


/**
* Performs a DELETE operation on the specified [keyExpr]
*
Expand Down Expand Up @@ -162,21 +152,6 @@ class Publisher internal constructor(
}
}

class Write internal constructor(
private var jniPublisher: JNIPublisher?,
val value: Value,
val sampleKind: SampleKind,
var attachment: Attachment? = null
) : Resolvable<Unit> {

fun withAttachment(attachment: Attachment) = apply { this.attachment = attachment }

@Throws(ZenohException::class)
override fun res() {
jniPublisher?.write(sampleKind, value, attachment)
}
}

class Delete internal constructor(
private var jniPublisher: JNIPublisher?,
var attachment: Attachment? = null
Expand Down
26 changes: 0 additions & 26 deletions zenoh-java/src/commonTest/kotlin/io/zenoh/PublisherTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,6 @@ class PublisherTest {
}
}

@Test
fun writeTest() {
val session = Session.open()
val receivedSamples = ArrayList<Sample>()
val subscriber = session.declareSubscriber(TEST_KEY_EXP).with { sample ->
receivedSamples.add(sample)
}.res()

val testSamples = arrayListOf(
Sample(TEST_KEY_EXP, Value("Test PUT"), SampleKind.PUT, null),
Sample(TEST_KEY_EXP, Value("Test DELETE"), SampleKind.DELETE, null),
)

val publisher = session.declarePublisher(TEST_KEY_EXP).res()
publisher.write(testSamples[0].kind, testSamples[0].value).res()
publisher.write(testSamples[1].kind, testSamples[1].value).res()

subscriber.undeclare()
publisher.undeclare()
session.close()
assertEquals(testSamples.size, receivedSamples.size)
for ((index, sample) in receivedSamples.withIndex()) {
assertEquals(sample, testSamples[index])
}
}

@Test
fun deleteTest() {
val session = Session.open()
Expand Down
42 changes: 0 additions & 42 deletions zenoh-java/src/commonTest/kotlin/io/zenoh/UserAttachmentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,48 +108,6 @@ class UserAttachmentTest {
assertNull(receivedSample!!.attachment)
}

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

var receivedSample: Sample? = null
val publisher = session.declarePublisher(keyExpr).res()
val subscriber = session.declareSubscriber(keyExpr).with { sample ->
receivedSample = sample
}.res()

publisher.write(SampleKind.PUT, Value("test")).withAttachment(attachment).res()
Thread.sleep(500)

subscriber.close()
publisher.close()
session.close()

assertAttachmentOk(receivedSample!!.attachment!!)
}

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

var receivedSample: Sample? = null
val publisher = session.declarePublisher(keyExpr).res()
val subscriber = session.declareSubscriber(keyExpr).with { sample ->
receivedSample = sample
}.res()

publisher.write(SampleKind.PUT, Value("test")).res()

Thread.sleep(500)

publisher.close()
subscriber.close()
session.close()

assertNotNull(receivedSample)
assertNull(receivedSample!!.attachment)
}

@Test
fun publisherDeleteWithAttachmentTest() {
val session = Session.open()
Expand Down
Loading

0 comments on commit 2e654c9

Please sign in to comment.