public ThrowType Throw() { System.Random r = new System.Random(); ThrowType type = (ThrowType)r.Next(4); return(type); }
public ThrowType SaveThrowType(ThrowType model) { model.ValidateModel(); ThrowType result = null; using (var db = new CFLSuiteDB()) { var dup = db.ThrowTypes.FirstOrDefault(x => x.Description == model.Description && x.ThrowTypeID != model.ThrowTypeID); if (dup == null) { if (model.ThrowTypeID > 0) { db.ThrowTypes.Attach(model); db.Entry(model).State = EntityState.Modified; } else { db.ThrowTypes.Add(model); } } else { throw new Exception("This throw already exists"); } db.SaveChanges(); result = model; } return(result); }
public object Any(ThrowType request) { switch (request.Type ?? "Exception") { case "Exception": throw new Exception(request.Message ?? "Server Error"); case "NotFound": throw HttpError.NotFound(request.Message ?? "What you're looking for isn't here"); case "Unauthorized": throw HttpError.Unauthorized(request.Message ?? "You shall not pass!"); case "Conflict": throw HttpError.Conflict(request.Message ?? "We haz Conflict!"); case "NotImplementedException": throw new NotImplementedException(request.Message ?? "Not implemented yet, try again later"); case "ArgumentException": throw new ArgumentException(request.Message ?? "Client Argument Error"); case "AuthenticationException": throw new AuthenticationException(request.Message ?? "We haz issue Authenticatting"); case "UnauthorizedAccessException": throw new UnauthorizedAccessException(request.Message ?? "You shall not pass!"); case "OptimisticConcurrencyException": throw new OptimisticConcurrencyException(request.Message ?? "Sorry too optimistic"); case "UnhandledException": throw new FileNotFoundException(request.Message ?? "File was never here"); case "RawResponse": Response.StatusCode = 418; Response.StatusDescription = request.Message ?? "On a tea break"; Response.EndRequest(); break; } return request; }
void makeThrow(ThrowDistance throwDistance, ThrowCurve throwCurve, ThrowType throwType) { //Debug.Log("Throwing at distance " + throwDistance + ", curve " + throwCurve + ", and type " + throwType); heldDiscTransform.localPosition = initialDiscPosition; // Reset the held disc position playerState = PlayerState.FREE; discController.CmdMakeThrow(throwDistance, throwCurve, throwType); playerNetworkController.ReleaseDiscAuthority(); // Hand auth over disc back to server cameraController.toggleFirstPersonCamera(); }
/// <summary> /// Toggle the object throw type between "meat" and "none" /// </summary> public void ToggleThrowTypeMeat() { if (throwType == ThrowType.MEAT) { throwType = ThrowType.NONE; } else { throwType = ThrowType.MEAT; SetAssistantText("That's a good chunk of meat! A carnivorous animal would love it!"); } SetThrowIndicators(); }
/// <summary> /// Toggle the object throw type between "broccoli" and "none" /// </summary> public void ToggleThrowTypeBroccoli() { if (throwType == ThrowType.BROCCOLI) { throwType = ThrowType.NONE; } else { throwType = ThrowType.BROCCOLI; SetAssistantText("That's a fresh veggie! An herbivorous animal would love that!"); } SetThrowIndicators(); }
public ActionResult SaveThrowType([DataSourceRequest] DataSourceRequest req, ThrowType model) { ThrowType result = null; try { result = new SetupService().SaveThrowType(model); } catch (Exception e) { ModelState.AddModelError("Error", e.Message); } return(Json(new[] { result }.ToDataSourceResult(req, ModelState))); }
public Throw(Player player, Domain.Game game, int sector, ThrowType type, ThrowResult result, int number, int points, PointF poi, int projectionResolution, int id = -1) { Id = id; Player = player; Game = game; Sector = sector; Type = type; Result = result; Number = number; Points = points; Poi = poi; ProjectionResolution = projectionResolution; TimeStamp = DateTime.Now; }
public DetectedThrow(PointF poi, Ray firstRay, Ray secondRay, int sector, ThrowType type, int projectionSide) { FirstRay = firstRay; SecondRay = secondRay; ProjectionResolution = projectionSide; Poi = poi; Sector = sector; Type = type; switch (type) { case ThrowType.Zero: Multiplier = 0; TotalPoints = 0; break; case ThrowType.Single: Multiplier = 1; TotalPoints = sector * Multiplier; break; case ThrowType.Double: Multiplier = 2; TotalPoints = sector * Multiplier; break; case ThrowType.Tremble: Multiplier = 3; TotalPoints = sector * Multiplier; break; case ThrowType._25: Multiplier = 2; TotalPoints = 25; break; case ThrowType.Bull: Multiplier = 3; TotalPoints = 50; break; default: throw new Exception("Unknown ThrowType"); } }
public object Any(ThrowType request) { switch (request.Type ?? "Exception") { case "Exception": throw new Exception(request.Message ?? "Server Error"); case "NotFound": throw HttpError.NotFound(request.Message ?? "What you're looking for isn't here"); case "Unauthorized": throw HttpError.Unauthorized(request.Message ?? "You shall not pass!"); case "Conflict": throw HttpError.Conflict(request.Message ?? "We haz Conflict!"); case "NotImplementedException": throw new NotImplementedException(request.Message ?? "Not implemented yet, try again later"); case "ArgumentException": throw new ArgumentException(request.Message ?? "Client Argument Error"); case "AuthenticationException": throw new AuthenticationException(request.Message ?? "We haz issue Authenticatting"); case "UnauthorizedAccessException": throw new UnauthorizedAccessException(request.Message ?? "You shall not pass!"); case "OptimisticConcurrencyExceptieon": throw new OptimisticConcurrencyException(request.Message ?? "Sorry too optimistic"); case "UnhandledException": throw new FileNotFoundException(request.Message ?? "File was never here"); case "RawResponse": Response.StatusCode = 418; Response.StatusDescription = request.Message ?? "On a tea break"; Response.Close(); break; } return(request); }
public void CmdMakeThrow(ThrowDistance throwDistance, ThrowCurve throwCurve, ThrowType throwType) { // Get indices for arrays from type of throw curveIndex = (int)throwCurve; int durationIndex = (int)throwDistance, heightIndex = (int)throwDistance, distanceIndex = (int)throwDistance; // Add forces useDiscBody(true); discBody.AddForce(transform.forward * distanceValues[distanceIndex]); discBody.AddForce(Vector3.up * heightValues[heightIndex]); // Spin the disc and make it fly discState = DiscState.FLIGHT; discBody.AddTorque(transform.up * rotationTorque); // Start routine for moving sideways curveEndTime = Time.time + durationValues[durationIndex]; curveDirection = transform.right; StartCoroutine("CurveRoutine"); // Start routine for detecting collisions StartCoroutine("CollisionsOnRoutine"); }
public void Throw(ThrowType throwType, HandType handType) { BallController.Throw(throwType, handType); // Compose Trigger's name (direction + hand) String TriggerName = "throw"; TriggerName += (throwType == ThrowType.HighThrow) ? "Up" : (throwType == ThrowType.MidThrow) ? "Side" : (throwType == ThrowType.FloorBounce) ? "Down" : "INVALID"; // Note that Triggers L&R follow user's perspective, while Hands Viola's TriggerName += (handType == HandType.Left) ? "R" : (handType == HandType.Right) ? "L" : "INVALID"; // Trigger throwing Animation if (name != "Viola") { ViolaAnimator.SetTrigger(TriggerName); } //Debug.Log(throwType.ToString() + " | " + handType.ToString()); //return; //Hand hand = null; //if (handType == HandType.Left) // hand = leftHand; //else if (handType == HandType.Right) // hand = rightHand; //hand.Throw(throwType); }
public Thrower(ThrowType t) { _t = t; }
public Hitbox(int damage, int chipDamage, int hitstun, int blockstun, Vector2 pushback, Rectangle hitboxBounds, Vector2 positionOffset, CancelState cancelStrength, HitSpark attackStrength, AttackProperty attackProperty = AttackProperty.Hit, int pushbackDuration = 5, int hitStop = -1, bool ignorePushback = false, ThrowType throwType = ThrowType.none) { this.damage = damage; this.chipDamage = chipDamage; this.hitstun = hitstun; this.blockstun = blockstun; this.pushbackDuration = pushbackDuration; this.pushback = pushback; this.hitboxBounds = hitboxBounds; this.positionOffset = positionOffset; this.attackProperty = attackProperty; this.cancelStrength = cancelStrength; this.attackStrength = attackStrength; this.ignorePushback = ignorePushback; this.throwType = throwType; moveMasterID = MasterObjectContainer.GetMoveMasterID(); moveCurrentUseID = 0; if (hitStop == -1) { if (attackStrength == HitSpark.light) { this.hitStop = 5; } else if (attackStrength == HitSpark.medium) { this.hitStop = 7; } else if (attackStrength == HitSpark.heavy) { this.hitStop = 9; } else { this.hitStop = 11; } } else { this.hitStop = hitStop; } }
public static void allTests(Ice.Communicator communicator) { string sref = "test:default -p 12010"; Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj); sref = "testController:tcp -p 12011"; obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj); Console.Out.Write("testing begin/end invocation... "); Console.Out.Flush(); { Ice.AsyncResult result; Dictionary<string, string> ctx = new Dictionary<string, string>(); result = p.begin_ice_isA("::Test::TestIntf"); test(p.end_ice_isA(result)); result = p.begin_ice_isA("::Test::TestIntf", ctx); test(p.end_ice_isA(result)); result = p.begin_ice_ping(); p.end_ice_ping(result); result = p.begin_ice_ping(ctx); p.end_ice_ping(result); result = p.begin_ice_id(); test(p.end_ice_id(result).Equals("::Test::TestIntf")); result = p.begin_ice_id(ctx); test(p.end_ice_id(result).Equals("::Test::TestIntf")); result = p.begin_ice_ids(); test(p.end_ice_ids(result).Length == 2); result = p.begin_ice_ids(ctx); test(p.end_ice_ids(result).Length == 2); result = p.begin_op(); p.end_op(result); result = p.begin_op(ctx); p.end_op(result); result = p.begin_opWithResult(); test(p.end_opWithResult(result) == 15); result = p.begin_opWithResult(ctx); test(p.end_opWithResult(result) == 15); result = p.begin_opWithUE(); try { p.end_opWithUE(result); test(false); } catch(Test.TestIntfException) { } result = p.begin_opWithUE(ctx); try { p.end_opWithUE(result); test(false); } catch(Test.TestIntfException) { } } Console.Out.WriteLine("ok"); Console.Out.Write("testing async callback... "); Console.Out.Flush(); { AsyncCallback cb = new AsyncCallback(); Dictionary<string, string> ctx = new Dictionary<string, string>(); Cookie cookie = new Cookie(5); AsyncCallback cbWC = new AsyncCallback(cookie); p.begin_ice_isA("::Test::TestIntf", cb.isA, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", cbWC.isA, cookie); cbWC.check(); p.begin_ice_isA("::Test::TestIntf", ctx, cb.isA, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", ctx, cbWC.isA, cookie); cbWC.check(); p.begin_ice_ping(cb.ping, null); cb.check(); p.begin_ice_ping(cbWC.ping, cookie); cbWC.check(); p.begin_ice_ping(ctx, cb.ping, null); cb.check(); p.begin_ice_ping(ctx, cbWC.ping, cookie); cbWC.check(); p.begin_ice_id(cb.id, null); cb.check(); p.begin_ice_id(cbWC.id, cookie); cbWC.check(); p.begin_ice_id(ctx, cb.id, null); cb.check(); p.begin_ice_id(ctx, cbWC.id, cookie); cbWC.check(); p.begin_ice_ids(cb.ids, null); cb.check(); p.begin_ice_ids(cbWC.ids, cookie); cbWC.check(); p.begin_ice_ids(ctx, cb.ids, null); cb.check(); p.begin_ice_ids(ctx, cbWC.ids, cookie); cbWC.check(); p.begin_op(cb.op, null); cb.check(); p.begin_op(cbWC.op, cookie); cbWC.check(); p.begin_op(ctx, cb.op, null); cb.check(); p.begin_op(ctx, cbWC.op, cookie); cbWC.check(); p.begin_opWithResult(cb.opWithResult, null); cb.check(); p.begin_opWithResult(cbWC.opWithResult, cookie); cbWC.check(); p.begin_opWithResult(ctx, cb.opWithResult, null); cb.check(); p.begin_opWithResult(ctx, cbWC.opWithResult, cookie); cbWC.check(); p.begin_opWithUE(cb.opWithUE, null); cb.check(); p.begin_opWithUE(cbWC.opWithUE, cookie); cbWC.check(); p.begin_opWithUE(ctx, cb.opWithUE, null); cb.check(); p.begin_opWithUE(ctx, cbWC.opWithUE, cookie); cbWC.check(); } Console.Out.WriteLine("ok"); Console.Out.Write("testing response callback... "); Console.Out.Flush(); { ResponseCallback cb = new ResponseCallback(); Dictionary<string, string> ctx = new Dictionary<string, string>(); p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", ctx).whenCompleted(cb.isA, null); cb.check(); p.begin_ice_ping().whenCompleted(cb.ping, null); cb.check(); p.begin_ice_ping(ctx).whenCompleted(cb.ping, null); cb.check(); p.begin_ice_id().whenCompleted(cb.id, null); cb.check(); p.begin_ice_id(ctx).whenCompleted(cb.id, null); cb.check(); p.begin_ice_ids().whenCompleted(cb.ids, null); cb.check(); p.begin_ice_ids(ctx).whenCompleted(cb.ids, null); cb.check(); p.begin_op().whenCompleted(cb.op, null); cb.check(); p.begin_op(ctx).whenCompleted(cb.op, null); cb.check(); p.begin_opWithResult().whenCompleted(cb.opWithResult, null); cb.check(); p.begin_opWithResult(ctx).whenCompleted(cb.opWithResult, null); cb.check(); p.begin_opWithUE().whenCompleted(cb.op, cb.opWithUE); cb.check(); p.begin_opWithUE(ctx).whenCompleted(cb.op, cb.opWithUE); cb.check(); } Console.Out.WriteLine("ok"); Console.Out.Write("testing local exceptions... "); Console.Out.Flush(); { Test.TestIntfPrx indirect = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); Ice.AsyncResult r; r = indirect.begin_op(); try { indirect.end_op(r); test(false); } catch(Ice.NoEndpointException) { } try { r = ((Test.TestIntfPrx)p.ice_oneway()).begin_opWithResult(); test(false); } catch(System.ArgumentException) { } // // Check that CommunicatorDestroyedException is raised directly. // Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); Ice.Communicator ic = Ice.Util.initialize(initData); Ice.ObjectPrx o = ic.stringToProxy(p.ToString()); Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.checkedCast(o); ic.destroy(); try { p2.begin_op(); test(false); } catch(Ice.CommunicatorDestroyedException) { // Expected. } } Console.Out.WriteLine("ok"); Console.Out.Write("testing local exceptions with async callback... "); Console.Out.Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); AsyncCallback cb = new AsyncCallback(); Cookie cookie = new Cookie(5); AsyncCallback cbWC = new AsyncCallback(cookie); i.begin_ice_isA("::Test::TestIntf", cb.isAEx, null); cb.check(); i.begin_ice_isA("::Test::TestIntf", cbWC.isAEx, cookie); cbWC.check(); i.begin_ice_ping(cb.pingEx, null); cb.check(); i.begin_ice_ping(cbWC.pingEx, cookie); cbWC.check(); i.begin_ice_id(cb.idEx, null); cb.check(); i.begin_ice_id(cbWC.idEx, cookie); cbWC.check(); i.begin_ice_ids(cb.idsEx, null); cb.check(); i.begin_ice_ids(cbWC.idsEx, cookie); cbWC.check(); i.begin_op(cb.opEx, null); cb.check(); i.begin_op(cbWC.opEx, cookie); cbWC.check(); } Console.Out.WriteLine("ok"); Console.Out.Write("testing local exceptions with response callback... "); Console.Out.Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ExceptionCallback cb = new ExceptionCallback(); i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, cb.ex); cb.check(); i.begin_ice_ping().whenCompleted(cb.ping, cb.ex); cb.check(); i.begin_ice_id().whenCompleted(cb.id, cb.ex); cb.check(); i.begin_ice_ids().whenCompleted(cb.ids, cb.ex); cb.check(); i.begin_op().whenCompleted(cb.op, cb.ex); cb.check(); } Console.Out.WriteLine("ok"); Console.Out.Write("testing exception callback... "); Console.Out.Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ExceptionCallback cb = new ExceptionCallback(); i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.ex); cb.check(); i.begin_op().whenCompleted(cb.ex); cb.check(); i.begin_opWithResult().whenCompleted(cb.ex); cb.check(); i.begin_opWithUE().whenCompleted(cb.ex); cb.check(); // Ensures no exception is called when response is received p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.noEx); p.begin_op().whenCompleted(cb.noEx); p.begin_opWithResult().whenCompleted(cb.noEx); // If response is a user exception, it should be received. p.begin_opWithUE().whenCompleted(cb.opWithUE); cb.check(); } Console.Out.WriteLine("ok"); Console.Out.Write("testing sent callback... "); Console.Out.Flush(); { SentCallback cb = new SentCallback(); p.begin_ice_isA("").whenCompleted(cb.isA, cb.ex).whenSent(cb.sent); cb.check(); p.begin_ice_ping().whenCompleted(cb.ping, cb.ex).whenSent(cb.sent); cb.check(); p.begin_ice_id().whenCompleted(cb.id, cb.ex).whenSent(cb.sent); cb.check(); p.begin_ice_ids().whenCompleted(cb.ids, cb.ex).whenSent(cb.sent); cb.check(); p.begin_op().whenCompleted(cb.op, cb.ex).whenSent(cb.sent); cb.check(); p.begin_op(cb.opAsync, null).whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); p.begin_op().whenCompleted(cb.ex).whenSent(cb.sent); cb.check(); List<SentCallback> cbs = new List<SentCallback>(); byte[] seq = new byte[10024]; (new System.Random()).NextBytes(seq); testController.holdAdapter(); try { Ice.AsyncResult r; do { SentCallback cb2 = new SentCallback(); r = p.begin_opWithPayload(seq).whenCompleted(cb2.ex).whenSent(cb2.sent); cbs.Add(cb2); } while(r.sentSynchronously()); } finally { testController.resumeAdapter(); } foreach(SentCallback cb3 in cbs) { cb3.check(); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing illegal arguments... "); Console.Out.Flush(); { Ice.AsyncResult result; result = p.begin_op(); p.end_op(result); try { p.end_op(result); test(false); } catch(System.ArgumentException) { } result = p.begin_op(); try { p.end_opWithResult(result); test(false); } catch(System.ArgumentException) { } try { p.end_op(null); test(false); } catch(System.ArgumentException) { } } Console.Out.WriteLine("ok"); Console.Out.Write("testing unexpected exceptions from callback... "); Console.Out.Flush(); { Test.TestIntfPrx q = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ThrowType[] throwEx = new ThrowType[]{ ThrowType.LocalException, ThrowType.UserException, ThrowType.OtherException }; for(int i = 0; i < 3; ++i) { Thrower cb = new Thrower(throwEx[i]); p.begin_op(cb.opAsync, null); cb.check(); p.begin_op().whenCompleted(cb.op, null); cb.check(); q.begin_op().whenCompleted(cb.op, cb.ex); cb.check(); p.begin_op().whenCompleted(cb.noOp, cb.ex).whenSent(cb.sent); cb.check(); q.begin_op().whenCompleted(cb.ex); cb.check(); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing batch requests with proxy... "); Console.Out.Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(cookie); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing batch requests with connection... "); Console.Out.Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(cookie); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing batch requests with communicator... "); Console.Out.Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // AsyncResult - 2 connections. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b1.opBatch(); b2.opBatch(); b2.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(4)); } { // // AsyncResult exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.waitForBatch(1)); } { // // AsyncResult exception - 2 connections - 2 failures. // // The sent callback should be invoked even if all connections fail. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); b2.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // 2 connections. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b1.opBatch(); b2.opBatch(); b2.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(4)); } { // // Exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.waitForBatch(1)); } { // // Exception - 2 connections - 2 failures. // // The sent callback should be invoked even if all connections fail. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); b2.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } } Console.Out.WriteLine("ok"); Console.Out.Write("testing AsyncResult operations... "); Console.Out.Flush(); { testController.holdAdapter(); Ice.AsyncResult r1; Ice.AsyncResult r2; try { r1 = p.begin_op(); byte[] seq = new byte[10024]; (new System.Random()).NextBytes(seq); while((r2 = p.begin_opWithPayload(seq)).sentSynchronously()); test(r1.sentSynchronously() && r1.isSent() && !r1.isCompleted_() || !r1.sentSynchronously() && !r1.isCompleted_()); test(!r2.sentSynchronously() && !r2.isCompleted_()); test(!r1.IsCompleted && !r1.CompletedSynchronously); test(!r2.IsCompleted && !r2.CompletedSynchronously); } finally { testController.resumeAdapter(); } WaitHandle w1 = r1.AsyncWaitHandle; WaitHandle w2 = r2.AsyncWaitHandle; r1.waitForSent(); test(r1.isSent()); r2.waitForSent(); test(r2.isSent()); r1.waitForCompleted(); test(r1.isCompleted_()); w1.WaitOne(); r2.waitForCompleted(); test(r2.isCompleted_()); w2.WaitOne(); test(r1.getOperation().Equals("op")); test(r2.getOperation().Equals("opWithPayload")); } Console.Out.WriteLine("ok"); p.shutdown(); }
public DiceThrowAttribute(ThrowType diceThrowType) { DiceThrowType = diceThrowType; }
public static void allTests(Ice.Communicator communicator) #endif { string sref = "test:default -p 12010"; Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj); sref = "testController:tcp -p 12011"; obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj); Write("testing begin/end invocation... "); Flush(); { Ice.AsyncResult result; Dictionary <string, string> ctx = new Dictionary <string, string>(); result = p.begin_ice_isA("::Test::TestIntf"); test(p.end_ice_isA(result)); result = p.begin_ice_isA("::Test::TestIntf", ctx); test(p.end_ice_isA(result)); result = p.begin_ice_ping(); p.end_ice_ping(result); result = p.begin_ice_ping(ctx); p.end_ice_ping(result); result = p.begin_ice_id(); test(p.end_ice_id(result).Equals("::Test::TestIntf")); result = p.begin_ice_id(ctx); test(p.end_ice_id(result).Equals("::Test::TestIntf")); result = p.begin_ice_ids(); test(p.end_ice_ids(result).Length == 2); result = p.begin_ice_ids(ctx); test(p.end_ice_ids(result).Length == 2); result = p.begin_op(); p.end_op(result); result = p.begin_op(ctx); p.end_op(result); result = p.begin_opWithResult(); test(p.end_opWithResult(result) == 15); result = p.begin_opWithResult(ctx); test(p.end_opWithResult(result) == 15); result = p.begin_opWithUE(); try { p.end_opWithUE(result); test(false); } catch (Test.TestIntfException) { } result = p.begin_opWithUE(ctx); try { p.end_opWithUE(result); test(false); } catch (Test.TestIntfException) { } } WriteLine("ok"); Write("testing async callback... "); Flush(); { AsyncCallback cb = new AsyncCallback(); Dictionary <string, string> ctx = new Dictionary <string, string>(); Cookie cookie = new Cookie(5); AsyncCallback cbWC = new AsyncCallback(cookie); p.begin_ice_isA("::Test::TestIntf", cb.isA, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", cbWC.isA, cookie); cbWC.check(); p.begin_ice_isA("::Test::TestIntf", ctx, cb.isA, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", ctx, cbWC.isA, cookie); cbWC.check(); p.begin_ice_ping(cb.ping, null); cb.check(); p.begin_ice_ping(cbWC.ping, cookie); cbWC.check(); p.begin_ice_ping(ctx, cb.ping, null); cb.check(); p.begin_ice_ping(ctx, cbWC.ping, cookie); cbWC.check(); p.begin_ice_id(cb.id, null); cb.check(); p.begin_ice_id(cbWC.id, cookie); cbWC.check(); p.begin_ice_id(ctx, cb.id, null); cb.check(); p.begin_ice_id(ctx, cbWC.id, cookie); cbWC.check(); p.begin_ice_ids(cb.ids, null); cb.check(); p.begin_ice_ids(cbWC.ids, cookie); cbWC.check(); p.begin_ice_ids(ctx, cb.ids, null); cb.check(); p.begin_ice_ids(ctx, cbWC.ids, cookie); cbWC.check(); p.begin_op(cb.op, null); cb.check(); p.begin_op(cbWC.op, cookie); cbWC.check(); p.begin_op(ctx, cb.op, null); cb.check(); p.begin_op(ctx, cbWC.op, cookie); cbWC.check(); p.begin_opWithResult(cb.opWithResult, null); cb.check(); p.begin_opWithResult(cbWC.opWithResult, cookie); cbWC.check(); p.begin_opWithResult(ctx, cb.opWithResult, null); cb.check(); p.begin_opWithResult(ctx, cbWC.opWithResult, cookie); cbWC.check(); p.begin_opWithUE(cb.opWithUE, null); cb.check(); p.begin_opWithUE(cbWC.opWithUE, cookie); cbWC.check(); p.begin_opWithUE(ctx, cb.opWithUE, null); cb.check(); p.begin_opWithUE(ctx, cbWC.opWithUE, cookie); cbWC.check(); } WriteLine("ok"); Write("testing response callback... "); Flush(); { ResponseCallback cb = new ResponseCallback(); Dictionary <string, string> ctx = new Dictionary <string, string>(); p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", ctx).whenCompleted(cb.isA, null); cb.check(); p.begin_ice_ping().whenCompleted(cb.ping, null); cb.check(); p.begin_ice_ping(ctx).whenCompleted(cb.ping, null); cb.check(); p.begin_ice_id().whenCompleted(cb.id, null); cb.check(); p.begin_ice_id(ctx).whenCompleted(cb.id, null); cb.check(); p.begin_ice_ids().whenCompleted(cb.ids, null); cb.check(); p.begin_ice_ids(ctx).whenCompleted(cb.ids, null); cb.check(); p.begin_op().whenCompleted(cb.op, null); cb.check(); p.begin_op(ctx).whenCompleted(cb.op, null); cb.check(); p.begin_opWithResult().whenCompleted(cb.opWithResult, null); cb.check(); p.begin_opWithResult(ctx).whenCompleted(cb.opWithResult, null); cb.check(); p.begin_opWithUE().whenCompleted(cb.op, cb.opWithUE); cb.check(); p.begin_opWithUE(ctx).whenCompleted(cb.op, cb.opWithUE); cb.check(); } WriteLine("ok"); Write("testing local exceptions... "); Flush(); { Test.TestIntfPrx indirect = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); Ice.AsyncResult r; r = indirect.begin_op(); try { indirect.end_op(r); test(false); } catch (Ice.NoEndpointException) { } try { r = ((Test.TestIntfPrx)p.ice_oneway()).begin_opWithResult(); test(false); } catch (System.ArgumentException) { } // // Check that CommunicatorDestroyedException is raised directly. // Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); Ice.Communicator ic = Ice.Util.initialize(initData); Ice.ObjectPrx o = ic.stringToProxy(p.ToString()); Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.checkedCast(o); ic.destroy(); try { p2.begin_op(); test(false); } catch (Ice.CommunicatorDestroyedException) { // Expected. } } WriteLine("ok"); Write("testing local exceptions with async callback... "); Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); AsyncCallback cb = new AsyncCallback(); Cookie cookie = new Cookie(5); AsyncCallback cbWC = new AsyncCallback(cookie); i.begin_ice_isA("::Test::TestIntf", cb.isAEx, null); cb.check(); i.begin_ice_isA("::Test::TestIntf", cbWC.isAEx, cookie); cbWC.check(); i.begin_ice_ping(cb.pingEx, null); cb.check(); i.begin_ice_ping(cbWC.pingEx, cookie); cbWC.check(); i.begin_ice_id(cb.idEx, null); cb.check(); i.begin_ice_id(cbWC.idEx, cookie); cbWC.check(); i.begin_ice_ids(cb.idsEx, null); cb.check(); i.begin_ice_ids(cbWC.idsEx, cookie); cbWC.check(); i.begin_op(cb.opEx, null); cb.check(); i.begin_op(cbWC.opEx, cookie); cbWC.check(); } WriteLine("ok"); Write("testing local exceptions with response callback... "); Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ExceptionCallback cb = new ExceptionCallback(); i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, cb.ex); cb.check(); i.begin_ice_ping().whenCompleted(cb.ping, cb.ex); cb.check(); i.begin_ice_id().whenCompleted(cb.id, cb.ex); cb.check(); i.begin_ice_ids().whenCompleted(cb.ids, cb.ex); cb.check(); i.begin_op().whenCompleted(cb.op, cb.ex); cb.check(); } WriteLine("ok"); Write("testing exception callback... "); Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ExceptionCallback cb = new ExceptionCallback(); i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.ex); cb.check(); i.begin_op().whenCompleted(cb.ex); cb.check(); i.begin_opWithResult().whenCompleted(cb.ex); cb.check(); i.begin_opWithUE().whenCompleted(cb.ex); cb.check(); // Ensures no exception is called when response is received p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.noEx); p.begin_op().whenCompleted(cb.noEx); p.begin_opWithResult().whenCompleted(cb.noEx); // If response is a user exception, it should be received. p.begin_opWithUE().whenCompleted(cb.opWithUE); cb.check(); } WriteLine("ok"); Write("testing sent callback... "); Flush(); { SentCallback cb = new SentCallback(); p.begin_ice_isA("").whenCompleted(cb.isA, cb.ex).whenSent(cb.sent); cb.check(); p.begin_ice_ping().whenCompleted(cb.ping, cb.ex).whenSent(cb.sent); cb.check(); p.begin_ice_id().whenCompleted(cb.id, cb.ex).whenSent(cb.sent); cb.check(); p.begin_ice_ids().whenCompleted(cb.ids, cb.ex).whenSent(cb.sent); cb.check(); p.begin_op().whenCompleted(cb.op, cb.ex).whenSent(cb.sent); cb.check(); p.begin_op(cb.opAsync, null).whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); p.begin_op().whenCompleted(cb.ex).whenSent(cb.sent); cb.check(); List <SentCallback> cbs = new List <SentCallback>(); byte[] seq = new byte[10024]; (new System.Random()).NextBytes(seq); testController.holdAdapter(); try { Ice.AsyncResult r; do { SentCallback cb2 = new SentCallback(); r = p.begin_opWithPayload(seq).whenCompleted(cb2.ex).whenSent(cb2.sent); cbs.Add(cb2); }while(r.sentSynchronously()); } finally { testController.resumeAdapter(); } foreach (SentCallback cb3 in cbs) { cb3.check(); } } WriteLine("ok"); Write("testing illegal arguments... "); Flush(); { Ice.AsyncResult result; result = p.begin_op(); p.end_op(result); try { p.end_op(result); test(false); } catch (System.ArgumentException) { } result = p.begin_op(); try { p.end_opWithResult(result); test(false); } catch (System.ArgumentException) { } try { p.end_op(null); test(false); } catch (System.ArgumentException) { } } WriteLine("ok"); Write("testing unexpected exceptions from callback... "); Flush(); { Test.TestIntfPrx q = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ThrowType[] throwEx = new ThrowType[] { ThrowType.LocalException, ThrowType.UserException, ThrowType.OtherException }; for (int i = 0; i < 3; ++i) { Thrower cb = new Thrower(throwEx[i]); p.begin_op(cb.opAsync, null); cb.check(); p.begin_op().whenCompleted(cb.op, null); cb.check(); q.begin_op().whenCompleted(cb.op, cb.ex); cb.check(); p.begin_op().whenCompleted(cb.noOp, cb.ex).whenSent(cb.sent); cb.check(); q.begin_op().whenCompleted(cb.ex); cb.check(); } } WriteLine("ok"); Write("testing batch requests with proxy... "); Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(cookie); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } } WriteLine("ok"); Write("testing batch requests with connection... "); Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(cookie); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } } WriteLine("ok"); Write("testing batch requests with communicator... "); Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // AsyncResult - 2 connections. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b1.opBatch(); b2.opBatch(); b2.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(4)); } { // // AsyncResult exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.waitForBatch(1)); } { // // AsyncResult exception - 2 connections - 2 failures. // // The sent callback should be invoked even if all connections fail. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); b2.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent((Ice.AsyncCallback)cb.sentAsync); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // 2 connections. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b1.opBatch(); b2.opBatch(); b2.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(4)); } { // // Exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.waitForBatch(1)); } { // // Exception - 2 connections - 2 failures. // // The sent callback should be invoked even if all connections fail. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); b2.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent((Ice.SentCallback)cb.sent); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } } WriteLine("ok"); Write("testing AsyncResult operations... "); Flush(); { { testController.holdAdapter(); Ice.AsyncResult r1; Ice.AsyncResult r2; try { r1 = p.begin_op(); byte[] seq = new byte[10024]; (new System.Random()).NextBytes(seq); while ((r2 = p.begin_opWithPayload(seq)).sentSynchronously()) { ; } test(r1.sentSynchronously() && r1.isSent() && !r1.isCompleted_() || !r1.sentSynchronously() && !r1.isCompleted_()); test(!r2.sentSynchronously() && !r2.isCompleted_()); test(!r1.IsCompleted && !r1.CompletedSynchronously); test(!r2.IsCompleted && !r2.CompletedSynchronously); } finally { testController.resumeAdapter(); } WaitHandle w1 = r1.AsyncWaitHandle; WaitHandle w2 = r2.AsyncWaitHandle; r1.waitForSent(); test(r1.isSent()); r2.waitForSent(); test(r2.isSent()); r1.waitForCompleted(); test(r1.isCompleted_()); w1.WaitOne(); r2.waitForCompleted(); test(r2.isCompleted_()); w2.WaitOne(); test(r1.getOperation().Equals("op")); test(r2.getOperation().Equals("opWithPayload")); } { Ice.AsyncResult r; // // Twoway // r = p.begin_ice_ping(); test(r.getOperation().Equals("ice_ping")); test(r.getConnection() == null); // Expected test(r.getCommunicator() == communicator); test(r.getProxy() == p); p.end_ice_ping(r); Test.TestIntfPrx p2; // // Oneway // p2 = p.ice_oneway() as Test.TestIntfPrx; r = p2.begin_ice_ping(); test(r.getOperation().Equals("ice_ping")); test(r.getConnection() == null); // Expected test(r.getCommunicator() == communicator); test(r.getProxy() == p2); // // Batch request via proxy // p2 = p.ice_batchOneway() as Test.TestIntfPrx; p2.ice_ping(); r = p2.begin_ice_flushBatchRequests(); test(r.getConnection() == null); // Expected test(r.getCommunicator() == communicator); test(r.getProxy() == p2); p2.end_ice_flushBatchRequests(r); // // Batch request via connection // Ice.Connection con = p.ice_getConnection(); p2 = p.ice_batchOneway() as Test.TestIntfPrx; p2.ice_ping(); r = con.begin_flushBatchRequests(); test(r.getConnection() == con); test(r.getCommunicator() == communicator); test(r.getProxy() == null); // Expected con.end_flushBatchRequests(r); // // Batch request via communicator // p2 = p.ice_batchOneway() as Test.TestIntfPrx; p2.ice_ping(); r = communicator.begin_flushBatchRequests(); test(r.getConnection() == null); // Expected test(r.getCommunicator() == communicator); test(r.getProxy() == null); // Expected communicator.end_flushBatchRequests(r); } } WriteLine("ok"); Write("testing close connection with sending queue... "); Flush(); { byte[] seq = new byte[1024 * 10]; (new System.Random()).NextBytes(seq); // Make sure the request doesn't compress too well. // // Send multiple opWithPayload, followed by a close and followed by multiple opWithPaylod. // The goal is to make sure that none of the opWithPayload fail even if the server closes // the connection gracefully in between. // int maxQueue = 2; bool done = false; while (!done && maxQueue < 50) { done = true; p.ice_ping(); List <Ice.AsyncResult> results = new List <Ice.AsyncResult>(); for (int i = 0; i < maxQueue; ++i) { results.Add(p.begin_opWithPayload(seq)); } if (!p.begin_close(false).isSent()) { for (int i = 0; i < maxQueue; i++) { Ice.AsyncResult r = p.begin_opWithPayload(seq); results.Add(r); if (r.isSent()) { done = false; maxQueue *= 2; break; } } } else { maxQueue *= 2; done = false; } foreach (Ice.AsyncResult q in results) { q.waitForCompleted(); try { q.throwLocalException(); } catch (Ice.LocalException) { test(false); } } } } WriteLine("ok"); p.shutdown(); }
public static void allTests(Ice.Communicator communicator, bool collocated) #endif { #if SILVERLIGHT bool collocated = false; #endif string sref = "test:default -p 12010"; Ice.ObjectPrx obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfPrx p = Test.TestIntfPrxHelper.uncheckedCast(obj); sref = "testController:default -p 12011"; obj = communicator.stringToProxy(sref); test(obj != null); Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj); Write("testing begin/end invocation... "); Flush(); { Ice.AsyncResult result; Dictionary<string, string> ctx = new Dictionary<string, string>(); result = p.begin_ice_isA("::Test::TestIntf"); test(p.end_ice_isA(result)); result = p.begin_ice_isA("::Test::TestIntf", ctx); test(p.end_ice_isA(result)); result = p.begin_ice_ping(); p.end_ice_ping(result); result = p.begin_ice_ping(ctx); p.end_ice_ping(result); result = p.begin_ice_id(); test(p.end_ice_id(result).Equals("::Test::TestIntf")); result = p.begin_ice_id(ctx); test(p.end_ice_id(result).Equals("::Test::TestIntf")); result = p.begin_ice_ids(); test(p.end_ice_ids(result).Length == 2); result = p.begin_ice_ids(ctx); test(p.end_ice_ids(result).Length == 2); if(!collocated) { result = p.begin_ice_getConnection(); test(p.end_ice_getConnection(result) != null); } result = p.begin_op(); p.end_op(result); result = p.begin_op(ctx); p.end_op(result); result = p.begin_opWithResult(); test(p.end_opWithResult(result) == 15); result = p.begin_opWithResult(ctx); test(p.end_opWithResult(result) == 15); result = p.begin_opWithUE(); try { p.end_opWithUE(result); test(false); } catch(Test.TestIntfException) { } result = p.begin_opWithUE(ctx); try { p.end_opWithUE(result); test(false); } catch(Test.TestIntfException) { } } WriteLine("ok"); Write("testing async callback... "); Flush(); { AsyncCallback cb = new AsyncCallback(); Dictionary<string, string> ctx = new Dictionary<string, string>(); Cookie cookie = new Cookie(5); AsyncCallback cbWC = new AsyncCallback(cookie); p.begin_ice_isA("::Test::TestIntf", cb.isA, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", cbWC.isA, cookie); cbWC.check(); p.begin_ice_isA("::Test::TestIntf", ctx, cb.isA, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", ctx, cbWC.isA, cookie); cbWC.check(); p.begin_ice_ping(cb.ping, null); cb.check(); p.begin_ice_ping(cbWC.ping, cookie); cbWC.check(); p.begin_ice_ping(ctx, cb.ping, null); cb.check(); p.begin_ice_ping(ctx, cbWC.ping, cookie); cbWC.check(); p.begin_ice_id(cb.id, null); cb.check(); p.begin_ice_id(cbWC.id, cookie); cbWC.check(); p.begin_ice_id(ctx, cb.id, null); cb.check(); p.begin_ice_id(ctx, cbWC.id, cookie); cbWC.check(); p.begin_ice_ids(cb.ids, null); cb.check(); p.begin_ice_ids(cbWC.ids, cookie); cbWC.check(); p.begin_ice_ids(ctx, cb.ids, null); cb.check(); p.begin_ice_ids(ctx, cbWC.ids, cookie); cbWC.check(); if(!collocated) { p.begin_ice_getConnection(cb.connection, null); cb.check(); p.begin_ice_getConnection(cbWC.connection, cookie); cbWC.check(); } p.begin_op(cb.op, null); cb.check(); p.begin_op(cbWC.op, cookie); cbWC.check(); p.begin_op(ctx, cb.op, null); cb.check(); p.begin_op(ctx, cbWC.op, cookie); cbWC.check(); p.begin_opWithResult(cb.opWithResult, null); cb.check(); p.begin_opWithResult(cbWC.opWithResult, cookie); cbWC.check(); p.begin_opWithResult(ctx, cb.opWithResult, null); cb.check(); p.begin_opWithResult(ctx, cbWC.opWithResult, cookie); cbWC.check(); p.begin_opWithUE(cb.opWithUE, null); cb.check(); p.begin_opWithUE(cbWC.opWithUE, cookie); cbWC.check(); p.begin_opWithUE(ctx, cb.opWithUE, null); cb.check(); p.begin_opWithUE(ctx, cbWC.opWithUE, cookie); cbWC.check(); } WriteLine("ok"); Write("testing response callback... "); Flush(); { ResponseCallback cb = new ResponseCallback(); Dictionary<string, string> ctx = new Dictionary<string, string>(); p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", ctx).whenCompleted(cb.isA, null); cb.check(); p.begin_ice_ping().whenCompleted(cb.ping, null); cb.check(); p.begin_ice_ping(ctx).whenCompleted(cb.ping, null); cb.check(); p.begin_ice_id().whenCompleted(cb.id, null); cb.check(); p.begin_ice_id(ctx).whenCompleted(cb.id, null); cb.check(); p.begin_ice_ids().whenCompleted(cb.ids, null); cb.check(); p.begin_ice_ids(ctx).whenCompleted(cb.ids, null); cb.check(); if(!collocated) { p.begin_ice_getConnection().whenCompleted(cb.connection, null); cb.check(); } p.begin_op().whenCompleted(cb.op, null); cb.check(); p.begin_op(ctx).whenCompleted(cb.op, null); cb.check(); p.begin_opWithResult().whenCompleted(cb.opWithResult, null); cb.check(); p.begin_opWithResult(ctx).whenCompleted(cb.opWithResult, null); cb.check(); p.begin_opWithUE().whenCompleted(cb.op, cb.opWithUE); cb.check(); p.begin_opWithUE(ctx).whenCompleted(cb.op, cb.opWithUE); cb.check(); } WriteLine("ok"); Write("testing lambda callback... "); Flush(); { ResponseCallback cb = new ResponseCallback(); Dictionary<string, string> ctx = new Dictionary<string, string>(); p.begin_ice_isA("::Test::TestIntf").whenCompleted( (bool r) => { cb.isA(r); }, null); cb.check(); p.begin_ice_isA("::Test::TestIntf", ctx).whenCompleted( (bool r) => { cb.isA(r); }, null); cb.check(); p.begin_ice_ping().whenCompleted( () => { cb.ping(); }, null); cb.check(); p.begin_ice_ping(ctx).whenCompleted( () => { cb.ping(); }, null); cb.check(); p.begin_ice_id().whenCompleted( (string id) => { cb.id(id); }, null); cb.check(); p.begin_ice_id(ctx).whenCompleted( (string id) => { cb.id(id); }, null); cb.check(); p.begin_ice_ids().whenCompleted( (string[] ids) => { cb.ids(ids); }, null); cb.check(); p.begin_ice_ids(ctx).whenCompleted( (string[] ids) => { cb.ids(ids); }, null); cb.check(); if(!collocated) { p.begin_ice_getConnection().whenCompleted( (Ice.Connection conn) => { cb.connection(conn); }, null); cb.check(); } p.begin_op().whenCompleted( () => { cb.op(); }, null); cb.check(); p.begin_op(ctx).whenCompleted( () => { cb.op(); }, null); cb.check(); p.begin_opWithResult().whenCompleted( (int r) => { cb.opWithResult(r); }, null); cb.check(); p.begin_opWithResult(ctx).whenCompleted( (int r) => { cb.opWithResult(r); }, null); cb.check(); p.begin_opWithUE().whenCompleted( () => { cb.op(); }, (Ice.Exception ex) => { cb.opWithUE(ex); }); cb.check(); p.begin_opWithUE(ctx).whenCompleted( () => { cb.op(); }, (Ice.Exception ex) => { cb.opWithUE(ex); }); cb.check(); } WriteLine("ok"); Write("testing local exceptions... "); Flush(); { Test.TestIntfPrx indirect = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); Ice.AsyncResult r; r = indirect.begin_op(); try { indirect.end_op(r); test(false); } catch(Ice.NoEndpointException) { } try { r = ((Test.TestIntfPrx)p.ice_oneway()).begin_opWithResult(); test(false); } catch(System.ArgumentException) { } // // Check that CommunicatorDestroyedException is raised directly. // if(p.ice_getConnection() != null) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); Ice.Communicator ic = Ice.Util.initialize(initData); Ice.ObjectPrx o = ic.stringToProxy(p.ToString()); Test.TestIntfPrx p2 = Test.TestIntfPrxHelper.checkedCast(o); ic.destroy(); try { p2.begin_op(); test(false); } catch(Ice.CommunicatorDestroyedException) { // Expected. } } } WriteLine("ok"); Write("testing local exceptions with async callback... "); Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); AsyncCallback cb = new AsyncCallback(); Cookie cookie = new Cookie(5); AsyncCallback cbWC = new AsyncCallback(cookie); i.begin_ice_isA("::Test::TestIntf", cb.isAEx, null); cb.check(); i.begin_ice_isA("::Test::TestIntf", cbWC.isAEx, cookie); cbWC.check(); i.begin_ice_ping(cb.pingEx, null); cb.check(); i.begin_ice_ping(cbWC.pingEx, cookie); cbWC.check(); i.begin_ice_id(cb.idEx, null); cb.check(); i.begin_ice_id(cbWC.idEx, cookie); cbWC.check(); i.begin_ice_ids(cb.idsEx, null); cb.check(); i.begin_ice_ids(cbWC.idsEx, cookie); cbWC.check(); if(!collocated) { i.begin_ice_getConnection(cb.connectionEx, null); cb.check(); i.begin_ice_getConnection(cbWC.connectionEx, cookie); cbWC.check(); } i.begin_op(cb.opEx, null); cb.check(); i.begin_op(cbWC.opEx, cookie); cbWC.check(); } WriteLine("ok"); Write("testing local exceptions with response callback... "); Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ExceptionCallback cb = new ExceptionCallback(); i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.isA, cb.ex); cb.check(); i.begin_ice_ping().whenCompleted(cb.ping, cb.ex); cb.check(); i.begin_ice_id().whenCompleted(cb.id, cb.ex); cb.check(); i.begin_ice_ids().whenCompleted(cb.ids, cb.ex); cb.check(); if(!collocated) { i.begin_ice_getConnection().whenCompleted(cb.connection, cb.ex); cb.check(); } i.begin_op().whenCompleted(cb.op, cb.ex); cb.check(); } WriteLine("ok"); Write("testing local exceptions with lambda callback... "); Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ExceptionCallback cb = new ExceptionCallback(); i.begin_ice_isA("::Test::TestIntf").whenCompleted( (bool r) => { cb.isA(r); }, (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); i.begin_ice_ping().whenCompleted( () => { cb.ping(); }, (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); i.begin_ice_id().whenCompleted( (string id) => { cb.id(id); }, (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); i.begin_ice_ids().whenCompleted( (string[] ids) => { cb.ids(ids); }, (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); if(!collocated) { i.begin_ice_getConnection().whenCompleted( (Ice.Connection conn) => { cb.connection(conn); }, (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); } i.begin_op().whenCompleted( () => { cb.op(); }, (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); } WriteLine("ok"); Write("testing exception callback... "); Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ExceptionCallback cb = new ExceptionCallback(); i.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.ex); cb.check(); i.begin_op().whenCompleted(cb.ex); cb.check(); i.begin_opWithResult().whenCompleted(cb.ex); cb.check(); i.begin_opWithUE().whenCompleted(cb.ex); cb.check(); // Ensures no exception is called when response is received p.begin_ice_isA("::Test::TestIntf").whenCompleted(cb.noEx); p.begin_op().whenCompleted(cb.noEx); p.begin_opWithResult().whenCompleted(cb.noEx); // If response is a user exception, it should be received. p.begin_opWithUE().whenCompleted(cb.opWithUE); cb.check(); } WriteLine("ok"); Write("testing lambda exception callback... "); Flush(); { Test.TestIntfPrx i = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ExceptionCallback cb = new ExceptionCallback(); i.begin_ice_isA("::Test::TestIntf").whenCompleted( (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); i.begin_op().whenCompleted( (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); i.begin_opWithResult().whenCompleted( (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); i.begin_opWithUE().whenCompleted( (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); // Ensures no exception is called when response is received p.begin_ice_isA("::Test::TestIntf").whenCompleted( (Ice.Exception ex) => { cb.noEx(ex); }); p.begin_op().whenCompleted( (Ice.Exception ex) => { cb.noEx(ex); }); p.begin_opWithResult().whenCompleted( (Ice.Exception ex) => { cb.noEx(ex); }); // If response is a user exception, it should be received. p.begin_opWithUE().whenCompleted( (Ice.Exception ex) => { cb.opWithUE(ex); }); cb.check(); } WriteLine("ok"); Write("testing sent callback... "); Flush(); { SentCallback cb = new SentCallback(); p.begin_ice_isA("").whenCompleted(cb.isA, cb.ex).whenSent(cb.sent); cb.check(); p.begin_ice_ping().whenCompleted(cb.ping, cb.ex).whenSent(cb.sent); cb.check(); p.begin_ice_id().whenCompleted(cb.id, cb.ex).whenSent(cb.sent); cb.check(); p.begin_ice_ids().whenCompleted(cb.ids, cb.ex).whenSent(cb.sent); cb.check(); p.begin_op().whenCompleted(cb.op, cb.ex).whenSent(cb.sent); cb.check(); p.begin_op(cb.opAsync, null).whenSent(cb.sentAsync); cb.check(); p.begin_op().whenCompleted(cb.ex).whenSent(cb.sent); cb.check(); List<SentCallback> cbs = new List<SentCallback>(); byte[] seq = new byte[10024]; (new System.Random()).NextBytes(seq); testController.holdAdapter(); try { Ice.AsyncResult r; do { SentCallback cb2 = new SentCallback(); r = p.begin_opWithPayload(seq).whenCompleted(cb2.ex).whenSent(cb2.sent); cbs.Add(cb2); } while(r.sentSynchronously()); } finally { testController.resumeAdapter(); } foreach(SentCallback cb3 in cbs) { cb3.check(); } } WriteLine("ok"); Write("testing lambda sent callback... "); Flush(); { SentCallback cb = new SentCallback(); p.begin_ice_isA("").whenCompleted( (bool r) => { cb.isA(r); }, (Ice.Exception ex) => { cb.ex(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); p.begin_ice_ping().whenCompleted( () => { cb.ping(); }, (Ice.Exception ex) => { cb.ex(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); p.begin_ice_id().whenCompleted( (string id) => { cb.id(id); }, (Ice.Exception ex) => { cb.ex(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); p.begin_ice_ids().whenCompleted( (string[] ids) => { cb.ids(ids); }, (Ice.Exception ex) => { cb.ex(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); p.begin_op().whenCompleted( () => { cb.op(); }, (Ice.Exception ex) => { cb.ex(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); p.begin_op(cb.opAsync, null).whenSent( (Ice.AsyncResult r) => { cb.sentAsync(r); }); cb.check(); p.begin_op().whenCompleted( (Ice.Exception ex) => { cb.ex(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); List<SentCallback> cbs = new List<SentCallback>(); byte[] seq = new byte[10024]; (new System.Random()).NextBytes(seq); testController.holdAdapter(); try { Ice.AsyncResult r; do { SentCallback cb2 = new SentCallback(); r = p.begin_opWithPayload(seq).whenCompleted( (Ice.Exception ex) => { cb2.ex(ex); } ).whenSent( (bool sentSynchronously) => { cb2.sent(sentSynchronously); }); cbs.Add(cb2); } while(r.sentSynchronously()); } finally { testController.resumeAdapter(); } foreach(SentCallback cb3 in cbs) { cb3.check(); } } WriteLine("ok"); Write("testing illegal arguments... "); Flush(); { Ice.AsyncResult result; result = p.begin_op(); p.end_op(result); try { p.end_op(result); test(false); } catch(System.ArgumentException) { } result = p.begin_op(); try { p.end_opWithResult(result); test(false); } catch(System.ArgumentException) { } try { p.end_op(null); test(false); } catch(System.ArgumentException) { } } WriteLine("ok"); Write("testing unexpected exceptions from callback... "); Flush(); { Test.TestIntfPrx q = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ThrowType[] throwEx = new ThrowType[]{ ThrowType.LocalException, ThrowType.UserException, ThrowType.OtherException }; for(int i = 0; i < 3; ++i) { Thrower cb = new Thrower(throwEx[i]); p.begin_op(cb.opAsync, null); cb.check(); p.begin_op().whenCompleted(cb.op, null); cb.check(); q.begin_op().whenCompleted(cb.op, cb.ex); cb.check(); p.begin_op().whenCompleted(cb.noOp, cb.ex).whenSent(cb.sent); cb.check(); q.begin_op().whenCompleted(cb.ex); cb.check(); } } WriteLine("ok"); Write("testing unexpected exceptions from callback with lambda... "); Flush(); { Test.TestIntfPrx q = Test.TestIntfPrxHelper.uncheckedCast(p.ice_adapterId("dummy")); ThrowType[] throwEx = new ThrowType[]{ ThrowType.LocalException, ThrowType.UserException, ThrowType.OtherException }; for(int i = 0; i < 3; ++i) { Thrower cb = new Thrower(throwEx[i]); p.begin_op().whenCompleted( () => { cb.op(); }, null); cb.check(); q.begin_op().whenCompleted( () => { cb.op(); }, (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); p.begin_op().whenCompleted( () => { cb.noOp(); }, (Ice.Exception ex) => { cb.ex(ex); } ).whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); q.begin_op().whenCompleted( (Ice.Exception ex) => { cb.ex(ex); }); cb.check(); } } WriteLine("ok"); Write("testing batch requests with proxy... "); Flush(); { test(p.ice_batchOneway().begin_ice_flushBatchRequests().sentSynchronously()); Cookie cookie = new Cookie(5); { // // AsyncResult. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie); r.whenSent(cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } if(p.ice_getConnection() != null) { // // AsyncResult exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(cookie); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(cb.completedAsync, cookie); r.whenSent(cb.sentAsync); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent(cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } if(p.ice_getConnection() != null) { // // Type-safe exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent(cb.sent); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } } WriteLine("ok"); Write("testing batch requests with proxy and lambda... "); Flush(); { test(p.ice_batchOneway().begin_ice_flushBatchRequests().sentSynchronously()); Cookie cookie = new Cookie(5); { // // AsyncResult. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests( (Ice.AsyncResult result) => { cb.completedAsync(result); }, cookie); r.whenSent( (Ice.AsyncResult result) => { cb.sentAsync(result); }); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); FlushCallback cb2 = new FlushCallback(cookie); Ice.AsyncResult r2 = b1.begin_ice_flushBatchRequests( (Ice.AsyncResult result) => { cb2.completedAsync(result); }, cookie); r2.whenSent( (Ice.AsyncResult result) => { cb2.sentAsync(result); }); cb2.check(); test(r2.isSent()); test(r2.IsCompleted); } if(p.ice_getConnection() != null) { // // AsyncResult exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(cookie); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests( (Ice.AsyncResult result) => { cb.completedAsync(result); }, cookie); r.whenSent( (Ice.AsyncResult result) => { cb.sentAsync(result); }); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); r.whenCompleted( (Ice.Exception ex) => { cb.exception(ex); }); r.whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } if(p.ice_getConnection() != null) { // // Type-safe exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(); Ice.AsyncResult r = b1.begin_ice_flushBatchRequests(); r.whenCompleted( (Ice.Exception ex) => { cb.exception(ex); }); r.whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } } WriteLine("ok"); if(p.ice_getConnection() != null) { Write("testing batch requests with connection... "); Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent(cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(cookie); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent(cb.sentAsync); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent(cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent(cb.sent); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } } WriteLine("ok"); } if(p.ice_getConnection() != null) { Write("testing batch requests with connection and lambda... "); Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests( (Ice.AsyncResult result) => { cb.completedAsync(result); }, cookie); r.whenSent( (Ice.AsyncResult result) => { cb.sentAsync(result); }); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(cookie); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests( (Ice.AsyncResult result) => { cb.completedAsync(result); }, cookie); r.whenSent( (Ice.AsyncResult result) => { cb.sentAsync(result); }); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(); r.whenCompleted( (Ice.Exception ex) => { cb.exception(ex); }); r.whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushExCallback cb = new FlushExCallback(); Ice.AsyncResult r = b1.ice_getConnection().begin_flushBatchRequests(); r.whenCompleted( (Ice.Exception ex) => { cb.exception(ex); }); r.whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); test(!r.isSent()); test(r.IsCompleted); test(p.opBatchCount() == 0); } } WriteLine("ok"); Write("testing batch requests with communicator... "); Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent(cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent(cb.sentAsync); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // AsyncResult - 2 connections. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b1.opBatch(); b2.opBatch(); b2.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent(cb.sentAsync); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(4)); } { // // AsyncResult exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent(cb.sentAsync); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.waitForBatch(1)); } { // // AsyncResult exception - 2 connections - 2 failures. // // The sent callback should be invoked even if all connections fail. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); b2.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests(cb.completedAsync, cookie); r.whenSent(cb.sentAsync); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent(cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent(cb.sent); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // 2 connections. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b1.opBatch(); b2.opBatch(); b2.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent(cb.sent); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(4)); } { // // Exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent(cb.sent); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.waitForBatch(1)); } { // // Exception - 2 connections - 2 failures. // // The sent callback should be invoked even if all connections fail. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); b2.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted(cb.exception); r.whenSent(cb.sent); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } } WriteLine("ok"); Write("testing batch requests with communicator with lambda... "); Flush(); { Cookie cookie = new Cookie(5); { // // AsyncResult - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests( (Ice.AsyncResult result) => { cb.completedAsync(result); }, cookie); r.whenSent( (Ice.AsyncResult result) => { cb.sentAsync(result); }); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // AsyncResult exception - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests( (Ice.AsyncResult result) => { cb.completedAsync(result); }, cookie); r.whenSent( (Ice.AsyncResult result) => { cb.sentAsync(result); }); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // AsyncResult - 2 connections. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b1.opBatch(); b2.opBatch(); b2.opBatch(); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests( (Ice.AsyncResult result) => { cb.completedAsync(result); }, cookie); r.whenSent( (Ice.AsyncResult result) => { cb.sentAsync(result); }); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(4)); } { // // AsyncResult exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests( (Ice.AsyncResult result) => { cb.completedAsync(result); }, cookie); r.whenSent( (Ice.AsyncResult result) => { cb.sentAsync(result); }); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.waitForBatch(1)); } { // // AsyncResult exception - 2 connections - 2 failures. // // The sent callback should be invoked even if all connections fail. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); b2.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(cookie); Ice.AsyncResult r = communicator.begin_flushBatchRequests( (Ice.AsyncResult result) => { cb.completedAsync(result); }, cookie); r.whenSent( (Ice.AsyncResult result) => { cb.sentAsync(result); }); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // Type-safe - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted( (Ice.Exception ex) => { cb.exception(ex); }); r.whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(2)); } { // // Type-safe exception - 1 connection. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); b1.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted( (Ice.Exception ex) => { cb.exception(ex); }); r.whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } { // // 2 connections. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b1.opBatch(); b2.opBatch(); b2.opBatch(); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted( (Ice.Exception ex) => { cb.exception(ex); }); r.whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); test(r.isSent()); test(r.IsCompleted); test(p.waitForBatch(4)); } { // // Exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted( (Ice.Exception ex) => { cb.exception(ex); }); r.whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.waitForBatch(1)); } { // // Exception - 2 connections - 2 failures. // // The sent callback should be invoked even if all connections fail. // test(p.opBatchCount() == 0); TestIntfPrx b1 = (TestIntfPrx)p.ice_batchOneway(); TestIntfPrx b2 = (TestIntfPrx)p.ice_connectionId("2").ice_batchOneway(); b2.ice_getConnection(); // Ensure connection is established. b1.opBatch(); b2.opBatch(); b1.ice_getConnection().close(false); b2.ice_getConnection().close(false); FlushCallback cb = new FlushCallback(); Ice.AsyncResult r = communicator.begin_flushBatchRequests(); r.whenCompleted( (Ice.Exception ex) => { cb.exception(ex); }); r.whenSent( (bool sentSynchronously) => { cb.sent(sentSynchronously); }); cb.check(); test(r.isSent()); // Exceptions are ignored! test(r.IsCompleted); test(p.opBatchCount() == 0); } } WriteLine("ok"); } Write("testing AsyncResult operations... "); Flush(); { { testController.holdAdapter(); Ice.AsyncResult r1; Ice.AsyncResult r2; try { r1 = p.begin_op(); byte[] seq = new byte[10024]; (new System.Random()).NextBytes(seq); while((r2 = p.begin_opWithPayload(seq)).sentSynchronously()); if(p.ice_getConnection() != null) { test(r1.sentSynchronously() && r1.isSent() && !r1.isCompleted_() || !r1.sentSynchronously() && !r1.isCompleted_()); test(!r2.sentSynchronously() && !r2.isCompleted_()); test(!r1.IsCompleted && !r1.CompletedSynchronously); test(!r2.IsCompleted && !r2.CompletedSynchronously); } } finally { testController.resumeAdapter(); } WaitHandle w1 = r1.AsyncWaitHandle; WaitHandle w2 = r2.AsyncWaitHandle; r1.waitForSent(); test(r1.isSent()); r2.waitForSent(); test(r2.isSent()); r1.waitForCompleted(); test(r1.isCompleted_()); w1.WaitOne(); r2.waitForCompleted(); test(r2.isCompleted_()); w2.WaitOne(); test(r1.getOperation().Equals("op")); test(r2.getOperation().Equals("opWithPayload")); } { Ice.AsyncResult r; // // Twoway // r = p.begin_ice_ping(); test(r.getOperation().Equals("ice_ping")); test(r.getConnection() == null); // Expected test(r.getCommunicator() == communicator); test(r.getProxy() == p); p.end_ice_ping(r); Test.TestIntfPrx p2; // // Oneway // p2 = p.ice_oneway() as Test.TestIntfPrx; r = p2.begin_ice_ping(); test(r.getOperation().Equals("ice_ping")); test(r.getConnection() == null); // Expected test(r.getCommunicator() == communicator); test(r.getProxy() == p2); // // Batch request via proxy // p2 = p.ice_batchOneway() as Test.TestIntfPrx; p2.ice_ping(); r = p2.begin_ice_flushBatchRequests(); test(r.getConnection() == null); // Expected test(r.getCommunicator() == communicator); test(r.getProxy() == p2); p2.end_ice_flushBatchRequests(r); if(p.ice_getConnection() != null) { // // Batch request via connection // Ice.Connection con = p.ice_getConnection(); p2 = p.ice_batchOneway() as Test.TestIntfPrx; p2.ice_ping(); r = con.begin_flushBatchRequests(); test(r.getConnection() == con); test(r.getCommunicator() == communicator); test(r.getProxy() == null); // Expected con.end_flushBatchRequests(r); // // Batch request via communicator // p2 = p.ice_batchOneway() as Test.TestIntfPrx; p2.ice_ping(); r = communicator.begin_flushBatchRequests(); test(r.getConnection() == null); // Expected test(r.getCommunicator() == communicator); test(r.getProxy() == null); // Expected communicator.end_flushBatchRequests(r); } } if(p.ice_getConnection() != null) { Ice.AsyncResult r1 = null; Ice.AsyncResult r2 = null; testController.holdAdapter(); try { Ice.AsyncResult r = null; byte[] seq = new byte[10024]; for(int i = 0; i < 200; ++i) // 2MB { r = p.begin_opWithPayload(seq); } test(!r.isSent()); r1 = p.begin_ice_ping(); r2 = p.begin_ice_id(); r1.cancel(); r2.cancel(); try { p.end_ice_ping(r1); test(false); } catch(Ice.InvocationCanceledException) { } try { p.end_ice_id(r2); test(false); } catch(Ice.InvocationCanceledException) { } } finally { testController.resumeAdapter(); p.ice_ping(); test(!r1.isSent() && r1.isCompleted_()); test(!r2.isSent() && r2.isCompleted_()); } testController.holdAdapter(); try { r1 = p.begin_op(); r2 = p.begin_ice_id(); r1.waitForSent(); r2.waitForSent(); r1.cancel(); r2.cancel(); try { p.end_op(r1); test(false); } catch(Ice.InvocationCanceledException) { } try { p.end_ice_id(r2); test(false); } catch(Ice.InvocationCanceledException) { } } finally { testController.resumeAdapter(); } } } WriteLine("ok"); if(p.ice_getConnection() != null) { Write("testing close connection with sending queue... "); Flush(); { byte[] seq = new byte[1024 * 10]; // // Send multiple opWithPayload, followed by a close and followed by multiple opWithPaylod. // The goal is to make sure that none of the opWithPayload fail even if the server closes // the connection gracefully in between. // int maxQueue = 2; bool done = false; while(!done && maxQueue < 50) { done = true; p.ice_ping(); List<Ice.AsyncResult> results = new List<Ice.AsyncResult>(); for(int i = 0; i < maxQueue; ++i) { results.Add(p.begin_opWithPayload(seq)); } if(!p.begin_close(false).isSent()) { for(int i = 0; i < maxQueue; i++) { Ice.AsyncResult r = p.begin_opWithPayload(seq); results.Add(r); if(r.isSent()) { done = false; maxQueue *= 2; break; } } } else { maxQueue *= 2; done = false; } foreach(Ice.AsyncResult q in results) { q.waitForCompleted(); try { q.throwLocalException(); } catch(Ice.LocalException) { test(false); } } } } WriteLine("ok"); } p.shutdown(); }
protected override void AttackOne() { currentThrow = ThrowType.Bell; }
protected override void AttackThree() { currentThrow = ThrowType.MysteryBall; }
protected override void AttackTwo() { currentThrow = ThrowType.Linear; }
public ThrowType SaveThrowType(ThrowType model) { return(new ThrowAccessor().SaveThrowType(model)); }