<commit_before>package com.fireflysource.net.http.client.impl

import com.fireflysource.net.http.common.model.HttpMethod
import com.fireflysource.net.http.common.model.HttpStatus
import com.fireflysource.net.http.common.model.HttpURI
import com.sun.net.httpserver.HttpServer
import kotlinx.coroutines.future.await
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.net.InetSocketAddress
import java.net.URL
import java.nio.charset.StandardCharsets
import kotlin.random.Random

class TestAsyncHttpClientConnectionManager {

    private lateinit var address: InetSocketAddress
    private lateinit var httpServer: HttpServer

    @BeforeEach
    fun init() {
        address = InetSocketAddress("localhost", Random.nextInt(2000, 5000))
        httpServer = HttpServer.create(address, 1024)

        httpServer.createContext("/test1") { exg ->
            val body = "test ok".toByteArray(StandardCharsets.UTF_8)
            exg.sendResponseHeaders(200, body.size.toLong())
            exg.responseBody.use { out -> out.write(body) }
            exg.close()
        }
        httpServer.start()
    }

    @AfterEach
    fun destroy() {
        httpServer.stop(5)
    }

    @Test
    fun test() = runBlocking {
        val client = AsyncHttpClientConnectionManager()

        val request = AsyncHttpClientRequest()
        request.method = HttpMethod.GET.value
        request.uri = HttpURI(URL("http://${address.hostName}:${address.port}/test1").toURI())

        val response = client.send(request).await()
        println("${response.status} ${response.reason}")
        println(response.httpFields)
        println()
        println(response.stringBody)

        assertEquals(HttpStatus.OK_200, response.status)
        assertEquals(7L, response.contentLength)
        assertEquals("test ok", response.stringBody)

        client.stop()
    }
}<commit_msg>[test]: add AsyncHttpClientConnectionManager test case<commit_after>package com.fireflysource.net.http.client.impl

import com.fireflysource.net.http.common.model.HttpMethod
import com.fireflysource.net.http.common.model.HttpStatus
import com.fireflysource.net.http.common.model.HttpURI
import com.sun.net.httpserver.HttpServer
import kotlinx.coroutines.future.await
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.net.InetSocketAddress
import java.net.URL
import java.nio.charset.StandardCharsets
import kotlin.random.Random

class TestAsyncHttpClientConnectionManager {

    private lateinit var address: InetSocketAddress
    private lateinit var httpServer: HttpServer

    @BeforeEach
    fun init() {
        address = InetSocketAddress("localhost", Random.nextInt(2000, 5000))
        httpServer = HttpServer.create(address, 1024)

        httpServer.createContext("/test1") { exg ->
            val body = "test ok".toByteArray(StandardCharsets.UTF_8)
            exg.sendResponseHeaders(200, body.size.toLong())
            exg.responseBody.use { out -> out.write(body) }
            exg.close()
        }
        httpServer.start()
    }

    @AfterEach
    fun destroy() {
        httpServer.stop(5)
    }

    @Test
    fun test() = runBlocking {
        val client = AsyncHttpClientConnectionManager()

        repeat(5) {
            val request = AsyncHttpClientRequest()
            request.method = HttpMethod.GET.value
            request.uri = HttpURI(URL("http://${address.hostName}:${address.port}/test1").toURI())

            val response = client.send(request).await()
            println("${response.status} ${response.reason}")
            println(response.httpFields)
            println()
            println(response.stringBody)

            assertEquals(HttpStatus.OK_200, response.status)
            assertEquals(7L, response.contentLength)
            assertEquals("test ok", response.stringBody)
        }

        client.stop()
    }
}
{'fraction_non_alphanumeric': 0.1064647921172795, 'fraction_numerical': 0.011295361691900985, 'mean_word_length': 3.1126482213438735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6278145', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1180, 'n_words': 203}