static void TestComposeStateSync(Protocol proto, String fileName, Func <mtest.publishable_dictionary> getState)
        {
            mtest.publishable_dictionary_publisher publ = new mtest.publishable_dictionary_publisher();
            mtest.publishable_dictionary           data = getState();
            publ.debugOnlySetData(data);

            SimpleBuffer         buffer   = new SimpleBuffer();
            IPublishableComposer composer = makePublishableComposer(proto, buffer);

            publ.generateStateSyncMessage(composer);

            // uncomment to update file
            if (WriteFiles)
            {
                buffer.writeToFile(fileName);
            }

            SimpleBuffer expected = SimpleBuffer.readFromFile(fileName);

            if (proto == Protocol.Json)
            {
                Assert.True(SimpleBuffer.AreEqualIgnoreEol(expected, buffer));
            }
            else if (proto == Protocol.Gmq)
            {
                Assert.AreEqual(expected, buffer);
            }
        }
示例#2
0
        public void postMessage(UInt64 connID, BufferT msgBuff)
        {
            //auto f = connections.find(connID);
            //assert(f != connections.end());
            //auto & conn = f->second;
            ClientConnection conn = connections[connID];
            Debug.Assert(conn.ref_id_at_client == connID); // self-consistency
            BufferT buff = platform.makeBuffer();
            IPublishableComposer composer = platform.makePublishableComposer(buff);
            PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
            mh.type = PublishableStateMessageHeader.MsgType.connectionMessage;
            mh.priority = 0; // TODO: source
            mh.state_type_id_or_direction = (UInt64)PublishableStateMessageHeader.ConnMsgDirection.toServer;
            Debug.Assert(conn.ref_id_at_client == connID);
            mh.ref_id_at_subscriber = conn.ref_id_at_client;
            Debug.Assert(conn.ref_id_at_server != 0);
            mh.ref_id_at_publisher = conn.ref_id_at_server;
            GMQueue.helperComposePublishableStateMessageBegin(composer, mh);
            ReadIteratorT riter = msgBuff.getReadIterator();

            composer.appendRaw(riter);

            GMQueue.helperComposePublishableStateMessageEnd(composer);
            //assert(transport != nullptr);
            transport.postMessage(buff);
        }
示例#3
0
        static void TestComposeUpdate(TestCommon.Protocol proto, String fileName, Func <mtest.publishable_dictionary> getState, Action <mtest.Ipublishable_dictionary> updateDelegate)
        {
            mtest.publishable_dictionary_publisher publ = new mtest.publishable_dictionary_publisher();
            mtest.publishable_dictionary           data = getState();
            publ.debugOnlySetData(data);

            SimpleBuffer         buffer   = new SimpleBuffer();
            IPublishableComposer composer = TestCommon.makePublishableComposer(proto, buffer);

            publ.startTick(composer);

            updateDelegate(publ);

            publ.endTick();

            if (WriteFiles)
            {
                buffer.writeToFile(fileName);
            }

            SimpleBuffer expected = SimpleBuffer.readFromFile(fileName);

            if (proto == TestCommon.Protocol.Json)
            {
                Assert.True(SimpleBuffer.AreEqualIgnoreEol(expected, buffer));
            }
            else if (proto == TestCommon.Protocol.Gmq)
            {
                Assert.AreEqual(expected, buffer);
            }
        }
 public PublisherVectorWrapper(IList <T> t, IPublishableComposer composer, UInt64[] address,
                               Action <IPublishableComposer, T> composeDelegate, Func <T, IPublishableComposer, UInt64[], T> elementWrapperDelegate)
 {
     this.t                      = t;
     this.composer               = composer;
     this.address                = address;
     this.composeDelegate        = composeDelegate;
     this.elementWrapperDelegate = elementWrapperDelegate;
 }
        static void TestParseComposeUpdate(TestCommon.Protocol proto, String fileNameInit, String fileName, Action <mtest.Ipublishable_html_tag> updateDelegate)
        {
            mtest.publishable_html_tag_publisher publ = new mtest.publishable_html_tag_publisher();

            SimpleBuffer       bufferInit = SimpleBuffer.readFromFile(fileNameInit);
            IPublishableParser parserInit = TestCommon.makePublishableParser(proto, bufferInit.getReadIterator());

            publ.applyStateSyncMessage(parserInit);


            mtest.publishable_html_tag_subscriber subs = new mtest.publishable_html_tag_subscriber();


            SimpleBuffer       bufferInit2 = SimpleBuffer.readFromFile(fileNameInit);
            IPublishableParser parserInit2 = TestCommon.makePublishableParser(proto, bufferInit2.getReadIterator());

            subs.applyStateSyncMessage(parserInit2);

            // init state at publ and subs are equal
            Assert.True(publ.isEquivalent(subs));


            SimpleBuffer         buffer   = new SimpleBuffer();
            IPublishableComposer composer = TestCommon.makePublishableComposer(proto, buffer);

            publ.startTick(composer);

            updateDelegate(publ);

            publ.endTick();

            if (WriteFiles)
            {
                buffer.writeToFile(fileName);
            }

            SimpleBuffer expected = SimpleBuffer.readFromFile(fileName);

            if (proto == TestCommon.Protocol.Json)
            {
                Assert.True(SimpleBuffer.AreEqualIgnoreEol(expected, buffer));
            }
            else if (proto == TestCommon.Protocol.Gmq)
            {
                Assert.AreEqual(expected, buffer);
            }

            // now state is different

            Assert.False(publ.isEquivalent(subs));
            IPublishableParser parser = TestCommon.makePublishableParser(proto, buffer.getReadIterator());

            subs.applyMessageWithUpdates(parser);

            // now state is equal
            Assert.True(publ.isEquivalent(subs));
        }
 public PublisherDictionaryWrapper(IDictionary <K, V> t, IPublishableComposer composer, UInt64[] address,
                                   Action <IPublishableComposer, K, bool> composeKeyDelegate, Action <IPublishableComposer, V> composeValueDelegate,
                                   Func <K, V, IPublishableComposer, UInt64[], V> valueWrapperDelegate)
 {
     this.t                    = t;
     this.composer             = composer;
     this.address              = address;
     this.composeKeyDelegate   = composeKeyDelegate;
     this.composeValueDelegate = composeValueDelegate;
     this.valueWrapperDelegate = valueWrapperDelegate;
 }
        static void TestParseComposeStateSync(TestCommon.Protocol proto, String fileName, Action <mtest.Ipublishable_html_tag> updateDelegate)
        {
            mtest.publishable_html_tag_publisher publ = new mtest.publishable_html_tag_publisher();

            SimpleBuffer         bufferTmp   = new SimpleBuffer();
            IPublishableComposer composerTmp = TestCommon.makePublishableComposer(proto, bufferTmp);

            publ.startTick(composerTmp);

            updateDelegate(publ);

            publ.endTick();

            SimpleBuffer         buffer   = new SimpleBuffer();
            IPublishableComposer composer = TestCommon.makePublishableComposer(proto, buffer);

            publ.generateStateSyncMessage(composer);

            // uncomment to update file
            if (WriteFiles)
            {
                buffer.writeToFile(fileName);
            }

            SimpleBuffer expected = SimpleBuffer.readFromFile(fileName);

            if (proto == TestCommon.Protocol.Json)
            {
                Assert.True(SimpleBuffer.AreEqualIgnoreEol(expected, buffer));
            }
            else if (proto == TestCommon.Protocol.Gmq)
            {
                Assert.AreEqual(expected, buffer);
            }


            mtest.publishable_html_tag_subscriber subs = new mtest.publishable_html_tag_subscriber();

            IPublishableParser parser = TestCommon.makePublishableParser(proto, buffer.getReadIterator());

            subs.applyStateSyncMessage(parser);
            Assert.True(publ.isEquivalent(subs));
        }
示例#8
0
        internal static void TestComposeStateSync(ITestPlatformSupport platform, String fileName)
        {
            mtest.StructSix_publisher publ = new  mtest.StructSix_publisher();
            mtest.StructSix           data = GetPublishableSix();
            publ.debugOnlySetData(data);

            SimpleBuffer         buffer   = new SimpleBuffer();
            IPublishableComposer composer = platform.makePublishableComposer(buffer);

            publ.generateStateSyncMessage(composer);

            if (WriteFiles)
            {
                buffer.writeToFile(fileName);
            }

            SimpleBuffer expected = SimpleBuffer.readFromFile(fileName);

            Assert.True(platform.AreEqual(expected, buffer));
        }
示例#9
0
 public void connect(UInt64 connID, string path)
 {
     ClientConnection conn = connections[connID];
     //assert(f != connections.end());
     //auto & conn = f->second;
     Debug.Assert(conn.ref_id_at_client == connID); // self-consistency
     BufferT buff = platform.makeBuffer();
     IPublishableComposer composer = platform.makePublishableComposer(buff);
     PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
     mh.type = PublishableStateMessageHeader.MsgType.connectionRequest;
     mh.priority = 0; // TODO: source
     mh.state_type_id_or_direction = (UInt64)PublishableStateMessageHeader.ConnMsgDirection.toServer;
     mh.path = path;
     Debug.Assert(conn.ref_id_at_client == connID);
     mh.ref_id_at_subscriber = conn.ref_id_at_client;
     GMQueue.helperComposePublishableStateMessageBegin(composer, mh);
     GMQueue.helperComposePublishableStateMessageEnd(composer);
     transport.postMessage(buff);
     conn.connection.setRequestSent();
 }
        static void TestComposeUpdate(Protocol proto, String fileName, Func <mtest.publishable_dictionary> getState, Action <mtest.Ipublishable_dictionary> updateDelegate)
        {
            mtest.publishable_dictionary_publisher publ = new mtest.publishable_dictionary_publisher();
            mtest.publishable_dictionary           data = getState();
            publ.debugOnlySetData(data);

            SimpleBuffer         buffer   = new SimpleBuffer();
            IPublishableComposer composer = makePublishableComposer(proto, buffer);

            publ.startTick(composer);

            updateDelegate(publ);

            publ.endTick();

            if (WriteFiles)
            {
                buffer.writeToFile(fileName);
            }

            Assert.AreEqual(buffer, SimpleBuffer.readFromFile(fileName));
        }
示例#11
0
 public void subscribe(StateSubscriberBase subscriber, string path)
 {
     for (int i = 0; i < subscribers.Count; ++i)
         if (subscribers[i].subscriber == subscriber)
         {
             BufferT buff = platform.makeBuffer();
             IPublishableComposer composer = platform.makePublishableComposer(buff);
             PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
             mh.type = PublishableStateMessageHeader.MsgType.subscriptionRequest;
             mh.priority = 0; // TODO: source
             mh.state_type_id_or_direction = subscriber.stateTypeID();
             mh.path = path;
             Debug.Assert(subscribers[i].ref_id_at_subscriber == (ulong)i);
             mh.ref_id_at_subscriber = subscribers[i].ref_id_at_subscriber;
             GMQueue.helperComposePublishableStateMessageBegin(composer, mh);
             GMQueue.helperComposePublishableStateMessageEnd(composer);
             //assert(transport != nullptr);
             transport.postMessage(buff);
             return;
         }
     Debug.Assert(false); // not found
 }
        static void TestComposeUpdate(ITestPlatformSupport platform, String fileName, Action <mtest.Ipublishable_seven> updateDelegate)
        {
            mtest.publishable_seven_publisher publ = new mtest.publishable_seven_publisher();
            mtest.publishable_seven           data = GetPublishableSeven();
            publ.debugOnlySetData(data);

            SimpleBuffer         buffer   = new SimpleBuffer();
            IPublishableComposer composer = platform.makePublishableComposer(buffer);

            publ.startTick(composer);

            updateDelegate(publ);

            publ.endTick();

            if (WriteFiles)
            {
                buffer.writeToFile(fileName);
            }

            SimpleBuffer expected = SimpleBuffer.readFromFile(fileName);

            Assert.True(platform.AreEqual(expected, buffer));
        }
示例#13
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);
        }
示例#14
0
 public void startTick(IPublishableComposer composer) { publisher.startTick(composer); }
示例#15
0
 public void generateStateSyncMessage(IPublishableComposer composer)
 {
     publisher.generateStateSyncMessage(composer);
 }