Skip to content

Commit 7c4b941

Browse files
committed
optimize some testcases
1 parent 481130d commit 7c4b941

3 files changed

Lines changed: 27 additions & 17 deletions

File tree

framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ public enum RequestSource {
169169
private static final String NO_BLOCK_HEADER_BY_HASH = "header for hash not found";
170170

171171
private static final String ERROR_SELECTOR = "08c379a0"; // Function selector for Error(string)
172-
private final int filterParallelThreshold = 10000;
172+
@Setter
173+
private int filterParallelThreshold = 10000;
173174
/**
174175
* Using the default maxLogFilterNum of 20,000, a 3-thread pool can keep up with log event
175176
* processing for each block within the 3-second BLOCK_PRODUCED_INTERVAL. Increasing the thread

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ private TransactionInfo buildTxInfoWithLog(byte[] address) {
4141
return TransactionInfo.newBuilder().addLog(LogInfo.buildLog(logInfo)).build();
4242
}
4343

44-
/** Events dispatched to a matching filter in the serial (<=10000 entries) path. */
44+
/**
45+
* Events dispatched to a matching filter in the serial (<=10000 entries) path.
46+
*/
4547
@Test
4648
public void testMatchingFilter_receivesLogElements() throws JsonRpcInvalidParamsException {
4749
FilterRequest fr = new FilterRequest();
@@ -58,7 +60,9 @@ public void testMatchingFilter_receivesLogElements() throws JsonRpcInvalidParams
5860
Assert.assertEquals(1, filterAndResult.getResult().size());
5961
}
6062

61-
/** Filter with fromBlock=100 does not receive a capsule whose blockNumber is 50. */
63+
/**
64+
* Filter with fromBlock=100 does not receive a capsule whose blockNumber is 50.
65+
*/
6266
@Test
6367
public void testBlockNumberBelowRange_noResult() throws JsonRpcInvalidParamsException {
6468
FilterRequest fr = new FilterRequest();
@@ -76,7 +80,9 @@ public void testBlockNumberBelowRange_noResult() throws JsonRpcInvalidParamsExce
7680
Assert.assertTrue(filterAndResult.getResult().isEmpty());
7781
}
7882

79-
/** An expired filter is removed from the map during handleLogsFilter. */
83+
/**
84+
* An expired filter is removed from the map during handleLogsFilter.
85+
*/
8086
@Test
8187
public void testExpiredFilter_removedFromMap() throws Exception {
8288
FilterRequest fr = new FilterRequest();
@@ -100,7 +106,9 @@ public void testExpiredFilter_removedFromMap() throws Exception {
100106
Assert.assertFalse("expired filter should be removed", map.containsKey(FILTER_ID_1));
101107
}
102108

103-
/** A solidified capsule is routed only to the solidity map; the full-node map is untouched. */
109+
/**
110+
* A solidified capsule is routed only to the solidity map; the full-node map is untouched.
111+
*/
104112
@Test
105113
public void testSolidifiedCapsule_routedToSolidityMap() throws JsonRpcInvalidParamsException {
106114
FilterRequest fr = new FilterRequest();
@@ -121,7 +129,9 @@ public void testSolidifiedCapsule_routedToSolidityMap() throws JsonRpcInvalidPar
121129
Assert.assertTrue("full-node filter must not be touched", fullFilter.getResult().isEmpty());
122130
}
123131

124-
/** A non-solidified capsule is routed only to the full-node map. */
132+
/**
133+
* A non-solidified capsule is routed only to the full-node map.
134+
*/
125135
@Test
126136
public void testNonSolidifiedCapsule_routedToFullMap() throws JsonRpcInvalidParamsException {
127137
FilterRequest fr = new FilterRequest();
@@ -142,7 +152,9 @@ public void testNonSolidifiedCapsule_routedToFullMap() throws JsonRpcInvalidPara
142152
Assert.assertTrue("solidity filter must not be touched", solidityFilter.getResult().isEmpty());
143153
}
144154

145-
/** Both filters in the map receive events when both match. */
155+
/**
156+
* Both filters in the map receive events when both match.
157+
*/
146158
@Test
147159
public void testMultipleMatchingFilters_bothReceiveEvents() throws JsonRpcInvalidParamsException {
148160
FilterRequest fr = new FilterRequest();
@@ -162,7 +174,9 @@ public void testMultipleMatchingFilters_bothReceiveEvents() throws JsonRpcInvali
162174
Assert.assertEquals(1, filter2.getResult().size());
163175
}
164176

165-
/** An empty txInfoList produces no results. */
177+
/**
178+
* An empty txInfoList produces no results.
179+
*/
166180
@Test
167181
public void testEmptyTxInfoList_noResult() throws JsonRpcInvalidParamsException {
168182
FilterRequest fr = new FilterRequest();
@@ -177,14 +191,8 @@ public void testEmptyTxInfoList_noResult() throws JsonRpcInvalidParamsException
177191
Assert.assertTrue(filterAndResult.getResult().isEmpty());
178192
}
179193

180-
// -------------------------------------------------------------------------
181-
// Parallel path tests (filterParallelThreshold lowered to 2 via reflection)
182-
// -------------------------------------------------------------------------
183-
184-
private void setParallelThreshold(int value) throws Exception {
185-
Field f = TronJsonRpcImpl.class.getDeclaredField("filterParallelThreshold");
186-
f.setAccessible(true);
187-
f.setInt(jsonRpc, value);
194+
private void setParallelThreshold(int value) {
195+
jsonRpc.setFilterParallelThreshold(value);
188196
}
189197

190198
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ public void testEnableInFullNode() {
159159
*/
160160
@Test
161161
public void testNewFilter_exceedsCapThrowsException() throws Exception {
162-
int cap = Args.getInstance().getJsonRpcMaxLogFilterNum();
162+
int cap = 5;
163+
Args.getInstance().setJsonRpcMaxLogFilterNum(cap);
163164
FilterRequest fr = new FilterRequest();
164165
TronJsonRpcImpl tronJsonRpc = new TronJsonRpcImpl(nodeInfoService, wallet);
165166
tronJsonRpc.setManager(dbManager);

0 commit comments

Comments
 (0)