Ejemplo n.º 1
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;
        }