diff --git a/pmemkv-binding/pom.xml b/pmemkv-binding/pom.xml index 71f69251..2b402992 100644 --- a/pmemkv-binding/pom.xml +++ b/pmemkv-binding/pom.xml @@ -95,5 +95,11 @@ [4.12,) test + + org.jetbrains.kotlinx + lincheck-jvm + [2.12,) + pom + diff --git a/pmemkv-binding/src/test/java/io/pmem/pmemkv/LincheckTest.java b/pmemkv-binding/src/test/java/io/pmem/pmemkv/LincheckTest.java new file mode 100644 index 00000000..90bb6a97 --- /dev/null +++ b/pmemkv-binding/src/test/java/io/pmem/pmemkv/LincheckTest.java @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* Copyright 2020-2021, Intel Corporation */ + +package io.pmem.pmemkv; + +import org.jetbrains.kotlinx.lincheck.execution.*; +import org.jetbrains.kotlinx.lincheck.annotations.Operation; +import org.jetbrains.kotlinx.lincheck.verifier.*; +import org.jetbrains.kotlinx.lincheck.LinChecker; +import org.jetbrains.kotlinx.lincheck.strategy.stress.StressCTest; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import static org.junit.Assert.*; + +import java.io.File; +import java.nio.ByteBuffer; + +import static io.pmem.pmemkv.TestUtils.*; + +@StressCTest(threads = 3, iterations = 10, invocationsPerIteration = 10, requireStateEquivalenceImplCheck = false) +public class LincheckTest { + + private final String ENGINE = "cmap"; + private String DB_PATH = ""; + private Database db; + + @Operation(runOnce = true) + public void put() { + db.put(stringToByteBuffer("key1"), stringToByteBuffer("value1")); + } + + @Operation(runOnce = true) + public void get() { + ByteBuffer resBuff; + try { + resBuff = db.get(stringToByteBuffer("key1")); + assertEquals(byteBufferToString(resBuff), "value1"); + } catch (NotFoundException e) { + System.out.println("just NotFound! ;)"); + } + } + + @Rule + public TemporaryFolder testDir = new TemporaryFolder(DEFAULT_DB_DIR); + + @Before + public void init() { + DB_PATH = testDir.getRoot() + File.separator + "testfile"; + assertTrue(DB_PATH != null && !DB_PATH.isEmpty()); + + db = createDB(ENGINE, DB_PATH, new ByteBufferConverter()); + } + + @After + public void finalize() { + db.stop(); + } + + @Test + public void testCreateAndOpen() { + LinChecker.check(LincheckTest.class); + } +} \ No newline at end of file