summaryrefslogtreecommitdiff
path: root/js/test/Ice/operations/Client.js
blob: 4c9f768b432958a9abdf1f822dcf363123dcb529 (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
// **********************************************************************
//
// 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 Twoways = require("Twoways").Twoways;
    const Oneways = require("Oneways").Oneways;
    const BatchOneways = require("BatchOneways").BatchOneways;

    class Client extends TestHelper
    {
        async allTests(Test, bidir)
        {
            const out = this.getWriter();
            const communicator = this.communicator();
            out.write("testing twoway operations... ");
            const ref = "test:" + this.getTestEndpoint();
            const base = communicator.stringToProxy(ref);
            const cl = await Test.MyClassPrx.checkedCast(base);
            const derived = await Test.MyDerivedClassPrx.checkedCast(cl);

            await Twoways.run(communicator, cl, Test, bidir, this);
            await Twoways.run(communicator, derived, Test, bidir, this);
            out.writeLine("ok");

            out.write("testing oneway operations... ");
            await Oneways.run(communicator, cl, Test, bidir);
            out.writeLine("ok");

            out.write("testing batch oneway operations... ");
            await BatchOneways.run(communicator, cl, Test, bidir);
            out.writeLine("ok");

            out.write("testing server shutdown... ");
            await cl.shutdown();
            try
            {
                await cl.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows
                throw new Error("test failed");
            }
            catch(ex)
            {
                if(ex instanceof Ice.LocalException)
                {
                    out.writeLine("ok");
                }
                else
                {
                    throw ex;
                }
            }
        }

        async run(args)
        {
            let communicator;
            try
            {
                const [properties] = this.createTestProperties(args);
                properties.setProperty("Ice.BatchAutoFlushSize", "100");
                [communicator] = this.initialize(properties);
                await this.allTests(Test, false);
            }
            finally
            {
                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));