package dorkboxTest.network import dorkbox.network.Client import dorkbox.network.Server import dorkbox.network.connection.Connection import dorkbox.network.connection.ConnectionParams import org.agrona.ExpandableDirectByteBuffer import org.junit.Assert import org.junit.Test import java.security.SecureRandom class StreamingTest : BaseTest() { @Test fun sendStreamingObject() { val sizeToTest = ExpandableDirectByteBuffer.MAX_BUFFER_LENGTH / 8 val hugeData = ByteArray(sizeToTest) SecureRandom().nextBytes(hugeData) run { val configuration = serverConfig() val server: Server = Server(configuration) addEndPoint(server) server.bind() server.onMessage { println("received data, shutting down!") Assert.assertEquals(sizeToTest, it.size) Assert.assertArrayEquals(hugeData, it) stopEndPoints() } } run { var connectionParams: ConnectionParams? = null val config = clientConfig() val client: Client = Client(config) { connectionParams = it Connection(it) } addEndPoint(client) client.onConnect { logger.error { "Sending huge data: ${hugeData.size} bytes" } send(hugeData) } client.connect(LOCALHOST) } waitForThreads() } }