summaryrefslogtreecommitdiff
path: root/js/test/Ice/retry/Client.js
blob: c28c640312513a5755a3e1edb7c1d85dfe10f453 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// **********************************************************************
//
// Copyright (c) 2003-present ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

(function(module, require, exports)
{
    const Ice = require("ice").Ice;
    const Test = require("Test").Test;
    const TestHelper = require("TestHelper").TestHelper;
    const test = TestHelper.test;

    class Client extends TestHelper
    {
        async allTests(communicator, communicator2)
        {
            const out = this.getWriter();
            out.write("testing stringToProxy... ");
            const ref = "retry:" + this.getTestEndpoint();
            const base1 = communicator.stringToProxy(ref);
            test(base1 !== null);
            const base2 = communicator.stringToProxy(ref);
            test(base2 !== null);
            out.writeLine("ok");

            out.write("testing checked cast... ");
            const retry1 = await Test.RetryPrx.checkedCast(base1);
            test(retry1 !== null);
            test(retry1.equals(base1));
            let retry2 = await Test.RetryPrx.checkedCast(base2);
            test(retry2 !== null);
            test(retry2.equals(base2));
            out.writeLine("ok");

            out.write("calling regular operation with first proxy... ");
            await retry1.op(false);
            out.writeLine("ok");

            out.write("calling operation to kill connection with second proxy... ");
            try
            {
                await retry2.op(true);
                test(false);
            }
            catch(ex)
            {
                if(typeof window === 'undefined' && typeof WorkerGlobalScope === 'undefined') // Nodejs
                {
                    test(ex instanceof Ice.ConnectionLostException, ex);
                }
                else // Browser
                {
                    test(ex instanceof Ice.SocketException, ex);
                }
                out.writeLine("ok");
            }

            out.write("calling regular operation with first proxy again... ");
            await retry1.op(false);
            out.writeLine("ok");

            out.write("testing idempotent operation... ");
            const count = await retry1.opIdempotent(4);
            test(count === 4);
            out.writeLine("ok");

            out.write("testing non-idempotent operation... ");
            try
            {
                await retry1.opNotIdempotent();
                test(false);
            }
            catch(ex)
            {
                test(ex instanceof Ice.LocalException, ex);
            }
            out.writeLine("ok");

            out.write("testing invocation timeout and retries... ");
            retry2 = Test.RetryPrx.uncheckedCast(communicator2.stringToProxy(retry1.toString()));
            try
            {
                await retry2.ice_invocationTimeout(500).opIdempotent(4);
                test(false);
            }
            catch(ex)
            {
                test(ex instanceof Ice.InvocationTimeoutException, ex);
            }

            await retry2.opIdempotent(-1);
            out.writeLine("ok");

            await retry1.shutdown();
        }

        async run(args)
        {
            let communicator;
            let communicator2;
            try
            {
                let [properties] = this.createTestProperties(args);

                //
                // For this test, we want to disable retries.
                //
                properties.setProperty("Ice.RetryIntervals", "0 1 10 1");

                //
                // We don't want connection warnings because of the timeout
                //
                properties.setProperty("Ice.Warn.Connections", "0");

                [communicator] = this.initialize(properties);

                //
                // Configure a second communicator for the invocation timeout
                // + retry test, we need to configure a large retry interval
                // to avoid time-sensitive failures.
                //
                properties = communicator.getProperties().clone();
                properties.setProperty("Ice.RetryIntervals", "0 1 10000");
                [communicator2] = this.initialize(properties);

                await this.allTests(communicator, communicator2);
            }
            finally
            {
                if(communicator2)
                {
                    await communicator2.destroy();
                }

                if(communicator)
                {
                    await communicator.destroy();
                }
            }
        }
    }
    exports.Client = Client;
}(typeof global !== "undefined" && typeof global.process !== "undefined" ? module : undefined,
  typeof global !== "undefined" && typeof global.process !== "undefined" ? require :
  (typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope) ? self.Ice._require : window.Ice._require,
  typeof global !== "undefined" && typeof global.process !== "undefined" ? exports :
  (typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope) ? self : window));