Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void concurrentlyPublishedEventsMustAllBeProcessed()
        internal virtual void ConcurrentlyPublishedEventsMustAllBeProcessed()
        {
            assertTimeout(ofSeconds(10), () =>
            {
                EventConsumer consumer = new EventConsumer();
                System.Threading.CountdownEvent startLatch = new System.Threading.CountdownEvent(1);
                const int threads               = 10;
                const int iterations            = 2_000;
                AsyncEvents <Event> asyncEvents = new AsyncEvents <Event>(consumer, AsyncEvents.Monitor_Fields.None);
                _executor.submit(asyncEvents);

                ExecutorService threadPool = Executors.newFixedThreadPool(threads);
                ThreadStart runner         = () =>
                {
                    try
                    {
                        startLatch.await();
                    }
                    catch (InterruptedException e)
                    {
                        throw new Exception(e);
                    }

                    for (int i = 0; i < iterations; i++)
                    {
                        asyncEvents.Send(new Event());
                    }
                };
                for (int i = 0; i < threads; i++)
                {
                    threadPool.submit(runner);
                }
                startLatch.countDown();

                Thread thisThread = Thread.CurrentThread;
                int eventCount    = threads * iterations;
                try
                {
                    for (int i = 0; i < eventCount; i++)
                    {
                        Event @event = consumer.Poll(1, TimeUnit.SECONDS);
                        if (@event == null)
                        {
                            i--;
                        }
                        else
                        {
                            assertThat(@event.ProcessedBy, @is(not(thisThread)));
                        }
                    }
                }
                finally
                {
                    asyncEvents.Shutdown();
                    threadPool.shutdown();
                }
            });
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void eventsMustBeProcessedByBackgroundThread() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void EventsMustBeProcessedByBackgroundThread()
        {
            EventConsumer consumer = new EventConsumer();

            AsyncEvents <Event> asyncEvents = new AsyncEvents <Event>(consumer, AsyncEvents.Monitor_Fields.None);

            _executor.submit(asyncEvents);

            Event firstSentEvent = new Event();

            asyncEvents.Send(firstSentEvent);
            Event firstProcessedEvent = consumer.Poll(10, TimeUnit.SECONDS);

            Event secondSentEvent = new Event();

            asyncEvents.Send(secondSentEvent);
            Event secondProcessedEvent = consumer.Poll(10, TimeUnit.SECONDS);

            asyncEvents.Shutdown();

            assertThat(firstProcessedEvent, @is(firstSentEvent));
            assertThat(secondProcessedEvent, @is(secondSentEvent));
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustProcessEventsDirectlyWhenShutDown()
        internal virtual void MustProcessEventsDirectlyWhenShutDown()
        {
            assertTimeout(ofSeconds(10), () =>
            {
                EventConsumer consumer = new EventConsumer();

                AsyncEvents <Event> asyncEvents = new AsyncEvents <Event>(consumer, AsyncEvents.Monitor_Fields.None);
                _executor.submit(asyncEvents);

                asyncEvents.Send(new Event());
                Thread threadForFirstEvent = consumer.Poll(10, TimeUnit.SECONDS).ProcessedBy;
                asyncEvents.Shutdown();

                assertThat(threadForFirstEvent, @is(not(Thread.CurrentThread)));

                Thread threadForSubsequentEvents;
                do
                {
                    asyncEvents.Send(new Event());
                    threadForSubsequentEvents = consumer.Poll(10, TimeUnit.SECONDS).ProcessedBy;
                } while (threadForSubsequentEvents != Thread.CurrentThread);
            });
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void mustNotProcessEventInSameThreadWhenNotShutDown() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void MustNotProcessEventInSameThreadWhenNotShutDown()
        {
            EventConsumer consumer = new EventConsumer();

            AsyncEvents <Event> asyncEvents = new AsyncEvents <Event>(consumer, AsyncEvents.Monitor_Fields.None);

            _executor.submit(asyncEvents);

            asyncEvents.Send(new Event());

            Thread processingThread = consumer.Poll(10, TimeUnit.SECONDS).ProcessedBy;

            asyncEvents.Shutdown();

            assertThat(processingThread, @is(not(Thread.CurrentThread)));
        }