1 package org.jacorb.test.orb.connection; 2 3 import java.util.Properties ; 4 5 import junit.framework.*; 6 7 import org.jacorb.test.*; 8 import org.jacorb.test.common.*; 9 10 14 public class BiDirTest extends ClientServerTestCase 15 { 16 private BiDirServer server = null; 17 private org.omg.PortableServer.POA biDirPOA = null; 18 19 private Object callbackLock = new Object (); 20 private boolean callbackReceived = false; 21 private String callbackMessage = null; 22 23 public BiDirTest (String name, ClientServerSetup setup) 24 { 25 super (name, setup); 26 } 27 28 public void setUp() throws Exception 29 { 30 server = BiDirServerHelper.narrow (setup.getServerObject()); 31 biDirPOA = ((BiDirSetup)setup).getBiDirPOA(); 32 } 33 34 private class ClientCallbackImpl extends ClientCallbackPOA 35 { 36 public void hello (String message) 37 { 38 synchronized (callbackLock) 39 { 40 callbackReceived = true; 41 callbackMessage = message; 42 callbackLock.notifyAll(); 43 } 44 } 45 } 46 47 private String waitForCallback (int timeout) 48 { 49 synchronized (callbackLock) 50 { 51 if (callbackReceived) 52 return callbackMessage; 53 else 54 { 55 try 56 { 57 callbackLock.wait (timeout); 58 } 59 catch (InterruptedException ex) 60 { 61 } 63 if (callbackReceived) 64 return callbackMessage; 65 else 66 throw new org.omg.CORBA.TIMEOUT 67 ("no callback received within timeout"); 68 } 69 } 70 } 71 72 public static Test suite() 73 { 74 TestSuite suite = new TestSuite ("Bidirectional GIOP Test"); 75 76 Properties properties = new Properties (); 77 properties.setProperty 78 ("org.omg.PortableInterceptor.ORBInitializerClass.bidir_init", 79 "org.jacorb.orb.giop.BiDirConnectionInitializer" ); 80 81 BiDirSetup setup = new BiDirSetup (suite, properties, properties); 82 83 suite.addTest (new BiDirTest ("test_callback", setup)); 84 85 return setup; 86 } 87 88 89 public void test_callback() 90 { 91 ClientCallback c = null; 92 try 93 { 94 c = ClientCallbackHelper.narrow ( 95 biDirPOA.servant_to_reference 96 (new ClientCallbackImpl())); 97 } 98 catch (Exception e) 99 { 100 fail ("exception creating callback object: " + e); 101 } 102 103 server.register_callback (c); 104 server.callback_hello ("This is a test"); 105 String result = waitForCallback (1000); 106 int n = server.get_open_client_transports(); 107 108 assertEquals ("This is a test", result); 109 110 assertEquals ("Server has too many client transports", 0, n); 113 } 114 115 } 116 | Popular Tags |