Exemplo n.º 1
0
        public void TestEventTypes(EventTestCase testCase)
        {
            var events = _grid1.GetEvents();

            events.EnableLocal(testCase.EventType);

            var listener = EventsTestHelper.GetListener();

            events.LocalListen(listener, testCase.EventType);

            EventsTestHelper.ClearReceived(testCase.EventCount);

            testCase.GenerateEvent(_grid1);

            EventsTestHelper.VerifyReceive(testCase.EventCount, testCase.EventObjectType, testCase.EventType);

            if (testCase.VerifyEvents != null)
            {
                testCase.VerifyEvents(EventsTestHelper.ReceivedEvents.Reverse(), _grid1);
            }

            // Check stop
            events.StopLocalListen(listener);

            EventsTestHelper.ClearReceived(0);

            testCase.GenerateEvent(_grid1);

            Thread.Sleep(EventsTestHelper.Timeout);
        }
Exemplo n.º 2
0
        public void TestLocalListenRepeatedSubscription()
        {
            var events    = _grid1.GetEvents();
            var listener  = EventsTestHelper.GetListener();
            var eventType = EventType.TaskExecutionAll;

            events.EnableLocal(eventType);

            events.LocalListen(listener, eventType);

            CheckSend(3);  // 3 events per task * 3 grids

            events.LocalListen(listener, eventType);
            events.LocalListen(listener, eventType);

            CheckSend(9);

            events.StopLocalListen(listener, eventType);

            CheckSend(6);

            events.StopLocalListen(listener, eventType);

            CheckSend(3);

            events.StopLocalListen(listener, eventType);

            CheckNoEvent();
        }
Exemplo n.º 3
0
        public void TestLocalListen()
        {
            var events    = _grid1.GetEvents();
            var listener  = EventsTestHelper.GetListener();
            var eventType = EventType.TaskExecutionAll;

            events.EnableLocal(eventType);

            events.LocalListen(listener, eventType);

            CheckSend(3);  // 3 events per task * 3 grids

            // Check unsubscription for specific event
            events.StopLocalListen(listener, EventType.TaskReduced);

            CheckSend(2);

            // Unsubscribe from all events
            events.StopLocalListen(listener, Enumerable.Empty <int>());

            CheckNoEvent();

            // Check unsubscription by filter
            events.LocalListen(listener, EventType.TaskReduced);

            CheckSend();

            EventsTestHelper.ListenResult = false;

            CheckSend();  // one last event will be received for each listener

            CheckNoEvent();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends events in various ways and verifies correct receive.
        /// </summary>
        /// <param name="repeat">Expected event count multiplier.</param>
        /// <param name="eventObjectType">Expected event object type.</param>
        /// <param name="eventType">Type of the event.</param>
        private void CheckSend(int repeat = 1, Type eventObjectType = null, params int[] eventType)
        {
            EventsTestHelper.ClearReceived(repeat);

            GenerateTaskEvent();

            EventsTestHelper.VerifyReceive(repeat, eventObjectType ?? typeof(TaskEvent),
                                           eventType.Any() ? eventType : EventType.TaskExecutionAll);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Checks that no event has arrived.
        /// </summary>
        private void CheckNoEvent()
        {
            // this will result in an exception in case of a event
            EventsTestHelper.ClearReceived(0);

            GenerateTaskEvent();

            Thread.Sleep(EventsTestHelper.Timeout);

            EventsTestHelper.AssertFailures();
        }
Exemplo n.º 6
0
        public void TearDown()
        {
            try
            {
                TestUtils.AssertHandleRegistryIsEmpty(1000, _grid1, _grid2, _grid3);
            }
            catch (Exception)
            {
                // Restart grids to cleanup
                StopGrids();

                throw;
            }
            finally
            {
                EventsTestHelper.AssertFailures();

                if (TestContext.CurrentContext.Test.Name.StartsWith("TestEventTypes"))
                {
                    StopGrids(); // clean events for other tests
                }
            }
        }
Exemplo n.º 7
0
        public void TestRemoteListen(
            [Values(true, false)] bool async,
            [Values(true, false)] bool portable,
            [Values(true, false)] bool autoUnsubscribe)
        {
            foreach (var g in _grids)
            {
                g.Events().EnableLocal(EventType.EvtsJobExecution);
                g.Events().EnableLocal(EventType.EvtsTaskExecution);
            }

            var events = _grid1.Events();

            var expectedType = EventType.EvtJobStarted;

            var remoteFilter = portable
                ?  (IEventFilter <IEvent>) new RemoteEventPortableFilter(expectedType)
                :  new RemoteEventFilter(expectedType);

            var localListener = EventsTestHelper.GetListener();

            if (async)
            {
                events = events.WithAsync();
            }

            var listenId = events.RemoteListen(localListener: localListener, remoteFilter: remoteFilter,
                                               autoUnsubscribe: autoUnsubscribe);

            if (async)
            {
                listenId = events.GetFuture <Guid>().Get();
            }

            CheckSend(3, typeof(JobEvent), expectedType);

            _grid3.Events().DisableLocal(EventType.EvtsJobExecution);

            CheckSend(2, typeof(JobEvent), expectedType);

            events.StopRemoteListen(listenId);

            if (async)
            {
                events.GetFuture().Get();
            }

            CheckNoEvent();

            // Check unsubscription with listener
            events.RemoteListen(localListener: localListener, remoteFilter: remoteFilter,
                                autoUnsubscribe: autoUnsubscribe);

            if (async)
            {
                events.GetFuture <Guid>().Get();
            }

            CheckSend(2, typeof(JobEvent), expectedType);

            EventsTestHelper.ListenResult = false;

            CheckSend(1, typeof(JobEvent), expectedType);  // one last event

            CheckNoEvent();
        }