Skip to content

Commit 0fbbc7a

Browse files
authored
test(refactor): create folders with temporaryFolder (#5477)
1 parent b54912a commit 0fbbc7a

161 files changed

Lines changed: 413 additions & 586 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

framework/src/test/java/org/tron/common/BaseTest.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package org.tron.common;
22

33
import com.google.protobuf.ByteString;
4-
import java.io.File;
4+
import java.io.IOException;
55
import javax.annotation.Resource;
66
import lombok.extern.slf4j.Slf4j;
7-
import org.apache.commons.lang3.StringUtils;
87
import org.junit.AfterClass;
8+
import org.junit.Assert;
9+
import org.junit.ClassRule;
10+
import org.junit.rules.TemporaryFolder;
911
import org.junit.runner.RunWith;
1012
import org.springframework.test.annotation.DirtiesContext;
1113
import org.springframework.test.context.ContextConfiguration;
1214
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
1315
import org.tron.common.crypto.ECKey;
1416
import org.tron.common.parameter.CommonParameter;
15-
import org.tron.common.utils.FileUtil;
1617
import org.tron.common.utils.Sha256Hash;
1718
import org.tron.consensus.base.Param;
1819
import org.tron.core.ChainBaseManager;
@@ -28,22 +29,27 @@
2829
@DirtiesContext
2930
public abstract class BaseTest {
3031

31-
protected static String dbPath;
32+
@ClassRule
33+
public static final TemporaryFolder temporaryFolder = new TemporaryFolder();
34+
3235
@Resource
3336
protected Manager dbManager;
3437
@Resource
3538
protected ChainBaseManager chainBaseManager;
3639

40+
41+
public static String dbPath() {
42+
try {
43+
return temporaryFolder.newFolder().toString();
44+
} catch (IOException e) {
45+
Assert.fail("create temp folder failed");
46+
}
47+
return null;
48+
}
49+
3750
@AfterClass
3851
public static void destroy() {
3952
Args.clearParam();
40-
if (StringUtils.isNotEmpty(dbPath)) {
41-
if (FileUtil.deleteDir(new File(dbPath))) {
42-
logger.info("Release resources successful.");
43-
} else {
44-
logger.info("Release resources failure.");
45-
}
46-
}
4753
}
4854

4955
public Protocol.Block getSignedBlock(ByteString witness, long time, byte[] privateKey) {

framework/src/test/java/org/tron/common/config/args/ArgsTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
package org.tron.common.config.args;
22

3-
import java.io.File;
3+
import java.io.IOException;
44
import org.junit.After;
55
import org.junit.Assert;
66
import org.junit.Before;
7+
import org.junit.Rule;
78
import org.junit.Test;
9+
import org.junit.rules.TemporaryFolder;
810
import org.tron.common.parameter.RateLimiterInitialization;
9-
import org.tron.common.utils.FileUtil;
1011
import org.tron.core.Constant;
1112
import org.tron.core.config.args.Args;
1213

1314

1415
public class ArgsTest {
1516

16-
private static final String dbPath = "output_arg_test";
17+
@Rule
18+
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
1719

1820
@Before
19-
public void init() {
20-
Args.setParam(new String[] {"--output-directory", dbPath, "--p2p-disable", "true",
21+
public void init() throws IOException {
22+
Args.setParam(new String[] {"--output-directory",
23+
temporaryFolder.newFolder().toString(), "--p2p-disable", "true",
2124
"--debug"}, Constant.TEST_CONF);
2225
}
2326

2427
@After
2528
public void destroy() {
2629
Args.clearParam();
27-
FileUtil.deleteDir(new File(dbPath));
2830
}
2931

3032
@Test

framework/src/test/java/org/tron/common/runtime/InheritanceTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public class InheritanceTest extends BaseTest {
2525
private static boolean init;
2626

2727
static {
28-
dbPath = "output_InheritanceTest";
29-
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
28+
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
3029
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
3130
}
3231

framework/src/test/java/org/tron/common/runtime/InternalTransactionComplexTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public class InternalTransactionComplexTest extends BaseTest {
2727
private static boolean init;
2828

2929
static {
30-
dbPath = "output_InternalTransactionComplexTest";
31-
Args.setParam(new String[]{"--output-directory", dbPath, "--debug", "--support-constant"},
30+
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug", "--support-constant"},
3231
Constant.TEST_CONF);
3332
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
3433
}

framework/src/test/java/org/tron/common/runtime/ProgramResultTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public class ProgramResultTest extends BaseTest {
4444
private static boolean init;
4545

4646
static {
47-
dbPath = "output_InternalTransactionComplexTest";
48-
Args.setParam(new String[]{"--output-directory", dbPath, "--debug", "--support-constant"},
47+
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug", "--support-constant"},
4948
Constant.TEST_CONF);
5049
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
5150
TRANSFER_TO = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc";

framework/src/test/java/org/tron/common/runtime/RuntimeImplTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public class RuntimeImplTest extends BaseTest {
4040
private final long creatorTotalBalance = 3_000_000_000L;
4141

4242
static {
43-
dbPath = "output_RuntimeImplTest";
44-
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
43+
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
4544
callerAddress = Hex
4645
.decode(Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc");
4746
creatorAddress = Hex

framework/src/test/java/org/tron/common/runtime/RuntimeTransferComplexTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public class RuntimeTransferComplexTest extends BaseTest {
3232
private static boolean init;
3333

3434
static {
35-
dbPath = "output_RuntimeTransferComplexTest";
36-
Args.setParam(new String[]{"--output-directory", dbPath, "--debug"}, Constant.TEST_CONF);
35+
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
3736
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
3837
TRANSFER_TO = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc";
3938
}

framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ public class BandWidthRuntimeOutOfTimeTest extends BaseTest {
6767
private static boolean init;
6868

6969
static {
70-
dbPath = "output_bandwidth_runtime_out_of_time_test";
7170
Args.setParam(
7271
new String[]{
73-
"--output-directory", dbPath,
72+
"--output-directory", dbPath(),
7473
"--storage-db-directory", dbDirectory,
7574
"--storage-index-directory", indexDirectory,
7675
"-w",

framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeWithCheckTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ public class BandWidthRuntimeOutOfTimeWithCheckTest extends BaseTest {
6868
private static boolean init;
6969

7070
static {
71-
dbPath = "output_bandwidth_runtime_out_of_time_with_check_test";
7271
Args.setParam(
7372
new String[]{
74-
"--output-directory", dbPath,
73+
"--output-directory", dbPath(),
7574
"--storage-db-directory", dbDirectory,
7675
"--storage-index-directory", indexDirectory,
7776
"-w",

framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ public class BandWidthRuntimeTest extends BaseTest {
5959

6060
@BeforeClass
6161
public static void init() {
62-
dbPath = "output_bandwidth_runtime_test";
6362
Args.setParam(
6463
new String[]{
65-
"--output-directory", dbPath,
64+
"--output-directory", dbPath(),
6665
"--storage-db-directory", dbDirectory,
6766
"--storage-index-directory", indexDirectory,
6867
"-w"

0 commit comments

Comments
 (0)