public void TryCount(int numThreads, int numMessages, String epl, GeneratorIteratorCallback generatorIteratorCallback)
        {
            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var stmt       = _engine.EPAdministrator.CreateEPL(epl);
            var listener   = new SupportUpdateListener();

            stmt.Events += listener.Update;

            var future = new Future <object> [numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                future[i] = threadPool.Submit(new SendEventCallable(i, _engine, EventGenerator.MakeEvents(numMessages, generatorIteratorCallback)));
            }

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

            for (int i = 0; i < numThreads; i++)
            {
                Assert.IsTrue(future[i].GetValueOrDefault().AsBoolean());
            }

            Assert.AreEqual(numMessages * numThreads, listener.GetNewDataListFlattened().Length);
        }
Exemple #2
0
        public void TryCount(int numThreads, int numMessages, String epl, GeneratorIteratorCallback generatorCallback)
        {
            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var stmt       = _engine.EPAdministrator.CreateEPL(epl);
            var listener   = new MTListener("mycount");

            stmt.Events += listener.Update;

            var future = new Future <object> [numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                future[i] = threadPool.Submit(new SendEventCallable(i, _engine, EventGenerator.MakeEvents(numMessages, generatorCallback)));
            }

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

            for (int i = 0; i < numThreads; i++)
            {
                Assert.IsTrue(future[i].GetValueOrDefault().AsBoolean());
            }

            // verify results
            Assert.AreEqual(numMessages * numThreads, listener.Values.Count);
            SortedSet <int> result = new SortedSet <int>();

            foreach (Object row in listener.Values)
            {
                result.Add(row.AsInt());
            }
            Assert.AreEqual(numMessages * numThreads, result.Count);
            Assert.AreEqual(1, (Object)result.First());
            Assert.AreEqual(numMessages * numThreads, (Object)result.Last());
        }
Exemple #3
0
        private void TrySend(int numThreads, int numRepeats)
        {
            // set time to 0
            _engine.EPRuntime.SendEvent(new CurrentTimeEvent(0));

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

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

            // Advance time window every 100 milliseconds for 1 second
            for (int i = 0; i < 10; i++)
            {
                _engine.EPRuntime.SendEvent(new CurrentTimeEvent(i * 1000));
                Thread.Sleep(100);
            }

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

            for (int i = 0; i < numThreads; i++)
            {
                Assert.IsTrue(future[i].GetValueOrDefault().AsBoolean());
            }

            // set time to a large value
            _engine.EPRuntime.SendEvent(new CurrentTimeEvent(10000000000L));

            // Assert results
            int totalExpected = numThreads * numRepeats;

            // assert new data
            EventBean[] resultNewData = _listener.GetNewDataListFlattened();
            Assert.AreEqual(totalExpected, resultNewData.Length);
            IDictionary <int, IList <String> > resultsNewData = SortPerIntKey(resultNewData);

            AssertResult(numRepeats, numThreads, resultsNewData);

            // assert old data
            EventBean[] resultOldData = _listener.GetOldDataListFlattened();
            Assert.AreEqual(totalExpected, resultOldData.Length);
            IDictionary <int, IList <String> > resultsOldData = SortPerIntKey(resultOldData);

            AssertResult(numRepeats, numThreads, resultsOldData);

            _listener.Reset();
        }