Exemple #1
0
    private static void validationTests(Configuration configuration, Test.BackgroundPrx background,
                                        Test.BackgroundControllerPrx ctl)
    {
        try
        {
            background.op();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        closeConnection(background);

        try
        {
            // Get the read() of connection validation to throw right away.
            configuration.readException(new Ice.SocketException());
            background.op();
            test(false);
        }
        catch (Ice.SocketException)
        {
            configuration.readException(null);
        }

        for (int i = 0; i < 2; ++i)
        {
            configuration.readException(new Ice.SocketException());
            BackgroundPrx   prx = i == 0 ? background : (BackgroundPrx)background.ice_oneway();
            Ice.AsyncResult r   = prx.begin_op();
            test(!r.sentSynchronously());
            try
            {
                prx.end_op(r);
                test(false);
            }
            catch (Ice.SocketException)
            {
            }
            test(r.IsCompleted);
            configuration.readException(null);
        }

        if (!background.ice_getCommunicator().getProperties().getProperty("Ice.Default.Protocol").Equals("test-ssl") &&
            !background.ice_getCommunicator().getProperties().getProperty("Ice.Default.Protocol").Equals("test-wss"))
        {
            try
            {
                // Get the read() of the connection validation to return "would block"
                configuration.readReady(false);
                background.op();
                configuration.readReady(true);
            }
            catch (Ice.LocalException ex)
            {
                Console.Error.WriteLine(ex);
                test(false);
            }
            closeConnection(background);

            try
            {
                // Get the read() of the connection validation to return "would block" and then throw.
                configuration.readReady(false);
                configuration.readException(new Ice.SocketException());
                background.op();
                test(false);
            }
            catch (Ice.SocketException)
            {
                configuration.readException(null);
                configuration.readReady(true);
            }

            for (int i = 0; i < 2; ++i)
            {
                configuration.readReady(false);
                configuration.readException(new Ice.SocketException());
                Ice.AsyncResult r = background.begin_op();
                test(!r.sentSynchronously());
                try
                {
                    background.end_op(r);
                    test(false);
                }
                catch (Ice.SocketException)
                {
                }
                test(r.IsCompleted);
                configuration.readException(null);
                configuration.readReady(true);
            }
        }

        {
            ctl.holdAdapter(); // Hold to block in connection validation
            Ice.AsyncResult r  = background.begin_op();
            Ice.AsyncResult r2 = background.begin_op();
            test(!r.sentSynchronously() && !r2.sentSynchronously());
            test(!r.IsCompleted && !r2.IsCompleted);
            ctl.resumeAdapter();
            background.end_op(r);
            background.end_op(r2);
            test(r.IsCompleted && r2.IsCompleted);
        }

        try
        {
            // Get the write() of connection validation to throw right away.
            ctl.writeException(true);
            background.op();
            test(false);
        }
        catch (Ice.ConnectionLostException)
        {
            ctl.writeException(false);
        }

        try
        {
            // Get the write() of the connection validation to return "would block"
            ctl.writeReady(false);
            background.op();
            ctl.writeReady(true);
        }
        catch (Ice.LocalException ex)
        {
            Console.Error.WriteLine(ex);
            test(false);
        }
        closeConnection(background);

        try
        {
            // Get the write() of the connection validation to return "would block" and then throw.
            ctl.writeReady(false);
            ctl.writeException(true);
            background.op();
            test(false);
        }
        catch (Ice.ConnectionLostException)
        {
            ctl.writeException(false);
            ctl.writeReady(true);
        }

        byte[] seq = new byte[512 * 1024];

        BackgroundPrx backgroundBatchOneway = BackgroundPrxHelper.uncheckedCast(background.ice_batchOneway());

        //
        // First send small requests to test without auto-flushing.
        //
        ctl.holdAdapter();
        backgroundBatchOneway.op();
        backgroundBatchOneway.op();
        backgroundBatchOneway.op();
        backgroundBatchOneway.op();
        ctl.resumeAdapter();
        backgroundBatchOneway.ice_flushBatchRequests();

        //
        // Send bigger requests to test with auto-flushing.
        //
        ctl.holdAdapter();
        backgroundBatchOneway.opWithPayload(seq);
        backgroundBatchOneway.opWithPayload(seq);
        backgroundBatchOneway.opWithPayload(seq);
        backgroundBatchOneway.opWithPayload(seq);
        ctl.resumeAdapter();
        backgroundBatchOneway.ice_flushBatchRequests();

        //
        // Then try the same thing with async flush.
        //

        ctl.holdAdapter();
        backgroundBatchOneway.op();
        backgroundBatchOneway.op();
        backgroundBatchOneway.op();
        backgroundBatchOneway.op();
        ctl.resumeAdapter();
        backgroundBatchOneway.begin_ice_flushBatchRequests();
        closeConnection(backgroundBatchOneway);

        ctl.holdAdapter();
        backgroundBatchOneway.opWithPayload(seq);
        backgroundBatchOneway.opWithPayload(seq);
        backgroundBatchOneway.opWithPayload(seq);
        backgroundBatchOneway.opWithPayload(seq);
        ctl.resumeAdapter();
        Ice.AsyncResult r3 = backgroundBatchOneway.begin_ice_flushBatchRequests();
        //
        // We can't close the connection before ensuring all the batches have been sent since
        // with auto-flushing the close connection message might be sent once the first call
        // opWithPayload is sent and before the flushBatchRequests (this would therefore result
        // in the flush to report a CloseConnectionException). Instead we flush a second time
        // with the same callback to wait for the first flush to complete.
        //
        //backgroundBatchOneway.ice_getConnection().close(false);
        backgroundBatchOneway.end_ice_flushBatchRequests(r3);
        closeConnection(backgroundBatchOneway);
    }
Exemple #2
0
    private static void readWriteTests(Configuration configuration, Test.BackgroundPrx background,
                                       Test.BackgroundControllerPrx ctl)
    {
        try
        {
            background.op();
        }
        catch (Ice.LocalException ex)
        {
            Console.Error.WriteLine(ex);
            test(false);
        }

        for (int i = 0; i < 2; ++i)
        {
            BackgroundPrx prx = i == 0 ? background : (BackgroundPrx)background.ice_oneway();

            try
            {
                prx.ice_ping();
                configuration.writeException(new Ice.SocketException());
                prx.op();
                test(false);
            }
            catch (Ice.SocketException)
            {
                configuration.writeException(null);
            }

            background.ice_ping();
            configuration.writeException(new Ice.SocketException());
            Ice.AsyncResult r = prx.begin_op();
            test(!r.sentSynchronously());
            try
            {
                prx.end_op(r);
                test(false);
            }
            catch (Ice.SocketException)
            {
            }
            test(r.IsCompleted);
            configuration.writeException(null);
        }

        try
        {
            background.ice_ping();
            configuration.readException(new Ice.SocketException());
            background.op();
            test(false);
        }
        catch (Ice.SocketException)
        {
            configuration.readException(null);
        }

        {
            background.ice_ping();
            configuration.readReady(false); // Required in C# to make sure beginRead() doesn't throw too soon.
            configuration.readException(new Ice.SocketException());
            Ice.AsyncResult r = background.begin_op();
            try
            {
                background.end_op(r);
                test(false);
            }
            catch (Ice.SocketException)
            {
            }
            test(r.IsCompleted);
            configuration.readException(null);
            configuration.readReady(true);
        }

        try
        {
            background.ice_ping();
            configuration.writeReady(false);
            background.op();
            configuration.writeReady(true);
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        try
        {
            background.ice_ping();
            configuration.readReady(false);
            background.op();
            configuration.readReady(true);
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        try
        {
            background.ice_ping();
            configuration.writeReady(false);
            configuration.writeException(new Ice.SocketException());
            background.op();
            test(false);
        }
        catch (Ice.SocketException)
        {
            configuration.writeReady(true);
            configuration.writeException(null);
        }

        for (int i = 0; i < 2; ++i)
        {
            BackgroundPrx prx = i == 0 ? background : (BackgroundPrx)background.ice_oneway();

            background.ice_ping();
            configuration.writeReady(false);
            configuration.writeException(new Ice.SocketException());
            Ice.AsyncResult r = prx.begin_op();
            test(!r.sentSynchronously());
            try
            {
                prx.end_op(r);
                test(false);
            }
            catch (Ice.SocketException)
            {
            }
            test(r.IsCompleted);
            configuration.writeReady(true);
            configuration.writeException(null);
        }

        try
        {
            background.ice_ping();
            configuration.readReady(false);
            configuration.readException(new Ice.SocketException());
            background.op();
            test(false);
        }
        catch (Ice.SocketException)
        {
            configuration.readException(null);
            configuration.readReady(true);
        }

        {
            background.ice_ping();
            configuration.readReady(false);
            configuration.readException(new Ice.SocketException());
            Ice.AsyncResult r = background.begin_op();
            try
            {
                background.end_op(r);
                test(false);
            }
            catch (Ice.SocketException)
            {
            }
            test(r.IsCompleted);
            configuration.readReady(true);
            configuration.readException(null);
        }

        {
            background.ice_ping();
            configuration.readReady(false);
            configuration.writeReady(false);
            configuration.readException(new Ice.SocketException());
            Ice.AsyncResult r = background.begin_op();
            // The read exception might propagate before the message send is seen as completed on IOCP.
            //r.waitForSent();
            try
            {
                background.end_op(r);
                test(false);
            }
            catch (Ice.SocketException)
            {
            }
            test(r.IsCompleted);
            configuration.writeReady(true);
            configuration.readReady(true);
            configuration.readException(null);
        }

        background.ice_ping(); // Establish the connection

        BackgroundPrx backgroundOneway = BackgroundPrxHelper.uncheckedCast(background.ice_oneway());

        test(backgroundOneway.ice_getConnection() == background.ice_getConnection());

        ctl.holdAdapter(); // Hold to block in request send.

        byte[] seq = new byte[10024];
        (new System.Random()).NextBytes(seq);
        OpAMICallback cbWP = new OpAMICallback();

        // Fill up the receive and send buffers
        for (int i = 0; i < 200; ++i) // 2MB
        {
            backgroundOneway.begin_opWithPayload(seq).whenCompleted(cbWP.noResponse, cbWP.noException);
        }

        OpAMICallback cb = new OpAMICallback();

        Ice.AsyncResult r1 = background.begin_op().whenCompleted(cb.response, cb.noException).whenSent(cb.sent);
        test(!r1.sentSynchronously() && !r1.isSent());

        OpAMICallback cb2 = new OpAMICallback();

        Ice.AsyncResult r2 = background.begin_op().whenCompleted(cb2.response, cb2.noException).whenSent(cb2.sent);
        test(!r2.sentSynchronously() && !r2.isSent());

        test(!backgroundOneway.begin_opWithPayload(seq).whenCompleted(cbWP.noResponse,
                                                                      cbWP.noException).sentSynchronously());
        test(!backgroundOneway.begin_opWithPayload(seq).whenCompleted(cbWP.noResponse,
                                                                      cbWP.noException).sentSynchronously());

        test(!cb.checkResponse(false));
        test(!cb2.checkResponse(false));
        ctl.resumeAdapter();
        cb.checkResponseAndSent();
        cb2.checkResponseAndSent();
        test(r1.isSent() && r1.IsCompleted);
        test(r2.isSent() && r2.IsCompleted);

        try
        {
            background.ice_ping();
            ctl.writeException(true);
            background.op();
            test(false);
        }
        catch (Ice.ConnectionLostException)
        {
            ctl.writeException(false);
        }

        try
        {
            background.ice_ping();
            ctl.readException(true);
            background.op();
            test(false);
        }
        catch (Ice.ConnectionLostException)
        {
            ctl.readException(false);
        }

        try
        {
            background.ice_ping();
            ctl.writeReady(false);
            background.op();
            ctl.writeReady(true);
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        try
        {
            background.ice_ping();
            ctl.readReady(false);
            background.op();
            ctl.readReady(true);
        }
        catch (Ice.LocalException)
        {
            test(false);
        }

        try
        {
            background.ice_ping();
            ctl.writeReady(false);
            ctl.writeException(true);
            background.op();
            test(false);
        }
        catch (Ice.ConnectionLostException)
        {
            ctl.writeException(false);
            ctl.writeReady(true);
        }

        try
        {
            background.ice_ping();
            ctl.readReady(false);
            ctl.readException(true);
            background.op();
            test(false);
        }
        catch (Ice.ConnectionLostException)
        {
            ctl.readException(false);
            ctl.readReady(true);
        }

        OpThread thread1 = new OpThread(background);
        OpThread thread2 = new OpThread(background);

        for (int i = 0; i < 5; i++)
        {
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            Thread.Sleep(10);
            configuration.writeException(new Ice.SocketException());
            try
            {
                background.op();
            }
            catch (Ice.LocalException)
            {
            }
            configuration.writeException(null);

            Thread.Sleep(10);

            background.ice_ping();
            background.ice_getCachedConnection().close(true);
            Thread.Sleep(10);

            background.ice_getCachedConnection().close(true);
        }

        thread1.destroy();
        thread2.destroy();

        thread1.Join();
        thread2.Join();
    }
Exemple #3
0
    private static void initializeTests(Configuration configuration, Test.BackgroundPrx background,
                                        Test.BackgroundControllerPrx ctl)
    {
        try
        {
            background.op();
        }
        catch (Ice.LocalException)
        {
            test(false);
        }
        background.ice_getConnection().close(false);

        for (int i = 0; i < 4; ++i)
        {
            if (i == 0 || i == 2)
            {
                configuration.initializeException(new Ice.SocketException());
            }
            else
            {
                continue;
            }
            BackgroundPrx prx = (i == 1 || i == 3) ? background : (BackgroundPrx)background.ice_oneway();

            try
            {
                prx.op();
                test(false);
            }
            catch (Ice.SocketException)
            {
            }

            Ice.AsyncResult r = prx.begin_op();
            test(!r.sentSynchronously());
            try
            {
                prx.end_op(r);
                test(false);
            }
            catch (Ice.Exception)
            {
            }
            test(r.IsCompleted);

            OpAMICallback cbEx = new OpAMICallback();
            r = prx.begin_op().whenCompleted(cbEx.exception);
            test(!r.sentSynchronously());
            cbEx.checkException(true);
            test(r.IsCompleted);

            if (i == 0 || i == 2)
            {
                configuration.initializeException(null);
            }
        }

        //
        // Now run the same tests with the server side.
        //

        try
        {
            ctl.initializeException(true);
            background.op();
            test(false);
        }
        catch (Ice.ConnectionLostException)
        {
            ctl.initializeException(false);
        }
        catch (Ice.SecurityException)
        {
            ctl.initializeException(false);
        }

        OpThread thread1 = new OpThread(background);
        OpThread thread2 = new OpThread(background);

        for (int i = 0; i < 5; i++)
        {
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            configuration.initializeException(new Ice.SocketException());
            background.ice_getCachedConnection().close(true);
            Thread.Sleep(10);
            configuration.initializeException(null);
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
            }
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            background.ice_getCachedConnection().close(true);
            background.ice_ping();

            ctl.initializeException(true);
            background.ice_getCachedConnection().close(true);
            Thread.Sleep(10);
            ctl.initializeException(false);
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
            }
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            try
            {
                background.ice_getCachedConnection().close(true);
                background.op();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }
        }

        thread1.destroy();
        thread2.destroy();

        thread1.Join();
        thread2.Join();
    }
Exemple #4
0
    private static void connectTests(Configuration configuration, Test.BackgroundPrx background)
    {
        try
        {
            background.op();
        }
        catch (Ice.LocalException ex)
        {
            System.Console.Out.WriteLine(ex);
            test(false);
        }
        background.ice_getConnection().close(false);

        for (int i = 0; i < 4; ++i)
        {
            if (i == 0 || i == 2)
            {
                configuration.connectorsException(new Ice.DNSException());
            }
            else
            {
                configuration.connectException(new Ice.SocketException());
            }
            BackgroundPrx prx = (i == 1 || i == 3) ? background : (BackgroundPrx)background.ice_oneway();

            try
            {
                prx.op();
                test(false);
            }
            catch (Ice.Exception)
            {
            }

            Ice.AsyncResult r = prx.begin_op();
            test(!r.sentSynchronously());
            try
            {
                prx.end_op(r);
                test(false);
            }
            catch (Ice.Exception)
            {
            }
            test(r.IsCompleted);

            OpAMICallback cbEx = new OpAMICallback();
            r = prx.begin_op().whenCompleted(cbEx.exception);
            test(!r.sentSynchronously());
            cbEx.checkException(true);
            test(r.IsCompleted);

            if (i == 0 || i == 2)
            {
                configuration.connectorsException(null);
            }
            else
            {
                configuration.connectException(null);
            }
        }

        OpThread thread1 = new OpThread(background);
        OpThread thread2 = new OpThread(background);

        for (int i = 0; i < 5; i++)
        {
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
                test(false);
            }

            configuration.connectException(new Ice.SocketException());
            background.ice_getCachedConnection().close(true);
            Thread.Sleep(10);
            configuration.connectException(null);
            try
            {
                background.ice_ping();
            }
            catch (Ice.LocalException)
            {
            }
        }

        thread1.destroy();
        thread2.destroy();

        thread1.Join();
        thread2.Join();
    }
Exemple #5
0
    private static void readWriteTests(Configuration configuration, Test.BackgroundPrx background,
                                       Test.BackgroundControllerPrx ctl)
    {
        try
        {
            background.op();
        }
        catch (LocalException ex)
        {
            Console.Error.WriteLine(ex);
            test(false);
        }

        for (int i = 0; i < 2; ++i)
        {
            BackgroundPrx prx = i == 0 ? background : background.Clone(oneway: true);

            try
            {
                prx.IcePing();
                configuration.writeException(new SocketException());
                prx.op();
                test(false);
            }
            catch (SocketException)
            {
                configuration.writeException(null);
            }

            background.IcePing();
            configuration.writeException(new SocketException());
            var sentSynchronously = false;
            var t = prx.opAsync(progress: new Progress <bool>(value =>
            {
                sentSynchronously = value;
            }));
            test(!sentSynchronously);
            try
            {
                t.Wait();
                test(false);
            }
            catch (AggregateException ex) when(ex.InnerException is SocketException)
            {
            }
            test(t.IsCompleted);
            configuration.writeException(null);
        }

        try
        {
            background.IcePing();
            configuration.readException(new SocketException());
            background.op();
            test(false);
        }
        catch (SocketException)
        {
            configuration.readException(null);
        }

        {
            background.IcePing();
            configuration.readReady(false); // Required in C# to make sure beginRead() doesn't throw too soon.
            configuration.readException(new SocketException());
            var t = background.opAsync();
            try
            {
                t.Wait();
                test(false);
            }
            catch (AggregateException ex) when(ex.InnerException is SocketException)
            {
            }
            test(t.IsCompleted);
            configuration.readException(null);
            configuration.readReady(true);
        }

        try
        {
            background.IcePing();
            configuration.writeReady(false);
            background.op();
            configuration.writeReady(true);
        }
        catch (LocalException)
        {
            test(false);
        }

        try
        {
            background.IcePing();
            configuration.readReady(false);
            background.op();
            configuration.readReady(true);
        }
        catch (LocalException)
        {
            test(false);
        }

        try
        {
            background.IcePing();
            configuration.writeReady(false);
            configuration.writeException(new SocketException());
            background.op();
            test(false);
        }
        catch (SocketException)
        {
            configuration.writeReady(true);
            configuration.writeException(null);
        }

        for (int i = 0; i < 2; ++i)
        {
            BackgroundPrx prx = i == 0 ? background : background.Clone(oneway: true);

            background.IcePing();
            configuration.writeReady(false);
            configuration.writeException(new SocketException());
            bool sentSynchronously = false;
            var  t = prx.opAsync(progress: new Progress <bool>(value =>
            {
                sentSynchronously = value;
            }));
            test(!sentSynchronously);
            try
            {
                t.Wait();
                test(false);
            }
            catch (AggregateException ex) when(ex.InnerException is SocketException)
            {
            }
            test(t.IsCompleted);
            configuration.writeReady(true);
            configuration.writeException(null);
        }

        try
        {
            background.IcePing();
            configuration.readReady(false);
            configuration.readException(new SocketException());
            background.op();
            test(false);
        }
        catch (SocketException)
        {
            configuration.readException(null);
            configuration.readReady(true);
        }

        {
            background.IcePing();
            configuration.readReady(false);
            configuration.readException(new SocketException());
            var t = background.opAsync();
            try
            {
                t.Wait();
                test(false);
            }
            catch (AggregateException ex) when(ex.InnerException is SocketException)
            {
            }
            test(t.IsCompleted);
            configuration.readReady(true);
            configuration.readException(null);
        }

        {
            background.IcePing();
            configuration.readReady(false);
            configuration.writeReady(false);
            configuration.readException(new SocketException());
            var t = background.opAsync();
            // The read exception might propagate before the message send is seen as completed on IOCP.
            //r.waitForSent();
            try
            {
                t.Wait();
                test(false);
            }
            catch (AggregateException ex) when(ex.InnerException is SocketException)
            {
            }
            test(t.IsCompleted);
            configuration.writeReady(true);
            configuration.readReady(true);
            configuration.readException(null);
        }

        background.IcePing(); // Establish the connection

        BackgroundPrx backgroundOneway = background.Clone(oneway: true);

        test(backgroundOneway.GetConnection() == background.GetConnection());

        ctl.holdAdapter(); // Hold to block in request send.

        byte[] seq = new byte[10024];
        (new System.Random()).NextBytes(seq);
        OpAMICallback cbWP = new OpAMICallback();

        // Fill up the receive and send buffers
        for (int i = 0; i < 200; ++i) // 2MB
        {
            backgroundOneway.opWithPayloadAsync(seq);
        }

        OpAMICallback cb     = new OpAMICallback();
        bool          t1Sent = false;
        var           t1     = background.opAsync(progress: new Progress <bool>(value =>
        {
            cb.sent(value);
            t1Sent = true;
        }));

        t1.ContinueWith(p =>
        {
            try
            {
                p.Wait();
                cb.response();
            }
            catch (Ice.Exception ex)
            {
                cb.exception(ex);
            }
        });
        test(!t1Sent);

        OpAMICallback cb2    = new OpAMICallback();
        var           t2Sent = false;
        var           t2     = background.opAsync(progress: new Progress <bool>(value =>
        {
            cb2.sent(value);
            t2Sent = true;
        }));

        t2.ContinueWith((Task p) =>
        {
            try
            {
                p.Wait();
                cb2.response();
            }
            catch (Ice.Exception ex)
            {
                cb2.noException(ex);
            }
        });
        test(!t2Sent);

        var t3SentSynchronously = false;
        var t3 = backgroundOneway.opWithPayloadAsync(seq, progress: new Progress <bool>(value =>
        {
            t3SentSynchronously = value;
        }));

        test(!t3SentSynchronously);
        t3.ContinueWith((Task p) =>
        {
            try
            {
                p.Wait();
                cbWP.noResponse();
            }
            catch (Ice.Exception ex)
            {
                cbWP.noException(ex);
            }
        });

        var t4SentSynchronously = false;
        var t4 = backgroundOneway.opWithPayloadAsync(seq, progress: new Progress <bool>(value =>
        {
            t4SentSynchronously = value;
        }));

        test(!t4SentSynchronously);
        t4.ContinueWith((Task p) =>
        {
            try
            {
                p.Wait();
                cbWP.noResponse();
            }
            catch (Ice.Exception ex)
            {
                cbWP.noException(ex);
            }
        });

        test(!cb.checkResponse(false));
        test(!cb2.checkResponse(false));
        ctl.resumeAdapter();
        cb.checkResponseAndSent();
        cb2.checkResponseAndSent();
        test(t1Sent);
        test(t1.IsCompleted);
        test(t2Sent);
        test(t2.IsCompleted);

        try
        {
            background.IcePing();
            ctl.writeException(true);
            background.op();
            test(false);
        }
        catch (ConnectionLostException)
        {
            ctl.writeException(false);
        }

        try
        {
            background.IcePing();
            ctl.readException(true);
            background.op();
            test(false);
        }
        catch (ConnectionLostException)
        {
            ctl.readException(false);
        }

        try
        {
            background.IcePing();
            ctl.writeReady(false);
            background.op();
            ctl.writeReady(true);
        }
        catch (LocalException)
        {
            test(false);
        }

        try
        {
            background.IcePing();
            ctl.readReady(false);
            background.op();
            ctl.readReady(true);
        }
        catch (LocalException)
        {
            test(false);
        }

        try
        {
            background.IcePing();
            ctl.writeReady(false);
            ctl.writeException(true);
            background.op();
            test(false);
        }
        catch (ConnectionLostException)
        {
            ctl.writeException(false);
            ctl.writeReady(true);
        }

        try
        {
            background.IcePing();
            ctl.readReady(false);
            ctl.readException(true);
            background.op();
            test(false);
        }
        catch (ConnectionLostException)
        {
            ctl.readException(false);
            ctl.readReady(true);
        }

        OpThread thread1 = new OpThread(background);
        OpThread thread2 = new OpThread(background);

        for (int i = 0; i < 5; i++)
        {
            try
            {
                background.IcePing();
            }
            catch (LocalException)
            {
                test(false);
            }

            Thread.Sleep(10);
            configuration.writeException(new SocketException());
            try
            {
                background.op();
            }
            catch (LocalException)
            {
            }
            configuration.writeException(null);

            Thread.Sleep(10);

            background.IcePing();
            background.GetCachedConnection() !.close(ConnectionClose.Forcefully);
            Thread.Sleep(10);

            background.GetCachedConnection() !.close(ConnectionClose.Forcefully);
        }

        thread1.destroy();
        thread2.destroy();

        thread1.Join();
        thread2.Join();
    }
Exemple #6
0
    private static void initializeTests(Configuration configuration, BackgroundPrx background,
                                        BackgroundControllerPrx ctl)
    {
        try
        {
            background.op();
        }
        catch (LocalException)
        {
            test(false);
        }
        background.GetConnection().close(ConnectionClose.GracefullyWithWait);

        for (int i = 0; i < 4; ++i)
        {
            if (i == 0 || i == 2)
            {
                configuration.initializeException(new SocketException());
            }
            else
            {
                continue;
            }
            BackgroundPrx prx = (i == 1 || i == 3) ? background : background.Clone(oneway: true);

            try
            {
                prx.op();
                test(false);
            }
            catch (SocketException)
            {
            }

            bool sentSynchronously = false;
            var  t = prx.opAsync(progress: new Progress <bool>(value =>
            {
                sentSynchronously = value;
            }));
            test(!sentSynchronously);
            try
            {
                t.Wait();
                test(false);
            }
            catch (AggregateException ex) when(ex.InnerException is Ice.Exception)
            {
            }
            test(t.IsCompleted);

            OpAMICallback cbEx = new OpAMICallback();
            t = prx.opAsync(progress: new Progress <bool>(value =>
            {
                sentSynchronously = false;
            }));
            test(!sentSynchronously);
            try
            {
                t.Wait();
            }
            catch (AggregateException ex) when(ex.InnerException is Ice.Exception)
            {
                cbEx.exception((Ice.Exception)ex.InnerException);
            }
            cbEx.checkException(true);
            test(t.IsCompleted);

            if (i == 0 || i == 2)
            {
                configuration.initializeException(null);
            }
        }

        //
        // Now run the same tests with the server side.
        //

        try
        {
            ctl.initializeException(true);
            background.op();
            test(false);
        }
        catch (ConnectionLostException)
        {
            ctl.initializeException(false);
        }
        catch (SecurityException)
        {
            ctl.initializeException(false);
        }

        OpThread thread1 = new OpThread(background);
        OpThread thread2 = new OpThread(background);

        for (int i = 0; i < 5; i++)
        {
            try
            {
                background.IcePing();
            }
            catch (LocalException)
            {
                test(false);
            }

            configuration.initializeException(new SocketException());
            background.GetCachedConnection() !.close(ConnectionClose.Forcefully);
            Thread.Sleep(10);
            configuration.initializeException(null);
            try
            {
                background.IcePing();
            }
            catch (LocalException)
            {
            }
            try
            {
                background.IcePing();
            }
            catch (LocalException)
            {
                test(false);
            }

            background.GetCachedConnection() !.close(ConnectionClose.Forcefully);
            background.IcePing();

            ctl.initializeException(true);
            background.GetCachedConnection() !.close(ConnectionClose.Forcefully);
            Thread.Sleep(10);
            ctl.initializeException(false);
            try
            {
                background.IcePing();
            }
            catch (LocalException)
            {
            }
            try
            {
                background.IcePing();
            }
            catch (LocalException)
            {
                test(false);
            }

            try
            {
                background.GetCachedConnection() !.close(ConnectionClose.Forcefully);
                background.op();
            }
            catch (LocalException)
            {
                test(false);
            }
        }

        thread1.destroy();
        thread2.destroy();

        thread1.Join();
        thread2.Join();
    }
Exemple #7
0
    private static void connectTests(Configuration configuration, Test.BackgroundPrx background)
    {
        try
        {
            background.op();
        }
        catch (LocalException ex)
        {
            System.Console.Out.WriteLine(ex);
            test(false);
        }
        background.GetConnection().close(ConnectionClose.GracefullyWithWait);

        for (int i = 0; i < 4; ++i)
        {
            if (i == 0 || i == 2)
            {
                configuration.connectorsException(new DNSException());
            }
            else
            {
                configuration.connectException(new SocketException());
            }
            BackgroundPrx prx = (i == 1 || i == 3) ? background : background.Clone(oneway: true);

            try
            {
                prx.op();
                test(false);
            }
            catch (Ice.Exception)
            {
            }

            var sentSynchronously = false;
            var t = prx.opAsync(progress: new Progress <bool>(value =>
            {
                sentSynchronously = value;
            }));
            test(!sentSynchronously);
            try
            {
                t.Wait();
                test(false);
            }
            catch (AggregateException ex) when(ex.InnerException is Ice.Exception)
            {
            }
            test(t.IsCompleted);

            OpAMICallback cbEx = new OpAMICallback();
            t = prx.opAsync(progress: new Progress <bool>(value =>
            {
                sentSynchronously = value;
            }));
            test(!sentSynchronously);

            t.ContinueWith((Task p) =>
            {
                try
                {
                    p.Wait();
                }
                catch (AggregateException ex) when(ex.InnerException is Ice.Exception)
                {
                    cbEx.exception((Ice.Exception)ex.InnerException);
                }
            });
            cbEx.checkException(true);
            test(t.IsCompleted);

            if (i == 0 || i == 2)
            {
                configuration.connectorsException(null);
            }
            else
            {
                configuration.connectException(null);
            }
        }

        OpThread thread1 = new OpThread(background);
        OpThread thread2 = new OpThread(background);

        try
        {
            for (int i = 0; i < 5; i++)
            {
                try
                {
                    background.IcePing();
                }
                catch (LocalException)
                {
                    test(false);
                }

                configuration.connectException(new SocketException());
                background.GetCachedConnection() !.close(ConnectionClose.Forcefully);
                Thread.Sleep(10);
                configuration.connectException(null);
                try
                {
                    background.IcePing();
                }
                catch (LocalException)
                {
                }
            }
        }
        catch (System.Exception ex)
        {
            Console.Out.WriteLine(ex);
            test(false);
        }
        finally
        {
            thread1.destroy();
            thread2.destroy();

            thread1.Join();
            thread2.Join();
        }
    }