Skip to content

Commit 8a4066b

Browse files
committed
remove all junit dir under tmp
1 parent 02f81c6 commit 8a4066b

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

framework/src/test/java/org/tron/core/event/BlockEventGetTest.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
import java.util.List;
1212
import java.util.concurrent.atomic.AtomicInteger;
1313
import lombok.extern.slf4j.Slf4j;
14-
import org.junit.After;
14+
import org.junit.AfterClass;
1515
import org.junit.Assert;
1616
import org.junit.Before;
17+
import org.junit.BeforeClass;
1718
import org.junit.ClassRule;
1819
import org.junit.Test;
1920
import org.junit.rules.TemporaryFolder;
@@ -63,22 +64,30 @@ public class BlockEventGetTest extends BlockGenerate {
6364
protected Manager dbManager;
6465
long currentHeader = -1;
6566
private TronNetDelegate tronNetDelegate;
66-
private TronApplicationContext context;
67+
private static TronApplicationContext context;
6768

6869

6970
static LocalDateTime localDateTime = LocalDateTime.now();
7071
private long time = ZonedDateTime.of(localDateTime,
7172
ZoneId.systemDefault()).toInstant().toEpochMilli();
7273

73-
protected void initDbPath() throws IOException {
74-
dbPath = temporaryFolder.newFolder().toString();
74+
75+
public static String dbPath() {
76+
try {
77+
return temporaryFolder.newFolder().toString();
78+
} catch (IOException e) {
79+
Assert.fail("create temp folder failed");
80+
}
81+
return null;
82+
}
83+
84+
@BeforeClass
85+
public static void init() {
86+
Args.setParam(new String[] {"--output-directory", dbPath()}, Constant.TEST_CONF);
7587
}
7688

7789
@Before
7890
public void before() throws IOException {
79-
initDbPath();
80-
logger.info("Full node running.");
81-
Args.setParam(new String[] {"-d", dbPath}, Constant.TEST_CONF);
8291
Args.getInstance().setNodeListenPort(10000 + port.incrementAndGet());
8392

8493
context = new TronApplicationContext(DefaultConfig.class);
@@ -91,7 +100,7 @@ public void before() throws IOException {
91100
tronNetDelegate = context.getBean(TronNetDelegate.class);
92101
tronNetDelegate.setExit(false);
93102
currentHeader = dbManager.getDynamicPropertiesStore()
94-
.getLatestBlockHeaderNumberFromDB();
103+
.getLatestBlockHeaderNumberFromDB();
95104

96105
ByteString addressBS = ByteString.copyFrom(address);
97106
WitnessCapsule witnessCapsule = new WitnessCapsule(addressBS);
@@ -108,8 +117,10 @@ public void before() throws IOException {
108117
dps.saveAllowTvmShangHai(1);
109118
}
110119

111-
@After
112-
public void after() throws IOException {
120+
@AfterClass
121+
public static void after() throws IOException {
122+
context.destroy();
123+
Args.clearParam();
113124
}
114125

115126
@Test
@@ -132,13 +143,13 @@ public void test() throws Exception {
132143
+ "57c973388f044038eff0e6474425b38037e75e66d6b3047647290605449c7764736f6c63430008140033";
133144
Protocol.Transaction trx = TvmTestUtils.generateDeploySmartContractAndGetTransaction(
134145
"TestTRC20", address, "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\""
135-
+ ":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"}"
136-
+ ",{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\","
137-
+ "\"type\":\"event\"}]", code, 0, (long) 1e9, 100, null, 1);
146+
+ ":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"}"
147+
+ ",{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\","
148+
+ "\"type\":\"event\"}]", code, 0, (long) 1e9, 100, null, 1);
138149
trx = trx.toBuilder().addRet(
139-
Protocol.Transaction.Result.newBuilder()
140-
.setContractRetValue(Protocol.Transaction.Result.contractResult.SUCCESS_VALUE)
141-
.build()).build();
150+
Protocol.Transaction.Result.newBuilder()
151+
.setContractRetValue(Protocol.Transaction.Result.contractResult.SUCCESS_VALUE)
152+
.build()).build();
142153

143154
Protocol.Block block = getSignedBlock(witnessCapsule.getAddress(), time, privateKey);
144155
BlockCapsule blockCapsule = new BlockCapsule(block.toBuilder().addTransactions(trx).build());

framework/src/test/java/org/tron/core/net/messagehandler/SyncBlockChainMsgHandlerTest.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.tron.core.net.messagehandler;
22

3+
import java.io.IOException;
34
import java.lang.reflect.Field;
45
import java.lang.reflect.InvocationTargetException;
56
import java.lang.reflect.Method;
@@ -9,7 +10,8 @@
910
import org.junit.After;
1011
import org.junit.Assert;
1112
import org.junit.Before;
12-
import org.junit.Rule;
13+
import org.junit.BeforeClass;
14+
import org.junit.ClassRule;
1315
import org.junit.Test;
1416
import org.junit.rules.TemporaryFolder;
1517
import org.tron.common.application.TronApplicationContext;
@@ -29,13 +31,25 @@ public class SyncBlockChainMsgHandlerTest {
2931
private TronApplicationContext context;
3032
private SyncBlockChainMsgHandler handler;
3133
private PeerConnection peer;
32-
@Rule
33-
public TemporaryFolder temporaryFolder = new TemporaryFolder();
34+
@ClassRule
35+
public static final TemporaryFolder temporaryFolder = new TemporaryFolder();
36+
37+
public static String dbPath() {
38+
try {
39+
return temporaryFolder.newFolder().toString();
40+
} catch (IOException e) {
41+
Assert.fail("create temp folder failed");
42+
}
43+
return null;
44+
}
45+
46+
@BeforeClass
47+
public static void before() {
48+
Args.setParam(new String[] {"--output-directory", dbPath()}, Constant.TEST_CONF);
49+
}
3450

3551
@Before
3652
public void init() throws Exception {
37-
Args.setParam(new String[]{"--output-directory",
38-
temporaryFolder.newFolder().toString(), "--debug"}, Constant.TEST_CONF);
3953
context = new TronApplicationContext(DefaultConfig.class);
4054
handler = context.getBean(SyncBlockChainMsgHandler.class);
4155
peer = context.getBean(PeerConnection.class);
@@ -65,16 +79,16 @@ public void testProcessMessage() throws Exception {
6579
blockIds.add(new BlockCapsule.BlockId());
6680
SyncBlockChainMessage message = new SyncBlockChainMessage(blockIds);
6781
Method method = handler.getClass().getDeclaredMethod(
68-
"check", PeerConnection.class, SyncBlockChainMessage.class);
82+
"check", PeerConnection.class, SyncBlockChainMessage.class);
6983
method.setAccessible(true);
70-
boolean f = (boolean)method.invoke(handler, peer, message);
84+
boolean f = (boolean) method.invoke(handler, peer, message);
7185
Assert.assertNotNull(message.getAnswerMessage());
7286
Assert.assertNotNull(message.toString());
7387
Assert.assertNotNull(((BlockInventoryMessage) message).getAnswerMessage());
7488
Assert.assertFalse(f);
7589
method.invoke(handler, peer, message);
7690
method.invoke(handler, peer, message);
77-
f = (boolean)method.invoke(handler, peer, message);
91+
f = (boolean) method.invoke(handler, peer, message);
7892
Assert.assertFalse(f);
7993

8094
Method method1 = handler.getClass().getDeclaredMethod(
@@ -95,6 +109,7 @@ public void testProcessMessage() throws Exception {
95109

96110
@After
97111
public void destroy() {
112+
context.destroy();
98113
Args.clearParam();
99114
}
100115

0 commit comments

Comments
 (0)