|
15 | 15 |
|
16 | 16 | package org.tron.gossip;
|
17 | 17 |
|
18 |
| -import java.util.concurrent.Semaphore; |
19 |
| -import java.util.concurrent.TimeUnit; |
20 | 18 | import org.junit.Assert;
|
21 | 19 | import org.junit.BeforeClass;
|
22 | 20 | import org.junit.Test;
|
23 |
| -import org.tron.gossip.example.StandNode; |
| 21 | +import org.tron.gossip.example.LocalNode; |
24 | 22 | import org.tron.overlay.message.Message;
|
25 | 23 | import org.tron.overlay.message.Type;
|
26 | 24 |
|
| 25 | +import java.util.concurrent.Semaphore; |
| 26 | +import java.util.concurrent.TimeUnit; |
| 27 | + |
27 | 28 | public class GossipTest {
|
28 |
| - private final static String CLUSTER = "mycluster"; |
29 |
| - private static StandNode standNode = null; |
30 |
| - private Semaphore lock = new Semaphore(0); |
31 |
| - private Object sharedData = null; |
| 29 | + private final static String CLUSTER = "mycluster"; |
| 30 | + private static LocalNode standNode = null; |
| 31 | + private Semaphore lock = new Semaphore(0); |
| 32 | + private Object sharedData = null; |
32 | 33 |
|
33 |
| - @BeforeClass |
34 |
| - public static void init() { |
35 |
| - standNode = new StandNode(CLUSTER, "udp://localhost:10000", "0"); |
36 |
| - } |
| 34 | + @BeforeClass |
| 35 | + public static void init() { |
| 36 | + standNode = new LocalNode(CLUSTER, "udp://localhost:10000", "0"); |
| 37 | + } |
37 | 38 |
|
38 |
| - @Test |
39 |
| - public void testGossipBroadcast() throws InterruptedException { |
40 |
| - standNode.getGossipManager().registerSharedDataSubscriber((key, oldValue, newValue) -> { |
41 |
| - if (key.equals("block")) { |
42 |
| - sharedData = newValue; |
43 |
| - } |
44 |
| - }); |
| 39 | + @Test |
| 40 | + public void testGossipBroadcast() throws InterruptedException { |
| 41 | + standNode.getGossipManager().registerSharedDataSubscriber((key, oldValue, newValue) -> { |
| 42 | + if (key.equals("block")) { |
| 43 | + sharedData = newValue; |
| 44 | + } |
| 45 | + }); |
45 | 46 |
|
46 |
| - Message message = new Message("test", Type.BLOCK); |
47 |
| - standNode.broadcast(message); |
48 |
| - lock.tryAcquire(10, TimeUnit.SECONDS); |
49 |
| - Assert.assertEquals("test", sharedData); |
50 |
| - } |
| 47 | + Message message = new Message("test", Type.BLOCK); |
| 48 | + standNode.broadcast(message); |
| 49 | + lock.tryAcquire(10, TimeUnit.SECONDS); |
| 50 | + Assert.assertEquals("test", sharedData); |
| 51 | + } |
51 | 52 | }
|
0 commit comments