All files / test/Ice/middleware Server.js

100% Statements 76/76
100% Branches 11/11
100% Functions 6/6
100% Lines 76/76

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 771x 1x 1x 1x 1x 1x 6x 3x 3x 3x 3x 3x 3x 3x 3x 6x 1x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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";
class Middleware extends Ice.Object {
    async dispatch(request) {
        if (request.current.operation === "shutdown") {
            return this._next.dispatch(request);
        }
        else {
            this._inLog.push(this._name);
            const response = await this._next.dispatch(request);
            this._outLog.push(this._name);
            return response;
        }
    }
    constructor(next, name, inLog, outLog) {
        super();
        this._next = next;
        this._name = name;
        this._inLog = inLog;
        this._outLog = outLog;
    }
}
class MyObjectI extends Test.MyObject {
    constructor() {
        super();
    }
    getName() {
        return "Foo";
    }
    shutdown(current) {
        current.adapter.getCommunicator().shutdown();
    }
}
export class Server extends TestHelper {
    async run(args) {
        let communicator = null;
        let echo = null;
        const inLog = [];
        const outLog = [];
        try {
            [communicator] = this.initialize(args);
            echo = new Test.EchoPrx(communicator, `__echo:${this.getTestEndpoint()}`);
            const adapter = await communicator.createObjectAdapter("");
            await echo.setConnection();
            echo.ice_getCachedConnection().setAdapter(adapter);
            this.serverReady();
            adapter.add(new MyObjectI(), new Ice.Identity("test"));
            adapter
                .use((next) => new Middleware(next, "A", inLog, outLog))
                .use((next) => new Middleware(next, "B", inLog, outLog))
                .use((next) => new Middleware(next, "C", inLog, outLog));
            await communicator.waitForShutdown();
        }
        finally {
            const out = this.getWriter();
            out.write("testing middleware execution order... ");
            test(inLog.length === 3);
            test(inLog[0] === "A");
            test(inLog[1] === "B");
            test(inLog[2] === "C");
            test(outLog.length === 3);
            test(outLog[0] === "C");
            test(outLog[1] === "B");
            test(outLog[2] === "A");
            out.writeLine("ok");
            if (echo) {
                await echo.shutdown();
            }
            if (communicator) {
                await communicator.destroy();
            }
        }
    }
}