コード例 #1
0
        private void TrySend()
        {
            _epService.EPAdministrator.CreateEPL("create context EverySecond as start (*, *, *, *, *, *) end (*, *, *, *, *, *)");
            _epService.EPAdministrator.CreateEPL("context EverySecond select * from SupportBean");

            var timerRunnable = new TimerRunnable(_epService, 0, 24 * 60 * 60 * 1000, 1000);
            var timerThread   = new Thread(timerRunnable.Run)
            {
                Name = "timer"
            };

            var eventRunnable = new EventRunnable(_epService, 1000000);
            var eventThread   = new Thread(eventRunnable.Run)
            {
                Name = "event"
            };

            timerThread.Start();
            eventThread.Start();

            timerThread.Join();
            eventThread.Join();
            Assert.IsNull(eventRunnable.Exception);
            Assert.IsNull(timerRunnable.Exception);
        }
コード例 #2
0
        public override void Run(EPServiceProvider epService)
        {
            epService.EPAdministrator.CreateEPL("create context EverySecond as start (*, *, *, *, *, *) end (*, *, *, *, *, *)");
            epService.EPAdministrator.CreateEPL("context EverySecond select * from SupportBean");

            var timerRunnable = new TimerRunnable(epService, 0, 24 * 60 * 60 * 1000, 1000);
            var timerThread   = new Thread(timerRunnable.Run);

            timerThread.Name = "timer";

            var eventRunnable = new EventRunnable(epService, 1000000);
            var eventThread   = new Thread(eventRunnable.Run);

            eventThread.Name = "event";

            timerThread.Start();
            eventThread.Start();

            timerThread.Join();
            eventThread.Join();
            Assert.IsNull(eventRunnable.Exception);
            Assert.IsNull(timerRunnable.Exception);
        }
コード例 #3
0
        public void Run(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            env.CompileDeploy("create context EverySecond as start (*, *, *, *, *, *) end (*, *, *, *, *, *)", path);
            env.CompileDeploy("context EverySecond select * from SupportBean", path);

            var timerRunnable = new TimerRunnable(env, 0, 24 * 60 * 60 * 1000, 1000);
            var timerThread = new Thread(timerRunnable.Run);
            timerThread.Name = GetType().Name + "-timer";

            var eventRunnable = new EventRunnable(env, 1000000);
            var eventThread = new Thread(eventRunnable.Run);
            eventThread.Name = GetType().Name + "event";

            timerThread.Start();
            eventThread.Start();

            ThreadJoin(timerThread);
            ThreadJoin(eventThread);
            Assert.IsNull(eventRunnable.Exception);
            Assert.IsNull(timerRunnable.Exception);

            env.UndeployAll();
        }
コード例 #4
0
        private static void TrySend(
            RegressionEnvironment env,
            int numThreads,
            int numEvents,
            string[] choices)
        {
            if (numEvents < choices.Length) {
                throw new ArgumentException("Number of events must at least match number of choices");
            }

            env.AdvanceTime(0);
            var path = new RegressionPath();
            env.CompileDeploy("@Name('var') create variable boolean myvar = false", path);
            env.CompileDeploy("create context SegmentedByString as partition by TheString from SupportBean", path);
            env.CompileDeploy(
                "@Name('s0') context SegmentedByString select TheString, count(*) - 1 as cnt from SupportBean output snapshot when myvar = true",
                path);
            var listener = new SupportUpdateListener();
            env.Statement("s0").AddListener(listener);

            // preload - since concurrently sending same-category events an event can be dropped
            for (var i = 0; i < choices.Length; i++) {
                env.SendEventBean(new SupportBean(choices[i], 0));
            }

            var runnables = new EventRunnable[numThreads];
            for (var i = 0; i < runnables.Length; i++) {
                runnables[i] = new EventRunnable(env, numEvents, choices);
            }

            // start
            var threads = new Thread[runnables.Length];
            for (var i = 0; i < runnables.Length; i++) {
                threads[i] = new Thread(runnables[i].Run);
                threads[i].Name = typeof(MultithreadContextPartitionedWCount).Name;
                threads[i].Start();
            }

            // join
            log.Info("Waiting for completion");
            for (var i = 0; i < runnables.Length; i++) {
                SupportCompileDeployUtil.ThreadJoin(threads[i]);
            }

            IDictionary<string, long> totals = new Dictionary<string, long>();
            foreach (var choice in choices) {
                totals.Put(choice, 0L);
            }

            // verify
            var sum = 0;
            for (var i = 0; i < runnables.Length; i++) {
                Assert.IsNull(runnables[i].Exception);
                foreach (var entry in runnables[i].GetTotals()) {
                    var current = totals.Get(entry.Key);
                    current += entry.Value;
                    sum += entry.Value;
                    totals.Put(entry.Key, current);
                    //System.out.println("Thread " + i + " key " + entry.getKey() + " count " + entry.getValue());
                }
            }

            Assert.AreEqual(numThreads * numEvents, sum);

            env.Runtime.VariableService.SetVariableValue(env.DeploymentId("var"), "myvar", true);
            env.AdvanceTime(10000);
            var result = listener.LastNewData;
            Assert.AreEqual(choices.Length, result.Length);
            foreach (var item in result) {
                var theString = (string) item.Get("TheString");
                var count = item.Get("cnt").AsInt64();
                //System.out.println("String " + string + " count " + count);
                Assert.AreEqual(count, totals.Get(theString));
            }

            env.UndeployAll();
        }
コード例 #5
0
        private void TrySend(int numThreads, int numEvents, string[] choices)
        {
            if (numEvents < choices.Length)
            {
                throw new ArgumentException("Number of events must at least match number of choices");
            }

            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0));
            _epService.EPAdministrator.CreateEPL("create variable boolean myvar = false");
            _epService.EPAdministrator.CreateEPL("create context SegmentedByString as partition by theString from SupportBean");
            var stmt = _epService.EPAdministrator.CreateEPL("context SegmentedByString select theString, count(*) - 1 as cnt from SupportBean output snapshot when myvar = true");

            stmt.AddListener(_listener);

            // preload - since concurrently sending same-category events an event can be dropped
            for (var i = 0; i < choices.Length; i++)
            {
                _epService.EPRuntime.SendEvent(new SupportBean(choices[i], 0));
            }

            var runnables = new EventRunnable[numThreads];

            for (var i = 0; i < runnables.Length; i++)
            {
                runnables[i] = new EventRunnable(_epService, numEvents, choices);
            }

            // start
            var threads = new Thread[runnables.Length];

            for (var i = 0; i < runnables.Length; i++)
            {
                threads[i] = new Thread(runnables[i].Run);
                threads[i].Start();
            }

            // join
            Log.Info("Waiting for completion");
            for (var i = 0; i < runnables.Length; i++)
            {
                threads[i].Join();
            }

            IDictionary <string, long?> totals = new Dictionary <string, long?>();

            foreach (var choice in choices)
            {
                totals.Put(choice, 0L);
            }

            // verify
            var sum = 0;

            for (var i = 0; i < runnables.Length; i++)
            {
                Assert.IsNull(runnables[i].Exception);
                foreach (var entry in runnables[i].Totals)
                {
                    var current = totals.Get(entry.Key);
                    current += entry.Value;
                    sum     += entry.Value;
                    totals.Put(entry.Key, current);
                    //System.out.println("Thread " + i + " key " + entry.getKey() + " count " + entry.getValue());
                }
            }

            Assert.AreEqual(numThreads * numEvents, sum);

            _epService.EPRuntime.SetVariableValue("myvar", true);
            _epService.EPRuntime.SendEvent(new CurrentTimeEvent(10000));
            var result = _listener.LastNewData;

            Assert.AreEqual(choices.Length, result.Length);
            foreach (var item in result)
            {
                var theString = (string)item.Get("theString");
                var count     = (long?)item.Get("cnt");
                //System.out.println("String " + string + " count " + count);
                Assert.AreEqual(count, totals.Get(theString));
            }
        }