Beispiel #1
0
 public bool Call()
 {
     try
     {
         for (int loop = 0; loop < _numRepeats; loop++)
         {
             var listener = new MyUpdateListener(_engine, _numThread);
             _statement.Events += listener.Update;
             _engine.EPRuntime.SendEvent(new SupportBean());
             _statement.Events -= listener.Update;
             listener.AssertCalled();
         }
     }
     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 #2
0
        public object Call()
        {
            try {
                for (var loop = 0; loop < numRepeats; loop++) {
                    var listener = new MyUpdateListener(env, numThread);
                    statement.AddListener(listener);
                    env.SendEventBean(new SupportBean(), "SupportBean");
                    statement.RemoveListener(listener);
                    listener.AssertCalled();
                }
            }
            catch (AssertionException ex) {
                Console.Error.WriteLine("Assertion error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                Console.Error.WriteLine(ex.StackTrace);
                log.Error("Assertion error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }
            catch (Exception ex) {
                Console.Error.WriteLine("Error in thread " + Thread.CurrentThread.ManagedThreadId);
                Console.Error.WriteLine(ex.StackTrace);
                log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex);
                return false;
            }

            return true;
        }
Beispiel #3
0
        public void TestFollowedByFilter()
        {
            // Test for ESPER-121
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.AddEventType <SupportTradeEvent>("FxTradeEvent");
            EPServiceProvider epService = EPServiceProviderManager.GetProvider(
                "testRFIDZoneEnter", config);

            epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName);
            }

            String expression = "every tradeevent1=FxTradeEvent(userId in ('U1000','U1001','U1002') ) -> " +
                                "(tradeevent2=FxTradeEvent(userId in ('U1000','U1001','U1002') and " +
                                "  userId != tradeevent1.userId and " +
                                "  ccypair = tradeevent1.ccypair and " +
                                "  direction = tradeevent1.direction) -> " +
                                " tradeevent3=FxTradeEvent(userId in ('U1000','U1001','U1002') and " +
                                "  userId != tradeevent1.userId and " +
                                "  userId != tradeevent2.userId and " +
                                "  ccypair = tradeevent1.ccypair and " +
                                "  direction = tradeevent1.direction)" +
                                ") where timer:within(600 sec)";

            EPStatement      statement = epService.EPAdministrator.CreatePattern(expression);
            MyUpdateListener listener  = new MyUpdateListener();

            statement.Events += (sender, e) => listener.Update(e.NewEvents, e.OldEvents);

            Random random = new Random();

            String[] users     = { "U1000", "U1001", "U1002" };
            String[] ccy       = { "USD", "JPY", "EUR" };
            String[] direction = { "B", "S" };

            for (int i = 0; i < 100; i++)
            {
                SupportTradeEvent theEvent = new SupportTradeEvent(
                    i,
                    users[random.Next(0, users.Length)],
                    ccy[random.Next(0, ccy.Length)],
                    direction[random.Next(0, direction.Length)]);
                epService.EPRuntime.SendEvent(theEvent);
            }

            Assert.AreEqual(0, listener.BadMatchCount);

            epService.Dispose();

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
        }
Beispiel #4
0
        public void Run(RegressionEnvironment env)
        {
            var epl = "create schema ScoreCycle (userId string, keyword string, ProductId string, score long);\n" +
                      "\n" +
                      "create schema UserKeywordTotalStream (userId string, keyword string, sumScore long);\n" +
                      "\n" +
                      "create context HashByUserCtx as\n" +
                      "coalesce by consistent_hash_crc32(userId) from ScoreCycle,\n" +
                      "consistent_hash_crc32(userId) from UserKeywordTotalStream \n" +
                      "granularity 10000000;\n" +
                      "\n" +
                      "context HashByUserCtx create window ScoreCycleWindow#unique(userId, keyword, ProductId) as ScoreCycle;\n" +
                      "\n" +
                      "context HashByUserCtx insert into ScoreCycleWindow select * from ScoreCycle;\n" +
                      "\n" +
                      "@Name('Select') context HashByUserCtx insert into UserKeywordTotalStream\n" +
                      "select userId, keyword, sum(score) as sumScore from ScoreCycleWindow group by userId, keyword;";
            env.CompileDeployWBusPublicType(epl, new RegressionPath());
            var listener = new MyUpdateListener();
            env.Statement("Select").AddListener(listener);

            IList<IDictionary<string, object>> sendsT1 = new List<IDictionary<string, object>>();
            sendsT1.Add(MakeEvent("A", "house", "P0", 1));
            sendsT1.Add(MakeEvent("B", "house", "P0", 2));
            IList<IDictionary<string, object>> sendsT2 = new List<IDictionary<string, object>>();
            sendsT2.Add(MakeEvent("B", "house", "P0", 3));
            sendsT1.Add(MakeEvent("A", "house", "P0", 4));

            var threadPool = Executors.NewFixedThreadPool(
                2,
                new SupportThreadFactory(typeof(MultithreadContextUnique)).ThreadFactory);
            var runnableOne = new SendEventRunnable(env.Runtime, sendsT1, "ScoreCycle");
            var runnableTwo = new SendEventRunnable(env.Runtime, sendsT2, "ScoreCycle");
            threadPool.Submit(runnableOne.Run);
            threadPool.Submit(runnableTwo.Run);

            threadPool.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(threadPool, 1, TimeUnit.SECONDS);

            Assert.IsNull(runnableOne.LastException);
            Assert.IsNull(runnableTwo.LastException);

            // compare
            var received = listener.Received;
            foreach (var item in received) {
                Console.Out.WriteLine(item);
            }

            Assert.AreEqual(4, received.Count);

            env.UndeployAll();
        }
Beispiel #5
0
        public void TestContextUnique()
        {
            String epl = "create schema ScoreCycle (userId string, keyword string, productId string, score long);\n" +
                         "\n" +
                         "create schema UserKeywordTotalStream (userId string, keyword string, sumScore long);\n" +
                         "\n" +
                         "create context HashByUserCtx as\n" +
                         "coalesce by consistent_hash_crc32(userId) from ScoreCycle,\n" +
                         "consistent_hash_crc32(userId) from UserKeywordTotalStream \n" +
                         "granularity 10000000;\n" +
                         "\n" +
                         "context HashByUserCtx create window ScoreCycleWindow.std:unique(userId, keyword, productId) as ScoreCycle;\n" +
                         "\n" +
                         "context HashByUserCtx insert into ScoreCycleWindow select * from ScoreCycle;\n" +
                         "\n" +
                         "@Name('Select') context HashByUserCtx insert into UserKeywordTotalStream\n" +
                         "select userId, keyword, sum(score) as sumScore from ScoreCycleWindow group by userId, keyword;";

            _engine.EPAdministrator.DeploymentAdmin.ParseDeploy(epl);
            var listener = new MyUpdateListener();

            _engine.EPAdministrator.GetStatement("Select").Events += listener.Update;

            var sendsT1 = new List <Map>();

            sendsT1.Add(MakeEvent("A", "house", "P0", 1));
            sendsT1.Add(MakeEvent("B", "house", "P0", 2));
            var sendsT2 = new List <Map>();

            sendsT2.Add(MakeEvent("B", "house", "P0", 3));
            sendsT1.Add(MakeEvent("A", "house", "P0", 4));

            var threadPool = Executors.NewFixedThreadPool(2);

            threadPool.Submit((new SendEventRunnable(_engine, sendsT1, "ScoreCycle")).Run);
            threadPool.Submit((new SendEventRunnable(_engine, sendsT2, "ScoreCycle")).Run);
            threadPool.Shutdown();
            threadPool.AwaitTermination(TimeSpan.FromSeconds(1));

            // compare
            List <Object> received = listener.Received;

            foreach (Object item in received)
            {
                Console.WriteLine(item);
            }
            Assert.AreEqual(4, received.Count);
        }
        public override void Run(EPServiceProvider epService)
        {
            string epl = "create schema ScoreCycle (userId string, keyword string, productId string, score long);\n" +
                         "\n" +
                         "create schema UserKeywordTotalStream (userId string, keyword string, sumScore long);\n" +
                         "\n" +
                         "create context HashByUserCtx as\n" +
                         "coalesce by Consistent_hash_crc32(userId) from ScoreCycle,\n" +
                         "Consistent_hash_crc32(userId) from UserKeywordTotalStream \n" +
                         "granularity 10000000;\n" +
                         "\n" +
                         "context HashByUserCtx create window ScoreCycleWindow#unique(userId, keyword, productId) as ScoreCycle;\n" +
                         "\n" +
                         "context HashByUserCtx insert into ScoreCycleWindow select * from ScoreCycle;\n" +
                         "\n" +
                         "@Name('Select') context HashByUserCtx insert into UserKeywordTotalStream\n" +
                         "select userId, keyword, sum(score) as sumScore from ScoreCycleWindow group by userId, keyword;";

            epService.EPAdministrator.DeploymentAdmin.ParseDeploy(epl);
            var listener = new MyUpdateListener();

            epService.EPAdministrator.GetStatement("Select").Events += listener.Update;

            var sendsT1 = new List <Map>();

            sendsT1.Add(MakeEvent("A", "house", "P0", 1));
            sendsT1.Add(MakeEvent("B", "house", "P0", 2));
            var sendsT2 = new List <Map>();

            sendsT2.Add(MakeEvent("B", "house", "P0", 3));
            sendsT1.Add(MakeEvent("A", "house", "P0", 4));

            var threadPool = Executors.NewFixedThreadPool(2);

            threadPool.Submit(new SendEventRunnable(epService, sendsT1, "ScoreCycle").Run);
            threadPool.Submit(new SendEventRunnable(epService, sendsT2, "ScoreCycle").Run);
            threadPool.Shutdown();
            threadPool.AwaitTermination(1, TimeUnit.SECONDS);

            // compare
            List <object> received = listener.Received;

            foreach (Object item in received)
            {
                Log.Info(item.ToString());
            }
            Assert.AreEqual(4, received.Count);
        }
        public object Call()
        {
            try {
                // add listener to triggering statement
                var listener = new MyUpdateListener(runtime, numRoutes, numThread, routed);
                statement.AddListener(listener);
                Thread.Sleep(100); // wait to send trigger event, other threads receive all other's events

                runtime.EventService.SendEventBean(new SupportBean(), "SupportBean");
            }
            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 #8
0
        private void RunAssertionFollowedByFilter(EPServiceProvider epService)
        {
            // Test for ESPER-121
            epService.EPAdministrator.Configuration.AddEventType("FxTradeEvent", typeof(SupportTradeEvent));

            string expression = "every tradeevent1=FxTradeEvent(userId in ('U1000','U1001','U1002') ) -> " +
                                "(tradeevent2=FxTradeEvent(userId in ('U1000','U1001','U1002') and " +
                                "  userId != tradeevent1.userId and " +
                                "  ccypair = tradeevent1.ccypair and " +
                                "  direction = tradeevent1.direction) -> " +
                                " tradeevent3=FxTradeEvent(userId in ('U1000','U1001','U1002') and " +
                                "  userId != tradeevent1.userId and " +
                                "  userId != tradeevent2.userId and " +
                                "  ccypair = tradeevent1.ccypair and " +
                                "  direction = tradeevent1.direction)" +
                                ") where timer:within(600 sec)";

            EPStatement statement = epService.EPAdministrator.CreatePattern(expression);
            var         listener  = new MyUpdateListener();

            statement.Events += listener.Update;

            var random = new Random();

            string[] users     = { "U1000", "U1001", "U1002" };
            string[] ccy       = { "USD", "JPY", "EUR" };
            string[] direction = { "B", "S" };

            for (int i = 0; i < 100; i++)
            {
                var theEvent = new SupportTradeEvent(i,
                                                     users[random.Next(users.Length)],
                                                     ccy[random.Next(ccy.Length)], direction[random.Next(direction.Length)]);
                epService.EPRuntime.SendEvent(theEvent);
            }

            Assert.AreEqual(0, listener.BadMatchCount);
            statement.Dispose();
        }
        public bool Call()
        {
            try
            {
                // add listener to triggering statement
                MyUpdateListener listener = new MyUpdateListener(_engine, _numRoutes, () => _numThread, _routed);
                _statement.Events += listener.Update;
                Thread.Sleep(100);      // wait to send trigger event, other threads receive all other's events

                _engine.EPRuntime.SendEvent(new SupportBean());
            }
            catch (AssertionException ex)
            {
                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 #10
0
            public void Run(RegressionEnvironment env)
            {
                var expression = "@Name('s0') select * from pattern [" +
                                 "every tradeevent1=SupportTradeEvent(UserId in ('U1000','U1001','U1002') ) -> " +
                                 "(tradeevent2=SupportTradeEvent(UserId in ('U1000','U1001','U1002') and " +
                                 "  UserId != tradeevent1.UserId and " +
                                 "  Ccypair = tradeevent1.Ccypair and " +
                                 "  Direction = tradeevent1.Direction) -> " +
                                 "  tradeevent3=SupportTradeEvent(UserId in ('U1000','U1001','U1002') and " +
                                 "  UserId != tradeevent1.UserId and " +
                                 "  UserId != tradeevent2.UserId and " +
                                 "  Ccypair = tradeevent1.Ccypair and " +
                                 "  Direction = tradeevent1.Direction)" +
                                 ") where timer:within(600 sec)]";

                env.CompileDeploy(expression);
                var listener = new MyUpdateListener();
                env.Statement("s0").AddListener(listener);

                var random = new Random();
                string[] users = {"U1000", "U1001", "U1002"};
                string[] ccy = {"USD", "JPY", "EUR"};
                string[] direction = {"B", "S"};

                for (var i = 0; i < 100; i++) {
                    var theEvent = new
                        SupportTradeEvent(
                            i,
                            users[random.Next(users.Length)],
                            ccy[random.Next(ccy.Length)],
                            direction[random.Next(direction.Length)]);
                    env.SendEventBean(theEvent);
                }

                Assert.AreEqual(0, listener.BadMatchCount);
                env.UndeployAll();
            }