示例#1
0
        static void TestParseUpdate(TestCommon.Protocol proto, String fileNameInit, String fileName, Func <mtest.publishable_dictionary> getState, Action <mtest.Ipublishable_dictionary> updateDelegate)
        {
            mtest.publishable_dictionary_subscriber subs = new mtest.publishable_dictionary_subscriber();
            //mtest.publishable_dictionary data = getState();
            //subs.debugOnlySetData(data);
            SimpleBuffer       bufferInit = SimpleBuffer.readFromFile(fileNameInit);
            IPublishableParser parserInit = TestCommon.makePublishableParser(proto, bufferInit.getReadIterator());

            subs.applyStateSyncMessage(parserInit);

            mtest.publishable_dictionary expected = getState();
            Assert.True(expected.isEquivalent(subs));

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

            subs.applyMessageWithUpdates(parser);


            Assert.False(expected.isEquivalent(subs));

            updateDelegate(expected);

            Assert.True(expected.isEquivalent(subs));
        }
示例#2
0
        internal static void TestParseUpdate(ITestPlatformSupport platform, String fileNameInit, String fileName, Action <mtest.IStructSix> updateDelegate)
        {
            mtest.StructSix_subscriber subs = new  mtest.StructSix_subscriber();
            //subs.debugOnlySetData(GetPublishableSix());
            SimpleBuffer       bufferInit = SimpleBuffer.readFromFile(fileNameInit);
            IPublishableParser parserInit = platform.makePublishableParser(bufferInit.getReadIterator());

            subs.applyStateSyncMessage(parserInit);

            SimpleBuffer       buffer = SimpleBuffer.readFromFile(fileName);
            IPublishableParser parser = platform.makePublishableParser(buffer.getReadIterator());

            subs.applyMessageWithUpdates(parser);

            //mtest.StructSix actual = ( mtest.StructSix)subs.debugOnlyGetData();
            mtest.StructSix expected = GetPublishableSix();

            if (updateDelegate != null)
            {
                // not equal yet
                Assert.False(subs.isEquivalent(expected));

                updateDelegate(expected);
            }

            Assert.True(subs.isEquivalent(expected));
        }
        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));
        }
示例#4
0
        internal static void TestParseStateSync(ITestPlatformSupport platform, String fileName)
        {
            mtest.StructSix_subscriber subs = new  mtest.StructSix_subscriber();

            SimpleBuffer       buffer = SimpleBuffer.readFromFile(fileName);
            IPublishableParser parser = platform.makePublishableParser(buffer.getReadIterator());

            subs.applyStateSyncMessage(parser);

            Assert.True(subs.isEquivalent(GetPublishableSix()));
        }
        static void TestParseStateSync(Protocol proto, String fileName, Func <mtest.publishable_dictionary> getState)
        {
            mtest.publishable_dictionary_subscriber subs = new mtest.publishable_dictionary_subscriber();

            SimpleBuffer       buffer = SimpleBuffer.readFromFile(fileName);
            IPublishableParser parser = makePublishableParser(proto, buffer.getReadIterator());

            subs.applyStateSyncMessage(parser);

            mtest.publishable_dictionary expected = getState();

            Assert.True(expected.isEquivalent(subs));
        }
        static void TestParseStateSync(ITestPlatformSupport platform, String fileName)
        {
            mtest.publishable_seven_subscriber subs = new mtest.publishable_seven_subscriber();

            SimpleBuffer       buffer = SimpleBuffer.readFromFile(fileName);
            IPublishableParser parser = platform.makePublishableParser(buffer.getReadIterator());

            subs.applyStateSyncMessage(parser);

            //mtest.publishable_seven actual = (mtest.publishable_seven)subs.debugOnlyGetData();
            mtest.publishable_seven expected = GetPublishableSeven();

            Assert.True(expected.isEquivalent(subs));
        }
        static void TestParseUpdate(TestCommon.Protocol proto, String fileName, Func <mtest.publishable_cycle> getState, Action <mtest.Ipublishable_cycle> updateDelegate)
        {
            mtest.publishable_cycle_subscriber subs = new mtest.publishable_cycle_subscriber();

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

            subs.applyMessageWithUpdates(parser);

            mtest.publishable_cycle expected = getState();

            Assert.False(expected.isEquivalent(subs));

            updateDelegate(expected);

            Assert.True(expected.isEquivalent(subs));
        }
        public static bool parseVectorPrimitive <T>(IPublishableParser parser, IList <T> data, int index,
                                                    Func <IPublishableParser, T> elementParser, Action <int, T> notifyUpdate,
                                                    Action <int> notifyInsert, Action <int> notifyRemove)
        {
            bool changed = false;

            Publishable.ActionOnVector action = (Publishable.ActionOnVector)parser.parseActionInPublishable();
            switch (action)
            {
            case Publishable.ActionOnVector.update_at:
            {
                T newVal = elementParser(parser);
                if (!data[index].Equals(newVal))
                {
                    T oldVal = data[index];
                    data[index] = newVal;
                    changed     = true;
                    notifyUpdate(index, oldVal);
                }
                break;
            }

            case Publishable.ActionOnVector.insert_single_before:
            {
                T newVal = elementParser(parser);
                data.Insert(index, newVal);
                changed = true;
                notifyInsert(index);
                break;
            }

            case Publishable.ActionOnVector.remove_at:
            {
                data.RemoveAt(index);
                changed = true;
                notifyRemove(index);
                break;
            }

            default:
                throw new Exception();
            }

            return(changed);
        }
        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));
        }
示例#10
0
 public void onMessage(IPublishableParser parser)
 {
     PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
     GMQueue.helperParsePublishableStateMessageBegin(parser, ref mh);
     switch (mh.type)
     {
         case PublishableStateMessageHeader.MsgType.connectionAccepted:
             {
                 //auto f = connections.find(mh.ref_id_at_subscriber);
                 //if (f == connections.end())
                 //	throw std::exception();
                 //auto & conn = f->second;
                 ClientConnection conn = connections[mh.ref_id_at_subscriber];
                 Debug.Assert(conn.ref_id_at_client == mh.ref_id_at_subscriber); // self-consistency
                 conn.ref_id_at_server = mh.ref_id_at_publisher;
                 //if (conn.connection->status != ConnectionT::Status::connRequestSent)
                 //	throw std::exception(); // well, we have not requested connection yet
                 //conn.connection->status = ConnectionT::Status::connected;
                 conn.connection.setConnected();
                 conn.connection.onConnectionAccepted();
                 break;
             }
         case PublishableStateMessageHeader.MsgType.connectionMessage:
             {
                 Debug.Assert(mh.state_type_id_or_direction == (ulong)PublishableStateMessageHeader.ConnMsgDirection.toClient);
                 //auto f = connections.find(mh.ref_id_at_subscriber);
                 //if (f == connections.end())
                 //	throw std::exception();
                 //auto & conn = f->second;
                 ClientConnection conn = connections[mh.ref_id_at_subscriber];
                 if (!conn.connection.isConnected())
                     throw new Exception(); // TODO: revise
                 Debug.Assert(conn.ref_id_at_server == mh.ref_id_at_publisher); // self-consistency
                                                                                //ReadIteratorT riter = parser.getIterator();
                 conn.connection.onMessage(parser.getIterator());
                 //parser = riter;
                 break;
             }
         default:
             throw new Exception(); // TODO: ... (unknown msg type)
     }
     GMQueue.helperParsePublishableStateMessageEnd(parser);
 }
示例#11
0
        void onMessage(IPublishableParser parser)
        {
            ReadIteratorT riter = parser.getIterator().shallowClone();

            IPublishableParser parser1 = platform.makePublishableParser(riter);
            PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
            GMQueue.helperParsePublishableStateMessageBegin(parser1, ref mh);
            switch (mh.type)
            {
                case PublishableStateMessageHeader.MsgType.subscriptionResponse:
                case PublishableStateMessageHeader.MsgType.stateUpdate:
                    subPool.onMessage(parser);
                    break;
                case PublishableStateMessageHeader.MsgType.subscriptionRequest:
                    pubPool.onMessage(parser);
                    break;
                case PublishableStateMessageHeader.MsgType.connectionRequest:
                    srvPool.onMessage(parser);
                    break;
                case PublishableStateMessageHeader.MsgType.connectionAccepted:
                    cliPool.onMessage(parser);
                    break;
                case PublishableStateMessageHeader.MsgType.connectionMessage:
                    switch ((PublishableStateMessageHeader.ConnMsgDirection)mh.state_type_id_or_direction)
                    {
                        case PublishableStateMessageHeader.ConnMsgDirection.toClient:
                            cliPool.onMessage(parser);
                            break;
                        case PublishableStateMessageHeader.ConnMsgDirection.toServer:
                            srvPool.onMessage(parser);
                            break;
                        default:
                            throw new Exception(); // TODO: ... (unknown msg type)
                    }
                    break;
                default:
                    throw new Exception(); // TODO: ... (unknown msg type)
            }
        }
示例#12
0
 public void onMessage(IPublishableParser parser)
 {
     PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
     GMQueue.helperParsePublishableStateMessageBegin(parser, ref mh);
     switch (mh.type)
     {
         case PublishableStateMessageHeader.MsgType.subscriptionResponse:
             //if (mh.ref_id_at_subscriber >= subscribers.size())
             //	throw std::exception(); // TODO: ... (invalid ID)
             subscribers[(int)(mh.ref_id_at_subscriber)].ref_id_at_publisher = mh.ref_id_at_publisher;
             //if constexpr(ParserT::proto == globalmq::marshalling::Proto::JSON)
             //	subscribers[mh.ref_id_at_subscriber].subscriber->applyJsonStateSyncMessage(parser);
             //else
             //{
             //	static_assert(ParserT::proto == globalmq::marshalling::Proto::GMQ);
             //	subscribers[mh.ref_id_at_subscriber].subscriber->applyGmqStateSyncMessage(parser);
             //}
             subscribers[(int)mh.ref_id_at_subscriber].subscriber.applyStateSyncMessage(parser);
             break;
         case PublishableStateMessageHeader.MsgType.stateUpdate:
             //if (mh.ref_id_at_subscriber >= subscribers.size())
             //	throw std::exception(); // TODO: ... (invalid ID)
             // TODO: consider the following:
             //if ( subscribers[mh.ref_id_at_subscriber].ref_id_at_publisher != mh.ref_id_at_publisher )
             //	throw std::exception(); // TODO: ... (invalid source)
             //if constexpr(ParserT::proto == globalmq::marshalling::Proto::JSON)
             //	subscribers[mh.ref_id_at_subscriber].subscriber->applyJsonMessageWithUpdates(parser);
             //else
             //{
             //	static_assert(ParserT::proto == globalmq::marshalling::Proto::GMQ);
             //	subscribers[mh.ref_id_at_subscriber].subscriber->applyGmqMessageWithUpdates(parser);
             //}
             subscribers[(int)mh.ref_id_at_subscriber].subscriber.applyMessageWithUpdates(parser);
             break;
         default:
             throw new Exception(); // TODO: ... (unknown msg type)
     }
     GMQueue.helperParsePublishableStateMessageEnd(parser);
 }
        static void TestParseUpdate(ITestPlatformSupport platform, String fileNameInit, String fileName, Action <mtest.Ipublishable_seven> updateDelegate)
        {
            mtest.publishable_seven_subscriber subs = new mtest.publishable_seven_subscriber();
            //subs.debugOnlySetData(GetPublishableSeven());
            SimpleBuffer       bufferInit = SimpleBuffer.readFromFile(fileNameInit);
            IPublishableParser parserInit = platform.makePublishableParser(bufferInit.getReadIterator());

            subs.applyStateSyncMessage(parserInit);

            SimpleBuffer       buffer = SimpleBuffer.readFromFile(fileName);
            IPublishableParser parser = platform.makePublishableParser(buffer.getReadIterator());

            subs.applyMessageWithUpdates(parser);

            //mtest.publishable_seven actual = (mtest.publishable_seven)subs.debugOnlyGetData();
            mtest.publishable_seven expected = GetPublishableSeven();

            Assert.False(expected.isEquivalent(subs));

            updateDelegate(expected);

            Assert.True(expected.isEquivalent(subs));
        }
 public static String parseForStateSync(IPublishableParser parser)
 {
     return(parser.parseString(null));
 }
 public static Double parseForStateSync(IPublishableParser parser)
 {
     return(parser.parseReal(null));
 }
 public static Int64 parseForStateSync(IPublishableParser parser)
 {
     return(parser.parseInteger(null));
 }
 public static UInt64 parseForStateSync(IPublishableParser parser)
 {
     return(parser.parseUnsigned(null));
 }
示例#18
0
 public void onMessage(BufferT buffer)
 {
     ReadIteratorT riter = buffer.getReadIterator();
     IPublishableParser parser = platform.makePublishableParser(riter);
     onMessage(parser);
 }
示例#19
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);
        }