Пример #1
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;
        }
Пример #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++)
                {
                    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;
        }
Пример #3
0
        public void Update(Object sender, UpdateEventArgs e)
        {
            EventBean theEvent = e.NewEvents[0];

            if (_fieldNameLogged == null)
            {
                ThreadLogUtil.Trace("listener received, " + " listener=" + this + " eventUnderlying=" +
                                    theEvent.Underlying.GetHashCode().ToString("X2"));
            }
            else
            {
                ThreadLogUtil.Trace("listener received, " + " listener=" + this + " eventUnderlying=" +
                                    theEvent.Get(_fieldNameLogged).GetHashCode().ToString("X2"));
            }
        }
        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);
        }
Пример #5
0
 public void Update(
     object sender,
     UpdateEventArgs eventArgs)
 {
     var theEvent = eventArgs.NewEvents[0];
     if (fieldNameLogged == null) {
         ThreadLogUtil.Trace(
             "listener received, " +
             " listener=" +
             this +
             " eventUnderlying=" +
             theEvent.Underlying.GetHashCode().ToString("X4"));
     }
     else {
         ThreadLogUtil.Trace(
             "listener received, " +
             " listener=" +
             this +
             " eventUnderlying=" +
             theEvent.Get("a").GetHashCode().ToString("X4"));
     }
 }
Пример #6
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);
        }
Пример #7
0
        private void ProcessMatches(EventBean theEvent)
        {
            var localData = LocalData;

            // get matching filters
            var matches = localData.MatchesArrayThreadLocal;

            _services.FilterService.Evaluate(theEvent, matches);

            if (ThreadLogUtil.ENABLED_TRACE)
            {
                ThreadLogUtil.Trace("Found matches for underlying ", matches.Count, theEvent.Underlying);
            }

            if (matches.Count == 0)
            {
                return;
            }

            var stmtCallbacks = localData.MatchesPerStmtThreadLocal;
            int entryCount    = matches.Count;

            for (int i = 0; i < entryCount; i++)
            {
                var handleCallback = (EPStatementHandleCallback)matches[i];
                var handle         = handleCallback.AgentInstanceHandle;

                // Self-joins require that the internal dispatch happens after all streams are evaluated.
                // Priority or preemptive settings also require special ordering.
                if (handle.CanSelfJoin || _isPrioritized)
                {
                    var callbacks = stmtCallbacks.Get(handle);
                    if (callbacks == null)
                    {
                        callbacks = new LinkedList <FilterHandleCallback>();
                        stmtCallbacks.Put(handle, callbacks);
                    }
                    callbacks.AddLast(handleCallback.FilterCallback);
                    continue;
                }

                ProcessStatementFilterSingle(handle, handleCallback, theEvent);
            }
            matches.Clear();
            if (stmtCallbacks.IsEmpty())
            {
                return;
            }

            foreach (var entry in stmtCallbacks)
            {
                var handle       = entry.Key;
                var callbackList = entry.Value;

                ProcessStatementFilterMultiple(handle, callbackList, theEvent);

                if ((_isPrioritized) && (handle.IsPreemptive))
                {
                    break;
                }
            }
            stmtCallbacks.Clear();
        }
Пример #8
0
        private void ProcessScheduleHandles(ArrayBackedCollection <ScheduleHandle> handles)
        {
            if (ThreadLogUtil.ENABLED_TRACE)
            {
                ThreadLogUtil.Trace("Found schedules for", handles.Count);
            }

            if (handles.Count == 0)
            {
                return;
            }

            // handle 1 result separatly for performance reasons
            if (handles.Count == 1)
            {
                Object[] handleArray = handles.Array;
                var      handle      = (EPStatementHandleCallback)handleArray[0];

                EPRuntimeImpl.ProcessStatementScheduleSingle(handle, _unisolatedServices);

                handles.Clear();
                return;
            }

            Object[] matchArray = handles.Array;
            int      entryCount = handles.Count;

            LinkedList <ScheduleHandleCallback> entries;

            // sort multiple matches for the event into statements
            var stmtCallbacks = SchedulePerStmt;

            stmtCallbacks.Clear();
            for (int i = 0; i < entryCount; i++)
            {
                var handleCallback = (EPStatementHandleCallback)matchArray[i];
                var handle         = handleCallback.AgentInstanceHandle;
                var callback       = handleCallback.ScheduleCallback;

                var entry = stmtCallbacks.Get(handle);

                // This statement has not been encountered before
                if (entry == null)
                {
                    stmtCallbacks.Put(handle, callback);
                    continue;
                }

                // This statement has been encountered once before
                if (entry is ScheduleHandleCallback)
                {
                    var existingCallback = (ScheduleHandleCallback)entry;
                    entries = new LinkedList <ScheduleHandleCallback>();
                    entries.AddLast(existingCallback);
                    entries.AddLast(callback);
                    stmtCallbacks.Put(handle, entries);
                    continue;
                }

                // This statement has been encountered more then once before
                entries = (LinkedList <ScheduleHandleCallback>)entry;
                entries.AddLast(callback);
            }
            handles.Clear();

            foreach (var entry in stmtCallbacks)
            {
                var handle         = entry.Key;
                var callbackObject = entry.Value;

                EPRuntimeImpl.ProcessStatementScheduleMultiple(handle, callbackObject, _unisolatedServices);

                if ((_isPrioritized) && (handle.IsPreemptive))
                {
                    break;
                }
            }
        }
Пример #9
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);
        }
Пример #10
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;
        }
Пример #11
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;
        }