Skip to content

Commit

Permalink
tests: add kotlinx lincheck scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszstolarczuk committed Apr 23, 2021
1 parent e9354c8 commit 10eef69
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pmemkv-binding/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,11 @@
<version>[4.12,)</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>lincheck-jvm</artifactId>
<version>[2.12,)</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
66 changes: 66 additions & 0 deletions pmemkv-binding/src/test/java/io/pmem/pmemkv/LincheckTest.java
Original file line number Diff line number Diff line change
@@ -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<ByteBuffer, ByteBuffer> 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);
}
}

0 comments on commit 10eef69

Please sign in to comment.