1 package org.jgroups.blocks; 2 3 import org.jgroups.tests.ChannelTestBase; 4 5 public class RpcDispatcherAnycastMultipleCallsTest extends ChannelTestBase 6 { 7 private RpcDispatcherAnycastServerObject[] targets = null; 8 9 protected void tearDown() throws Exception { 10 if(targets != null) { 11 for(int i=0; i < targets.length; i++) { 12 if(targets[i] != null) targets[i].shutdown(); 13 targets[i]=null; 14 } 15 targets=null; 16 } 17 super.tearDown(); 18 } 19 20 public void test2InstancesAnycastIncludeSelf() throws Exception 21 { 22 performTest(true, 2, false); 23 } 24 25 public void test3InstancesAnycastIncludeSelf() throws Exception 26 { 27 performTest(true, 3, false); 28 } 29 30 public void test2InstancesMcastIncludeSelf() throws Exception 31 { 32 performTest(false, 2, false); 33 } 34 35 public void test3InstancesMcastIncludeSelf() throws Exception 36 { 37 performTest(false, 3, false); 38 } 39 40 public void test2InstancesAnycastExcludeSelf() throws Exception 41 { 42 performTest(true, 2, true); 43 } 44 45 public void test3InstancesAnycastExcludeSelf() throws Exception 46 { 47 performTest(true, 3, true); 48 } 49 50 public void test2InstancesMcastExcludeSelf() throws Exception 51 { 52 performTest(false, 2, true); 53 } 54 55 public void test3InstancesMcastExcludeSelf() throws Exception 56 { 57 performTest(false, 3, true); 58 } 59 60 61 72 private void performTest(boolean useAnycast, int n, boolean excludeSelf) throws Exception 73 { 74 targets = new RpcDispatcherAnycastServerObject[n]; 76 for (int i=0; i<n; i++){ 77 targets[i] = new RpcDispatcherAnycastServerObject(createChannel("A")); 78 } 79 80 for (int i=0; i<n; i++) assertEquals(0, targets[i].i); 82 83 int value = 0; 85 86 int[] expectedValues = null; 88 89 if (excludeSelf) 90 { 91 expectedValues = new int[n]; 92 for (int i=0; i<n; i++) expectedValues[i] = 0; 93 } 94 95 for (int instances = 0; instances < n; instances++) 96 { 97 targets[instances].callRemote(useAnycast, excludeSelf); 98 99 101 if (excludeSelf) 102 { 103 for (int i=0; i<n; i++) 104 { 105 if (i != instances) expectedValues[i]++; 106 } 107 for (int i=0; i<n; i++) assertEquals("Failure when invoking call on instance " + instances + ". Did not reach instance " + i + ".", expectedValues[i], targets[i].i); 108 } 109 else 110 { 111 value++; 112 for (int i=0; i<n; i++) assertEquals("Failure when invoking call on instance " + instances + ". Did not reach instance " + i + ".", value, targets[i].i); 113 } 114 } 115 116 } 117 } 118 | Popular Tags |