All files / test/Ice/adapterDeactivation Client.js

94.73% Statements 144/152
44.44% Branches 4/9
100% Functions 2/2
94.73% Lines 144/152

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 1531x 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 10x 10x 10x 10x 10x 10x 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  
// 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 out = this.getWriter();
        const communicator = this.communicator();
        const obj = new Test.TestIntfPrx(communicator, `test:${this.getTestEndpoint()}`);
        {
            out.write("creating/destroying/recreating object adapter... ");
            communicator.getProperties().setProperty("TransientTestAdapter.ProxyOptions", "-t");
            const adapter = await communicator.createObjectAdapter("TransientTestAdapter");
            try {
                await communicator.createObjectAdapter("TransientTestAdapter");
                test(false);
            }
            catch (ex) {
                test(ex instanceof Ice.AlreadyRegisteredException);
            }
            adapter.destroy();
            out.writeLine("ok");
        }
        out.write("creating/activating/deactivating object adapter in one operation... ");
        await obj.transient();
        out.writeLine("ok");
        out.write("testing connection closure... ");
        for (let i = 0; i < 10; ++i) {
            const initData = new Ice.InitializationData();
            initData.properties = communicator.getProperties().clone();
            const comm = new Ice.Communicator(initData);
            await new Ice.ObjectPrx(comm, `test:${this.getTestEndpoint()}`).ice_ping();
            await comm.destroy();
        }
        out.writeLine("ok");
        out.write("testing object adapter published endpoints... ");
        {
            communicator
                .getProperties()
                .setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000");
            const adapter = await communicator.createObjectAdapter("PAdapter");
            test(adapter.getPublishedEndpoints().length === 1);
            const endpt = adapter.getPublishedEndpoints()[0];
            test(endpt.toString() == "tcp -h localhost -p 12345 -t 30000");
            const prx = new Ice.ObjectPrx(communicator, "dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000");
            adapter.setPublishedEndpoints(prx.ice_getEndpoints());
            test(adapter.getPublishedEndpoints().length === 2);
            const id = new Ice.Identity();
            id.name = "dummy";
            test(Ice.ArrayUtil.equals(adapter.createProxy(id).ice_getEndpoints(), prx.ice_getEndpoints()));
            test(Ice.ArrayUtil.equals(adapter.getPublishedEndpoints(), prx.ice_getEndpoints()));
            adapter.destroy();
            test(adapter.getPublishedEndpoints().length === 0);
        }
        out.writeLine("ok");
        out.write("testing object adapter with bi-dir connection... ");
        {
            test(communicator.getDefaultObjectAdapter() === null);
            test(obj.ice_getCachedConnection().getAdapter() === null);
            let adapter = await communicator.createObjectAdapter("");
            communicator.setDefaultObjectAdapter(adapter);
            test(communicator.getDefaultObjectAdapter() === adapter);
            // create new connection
            await obj.ice_getCachedConnection().close();
            await obj.ice_ping();
            test(obj.ice_getCachedConnection().getAdapter() === adapter);
            // Ensure destroying the OA doesn't affect the ability to send outgoing requests.
            adapter.destroy();
            await obj.ice_getCachedConnection().close();
            await obj.ice_ping();
            communicator.setDefaultObjectAdapter(null);
            // create new connection
            await obj.ice_getCachedConnection().close();
            await obj.ice_ping();
            test(obj.ice_getCachedConnection().getAdapter() === null);
            adapter = await communicator.createObjectAdapter("");
            obj.ice_getCachedConnection().setAdapter(adapter);
            test(obj.ice_getCachedConnection().getAdapter() === adapter);
            obj.ice_getCachedConnection().setAdapter(null);
            adapter.destroy();
            try {
                (await obj.ice_getConnection()).setAdapter(adapter);
                test(false);
            }
            catch (ex) {
                test(ex instanceof Ice.ObjectAdapterDestroyedException);
            }
        }
        out.writeLine("ok");
        out.write("testing object adapter with router... ");
        {
            const routerId = new Ice.Identity();
            routerId.name = "router";
            let router = Ice.RouterPrx.uncheckedCast(obj.ice_identity(routerId).ice_connectionId("rc"));
            const adapter = await communicator.createObjectAdapterWithRouter("", router);
            test(adapter.getPublishedEndpoints().length == 1);
            test(adapter.getPublishedEndpoints()[0].toString() == "tcp -h localhost -p 23456 -t 30000");
            try {
                adapter.setPublishedEndpoints(router.ice_getEndpoints());
                test(false);
            }
            catch (ex) {
                // Expected.
                test(ex instanceof Error);
            }
            adapter.destroy();
            try {
                routerId.name = "test";
                router = new Ice.RouterPrx(communicator, `test:${this.getTestEndpoint(0)}`);
                await communicator.createObjectAdapterWithRouter("", router);
                test(false);
            }
            catch (ex) {
                // Expected: the "test" object doesn't implement Ice::Router!
                test(ex instanceof Ice.OperationNotExistException);
            }
            try {
                router = new Ice.RouterPrx(communicator, `router:${this.getTestEndpoint(1)}`);
                await communicator.createObjectAdapterWithRouter("", router);
                test(false);
            }
            catch (ex) {
                test(ex instanceof Ice.ConnectFailedException || ex instanceof Ice.ConnectTimeoutException);
            }
        }
        out.writeLine("ok");
        out.write("deactivating object adapter in the server... ");
        await obj.deactivate();
        out.writeLine("ok");
        out.write("testing whether server is gone... ");
        try {
            await obj.ice_invocationTimeout(100).ice_ping(); // Use timeout to speed up testing on Windows
            test(false);
        }
        catch (ex) {
            test(ex instanceof Ice.LocalException);
        }
        out.writeLine("ok");
    }
    async run(args) {
        let communicator = null;
        try {
            [communicator, args] = this.initialize(args);
            await this.allTests();
        }
        finally {
            if (communicator) {
                await communicator.destroy();
            }
        }
    }
}