forked from pmem/pmemkv-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add kotlinx lincheck scenarios
Ref: pmem#140
- Loading branch information
1 parent
e9354c8
commit 2debbb1
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
pmemkv-binding/src/test/java/io/pmem/pmemkv/LincheckTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
/* Copyright 2020-2021, Intel Corporation */ | ||
|
||
package io.pmem.pmemkv; | ||
|
||
import org.jetbrains.kotlinx.lincheck.annotations.*; | ||
import org.jetbrains.kotlinx.lincheck.LinChecker; | ||
import org.jetbrains.kotlinx.lincheck.paramgen.*; | ||
import org.jetbrains.kotlinx.lincheck.strategy.stress.StressCTest; | ||
import org.junit.After; | ||
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) | ||
@Param(name = "key", gen = StringGen.class, conf = "8") | ||
public class LincheckTest { | ||
|
||
private final String ENGINE = "cmap"; | ||
private String DB_PATH = ""; | ||
private Database<ByteBuffer, ByteBuffer> db; | ||
|
||
@Operation(runOnce = true) | ||
public void put(@Param(name = "key") String k, @Param(name = "key") String v) { | ||
System.out.println("Visit: " + k + " : " + v); | ||
ByteBuffer key = stringToByteBuffer(k); | ||
ByteBuffer value = stringToByteBuffer(v); | ||
db.put(key, value); | ||
} | ||
|
||
@Operation(runOnce = true) | ||
public void put2(@Param(name = "key") String k, @Param(name = "key") String v) { | ||
System.out.println("Visit: " + k + " : " + v); | ||
ByteBuffer key = stringToByteBuffer(k); | ||
ByteBuffer value = stringToByteBuffer(v); | ||
// ByteBuffer key = stringToByteBuffer("key2"); | ||
// ByteBuffer value = stringToByteBuffer("value2"); | ||
db.put(key, value); | ||
} | ||
|
||
// @Operation(handleExceptionsAsResult = NotFoundException.class) | ||
// public void get() { | ||
// ByteBuffer resBuff = db.getCopy(stringToByteBuffer("key1")); | ||
// if (resBuff != null) { | ||
// assertEquals(byteBufferToString(resBuff), "value1"); | ||
// } | ||
// } | ||
|
||
@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()); | ||
System.out.println("Init DONE !!!"); | ||
} | ||
|
||
@After | ||
public void finalize() { | ||
db.stop(); | ||
} | ||
|
||
@Test | ||
public void basicTest() { | ||
LinChecker.check(LincheckTest.class); | ||
} | ||
} |