Пример #1
0
        public override async Task RunAsync(string[] args)
        {
            Dictionary <string, string> properties = CreateTestProperties(ref args);

            properties["Ice.Warn.Connections"]     = "0";
            properties["Ice.IncomingFrameSizeMax"] = "10K";
            await using Communicator communicator  = Initialize(properties);
            communicator.SetProperty("TestAdapter.Endpoints", GetTestEndpoint(0));
            IThrowerPrx thrower = AllTests.Run(this);
            await thrower.ShutdownAsync();
        }
Пример #2
0
        public override void Run(string[] args)
        {
            Dictionary <string, string> properties = CreateTestProperties(ref args);

            properties["Ice.Warn.Connections"] = "0";
            properties["Ice.MessageSizeMax"]   = "10"; // 10KB max
            using Communicator communicator    = Initialize(properties);
            communicator.SetProperty("TestAdapter.Endpoints", GetTestEndpoint(0));
            IThrowerPrx thrower = AllTests.allTests(this);

            thrower.shutdown();
        }
Пример #3
0
        public static IThrowerPrx allTests(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator();

            TestHelper.Assert(communicator != null);
            System.IO.TextWriter output = helper.GetWriter();
            {
                output.Write("testing object adapter registration exceptions... ");
                ObjectAdapter first;
                try
                {
                    first = communicator.CreateObjectAdapter("TestAdapter0");
                }
                catch (InvalidConfigurationException)
                {
                    // Expected
                }

                communicator.SetProperty("TestAdapter0.Endpoints", "tcp -h *");
                first = communicator.CreateObjectAdapter("TestAdapter0");
                try
                {
                    communicator.CreateObjectAdapter("TestAdapter0");
                    TestHelper.Assert(false);
                }
                catch (ArgumentException)
                {
                    // Expected.
                }

                try
                {
                    ObjectAdapter second =
                        communicator.CreateObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                    TestHelper.Assert(false);

                    //
                    // Quell mono error that variable second isn't used.
                    //
                    second.Deactivate();
                }
                catch (ArgumentException)
                {
                    // Expected
                }
                first.Deactivate();
                output.WriteLine("ok");
            }

            {
                output.Write("testing servant registration exceptions... ");
                communicator.SetProperty("TestAdapter1.Endpoints", "tcp -h *");
                ObjectAdapter adapter = communicator.CreateObjectAdapter("TestAdapter1");
                var           obj     = new Empty();
                adapter.Add("x", obj);
                try
                {
                    adapter.Add("x", obj);
                    TestHelper.Assert(false);
                }
                catch (ArgumentException)
                {
                }

                try
                {
                    adapter.Add("", obj);
                    TestHelper.Assert(false);
                }
                catch (FormatException)
                {
                }

                adapter.Remove("x");
                adapter.Remove("x"); // as of Ice 4.0, can remove multiple times
                adapter.Deactivate();
                output.WriteLine("ok");
            }

            var thrower = IThrowerPrx.Parse($"thrower:{helper.GetTestEndpoint(0)}", communicator);

            TestHelper.Assert(thrower != null);
            output.Write("catching exact types... ");
            output.Flush();

            try
            {
                thrower.throwAasA(1);
                TestHelper.Assert(false);
            }
            catch (A ex)
            {
                TestHelper.Assert(ex.aMem == 1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwAorDasAorD(1);
                TestHelper.Assert(false);
            }
            catch (A ex)
            {
                TestHelper.Assert(ex.aMem == 1);
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwAorDasAorD(-1);
                TestHelper.Assert(false);
            }
            catch (D ex)
            {
                TestHelper.Assert(ex.dMem == -1);
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwBasB(1, 2);
                TestHelper.Assert(false);
            }
            catch (B ex)
            {
                TestHelper.Assert(ex.aMem == 1);
                TestHelper.Assert(ex.bMem == 2);
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwCasC(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C ex)
            {
                TestHelper.Assert(ex.aMem == 1);
                TestHelper.Assert(ex.bMem == 2);
                TestHelper.Assert(ex.cMem == 3);
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching base types... ");
            output.Flush();

            try
            {
                thrower.throwBasB(1, 2);
                TestHelper.Assert(false);
            }
            catch (A ex)
            {
                TestHelper.Assert(ex.aMem == 1);
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwCasC(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (B ex)
            {
                TestHelper.Assert(ex.aMem == 1);
                TestHelper.Assert(ex.bMem == 2);
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching derived types... ");
            output.Flush();

            try
            {
                thrower.throwBasA(1, 2);
                TestHelper.Assert(false);
            }
            catch (B ex)
            {
                TestHelper.Assert(ex.aMem == 1);
                TestHelper.Assert(ex.bMem == 2);
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwCasA(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C ex)
            {
                TestHelper.Assert(ex.aMem == 1);
                TestHelper.Assert(ex.bMem == 2);
                TestHelper.Assert(ex.cMem == 3);
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwCasB(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C ex)
            {
                TestHelper.Assert(ex.aMem == 1);
                TestHelper.Assert(ex.bMem == 2);
                TestHelper.Assert(ex.cMem == 3);
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching remote exception... ");
            output.Flush();

            try
            {
                thrower.throwUndeclaredA(1);
                TestHelper.Assert(false);
            }
            catch (A)
            {
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwUndeclaredB(1, 2);
                TestHelper.Assert(false);
            }
            catch (B)
            {
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwUndeclaredC(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C)
            {
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            if (thrower.GetConnection() != null)
            {
                output.Write("testing memory limit marshal exception...");
                output.Flush();
                try
                {
                    thrower.throwMemoryLimitException(Array.Empty <byte>());
                    TestHelper.Assert(false);
                }
                catch (InvalidDataException)
                {
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }

                try
                {
                    thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB
                    TestHelper.Assert(false);
                }
                catch (ConnectionLostException)
                {
                }
                catch (UnhandledException)
                {
                    // Expected with JS bidir server
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }

                try
                {
                    var thrower2 = IThrowerPrx.Parse("thrower:" + helper.GetTestEndpoint(1), communicator);
                    try
                    {
                        thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB(no limits)
                    }
                    catch (InvalidDataException)
                    {
                    }
                    var thrower3 = IThrowerPrx.Parse("thrower:" + helper.GetTestEndpoint(2), communicator);
                    try
                    {
                        thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionLostException)
                    {
                    }
                }
                catch (ConnectionRefusedException)
                {
                    // Expected with JS bidir server
                }

                output.WriteLine("ok");
            }

            output.Write("catching object not exist exception... ");
            output.Flush();

            {
                var identity = Identity.Parse("does not exist");
                try
                {
                    IThrowerPrx thrower2 = thrower.Clone(identity, IThrowerPrx.Factory);
                    thrower2.IcePing();
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException ex)
                {
                    TestHelper.Assert(ex.Id.Equals(identity));
                    TestHelper.Assert(ex.Message.Contains("servant")); // verify we don't get system message
                }
                catch (Exception)
                {
                    TestHelper.Assert(false);
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception... ");
            output.Flush();

            try
            {
                IThrowerPrx thrower2 = thrower.Clone(facet: "no such facet", IThrowerPrx.Factory);
                try
                {
                    thrower2.IcePing();
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException ex)
                {
                    TestHelper.Assert(ex.Facet.Equals("no such facet"));
                    TestHelper.Assert(ex.Message.Contains("with facet")); // verify we don't get system message
                }
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception... ");
            output.Flush();

            try
            {
                var thrower2 = IWrongOperationPrx.UncheckedCast(thrower);
                thrower2.noSuchOperation();
                TestHelper.Assert(false);
            }
            catch (OperationNotExistException ex)
            {
                TestHelper.Assert(ex.Operation.Equals("noSuchOperation"));
                TestHelper.Assert(ex.Message.Contains("could not find operation")); // verify we don't get system message
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching unhandled local exception... ");
            output.Flush();

            try
            {
                thrower.throwLocalException();
                TestHelper.Assert(false);
            }
            catch (UnhandledException ex)
            {
                TestHelper.Assert(ex.Message.Contains("unhandled exception"));  // verify we get custom message
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            try
            {
                thrower.throwLocalExceptionIdempotent();
                TestHelper.Assert(false);
            }
            catch (UnhandledException)
            {
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching unhandled non-Ice exception... ");
            output.Flush();
            try
            {
                thrower.throwNonIceException();
                TestHelper.Assert(false);
            }
            catch (UnhandledException)
            {
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("catching unhandled remote exception... ");
            output.Flush();
            try
            {
                thrower.throwAConvertedToUnhandled();
                TestHelper.Assert(false);
            }
            catch (UnhandledException)
            {
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing asynchronous exceptions... ");
            output.Flush();

            try
            {
                thrower.throwAfterResponse();
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.throwAfterException();
                TestHelper.Assert(false);
            }
            catch (A)
            {
            }
            catch (Exception)
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("catching exact types with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.throwAasAAsync(1).Wait();
                }
                catch (AggregateException ex)
                {
                    TestHelper.Assert(ex.InnerException != null);
                    TestHelper.Assert(((A)ex.InnerException).aMem == 1);
                }
            }

            {
                try
                {
                    thrower.throwAorDasAorDAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (A ex)
                    {
                        TestHelper.Assert(ex.aMem == 1);
                    }
                    catch (D ex)
                    {
                        TestHelper.Assert(ex.dMem == -1);
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwAorDasAorDAsync(-1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (A ex)
                    {
                        TestHelper.Assert(ex.aMem == 1);
                    }
                    catch (D ex)
                    {
                        TestHelper.Assert(ex.dMem == -1);
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwBasBAsync(1, 2).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (B ex)
                    {
                        TestHelper.Assert(ex.aMem == 1);
                        TestHelper.Assert(ex.bMem == 2);
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwCasCAsync(1, 2, 3).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        TestHelper.Assert(ex.aMem == 1);
                        TestHelper.Assert(ex.bMem == 2);
                        TestHelper.Assert(ex.cMem == 3);
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching derived types with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.throwBasAAsync(1, 2).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (B ex)
                    {
                        TestHelper.Assert(ex.aMem == 1);
                        TestHelper.Assert(ex.bMem == 2);
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwCasAAsync(1, 2, 3).Wait();
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        TestHelper.Assert(ex.aMem == 1);
                        TestHelper.Assert(ex.bMem == 2);
                        TestHelper.Assert(ex.cMem == 3);
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwCasBAsync(1, 2, 3).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        TestHelper.Assert(ex.aMem == 1);
                        TestHelper.Assert(ex.bMem == 2);
                        TestHelper.Assert(ex.cMem == 3);
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching remote exception with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.throwUndeclaredAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (A)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwUndeclaredBAsync(1, 2).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (B)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwUndeclaredCAsync(1, 2, 3).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                var         identity = Identity.Parse("does not exist");
                IThrowerPrx thrower2 = thrower.Clone(identity, IThrowerPrx.Factory);
                try
                {
                    thrower2.throwAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Id.Equals(identity));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                IThrowerPrx thrower2 = thrower.Clone(facet: "no such facet", IThrowerPrx.Factory);
                try
                {
                    thrower2.throwAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Facet.Equals("no such facet"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception with AMI... ");
            output.Flush();

            {
                try
                {
                    var thrower4 = IWrongOperationPrx.UncheckedCast(thrower);
                    thrower4.noSuchOperationAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (OperationNotExistException ex)
                    {
                        TestHelper.Assert(ex.Operation.Equals("noSuchOperation"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled local exception with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.throwLocalExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwLocalExceptionIdempotentAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled non-Ice exception with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.throwNonIceExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("catching remote exception with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.throwUndeclaredAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (A)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwUndeclaredBAsync(1, 2).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (B)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwUndeclaredCAsync(1, 2, 3).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                var         identity = Identity.Parse("does not exist");
                IThrowerPrx thrower2 = thrower.Clone(identity, IThrowerPrx.Factory);
                try
                {
                    thrower2.throwAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    TestHelper.Assert(exc.InnerException != null);
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Id.Equals(identity));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                IThrowerPrx thrower2 = thrower.Clone(facet: "no such facet", IThrowerPrx.Factory);
                try
                {
                    thrower2.throwAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Facet.Equals("no such facet"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception with AMI... ");
            output.Flush();

            {
                var thrower4 = IWrongOperationPrx.UncheckedCast(thrower);
                try
                {
                    thrower4.noSuchOperationAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (OperationNotExistException ex)
                    {
                        TestHelper.Assert(ex.Operation.Equals("noSuchOperation"));
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled local exception with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.throwLocalExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwLocalExceptionIdempotentAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled non-Ice exception with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.throwNonIceExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("catching unhandled remote exception with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.throwAConvertedToUnhandledAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch (Exception)
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            return(thrower);
        }
Пример #4
0
        public static IThrowerPrx allTests(global::Test.TestHelper helper)
        {
            Communicator communicator = helper.communicator();
            var          output       = helper.getWriter();

            {
                output.Write("testing object adapter registration exceptions... ");
                ObjectAdapter first;
                try
                {
                    first = communicator.CreateObjectAdapter("TestAdapter0");
                }
                catch (InitializationException)
                {
                    // Expected
                }

                communicator.SetProperty("TestAdapter0.Endpoints", "tcp -h *");
                first = communicator.CreateObjectAdapter("TestAdapter0");
                try
                {
                    communicator.CreateObjectAdapter("TestAdapter0");
                    test(false);
                }
                catch (ArgumentException)
                {
                    // Expected.
                }

                try
                {
                    ObjectAdapter second =
                        communicator.CreateObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                    test(false);

                    //
                    // Quell mono error that variable second isn't used.
                    //
                    second.Deactivate();
                }
                catch (ArgumentException)
                {
                    // Expected
                }
                first.Deactivate();
                output.WriteLine("ok");
            }

            {
                output.Write("testing servant registration exceptions... ");
                communicator.SetProperty("TestAdapter1.Endpoints", "tcp -h *");
                ObjectAdapter adapter = communicator.CreateObjectAdapter("TestAdapter1");
                var           obj     = new Empty();
                adapter.Add(obj, "x");
                try
                {
                    adapter.Add(obj, "x");
                    test(false);
                }
                catch (ArgumentException)
                {
                }

                try
                {
                    adapter.Add(obj, "");
                    test(false);
                }
                catch (FormatException)
                {
                }

                adapter.Remove("x");
                try
                {
                    adapter.Remove("x");
                    test(false);
                }
                catch (NotRegisteredException)
                {
                }
                adapter.Deactivate();
                output.WriteLine("ok");
            }

            {
                output.Write("testing servant locator registration exceptions... ");
                communicator.SetProperty("TestAdapter2.Endpoints", "tcp -h *");
                ObjectAdapter adapter = communicator.CreateObjectAdapter("TestAdapter2");
                var           loc     = new ServantLocator();
                adapter.AddServantLocator(loc, "x");
                try
                {
                    adapter.AddServantLocator(loc, "x");
                    test(false);
                }
                catch (ArgumentException)
                {
                }

                adapter.Deactivate();
                output.WriteLine("ok");
            }

            output.Write("testing stringToProxy... ");
            output.Flush();
            string @ref  = "thrower:" + helper.getTestEndpoint(0);
            var    @base = IObjectPrx.Parse(@ref, communicator);

            test(@base != null);
            output.WriteLine("ok");

            output.Write("testing checked cast... ");
            output.Flush();
            var thrower = IThrowerPrx.CheckedCast(@base);

            test(thrower != null);
            test(thrower.Equals(@base));
            output.WriteLine("ok");

            output.Write("catching exact types... ");
            output.Flush();

            try
            {
                thrower.throwAasA(1);
                test(false);
            }
            catch (A ex)
            {
                test(ex.aMem == 1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                test(false);
            }

            try
            {
                thrower.throwAorDasAorD(1);
                test(false);
            }
            catch (A ex)
            {
                test(ex.aMem == 1);
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwAorDasAorD(-1);
                test(false);
            }
            catch (D ex)
            {
                test(ex.dMem == -1);
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwBasB(1, 2);
                test(false);
            }
            catch (Test.B ex)
            {
                test(ex.aMem == 1);
                test(ex.bMem == 2);
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwCasC(1, 2, 3);
                test(false);
            }
            catch (C ex)
            {
                test(ex.aMem == 1);
                test(ex.bMem == 2);
                test(ex.cMem == 3);
            }
            catch (Exception)
            {
                test(false);
            }

            output.WriteLine("ok");

            output.Write("catching base types... ");
            output.Flush();

            try
            {
                thrower.throwBasB(1, 2);
                test(false);
            }
            catch (A ex)
            {
                test(ex.aMem == 1);
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwCasC(1, 2, 3);
                test(false);
            }
            catch (B ex)
            {
                test(ex.aMem == 1);
                test(ex.bMem == 2);
            }
            catch (Exception)
            {
                test(false);
            }

            output.WriteLine("ok");

            output.Write("catching derived types... ");
            output.Flush();

            try
            {
                thrower.throwBasA(1, 2);
                test(false);
            }
            catch (B ex)
            {
                test(ex.aMem == 1);
                test(ex.bMem == 2);
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwCasA(1, 2, 3);
                test(false);
            }
            catch (C ex)
            {
                test(ex.aMem == 1);
                test(ex.bMem == 2);
                test(ex.cMem == 3);
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwCasB(1, 2, 3);
                test(false);
            }
            catch (C ex)
            {
                test(ex.aMem == 1);
                test(ex.bMem == 2);
                test(ex.cMem == 3);
            }
            catch (Exception)
            {
                test(false);
            }

            output.WriteLine("ok");

            if (thrower.supportsUndeclaredExceptions())
            {
                output.Write("catching unknown user exception... ");
                output.Flush();

                try
                {
                    thrower.throwUndeclaredA(1);
                    test(false);
                }
                catch (UnknownUserException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwUndeclaredB(1, 2);
                    test(false);
                }
                catch (UnknownUserException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwUndeclaredC(1, 2, 3);
                    test(false);
                }
                catch (UnknownUserException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                output.WriteLine("ok");
            }

            if (thrower.GetConnection() != null)
            {
                output.Write("testing memory limit marshal exception...");
                output.Flush();
                try
                {
                    thrower.throwMemoryLimitException(null);
                    test(false);
                }
                catch (MemoryLimitException)
                {
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    thrower.throwMemoryLimitException(new byte[20 * 1024]); // 20KB
                    test(false);
                }
                catch (ConnectionLostException)
                {
                }
                catch (UnknownLocalException)
                {
                    // Expected with JS bidir server
                }
                catch (Exception)
                {
                    test(false);
                }

                try
                {
                    var thrower2 = IThrowerPrx.Parse("thrower:" + helper.getTestEndpoint(1), communicator);
                    try
                    {
                        thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB(no limits)
                    }
                    catch (MemoryLimitException)
                    {
                    }
                    var thrower3 = IThrowerPrx.Parse("thrower:" + helper.getTestEndpoint(2), communicator);
                    try
                    {
                        thrower3.throwMemoryLimitException(new byte[1024]); // 1KB limit
                        test(false);
                    }
                    catch (ConnectionLostException)
                    {
                    }
                }
                catch (ConnectionRefusedException)
                {
                    // Expected with JS bidir server
                }

                output.WriteLine("ok");
            }

            output.Write("catching object not exist exception... ");
            output.Flush();

            {
                Identity id = Identity.Parse("does not exist");
                try
                {
                    var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(id));
                    thrower2.IcePing();
                    test(false);
                }
                catch (ObjectNotExistException ex)
                {
                    test(ex.Id.Equals(id));
                }
                catch (Exception)
                {
                    test(false);
                }
            }

            output.WriteLine("ok");

            output.Write("catching facet not exist exception... ");
            output.Flush();

            try
            {
                var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(facet: "no such facet"));
                try
                {
                    thrower2.IcePing();
                    test(false);
                }
                catch (FacetNotExistException ex)
                {
                    test(ex.Facet.Equals("no such facet"));
                }
            }
            catch (Exception)
            {
                test(false);
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception... ");
            output.Flush();

            try
            {
                var thrower2 = Test.IWrongOperationPrx.UncheckedCast(thrower);
                thrower2.noSuchOperation();
                test(false);
            }
            catch (OperationNotExistException ex)
            {
                test(ex.Operation.Equals("noSuchOperation"));
            }
            catch (Exception)
            {
                test(false);
            }

            output.WriteLine("ok");

            output.Write("catching unknown local exception... ");
            output.Flush();

            try
            {
                thrower.throwLocalException();
                test(false);
            }
            catch (UnknownLocalException)
            {
            }
            catch (Exception)
            {
                test(false);
            }
            try
            {
                thrower.throwLocalExceptionIdempotent();
                test(false);
            }
            catch (UnknownLocalException)
            {
            }
            catch (OperationNotExistException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            output.WriteLine("ok");

            output.Write("catching unknown non-Ice exception... ");
            output.Flush();

            try
            {
                thrower.throwNonIceException();
                test(false);
            }
            catch (UnknownException)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            output.WriteLine("ok");

            output.Write("testing asynchronous exceptions... ");
            output.Flush();

            try
            {
                thrower.throwAfterResponse();
            }
            catch (Exception)
            {
                test(false);
            }

            try
            {
                thrower.throwAfterException();
                test(false);
            }
            catch (A)
            {
            }
            catch (Exception)
            {
                test(false);
            }

            output.WriteLine("ok");

            output.Write("catching exact types with AMI mapping... ");
            output.Flush();

            {
                try
                {
                    thrower.throwAasAAsync(1).Wait();
                }
                catch (AggregateException exc)
                {
                    test(exc.InnerException is A);
                    var ex = exc.InnerException as Test.A;
                    test(ex.aMem == 1);
                }
            }

            {
                try
                {
                    thrower.throwAorDasAorDAsync(1).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (A ex)
                    {
                        test(ex.aMem == 1);
                    }
                    catch (D ex)
                    {
                        test(ex.dMem == -1);
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwAorDasAorDAsync(-1).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (A ex)
                    {
                        test(ex.aMem == 1);
                    }
                    catch (D ex)
                    {
                        test(ex.dMem == -1);
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwBasBAsync(1, 2).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (B ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwCasCAsync(1, 2, 3).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                        test(ex.cMem == 3);
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching derived types with new AMI mapping... ");
            output.Flush();

            {
                try
                {
                    thrower.throwBasAAsync(1, 2).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (B ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwCasAAsync(1, 2, 3).Wait();
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                        test(ex.cMem == 3);
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwCasBAsync(1, 2, 3).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        test(ex.aMem == 1);
                        test(ex.bMem == 2);
                        test(ex.cMem == 3);
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            if (thrower.supportsUndeclaredExceptions())
            {
                output.Write("catching unknown user exception with new AMI mapping... ");
                output.Flush();

                {
                    try
                    {
                        thrower.throwUndeclaredAAsync(1).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownUserException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwUndeclaredBAsync(1, 2).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownUserException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwUndeclaredCAsync(1, 2, 3).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownUserException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");
            }

            output.Write("catching object not exist exception with new AMI mapping... ");
            output.Flush();

            {
                Identity id       = Identity.Parse("does not exist");
                var      thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(id));
                try
                {
                    thrower2.throwAasAAsync(1).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        test(ex.Id.Equals(id));
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching facet not exist exception with new AMI mapping... ");
            output.Flush();

            {
                var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(facet: "no such facet"));
                try
                {
                    thrower2.throwAasAAsync(1).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (FacetNotExistException ex)
                    {
                        test(ex.Facet.Equals("no such facet"));
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception with new AMI mapping... ");
            output.Flush();

            {
                try
                {
                    var thrower4 = IWrongOperationPrx.UncheckedCast(thrower);
                    thrower4.noSuchOperationAsync().Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (OperationNotExistException ex)
                    {
                        test(ex.Operation.Equals("noSuchOperation"));
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unknown local exception with new AMI mapping... ");
            output.Flush();

            {
                try
                {
                    thrower.throwLocalExceptionAsync().Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (UnknownLocalException)
                    {
                    }
                    catch (OperationNotExistException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwLocalExceptionIdempotentAsync().Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (UnknownLocalException)
                    {
                    }
                    catch (OperationNotExistException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unknown non-Ice exception with new AMI mapping... ");
            output.Flush();

            {
                try
                {
                    thrower.throwNonIceExceptionAsync().Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (UnknownException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            if (thrower.supportsUndeclaredExceptions())
            {
                output.Write("catching unknown user exception with new AMI mapping... ");
                output.Flush();

                {
                    try
                    {
                        thrower.throwUndeclaredAAsync(1).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownUserException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwUndeclaredBAsync(1, 2).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownUserException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                {
                    try
                    {
                        thrower.throwUndeclaredCAsync(1, 2, 3).Wait();
                        test(false);
                    }
                    catch (AggregateException exc)
                    {
                        try
                        {
                            throw exc.InnerException;
                        }
                        catch (UnknownUserException)
                        {
                        }
                        catch (Exception)
                        {
                            test(false);
                        }
                    }
                }

                output.WriteLine("ok");
            }

            output.Write("catching object not exist exception with new AMI mapping... ");
            output.Flush();

            {
                Identity id       = Identity.Parse("does not exist");
                var      thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(id));
                try
                {
                    thrower2.throwAasAAsync(1).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        test(ex.Id.Equals(id));
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching facet not exist exception with new AMI mapping... ");
            output.Flush();

            {
                var thrower2 = IThrowerPrx.UncheckedCast(thrower.Clone(facet: "no such facet"));
                try
                {
                    thrower2.throwAasAAsync(1).Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (FacetNotExistException ex)
                    {
                        test(ex.Facet.Equals("no such facet"));
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception with new AMI mapping... ");
            output.Flush();

            {
                var thrower4 = IWrongOperationPrx.UncheckedCast(thrower);
                try
                {
                    thrower4.noSuchOperationAsync().Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (OperationNotExistException ex)
                    {
                        test(ex.Operation.Equals("noSuchOperation"));
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unknown local exception with new AMI mapping... ");
            output.Flush();

            {
                try
                {
                    thrower.throwLocalExceptionAsync().Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (UnknownLocalException)
                    {
                    }
                    catch (OperationNotExistException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            {
                try
                {
                    thrower.throwLocalExceptionIdempotentAsync().Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (UnknownLocalException)
                    {
                    }
                    catch (OperationNotExistException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unknown non-Ice exception with new AMI mapping... ");
            output.Flush();

            {
                try
                {
                    thrower.throwNonIceExceptionAsync().Wait();
                    test(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (UnknownException)
                    {
                    }
                    catch (Exception)
                    {
                        test(false);
                    }
                }
            }

            output.WriteLine("ok");
            return(thrower);
        }
Пример #5
0
        public static IThrowerPrx Run(TestHelper helper)
        {
            Communicator?communicator = helper.Communicator;

            TestHelper.Assert(communicator != null);
            bool       ice1   = helper.Protocol == Protocol.Ice1;
            TextWriter output = helper.Output;
            {
                output.Write("testing object adapter registration exceptions... ");
                ObjectAdapter first;
                try
                {
                    first = communicator.CreateObjectAdapter("TestAdapter0");
                }
                catch (InvalidConfigurationException)
                {
                    // Expected
                }

                communicator.SetProperty("TestAdapter0.Endpoints", "tcp -h *");
                first = communicator.CreateObjectAdapter("TestAdapter0");
                try
                {
                    communicator.CreateObjectAdapter("TestAdapter0");
                    TestHelper.Assert(false);
                }
                catch (ArgumentException)
                {
                    // Expected.
                }

                try
                {
                    _ = communicator.CreateObjectAdapterWithEndpoints("TestAdapter0", "ssl -h foo -p 12011");
                    TestHelper.Assert(false);
                }
                catch (ArgumentException)
                {
                    // Expected
                }
                first.Dispose();
                output.WriteLine("ok");
            }

            {
                output.Write("testing servant registration exceptions... ");
                communicator.SetProperty("TestAdapter1.Endpoints", "tcp -h *");
                ObjectAdapter adapter = communicator.CreateObjectAdapter("TestAdapter1");
                var           obj     = new Empty();
                adapter.Add("x", obj);
                try
                {
                    adapter.Add("x", obj);
                    TestHelper.Assert(false);
                }
                catch (ArgumentException)
                {
                }

                try
                {
                    adapter.Add("", obj);
                    TestHelper.Assert(false);
                }
                catch (FormatException)
                {
                }

                adapter.Remove("x");
                adapter.Remove("x"); // as of Ice 4.0, Remove succeeds with multiple removals
                adapter.Dispose();
                output.WriteLine("ok");
            }

            var thrower = IThrowerPrx.Parse(helper.GetTestProxy("thrower", 0), communicator);

            TestHelper.Assert(thrower != null);
            output.Write("catching exact types... ");
            output.Flush();

            try
            {
                thrower.ThrowAasA(1);
                TestHelper.Assert(false);
            }
            catch (A ex)
            {
                TestHelper.Assert(ex.AMem == 1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowAorDasAorD(1);
                TestHelper.Assert(false);
            }
            catch (A ex)
            {
                TestHelper.Assert(ex.AMem == 1);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowAorDasAorD(-1);
                TestHelper.Assert(false);
            }
            catch (D ex)
            {
                TestHelper.Assert(ex.DMem == -1);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowBasB(1, 2);
                TestHelper.Assert(false);
            }
            catch (B ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowCasC(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
                TestHelper.Assert(ex.CMem == 3);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching base types... ");
            output.Flush();

            try
            {
                thrower.ThrowBasB(1, 2);
                TestHelper.Assert(false);
            }
            catch (A ex)
            {
                TestHelper.Assert(ex.AMem == 1);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowCasC(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (B ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching derived types... ");
            output.Flush();

            try
            {
                thrower.ThrowBasA(1, 2);
                TestHelper.Assert(false);
            }
            catch (B ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowCasA(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
                TestHelper.Assert(ex.CMem == 3);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowCasB(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
                TestHelper.Assert(ex.CMem == 3);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            if (thrower.GetConnection() is not ColocatedConnection)
            {
                output.Write("testing memory limit marshal exception...");
                output.Flush();
                try
                {
                    thrower.ThrowMemoryLimitException(Array.Empty <byte>());
                    TestHelper.Assert(false);
                }
                catch (InvalidDataException)
                {
                }
                catch
                {
                    TestHelper.Assert(false);
                }

                try
                {
                    thrower.ThrowMemoryLimitException(new byte[20 * 1024]); // 20KB
                    TestHelper.Assert(false);
                }
                catch (ConnectionLostException)
                {
                }
                catch (UnhandledException)
                {
                    // Expected with JS bidir server
                }
                catch
                {
                    TestHelper.Assert(false);
                }

                try
                {
                    var thrower2 = IThrowerPrx.Parse(helper.GetTestProxy("thrower", 1), communicator);
                    try
                    {
                        thrower2.ThrowMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB(no limits)
                    }
                    catch (InvalidDataException)
                    {
                    }

                    var thrower3 = IThrowerPrx.Parse(helper.GetTestProxy("thrower", 2), communicator);
                    try
                    {
                        thrower3.ThrowMemoryLimitException(new byte[1024]); // 1KB limit
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionLostException)
                    {
                    }
                }
                catch (ConnectionRefusedException)
                {
                    // Expected with JS bidir server
                }

                output.WriteLine("ok");
            }

            output.Write("catching object not exist exception... ");
            output.Flush();

            {
                var identity = Identity.Parse("does not exist");
                try
                {
                    IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, identity: identity);
                    thrower2.IcePing();
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException ex)
                {
                    TestHelper.Assert(ex.Origin !.Value.Identity == identity);
                    TestHelper.Assert(ex.Message.Contains("servant")); // verify we don't get system message
                }
                catch
                {
                    TestHelper.Assert(false);
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception... ");
            output.Flush();

            try
            {
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, facet: "no such facet");
                try
                {
                    thrower2.IcePing();
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException ex)
                {
                    TestHelper.Assert(ex.Origin !.Value.Facet == "no such facet");
                    TestHelper.Assert(ex.Message.Contains("with facet")); // verify we don't get system message
                }
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception... ");
            output.Flush();

            try
            {
                var thrower2 = thrower.Clone(IWrongOperationPrx.Factory);
                thrower2.NoSuchOperation();
                TestHelper.Assert(false);
            }
            catch (OperationNotExistException ex)
            {
                TestHelper.Assert(ex.Origin !.Value.Operation == "noSuchOperation");
                TestHelper.Assert(ex.Message.Contains("could not find operation")); // verify we don't get system message
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching unhandled local exception... ");
            output.Flush();

            try
            {
                thrower.ThrowLocalException();
                TestHelper.Assert(false);
            }
            catch (UnhandledException ex)
            {
                TestHelper.Assert(ex.Message.Contains("unhandled exception")); // verify we get custom message

                // With ice1, the origin is not set; with ice2, it is.
                if (ice1)
                {
                    TestHelper.Assert(ex.Origin == null);
                }
                else
                {
                    TestHelper.Assert(ex.Origin !.Value.Identity == thrower.Identity &&
                                      ex.Origin !.Value.Operation == "throwLocalException");
                }
            }
            catch
            {
                TestHelper.Assert(false);
            }
            try
            {
                thrower.ThrowLocalExceptionIdempotent();
                TestHelper.Assert(false);
            }
            catch (UnhandledException)
            {
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching unhandled non-Ice exception... ");
            output.Flush();
            try
            {
                thrower.ThrowNonIceException();
                TestHelper.Assert(false);
            }
            catch (UnhandledException)
            {
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("catching unhandled remote exception... ");
            output.Flush();
            try
            {
                thrower.ThrowAConvertedToUnhandled();
                TestHelper.Assert(false);
            }
            catch (UnhandledException)
            {
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing asynchronous exceptions... ");
            output.Flush();

            try
            {
                thrower.ThrowAfterResponse();
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowAfterException();
                TestHelper.Assert(false);
            }
            catch (A)
            {
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("catching exact types with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.ThrowAasAAsync(1).Wait();
                }
                catch (AggregateException ex)
                {
                    TestHelper.Assert(ex.InnerException != null);
                    TestHelper.Assert(((A)ex.InnerException).AMem == 1);
                }
            }

            {
                try
                {
                    thrower.ThrowAorDasAorDAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (A ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                    }
                    catch (D ex)
                    {
                        TestHelper.Assert(ex.DMem == -1);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowAorDasAorDAsync(-1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (A ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                    }
                    catch (D ex)
                    {
                        TestHelper.Assert(ex.DMem == -1);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowBasBAsync(1, 2).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (B ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowCasCAsync(1, 2, 3).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                        TestHelper.Assert(ex.CMem == 3);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching derived types with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.ThrowBasAAsync(1, 2).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (B ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowCasAAsync(1, 2, 3).Wait();
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                        TestHelper.Assert(ex.CMem == 3);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowCasBAsync(1, 2, 3).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                        TestHelper.Assert(ex.CMem == 3);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                var         identity = Identity.Parse("does not exist");
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, identity: identity);
                try
                {
                    thrower2.ThrowAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Identity == identity);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, facet: "no such facet");
                try
                {
                    thrower2.ThrowAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Facet.Equals("no such facet"));
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception with AMI... ");
            output.Flush();

            {
                try
                {
                    var thrower4 = thrower.Clone(IWrongOperationPrx.Factory);
                    thrower4.NoSuchOperationAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (OperationNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Operation.Equals("noSuchOperation"));
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("catching unhandled local exception with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.ThrowLocalExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowLocalExceptionIdempotentAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled non-Ice exception with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.ThrowNonIceExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                var         identity = Identity.Parse("does not exist");
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, identity: identity);
                try
                {
                    thrower2.ThrowAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    TestHelper.Assert(exc.InnerException != null);
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Identity == identity);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, facet: "no such facet");
                try
                {
                    thrower2.ThrowAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Facet == "no such facet");
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception with AMI... ");
            output.Flush();

            {
                var thrower4 = thrower.Clone(IWrongOperationPrx.Factory);
                try
                {
                    thrower4.NoSuchOperationAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (OperationNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Operation == "noSuchOperation");
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled local exception with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.ThrowLocalExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowLocalExceptionIdempotentAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled non-Ice exception with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.ThrowNonIceExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("catching unhandled remote exception with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.ThrowAConvertedToUnhandledAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            return(thrower);
        }
Пример #6
0
        public static async Task RunAsync(TestHelper helper)
        {
            Communicator communicator = helper.Communicator;

            bool       ice1   = helper.Protocol == Protocol.Ice1;
            TextWriter output = helper.Output;
            {
                output.Write("testing object adapter registration exceptions... ");
                ObjectAdapter first;
                try
                {
                    first = communicator.CreateObjectAdapter("TestAdapter0");
                }
                catch (InvalidConfigurationException)
                {
                    // Expected
                }

                communicator.SetProperty("TestAdapter0.Endpoints", helper.GetTestEndpoint(ephemeral: true));
                first = communicator.CreateObjectAdapter("TestAdapter0");
                try
                {
                    communicator.CreateObjectAdapter("TestAdapter0");
                    TestHelper.Assert(false);
                }
                catch (ArgumentException)
                {
                    // Expected.
                }

                try
                {
                    // test that foo does not resolve
                    var props = communicator.GetProperties();
                    props["Test.Host"] = "foo";
                    _ = communicator.CreateObjectAdapterWithEndpoints("TestAdapter0",
                                                                      TestHelper.GetTestEndpoint(props, ephemeral: true));

                    TestHelper.Assert(false);
                }
                catch (ArgumentException)
                {
                    // Expected
                }
                await first.DisposeAsync();

                output.WriteLine("ok");
            }

            {
                output.Write("testing servant registration exceptions... ");
                communicator.SetProperty("TestAdapter1.Endpoints", helper.GetTestEndpoint(ephemeral: true));
                await using ObjectAdapter adapter = communicator.CreateObjectAdapter("TestAdapter1");
                var obj = new Empty();
                adapter.Add("x", obj);
                try
                {
                    adapter.Add("x", obj);
                    TestHelper.Assert(false);
                }
                catch (ArgumentException)
                {
                }

                try
                {
                    adapter.Add("", obj);
                    TestHelper.Assert(false);
                }
                catch (FormatException)
                {
                }

                adapter.Remove("x");
                adapter.Remove("x"); // as of Ice 4.0, Remove succeeds with multiple removals
                output.WriteLine("ok");
            }

            var thrower = IThrowerPrx.Parse(helper.GetTestProxy("thrower", 0), communicator);

            TestHelper.Assert(thrower != null);
            output.Write("catching exact types... ");
            output.Flush();

            try
            {
                thrower.ThrowAasA(1);
                TestHelper.Assert(false);
            }
            catch (A ex)
            {
                TestHelper.Assert(ex.AMem == 1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowAorDasAorD(1);
                TestHelper.Assert(false);
            }
            catch (A ex)
            {
                TestHelper.Assert(ex.AMem == 1);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowAorDasAorD(-1);
                TestHelper.Assert(false);
            }
            catch (D ex)
            {
                TestHelper.Assert(ex.DMem == -1);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowBasB(1, 2);
                TestHelper.Assert(false);
            }
            catch (B ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowCasC(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
                TestHelper.Assert(ex.CMem == 3);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching base types... ");
            output.Flush();

            try
            {
                thrower.ThrowBasB(1, 2);
                TestHelper.Assert(false);
            }
            catch (A ex)
            {
                TestHelper.Assert(ex.AMem == 1);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowCasC(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (B ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching derived types... ");
            output.Flush();

            try
            {
                thrower.ThrowBasA(1, 2);
                TestHelper.Assert(false);
            }
            catch (B ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowCasA(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
                TestHelper.Assert(ex.CMem == 3);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowCasB(1, 2, 3);
                TestHelper.Assert(false);
            }
            catch (C ex)
            {
                TestHelper.Assert(ex.AMem == 1);
                TestHelper.Assert(ex.BMem == 2);
                TestHelper.Assert(ex.CMem == 3);
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            if (await thrower.GetConnectionAsync() is not ColocatedConnection)
            {
                output.Write("testing incoming frame max size...");
                output.Flush();
                if (thrower.Protocol == Protocol.Ice1)
                {
                    TestHelper.Assert((await thrower.GetConnectionAsync()).PeerIncomingFrameMaxSize == -1);
                    try
                    {
                        thrower.SendAndReceive(Array.Empty <byte>());
                        TestHelper.Assert(false);
                    }
                    catch (InvalidDataException)
                    {
                        TestHelper.Assert(!thrower.GetCachedConnection() !.IsActive);
                    }
                    catch (Exception ex)
                    {
                        TestHelper.Assert(false, $"unexpected exception:\n{ex}");
                    }

                    try
                    {
                        thrower.SendAndReceive(new byte[20 * 1024]); // 20KB
                        TestHelper.Assert(false);
                    }
                    catch (ConnectionLostException)
                    {
                        TestHelper.Assert(!thrower.GetCachedConnection() !.IsActive);
                    }
                    catch (UnhandledException)
                    {
                        // Expected with JS bidir server
                    }
                    catch (Exception ex)
                    {
                        TestHelper.Assert(false, $"unexpected exception:\n{ex}");
                    }

                    try
                    {
                        var thrower2 = IThrowerPrx.Parse(helper.GetTestProxy("thrower", 1), communicator);
                        try
                        {
                            thrower2.SendAndReceive(new byte[2 * 1024 * 1024]); // 2MB(no limits)
                            TestHelper.Assert(false);
                        }
                        catch (InvalidDataException)
                        {
                        }

                        var thrower3 = IThrowerPrx.Parse(helper.GetTestProxy("thrower", 2), communicator);
                        try
                        {
                            thrower3.SendAndReceive(new byte[1024]); // 1KB limit
                            TestHelper.Assert(false);
                        }
                        catch (ConnectionLostException)
                        {
                            TestHelper.Assert(thrower.GetCachedConnection() !.Protocol == Protocol.Ice1);
                        }
                    }
                    catch (ConnectionRefusedException)
                    {
                        // Expected with JS bidir server
                    }
                }
                else
                {
                    TestHelper.Assert((await thrower.GetConnectionAsync()).PeerIncomingFrameMaxSize == 10 * 1024);
                    try
                    {
                        // The response is too large
                        thrower.SendAndReceive(Array.Empty <byte>());
                        TestHelper.Assert(false);
                    }
                    catch (ServerException)
                    {
                        TestHelper.Assert(thrower.GetCachedConnection() !.IsActive);
                    }

                    try
                    {
                        // The request is too large
                        thrower.SendAndReceive(new byte[20 * 1024]); // 20KB
                        TestHelper.Assert(false);
                    }
                    catch (LimitExceededException)
                    {
                        TestHelper.Assert(thrower.GetCachedConnection() !.IsActive);
                    }

                    var thrower2 = IThrowerPrx.Parse(helper.GetTestProxy("thrower", 1), communicator);
                    TestHelper.Assert((await thrower2.GetConnectionAsync()).PeerIncomingFrameMaxSize == int.MaxValue);
                    try
                    {
                        // The response is too large
                        thrower2.SendAndReceive(new byte[2 * 1024 * 1024]); // 2MB (no limits)
                        TestHelper.Assert(false);
                    }
                    catch (ServerException)
                    {
                        TestHelper.Assert(thrower.GetCachedConnection() !.IsActive);
                    }

                    var thrower3 = IThrowerPrx.Parse(helper.GetTestProxy("thrower", 2), communicator);
                    TestHelper.Assert((await thrower3.GetConnectionAsync()).PeerIncomingFrameMaxSize == 1024);
                    try
                    {
                        // The request is too large
                        thrower3.SendAndReceive(new byte[1024]); // 1KB limit
                        TestHelper.Assert(false);
                    }
                    catch (LimitExceededException)
                    {
                    }

                    var forwarder = IThrowerPrx.Parse(helper.GetTestProxy("forwarder", 3), communicator);
                    TestHelper.Assert((await forwarder.GetConnectionAsync()).PeerIncomingFrameMaxSize == int.MaxValue);
                    try
                    {
                        forwarder.SendAndReceive(new byte[20 * 1024]);
                        TestHelper.Assert(false);
                    }
                    catch (ServerException)
                    {
                        TestHelper.Assert(thrower.GetCachedConnection() !.IsActive);
                    }

                    try
                    {
                        forwarder.SendAndReceive(Array.Empty <byte>());
                        TestHelper.Assert(false);
                    }
                    catch (ServerException)
                    {
                        TestHelper.Assert(thrower.GetCachedConnection() !.IsActive);
                    }
                }
                output.WriteLine("ok");
            }

            output.Write("catching object not exist exception... ");
            output.Flush();

            {
                var identity = Identity.Parse("does not exist");
                try
                {
                    IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, identity: identity);
                    thrower2.IcePing();
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException ex)
                {
                    TestHelper.Assert(ex.Origin !.Value.Identity == identity);
                    TestHelper.Assert(ex.Message.Contains("servant")); // verify we don't get system message
                }
                catch
                {
                    TestHelper.Assert(false);
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception... ");
            output.Flush();

            try
            {
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, facet: "no such facet");
                try
                {
                    thrower2.IcePing();
                    TestHelper.Assert(false);
                }
                catch (ObjectNotExistException ex)
                {
                    TestHelper.Assert(ex.Origin !.Value.Facet == "no such facet");
                    TestHelper.Assert(ex.Message.Contains("with facet")); // verify we don't get system message
                }
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception... ");
            output.Flush();

            try
            {
                var thrower2 = thrower.Clone(IWrongOperationPrx.Factory);
                thrower2.NoSuchOperation();
                TestHelper.Assert(false);
            }
            catch (OperationNotExistException ex)
            {
                TestHelper.Assert(ex.Origin !.Value.Operation == "noSuchOperation");
                TestHelper.Assert(ex.Message.Contains("could not find operation")); // verify we don't get system message
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching unhandled local exception... ");
            output.Flush();

            try
            {
                thrower.ThrowLocalException();
                TestHelper.Assert(false);
            }
            catch (UnhandledException ex)
            {
                TestHelper.Assert(ex.Message.Contains("unhandled exception")); // verify we get custom message

                // With ice1, the origin is not set; with ice2, it is.
                if (ice1)
                {
                    TestHelper.Assert(ex.Origin == null);
                }
                else
                {
                    TestHelper.Assert(ex.Origin !.Value.Identity == thrower.Identity &&
                                      ex.Origin !.Value.Operation == "throwLocalException");
                }
            }
            catch
            {
                TestHelper.Assert(false);
            }
            try
            {
                thrower.ThrowLocalExceptionIdempotent();
                TestHelper.Assert(false);
            }
            catch (UnhandledException)
            {
            }
            catch
            {
                TestHelper.Assert(false);
            }

            output.WriteLine("ok");

            output.Write("catching unhandled non-Ice exception... ");
            output.Flush();
            try
            {
                thrower.ThrowNonIceException();
                TestHelper.Assert(false);
            }
            catch (UnhandledException)
            {
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("catching unhandled remote exception... ");
            output.Flush();
            try
            {
                thrower.ThrowAConvertedToUnhandled();
                TestHelper.Assert(false);
            }
            catch (UnhandledException)
            {
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("testing asynchronous exceptions... ");
            output.Flush();

            try
            {
                thrower.ThrowAfterResponse();
            }
            catch
            {
                TestHelper.Assert(false);
            }

            try
            {
                thrower.ThrowAfterException();
                TestHelper.Assert(false);
            }
            catch (A)
            {
            }
            catch
            {
                TestHelper.Assert(false);
            }
            output.WriteLine("ok");

            output.Write("catching exact types with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.ThrowAasAAsync(1).Wait();
                }
                catch (AggregateException ex)
                {
                    TestHelper.Assert(ex.InnerException != null);
                    TestHelper.Assert(((A)ex.InnerException).AMem == 1);
                }
            }

            {
                try
                {
                    thrower.ThrowAorDasAorDAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (A ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                    }
                    catch (D ex)
                    {
                        TestHelper.Assert(ex.DMem == -1);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowAorDasAorDAsync(-1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (A ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                    }
                    catch (D ex)
                    {
                        TestHelper.Assert(ex.DMem == -1);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowBasBAsync(1, 2).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (B ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowCasCAsync(1, 2, 3).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                        TestHelper.Assert(ex.CMem == 3);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching derived types with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.ThrowBasAAsync(1, 2).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (B ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowCasAAsync(1, 2, 3).Wait();
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                        TestHelper.Assert(ex.CMem == 3);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowCasBAsync(1, 2, 3).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (C ex)
                    {
                        TestHelper.Assert(ex.AMem == 1);
                        TestHelper.Assert(ex.BMem == 2);
                        TestHelper.Assert(ex.CMem == 3);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                var         identity = Identity.Parse("does not exist");
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, identity: identity);
                try
                {
                    thrower2.ThrowAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Identity == identity);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, facet: "no such facet");
                try
                {
                    thrower2.ThrowAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Facet.Equals("no such facet"));
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception with AMI... ");
            output.Flush();

            {
                try
                {
                    var thrower4 = thrower.Clone(IWrongOperationPrx.Factory);
                    thrower4.NoSuchOperationAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (OperationNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Operation.Equals("noSuchOperation"));
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("catching unhandled local exception with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.ThrowLocalExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowLocalExceptionIdempotentAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled non-Ice exception with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.ThrowNonIceExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                var         identity = Identity.Parse("does not exist");
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, identity: identity);
                try
                {
                    thrower2.ThrowAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    TestHelper.Assert(exc.InnerException != null);
                    try
                    {
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Identity == identity);
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching object not exist exception with AMI... ");
            output.Flush();

            {
                IThrowerPrx thrower2 = thrower.Clone(IThrowerPrx.Factory, facet: "no such facet");
                try
                {
                    thrower2.ThrowAasAAsync(1).Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (ObjectNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Facet == "no such facet");
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching operation not exist exception with AMI... ");
            output.Flush();

            {
                var thrower4 = thrower.Clone(IWrongOperationPrx.Factory);
                try
                {
                    thrower4.NoSuchOperationAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (OperationNotExistException ex)
                    {
                        TestHelper.Assert(ex.Origin !.Value.Operation == "noSuchOperation");
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled local exception with AMI... ");
            output.Flush();

            {
                try
                {
                    thrower.ThrowLocalExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            {
                try
                {
                    thrower.ThrowLocalExceptionIdempotentAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }

            output.WriteLine("ok");

            output.Write("catching unhandled non-Ice exception with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.ThrowNonIceExceptionAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");

            output.Write("catching unhandled remote exception with AMI... ");
            output.Flush();
            {
                try
                {
                    thrower.ThrowAConvertedToUnhandledAsync().Wait();
                    TestHelper.Assert(false);
                }
                catch (AggregateException exc)
                {
                    try
                    {
                        TestHelper.Assert(exc.InnerException != null);
                        throw exc.InnerException;
                    }
                    catch (UnhandledException)
                    {
                    }
                    catch
                    {
                        TestHelper.Assert(false);
                    }
                }
            }
            output.WriteLine("ok");
            await thrower.ShutdownAsync();
        }