static MetaPool initializeGmQueue(MwsrThreadQueue msgQueue) { IPlatformSupport platform = new DefaultJsonPlatformSupport(); GMQueue gmq = new GMQueue(); gmq.initStateConcentratorFactory(new mtest.StateConcentratorFactory()); gmq.initPlatformSupport(platform); gmq.initAuthority(String.Empty); //BasicMtQueue<ThreadQueueItem> msgQueue = new BasicMtQueue<ThreadQueueItem>(); ThreadQueuePostman postMan = new ThreadQueuePostman(msgQueue, 1); SlotIdx idx_; UInt64 id_ = gmq.add("test_node", postMan, out idx_); GMQTransport transport = new GMQTransport(gmq, "test_node", idx_, id_); MetaPool mp = new MetaPool(); mp.setTransport(transport); mp.setPlatform(platform); return(mp); }
public static void TestGmQueueWithMock3() { MwsrThreadQueue msgQueue = new MwsrThreadQueue(5); MetaPool mp = initializeGmQueue(msgQueue); mtest.Mock_publisher publ = new mtest.Mock_publisher(); mp.add(publ); mp.remove(publ); mp.add(publ); string path = getSubscriptionAddress("Mock"); mtest.Mock_subscriber subs1 = new mtest.Mock_subscriber(); mp.add(subs1); mp.remove(subs1); mp.add(subs1); mp.subscribe(subs1, path); int msgCnt = 0; //mp.postAllUpdates(); deliverAllMessages(mp, msgQueue, "test_gmqueue3_", ref msgCnt); mp.postAllUpdates(); deliverAllMessages(mp, msgQueue, "test_gmqueue3_", ref msgCnt); }
static void deliverAllMessages(MetaPool pool, MwsrThreadQueue msgQueue, String filePrefix, ref int msgCnt) { ThreadQueueItem[] messages = new ThreadQueueItem[16]; while (true) { int popped = msgQueue.pop_front(messages); if (popped == 0) { break; } for (int i = 0; i < popped; ++i) { pool.onMessage(messages[i].msg); ++msgCnt; if (filePrefix != null) { SimpleBuffer buffer = (SimpleBuffer)messages[i].msg; String fileName = TestCommon.DataPathPrefix + filePrefix + msgCnt + ".json"; // uncomment to update file //buffer.writeToFile(fileName); SimpleBuffer expected = SimpleBuffer.readFromFile(fileName); Assert.True(SimpleBuffer.AreEqualIgnoreEol(expected, buffer)); } } } }
public static void TestGmQueueWithStructSix() { MwsrThreadQueue msgQueue = new MwsrThreadQueue(5); MetaPool mp = initializeGmQueue(msgQueue); mtest.StructSix_publisher publ = new mtest.StructSix_publisher(); mtest.StructSix data = test_publishable_six.GetPublishableSix(); publ.debugOnlySetData(data); mp.add(publ); string path = getSubscriptionAddress("StructSix"); mtest.StructSix_subscriber subs1 = new mtest.StructSix_subscriber(); Assert.False(publ.isEquivalent(subs1)); mp.add(subs1); mp.subscribe(subs1, path); int msgCnt = 0; mp.postAllUpdates(); deliverAllMessages(mp, msgQueue, null, ref msgCnt); Assert.True(publ.isEquivalent(subs1)); mtest.StructSix_subscriber subs2 = new mtest.StructSix_subscriber(); //mtest.StructSix data2 = (mtest.StructSix)subs2.debugOnlyGetData(); mp.add(subs2); mp.subscribe(subs2, path); mtest.StructSix_subscriber subs3 = new mtest.StructSix_subscriber(); //mtest.StructSix data3 = (mtest.StructSix)subs3.debugOnlyGetData(); mp.add(subs3); mp.subscribe(subs3, path); mp.postAllUpdates(); deliverAllMessages(mp, msgQueue, null, ref msgCnt); Assert.True(publ.isEquivalent(subs2)); Assert.True(publ.isEquivalent(subs3)); test_publishable_six.doUpdate1(publ); Assert.False(publ.isEquivalent(subs1)); Assert.False(publ.isEquivalent(subs2)); Assert.False(publ.isEquivalent(subs3)); mp.postAllUpdates(); deliverAllMessages(mp, msgQueue, null, ref msgCnt); Assert.True(publ.isEquivalent(subs1)); Assert.True(publ.isEquivalent(subs2)); Assert.True(publ.isEquivalent(subs3)); }