Пример #1
0
        /// <summary>
        /// Tests RemoteListen.
        /// </summary>
        private void TestRemoteListen(object topic, bool async = false)
        {
            var messaging = _grid1.GetMessaging();

            var listener = MessagingTestHelper.GetListener("first");
            var listenId = async
                ? messaging.RemoteListenAsync(listener, topic).Result
                : messaging.RemoteListen(listener, topic);

            // Test sending
            CheckSend(topic, msg: messaging, remoteListen: true);

            // Test different topic
            CheckNoMessage(NextId());

            // Test multiple subscriptions for the same filter
            var listener2 = MessagingTestHelper.GetListener("second");
            var listenId2 = async
                ? messaging.RemoteListenAsync(listener2, topic).Result
                : messaging.RemoteListen(listener2, topic);

            CheckSend(topic, msg: messaging, remoteListen: true, repeatMultiplier: 2); // expect twice the messages

            if (async)
            {
                messaging.StopRemoteListenAsync(listenId2).Wait();
            }
            else
            {
                messaging.StopRemoteListen(listenId2);
            }

            // Wait for all to unsubscribe: StopRemoteListen (both sync and async) does not remove remote listeners
            // upon exit. Remote listeners are removed with disco messages after some delay -
            // see TestStopRemoteListenRemovesAllCallbacksUponExit.
            TestUtils.AssertHandleRegistryHasItems(
                (int)MessagingTestHelper.SleepTimeout.TotalMilliseconds,
                1,
                _grid1, _grid2, _grid3);

            CheckSend(topic, msg: messaging, remoteListen: true); // back to normal after unsubscription

            // Test message type mismatch
            var ex = Assert.Throws <IgniteException>(() => messaging.Send(1.1, topic));

            Assert.AreEqual("Unable to cast object of type 'System.Double' to type 'System.String'.", ex.Message);

            // Test end listen
            if (async)
            {
                messaging.StopRemoteListenAsync(listenId).Wait();
            }
            else
            {
                messaging.StopRemoteListen(listenId);
            }

            CheckNoMessage(topic);
        }
Пример #2
0
        public void TestTearDown()
        {
            try
            {
                TestUtils.AssertHandleRegistryHasItems(1000, _expectedHandleRegistryEntries, _grids);
            }
            catch (Exception)
            {
                // Restart grids to cleanup
                StopGrids();

                throw;
            }
        }
Пример #3
0
        public void TestStopRemoteListenRemovesAllCallbacksUponExit()
        {
            const string topic = "topic";

            var messaging = _grid1.GetMessaging();
            var listenId  = messaging.RemoteListen(MessagingTestHelper.GetListener("first"), topic);

            TestUtils.AssertHandleRegistryHasItems(-1, 1, _grid1, _grid2, _grid3);

            messaging.Send(1, topic);
            messaging.StopRemoteListen(listenId);

            TestUtils.AssertHandleRegistryHasItems(-1, 0, _grid1, _grid2, _grid3);
        }