Skip to content

Commit 6df929f

Browse files
committed
delete db after testcase in tmp dir; short the time cost of some case; optimize some shutdown action
1 parent 53f81a4 commit 6df929f

10 files changed

Lines changed: 25 additions & 29 deletions

File tree

framework/src/test/java/org/tron/common/utils/FileUtilTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void testReadData_NormalFile() throws IOException {
6767
try (FileWriter writer = new FileWriter(tempFile.toFile())) {
6868
writer.write("Hello, World!");
6969
}
70+
tempFile.toFile().deleteOnExit();
7071

7172
char[] buffer = new char[1024];
7273
int len = readData(tempFile.toString(), buffer);

framework/src/test/java/org/tron/common/utils/client/utils/HttpMethed.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,7 @@ public static void waitToProduceOneBlock(String httpNode) {
22312231
}
22322232
Integer nextBlockNum = 0;
22332233
Integer times = 0;
2234-
while (nextBlockNum <= currentBlockNum + 1 && times++ <= 10) {
2234+
while (nextBlockNum < currentBlockNum + 1 && times++ <= 6) {
22352235
response = HttpMethed.getNowBlock(httpNode);
22362236
responseContent = HttpMethed.parseResponseContent(response);
22372237
if (responseContent.containsKey("block_header")) {

framework/src/test/java/org/tron/core/jsonrpc/BloomTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private TransactionInfo createTransactionInfo(byte[] address1, byte[] address2)
131131

132132
@Test
133133
public void benchmarkCreateByTransaction() {
134-
int times = 10000;
134+
int times = 1000;
135135

136136
// small
137137
TransactionRetCapsule smallCapsule = new TransactionRetCapsule();

framework/src/test/java/org/tron/core/jsonrpc/ConcurrentHashMapTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void run() {
6767
TronJsonRpcImpl.handleBLockFilter(blockFilterCapsule);
6868
}
6969
try {
70-
Thread.sleep(randomInt(100, 200));
70+
Thread.sleep(randomInt(50, 100));
7171
} catch (InterruptedException e) {
7272
e.printStackTrace();
7373
}
@@ -81,7 +81,7 @@ public void run() {
8181
for (int t = 1; t <= times * 2; t++) {
8282

8383
try {
84-
Thread.sleep(randomInt(100, 200));
84+
Thread.sleep(randomInt(50, 100));
8585
} catch (InterruptedException e) {
8686
e.printStackTrace();
8787
}
@@ -111,7 +111,7 @@ public void run() {
111111
for (int t = 1; t <= times * 2; t++) {
112112

113113
try {
114-
Thread.sleep(randomInt(100, 200));
114+
Thread.sleep(randomInt(50, 100));
115115
} catch (InterruptedException e) {
116116
e.printStackTrace();
117117
}
@@ -144,7 +144,7 @@ public void run() {
144144
for (int t = 1; t <= times * 2; t++) {
145145

146146
try {
147-
Thread.sleep(randomInt(100, 200));
147+
Thread.sleep(randomInt(50, 100));
148148
} catch (InterruptedException e) {
149149
e.printStackTrace();
150150
}

framework/src/test/java/org/tron/core/metrics/prometheus/PrometheusApiServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class PrometheusApiServiceTest extends BaseTest {
4141
static LocalDateTime localDateTime = LocalDateTime.now();
4242
@Resource
4343
private DposSlot dposSlot;
44-
final int blocks = 512;
44+
final int blocks = 100;
4545
private final String key = PublicMethod.getRandomPrivateKey();
4646
private final byte[] privateKey = ByteArray.fromHexString(key);
4747
private static final AtomicInteger port = new AtomicInteger(0);

framework/src/test/java/org/tron/core/services/DelegationServiceTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,21 @@
44
import static org.tron.common.utils.client.Parameter.CommonConstant.ADD_PRE_FIX_BYTE_MAINNET;
55

66
import com.google.protobuf.ByteString;
7-
import io.grpc.ManagedChannelBuilder;
87
import javax.annotation.Resource;
98
import lombok.extern.slf4j.Slf4j;
109
import org.junit.Assert;
1110
import org.junit.BeforeClass;
1211
import org.junit.Test;
13-
import org.tron.api.GrpcAPI.BytesMessage;
14-
import org.tron.api.GrpcAPI.TransactionExtention;
15-
import org.tron.api.WalletGrpc;
16-
import org.tron.api.WalletGrpc.WalletBlockingStub;
1712
import org.tron.common.BaseTest;
1813
import org.tron.core.Constant;
1914
import org.tron.core.Wallet;
2015
import org.tron.core.capsule.AccountCapsule;
2116
import org.tron.core.config.args.Args;
2217
import org.tron.core.service.MortgageService;
23-
import org.tron.protos.contract.StorageContract.UpdateBrokerageContract;
2418

2519
@Slf4j
2620
public class DelegationServiceTest extends BaseTest {
2721

28-
private static String fullnode = "127.0.0.1:50051";
2922
@Resource
3023
protected MortgageService mortgageService;
3124

@@ -82,7 +75,6 @@ private void testWithdraw() {
8275
long reward2 = (long) ((double) dbManager.getDelegationStore().getReward(1, sr27) / 100000000
8376
* 10000000);
8477
long reward = reward1 + reward2;
85-
System.out.println("testWithdraw:" + value + ", reward:" + reward);
8678
Assert.assertEquals(reward, value);
8779
mortgageService.withdrawReward(sr1);
8880
accountCapsule = dbManager.getAccountStore().get(sr1);

framework/src/test/java/org/tron/core/services/RpcApiServicesTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
112112
public class RpcApiServicesTest {
113113

114+
private static Application appTest;
114115
private static TronApplicationContext context;
115116
private static ManagedChannel channelFull = null;
116117
private static ManagedChannel channelPBFT = null;
@@ -181,7 +182,7 @@ public static void init() throws IOException {
181182
manager.getAccountStore().put(ownerCapsule.createDbKey(), ownerCapsule);
182183
manager.getDynamicPropertiesStore().saveAllowShieldedTransaction(1);
183184
manager.getDynamicPropertiesStore().saveAllowShieldedTRC20Transaction(1);
184-
Application appTest = ApplicationFactory.create(context);
185+
appTest = ApplicationFactory.create(context);
185186
appTest.startup();
186187
}
187188

@@ -197,6 +198,7 @@ public static void destroy() {
197198
channelSolidity.shutdown();
198199
}
199200
context.close();
201+
appTest.shutdown();
200202
Args.clearParam();
201203
}
202204

framework/src/test/java/org/tron/core/services/WalletApiTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io.grpc.ManagedChannelBuilder;
44
import java.io.IOException;
55
import lombok.extern.slf4j.Slf4j;
6-
import org.junit.After;
6+
import org.junit.AfterClass;
77
import org.junit.Assert;
88
import org.junit.BeforeClass;
99
import org.junit.ClassRule;
@@ -66,10 +66,11 @@ public void listNodesTest() {
6666
}
6767
}
6868

69-
@After
70-
public void destroy() {
71-
Args.clearParam();
69+
@AfterClass
70+
public static void destroy() {
7271
context.destroy();
72+
appT.shutdown();
73+
Args.clearParam();
7374
}
7475

7576
}

plugins/src/test/java/org/tron/plugins/DbCopyTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ public class DbCopyTest extends DbTest {
1414
public void testRunForLevelDB() throws RocksDBException, IOException {
1515
init(DbTool.DbType.LevelDB);
1616
String[] args = new String[] { "db", "cp", INPUT_DIRECTORY,
17-
genarateTmpDir()};
17+
generateTmpDir()};
1818
Assert.assertEquals(0, cli.execute(args));
1919
}
2020

2121
@Test
2222
public void testRunForRocksDB() throws RocksDBException, IOException {
2323
init(DbTool.DbType.RocksDB);
2424
String[] args = new String[] { "db", "cp", INPUT_DIRECTORY,
25-
genarateTmpDir()};
25+
generateTmpDir()};
2626
Assert.assertEquals(0, cli.execute(args));
2727
}
2828

@@ -43,7 +43,7 @@ public void testNotExist() {
4343
@Test
4444
public void testEmpty() throws IOException {
4545
String[] args = new String[] {"db", "cp", temporaryFolder.newFolder().toString(),
46-
genarateTmpDir()};
46+
generateTmpDir()};
4747
Assert.assertEquals(0, cli.execute(args));
4848
}
4949

@@ -57,7 +57,7 @@ public void testDestIsExist() throws IOException {
5757
@Test
5858
public void testSrcIsFile() throws IOException {
5959
String[] args = new String[] {"db", "cp", temporaryFolder.newFile().toString(),
60-
genarateTmpDir()};
60+
generateTmpDir()};
6161
Assert.assertEquals(403, cli.execute(args));
6262
}
6363

plugins/src/test/java/org/tron/plugins/DbTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class DbTest {
2121
private static final String ACCOUNT = "account";
2222
private static final String MARKET = DBUtils.MARKET_PAIR_PRICE_TO_ORDER;
2323
public CommandLine cli = new CommandLine(new Toolkit());
24-
String tmpDir = System.getProperty("java.io.tmpdir");
2524

2625
@Rule
2726
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -51,7 +50,7 @@ private static void initDB(String sourceDir, String dbName, DbTool.DbType dbType
5150
}
5251
return;
5352
}
54-
try (DBInterface db = DbTool.getDB(sourceDir, dbName, dbType)) {
53+
try (DBInterface db = DbTool.getDB(sourceDir, dbName, dbType)) {
5554
if (MARKET.equalsIgnoreCase(dbName)) {
5655
byte[] sellTokenID1 = ByteArray.fromString("100");
5756
byte[] buyTokenID1 = ByteArray.fromString("200");
@@ -74,7 +73,6 @@ private static void initDB(String sourceDir, String dbName, DbTool.DbType dbType
7473
2003L
7574
);
7675

77-
7876
//Use out-of-order insertion,key in store should be 1,2,3
7977
db.put(pairPriceKey1, "1".getBytes(StandardCharsets.UTF_8));
8078
db.put(pairPriceKey2, "2".getBytes(StandardCharsets.UTF_8));
@@ -90,10 +88,12 @@ private static void initDB(String sourceDir, String dbName, DbTool.DbType dbType
9088

9189
/**
9290
* Generate a not-exist temporary directory path.
91+
*
9392
* @return temporary path
9493
*/
95-
public String genarateTmpDir() {
96-
File dir = Paths.get(tmpDir, UUID.randomUUID().toString()).toFile();
94+
public String generateTmpDir() throws IOException {
95+
File dir = Paths.get(temporaryFolder.newFolder().toString(), UUID.randomUUID().toString())
96+
.toFile();
9797
dir.deleteOnExit();
9898
return dir.getPath();
9999
}

0 commit comments

Comments
 (0)