Plugins migrate to junit5 (#5703)

* Migrate util module to JUnit 5.0

Signed-off-by: 7suyash7 <suyashnyn1@gmail.com>

* Migrate plugins to Junit 5.0

Signed-off-by: 7suyash7 <suyashnyn1@gmail.com>

* refactor tests

Signed-off-by: 7suyash7 <suyashnyn1@gmail.com>

* removed file properly

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

---------

Signed-off-by: 7suyash7 <suyashnyn1@gmail.com>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: 7suyash7 <suyashnyn1@gmail.com>
pull/5710/head
Sally MacFarlane 1 year ago committed by GitHub
parent 9f42a3f261
commit 407f84a98b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      plugins/rocksdb/build.gradle
  2. 2
      plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBCLIOptionsTest.java
  3. 25
      plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBKeyValuePrivacyStorageFactoryTest.java
  4. 49
      plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBKeyValueStorageFactoryTest.java
  5. 16
      plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBMetricsTest.java
  6. 22
      plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/configuration/DatabaseMetadataTest.java
  7. 4
      plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/OptimisticTransactionDBRocksDBColumnarKeyValueStorageTest.java
  8. 3
      plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorageTest.java
  9. 2
      plugins/rocksdb/src/test/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/TransactionDBRocksDBColumnarKeyValueStorageTest.java

@ -51,11 +51,11 @@ dependencies {
testImplementation project(':testutil')
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-junit-jupiter'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

@ -26,7 +26,7 @@ import static org.hyperledger.besu.plugin.services.storage.rocksdb.configuration
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBCLIOptions;
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBFactoryConfiguration;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;
public class RocksDBCLIOptionsTest {

@ -28,29 +28,28 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class RocksDBKeyValuePrivacyStorageFactoryTest {
private static final int DEFAULT_VERSION = 1;
private static final int DEFAULT_PRIVACY_VERSION = 1;
@Mock private RocksDBFactoryConfiguration rocksDbConfiguration;
@Mock private BesuConfiguration commonConfiguration;
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
@TempDir private Path temporaryFolder;
private final ObservableMetricsSystem metricsSystem = new NoOpMetricsSystem();
private final List<SegmentIdentifier> segments = List.of();
@Mock private SegmentIdentifier segment;
@Test
public void shouldDetectVersion1DatabaseIfNoMetadataFileFound() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
final Path tempPrivateDatabaseDir = tempDatabaseDir.resolve("private");
Files.createDirectories(tempPrivateDatabaseDir);
Files.createDirectories(tempDataDir);
@ -77,8 +76,8 @@ public class RocksDBKeyValuePrivacyStorageFactoryTest {
@Test
public void shouldCreateCorrectMetadataFileForLatestVersion() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
when(commonConfiguration.getDataPath()).thenReturn(tempDataDir);
when(commonConfiguration.getDatabaseVersion()).thenReturn(DEFAULT_VERSION);
@ -103,8 +102,8 @@ public class RocksDBKeyValuePrivacyStorageFactoryTest {
@Test
public void shouldUpdateCorrectMetadataFileForLatestVersion() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
when(commonConfiguration.getDataPath()).thenReturn(tempDataDir);
when(commonConfiguration.getDatabaseVersion()).thenReturn(DEFAULT_VERSION);

@ -32,14 +32,13 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class RocksDBKeyValueStorageFactoryTest {
private static final String METADATA_FILENAME = "DATABASE_METADATA.json";
@ -47,15 +46,15 @@ public class RocksDBKeyValueStorageFactoryTest {
@Mock private RocksDBFactoryConfiguration rocksDbConfiguration;
@Mock private BesuConfiguration commonConfiguration;
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
@TempDir public Path temporaryFolder;
private final ObservableMetricsSystem metricsSystem = new NoOpMetricsSystem();
private final List<SegmentIdentifier> segments = List.of();
@Mock private SegmentIdentifier segment;
@Test
public void shouldCreateCorrectMetadataFileForLatestVersion() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
when(commonConfiguration.getDataPath()).thenReturn(tempDataDir);
when(commonConfiguration.getDatabaseVersion()).thenReturn(DEFAULT_VERSION);
@ -72,8 +71,8 @@ public class RocksDBKeyValueStorageFactoryTest {
@Test
public void shouldDetectVersion1DatabaseIfNoMetadataFileFound() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
Files.createDirectories(tempDatabaseDir);
Files.createDirectories(tempDataDir);
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
@ -90,8 +89,8 @@ public class RocksDBKeyValueStorageFactoryTest {
@Test
public void shouldDetectCorrectVersionIfMetadataFileExists() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
Files.createDirectories(tempDataDir);
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
when(commonConfiguration.getDataPath()).thenReturn(tempDataDir);
@ -109,8 +108,8 @@ public class RocksDBKeyValueStorageFactoryTest {
@Test
public void shouldDetectCorrectVersionInCaseOfRollback() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
Files.createDirectories(tempDatabaseDir);
Files.createDirectories(tempDataDir);
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
@ -131,8 +130,8 @@ public class RocksDBKeyValueStorageFactoryTest {
@Test
public void shouldThrowExceptionWhenVersionNumberIsInvalid() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
Files.createDirectories(tempDatabaseDir);
Files.createDirectories(tempDataDir);
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
@ -150,8 +149,8 @@ public class RocksDBKeyValueStorageFactoryTest {
@Test
public void shouldSetSegmentationFieldDuringCreation() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
Files.createDirectories(tempDatabaseDir);
Files.createDirectories(tempDataDir);
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
@ -166,8 +165,8 @@ public class RocksDBKeyValueStorageFactoryTest {
@Test
public void shouldThrowExceptionWhenMetaDataFileIsCorrupted() throws Exception {
final Path tempDataDir = temporaryFolder.newFolder().toPath().resolve("data");
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
final Path tempDataDir = temporaryFolder.resolve("data");
final Path tempDatabaseDir = temporaryFolder.resolve("db");
Files.createDirectories(tempDatabaseDir);
Files.createDirectories(tempDataDir);
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
@ -202,12 +201,10 @@ public class RocksDBKeyValueStorageFactoryTest {
@Test
public void shouldCreateDBCorrectlyIfSymlink() throws Exception {
final Path tempRealDataDir =
Files.createDirectories(temporaryFolder.newFolder().toPath().resolve("real-data-dir"));
final Path tempRealDataDir = Files.createDirectories(temporaryFolder.resolve("real-data-dir"));
final Path tempSymLinkDataDir =
Files.createSymbolicLink(
temporaryFolder.newFolder().toPath().resolve("symlink-data-dir"), tempRealDataDir);
final Path tempDatabaseDir = temporaryFolder.newFolder().toPath().resolve("db");
Files.createSymbolicLink(temporaryFolder.resolve("symlink-data-dir"), tempRealDataDir);
final Path tempDatabaseDir = temporaryFolder.resolve("db");
when(commonConfiguration.getStoragePath()).thenReturn(tempDatabaseDir);
when(commonConfiguration.getDataPath()).thenReturn(tempSymLinkDataDir);
when(commonConfiguration.getDatabaseVersion()).thenReturn(DEFAULT_VERSION);

@ -30,19 +30,19 @@ import org.hyperledger.besu.plugin.services.metrics.OperationTimer;
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBConfiguration;
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBConfigurationBuilder;
import java.nio.file.Path;
import java.util.function.LongSupplier;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.rocksdb.OptimisticTransactionDB;
import org.rocksdb.Statistics;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class RocksDBMetricsTest {
@Mock private ObservableMetricsSystem metricsSystemMock;
@ -52,7 +52,7 @@ public class RocksDBMetricsTest {
@Mock private OptimisticTransactionDB db;
@Mock private Statistics stats;
@Rule public final TemporaryFolder folder = new TemporaryFolder();
@TempDir public Path folder;
@Test
public void createStoreMustCreateMetrics() throws Exception {
@ -120,6 +120,6 @@ public class RocksDBMetricsTest {
}
private RocksDBConfiguration config() throws Exception {
return new RocksDBConfigurationBuilder().databaseDir(folder.newFolder().toPath()).build();
return new RocksDBConfigurationBuilder().databaseDir(folder).build();
}
}

@ -21,22 +21,21 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
public class DatabaseMetadataTest {
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
class DatabaseMetadataTest {
@TempDir public Path temporaryFolder;
@Test
public void getVersion() {
void getVersion() {
final DatabaseMetadata databaseMetadata = new DatabaseMetadata(42);
assertThat(databaseMetadata).isNotNull();
assertThat(databaseMetadata.getVersion()).isEqualTo(42);
}
@Test
public void metaFileShouldMayContain() throws Exception {
void metaFileShouldMayContain() throws Exception {
final Path tempDataDir =
createAndWrite(
"data", "DATABASE_METADATA.json", "{\"version\":42 , \"privacyVersion\":55}");
@ -49,7 +48,7 @@ public class DatabaseMetadataTest {
}
@Test
public void metaFileShouldBeSoughtIntoDataDirFirst() throws Exception {
void metaFileShouldBeSoughtIntoDataDirFirst() throws Exception {
final Path tempDataDir = createAndWrite("data", "DATABASE_METADATA.json", "{\"version\":42}");
final DatabaseMetadata databaseMetadata = DatabaseMetadata.lookUpFrom(tempDataDir);
assertThat(databaseMetadata).isNotNull();
@ -62,12 +61,9 @@ public class DatabaseMetadataTest {
}
private Path createAndWrite(
final TemporaryFolder temporaryFolder,
final String dir,
final String file,
final String content)
final Path temporaryFolder, final String dir, final String file, final String content)
throws IOException {
final Path tmpDir = temporaryFolder.newFolder().toPath().resolve(dir);
final Path tmpDir = temporaryFolder.resolve(dir);
Files.createDirectories(tmpDir);
createAndWrite(tmpDir.resolve(file), content);
return tmpDir;

@ -22,11 +22,11 @@ import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDbSegmentIdenti
import org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBConfigurationBuilder;
import org.hyperledger.besu.services.kvstore.SegmentedKeyValueStorage;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
@ -39,7 +39,7 @@ public class OptimisticTransactionDBRocksDBColumnarKeyValueStorageTest
throws Exception {
return new OptimisticRocksDBColumnarKeyValueStorage(
new RocksDBConfigurationBuilder()
.databaseDir(folder.resolve(Bytes.random(9).toString()))
.databaseDir(Files.createTempDirectory("segmentedStore"))
.build(),
Arrays.asList(TestSegment.FOO, TestSegment.BAR),
List.of(),

@ -214,8 +214,9 @@ public abstract class RocksDBColumnarKeyValueStorageTest extends AbstractKeyValu
}
@Test
public void dbShouldNotIgnoreExperimentalSegmentsIfExisted(@TempDir final Path testPath)
public void dbShouldNotIgnoreExperimentalSegmentsIfExisted(@TempDir final Path tempDir)
throws Exception {
final Path testPath = tempDir.resolve("testdb");
// Create new db with experimental column family
SegmentedKeyValueStorage<RocksDbSegmentIdentifier> store =
createSegmentedStore(

@ -50,7 +50,7 @@ public class TransactionDBRocksDBColumnarKeyValueStorageTest
final List<SegmentIdentifier> segments,
final List<SegmentIdentifier> ignorableSegments) {
return new TransactionDBRocksDBColumnarKeyValueStorage(
new RocksDBConfigurationBuilder().databaseDir(path).build(),
new RocksDBConfigurationBuilder().databaseDir(folder).build(),
segments,
ignorableSegments,
new NoOpMetricsSystem(),

Loading…
Cancel
Save