Best Kotest code snippet using io.kotest.matchers.future.matchers.test
ProfiledConnectionPoolListenerTest.kt
Source:ProfiledConnectionPoolListenerTest.kt
...4import com.linecorp.armeria.client.WebClient5import com.linecorp.armeria.common.HttpResponse6import com.linecorp.armeria.common.HttpStatus7import com.linecorp.armeria.common.SessionProtocol8import io.kotest.assertions.assertSoftly9import io.kotest.assertions.timing.eventually10import io.kotest.matchers.longs.shouldBeBetween11import io.kotest.matchers.maps.shouldContainExactly12import io.kotest.matchers.nulls.shouldNotBeNull13import io.kotest.matchers.should14import io.kotest.matchers.shouldBe15import kotlinx.coroutines.future.await16import org.apache.logging.log4j.kotlin.Logging17import org.junit.jupiter.api.*18import ru.fix.aggregating.profiler.AggregatingProfiler19import ru.fix.armeria.aggregating.profiler.ProfilerTestUtils.EPOLL_SOCKET_CHANNEL20import ru.fix.armeria.aggregating.profiler.ProfilerTestUtils.indicatorWithNameEnding21import ru.fix.armeria.aggregating.profiler.ProfilerTestUtils.profiledCallReportWithNameEnding22import ru.fix.armeria.commons.testing.ArmeriaMockServer23import ru.fix.armeria.commons.testing.LocalHost24import java.time.Duration25import kotlin.time.ExperimentalTime26import kotlin.time.milliseconds27import kotlin.time.seconds28@ExperimentalTime29@TestInstance(TestInstance.Lifecycle.PER_CLASS)30internal class ProfiledConnectionPoolListenerTest {31 private val mockServer = ArmeriaMockServer()32 @BeforeAll33 suspend fun beforeAll() {34 mockServer.start()35 }36 @AfterAll37 suspend fun afterAll() {...
ReshardingVerticleTest.kt
Source:ReshardingVerticleTest.kt
...4import ch.sourcemotion.vertx.kinesis.consumer.orchestra.impl.ext.shardIdTyped5import ch.sourcemotion.vertx.kinesis.consumer.orchestra.impl.streamDescriptionWhenActiveAwait6import ch.sourcemotion.vertx.kinesis.consumer.orchestra.internal.service.ConsumerControlService7import ch.sourcemotion.vertx.kinesis.consumer.orchestra.internal.service.StopConsumersCmdResult8import ch.sourcemotion.vertx.kinesis.consumer.orchestra.testing.*9import io.kotest.matchers.collections.shouldContain10import io.kotest.matchers.nulls.shouldBeNull11import io.kotest.matchers.nulls.shouldNotBeNull12import io.kotest.matchers.shouldBe13import io.vertx.core.Future14import io.vertx.core.Promise15import io.vertx.junit5.Timeout16import io.vertx.junit5.VertxTestContext17import io.vertx.kotlin.coroutines.await18import kotlinx.coroutines.CoroutineScope19import kotlinx.coroutines.launch20import org.junit.jupiter.api.Test21import java.util.concurrent.TimeUnit22internal class ReshardingVerticleTest : AbstractKinesisAndRedisTest() {23 /**24 * On merge resharding event, both parent shard must get stopped.25 */26 @Timeout(value = 1, timeUnit = TimeUnit.MINUTES)27 @Test28 internal fun stop_consumer_cmd_on_all_merge_resharding_events(testContext: VertxTestContext) =29 testContext.async(2) { checkpoint ->30 val (childShardId, parentShardIds) = createStreamAndMerge()31 ConsumerControlService.exposeService(vertx, StopOnlyConsumerControlService(defaultTestScope) { shardId ->32 val sequenceNumber =33 shardStatePersistenceService.getConsumerShardSequenceNumber(childShardId)34 testContext.verify {35 sequenceNumber.shouldNotBeNull()36 parentShardIds.shouldContain(shardId)37 }38 checkpoint.flag()39 }).await()40 val options = ReshardingVerticle.Options(TEST_CLUSTER_ORCHESTRA_NAME, redisHeimdallOptions)41 deployTestVerticle<ReshardingVerticle>(options)42 parentShardIds.forEach { parentShardId ->43 eventBus.request<Unit>(44 EventBusAddr.resharding.notification,45 MergeReshardingEvent(parentShardId, childShardId)46 ).await()47 }48 }49 /**50 * On split resharding the parent should be stopped and the first child consume command should send immediately.51 */52 @Timeout(value = 1, timeUnit = TimeUnit.MINUTES)53 @Test54 internal fun split_resharding(testContext: VertxTestContext) =55 testContext.async(1) { checkpoint ->56 val (childShardIds, parentShardId) = createStreamAndSplit()57 ConsumerControlService.exposeService(vertx, StopOnlyConsumerControlService(defaultTestScope) { shardId ->58 val sequenceNumber = shardStatePersistenceService.getConsumerShardSequenceNumber(shardId)59 testContext.verify {60 shardId.shouldBe(parentShardId)61 sequenceNumber.shouldBeNull()62 }63 checkpoint.flag()64 }).await()65 val options = ReshardingVerticle.Options(TEST_CLUSTER_ORCHESTRA_NAME, redisHeimdallOptions)66 deployTestVerticle<ReshardingVerticle>(options)67 eventBus.request<Unit>(68 EventBusAddr.resharding.notification,69 SplitReshardingEvent(parentShardId, childShardIds)70 ).await()71 }72 private suspend fun createStreamAndSplit(): Pair<List<ShardId>, ShardId> {73 val streamDescription = kinesisClient.createAndGetStreamDescriptionWhenActive(1)...
SubscriptionPostReconnectJobTest.kt
Source:SubscriptionPostReconnectJobTest.kt
1package ch.sourcemotion.vertx.redis.client.heimdall.impl.subscription2import ch.sourcemotion.vertx.redis.client.heimdall.impl.subscription.connection.RedisHeimdallSubscriptionConnection3import ch.sourcemotion.vertx.redis.client.heimdall.testing.AbstractVertxTest4import ch.sourcemotion.vertx.redis.client.heimdall.testing.assertSuccess5import io.kotest.matchers.booleans.shouldBeFalse6import io.kotest.matchers.booleans.shouldBeTrue7import io.kotest.matchers.shouldBe8import io.kotest.matchers.types.shouldBeInstanceOf9import io.mockk.every10import io.mockk.mockk11import io.vertx.core.Future12import io.vertx.junit5.VertxTestContext13import io.vertx.redis.client.Redis14import io.vertx.redis.client.RedisConnection15import org.junit.jupiter.api.Test16internal class SubscriptionPostReconnectJobTest : AbstractVertxTest() {17 private val sut = SubscriptionPostReconnectJob18 @Test19 internal fun subscription_after_reconnect_successful(testContext: VertxTestContext) =20 testContext.async {21 // given22 val heimdallConnection = createHeimdallConnection()23 val redis = createSuccessfulConnectRedis(heimdallConnection)24 // when & then25 testContext.assertSuccess(sut.execute(redis))26 }27 @Test28 internal fun subscription_after_reconnect_fail(testContext: VertxTestContext) = testContext.async(1) { checkpoint ->29 // given30 val subscriptionFailureCase = Exception("subscription-failure")31 val heimdallConnection = createHeimdallConnection(subscriptionFailureCase)32 val redis = createSuccessfulConnectRedis(heimdallConnection)33 // when & then34 sut.execute(redis).onComplete {35 testContext.verify {36 it.succeeded().shouldBeFalse()37 val subscriptionFailCause = it.cause().shouldBeInstanceOf<java.lang.Exception>()38 subscriptionFailCause.message.shouldBe(subscriptionFailureCase.message)39 }40 checkpoint.flag()41 }42 }43 @Test44 internal fun redis_connect_failed(testContext: VertxTestContext) = testContext.async(1) { checkpoint ->45 // given46 val rootCause = Exception("Test-connect-failure")47 val redis = createFailingConnectRedis(rootCause)48 // when & then49 sut.execute(redis).onComplete {50 testContext.verify {51 it.succeeded().shouldBeFalse()52 val heimdallException = it.cause().shouldBeInstanceOf<java.lang.Exception>()53 heimdallException.message.shouldBe(rootCause.message)54 }55 checkpoint.flag()56 }57 }58 @Test59 internal fun subscription_after_reconnect_successful_even_wrong_connection_type(testContext: VertxTestContext) =60 testContext.async(1) { checkpoint ->61 // given62 val redis = createSuccessfulConnectRedis(createNonHeimdallConnection())63 // when & then64 sut.execute(redis).onComplete {65 testContext.verify { it.succeeded().shouldBeTrue() }66 checkpoint.flag()67 }68 }69 private fun createNonHeimdallConnection() = mockk<RedisConnection>()70 private fun createHeimdallConnection(reconnectFailureCase: Throwable? = null) =71 mockk<RedisHeimdallSubscriptionConnection> {72 every { subscribeAfterReconnect() } answers {73 if (reconnectFailureCase != null) {74 Future.failedFuture(reconnectFailureCase)75 } else {76 Future.succeededFuture(Unit)77 }78 }79 }...
CachingBodySubscriberTest.kt
Source:CachingBodySubscriberTest.kt
...13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.github.nstdio.http.ext17import io.kotest.property.Arb18import io.kotest.property.arbitrary.next19import io.kotest.property.arbitrary.string20import org.assertj.core.api.Assertions21import org.junit.jupiter.api.Test22import org.junit.jupiter.api.io.TempDir23import org.mockito.ArgumentMatchers24import org.mockito.Mockito25import java.net.http.HttpResponse26import java.net.http.HttpResponse.BodySubscriber27import java.nio.file.Files28import java.nio.file.Path29import java.nio.file.StandardOpenOption30internal class CachingBodySubscriberTest {31 @Test32 fun shouldWriteAndReadFromEmptyFile(@TempDir dir: Path) {33 //given...
RedisLockFactoryTest.kt
Source:RedisLockFactoryTest.kt
1package ch.sourcemotion.vertx.redis.clustermanager.impl2import ch.sourcemotion.vertx.redis.clustermanager.RedisClusterManagerException3import ch.sourcemotion.vertx.redis.clustermanager.impl.lua.lua.LuaExecutor4import ch.sourcemotion.vertx.redis.clustermanager.testing.AbstractRedisTest5import io.kotest.matchers.nulls.shouldBeNull6import io.kotest.matchers.shouldBe7import io.kotest.matchers.types.shouldBeInstanceOf8import io.vertx.core.Promise9import io.vertx.core.shareddata.Lock10import io.vertx.junit5.VertxTestContext11import io.vertx.kotlin.coroutines.await12import io.vertx.redis.client.Command13import io.vertx.redis.client.Request14import kotlinx.coroutines.delay15import org.junit.jupiter.api.Test16internal class RedisLockFactoryTest : AbstractRedisTest() {17 private companion object {18 val clusterName = ClusterName("cluster")19 val lockName = RedisLockName("redis-lock")20 val lockKey = clusterName.serviceKey(lockName)21 }22 @Test23 internal fun lock_acquisition_successful(testContext: VertxTestContext) = testContext.async(1) { checkpoint ->24 val sut = RedisLockFactory(vertx, clusterName, redis, LuaExecutor(redis), 100, 1000)25 val promise = Promise.promise<Lock>()26 sut.createLock(lockName, 1, promise)27 val future = promise.future()28 future.onSuccess {29 checkpoint.flag()30 }31 future.onFailure { testContext.failNow(it) }32 }33 @Test34 internal fun lock_acquisition_timeout(testContext: VertxTestContext) = testContext.async(1) { checkpoint ->35 val sut = RedisLockFactory(vertx, clusterName, redis, LuaExecutor(redis), 100, 1000)36 // Another client got the lock earlier37 redis.send(Request.cmd(Command.SET).arg(lockKey).arg(1)).await()38 val promise = Promise.promise<Lock>()39 sut.createLock(lockName, 500, promise)40 val future = promise.future()41 future.onSuccess { testContext.failNow("Lock timeout expected") }42 future.onFailure {43 testContext.verify { it.shouldBeInstanceOf<RedisClusterManagerException>() }44 checkpoint.flag()45 }46 }47 @Test48 internal fun lock_expiration(testContext: VertxTestContext) = testContext.async(1) { checkpoint ->49 val expiration = 200L50 val sut = RedisLockFactory(vertx, clusterName, redis, LuaExecutor(redis), 100, expiration)51 val firstLockPromise = Promise.promise<Lock>()52 sut.createLock(lockName, 100, firstLockPromise)53 firstLockPromise.future().await()54 delay(expiration + 10L)55 val secondLockPromise = Promise.promise<Lock>()56 sut.createLock(lockName, 1, secondLockPromise)57 val secondLockFuture = secondLockPromise.future()58 secondLockFuture.onSuccess { checkpoint.flag() }59 secondLockFuture.onFailure { testContext.failNow(it) }60 }61 @Test62 internal fun lock_release(testContext: VertxTestContext) = testContext.async {63 val sut = RedisLockFactory(vertx, clusterName, redis, LuaExecutor(redis), 100, 1000)64 val promise = Promise.promise<Lock>()65 sut.createLock(lockName, 1, promise)66 val lock = promise.future().await()67 redis.send(Request.cmd(Command.GET).arg(lockKey)).await().toInteger().shouldBe(1)68 lock.release()69 delay(200) // Enough time, even for slow machines.70 redis.send(Request.cmd(Command.GET).arg(lockKey)).await().shouldBeNull()71 }72}...
QueueServiceImplTest.kt
Source:QueueServiceImplTest.kt
1package uk.gov.dwp.dataworks.egress.services.impl2import com.nhaarman.mockitokotlin2.*3import io.kotest.core.spec.style.StringSpec4import io.kotest.core.spec.style.WordSpec5import io.kotest.matchers.collections.shouldContainInOrder6import io.kotest.matchers.shouldBe7import kotlinx.coroutines.flow.collect8import kotlinx.coroutines.withTimeoutOrNull9import software.amazon.awssdk.services.sqs.SqsAsyncClient10import software.amazon.awssdk.services.sqs.model.*11import java.util.concurrent.CompletableFuture12import kotlin.time.ExperimentalTime13@ExperimentalTime14class QueueServiceImplTest: WordSpec() {15 init {16 "QueueService" should {17 "emit a message when one appears on the queue" {18 val queueAttributesResponse = with(GetQueueAttributesResponse.builder()) {19 attributes(mapOf(QueueAttributeName.APPROXIMATE_NUMBER_OF_MESSAGES to "1"))20 build()...
BasicAuthProviderTest.kt
Source:BasicAuthProviderTest.kt
1package dev.neeffect.nee.ctx.web2import dev.neeffect.nee.effects.security.SecurityErrorType3import dev.neeffect.nee.effects.toFuture4import dev.neeffect.nee.security.InMemoryUserRealm5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.matchers.be7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.matchers.types.shouldBeTypeOf10import io.vavr.control.Option.none11import io.vavr.control.Option.some12internal class BasicAuthProviderTest : DescribeSpec({13 describe("basic auth") {14 val userRealm = InMemoryUserRealm<String, String>().withPassword("test1", "test2".toCharArray())15 .withRole("test1", "unfixer")16 describe("with correct auth header") {17 val provider = BasicAuthProvider(some("Basic dGVzdDE6dGVzdDI="), userRealm)18 it("should find role context") {19 provider.getSecurityContext()20 .toFuture().get().get()21 .getCurrentUser().toFuture().get().get() should be("test1")22 }23 it("should find role") {24 provider.getSecurityContext()25 .toFuture().get().get()26 .hasRole("unfixer") should be(true)27 }28 it("should reject unknown role") {29 provider.getSecurityContext()30 .toFuture().get().get()31 .hasRole("admin") should be(false)32 }33 }34 describe("with no header") {35 val provider = BasicAuthProvider(none(), userRealm)...
FoldTest.kt
Source:FoldTest.kt
1package dev.helk2import io.kotest.matchers.shouldBe3import io.kotest.matchers.types.shouldBeSameInstanceAs4import org.junit.jupiter.api.Test5internal class FoldTest {6 @Test7 fun `when completable future succeed`() {8 Future { "a successfully completable future" }.fold(9 { throw RuntimeException("error") },10 { "$it folded" }11 ).join() shouldBe "a successfully completable future folded"12 }13 @Test14 fun `when completable future fails`() {15 try {16 Future<String> { throw TestError() }.fold(17 { throw AnotherTestError(it) },...
test
Using AI Code Generation
1 import io.kotest.matchers.future.matchers.shouldBeCompletedWith2 import io.kotest.matchers.future.shouldBeCompleted3 import io.kotest.matchers.future.shouldBeCompletedWith4 import io.kotest.matchers.future.shouldBeFailed5 import io.kotest.matchers.future.shouldBeFailedWith6 import io.kotest.matchers.future.shouldBePending7 import io.kotest.matchers.future.shouldBePendingWith8 import io.kotest.matchers.future.shouldBeResolved9 import io.kotest.matchers.future.shouldBeResolvedWith10 import io.kotest.matchers.future.shouldBeSucceeded11 import io.kotest.matchers.future.shouldBeSucceededWith12 import io.kotest.matchers.future.shouldBeTerminated13 import io.kotest.matchers.future.shouldBeTerminatedWith14 import io.kotest.matchers.future.shouldBeUnresolved15 import io.kotest.matchers.future.shouldBeUnresolvedWith16 import io.kotest.matchers.future.shouldBeUnsatisfied17 import io.kotest.matchers.future.shouldBeUnsatisfiedWith18 import io.kotest.matchers.future.shouldBeWaiting19 import io.kotest.matchers.future.shouldBeWaitingWith20 import io.kotest.matchers.future.shouldBeWaitingWithAnyOf21 import io.kotest.matchers.future.shouldBeWaitingWithAllOf22 import io.kotest.matchers.future.shouldBeWaitingWithNoneOf23 import io.kotest.matchers.future.shouldBeWaitingWithOneOf24 import io.kotest.matchers.future.shouldBeWaitingWithSequence25 import io.kotest.matchers.future.shouldBeWaitingWithTimes26 import io.kotest.matchers.future.shouldBeWaitingWithTimesOrMore27 import io.kotest.matchers.future.shouldBeWaitingWithTimesOrLess28 import io.kotest.matchers.future.shouldBeWaitingWithZeroTimes29 import io.kotest.matchers.future.shouldBeWaitingWithZeroOrMoreTimes30 import io.kotest.matchers.future.shouldBeWaitingWithZeroOrLessTimes31 import io.kotest.matchers.future.shouldBeWaitingWithZeroOrMoreTimes32 import io.kotest.matchers.future.shouldBeWaitingWithZeroOrLessTimes33 import io.kotest.matchers.future.shouldBeWaitingWith
test
Using AI Code Generation
1val future = Future.succeededFuture("Hello")2future.shouldBeSuccessful("Hello")3future.shouldBeFailed()4future.shouldBeFailedWith<IllegalStateException>()5future.shouldBeFailedWith<IllegalStateException>("Hello")6future.shouldBeCompleted()7future.shouldBeCompletedWith("Hello")8future.shouldBeCompletedWithException<IllegalStateException>()9future.shouldBeCompletedWithException<IllegalStateException>("Hello")10future.shouldBeCompletedWithFailure<IllegalStateException>()11future.shouldBeCompletedWithFailure<IllegalStateException>("Hello")12future.shouldBeCompletedWithSuccess("Hello")13future.shouldBeCompletedWithSuccessOfType<String>()14future.shouldBeCompletedWithSuccessOfType<String>("Hello")15future.shouldBeCompletedWithSuccessOfType<CharSequence>()16future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello")17future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", "Hello")18future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", "World")19future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1)20future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello")21future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", "Hello")22future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", "World")23future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", 1)24future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", 1, "Hello")25future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", 1, "Hello", "Hello")26future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", 1, "Hello", "World")27future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", 1, "Hello", 1)28future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", 1, "Hello", 1, "Hello")29future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", 1, "Hello", 1, "Hello", "Hello")30future.shouldBeCompletedWithSuccessOfType<CharSequence>("Hello", 1, "Hello", 1, "Hello", 1, "Hello", "World")
test
Using AI Code Generation
1test("testFuture") {2val future = Future { Thread.sleep(1000); 1 }3future should beCompletedWith(1)4}5}6}7}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!