88import java .util .concurrent .ConcurrentHashMap ;
99import java .util .concurrent .ExecutorService ;
1010import lombok .extern .slf4j .Slf4j ;
11+ import org .apache .commons .collections4 .MapUtils ;
1112import org .junit .After ;
1213import org .junit .Assert ;
1314import org .junit .Before ;
1819import org .tron .common .overlay .client .PeerClient ;
1920import org .tron .common .overlay .discover .Node ;
2021import org .tron .common .overlay .message .Message ;
22+ import org .tron .common .overlay .server .Channel ;
2123import org .tron .common .overlay .server .ChannelManager ;
2224import org .tron .common .overlay .server .MessageQueue ;
2325import org .tron .common .overlay .server .SyncPool ;
2729import org .tron .core .capsule .BlockCapsule ;
2830import org .tron .core .config .DefaultConfig ;
2931import org .tron .core .config .args .Args ;
32+ import org .tron .core .db .ByteArrayWrapper ;
3033import org .tron .core .db .Manager ;
3134import org .tron .core .net .message .BlockMessage ;
3235import org .tron .core .net .message .MessageTypes ;
@@ -234,7 +237,6 @@ public void run() {
234237 }
235238 }
236239
237- private static int trys = 0 ;
238240 private void prepare () {
239241 try {
240242 ExecutorService advertiseLoopThread = ReflectUtils .getFieldValue (node , "broadPool" );
@@ -251,7 +253,13 @@ public void run() {
251253 peerClient .connect (node .getHost (), node .getPort (), node .getHexId ());
252254 }
253255 }).start ();
254- Thread .sleep (5000 );
256+ Thread .sleep (2000 );
257+ Map <ByteArrayWrapper , Channel > activePeers = ReflectUtils
258+ .getFieldValue (channelManager , "activePeers" );
259+ int tryTimes = 0 ;
260+ while (MapUtils .isEmpty (activePeers ) && ++tryTimes < 10 ) {
261+ Thread .sleep (1000 );
262+ }
255263 go = true ;
256264 } catch (Exception e ) {
257265 e .printStackTrace ();
0 commit comments