services - migrate to junit 5 (#5613)

* services to junit5

* removed some junit4 engine imports

* updated some plugins test since these extend from testutil KV storage

* one more form of EPL v2

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
This commit is contained in:
Sally MacFarlane
2023-06-21 09:12:51 +10:00
committed by GitHub
parent 5bff76f107
commit db173ebd98
27 changed files with 143 additions and 105 deletions

View File

@@ -36,7 +36,7 @@ dependencies {
implementation 'com.google.guava:guava'
implementation 'com.squareup.okhttp3:okhttp'
implementation 'io.vertx:vertx-core'
implementation 'junit:junit'
implementation 'org.junit.jupiter:junit-jupiter'
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-io'
implementation 'org.apache.tuweni:tuweni-toml'

View File

@@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorage;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -32,11 +33,12 @@ import java.util.stream.Stream;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.tuweni.bytes.Bytes;
import org.junit.Ignore;
import org.junit.Test;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/** The Abstract key value storage test. */
@Ignore
@Disabled
public abstract class AbstractKeyValueStorageTest {
/**
@@ -352,12 +354,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
*/
@Test(expected = IllegalStateException.class)
@Test
public void transactionPutAfterCommit() throws Exception {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.commit();
tx.put(bytesOf(1), bytesOf(1));
Assertions.assertThatThrownBy(
() -> {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.commit();
tx.put(bytesOf(1), bytesOf(1));
})
.isInstanceOf(IllegalStateException.class);
}
/**
@@ -365,12 +371,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
*/
@Test(expected = IllegalStateException.class)
@Test
public void transactionRemoveAfterCommit() throws Exception {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.commit();
tx.remove(bytesOf(1));
Assertions.assertThatThrownBy(
() -> {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.commit();
tx.remove(bytesOf(1));
})
.isInstanceOf(IllegalStateException.class);
}
/**
@@ -378,12 +388,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
*/
@Test(expected = IllegalStateException.class)
@Test
public void transactionPutAfterRollback() throws Exception {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.rollback();
tx.put(bytesOf(1), bytesOf(1));
Assertions.assertThatThrownBy(
() -> {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.rollback();
tx.put(bytesOf(1), bytesOf(1));
})
.isInstanceOf(IllegalStateException.class);
}
/**
@@ -391,12 +405,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
*/
@Test(expected = IllegalStateException.class)
@Test
public void transactionRemoveAfterRollback() throws Exception {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.rollback();
tx.remove(bytesOf(1));
Assertions.assertThatThrownBy(
() -> {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.rollback();
tx.remove(bytesOf(1));
})
.isInstanceOf(IllegalStateException.class);
}
/**
@@ -404,12 +422,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
*/
@Test(expected = IllegalStateException.class)
@Test
public void transactionCommitAfterRollback() throws Exception {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.rollback();
tx.commit();
Assertions.assertThatThrownBy(
() -> {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.rollback();
tx.commit();
})
.isInstanceOf(IllegalStateException.class);
}
/**
@@ -417,12 +439,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
*/
@Test(expected = IllegalStateException.class)
@Test
public void transactionCommitTwice() throws Exception {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.commit();
tx.commit();
Assertions.assertThatThrownBy(
() -> {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.commit();
tx.commit();
})
.isInstanceOf(IllegalStateException.class);
}
/**
@@ -430,12 +456,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
*/
@Test(expected = IllegalStateException.class)
@Test
public void transactionRollbackAfterCommit() throws Exception {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.commit();
tx.rollback();
Assertions.assertThatThrownBy(
() -> {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.commit();
tx.rollback();
})
.isInstanceOf(IllegalStateException.class);
}
/**
@@ -443,12 +473,16 @@ public abstract class AbstractKeyValueStorageTest {
*
* @throws Exception the exception
*/
@Test(expected = IllegalStateException.class)
@Test
public void transactionRollbackTwice() throws Exception {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.rollback();
tx.rollback();
Assertions.assertThatThrownBy(
() -> {
final KeyValueStorage store = createStore();
final KeyValueStorageTransaction tx = store.startTransaction();
tx.rollback();
tx.rollback();
})
.isInstanceOf(IllegalStateException.class);
}
/**
@@ -547,4 +581,15 @@ public abstract class AbstractKeyValueStorageTest {
protected byte[] bytesOf(final int... bytes) {
return Bytes.of(bytes).toArrayUnsafe();
}
/**
* Create a sub folder from the given path, that will not conflict with other folders.
*
* @param folder the folder in which to create the sub folder
* @return the path representing the sub folder
* @throws Exception if the folder cannot be created
*/
protected Path getTempSubFolder(final Path folder) throws Exception {
return java.nio.file.Files.createTempDirectory(folder, null);
}
}