private static void TryThreadSafetyHistoricalJoin( RegressionEnvironment env, int numThreads, int numRepeats) { var listener = new MyListener(); env.Statement("select").AddListener(listener); var events = new IList<object>[numThreads]; for (var threadNum = 0; threadNum < numThreads; threadNum++) { events[threadNum] = new List<object>(); for (var eventNum = 0; eventNum < numRepeats; eventNum++) { // range: 1 to 1000 var partition = eventNum + 1; events[threadNum].Add(new SupportBean(new int?(partition).ToString(), 0)); } } var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadContextDBAccess)).ThreadFactory); var futures = new IFuture<bool>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new SendEventCallable(i, env.Runtime, events[i].GetEnumerator()); futures[i] = threadPool.Submit(callable); } SupportCompileDeployUtil.AssertFutures(futures); threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); Assert.AreEqual(numRepeats * numThreads, listener.Count); }
private static void TryStatementCreateSendAndStop( RegressionEnvironment env, int numThreads, StmtMgmtCallablePair[] statements, int numRepeats) { var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtMgmt)).ThreadFactory); var future = new IFuture<object>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new StmtMgmtCallable(env.Runtime, statements, numRepeats); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); var statementDigest = new StringBuilder(); for (var i = 0; i < statements.Length; i++) { statementDigest.Append(statements[i].Epl); } 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(); }
private static void TrySend( RegressionEnvironment env, EPStatement stmtWindow, int numThreads, int numRepeats) { var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtNamedWindowPriority)).ThreadFactory); var future = new IFuture<object>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new StmtNamedWindowPriorityCallable(i, env.Runtime, numRepeats); future[i] = threadPool.Submit(callable); } SupportCompileDeployUtil.AssertFutures(future); threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); var events = EPAssertionUtil.EnumeratorToArray(stmtWindow.GetEnumerator()); Assert.AreEqual(numThreads * numRepeats, events.Length); for (var i = 0; i < events.Length; i++) { var valueC1 = (string) events[i].Get("c1"); Assert.AreEqual("y", valueC1); } }
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(); }
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); }
private static void TryCount( RegressionEnvironment env, int numThreads, int numMessages, string epl, GeneratorEnumeratorCallback generatorEnumeratorCallback) { var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtStatelessEnummethod)).ThreadFactory); env.CompileDeploy(epl); var listener = new SupportMTUpdateListener(); env.Statement("s0").AddListener(listener); var future = new IFuture <bool> [numThreads]; for (var i = 0; i < numThreads; i++) { future[i] = threadPool.Submit( new SendEventCallable( i, env.Runtime, new GeneratorEnumerator(numMessages, generatorEnumeratorCallback))); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); Assert.AreEqual(numMessages * numThreads, listener.GetNewDataListFlattened().Length); }
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(); }
public void TryCount( RegressionEnvironment env, int numUsers, int numOrders, int numThreads) { var path = new RegressionPath(); for (var i = 0; i < numUsers; i++) { env.CompileDeploy( "@Name('create_" + i + "') create window MyWindow_" + i + "#unique(OrderId) as select * from OrderEvent", path); env.CompileDeploy( "@Name('insert_" + i + "') insert into MyWindow_" + i + " select * from OrderEvent(UserId = 'user" + i + "')", path); env.CompileDeploy( "on OrderCancelEvent as d delete from MyWindow_" + i + " w where w.OrderId = d.OrderId", path); env.CompileDeploy( "@Name('select_" + i + "') on OrderEvent as s select sum(w.Price) from MyWindow_" + i + " w where w.Side = s.Side group by w.Side", path); } var runnables = new RunnableOrderSim[numThreads]; var threads = new Thread[numThreads]; for (var i = 0; i < numThreads; i++) { runnables[i] = new RunnableOrderSim(env.Runtime, i, numUsers, numOrders); threads[i] = new Thread(runnables[i].Run) { Name = typeof(MultithreadStmtNamedWindowMultiple).Name }; } for (var i = 0; i < threads.Length; i++) { threads[i].Start(); } for (var i = 0; i < threads.Length; i++) { SupportCompileDeployUtil.ThreadJoin(threads[i]); Assert.IsTrue(runnables[i].Status); } env.UndeployAll(); }
private static void TrySend( RegressionEnvironment env, int numThreads, int numEventsPerThread, bool indexShare) { // setup statements var path = new RegressionPath(); var schemas = "create schema UpdateEvent as (uekey string, ueint int);\n" + "create schema WindowSchema as (wskey string, wsint int);\n"; env.CompileDeployWBusPublicType(schemas, path); var createEpl = "@Name('namedWindow') create window MyWindow#keepall as WindowSchema"; if (indexShare) { createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl; } env.CompileDeploy(createEpl, path); env.CompileDeploy("create index ABC on MyWindow(wskey)", path); env.CompileDeploy( "on UpdateEvent mue merge MyWindow mw " + "where uekey = wskey and ueint = wsint " + "when not matched then insert select uekey as wskey, ueint as wsint " + "when matched then delete", path); // note: here all threads use the same string key to insert/delete and different values for the int env.CompileDeploy( "@Name('target') select (select intListAgg(wsint) from MyWindow mw where wskey = sb.TheString) as val from SupportBean sb", path); // execute var executor = Executors.NewMultiThreadedExecutor(numThreads); // new SupportThreadFactory(typeof(MultithreadStmtNamedWindowSubqueryAgg)).ThreadFactory) var futures = new List<IFuture<bool?>>(); for (var i = 0; i < numThreads; i++) { futures.Add(executor.Submit( new StmtNamedWindowSubqueryAggCallable( i, env.Runtime, numEventsPerThread, env.Statement("target")))); } // Give the futures 10 seconds to complete the futures... futures.AsParallel().ForAll(future => future.Wait(TimeSpan.FromSeconds(10))); executor.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(executor, TimeSpan.FromSeconds(10)); SupportCompileDeployUtil.AssertFutures(futures); var events = EPAssertionUtil.EnumeratorToArray(env.Statement("namedWindow").GetEnumerator()); Assert.AreEqual(0, events.Length); 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(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(); }
private static void TryPattern( RegressionEnvironment env, string pattern, int numThreads, int numEvents) { var sendLock = new object(); var executor = Executors.NewMultiThreadedExecutor(numThreads); // new SupportThreadFactory(typeof(MultithreadStmtPattern)).ThreadFactory); var futures = new List<IFuture<object>>(); var callables = new SendEventWaitCallable[numThreads]; for (var i = 0; i < numThreads; i++) { callables[i] = new SendEventWaitCallable(i, env.Runtime, sendLock, new GeneratorEnumerator(numEvents)); futures.Add(executor.Submit(callables[i])); } var listener = new SupportMTUpdateListener[numEvents]; var epl = "select * from pattern[" + pattern + "]"; var compiled = env.Compile(epl); for (var i = 0; i < numEvents; i++) { var stmtName = "p" + i; env.Deploy(compiled, new DeploymentOptions().WithStatementNameRuntime(ctx => stmtName)); var stmt = env.Statement(stmtName); listener[i] = new SupportMTUpdateListener(); stmt.AddListener(listener[i]); lock (sendLock) { Monitor.PulseAll(sendLock); } } foreach (var callable in callables) { callable.Shutdown(); } lock (sendLock) { Monitor.PulseAll(sendLock); } executor.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(executor, TimeSpan.FromSeconds(10)); for (var i = 0; i < numEvents; i++) { var theEventReceived = listener[i].AssertOneGetNewAndReset(); Assert.NotNull(theEventReceived); var theEventValue = theEventReceived.Get("a"); Assert.NotNull(theEventValue); Assert.IsInstanceOf<SupportBean>(theEventValue); } env.UndeployAll(); }
private static void TryPerformanceDispatch( RegressionEnvironment env, int numThreads, int numRepeats) { var listener = new MyListener(); env.Statement("select").AddListener(listener); var random = new Random(); var events = new IList<object>[numThreads]; var eventId = 0; for (var threadNum = 0; threadNum < numThreads; threadNum++) { events[threadNum] = new List<object>(); for (var eventNum = 0; eventNum < numRepeats; eventNum++) { // range: 1 to 1000 var partition = random.Next(0, 50); eventId++; events[threadNum].Add(new SupportBean(new int?(partition).ToString(), eventId)); } } var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadContextPartitioned)).ThreadFactory); var futures = new IFuture<bool>[numThreads]; var startTime = PerformanceObserver.MilliTime; for (var i = 0; i < numThreads; i++) { var callable = new SendEventCallable(i, env.Runtime, events[i].GetEnumerator()); futures[i] = threadPool.Submit(callable); } SupportCompileDeployUtil.AssertFutures(futures); var delta = PerformanceObserver.MilliTime - startTime; threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); // print those events not received foreach (var eventList in events) { foreach (var @event in eventList) { if (!listener.Beans.Contains(@event)) { log.Info("Expected event was not received, event " + @event); } } } Assert.AreEqual(numRepeats * numThreads, listener.Beans.Count); Assert.That(delta, Is.LessThan(500)); }
private static void TrySend( int numThreads, int numEvents, bool isPreserveOrder, Locking locking, Configuration configuration) { configuration.Runtime.Threading.IsListenerDispatchPreserveOrder = isPreserveOrder; configuration.Runtime.Threading.ListenerDispatchLocking = locking; configuration.Common.AddEventType(typeof(SupportBean)); var runtime = EPRuntimeProvider.GetRuntime(typeof(MultithreadDeterminismListener).Name, configuration); runtime.Initialize(); // setup statements var deployed = SupportCompileDeployUtil.CompileDeploy( "@Name('s0') select count(*) as cnt from SupportBean", runtime, configuration); var listener = new SupportMTUpdateListener(); deployed.Statements[0].AddListener(listener); // execute var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadDeterminismListener)).ThreadFactory); var future = new IFuture<bool>[numThreads]; for (var i = 0; i < numThreads; i++) { future[i] = threadPool.Submit(new SendEventCallable(i, runtime, new GeneratorEnumerator(numEvents))); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); var events = listener.GetNewDataListFlattened(); var result = new long[events.Length]; for (var i = 0; i < events.Length; i++) { result[i] = events[i].Get("cnt").AsInt64(); } //log.info(".trySend result=" + Arrays.toString(result)); // assert result Assert.AreEqual(numEvents * numThreads, events.Length); for (var i = 0; i < numEvents * numThreads; i++) { Assert.AreEqual(result[i], (long) i + 1); } runtime.Destroy(); }
private static void TrySend( RegressionEnvironment env, SupportMTUpdateListener listener, int numThreads, int numRepeats) { var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtInsertInto)).ThreadFactory); var future = new IFuture<object>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new StmtInsertIntoCallable(Convert.ToString(i), env.Runtime, numRepeats); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); // Assert results var totalExpected = numThreads * numRepeats * 2; var result = listener.GetNewDataListFlattened(); Assert.AreEqual(totalExpected, result.Length); IDictionary<long, ICollection<string>> results = new Dictionary<long, ICollection<string>>(); foreach (var theEvent in result) { var count = theEvent.Get("mycount").AsInt64(); var key = (string) theEvent.Get("key"); var entries = results.Get(count); if (entries == null) { entries = new HashSet<string>(); results.Put(count, entries); } entries.Add(key); } Assert.AreEqual(numRepeats, results.Count); foreach (var value in results.Values) { Assert.AreEqual(2 * numThreads, value.Count); for (var i = 0; i < numThreads; i++) { Assert.IsTrue(value.Contains("E1_" + i)); Assert.IsTrue(value.Contains("E2_" + i)); } } listener.Reset(); }
private static void TryListener( RegressionEnvironment env, int numThreads, int numRoutes) { env.CompileDeploy("@Name('trigger') select * from SupportBean"); env.CompileDeploy("@Name('s0') select * from SupportMarketDataBean"); var listener = new SupportMTUpdateListener(); env.Statement("s0").AddListener(listener); // Set of events routed by each listener ISet<SupportMarketDataBean> routed = new HashSet<SupportMarketDataBean>().AsSyncSet(); var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtListenerRoute)).ThreadFactory); var future = new IFuture<object>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new StmtListenerCreateStmtCallable( i, env.Runtime, env.Statement("trigger"), numRoutes, routed); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); // assert var results = listener.GetNewDataListFlattened(); Assert.IsTrue(results.Length >= numThreads * numRoutes); foreach (var routedEvent in routed) { var found = false; for (var i = 0; i < results.Length; i++) { if (results[i].Underlying == routedEvent) { found = true; } } Assert.IsTrue(found); } env.UndeployAll(); }
private static void TrySend( RegressionEnvironment env, SupportMTUpdateListener listenerWindow, SupportMTUpdateListener listenerConsumer, int numThreads, int numRepeats) { var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtNamedWindowDelete)).ThreadFactory); var future = new IFuture<object>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new StmtNamedWindowDeleteCallable(Convert.ToString(i), env.Runtime, numRepeats); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); // compute list of expected IList<string> expectedIdsList = new List<string>(); for (var i = 0; i < numThreads; i++) { try { expectedIdsList.AddAll((IList<string>) future[i].Get()); } catch (Exception t) { throw new EPException(t); } } var expectedIds = expectedIdsList.ToArray(); Assert.AreEqual(2 * numThreads * numRepeats, listenerWindow.NewDataList.Count); // old and new each Assert.AreEqual(2 * numThreads * numRepeats, listenerConsumer.NewDataList.Count); // old and new each // compute list of received var newEvents = listenerWindow.GetNewDataListFlattened(); var receivedIds = new string[newEvents.Length]; for (var i = 0; i < newEvents.Length; i++) { receivedIds[i] = (string) newEvents[i].Get("TheString"); } Assert.AreEqual(receivedIds.Length, expectedIds.Length); Array.Sort(receivedIds); Array.Sort(expectedIds); CompatExtensions.DeepEqualsWithType(expectedIds, receivedIds); }
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); } }
private void tryCount( RegressionEnvironment env, int numThreads, int numMessages, string epl, GeneratorEnumeratorCallback generatorEnumeratorCallback) { var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtFilter)).ThreadFactory); env.CompileDeploy(epl); var listener = new MTListener("mycount"); env.Statement("s0").AddListener(listener); var future = new IFuture <bool> [numThreads]; for (var i = 0; i < numThreads; i++) { future[i] = threadPool.Submit( new SendEventCallable( i, env.Runtime, new GeneratorEnumerator(numMessages, generatorEnumeratorCallback))); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); // verify results Assert.AreEqual(numMessages * numThreads, listener.Values.Count); var result = new SortedSet <int>(); foreach (var row in listener.Values) { result.Add(row.AsInt32()); } Assert.AreEqual(numMessages * numThreads, result.Count); Assert.AreEqual(1, result.First()); Assert.AreEqual(numMessages * numThreads, result.Last()); env.UndeployAll(); }
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(); }
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 TrySend( RegressionEnvironment env, int numThreads, int numEventsPerThread) { var path = new RegressionPath(); var schemas = "create schema MyUpdateEvent as (key string, intupd int);\n" + "create schema MySchema as (TheString string, intval int);\n"; env.CompileDeployWBusPublicType(schemas, path); env.CompileDeploy("@Name('window') create window MyWindow#keepall as MySchema", path); env.CompileDeploy( "on MyUpdateEvent mue merge MyWindow mw " + "where mw.TheString = mue.key " + "when not matched then insert select key as TheString, intupd as intval " + "when matched then delete", path); env.CompileDeploy( "@Name('target') select (select intval from MyWindow mw where mw.TheString = sb.TheString) as val from SupportBean sb", path); // execute var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtNamedWindowSubqueryLookup)).ThreadFactory); var future = new IFuture<bool?>[numThreads]; for (var i = 0; i < numThreads; i++) { future[i] = threadPool.Submit( new StmtNamedWindowSubqueryLookupCallable( i, env.Runtime, numEventsPerThread, env.Statement("target"))); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); var events = EPAssertionUtil.EnumeratorToArray(env.GetEnumerator("window")); Assert.AreEqual(0, events.Length); env.UndeployAll(); }
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(); }
private static void RunAssertionOptionModuleName( RegressionEnvironment env, string epl) { EPCompiled compiledBoth; try { var args = new CompilerArguments(env.Configuration); args.Options.ModuleName = ctx => "abc"; compiledBoth = env.Compiler.Compile(epl, args); } catch (EPCompileException ex) { throw new EPRuntimeException(ex); } var deployed = SupportCompileDeployUtil.Deploy(compiledBoth, env.Runtime); Assert.AreEqual("abc", deployed.ModuleName); // Option-provided module-name wins env.UndeployAll(); }
private static void TrySendAndReceive( RegressionEnvironment env, int numThreads, EPStatement statement, int numRepeats) { var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtJoin)).ThreadFactory); var future = new IFuture<object>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new StmtJoinCallable(i, env.Runtime, statement, numRepeats); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); }
private static void TryIterate( RegressionEnvironment env, RegressionPath path, int numThreads, int numRepeats) { var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtNamedWindowIterate)).ThreadFactory); var future = new IFuture<object>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new StmtNamedWindowIterateCallable(Convert.ToString(i), env, path, numRepeats); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); }
public void Run(RegressionEnvironment env) { env.AdvanceTime(0); var path = new RegressionPath(); env.CompileDeploy( "create context MyCtx partition by TheString from SupportBean terminated after 1 second", path); env.CompileDeploy( "@Name('s0') context MyCtx select count(*) as cnt from SupportBean output last when terminated", path); var listener = new SupportUpdateListener(); env.Statement("s0").AddListener(listener); var latch = new AtomicBoolean(true); // With 0-sleep or 1-sleep the counts start to drop because the event is chasing the context partition. var t = new Thread( new MyTimeAdvancingRunnable(env, latch, 10, -1).Run); t.Name = typeof(MultithreadContextPartitionedWTerm).Name; t.Start(); var numEvents = 10000; for (var i = 0; i < numEvents; i++) { env.SendEventBean(new SupportBean()); } latch.Set(false); SupportCompileDeployUtil.ThreadJoin(t); env.AdvanceTime(int.MaxValue); long total = 0; var deliveries = listener.NewDataListFlattened; foreach (var @event in deliveries) { var count = @event.Get("cnt").AsInt64(); total += count; } Assert.AreEqual(numEvents, total); env.UndeployAll(); }
private static void TrySend( RegressionEnvironment env, int numThreads, int numRepeats) { env.CompileDeploy( "@Name('s0') select (select Id from SupportBean_S0#length(1000000) where Id = S1.Id) as value from SupportBean_S1 as S1"); var listener = new SupportMTUpdateListener(); env.Statement("s0").AddListener(listener); var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtSubquery)).ThreadFactory); var future = new IFuture<object>[numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new StmtSubqueryCallable(i, env.Runtime, numRepeats); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); // Assert results var totalExpected = numThreads * numRepeats; // assert new data var resultNewData = listener.GetNewDataListFlattened(); Assert.AreEqual(totalExpected, resultNewData.Length); ISet<int> values = new HashSet<int>(); foreach (var theEvent in resultNewData) { values.Add(theEvent.Get("value").AsInt32()); } Assert.AreEqual(totalExpected, values.Count, "Unexpected duplicates"); listener.Reset(); env.UndeployAll(); }
private static void TrySend( RegressionEnvironment env, int numThreads, int numEventsPerThread) { // setup statements var path = new RegressionPath(); env.CompileDeploy("create window MyWindow#keepall as select * from SupportBean", path); env.CompileDeploy( "on SupportBean sb " + "merge MyWindow nw where nw.TheString = sb.TheString " + " when not matched then insert select * " + " when matched then update set IntPrimitive = nw.IntPrimitive + 1", path); // execute var threadPool = Executors.NewFixedThreadPool( numThreads, new SupportThreadFactory(typeof(MultithreadStmtNamedWindowMerge)).ThreadFactory); var future = new IFuture<bool?>[numThreads]; for (var i = 0; i < numThreads; i++) { future[i] = threadPool.Submit(new StmtNamedWindowMergeCallable(env.Runtime, numEventsPerThread)); } threadPool.Shutdown(); SupportCompileDeployUtil.ExecutorAwait(threadPool, 10, TimeUnit.SECONDS); SupportCompileDeployUtil.AssertFutures(future); // compare var rows = env.CompileExecuteFAF("select * from MyWindow", path).Array; Assert.AreEqual(numEventsPerThread, rows.Length); foreach (var row in rows) { Assert.AreEqual(numThreads - 1, row.Get("IntPrimitive")); } //long deltaTime = endTime - startTime; //System.out.println("Totals updated: " + totalUpdates + " Delta cumu: " + deltaCumulative + " Delta pooled: " + deltaTime); env.UndeployAll(); }