Skip to content

Commit fe599e8

Browse files
committed
mdf TcpNetTest.java
1 parent b0f5c6d commit fe599e8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/test/java/org/tron/core/net/node/TcpNetTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.tron.protos.Protocol.ReasonCode.INCOMPATIBLE_CHAIN;
88
import static org.tron.protos.Protocol.ReasonCode.INCOMPATIBLE_PROTOCOL;
99

10+
import com.google.common.cache.CacheBuilder;
1011
import io.netty.buffer.ByteBuf;
1112
import io.netty.buffer.Unpooled;
1213
import io.netty.channel.Channel;
@@ -19,6 +20,7 @@
1920
import java.util.Date;
2021
import java.util.List;
2122
import java.util.concurrent.ConcurrentHashMap;
23+
import java.util.concurrent.TimeUnit;
2224
import lombok.extern.slf4j.Slf4j;
2325
import org.apache.commons.collections4.map.LRUMap;
2426
import org.apache.commons.lang3.ArrayUtils;
@@ -233,8 +235,8 @@ private void validResultCloseConnect(Channel channel) throws InterruptedExceptio
233235
finish = false;
234236
channel.close();
235237
Thread.sleep(sleepTime);
236-
ReflectUtils.setFieldValue(channelManager, "recentlyDisconnected", Collections
237-
.synchronizedMap(new LRUMap<InetAddress, Date>(500)));
238+
ReflectUtils.setFieldValue(channelManager, "recentlyDisconnected", CacheBuilder.newBuilder().maximumSize(1000)
239+
.expireAfterWrite(30, TimeUnit.SECONDS).recordStats().build());
238240
ReflectUtils.setFieldValue(pool, "activePeers",
239241
Collections.synchronizedList(new ArrayList<PeerConnection>()));
240242
ReflectUtils.setFieldValue(channelManager, "activePeers", new ConcurrentHashMap<>());
@@ -252,8 +254,8 @@ private void validResultUnCloseConnect() throws InterruptedException {
252254
private void clearConnect(Channel channel) throws InterruptedException {
253255
channel.close();
254256
Thread.sleep(sleepTime);
255-
ReflectUtils.setFieldValue(channelManager, "recentlyDisconnected", Collections
256-
.synchronizedMap(new LRUMap<InetAddress, Date>(500)));
257+
ReflectUtils.setFieldValue(channelManager, "recentlyDisconnected", CacheBuilder.newBuilder().maximumSize(1000)
258+
.expireAfterWrite(30, TimeUnit.SECONDS).recordStats().build());
257259
ReflectUtils.setFieldValue(pool, "activePeers",
258260
Collections.synchronizedList(new ArrayList<PeerConnection>()));
259261
ReflectUtils.setFieldValue(channelManager, "activePeers", new ConcurrentHashMap<>());

0 commit comments

Comments
 (0)