public void Run(Configuration configuration)
        {
            idCounter = new AtomicLong(0);
            executorService = Executors.NewCachedThreadPool();
            noActionUpdateListener = new NoActionUpdateListener();

            configuration.Runtime.Threading.IsInternalTimerEnabled = true;
            configuration.Common.AddEventType(typeof(SupportBean));
            configuration.Runtime.Threading.InsertIntoDispatchLocking = Locking.SUSPEND;

            var runtime = EPRuntimeProvider.GetRuntime(GetType().Name, configuration);
            runtime.Initialize();
            epRuntime = runtime.EventService;

            var path = new RegressionPath();
            var epl = "insert into Stream1 select count(*) as cnt from SupportBean#time(7 sec)";
            var compiled = SupportCompileDeployUtil.Compile(epl, configuration, path);
            path.Add(compiled);
            SupportCompileDeployUtil.Deploy(compiled, runtime);

            epl = epl + " output every 10 seconds";
            compiled = SupportCompileDeployUtil.Compile(epl, configuration, path);
            SupportCompileDeployUtil.DeployAddListener(compiled, "insert", noActionUpdateListener, runtime);

            var sendTickEventRunnable = new SendEventRunnable(this, 10000);
            Start(sendTickEventRunnable, 4);

            // Adjust here for long-running test
            SupportCompileDeployUtil.ThreadSleep(3000);
            sendTickEventRunnable.Shutdown = true;

            executorService.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(executorService, 1, TimeUnit.SECONDS);
            runtime.Destroy();
        }
Example #2
0
        private static void TrySend(
            RegressionEnvironment env,
            int numThreads,
            int numRepeats)
        {
            var compiled = env.Compile("@Name('upd') update istream SupportBean set TheString='a'");

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

            for (var i = 0; i < 50; i++) {
                env.Deploy(compiled);
                SupportCompileDeployUtil.ThreadSleep(10);
                env.UndeployModuleContaining("upd");
            }

            threadPool.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(threadPool, 5, TimeUnit.SECONDS);
            SupportCompileDeployUtil.AssertFutures(future);
        }
        public void Run(RegressionEnvironment env)
        {
            var statementTwo = "select * from pattern[( every event1=SupportTradeEvent(UserId in ('100','101')) ->\n" +
                               "         (SupportTradeEvent(UserId in ('100','101'), Direction = event1.Direction ) ->\n" +
                               "          SupportTradeEvent(UserId in ('100','101'), Direction = event1.Direction )\n" +
                               "         ) where timer:within(8 hours)\n" +
                               "         and not eventNC=SupportTradeEvent(UserId in ('100','101'), Direction!= event1.Direction )\n" +
                               "        ) -> eventFinal=SupportTradeEvent(UserId in ('100','101'), Direction != event1.Direction ) where timer:within(1 hour)]";
            var compiledTwo = env.Compile(statementTwo);

            var runnable = new TwoPatternRunnable(env);
            var t = new Thread(runnable.Run);
            t.Name = typeof(MultithreadStmtTwoPatterns).Name;
            t.Start();
            SupportCompileDeployUtil.ThreadSleep(100);

            // Create a second pattern, wait 500 msec, destroy second pattern in a loop
            var numRepeats = env.IsHA ? 1 : 10;
            for (var i = 0; i < numRepeats; i++) {
                try {
                    var deployed = env.Deployment.Deploy(compiledTwo);
                    SupportCompileDeployUtil.ThreadSleep(200);
                    env.Undeploy(deployed.DeploymentId);
                }
                catch (Exception ex) {
                    throw new EPException(ex);
                }
            }

            runnable.Shutdown = true;
            SupportCompileDeployUtil.ThreadSleep(1000);
            Assert.IsFalse(t.IsAlive);

            env.UndeployAll();
        }
Example #4
0
        public void Run(RegressionEnvironment env)
        {
            var path = new RegressionPath();
            var eplStatement = "create context MyContext start PayloadEvent end after 0.5 seconds";
            env.CompileDeploy(eplStatement, path);

            var aggStatement = "@Name('select') context MyContext " +
                               "select count(*) as theCount " +
                               "from PayloadEvent " +
                               "output snapshot when terminated";
            env.CompileDeploy(aggStatement, path);
            var listener = new MyListener();
            env.Statement("select").AddListener(listener);

            // start thread
            long numEvents = 10000000;
            var myRunnable = new MyRunnable(env.Runtime, numEvents);
            var thread = new Thread(myRunnable.Run);
            thread.Name = typeof(MultithreadContextStartedBySameEvent).Name;
            thread.Start();
            SupportCompileDeployUtil.ThreadJoin(thread);

            SupportCompileDeployUtil.ThreadSleep(1000);

            // assert
            Assert.IsNull(myRunnable.exception);
            Assert.AreEqual(numEvents, listener.total);

            env.UndeployAll();
        }
        private static void TrySend(
            RegressionEnvironment env,
            int numThreads,
            int numRepeats)
        {
            // set time to 0
            env.AdvanceTime(0);

            var listener = new SupportMTUpdateListener();
            env.CompileDeploy(
                "@Name('s0') select irstream IntPrimitive, TheString as key from SupportBean#time(1 sec)");
            env.Statement("s0").AddListener(listener);

            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadStmtTimeWindow)).ThreadFactory);
            var futures = new List<IFuture<bool>>();
            for (var i = 0; i < numThreads; i++) {
                var callable = new SendEventCallable(i, env.Runtime, new GeneratorEnumerator(numRepeats));
                futures.Add(threadPool.Submit(callable));
            }

            // Advance time window every 100 milliseconds for 1 second
            for (var i = 0; i < 10; i++) {
                env.AdvanceTime(i * 1000);
                SupportCompileDeployUtil.ThreadSleep(100);
            }

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

            // set time to a large value
            env.AdvanceTime(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);

            env.UndeployAll();
        }
 public void Run()
 {
     long time = 1000;
     long numAdvances = 0;
     try {
         while (latch.Get() && (maxNumAdvances == -1 || numAdvances < maxNumAdvances)) {
             env.AdvanceTime(time);
             numAdvances++;
             time += 1000;
             SupportCompileDeployUtil.ThreadSleep((int) threadSleepTime);
         }
     }
     catch (Exception ex) {
         log.Error("Error while processing", ex);
     }
 }
Example #7
0
        private void RunAssertion(
            FilterServiceProfile profile,
            Configuration configuration)
        {
            configuration.Runtime.Execution.FilterServiceProfile = profile;
            configuration.Common.AddEventType(typeof(MyEvent));

            var runtimeURI = GetType().Name + "_" + profile;
            var runtime = EPRuntimeProvider.GetRuntime(runtimeURI, configuration);

            var path = new RegressionPath();
            var eplContext = "create context MyContext start @now end after 100 milliseconds;\n";
            var compiledContext = SupportCompileDeployUtil.Compile(eplContext, configuration, path);
            SupportCompileDeployUtil.Deploy(compiledContext, runtime);
            path.Add(compiledContext);

            var epl = "context MyContext select FieldOne, count(*) as cnt from MyEvent " +
                      "group by FieldOne output last when terminated;\n";
            var compiledStmt = SupportCompileDeployUtil.Compile(epl, configuration, path);
            var listeners = new SupportUpdateListener[100];

            for (var i = 0; i < 100; i++) {
                listeners[i] = new SupportUpdateListener();
                var stmtName = "s" + i;
                SupportCompileDeployUtil.DeployAddListener(compiledStmt, stmtName, listeners[i], runtime);
            }

            var eventCount = 100000; // keep this divisible by 1000
            for (var i = 0; i < eventCount; i++) {
                var group = Convert.ToString(eventCount % 1000);
                runtime.EventService.SendEventBean(new MyEvent(Convert.ToString(i), group), "MyEvent");
            }

            SupportCompileDeployUtil.ThreadSleep(2000);

            AssertReceived(eventCount, listeners);

            try {
                runtime.DeploymentService.UndeployAll();
            }
            catch (EPUndeployException e) {
                throw new EPException(e);
            }

            runtime.Destroy();
        }
Example #8
0
        private static void TrySendContextCountSimple(
            RegressionEnvironment env,
            int numThreads,
            int numRepeats)
        {
            var listener = new SupportMTUpdateListener();
            env.Statement("select").AddListener(listener);

            IList<object>[] eventsPerThread = new List<object>[numThreads];
            for (var t = 0; t < numThreads; t++) {
                eventsPerThread[t] = new List<object>();
                for (var i = 0; i < numRepeats; i++) {
                    eventsPerThread[t].Add(new SupportBean_S0(-1, "E" + i, i + "_" + t));
                }
            }

            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadContextCountSimple)).ThreadFactory);
            var future = new IFuture<bool>[numThreads];
            for (var i = 0; i < numThreads; i++) {
                var callable = new SendEventCallable(i, env.Runtime, eventsPerThread[i].GetEnumerator());
                future[i] = threadPool.Submit(callable);
            }

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

            var result = listener.GetNewDataListFlattened();
            ISet<string> received = new HashSet<string>();
            foreach (var @event in result) {
                var key = (string) @event.Get("P01");
                if (received.Contains(key)) {
                    Assert.Fail("key " + key + " received multiple times");
                }

                received.Add(key);
            }

            if (received.Count != numRepeats * numThreads) {
                log.Info("Received are " + received.Count + " entries");
                Assert.Fail();
            }
        }
        private static void TryChainedCountSum(
            RegressionEnvironment env,
            int numThreads,
            int numEvents)
        {
            // setup statements
            var path = new RegressionPath();
            env.CompileDeploy("insert into MyStreamOne select count(*) as cnt from SupportBean", path);
            env.CompileDeploy("@Name('s0') insert into MyStreamTwo select sum(cnt) as mysum from MyStreamOne", path);
            var listener = new SupportUpdateListener();
            env.Statement("s0").AddListener(listener);

            // execute
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadDeterminismInsertInto)).ThreadFactory);
            var future = new IFuture<object>[numThreads];
            IReaderWriterLock sharedStartLock = new SlimReaderWriterLock();
            using (sharedStartLock.WriteLock.Acquire()) {
                for (var i = 0; i < numThreads; i++) {
                    future[i] = threadPool.Submit(
                        new SendEventRWLockCallable(
                            i,
                            sharedStartLock,
                            env.Runtime,
                            new GeneratorEnumerator(numEvents)));
                }

                SupportCompileDeployUtil.ThreadSleep(100);
            }

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

            // assert result
            var newEvents = listener.NewDataListFlattened;
            for (var i = 0; i < numEvents - 1; i++) {
                var expected = Total(i + 1);
                Assert.AreEqual(expected, newEvents[i].Get("mysum"));
            }

            env.UndeployAll();
        }
Example #10
0
        private static void TryIterate(
            RegressionEnvironment env,
            RegressionPath path,
            int numThreads,
            int numRepeats)
        {
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadStmtNamedWindowFAF)).ThreadFactory);
            var future = new IFuture<object>[numThreads];
            for (var i = 0; i < numThreads; i++) {
                var callable = new StmtNamedWindowQueryCallable(env, path, numRepeats, Convert.ToString(i));
                future[i] = threadPool.Submit(callable);
            }

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

            SupportCompileDeployUtil.ThreadSleep(100);
            SupportCompileDeployUtil.AssertFutures(future);
        }
            public object Call()
            {
                var count = 0;
                while (true) {
                    insertIntoTimer.SendEvent();
                    SupportCompileDeployUtil.ThreadSleep(1);
                    count++;

                    if (count % 1000 == 0) {
                        log.Info("Thread " + Thread.CurrentThread.ManagedThreadId + " send " + count + " events");
                    }

                    if (count > maxSent) {
                        break;
                    }

                    if (shutdown) {
                        break;
                    }
                }

                return null;
            }
        public void Run(RegressionEnvironment env)
        {
            var epl = "create window A#unique(Key) as MyEventA;\n" +
                      "create window B#unique(Key) as MyEventB;\n" +
                      "insert into A select * from MyEventA;\n" +
                      "insert into B select * from MyEventB;\n" +
                      "\n" +
                      "@Name('stmt') select sum(A.Data) as aTotal,sum(B.Data) as bTotal " +
                      "from A unidirectional, B where A.Key = B.Key;\n";
            env.CompileDeploy(epl);

            var es = Executors.NewFixedThreadPool(
                10,
                new SupportThreadFactory(typeof(MultithreadStmtNamedWindowJoinUniqueView)).ThreadFactory);
            IList<MyRunnable> runnables = new List<MyRunnable>();
            for (var i = 0; i < 6; i++) {
                runnables.Add(new MyRunnable(env.EventService));
            }

            foreach (var toRun in runnables) {
                es.Submit(toRun.Run);
            }

            SupportCompileDeployUtil.ThreadSleep(2000);
            foreach (var toRun in runnables) {
                toRun.Shutdown = true;
            }

            es.Shutdown();
            SupportCompileDeployUtil.ExecutorAwait(es, 20, TimeUnit.SECONDS);

            foreach (var runnable in runnables) {
                Assert.IsNull(runnable.Exception);
            }

            env.UndeployAll();
        }
        private static void TryMultiInsertGroup(
            RegressionEnvironment env,
            int numThreads,
            int numStatements,
            int numEvents)
        {
            // This should fail all test in this class
            // config.getEngineDefaults().getThreading().setInsertIntoDispatchPreserveOrder(false);

            // setup statements
            var path = new RegressionPath();
            var insertIntoStmts = new EPStatement[numStatements];
            for (var i = 0; i < numStatements; i++) {
                var epl = $"@Name('s{i}') insert into MyStream select {i} as ident,count(*) as cnt from SupportBean";
                insertIntoStmts[i] = env.CompileDeploy(epl, path).Statement("s" + i);
            }

            env.CompileDeploy("@Name('final') select ident, sum(cnt) as mysum from MyStream group by ident", path);
            var listener = new SupportMTUpdateListener();
            env.Statement("final").AddListener(listener);

            // execute
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadDeterminismInsertInto)).ThreadFactory);
            var future = new IFuture<object>[numThreads];
            var sharedStartLock = new SlimReaderWriterLock();
            using (sharedStartLock.WriteLock.Acquire()) {
                for (var i = 0; i < numThreads; i++) {
                    future[i] = threadPool.Submit(
                        new SendEventRWLockCallable(
                            i,
                            sharedStartLock,
                            env.Runtime,
                            new GeneratorEnumerator(numEvents)));
                }

                SupportCompileDeployUtil.ThreadSleep(100);
            }

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

            // assert result
            var newEvents = listener.GetNewDataListFlattened();
            IList<long>[] resultsPerIdent = new List<long>[numStatements];
            foreach (var theEvent in newEvents) {
                var ident = theEvent.Get("ident").AsInt32();
                if (resultsPerIdent[ident] == null) {
                    resultsPerIdent[ident] = new List<long>();
                }

                var mysum = theEvent.Get("mysum").AsInt64();
                resultsPerIdent[ident].Add(mysum);
            }

            for (var statement = 0; statement < numStatements; statement++) {
                for (var i = 0; i < numEvents - 1; i++) {
                    var expected = Total(i + 1);
                    Assert.AreEqual(
                        expected,
                        resultsPerIdent[statement][i],
                        "Failed for statement " + statement);
                }
            }

            env.UndeployAll();
        }