Skip to content

Commit 6db67ef

Browse files
committed
refactor
1. unit test module
1 parent 13a89be commit 6db67ef

7 files changed

Lines changed: 189 additions & 186 deletions

File tree

src/test/java/org/tron/config/ConfigerTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
import org.junit.Test;
1919
import org.slf4j.Logger;
2020
import org.slf4j.LoggerFactory;
21-
import org.tron.crypto.ECKey;
22-
import org.tron.utils.ByteArray;
21+
import org.tron.common.crypto.ECKey;
22+
import org.tron.common.utils.ByteArray;
23+
import org.tron.core.config.Configer;
2324

2425
public class ConfigerTest {
25-
private static final Logger logger = LoggerFactory.getLogger("Test");
26+
private static final Logger logger = LoggerFactory.getLogger("Test");
2627

27-
@Test
28-
public void testGetECKey() {
29-
ECKey key = Configer.getMyKey();
28+
@Test
29+
public void testGetECKey() {
30+
ECKey key = Configer.getMyKey();
3031

31-
logger.info("address = {}", ByteArray.toHexString(key.getAddress()));
32-
}
32+
logger.info("address = {}", ByteArray.toHexString(key.getAddress()));
33+
}
3334
}

src/test/java/org/tron/consensus/client/ClientTest.java

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,64 @@
1818
import io.atomix.catalyst.transport.Address;
1919
import io.atomix.catalyst.transport.netty.NettyTransport;
2020
import io.atomix.copycat.client.CopycatClient;
21+
import org.tron.core.consensus.common.GetQuery;
22+
import org.tron.core.consensus.common.PutCommand;
23+
2124
import java.net.InetAddress;
2225
import java.net.UnknownHostException;
2326
import java.util.Arrays;
2427
import java.util.Collection;
2528
import java.util.concurrent.CompletableFuture;
26-
import org.tron.consensus.common.GetQuery;
27-
import org.tron.consensus.common.PutCommand;
2829

2930
public class ClientTest {
30-
public static void main(String[] args) {
31-
CopycatClient.Builder builder = CopycatClient.builder();
31+
public static void main(String[] args) {
32+
CopycatClient.Builder builder = CopycatClient.builder();
3233

33-
builder.withTransport(NettyTransport.builder()
34-
.withThreads(2)
35-
.build());
34+
builder.withTransport(NettyTransport.builder()
35+
.withThreads(2)
36+
.build());
3637

37-
CopycatClient client = builder.build();
38+
CopycatClient client = builder.build();
3839

39-
client.serializer().register(PutCommand.class);
40-
client.serializer().register(GetQuery.class);
40+
client.serializer().register(PutCommand.class);
41+
client.serializer().register(GetQuery.class);
4142

42-
InetAddress localhost = null;
43-
try {
44-
localhost = InetAddress.getLocalHost();
45-
System.out.println(localhost);
46-
Collection<Address> cluster = Arrays.asList(
47-
new Address(localhost.getHostAddress(), 5000)
48-
);
49-
CompletableFuture<CopycatClient> future = client.connect(cluster);
50-
future.join();
51-
} catch (UnknownHostException e) {
52-
e.printStackTrace();
53-
}
54-
client.submit(new GetQuery("block")).thenAccept(result1 -> {
55-
System.out.println("foo is: " + result1.toString());
56-
});
57-
int i = 1;
58-
//客户端提交查询
59-
boolean f = true;
60-
while (f) {
61-
String key = "block" + i;
62-
Object result = client.submit(new GetQuery(key)).join();
63-
try {
64-
if (!(result == null)) {
65-
System.out.println("空指针异常没有发生,为null");
66-
System.out.println("Consensus " + key + " is: " + result);
67-
f = true;
68-
i = i + 1;
69-
} else {
70-
f = false;
43+
InetAddress localhost = null;
44+
try {
45+
localhost = InetAddress.getLocalHost();
46+
System.out.println(localhost);
47+
Collection<Address> cluster = Arrays.asList(
48+
new Address(localhost.getHostAddress(), 5000)
49+
);
50+
CompletableFuture<CopycatClient> future = client.connect(cluster);
51+
future.join();
52+
} catch (UnknownHostException e) {
53+
e.printStackTrace();
7154
}
55+
client.submit(new GetQuery("block")).thenAccept(result1 -> {
56+
System.out.println("foo is: " + result1.toString());
57+
});
58+
int i = 1;
59+
//客户端提交查询
60+
boolean f = true;
61+
while (f) {
62+
String key = "block" + i;
63+
Object result = client.submit(new GetQuery(key)).join();
64+
try {
65+
if (!(result == null)) {
66+
System.out.println("空指针异常没有发生,为null");
67+
System.out.println("Consensus " + key + " is: " + result);
68+
f = true;
69+
i = i + 1;
70+
} else {
71+
f = false;
72+
}
7273

73-
} catch (NullPointerException e) {
74-
System.out.println("object == null不会导致空指针异常发生");
75-
f = false;
76-
}
74+
} catch (NullPointerException e) {
75+
System.out.println("object == null不会导致空指针异常发生");
76+
f = false;
77+
}
7778

79+
}
7880
}
79-
}
8081
}

src/test/java/org/tron/dbStore/BlockStoresTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,27 @@
1717

1818
import org.junit.Ignore;
1919
import org.junit.Test;
20+
import org.tron.common.utils.ByteArray;
2021
import org.tron.core.Constant;
21-
import org.tron.utils.ByteArray;
22+
import org.tron.core.dbStore.BlockStores;
2223

2324
import static org.tron.core.Constant.BLOCK_DB_NAME;
2425

2526
@Ignore
2627
public class BlockStoresTest {
2728

28-
@Test
29-
public void saveBlock() {
30-
BlockStores blockStores = new BlockStores(Constant.TEST, BLOCK_DB_NAME);
31-
blockStores.saveBlock("0001245".getBytes(), "xxdfrgds".getBytes());
32-
blockStores.close();
33-
}
29+
@Test
30+
public void saveBlock() {
31+
BlockStores blockStores = new BlockStores(Constant.TEST, BLOCK_DB_NAME);
32+
blockStores.saveBlock("0001245".getBytes(), "xxdfrgds".getBytes());
33+
blockStores.close();
34+
}
3435

35-
@Test
36-
public void findBlockByHash() {
37-
BlockStores blockStores = new BlockStores(Constant.TEST, BLOCK_DB_NAME);
38-
byte[] blockByHash = blockStores.findBlockByHash("0001245".getBytes());
39-
blockStores.close();
40-
System.out.println(ByteArray.toStr(blockByHash));
41-
}
36+
@Test
37+
public void findBlockByHash() {
38+
BlockStores blockStores = new BlockStores(Constant.TEST, BLOCK_DB_NAME);
39+
byte[] blockByHash = blockStores.findBlockByHash("0001245".getBytes());
40+
blockStores.close();
41+
System.out.println(ByteArray.toStr(blockByHash));
42+
}
4243
}

src/test/java/org/tron/dbStore/UTXOStoreTest.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,32 @@
1515

1616
package org.tron.dbStore;
1717

18-
import static org.tron.core.Constant.BLOCK_DB_NAME;
19-
2018
import org.junit.Ignore;
2119
import org.junit.Test;
20+
import org.tron.common.utils.ByteArray;
2221
import org.tron.core.Constant;
23-
import org.tron.utils.ByteArray;
22+
import org.tron.core.dbStore.UTXOStore;
23+
24+
import static org.tron.core.Constant.BLOCK_DB_NAME;
2425

2526
@Ignore
2627
public class UTXOStoreTest {
2728

28-
/**
29-
* save utxo
30-
*/
31-
@Test
32-
public void saveUTXO() {
33-
UTXOStore utxoStore = new UTXOStore(Constant.TEST, BLOCK_DB_NAME);
34-
utxoStore.saveUTXO("00012546".getBytes(), "300".getBytes());
35-
utxoStore.close();
36-
}
29+
/**
30+
* save utxo
31+
*/
32+
@Test
33+
public void saveUTXO() {
34+
UTXOStore utxoStore = new UTXOStore(Constant.TEST, BLOCK_DB_NAME);
35+
utxoStore.saveUTXO("00012546".getBytes(), "300".getBytes());
36+
utxoStore.close();
37+
}
3738

38-
@Test
39-
public void find() {
40-
UTXOStore utxoStore = new UTXOStore(Constant.TEST, BLOCK_DB_NAME);
41-
byte[] bytes = utxoStore.find("00012546".getBytes());
42-
utxoStore.close();
43-
System.out.println(ByteArray.toStr(bytes));
44-
}
39+
@Test
40+
public void find() {
41+
UTXOStore utxoStore = new UTXOStore(Constant.TEST, BLOCK_DB_NAME);
42+
byte[] bytes = utxoStore.find("00012546".getBytes());
43+
utxoStore.close();
44+
System.out.println(ByteArray.toStr(bytes));
45+
}
4546
}

src/test/java/org/tron/storage/leveldb/LevelDbDataSourceImplTest.java

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,54 @@
1717
*/
1818
package org.tron.storage.leveldb;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotNull;
22-
2320
import org.junit.Ignore;
2421
import org.junit.Test;
22+
import org.tron.common.storage.leveldb.LevelDbDataSourceImpl;
23+
import org.tron.common.utils.ByteArray;
2524
import org.tron.core.Constant;
26-
import org.tron.utils.ByteArray;
25+
26+
import static org.junit.Assert.assertEquals;
27+
import static org.junit.Assert.assertNotNull;
2728

2829
@Ignore
2930
public class LevelDbDataSourceImplTest {
3031

31-
@Test
32-
public void testGet() {
33-
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(Constant.TEST, "test");
34-
dataSource.initDB();
35-
String key1 = "000134yyyhy";
36-
byte[] key = key1.getBytes();
37-
byte[] value = dataSource.getData(key);
38-
String s = ByteArray.toStr(value);
39-
dataSource.closeDB();
40-
System.out.println(s);
41-
}
32+
@Test
33+
public void testGet() {
34+
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(Constant.TEST, "test");
35+
dataSource.initDB();
36+
String key1 = "000134yyyhy";
37+
byte[] key = key1.getBytes();
38+
byte[] value = dataSource.getData(key);
39+
String s = ByteArray.toStr(value);
40+
dataSource.closeDB();
41+
System.out.println(s);
42+
}
4243

43-
@Test
44-
public void testPut() {
45-
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(Constant.TEST, "test");
46-
dataSource.initDB();
47-
String key1 = "000134yyyhy";
48-
byte[] key = key1.getBytes();
44+
@Test
45+
public void testPut() {
46+
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(Constant.TEST, "test");
47+
dataSource.initDB();
48+
String key1 = "000134yyyhy";
49+
byte[] key = key1.getBytes();
4950

50-
String value1 = "50000";
51-
byte[] value = value1.getBytes();
51+
String value1 = "50000";
52+
byte[] value = value1.getBytes();
5253

53-
dataSource.putData(key, value);
54+
dataSource.putData(key, value);
5455

55-
assertNotNull(dataSource.getData(key));
56-
assertEquals(1, dataSource.allKeys().size());
56+
assertNotNull(dataSource.getData(key));
57+
assertEquals(1, dataSource.allKeys().size());
5758

58-
dataSource.closeDB();
59-
}
59+
dataSource.closeDB();
60+
}
6061

61-
@Test
62-
public void testRest() {
62+
@Test
63+
public void testRest() {
6364

64-
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(Constant.TEST_CONF, "test");
65-
dataSource.resetDB();
66-
dataSource.closeDB();
67-
}
65+
LevelDbDataSourceImpl dataSource = new LevelDbDataSourceImpl(Constant.TEST_CONF, "test");
66+
dataSource.resetDB();
67+
dataSource.closeDB();
68+
}
6869

6970
}

0 commit comments

Comments
 (0)