Skip to content

Commit

Permalink
Corrected after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Dec 27, 2023
1 parent f78339b commit f659be3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 65 deletions.
18 changes: 7 additions & 11 deletions src/main/kotlin/com/exactpro/th2/http/client/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.module.kotlin.KotlinFeature
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.google.common.util.concurrent.ThreadFactoryBuilder
import mu.KotlinLogging
import rawhttp.core.RawHttpRequest
import rawhttp.core.RawHttpResponse
Expand All @@ -65,7 +66,6 @@ import java.util.ServiceLoader
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit.SECONDS
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong

private const val SEND_PIN_ATTRIBUTE = "send"
Expand Down Expand Up @@ -94,7 +94,7 @@ class Application(
.configure(KotlinFeature.NullToEmptyCollection, false)
.configure(KotlinFeature.NullToEmptyMap, false)
.configure(KotlinFeature.NullIsSameAsDefault, true)
.configure(KotlinFeature.SingletonSupport, false)
.configure(KotlinFeature.SingletonSupport, true)
.configure(KotlinFeature.StrictNullChecks, false)
.build()
)
Expand Down Expand Up @@ -326,12 +326,8 @@ private fun createSequence(): () -> Long = Instant.now().run {
AtomicLong(epochSecond * SECONDS.toNanos(1) + nano)
}::incrementAndGet

private fun createExecutorService(maxCount: Int): ExecutorService {
val threadCount = AtomicInteger(1)
return Executors.newFixedThreadPool(maxCount) { runnable: Runnable? ->
Thread(runnable).apply {
isDaemon = true
name = "th2-http-client-${threadCount.incrementAndGet()}"
}
}
}
private fun createExecutorService(maxCount: Int): ExecutorService =
Executors.newFixedThreadPool(maxCount, ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat("th2-http-client-%d")
.build())
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ import org.junit.jupiter.api.Test
import strikt.api.Assertion
import strikt.api.expectThat
import strikt.assertions.all
import strikt.assertions.hasSize
import strikt.assertions.isEmpty
import strikt.assertions.isEqualTo
import strikt.assertions.isFalse
import strikt.assertions.matches
import strikt.assertions.single
import strikt.assertions.withElementAt
import java.time.Duration.ofSeconds
import java.time.Instant
Expand Down Expand Up @@ -127,24 +127,21 @@ class ApplicationIntegrationTest {

assertNotNull(eventListener.poll(ofSeconds(2))).also {
expectThat(it) {
get { eventsList }.apply {
hasSize(1)
withElementAt(0) {
get { name }.isEqualTo("Failed to handle transport message group")
get { type }.isEqualTo("Error")
get { status }.isEqualTo(EventStatus.FAILED)
get { id }.apply {
get { bookName }.isEqualTo(rootEventId.bookName)
get { scope }.isEqualTo(rootEventId.scope)
}
get { parentId }.isEqualTo(rootEventId)
get { attachedMessageIdsList }.isEmpty()
get { body.toString(Charsets.UTF_8) }.isEqualTo(
"""
get { eventsList }.single().apply {
get { name }.isEqualTo("Failed to handle transport message group")
get { type }.isEqualTo("Error")
get { status }.isEqualTo(EventStatus.FAILED)
get { id }.apply {
get { bookName }.isEqualTo(rootEventId.bookName)
get { scope }.isEqualTo(rootEventId.scope)
}
get { parentId }.isEqualTo(rootEventId)
get { attachedMessageIdsList }.isEmpty()
get { body.toString(Charsets.UTF_8) }.isEqualTo(
"""
[{"data":"java.net.ConnectException: Connection refused (Connection refused)","type":"message"}]
""".trimIndent()
)
}
)
}
}
}
Expand Down Expand Up @@ -186,24 +183,21 @@ class ApplicationIntegrationTest {

assertNotNull(eventListener.poll(ofSeconds(2))).also {
expectThat(it) {
get { eventsList }.apply {
hasSize(1)
withElementAt(0) {
get { name }.isEqualTo("Failed to handle transport message group")
get { type }.isEqualTo("Error")
get { status }.isEqualTo(EventStatus.FAILED)
get { id }.apply {
get { bookName }.isEqualTo(eventId.book)
get { scope }.isEqualTo(eventId.scope)
}
get { parentId }.isEqualTo(eventId.toProto())
get { attachedMessageIdsList }.isEmpty()
get { body.toString(Charsets.UTF_8) }.isEqualTo(
"""
get { eventsList }.single().apply {
get { name }.isEqualTo("Failed to handle transport message group")
get { type }.isEqualTo("Error")
get { status }.isEqualTo(EventStatus.FAILED)
get { id }.apply {
get { bookName }.isEqualTo(eventId.book)
get { scope }.isEqualTo(eventId.scope)
}
get { parentId }.isEqualTo(eventId.toProto())
get { attachedMessageIdsList }.isEmpty()
get { body.toString(Charsets.UTF_8) }.isEqualTo(
"""
[{"data":"java.net.ConnectException: Connection refused (Connection refused)","type":"message"}]
""".trimIndent()
)
}
)
}
}
}
Expand Down Expand Up @@ -268,22 +262,19 @@ class ApplicationIntegrationTest {

expectThat(events) {
all {
get { eventsList }.apply {
hasSize(1)
withElementAt(0) {
get { name }.isEqualTo("Failed to handle transport message group")
get { type }.isEqualTo("Error")
get { status }.isEqualTo(EventStatus.FAILED)
get { id }.apply {
get { bookName }.isEqualTo(BOOK_TEST)
}
get { attachedMessageIdsList }.isEmpty()
get { body.toString(Charsets.UTF_8) }.isEqualTo(
"""
[{"data":"java.net.ConnectException: Connection refused (Connection refused)","type":"message"}]
""".trimIndent()
)
get { eventsList }.single().apply {
get { name }.isEqualTo("Failed to handle transport message group")
get { type }.isEqualTo("Error")
get { status }.isEqualTo(EventStatus.FAILED)
get { id }.apply {
get { bookName }.isEqualTo(BOOK_TEST)
}
get { attachedMessageIdsList }.isEmpty()
get { body.toString(Charsets.UTF_8) }.isEqualTo(
"""
[{"data":"java.net.ConnectException: Connection refused (Connection refused)","type":"message"}]
""".trimIndent()
)
}
}
withElementAt(0) {
Expand Down Expand Up @@ -324,12 +315,7 @@ class ApplicationIntegrationTest {
private fun CollectorMessageListener<EventBatch>.assertRootEvent() =
assertNotNull(poll(ofSeconds(1))).also {
expectThat(it) {
get { eventsList }.apply {
hasSize(1)
withElementAt(0) {
isRootEvent(DEFAULT_BOOK_NAME, "app")
}
}
get { eventsList }.single().isRootEvent(DEFAULT_BOOK_NAME, "app")
}
}.getEvents(0)

Expand Down

0 comments on commit f659be3

Please sign in to comment.