1 // 2 // Copyright (c) ZeroC, Inc. All rights reserved. 3 // 4 5 using Test; 6 using System; 7 using System.Reflection; 8 using System.Threading; 9 10 [assembly: CLSCompliant(true)] 11 12 [assembly: AssemblyTitle("IceTest")] 13 [assembly: AssemblyDescription("Ice test")] 14 [assembly: AssemblyCompany("ZeroC, Inc.")] 15 16 public class Client : Test.TestHelper 17 { 18 class CallbackReceiverI : Test.CallbackReceiverDisp_ 19 { 20 public override void callback(Ice.Current current)21 callback(Ice.Current current) 22 { 23 lock(this) 24 { 25 _received = true; 26 Monitor.PulseAll(this); 27 } 28 } 29 30 public void waitForCallback()31 waitForCallback() 32 { 33 lock(this) 34 { 35 while(!_received) 36 { 37 try 38 { 39 Monitor.Wait(this); 40 } 41 catch(ThreadInterruptedException) 42 { 43 continue; 44 } 45 } 46 _received = false; 47 } 48 } 49 50 bool _received = false; 51 } 52 53 class Application : Glacier2.Application 54 { Application()55 public Application() 56 { 57 _receiver = new CallbackReceiverI(); 58 } 59 60 public override Glacier2.SessionPrx createSession()61 createSession() 62 { 63 Glacier2.SessionPrx session = null; 64 try 65 { 66 session = Glacier2.SessionPrxHelper.uncheckedCast(router().createSession("userid", "abc123")); 67 } 68 catch(Glacier2.PermissionDeniedException ex) 69 { 70 Console.WriteLine("permission denied:\n" + ex.reason); 71 } 72 catch(Glacier2.CannotCreateSessionException ex) 73 { 74 Console.WriteLine("cannot create session:\n" + ex.reason); 75 } 76 return session; 77 } 78 runWithSession(string[] args)79 public override int runWithSession(string[] args) 80 { 81 test(router() != null); 82 test(categoryForClient() != ""); 83 test(objectAdapter() != null); 84 85 if(_restart == 0) 86 { 87 Console.Out.Write("testing Glacier2::Application restart... "); 88 Console.Out.Flush(); 89 } 90 Ice.ObjectPrx @base = communicator().stringToProxy("callback:" + 91 getTestEndpoint(communicator().getProperties(), 0)); 92 CallbackPrx callback = CallbackPrxHelper.uncheckedCast(@base); 93 if(++_restart < 5) 94 { 95 CallbackReceiverPrx receiver = CallbackReceiverPrxHelper.uncheckedCast(addWithUUID(_receiver)); 96 callback.initiateCallback(receiver); 97 _receiver.waitForCallback(); 98 restart(); 99 } 100 Console.Out.WriteLine("ok"); 101 102 Console.Out.Write("testing server shutdown... "); 103 Console.Out.Flush(); 104 callback.shutdown(); 105 Console.Out.WriteLine("ok"); 106 return 0; 107 } 108 sessionDestroyed()109 public override void sessionDestroyed() 110 { 111 _destroyed = true; 112 } 113 114 public int _restart = 0; 115 public bool _destroyed = false; 116 private CallbackReceiverI _receiver; 117 } 118 run(string[] args)119 public override void run(string[] args) 120 { 121 Application app = new Application(); 122 123 Ice.Properties properties = createTestProperties(ref args); 124 Ice.InitializationData initData = new Ice.InitializationData(); 125 initData.properties = properties.ice_clone_(); 126 initData.properties.setProperty("Ice.Warn.Connections", "0"); 127 initData.properties.setProperty("Ice.Default.Router", 128 "Glacier2/router:" + getTestEndpoint(initData.properties, 50)); 129 if(app.main(args, initData) != 0) 130 { 131 test(false); 132 } 133 134 using(var communicator = initialize(properties)) 135 { 136 Console.Out.Write("testing stringToProxy for process object... "); 137 Console.Out.Flush(); 138 Ice.ObjectPrx processBase = communicator.stringToProxy("Glacier2/admin -f Process:" + getTestEndpoint(51)); 139 Console.Out.WriteLine("ok"); 140 141 Console.Out.Write("testing checked cast for admin object... "); 142 Console.Out.Flush(); 143 Ice.ProcessPrx process = Ice.ProcessPrxHelper.checkedCast(processBase); 144 test(process != null); 145 Console.Out.WriteLine("ok"); 146 147 Console.Out.Write("testing Glacier2 shutdown... "); 148 Console.Out.Flush(); 149 process.shutdown(); 150 try 151 { 152 process.ice_ping(); 153 test(false); 154 } 155 catch(Ice.LocalException) 156 { 157 Console.Out.WriteLine("ok"); 158 } 159 test(app._restart == 5); 160 test(app._destroyed); 161 } 162 } 163 Main(string[] args)164 public static int Main(string[] args) 165 { 166 return Test.TestDriver.runTest<Client>(args); 167 } 168 } 169