All files / test/Ice/ami Client.js

98.9% Statements 272/275
88.88% Branches 16/18
100% Functions 5/5
98.9% Lines 272/275

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 2761x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 26x 26x 26x 25x 25x 1x 1x 1x 26x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 26x 26x 26x 25x 25x 1x 1x 1x 26x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
// Copyright (c) ZeroC, Inc.
import { Ice } from "@zeroc/ice";
import { Test } from "./Test.js";
import { TestHelper, test } from "../../Common/TestHelper.js";
export class Client extends TestHelper {
    async allTests() {
        const communicator = this.communicator();
        const out = this.getWriter();
        const p = new Test.TestIntfPrx(communicator, `test:${this.getTestEndpoint()}`);
        const testController = new Test.TestIntfControllerPrx(communicator, `testController:${this.getTestEndpoint(1)}`);
        out.write("testing batch requests with proxy... ");
        {
            const count = await p.opBatchCount();
            test(count === 0);
            const b1 = p.ice_batchOneway();
            const bf = b1.opBatch();
            test(bf.isCompleted());
            test(!bf.isSent());
            b1.opBatch();
            await b1.ice_flushBatchRequests();
            await p.waitForBatch(2);
            await b1.ice_flushBatchRequests();
        }
        out.writeLine("ok");
        out.write("testing batch requests with connection... ");
        {
            test((await p.opBatchCount()) === 0);
            const connection = await p.ice_getConnection();
            const b1 = Test.TestIntfPrx.uncheckedCast(connection.createProxy(p.ice_getIdentity()).ice_batchOneway());
            await b1.opBatch();
            await b1.opBatch();
            await connection.flushBatchRequests();
            test(await p.waitForBatch(2));
        }
        {
            test((await p.opBatchCount()) == 0);
            let connection = await p.ice_getConnection();
            const b1 = Test.TestIntfPrx.uncheckedCast(connection.createProxy(p.ice_getIdentity()).ice_batchOneway());
            await b1.opBatch();
            await connection.close();
            try {
                connection = await b1.ice_getConnection();
                await connection.flushBatchRequests();
                test(false);
            }
            catch (ex) {
                test(ex instanceof Ice.ConnectionClosedException);
            }
            test(await p.waitForBatch(0));
        }
        out.writeLine("ok");
        out.write("testing batch requests with communicator... ");
        {
            // Async task - 1 connection.
            test((await p.opBatchCount()) === 0);
            const connection = await p.ice_getConnection();
            const b1 = Test.TestIntfPrx.uncheckedCast(connection.createProxy(p.ice_getIdentity()).ice_batchOneway());
            await b1.opBatch();
            await b1.opBatch();
            await communicator.flushBatchRequests();
            test(await p.waitForBatch(2));
        }
        {
            // Async task exception - 1 connection.
            test((await p.opBatchCount()) === 0);
            const connection = await p.ice_getConnection();
            const b1 = Test.TestIntfPrx.uncheckedCast(connection.createProxy(p.ice_getIdentity()).ice_batchOneway());
            await b1.opBatch();
            await connection.close();
            await communicator.flushBatchRequests();
            test((await p.opBatchCount()) == 0);
        }
        {
            // Async task - 2 connections.
            test((await p.opBatchCount()) === 0);
            const connection1 = await p.ice_getConnection();
            const b1 = Test.TestIntfPrx.uncheckedCast(connection1.createProxy(p.ice_getIdentity()).ice_batchOneway());
            const connection2 = await p.ice_connectionId("2").ice_getConnection();
            const b2 = Test.TestIntfPrx.uncheckedCast(connection2.createProxy(p.ice_getIdentity()).ice_batchOneway());
            await b2.ice_getConnection(); // Ensure connection is established.
            await b1.opBatch();
            await b1.opBatch();
            await b2.opBatch();
            await b2.opBatch();
            await communicator.flushBatchRequests();
            test(await p.waitForBatch(4));
        }
        {
            // AsyncResult exception - 2 connections - 1 failure.
            //
            // All connections should be flushed even if there are failures on some connections.
            // Exceptions should not be reported.
            test((await p.opBatchCount()) === 0);
            const connection1 = await p.ice_getConnection();
            const b1 = Test.TestIntfPrx.uncheckedCast(connection1.createProxy(p.ice_getIdentity()).ice_batchOneway());
            const connection2 = await p.ice_connectionId("2").ice_getConnection();
            const b2 = Test.TestIntfPrx.uncheckedCast(connection2.createProxy(p.ice_getIdentity()).ice_batchOneway());
            await b2.ice_getConnection(); // Ensure connection is established.
            await b1.opBatch();
            await b2.opBatch();
            await connection1.close();
            await communicator.flushBatchRequests();
            test(await p.waitForBatch(1));
        }
        {
            //
            // Async task exception - 2 connections - 2 failures.
            //
            // The sent callback should be invoked even if all connections fail.
            //
            test((await p.opBatchCount()) == 0);
            const connection1 = await p.ice_getConnection();
            const b1 = Test.TestIntfPrx.uncheckedCast(connection1.createProxy(p.ice_getIdentity()).ice_batchOneway());
            const connection2 = await p.ice_connectionId("2").ice_getConnection();
            const b2 = Test.TestIntfPrx.uncheckedCast(connection2.createProxy(p.ice_getIdentity()).ice_batchOneway());
            await b2.ice_getConnection(); // Ensure connection is established.
            await b1.opBatch();
            await b2.opBatch();
            await connection1.close();
            await connection2.close();
            await communicator.flushBatchRequests();
            test((await p.opBatchCount()) === 0);
        }
        out.writeLine("ok");
        out.write("testing AsyncResult operations... ");
        {
            let r1;
            let r2;
            {
                await testController.holdAdapter();
                const requests = [];
                try {
                    r1 = p.op();
                    const seq = new Uint8Array(100000);
                    while (true) {
                        r2 = p.opWithPayload(seq);
                        requests.push(r2);
                        if (r2.sentSynchronously()) {
                            await Ice.Promise.delay(0);
                        }
                        else {
                            break;
                        }
                    }
                    test((r1.sentSynchronously() && r1.isSent() && !r1.isCompleted()) ||
                        (!r1.sentSynchronously() && !r1.isCompleted()));
                    test(!r2.sentSynchronously() && !r2.isCompleted());
                    test(!r1.isCompleted());
                    test(!r2.isCompleted());
                }
                finally {
                    await testController.resumeAdapter();
                }
                await r1;
                test(r1.isSent());
                test(r1.isCompleted());
                await r2;
                test(r2.isSent());
                test(r2.isCompleted());
                await Promise.all(requests);
                test(r1.operation == "op");
                test(r2.operation == "opWithPayload");
            }
            {
                const r = p.ice_ping();
                test(r.operation === "ice_ping");
                test(r.communicator == communicator);
                test(r.proxy == p);
                await r;
            }
            //
            // Oneway
            //
            {
                let p2 = p.ice_oneway();
                const r = p2.ice_ping();
                test(r.operation === "ice_ping");
                test(r.communicator == communicator);
                test(r.proxy == p2);
                await r;
                //
                // Batch request via proxy
                //
                p2 = p.ice_batchOneway();
                p2.ice_ping();
                await p2.ice_flushBatchRequests();
            }
            {
                const con = p.ice_getCachedConnection();
                let p2 = p.ice_batchOneway();
                p2.ice_ping();
                await con.flushBatchRequests();
                p2 = p.ice_batchOneway();
                p2.ice_ping();
                await communicator.flushBatchRequests();
            }
        }
        {
            await testController.holdAdapter();
            const seq = new Uint8Array(new Array(100000));
            let r;
            const requests = [];
            while (true) {
                r = p.opWithPayload(seq);
                requests.push(r);
                if (r.sentSynchronously()) {
                    await Ice.Promise.delay(0);
                }
                else {
                    break;
                }
            }
            test(!r.isSent());
            const r1 = p.ice_ping();
            r1.then(() => test(false), (ex) => test(ex instanceof Ice.InvocationCanceledException));
            const r2 = p.ice_id();
            r2.then(() => test(false), (ex) => test(ex instanceof Ice.InvocationCanceledException));
            r1.cancel();
            r2.cancel();
            await testController.resumeAdapter();
            await Promise.all(requests);
            test(!r1.isSent() && r1.isCompleted());
            test(!r2.isSent() && r2.isCompleted());
        }
        {
            await testController.holdAdapter();
            const r1 = p.op();
            const r2 = p.ice_id();
            await p.ice_oneway().ice_ping();
            r1.cancel();
            const r1Result = r1.then(() => test(false), (ex) => test(ex instanceof Ice.InvocationCanceledException));
            r2.cancel();
            const r2Result = r2.then(() => test(false), (ex) => test(ex instanceof Ice.InvocationCanceledException));
            await testController.resumeAdapter();
            await Promise.all([r1Result, r2Result]);
        }
        out.writeLine("ok");
        out.write("testing bi-dir... ");
        const adapter = await communicator.createObjectAdapter("");
        const replyI = new PingReplyI();
        const reply = Test.PingReplyPrx.uncheckedCast(adapter.addWithUUID(replyI));
        const context = new Map([["ONE", ""]]);
        await p.pingBiDir(reply, context);
        (await p.ice_getConnection()).setAdapter(adapter);
        await p.pingBiDir(reply);
        test(replyI.checkReceived());
        adapter.destroy();
        out.writeLine("ok");
        await p.shutdown();
    }
    async run(args) {
        let communicator = null;
        try {
            [communicator, args] = this.initialize(args);
            await this.allTests();
        }
        finally {
            if (communicator) {
                await communicator.destroy();
            }
        }
    }
}
class PingReplyI extends Test.PingReply {
    constructor() {
        super(...arguments);
        this._received = false;
    }
    reply(_) {
        this._received = true;
    }
    checkReceived() {
        return this._received;
    }
}