Beispiel #1
0
        public bool Call()
        {
            try {
                var listener = new SupportMTUpdateListener();
                _targetStatement.Events += listener.Update;

                for (var loop = 0; loop < _numRepeats; loop++)
                {
                    var generalKey    = "Key";
                    var valueExpected = _threadNum * 1000000000 + loop + 1;

                    // send insert event with string-value NOT specific to thread
                    SendEvent(generalKey, valueExpected);

                    // send subquery trigger event
                    _engine.EPRuntime.SendEvent(new SupportBean(generalKey, -1));

                    // assert trigger event received
                    var events = listener.NewDataListCopy;
                    var found  = false;
                    foreach (var arr in events)
                    {
                        foreach (var item in arr)
                        {
                            var value = item.Get("val").Unwrap <int?>();
                            foreach (var valueReceived in value)
                            {
                                if (valueReceived == valueExpected)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (found)
                            {
                                break;
                            }
                        }
                        if (found)
                        {
                            break;
                        }
                    }
                    listener.Reset();

                    if (!found)
                    {
                        return(false);
                    }

                    // send delete event with string-value specific to thread
                    SendEvent(generalKey, valueExpected);
                }
            } catch (Exception ex) {
                Log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public bool Call()
        {
            try
            {
                // Add assertListener
                var assertListener = new SupportMTUpdateListener();
                ThreadLogUtil.Trace("adding listeners ", assertListener);
                _stmt.Events += assertListener.Update;

                for (var loop = 0; loop < _numRepeats; loop++)
                {
                    long id = _threadNum * 100000000 + loop;
                    object eventS0 = MakeEvent("s0", id);
                    object eventS1 = MakeEvent("s1", id);

                    ThreadLogUtil.Trace("SENDING s0 event ", id, eventS0);
                    _engine.EPRuntime.SendEvent(eventS0);
                    ThreadLogUtil.Trace("SENDING s1 event ", id, eventS1);
                    _engine.EPRuntime.SendEvent(eventS1);

                    //ThreadLogUtil.Info("sent", eventS0, eventS1);
                    // Should have received one that's mine, possible multiple since the statement is used by other threads
                    var found = false;
                    var events = assertListener.GetNewDataListFlattened();
                    foreach (var theEvent in events)
                    {
                        var s0Received = theEvent.Get("s0");
                        var s1Received = theEvent.Get("s1");
                        //ThreadLogUtil.Info("received", @event.Get("s0"), @event.Get("s1"));
                        if (s0Received == eventS0 && s1Received == eventS1)
                        {
                            found = true;
                        }
                    }

                    if (!found)
                    {
                    }

                    Assert.IsTrue(found);
                    assertListener.Reset();
                }
            }
            catch (AssertionException ex)
            {
                Log.Error("Assertion error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }
            catch (Exception ex)
            {
                Log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }

            return true;
        }
        public bool Call()
        {
            try
            {
                SupportMTUpdateListener listener = new SupportMTUpdateListener();
                _targetStatement.Events += listener.Update;

                for (int loop = 0; loop < _numRepeats; loop++)
                {
                    String threadKey     = "K" + loop + "_" + _threadNum;
                    int    valueExpected = _threadNum * 1000000000 + loop + 1;

                    // send insert event with string-value specific to thread
                    SendEvent(threadKey, valueExpected);

                    // send subquery trigger event with string-value specific to thread
                    _engine.EPRuntime.SendEvent(new SupportBean(threadKey, -1));

                    // assert trigger event received
                    IList <EventBean[]> events = listener.GetNewDataListCopy();
                    bool found = false;
                    foreach (EventBean[] arr in events)
                    {
                        foreach (EventBean item in arr)
                        {
                            var value = (int?)item.Get("val");
                            if (value == valueExpected)
                            {
                                found = true;
                                break;
                            }
                        }
                        if (found)
                        {
                            break;
                        }
                    }
                    listener.Reset();

                    if (!found)
                    {
                        return(false);
                    }

                    // send delete event with string-value specific to thread
                    SendEvent(threadKey, 0);
                }
            }
            catch (Exception ex)
            {
                Log.Fatal("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return(false);
            }
            return(true);
        }
        private void TrySend(EPServiceProvider epService, SupportMTUpdateListener listener, int numThreads, int numRepeats)
        {
            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var future     = new Future <bool> [numThreads];

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

            threadPool.Shutdown();
            threadPool.AwaitTermination(10, TimeUnit.SECONDS);

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

            // Assert results
            int totalExpected = numThreads * numRepeats * 2;

            EventBean[] result = listener.GetNewDataListFlattened();
            Assert.AreEqual(totalExpected, result.Length);
            var results = new LinkedHashMap <long, ISet <string> >();

            foreach (EventBean theEvent in result)
            {
                long   count = (long)theEvent.Get("mycount");
                string key   = (string)theEvent.Get("key");

                ISet <string> entries = results.Get(count);
                if (entries == null)
                {
                    entries = new HashSet <string>();
                    results.Put(count, entries);
                }
                entries.Add(key);
            }

            Assert.AreEqual(numRepeats, results.Count);
            foreach (ISet <string> value in results.Values)
            {
                Assert.AreEqual(2 * numThreads, value.Count);
                for (int i = 0; i < numThreads; i++)
                {
                    Assert.IsTrue(value.Contains("E1_" + i));
                    Assert.IsTrue(value.Contains("E2_" + i));
                }
            }

            listener.Reset();
        }
        private void TrySend(EPServiceProvider epService, SupportMTUpdateListener listener, int numThreads, int numRepeats)
        {
            // set time to 0
            epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));

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

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

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

            threadPool.Shutdown();
            threadPool.AwaitTermination(10, TimeUnit.SECONDS);

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

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

            // Assert results
            var totalExpected = numThreads * numRepeats;

            // assert new data
            var resultNewData = listener.GetNewDataListFlattened();

            Assert.AreEqual(totalExpected, resultNewData.Length);
            var resultsNewData = SortPerIntKey(resultNewData);

            AssertResult(numRepeats, numThreads, resultsNewData);

            // assert old data
            var resultOldData = listener.GetOldDataListFlattened();

            Assert.AreEqual(totalExpected, resultOldData.Length);
            var resultsOldData = SortPerIntKey(resultOldData);

            AssertResult(numRepeats, numThreads, resultsOldData);

            listener.Reset();
        }
Beispiel #6
0
        private void TrySend(int numThreads, int numRepeats)
        {
            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var future     = new Future <bool> [numThreads];

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

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

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

            // Assert results
            int totalExpected = numThreads * numRepeats * 2;

            EventBean[] result = _listener.GetNewDataListFlattened();
            Assert.AreEqual(totalExpected, result.Length);
            var results = new LinkedHashMap <long, ICollection <String> >();

            foreach (EventBean theEvent in result)
            {
                var count = theEvent.Get("mycount").AsLong();
                var key   = (String)theEvent.Get("key");

                ICollection <String> entries = results.Get(count);
                if (entries == null)
                {
                    entries = new HashSet <String>();
                    results.Put(count, entries);
                }
                entries.Add(key);
            }

            Assert.AreEqual(numRepeats, results.Count);
            foreach (ICollection <String> value in results.Values)
            {
                Assert.AreEqual(2 * numThreads, value.Count);
                for (int i = 0; i < numThreads; i++)
                {
                    Assert.IsTrue(value.Contains("E1_" + i));
                    Assert.IsTrue(value.Contains("E2_" + i));
                }
            }

            _listener.Reset();
        }
Beispiel #7
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();
        }
Beispiel #8
0
        public bool Call()
        {
            try
            {
                // Add assertListener
                var assertListener = new SupportMTUpdateListener();
                ThreadLogUtil.Trace("adding listeners ", assertListener);
                _stmt.Events += assertListener.Update;

                for (var loop = 0; loop < _numRepeats; loop++)
                {
                    var intPrimitive = loop % 10 + 1;
                    object eventS0 = MakeEvent(intPrimitive);

                    _engine.EPRuntime.SendEvent(eventS0);

                    // Should have received one that's mine, possible multiple since the statement is used by other threads
                    var found = false;
                    var events = assertListener.GetNewDataListFlattened();
                    foreach (var theEvent in events)
                    {
                        var s0Received = theEvent.Get("s0");
                        var s1Received = (IDictionary<string, object>) theEvent.Get("s1");
                        if (s0Received == eventS0 ||
                            s1Received.Get("myvarchar").Equals(_myvarcharValues[intPrimitive - 1]))
                        {
                            found = true;
                        }
                    }

                    if (!found)
                    {
                    }

                    Assert.IsTrue(found);
                    assertListener.Reset();
                }
            }
            catch (AssertionException ex)
            {
                Log.Error("Assertion error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }
            catch (Exception ex)
            {
                Log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }

            return true;
        }
Beispiel #9
0
        private static void TrySend(
            RegressionEnvironment env,
            SupportMTUpdateListener listener,
            int numThreads,
            int numRepeats)
        {
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadStmtInsertInto)).ThreadFactory);
            var future = new IFuture<object>[numThreads];
            for (var i = 0; i < numThreads; i++) {
                var callable = new StmtInsertIntoCallable(Convert.ToString(i), env.Runtime, numRepeats);
                future[i] = threadPool.Submit(callable);
            }

            threadPool.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS);
            SupportCompileDeployUtil.AssertFutures(future);

            // Assert results
            var totalExpected = numThreads * numRepeats * 2;
            var result = listener.GetNewDataListFlattened();
            Assert.AreEqual(totalExpected, result.Length);
            IDictionary<long, ICollection<string>> results = new Dictionary<long, ICollection<string>>();
            foreach (var theEvent in result) {
                var count = theEvent.Get("mycount").AsInt64();
                var key = (string) theEvent.Get("key");

                var entries = results.Get(count);
                if (entries == null) {
                    entries = new HashSet<string>();
                    results.Put(count, entries);
                }

                entries.Add(key);
            }

            Assert.AreEqual(numRepeats, results.Count);
            foreach (var value in results.Values) {
                Assert.AreEqual(2 * numThreads, value.Count);
                for (var i = 0; i < numThreads; i++) {
                    Assert.IsTrue(value.Contains("E1_" + i));
                    Assert.IsTrue(value.Contains("E2_" + i));
                }
            }

            listener.Reset();
        }
Beispiel #10
0
        public bool? Call()
        {
            try {
                var listener = new SupportMTUpdateListener();
                targetStatement.AddListener(listener);

                for (var loop = 0; loop < numRepeats; loop++) {
                    var threadKey = "K" + loop + "_" + threadNum;
                    var valueExpected = threadNum * 1000000000 + loop + 1;

                    // send insert event with string-value specific to thread
                    SendEvent(threadKey, valueExpected);

                    // send subquery trigger event with string-value specific to thread
                    runtime.EventService.SendEventBean(new SupportBean(threadKey, -1), "SupportBean");

                    // assert trigger event received
                    var events = listener.GetNewDataListCopy();
                    var found = false;
                    foreach (var arr in events) {
                        found = arr
                            .Select(item => item.Get("val").AsInt32())
                            .Any(value => value == valueExpected);
                        if (found) {
                            break;
                        }
                    }

                    listener.Reset();

                    if (!found) {
                        return false;
                    }

                    // send delete event with string-value specific to thread
                    SendEvent(threadKey, 0);
                }
            }
            catch (Exception ex) {
                log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }

            return true;
        }
        public bool Call()
        {
            try {
                // Add assertListener
                var assertListener1 = new SupportMTUpdateListener(Thread.CurrentThread.Name + "#1");
                ThreadLogUtil.Trace("adding listeners ", assertListener1);
                //stmt.Events += assertListener1.Update;
                _stmt.Events += assertListener1.Update;

                for (int loop = 0; loop < _numRepeats; loop++)
                {
                    var intPrimitive = loop % 10 + 1;
                    var eventS0      = MakeEvent(intPrimitive);
                    _engine.EPRuntime.SendEvent(eventS0);

                    // Should have received one that's mine, possible multiple since the statement is used by other threads
                    var found  = false;
                    var events = assertListener1.GetNewDataListFlattened();

                    foreach (var theEvent in events)
                    {
                        var s0Received = theEvent.Get("s0");
                        var s1Received = (DataMap)theEvent.Get("s1");
                        if ((s0Received == eventS0) ||
                            (s1Received.Get("myvarchar").Equals(_myvarcharValues[intPrimitive - 1])))
                        {
                            found = true;
                        }
                    }

                    Assert.IsTrue(found);
                    assertListener1.Reset();
                }
            }
            catch (AssertionException ex) {
                Console.WriteLine(ex.Message);
                Log.Fatal("Assertion error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return(false);
            }
            catch (Exception ex) {
                Log.Fatal("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return(false);
            }
            return(true);
        }
Beispiel #12
0
        private void FindEvent(SupportMTUpdateListener listener, int loop, object theEvent)
        {
            var message = "Failed in loop " + loop + " threads " + Thread.CurrentThread;
            Assert.IsTrue(listener.IsInvoked, message);
            var eventBeans = listener.NewDataListCopy;
            var found = false;
            foreach (var events in eventBeans)
            {
                Assert.AreEqual(1, events.Length, message);
                if (events[0].Underlying == theEvent)
                {
                    found = true;
                }
            }

            Assert.IsTrue(found, message);
            listener.Reset();
        }
Beispiel #13
0
        private void TrySend(EPServiceProvider epService, int numThreads, int numRepeats)
        {
            EPStatement stmt = epService.EPAdministrator.CreateEPL(
                "select (select id from S0#length(1000000) where id = s1.id) as value from S1 as s1");

            var listener = new SupportMTUpdateListener();

            stmt.Events += listener.Update;

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

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

            threadPool.Shutdown();
            threadPool.AwaitTermination(10, TimeUnit.SECONDS);

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

            // Assert results
            int totalExpected = numThreads * numRepeats;

            // assert new data
            EventBean[] resultNewData = listener.GetNewDataListFlattened();
            Assert.AreEqual(totalExpected, resultNewData.Length);

            var values = new HashSet <int?>();

            foreach (EventBean theEvent in resultNewData)
            {
                values.Add((int?)theEvent.Get("value"));
            }
            Assert.AreEqual(totalExpected, values.Count, "Unexpected duplicates");

            listener.Reset();
            stmt.Stop();
        }
Beispiel #14
0
        private static void TrySend(
            RegressionEnvironment env,
            int numThreads,
            int numRepeats)
        {
            env.CompileDeploy(
                "@Name('s0') select (select Id from SupportBean_S0#length(1000000) where Id = S1.Id) as value from SupportBean_S1 as S1");
            var listener = new SupportMTUpdateListener();
            env.Statement("s0").AddListener(listener);

            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadStmtSubquery)).ThreadFactory);
            var future = new IFuture<object>[numThreads];
            for (var i = 0; i < numThreads; i++) {
                var callable = new StmtSubqueryCallable(i, env.Runtime, numRepeats);
                future[i] = threadPool.Submit(callable);
            }

            threadPool.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS);
            SupportCompileDeployUtil.AssertFutures(future);

            // Assert results
            var totalExpected = numThreads * numRepeats;

            // assert new data
            var resultNewData = listener.GetNewDataListFlattened();
            Assert.AreEqual(totalExpected, resultNewData.Length);

            ISet<int> values = new HashSet<int>();
            foreach (var theEvent in resultNewData) {
                values.Add(theEvent.Get("value").AsInt32());
            }

            Assert.AreEqual(totalExpected, values.Count, "Unexpected duplicates");

            listener.Reset();
            env.UndeployAll();
        }
Beispiel #15
0
        public bool Call()
        {
            var listenerIsolated = new SupportMTUpdateListener();
            var listenerUnisolated = new SupportMTUpdateListener();
            var stmt = _engine.EPAdministrator.CreateEPL("select * from SupportBean");

            try
            {
                for (var i = 0; i < _loopCount; i++)
                {
                    var isolated = _engine.GetEPServiceIsolated("i1");
                    isolated.EPAdministrator.AddStatement(stmt);

                    listenerIsolated.Reset();
                    stmt.Events += listenerIsolated.Update;
                    var theEvent = new SupportBean();
                    //Log.Info("Sensing event : " + event + " by thread " + Thread.CurrentThread.ManagedThreadId);
                    isolated.EPRuntime.SendEvent(theEvent);
                    FindEvent(listenerIsolated, i, theEvent);
                    stmt.RemoveAllEventHandlers();

                    isolated.EPAdministrator.RemoveStatement(stmt);

                    stmt.Events += listenerUnisolated.Update;
                    theEvent = new SupportBean();
                    _engine.EPRuntime.SendEvent(theEvent);
                    FindEvent(listenerUnisolated, i, theEvent);
                    stmt.RemoveAllEventHandlers();
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error in thread " + _threadNum, ex);
                return false;
            }

            return true;
        }
Beispiel #16
0
        public bool Call()
        {
            SupportMTUpdateListener listenerIsolated   = new SupportMTUpdateListener();
            SupportMTUpdateListener listenerUnisolated = new SupportMTUpdateListener();
            EPStatement             stmt = _engine.EPAdministrator.CreateEPL("select * from SupportBean");

            try
            {
                for (int i = 0; i < _loopCount; i++)
                {
                    EPServiceProviderIsolated isolated = _engine.GetEPServiceIsolated("i1");
                    isolated.EPAdministrator.AddStatement(stmt);

                    listenerIsolated.Reset();
                    stmt.Events += listenerIsolated.Update;
                    Object theEvent = new SupportBean();
                    //Console.Out.WriteLine("Sensing event : " + event + " by thread " + Thread.CurrentThread.ManagedThreadId);
                    isolated.EPRuntime.SendEvent(theEvent);
                    FindEvent(listenerIsolated, i, theEvent);
                    stmt.RemoveAllEventHandlers();

                    isolated.EPAdministrator.RemoveStatement(stmt);

                    stmt.Events += listenerUnisolated.Update;
                    theEvent     = new SupportBean();
                    _engine.EPRuntime.SendEvent(theEvent);
                    FindEvent(listenerUnisolated, i, theEvent);
                    stmt.RemoveAllEventHandlers();
                }
            }
            catch (Exception ex)
            {
                Log.Fatal("Error in thread " + _threadNum, ex);
                return(false);
            }
            return(true);
        }
Beispiel #17
0
        public bool Call()
        {
            try {
                for (int loop = 0; loop < _numRepeats; loop++)
                {
                    // Add assertListener
                    var assertListener = new SupportMTUpdateListener();
                    LogUpdateListener logListener;
                    if (_isEPL)
                    {
                        logListener = new LogUpdateListener(null);
                    }
                    else
                    {
                        logListener = new LogUpdateListener("a");
                    }
                    ThreadLogUtil.Trace("adding listeners ", assertListener, logListener);
                    _stmt.Events += assertListener.Update;
                    _stmt.Events += logListener.Update;

                    // send event
                    Object theEvent = MakeEvent();
                    ThreadLogUtil.Trace("sending event ", theEvent);
                    _engine.EPRuntime.SendEvent(theEvent);

                    // Should have received one or more events, one of them must be mine
                    EventBean[] newEvents = assertListener.GetNewDataListFlattened();
                    Assert.IsTrue(newEvents.Length >= 1, "No event received");
                    ThreadLogUtil.Trace("assert received, size is", newEvents.Length);
                    bool found = false;
                    for (int i = 0; i < newEvents.Length; i++)
                    {
                        Object underlying = newEvents[i].Underlying;
                        if (!_isEPL)
                        {
                            underlying = newEvents[i].Get("a");
                        }
                        if (underlying == theEvent)
                        {
                            found = true;
                        }
                    }
                    Assert.IsTrue(found);
                    assertListener.Reset();

                    // Remove assertListener
                    ThreadLogUtil.Trace("removing assertListener");
                    _stmt.Events -= assertListener.Update;
                    _stmt.Events -= logListener.Update;

                    // Send another event
                    theEvent = MakeEvent();
                    ThreadLogUtil.Trace("send non-matching event ", theEvent);
                    _engine.EPRuntime.SendEvent(theEvent);

                    // Make sure the event was not received
                    newEvents = assertListener.GetNewDataListFlattened();
                    found     = false;
                    for (int i = 0; i < newEvents.Length; i++)
                    {
                        Object underlying = newEvents[i].Underlying;
                        if (!_isEPL)
                        {
                            underlying = newEvents[i].Get("a");
                        }
                        if (underlying == theEvent)
                        {
                            found = true;
                        }
                    }
                    Assert.IsFalse(found);
                }
            }
            catch (AssertionException ex) {
                Log.Error("Assertion error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return(false);
            }
            catch (Exception ex) {
                Log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return(false);
            }
            return(true);
        }
Beispiel #18
0
        public bool Call()
        {
            try
            {
                for (int loop = 0; loop < _numRepeats; loop++)
                {
                    foreach (object[] statement in _statements)
                    {
                        bool   isEPL         = statement[0].AsBoolean();
                        string statementText = (string)statement[1];

                        // Create EPL or pattern statement
                        EPStatement stmt;
                        ThreadLogUtil.Trace("stmt create,", statementText);
                        if (isEPL)
                        {
                            stmt = _engine.EPAdministrator.CreateEPL(statementText);
                        }
                        else
                        {
                            stmt = _engine.EPAdministrator.CreatePattern(statementText);
                        }

                        ThreadLogUtil.Trace("stmt done,", stmt);

                        // Add listener
                        var listener = new SupportMTUpdateListener();
                        LogUpdateListener logListener;
                        if (isEPL)
                        {
                            logListener = new LogUpdateListener(null);
                        }
                        else
                        {
                            logListener = new LogUpdateListener("a");
                        }

                        ThreadLogUtil.Trace("adding listeners ", listener, logListener);
                        stmt.Events += listener.Update;
                        stmt.Events += logListener.Update;

                        Object theEvent = MakeEvent();
                        ThreadLogUtil.Trace("sending event ", theEvent);
                        _engine.EPRuntime.SendEvent(theEvent);

                        // Should have received one or more events, one of them must be mine
                        EventBean[] newEvents = listener.GetNewDataListFlattened();
                        Assert.IsTrue(newEvents.Length >= 1, "No event received");
                        ThreadLogUtil.Trace("assert received, size is", newEvents.Length);
                        bool found = false;
                        for (int i = 0; i < newEvents.Length; i++)
                        {
                            var underlying = newEvents[i].Underlying;
                            if (!isEPL)
                            {
                                underlying = newEvents[i].Get("a");
                            }

                            if (underlying == theEvent)
                            {
                                found = true;
                            }
                        }

                        Assert.IsTrue(found);
                        listener.Reset();

                        // Stopping statement, the event should not be received, another event may however
                        ThreadLogUtil.Trace("stop statement");
                        stmt.Stop();
                        theEvent = MakeEvent();
                        ThreadLogUtil.Trace("send non-matching event ", theEvent);
                        _engine.EPRuntime.SendEvent(theEvent);

                        // Make sure the event was not received
                        newEvents = listener.GetNewDataListFlattened();
                        found     = false;
                        for (int i = 0; i < newEvents.Length; i++)
                        {
                            var underlying = newEvents[i].Underlying;
                            if (!isEPL)
                            {
                                underlying = newEvents[i].Get("a");
                            }

                            if (underlying == theEvent)
                            {
                                found = true;
                            }
                        }

                        Assert.IsFalse(found);
                    }
                }
            }
            catch (AssertionException ex)
            {
                Log.Error("Assertion error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return(false);
            }
            catch (Exception ex)
            {
                Log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return(false);
            }

            return(true);
        }
Beispiel #19
0
        public object Call()
        {
            try {
                for (var loop = 0; loop < numRepeats; loop++) {
                    foreach (var statement in statements) {
                        var statementText = statement.Epl;
                        var compiled = statement.Compiled;

                        // Create EPL or pattern statement
                        ThreadLogUtil.Trace("stmt create,", statementText);
                        var deployed = runtime.DeploymentService.Deploy(compiled);
                        ThreadLogUtil.Trace("stmt done,", statementText);

                        // Add listener
                        var listener = new SupportMTUpdateListener();
                        var logListener = new LogUpdateListener(null);
                        ThreadLogUtil.Trace("adding listeners ", listener, logListener);
                        deployed.Statements[0].AddListener(listener);
                        deployed.Statements[0].AddListener(logListener);

                        object theEvent = MakeEvent();
                        ThreadLogUtil.Trace("sending event ", theEvent);
                        runtime.EventService.SendEventBean(theEvent, theEvent.GetType().Name);

                        // Should have received one or more events, one of them must be mine
                        var newEvents = listener.GetNewDataListFlattened();
                        Assert.IsTrue(newEvents.Length >= 1, "No event received");
                        ThreadLogUtil.Trace("assert received, size is", newEvents.Length);
                        var found = false;
                        for (var i = 0; i < newEvents.Length; i++) {
                            var underlying = newEvents[i].Underlying;
                            if (underlying == theEvent) {
                                found = true;
                            }
                        }

                        Assert.IsTrue(found);
                        listener.Reset();

                        // Stopping statement, the event should not be received, another event may however
                        ThreadLogUtil.Trace("stop statement");
                        runtime.DeploymentService.Undeploy(deployed.DeploymentId);
                        theEvent = MakeEvent();
                        ThreadLogUtil.Trace("send non-matching event ", theEvent);
                        runtime.EventService.SendEventBean(theEvent, theEvent.GetType().Name);

                        // Make sure the event was not received
                        newEvents = listener.GetNewDataListFlattened();
                        found = false;
                        for (var i = 0; i < newEvents.Length; i++) {
                            var underlying = newEvents[i].Underlying;
                            if (underlying == theEvent) {
                                found = true;
                            }
                        }

                        Assert.IsFalse(found);
                    }
                }
            }
            catch (AssertionException ex) {
                log.Error("Assertion error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }
            catch (Exception ex) {
                log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }

            return true;
        }
Beispiel #20
0
        public object Call()
        {
            try {
                for (var loop = 0; loop < numRepeats; loop++) {
                    // Add assertListener
                    var assertListener = new SupportMTUpdateListener();
                    LogUpdateListener logListener;
                    if (isEPL) {
                        logListener = new LogUpdateListener(null);
                    }
                    else {
                        logListener = new LogUpdateListener("a");
                    }

                    ThreadLogUtil.Trace("adding listeners ", assertListener, logListener);
                    stmt.AddListener(assertListener);
                    stmt.AddListener(logListener);

                    // send event
                    object theEvent = MakeEvent();
                    ThreadLogUtil.Trace("sending event ", theEvent);
                    runtime.EventService.SendEventBean(theEvent, theEvent.GetType().Name);

                    // Should have received one or more events, one of them must be mine
                    var newEvents = assertListener.GetNewDataListFlattened();
                    ThreadLogUtil.Trace("assert received, size is", newEvents.Length);
                    var found = false;
                    for (var i = 0; i < newEvents.Length; i++) {
                        var underlying = newEvents[i].Underlying;
                        if (!isEPL) {
                            underlying = newEvents[i].Get("a");
                        }

                        if (underlying == theEvent) {
                            found = true;
                        }
                    }

                    Assert.IsTrue(found);
                    assertListener.Reset();

                    // Remove assertListener
                    ThreadLogUtil.Trace("removing assertListener");
                    stmt.RemoveListener(assertListener);
                    stmt.RemoveListener(logListener);

                    // Send another event
                    theEvent = MakeEvent();
                    ThreadLogUtil.Trace("send non-matching event ", theEvent);
                    runtime.EventService.SendEventBean(theEvent, theEvent.GetType().Name);

                    // Make sure the event was not received
                    newEvents = assertListener.GetNewDataListFlattened();
                    found = false;
                    for (var i = 0; i < newEvents.Length; i++) {
                        var underlying = newEvents[i].Underlying;
                        if (!isEPL) {
                            underlying = newEvents[i].Get("a");
                        }

                        if (underlying == theEvent) {
                            found = true;
                        }
                    }

                    Assert.IsFalse(found);
                }
            }
            catch (AssertionException ex) {
                log.Error("Assertion error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }
            catch (Exception ex) {
                log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }

            return true;
        }