All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonTest.channels.ChannelFactoryTest.kt Maven / Gradle / Ivy

There is a newer version: 1.9.0
Show newest version
/*
 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package kotlinx.coroutines.channels

import kotlinx.coroutines.*
import kotlin.test.*


class ChannelFactoryTest : TestBase() {
    @Test
    fun testRendezvousChannel() {
        assertTrue(Channel() is RendezvousChannel)
        assertTrue(Channel(0) is RendezvousChannel)
    }

    @Test
    fun testLinkedListChannel() {
        assertTrue(Channel(Channel.UNLIMITED) is LinkedListChannel)
        assertTrue(Channel(Channel.UNLIMITED, BufferOverflow.DROP_OLDEST) is LinkedListChannel)
        assertTrue(Channel(Channel.UNLIMITED, BufferOverflow.DROP_LATEST) is LinkedListChannel)
    }

    @Test
    fun testConflatedChannel() {
        assertTrue(Channel(Channel.CONFLATED) is ConflatedChannel)
        assertTrue(Channel(1, BufferOverflow.DROP_OLDEST) is ConflatedChannel)
    }

    @Test
    fun testArrayChannel() {
        assertTrue(Channel(1) is ArrayChannel)
        assertTrue(Channel(1, BufferOverflow.DROP_LATEST) is ArrayChannel)
        assertTrue(Channel(10) is ArrayChannel)
    }

    @Test
    fun testInvalidCapacityNotSupported() {
        assertFailsWith { Channel(-3) }
    }
    
    @Test
    fun testUnsupportedBufferOverflow() {
        assertFailsWith { Channel(Channel.CONFLATED, BufferOverflow.DROP_OLDEST) }
        assertFailsWith { Channel(Channel.CONFLATED, BufferOverflow.DROP_LATEST) }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy