forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db):tune the databases closure (tronprotocol#5429)
- Loading branch information
1 parent
e1d096b
commit a4100b6
Showing
9 changed files
with
140 additions
and
84 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
101 changes: 101 additions & 0 deletions
101
framework/src/test/java/org/tron/core/db/TronDatabaseTest.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,101 @@ | ||
package org.tron.core.db; | ||
|
||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import java.io.IOException; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.rocksdb.RocksDB; | ||
import org.tron.core.Constant; | ||
import org.tron.core.config.args.Args; | ||
import org.tron.core.exception.BadItemException; | ||
import org.tron.core.exception.ItemNotFoundException; | ||
|
||
public class TronDatabaseTest extends TronDatabase<String> { | ||
|
||
@ClassRule | ||
public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
static { | ||
RocksDB.loadLibrary(); | ||
} | ||
|
||
@BeforeClass | ||
public static void initArgs() throws IOException { | ||
Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); | ||
} | ||
|
||
@AfterClass | ||
public static void destroy() { | ||
Args.clearParam(); | ||
} | ||
|
||
@Override | ||
public void put(byte[] key, String item) { | ||
|
||
} | ||
|
||
@Override | ||
public void delete(byte[] key) { | ||
|
||
} | ||
|
||
@Override | ||
public String get(byte[] key) { | ||
return "test"; | ||
} | ||
|
||
@Override | ||
public boolean has(byte[] key) { | ||
return false; | ||
} | ||
|
||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@Test | ||
public void TestInit() { | ||
TronDatabaseTest db = new TronDatabaseTest(); | ||
Assert.assertNull(db.getDbSource()); | ||
Assert.assertNull(db.getDbName()); | ||
} | ||
|
||
@Test | ||
public void TestIterator() { | ||
TronDatabaseTest db = new TronDatabaseTest(); | ||
thrown.expect(UnsupportedOperationException.class); | ||
db.iterator(); | ||
} | ||
|
||
@Test | ||
public void TestIsNotEmpty() { | ||
TronDatabaseTest db = new TronDatabaseTest(); | ||
thrown.expect(UnsupportedOperationException.class); | ||
db.isNotEmpty(); | ||
} | ||
|
||
@Test | ||
public void TestGetUnchecked() { | ||
TronDatabaseTest db = new TronDatabaseTest(); | ||
Assert.assertNull(db.getUnchecked("test".getBytes())); | ||
} | ||
|
||
@Test | ||
public void TestClose() { | ||
TronDatabaseTest db = new TronDatabaseTest(); | ||
db.close(); | ||
} | ||
|
||
@Test | ||
public void TestGetFromRoot() throws | ||
InvalidProtocolBufferException, BadItemException, ItemNotFoundException { | ||
TronDatabaseTest db = new TronDatabaseTest(); | ||
Assert.assertEquals(db.getFromRoot("test".getBytes()), | ||
"test"); | ||
} | ||
} |
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