static void checkParser(GmqPathHelper.PathComponents pc, String path, PublishableStateMessageHeader.MsgType msgType)
        {
            GmqPathHelper.PathComponents result = new GmqPathHelper.PathComponents();
            result.type = msgType;
            Assert.True(GmqPathHelper.parse(path, result));

            Assert.AreEqual(pc, result);
        }
        public static void TestException5()
        {
            GmqPathHelper.PathComponents pc = new GmqPathHelper.PathComponents();
            pc.type     = PublishableStateMessageHeader.MsgType.subscriptionRequest;
            pc.nodeName = "";
            pc.statePublisherOrConnectionType = "StructSix";

            Assert.Throws <ArgumentException>(() => { GmqPathHelper.compose(pc); });
        }
        static String getSubscriptionAddress(String publisher)
        {
            GmqPathHelper.PathComponents pc = new GmqPathHelper.PathComponents();
            pc.type     = PublishableStateMessageHeader.MsgType.subscriptionRequest;
            pc.nodeName = "test_node";
            pc.statePublisherOrConnectionType = publisher;
            string path = GmqPathHelper.compose(pc);

            return(path);
        }
        public static void Test10()
        {
            GmqPathHelper.PathComponents pc = new GmqPathHelper.PathComponents();
            pc.type     = PublishableStateMessageHeader.MsgType.subscriptionRequest;
            pc.nodeName = "test_node";
            pc.statePublisherOrConnectionType = "StructSix";

            string path = GmqPathHelper.compose(pc);

            Assert.AreEqual("globalmq:/test_node?sp=StructSix", path);

            checkParser(pc, path, PublishableStateMessageHeader.MsgType.subscriptionRequest);
        }
        public static void Test15()
        {
            GmqPathHelper.PathComponents pc = new GmqPathHelper.PathComponents();
            pc.type     = PublishableStateMessageHeader.MsgType.subscriptionRequest;
            pc.nodeName = "test_node";
            pc.statePublisherOrConnectionType = "StructSix";
            pc.authority         = "authority";
            pc.furtherResolution = true;
            pc.hasPort           = true;
            pc.port = 8080;

            string path = GmqPathHelper.compose(pc);

            Assert.AreEqual("globalmq://authority!gmq:8080/test_node?sp=StructSix", path);

            checkParser(pc, path, PublishableStateMessageHeader.MsgType.subscriptionRequest);
        }
예제 #6
0
        public void onMessage(IPublishableParser parser)
        {
            PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
            GMQueue.helperParsePublishableStateMessageBegin(parser, ref mh);
            switch (mh.type)
            {
                case PublishableStateMessageHeader.MsgType.connectionRequest:
                    {
                        GmqPathHelper.PathComponents pc = new GmqPathHelper.PathComponents();
                        pc.type = PublishableStateMessageHeader.MsgType.connectionRequest;
                        bool pathOK = GmqPathHelper.parse(mh.path, pc);
                        if (!pathOK)
                            throw new Exception(); // TODO: ... (bad path)

                        //auto f = connFactories.find(pc.statePublisherOrConnectionType);
                        //if (f == connFactories.end())
                        //	throw std::exception(); // TODO:  ... (no factory for conn name)
                        //auto & connFactory = *f->second;
                        IConnectionFactory connFactory = connFactories[pc.statePublisherOrConnectionType];

                        ServerConnection sc = new ServerConnection();
                        sc.connection = connFactory.create();
                        sc.ref_id_at_client = mh.ref_id_at_subscriber;
                        sc.ref_id_at_server = ++connIdxBase;
                        //sc.connection->pool = this;
                        //sc.connection->connID = sc.ref_id_at_server;
                        //sc.connection->status = ConnectionT::Status::connected;
                        sc.connection.setServerConnected(this, sc.ref_id_at_server);
                        /*auto ins = */
                        connections.Add(sc.ref_id_at_server, sc);
                        //assert(ins.second);

                        PublishableStateMessageHeader hdrBack = new PublishableStateMessageHeader();
                        hdrBack.type = PublishableStateMessageHeader.MsgType.connectionAccepted;
                        hdrBack.state_type_id_or_direction = (ulong)PublishableStateMessageHeader.ConnMsgDirection.toClient;
                        hdrBack.priority = mh.priority; // TODO: source?
                        hdrBack.ref_id_at_subscriber = mh.ref_id_at_subscriber;
                        hdrBack.ref_id_at_publisher = sc.ref_id_at_server;

                        BufferT msgBack = platform.makeBuffer();
                        IPublishableComposer composer = platform.makePublishableComposer(msgBack);
                        GMQueue.helperComposePublishableStateMessageBegin(composer, hdrBack);
                        GMQueue.helperComposePublishableStateMessageEnd(composer);
                        //assert(transport != nullptr);
                        transport.postMessage(msgBack);

                        break;
                    }
                case PublishableStateMessageHeader.MsgType.connectionMessage:
                    {
                        Debug.Assert(mh.state_type_id_or_direction == (ulong)PublishableStateMessageHeader.ConnMsgDirection.toServer);
                        //auto f = connections.find(mh.ref_id_at_publisher);
                        //if (f == connections.end())
                        //	throw std::exception();
                        //auto & conn = f->second;
                        ServerConnection conn = connections[mh.ref_id_at_publisher];
                        Debug.Assert(conn.ref_id_at_server == mh.ref_id_at_publisher); // self-consistency
                                                                                       //auto riter = parser.getIterator();
                        conn.connection.onMessage(parser.getIterator());
                        //parser = riter;
                        break;
                    }
                default:
                    throw new Exception(); // TODO: ... (unknown msg type)
            }
            GMQueue.helperParsePublishableStateMessageEnd(parser);
        }
        public static void TestException2()
        {
            GmqPathHelper.PathComponents pc = new GmqPathHelper.PathComponents();

            Assert.Throws <ArgumentException>(() => { GmqPathHelper.compose(pc); });
        }
 public static void TestException1()
 {
     Assert.Throws <ArgumentException>(() => { GmqPathHelper.compose(null); });
 }