2022-04-04 14:46:22 +02:00
|
|
|
package dorkboxTest.network
|
|
|
|
|
|
|
|
import dorkbox.network.Client
|
|
|
|
import dorkbox.network.Server
|
|
|
|
import dorkbox.network.connection.Connection
|
|
|
|
import dorkbox.network.connection.ConnectionParams
|
2022-06-11 23:54:40 +02:00
|
|
|
import org.agrona.ExpandableDirectByteBuffer
|
|
|
|
import org.junit.Assert
|
2022-04-04 14:46:22 +02:00
|
|
|
import org.junit.Test
|
2022-06-11 23:54:40 +02:00
|
|
|
import java.security.SecureRandom
|
2022-04-04 14:46:22 +02:00
|
|
|
|
|
|
|
class StreamingTest : BaseTest() {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun sendStreamingObject() {
|
2022-06-29 21:56:12 +02:00
|
|
|
val sizeToTest = ExpandableDirectByteBuffer.MAX_BUFFER_LENGTH / 8
|
|
|
|
val hugeData = ByteArray(sizeToTest)
|
|
|
|
SecureRandom().nextBytes(hugeData)
|
|
|
|
|
|
|
|
|
2022-04-04 14:46:22 +02:00
|
|
|
run {
|
|
|
|
val configuration = serverConfig()
|
|
|
|
|
|
|
|
val server: Server<Connection> = Server(configuration)
|
|
|
|
addEndPoint(server)
|
|
|
|
server.bind()
|
|
|
|
|
|
|
|
server.onMessage<ByteArray> {
|
|
|
|
println("received data, shutting down!")
|
2022-06-11 23:54:40 +02:00
|
|
|
Assert.assertEquals(sizeToTest, it.size)
|
2022-06-29 21:56:12 +02:00
|
|
|
Assert.assertArrayEquals(hugeData, it)
|
2022-04-04 14:46:22 +02:00
|
|
|
stopEndPoints()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
run {
|
|
|
|
var connectionParams: ConnectionParams<Connection>? = null
|
|
|
|
val config = clientConfig()
|
|
|
|
|
|
|
|
val client: Client<Connection> = Client(config) {
|
|
|
|
connectionParams = it
|
|
|
|
Connection(it)
|
|
|
|
}
|
|
|
|
addEndPoint(client)
|
|
|
|
|
|
|
|
client.onConnect {
|
|
|
|
val params = connectionParams ?: throw Exception("We should not have null connectionParams!")
|
2022-07-29 04:52:11 +02:00
|
|
|
val publication = params.connectionInfo.publication
|
2022-04-04 14:46:22 +02:00
|
|
|
this.endPoint.send(hugeData, publication, this)
|
|
|
|
}
|
|
|
|
|
|
|
|
client.connect(LOCALHOST)
|
|
|
|
}
|
|
|
|
|
|
|
|
waitForThreads(0)
|
|
|
|
}
|
|
|
|
}
|