Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

changed FCTest to use SHARED_LOOPBACK instead of Simulator

  • Loading branch information...
commit 6dac307ca026abe1cf569c836627c7b6320bf0a6 1 parent b8b6c07
Bela Ban authored
65  tests/junit-functional/org/jgroups/tests/FCTest.java
@@ -2,18 +2,15 @@
2 2
 package org.jgroups.tests;
3 3
 
4 4
 import org.jgroups.*;
5  
-import org.jgroups.debug.Simulator;
6  
-import org.jgroups.protocols.FC;
7  
-import org.jgroups.protocols.FRAG2;
8  
-import org.jgroups.stack.IpAddress;
9  
-import org.jgroups.stack.Protocol;
  5
+import org.jgroups.protocols.*;
  6
+import org.jgroups.protocols.pbcast.GMS;
  7
+import org.jgroups.protocols.pbcast.NAKACK;
  8
+import org.jgroups.protocols.pbcast.STABLE;
10 9
 import org.jgroups.util.Util;
11 10
 import org.testng.annotations.AfterMethod;
12 11
 import org.testng.annotations.BeforeMethod;
13 12
 import org.testng.annotations.Test;
14 13
 
15  
-import java.util.Vector;
16  
-
17 14
 
18 15
 /**
19 16
  * Tests the flow control (FC) protocol
@@ -21,7 +18,7 @@
21 18
  */
22 19
 @Test(groups=Global.FUNCTIONAL,sequential=true)
23 20
 public class FCTest {
24  
-    Simulator s=null;
  21
+    JChannel ch;
25 22
     static final int SIZE=1000; // bytes
26 23
     static final int NUM_MSGS=100000;
27 24
     static final int PRINT=NUM_MSGS / 10;
@@ -30,40 +27,30 @@
30 27
 
31 28
     @BeforeMethod
32 29
     void setUp() throws Exception {
33  
-        IpAddress a1=new IpAddress(1111);
34  
-        Vector<Address> members=new Vector<Address>();
35  
-        members.add(a1);
36  
-        View v=new View(a1, 1, members);
37  
-        s=new Simulator();
38  
-        s.setLocalAddress(a1);
39  
-        s.setView(v);
40  
-        s.addMember(a1);
41  
-        FC fc=new FC();
42  
-        fc.setMinCredits(1000);
43  
-        fc.setMaxCredits(10000);
44  
-        fc.setMaxBlockTime(1000);
45  
-        FRAG2 frag=new FRAG2();
46  
-        frag.setFragSize(8000);
47  
-        Protocol[] stack=new Protocol[]{frag, fc};
48  
-        s.setProtocolStack(stack);
49  
-        s.start();
  30
+        ch=Util.createChannel(new SHARED_LOOPBACK().setValue("thread_pool_rejection_policy", "run").setValue("loopback", true),
  31
+                              new PING(),
  32
+                              new NAKACK().setValue("use_mcast_xmit", false),
  33
+                              new UNICAST2(),
  34
+                              new STABLE().setValue("max_bytes", 50000),
  35
+                              new GMS().setValue("print_local_addr", false),
  36
+                              new FC().setValue("min_credits", 1000).setValue("max_credits", 10000).setValue("max_block_time", 1000),
  37
+                              new FRAG2());
  38
+        ch.connect("FCTest");
50 39
     }
51 40
 
52 41
     @AfterMethod
53 42
     void tearDown() throws Exception {
54  
-        s.stop();
  43
+        Util.close(ch);
55 44
     }
56 45
 
57 46
 
58  
-    @Test(groups=Global.FUNCTIONAL)
59  
-    public void testReceptionOfAllMessages() {
  47
+    public void testReceptionOfAllMessages() throws ChannelNotConnectedException, ChannelClosedException {
60 48
         int num_received=0;
61 49
         Receiver r=new Receiver();
62  
-        s.setReceiver(r);
  50
+        ch.setReceiver(r);
63 51
         for(int i=1; i <= NUM_MSGS; i++) {
64 52
             Message msg=new Message(null, null, createPayload(SIZE));
65  
-            Event evt=new Event(Event.MSG, msg);
66  
-            s.send(evt);
  53
+            ch.send(msg);
67 54
             if(i % PRINT == 0)
68 55
                 System.out.println("==> " + i);
69 56
         }
@@ -71,7 +58,7 @@ public void testReceptionOfAllMessages() {
71 58
         while(num_tries > 0) {
72 59
             Util.sleep(1000);
73 60
             num_received=r.getNumberOfReceivedMessages();
74  
-            System.out.println("-- num received=" + num_received + ", stats:\n" + s.dumpStats());
  61
+            System.out.println("-- num received=" + num_received);
75 62
             if(num_received >= NUM_MSGS)
76 63
                 break;
77 64
             num_tries--;
@@ -81,6 +68,8 @@ public void testReceptionOfAllMessages() {
81 68
 
82 69
 
83 70
 
  71
+
  72
+
84 73
     private static byte[] createPayload(int size) {
85 74
         byte[] retval=new byte[size];
86 75
         for(int i=0; i < size; i++)
@@ -89,15 +78,13 @@ public void testReceptionOfAllMessages() {
89 78
     }
90 79
 
91 80
 
92  
-    static class Receiver implements Simulator.Receiver {
  81
+    static class Receiver extends ReceiverAdapter {
93 82
         int num_mgs_received=0;
94 83
 
95  
-        public void receive(Event evt) {
96  
-            if(evt.getType() == Event.MSG) {
97  
-                num_mgs_received++;
98  
-                if(num_mgs_received % PRINT == 0)
99  
-                    System.out.println("<== " + num_mgs_received);
100  
-            }
  84
+        public void receive(Message msg) {
  85
+            num_mgs_received++;
  86
+            if(num_mgs_received % PRINT == 0)
  87
+                System.out.println("<== " + num_mgs_received);
101 88
         }
102 89
 
103 90
         public int getNumberOfReceivedMessages() {

0 notes on commit 6dac307

Please sign in to comment.
Something went wrong with that request. Please try again.