|
|
|
@ -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); |
|
|
|
|