Exemplo n.º 1
0
        private void TrySendCountFollowedBy(int numThreads, int numEvents, ConfigurationEngineDefaults.ThreadingConfig.Locking locking)
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.Threading.InsertIntoDispatchLocking = locking;
            config.EngineDefaults.Threading.InsertIntoDispatchTimeout = 5000; // 5 second timeout
            // This should fail all test in this class
            // config.EngineDefaults.Threading.InsertIntoDispatchPreserveOrder = false;

            var engine = EPServiceProviderManager.GetDefaultProvider(config);

            engine.Initialize();

            // setup statements
            var stmtInsert = engine.EPAdministrator.CreateEPL("insert into MyStream select count(*) as cnt from " + typeof(SupportBean).FullName);

            stmtInsert.Events += ((sender, e) => Log.Debug(".Update cnt=" + e.NewEvents[0].Get("cnt")));

            var listeners = new SupportUpdateListener[numEvents];

            for (var i = 0; i < numEvents; i++)
            {
                var text = "select * from pattern [MyStream(cnt=" + (i + 1) + ") -> MyStream(cnt=" + (i + 2) + ")]";
                var stmt = engine.EPAdministrator.CreateEPL(text);
                listeners[i] = new SupportUpdateListener();
                stmt.Events += listeners[i].Update;
            }

            // execute
            var threadPool      = Executors.NewFixedThreadPool(numThreads);
            var future          = new Future <bool> [numThreads];
            var sharedStartLock = ReaderWriterLockManager.CreateLock(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            using (sharedStartLock.AcquireWriteLock()) {
                for (var i = 0; i < numThreads; i++)
                {
                    future[i] = threadPool.Submit(new SendEventRWLockCallable(
                                                      i, sharedStartLock.ReadLock, engine,
                                                      EnumerationGenerator.Create(numEvents)));
                }
                Thread.Sleep(100);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(new TimeSpan(0, 0, 10));

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

            // assert result
            for (var i = 0; i < numEvents - 1; i++)
            {
                Assert.AreEqual(1, listeners[i].NewDataList.Count, "Listener not invoked: #" + i);
            }
        }
Exemplo n.º 2
0
        private void TrySend(int numThreads, int numEvents, bool isPreserveOrder, ConfigurationEngineDefaults.ThreadingConfig.Locking?locking)
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.Threading.IsListenerDispatchPreserveOrder = isPreserveOrder;
            config.EngineDefaults.Threading.ListenerDispatchLocking         = locking.GetValueOrDefault();

            _engine = EPServiceProviderManager.GetDefaultProvider(config);
            _engine.Initialize();

            // setup statements
            var stmtInsert = _engine.EPAdministrator.CreateEPL("select count(*) as cnt from " + typeof(SupportBean).FullName);
            var listener   = new SupportMTUpdateListener();

            stmtInsert.Events += listener.Update;

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

            for (var i = 0; i < numThreads; i++)
            {
                future[i] = threadPool.Submit(new SendEventCallable(i, _engine, EnumerationGenerator.Create(numEvents)));
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(new TimeSpan(0, 0, 10));

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

            var events = listener.GetNewDataListFlattened();
            var result = new long[events.Length];

            for (var i = 0; i < events.Length; i++)
            {
                result[i] = (long)events[i].Get("cnt");
            }
            //Log.Info(".trySend result=" + CompatExtensions.RenderAny(result));

            // assert result
            Assert.AreEqual(numEvents * numThreads, events.Length);
            for (var i = 0; i < numEvents * numThreads; i++)
            {
                Assert.AreEqual(result[i], (long)i + 1);
            }
        }
Exemplo n.º 3
0
        private void TryPattern(String pattern, int numThreads, int numEvents)
        {
            var sendLock   = new Object();
            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var future     = new Future <bool> [numThreads];
            var callables  = new SendEventWaitCallable[numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                callables[i] = new SendEventWaitCallable(i, _engine, sendLock, EnumerationGenerator.Create(numEvents));
                future[i]    = threadPool.Submit(callables[i]);
            }

            var listener = new SupportMTUpdateListener[numEvents];

            for (int i = 0; i < numEvents; i++)
            {
                EPStatement stmt = _engine.EPAdministrator.CreatePattern(pattern);
                listener[i]  = new SupportMTUpdateListener();
                stmt.Events += listener[i].Update;

                lock (sendLock) {
                    Monitor.PulseAll(sendLock);
                }
            }

            foreach (SendEventWaitCallable callable in callables)
            {
                callable.SetShutdown(true);
            }

            lock (sendLock) {
                Monitor.PulseAll(sendLock);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(new TimeSpan(0, 0, 10));


            for (int i = 0; i < numEvents; i++)
            {
                Assert.That(listener[i].AssertOneGetNewAndReset().Get("a"), Is.InstanceOf <SupportBean>());
            }
        }
Exemplo n.º 4
0
        private void TryMultiInsertGroup(int numThreads, int numStatements, int numEvents)
        {
            var config = SupportConfigFactory.GetConfiguration();
            // This should fail all test in this class
            // config.EngineDefaults.Threading.InsertIntoDispatchPreserveOrder = false;

            var engine = EPServiceProviderManager.GetDefaultProvider(config);

            engine.Initialize();

            // setup statements
            var insertIntoStmts = new EPStatement[numStatements];

            for (var i = 0; i < numStatements; i++)
            {
                insertIntoStmts[i] = engine.EPAdministrator.CreateEPL("insert into MyStream select " + i + " as ident,count(*) as cnt from " + typeof(SupportBean).FullName);
            }
            var stmtInsertTwo = engine.EPAdministrator.CreateEPL("select ident, sum(cnt) as mysum from MyStream group by ident");
            var listener      = new SupportUpdateListener();

            stmtInsertTwo.Events += listener.Update;

            // execute
            var threadPool      = Executors.NewFixedThreadPool(numThreads);
            var future          = new Future <bool> [numThreads];
            var sharedStartLock = ReaderWriterLockManager.CreateLock(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            using (sharedStartLock.AcquireWriteLock()) {
                for (var i = 0; i < numThreads; i++)
                {
                    future[i] = threadPool.Submit(
                        new SendEventRWLockCallable(i, sharedStartLock.ReadLock, engine, EnumerationGenerator.Create(numEvents)));
                }
                Thread.Sleep(100);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(new TimeSpan(0, 0, 10));

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

            // assert result
            var newEvents       = listener.GetNewDataListFlattened();
            var resultsPerIdent = new ArrayList[numStatements];

            foreach (var theEvent in newEvents)
            {
                var ident = (int)theEvent.Get("ident");
                if (resultsPerIdent[ident] == null)
                {
                    resultsPerIdent[ident] = new ArrayList();
                }
                var mysum = (long)theEvent.Get("mysum");
                resultsPerIdent[ident].Add(mysum);
            }

            for (var statement = 0; statement < numStatements; statement++)
            {
                for (var i = 0; i < numEvents - 1; i++)
                {
                    var expected = Total(i + 1);
                    Assert.AreEqual(expected, resultsPerIdent[statement][i]);
                }
            }

            // destroy
            for (var i = 0; i < numStatements; i++)
            {
                insertIntoStmts[i].Dispose();
            }
            stmtInsertTwo.Dispose();
        }
Exemplo n.º 5
0
        private void TryChainedCountSum(int numThreads, int numEvents)
        {
            var config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.Threading.IsInternalTimerEnabled = false;
            // This should fail all test in this class
            // config.EngineDefaults.Threading.InsertIntoDispatchPreserveOrder = false;

            var engine = EPServiceProviderManager.GetDefaultProvider(config);

            engine.Initialize();

            // setup statements
            var stmtInsertOne = engine.EPAdministrator.CreateEPL("insert into MyStreamOne select count(*) as cnt from " + typeof(SupportBean).FullName);
            var stmtInsertTwo = engine.EPAdministrator.CreateEPL("insert into MyStreamTwo select sum(cnt) as mysum from MyStreamOne");
            var listener      = new SupportUpdateListener();

            stmtInsertTwo.Events += listener.Update;

            // execute
            var threadPool      = Executors.NewFixedThreadPool(numThreads);
            var future          = new Future <bool> [numThreads];
            var sharedStartLock = ReaderWriterLockManager.CreateLock(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            using (sharedStartLock.AcquireWriteLock()) {
                for (var i = 0; i < numThreads; i++)
                {
                    future[i] = threadPool.Submit(
                        new SendEventRWLockCallable(i, sharedStartLock.ReadLock, engine, EnumerationGenerator.Create(numEvents)));
                }
                Thread.Sleep(100);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(new TimeSpan(0, 0, 10));

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

            // assert result
            var newEvents = listener.GetNewDataListFlattened();

            for (var i = 0; i < numEvents - 1; i++)
            {
                var expected = Total(i + 1);
                Assert.AreEqual(expected, newEvents[i].Get("mysum"));
            }

            stmtInsertOne.Dispose();
            stmtInsertTwo.Dispose();
        }