Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@ src/main/gen
src/main/java/org/tron/core/bftconsensus
src/test/java/org/tron/consensus2
src/main/java/META-INF/
src/main/resources/META-INF/
src/main/resources/META-INF/
/bin/

# Eclipse IDE specific files and folders
/.project
/.classpath
/.settings/

# output directory
/output-directory/
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
* Copyright (c) [2016] [ <ether.camp> ] This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* The ethereumJ library is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* The ethereumJ library is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Lesser General Public License along with the ethereumJ
* library. If not, see <http://www.gnu.org/licenses/>.
*/

package org.tron.common.storage.leveldb;

import static org.fusesource.leveldbjni.JniDBFactory.factory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -43,7 +39,6 @@
import org.tron.core.Constant;
import org.tron.core.config.Configer;


public class LevelDbDataSourceImpl implements DbSourceInter<byte[]> {

private static final Logger logger = LoggerFactory.getLogger("dbStore");
Expand All @@ -53,8 +48,7 @@ public class LevelDbDataSourceImpl implements DbSourceInter<byte[]> {
private String parentName;
private ReadWriteLock resetDbLock = new ReentrantReadWriteLock();

public LevelDbDataSourceImpl() {
}
public LevelDbDataSourceImpl() {}

public LevelDbDataSourceImpl(String cfgType, String parentName, String name) {
if (Constant.NORMAL == cfgType) {
Expand Down Expand Up @@ -240,10 +234,10 @@ public boolean flush() {
@Override
public void closeDB() {
resetDbLock.writeLock().lock();
if (!isAlive()) {
return;
}
try {
if (!isAlive()) {
return;
}
database.close();
alive = false;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
* Copyright (c) [2016] [ <ether.camp> ] This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* The ethereumJ library is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* The ethereumJ library is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
* You should have received a copy of the GNU Lesser General Public License along with the ethereumJ
* library. If not, see <http://www.gnu.org/licenses/>.
*/

package org.tron.common.storage.leveldb;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;

import org.junit.Ignore;
import org.junit.Before;
import org.junit.Test;
import org.tron.common.utils.ByteArray;
import org.tron.core.Constant;

@Ignore
public class LevelDbDataSourceImplTest {

private LevelDbDataSourceImpl dataSource;

@Before
public void setup() {
dataSource = new LevelDbDataSourceImpl(Constant.TEST, Constant.OUTPUT_DIR, "test");
}

@Test
public void testGet() {
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(Constant.TEST, Constant.OUTPUT_DIR,
"test");
dataSource.initDB();
String key1 = "000134yyyhy";
byte[] key = key1.getBytes();
Expand All @@ -44,8 +45,6 @@ public void testGet() {

@Test
public void testPut() {
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(Constant.TEST, Constant.OUTPUT_DIR,
"test");
dataSource.initDB();
String key1 = "000134yyyhy";
byte[] key = key1.getBytes();
Expand All @@ -63,11 +62,21 @@ public void testPut() {

@Test
public void testRest() {

LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(Constant.TEST_CONF,
Constant.OUTPUT_DIR, "test");
dataSource.resetDB();
dataSource.closeDB();
}

}
@Test(timeout = 100)
public void testLockReleased() {
dataSource.initDB();
// normal close
dataSource.closeDB();
// closing already closed db.
dataSource.closeDB();
// closing again to make sure the lock is free. If not test will hang.
dataSource.closeDB();

assertFalse("Database is still alive after closing.", dataSource.isAlive());
}

}