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

jvmTest.linearizability.SegmentQueueLCStressTest.kt Maven / Gradle / Ivy

There is a newer version: 1.4.2-native-mt
Show newest version
/*
 * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */
@file:Suppress("unused")

package kotlinx.coroutines.linearizability

import kotlinx.coroutines.*
import kotlinx.coroutines.internal.SegmentBasedQueue
import org.jetbrains.kotlinx.lincheck.annotations.*
import org.jetbrains.kotlinx.lincheck.annotations.Operation
import org.jetbrains.kotlinx.lincheck.paramgen.*
import org.jetbrains.kotlinx.lincheck.verifier.*
import org.junit.*

@Param(name = "value", gen = IntGen::class, conf = "1:5")
class SegmentQueueLCStressTest : VerifierState() {
    private val q = SegmentBasedQueue()

    @Operation
    fun enqueue(@Param(name = "value") x: Int): Boolean {
        return q.enqueue(x) !== null
    }

    @Operation
    fun dequeue(): Int? = q.dequeue()

    @Operation
    fun close() {
        q.close()
    }

    override fun extractState(): Any {
        val elements = ArrayList()
        while (true) {
            val x = q.dequeue() ?: break
            elements.add(x)
        }
        val closed = q.enqueue(0) === null
        return elements to closed
    }

    @Test
    fun test() = LCStressOptionsDefault().check(this::class)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy