Beispiel #1
0
        private void TrySend(int numThreads, int numRepeats, int numConsumers)
        {
            _listenerConsumers = new SupportMTUpdateListener[numConsumers];
            for (int i = 0; i < _listenerConsumers.Length; i++)
            {
                EPStatement stmtConsumer = _engine.EPAdministrator.CreateEPL("select TheString, LongPrimitive from MyWindow");
                _listenerConsumers[i] = new SupportMTUpdateListener();
                stmtConsumer.Events  += _listenerConsumers[i].Update;
            }

            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var future     = new Future <IList <string> > [numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                var callable = new StmtNamedWindowConsumeCallable(Convert.ToString(i), _engine, numRepeats);
                future[i] = threadPool.Submit(callable);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(TimeSpan.FromSeconds(10));

            // Compute list of expected
            var expectedIdsList = new List <String>();

            for (int i = 0; i < numThreads; i++)
            {
                expectedIdsList.AddAll(future[i].GetValueOrDefault());
            }
            String[] expectedIds = expectedIdsList.ToArray();

            Assert.AreEqual(numThreads * numRepeats, _listenerWindow.GetNewDataList().Count);  // old and new each

            // Compute list of received
            for (int i = 0; i < _listenerConsumers.Length; i++)
            {
                var newEvents   = _listenerConsumers[i].GetNewDataListFlattened();
                var receivedIds = new String[newEvents.Length];
                for (int j = 0; j < newEvents.Length; j++)
                {
                    receivedIds[j] = (String)newEvents[j].Get("TheString");
                }
                Assert.AreEqual(receivedIds.Length, expectedIds.Length);

                Array.Sort(receivedIds);
                Array.Sort(expectedIds);
                CompatExtensions.DeepEquals(expectedIds, receivedIds);
            }
        }
        private void TrySend(int numThreads, int numRepeats)
        {
            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var future     = new Future <IList <string> > [numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                var callable = new StmtNamedWindowDeleteCallable(Convert.ToString(i), _engine, numRepeats);
                future[i] = threadPool.Submit(callable);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(TimeSpan.FromSeconds(10));

            // Compute list of expected
            List <String> expectedIdsList = new List <String>();

            for (int i = 0; i < numThreads; i++)
            {
                expectedIdsList.AddAll(future[i].GetValueOrDefault());
            }
            String[] expectedIds = expectedIdsList.ToArray();

            Assert.AreEqual(2 * numThreads * numRepeats, _listenerWindow.GetNewDataList().Count);   // old and new each
            Assert.AreEqual(2 * numThreads * numRepeats, _listenerConsumer.GetNewDataList().Count); // old and new each

            // Compute list of received
            EventBean[] newEvents   = _listenerWindow.GetNewDataListFlattened();
            String[]    receivedIds = new String[newEvents.Length];
            for (int i = 0; i < newEvents.Length; i++)
            {
                receivedIds[i] = (String)newEvents[i].Get("TheString");
            }
            Assert.AreEqual(receivedIds.Length, expectedIds.Length);

            Array.Sort(receivedIds);
            Array.Sort(expectedIds);

            CompatExtensions.DeepEquals(expectedIds, receivedIds);
        }
        private void RunAssertion(bool useDefault, bool?preserve, ConfigurationEngineDefaults.Threading.Locking?locking)
        {
            var config = SupportConfigFactory.GetConfiguration();

            if (!useDefault)
            {
                if (preserve != null)
                {
                    config.EngineDefaults.ThreadingConfig.IsNamedWindowConsumerDispatchPreserveOrder = preserve.Value;
                }
                if (locking != null)
                {
                    config.EngineDefaults.ThreadingConfig.NamedWindowConsumerDispatchLocking = locking.Value;
                }
            }

            var epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();
            epService.EPAdministrator.Configuration.AddEventType(typeof(EventOne));
            epService.EPAdministrator.Configuration.AddEventType(typeof(EventTwo));

            var epl =
                "create window EventOneWindow.std:unique(key) as EventOne;\n" +
                "insert into EventOneWindow select * from EventOne;\n" +
                "create window EventTwoWindow.std:unique(key) as EventTwo;\n" +
                "insert into EventTwoWindow select * from EventTwo;\n" +
                "@Name('out') select * from EventOneWindow as e1, EventTwoWindow as e2 where e1.key = e2.key";

            epService.EPAdministrator.DeploymentAdmin.ParseDeploy(epl);

            var listener = new SupportMTUpdateListener();

            epService.EPAdministrator.GetStatement("out").Events += listener.Update;

            ThreadStart runnableOne = () =>
            {
                for (var i = 0; i < 33; i++)
                {
                    var eventOne = new EventOne("TEST");
                    epService.EPRuntime.SendEvent(eventOne);
                    var eventTwo = new EventTwo("TEST");
                    epService.EPRuntime.SendEvent(eventTwo);
                }
            };
            ThreadStart runnableTwo = () =>
            {
                for (var i = 0; i < 33; i++)
                {
                    var eventTwo = new EventTwo("TEST");
                    epService.EPRuntime.SendEvent(eventTwo);
                    var eventOne = new EventOne("TEST");
                    epService.EPRuntime.SendEvent(eventOne);
                }
            };
            ThreadStart runnableThree = () =>
            {
                for (var i = 0; i < 34; i++)
                {
                    var eventTwo = new EventTwo("TEST");
                    epService.EPRuntime.SendEvent(eventTwo);
                    var eventOne = new EventOne("TEST");
                    epService.EPRuntime.SendEvent(eventOne);
                }
            };

            var t1 = new Thread(runnableOne);
            var t2 = new Thread(runnableTwo);
            var t3 = new Thread(runnableThree);

            t1.Start();
            t2.Start();
            t3.Start();

            t1.Join();
            t2.Join();
            t3.Join();

            var delivered = listener.GetNewDataList();

            // count deliveries of multiple rows
            var countMultiDeliveries = 0;

            foreach (var events in delivered)
            {
                countMultiDeliveries += (events.Length > 1 ? 1 : 0);
            }

            // count deliveries where instance doesn't monotonically increase from previous row for one column
            var  countNotMonotone = 0;
            long?previousIdE1     = null;
            long?previousIdE2     = null;

            foreach (var events in delivered)
            {
                var idE1 = events[0].Get("e1.instance").AsLong();
                var idE2 = events[0].Get("e2.instance").AsLong();
                // comment-in when needed: System.out.println("Received " + idE1 + " " + idE2);

                if (previousIdE1 != null)
                {
                    var incorrect = idE1 != previousIdE1 && idE2 != previousIdE2;
                    if (!incorrect)
                    {
                        incorrect = (idE1 == previousIdE1 && idE2 != (previousIdE2 + 1) ||
                                     (idE2 == previousIdE2 && idE1 != (previousIdE1 + 1)));
                    }
                    if (incorrect)
                    {
                        // comment-in when needed: System.out.println("Non-Monotone increase (this is still correct but noteworthy)");
                        countNotMonotone++;
                    }
                }

                previousIdE1 = idE1;
                previousIdE2 = idE2;
            }

            if (useDefault || preserve.Value)
            {
                Assert.AreEqual(0, countMultiDeliveries, "multiple row deliveries: " + countMultiDeliveries);
                // the number of non-monotone delivers should be small but not zero
                // this is because when the event get generated and when the event actually gets processed may not be in the same order
                Assert.That(countNotMonotone, Is.LessThan(50), "count not monotone: " + countNotMonotone);
                Assert.That(delivered.Count, Is.GreaterThanOrEqualTo(197));     // its possible to not have 199 since there may not be events on one side of the join
            }
            else
            {
                Assert.That(countMultiDeliveries, Is.GreaterThan(0), "multiple row deliveries: " + countMultiDeliveries);
                Assert.That(countNotMonotone, Is.GreaterThan(5), "count not monotone: " + countNotMonotone);
            }
        }