1 2 package org.jacorb.test.orb.policies; 3 4 import junit.framework.*; 5 6 import org.omg.CORBA.*; 7 import org.omg.Messaging.*; 8 9 import org.jacorb.test.*; 10 import org.jacorb.test.common.*; 11 12 18 public class SyncScopeTest extends ClientServerTestCase 19 { 20 private SyncScopeServer server; 21 22 public SyncScopeTest (String name, ClientServerSetup setup) 23 { 24 super (name, setup); 25 } 26 27 protected void setUp() throws Exception 28 { 29 server = SyncScopeServerHelper.narrow (setup.getServerObject()); 30 } 31 32 public static Test suite() 33 { 34 TestSuite suite = new TestSuite ("Sync Scope"); 35 ClientServerSetup setup = 36 new ClientServerSetup 37 (suite, 38 "org.jacorb.test.orb.policies.SyncScopeServerImpl"); 39 40 suite.addTest (new SyncScopeTest ("test_warm_up", setup)); 41 suite.addTest (new SyncScopeTest ("test_sync_none", setup)); 42 suite.addTest (new SyncScopeTest ("test_sync_with_transport", setup)); 43 suite.addTest (new SyncScopeTest ("test_sync_with_server", setup)); 44 suite.addTest (new SyncScopeTest ("test_sync_with_target", setup)); 45 46 return setup; 47 } 48 49 public void test_warm_up() 50 { 51 server.operation (50); 52 server.oneway_op (50); 53 } 54 55 public void test_sync_none() 56 { 57 setSyncScope (server, SYNC_NONE.value); 58 long start = System.currentTimeMillis(); 59 server.oneway_op (100); 60 long time = System.currentTimeMillis() - start; 61 assertTrue ("return too late", time < 100); 62 } 63 64 public void test_sync_with_transport() 65 { 66 setSyncScope (server, SYNC_WITH_TRANSPORT.value); 67 long start = System.currentTimeMillis(); 68 server.oneway_op (100); 69 long time = System.currentTimeMillis() - start; 70 assertTrue ("return too late", time < 100); 71 } 72 73 public void test_sync_with_server() 74 { 75 setSyncScope (server, SYNC_WITH_SERVER.value); 76 long start = System.currentTimeMillis(); 77 server.oneway_op (100); 78 long time = System.currentTimeMillis() - start; 79 assertTrue ("return too late", time < 100); 80 } 81 82 public void test_sync_with_target() 83 { 84 setSyncScope (server, SYNC_WITH_TARGET.value); 85 long start = System.currentTimeMillis(); 86 server.oneway_op (100); 87 long time = System.currentTimeMillis() - start; 88 assertTrue ("return too early", time > 100); 89 } 90 91 private void setSyncScope (SyncScopeServer server, short syncScope) 92 { 93 org.omg.CORBA.ORB orb = setup.getClientOrb(); 94 org.omg.CORBA.Any a = orb.create_any(); 95 a.insert_short (syncScope); 96 try 97 { 98 Policy p = 99 orb.create_policy(SYNC_SCOPE_POLICY_TYPE.value, a); 100 server._set_policy_override (new Policy[]{ p }, 101 SetOverrideType.ADD_OVERRIDE); 102 } 103 catch (PolicyError e) 104 { 105 throw new RuntimeException ("policy error: " + e); 106 } 107 108 } 109 110 } 111 | Popular Tags |