-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
109 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
modAionImpl/test/org/aion/zero/impl/db/DatabaseUtilsTest.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,109 @@ | ||
package org.aion.zero.impl.db; | ||
|
||
import static org.aion.zero.impl.db.DatabaseUtils.deleteRecursively; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import org.aion.mcf.db.exception.InvalidFileTypeException; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class DatabaseUtilsTest { | ||
|
||
File testDB; | ||
File linkedDB; | ||
String dbName = "database"; | ||
String levelDB = "leveldb"; | ||
String rocksDB = "rocksdb"; | ||
|
||
String testDBPath = System.getProperty("user.dir") + "/tmp/testPath"; | ||
String linkDBPath = System.getProperty("user.dir") + "/tmp/linkedPath"; | ||
|
||
@Before | ||
public void setup() { | ||
testDB = new File(testDBPath, ""); | ||
testDB.mkdirs(); | ||
linkedDB = new File(linkDBPath, dbName); | ||
linkedDB.mkdirs(); | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
deleteRecursively(testDB); | ||
deleteRecursively(linkedDB); | ||
} | ||
|
||
@Test | ||
public void testVerifyRocksDBfileTypeWithLinkDBPath() throws IOException, InvalidFileTypeException { | ||
|
||
File options = new File(linkedDB, "OPTIONS-123"); | ||
options.createNewFile(); | ||
|
||
File symbolicLink = new File(testDB, dbName); | ||
|
||
Files.createSymbolicLink(symbolicLink.toPath(), linkedDB.toPath()); | ||
DatabaseUtils.verifyDBfileType(testDB, rocksDB); | ||
} | ||
|
||
@Test (expected = InvalidFileTypeException.class) | ||
public void testVerifyRocksDBfileTypeWithInvalidOptionFile() throws IOException, InvalidFileTypeException { | ||
|
||
File options = new File(linkedDB, "OPTION-123"); | ||
options.createNewFile(); | ||
|
||
File symbolicLink = new File(testDB, dbName); | ||
|
||
Files.createSymbolicLink(symbolicLink.toPath(), linkedDB.toPath()); | ||
DatabaseUtils.verifyDBfileType(testDB, rocksDB); | ||
} | ||
|
||
@Test (expected = InvalidFileTypeException.class) | ||
public void testVerifyRocksDBfileTypeWithInvalidLDBFile() throws IOException, InvalidFileTypeException { | ||
|
||
File options = new File(linkedDB, "123.ldb"); | ||
options.createNewFile(); | ||
|
||
File symbolicLink = new File(testDB, dbName); | ||
|
||
Files.createSymbolicLink(symbolicLink.toPath(), linkedDB.toPath()); | ||
DatabaseUtils.verifyDBfileType(testDB, rocksDB); | ||
} | ||
|
||
@Test | ||
public void testVerifyLevelDBfileTypeWithLinkDBPath() throws IOException, InvalidFileTypeException { | ||
|
||
File options = new File(linkedDB, "123.ldb"); | ||
options.createNewFile(); | ||
|
||
File symbolicLink = new File(testDB, dbName); | ||
|
||
Files.createSymbolicLink(symbolicLink.toPath(), linkedDB.toPath()); | ||
DatabaseUtils.verifyDBfileType(testDB, levelDB); | ||
} | ||
|
||
@Test (expected = InvalidFileTypeException.class) | ||
public void testVerifyLevelDBfileTypeWithInvalidOptionFile() throws IOException, InvalidFileTypeException { | ||
|
||
File options = new File(linkedDB, "OPTIONS-123"); | ||
options.createNewFile(); | ||
|
||
File symbolicLink = new File(testDB, dbName); | ||
|
||
Files.createSymbolicLink(symbolicLink.toPath(), linkedDB.toPath()); | ||
DatabaseUtils.verifyDBfileType(testDB, levelDB); | ||
} | ||
|
||
@Test (expected = InvalidFileTypeException.class) | ||
public void testVerifyLevelDBfileTypeWithInvalidSSTFile() throws IOException, InvalidFileTypeException { | ||
|
||
File options = new File(linkedDB, "123.sst"); | ||
options.createNewFile(); | ||
|
||
File symbolicLink = new File(testDB, dbName); | ||
|
||
Files.createSymbolicLink(symbolicLink.toPath(), linkedDB.toPath()); | ||
DatabaseUtils.verifyDBfileType(testDB, levelDB); | ||
} | ||
} |