private void TrySendContextCountSimple(int numThreads, int numRepeats) { var listener = new SupportMTUpdateListener(); _engine.EPAdministrator.GetStatement("select").Events += listener.Update; var events = new List <Object>(); for (int i = 0; i < numRepeats; i++) { events.Add(new SupportBean("E" + i, i)); } var threadPool = Executors.NewFixedThreadPool(numThreads); var future = new Future <object> [numThreads]; for (int i = 0; i < numThreads; i++) { var callable = new SendEventCallable(i, _engine, events.GetEnumerator()); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); threadPool.AwaitTermination(TimeSpan.FromSeconds(10)); EventBean[] result = listener.GetNewDataListFlattened(); Assert.AreEqual(numRepeats * numThreads, result.Length); }
private void TryPerformanceDispatch(int numThreads, int numRepeats) { var listener = new MyListener(); _engine.EPAdministrator.GetStatement("select").Events += listener.Update; var random = new Random(); var eventId = 0; var events = new IList <object> [numThreads]; for (int threadNum = 0; threadNum < numThreads; threadNum++) { events[threadNum] = new List <Object>(); for (int eventNum = 0; eventNum < numRepeats; eventNum++) { // range: 1 to 1000 int partition = random.Next(0, 51); eventId++; events[threadNum].Add(new SupportBean(partition.ToString(CultureInfo.InvariantCulture), eventId)); } } var threadPool = Executors.NewFixedThreadPool(numThreads); var futures = new Future <object> [numThreads]; var delta = PerformanceObserver.TimeMillis( () => { for (int i = 0; i < numThreads; i++) { var callable = new SendEventCallable(i, _engine, events[i].GetEnumerator()); futures[i] = threadPool.Submit(callable); } threadPool.Shutdown(); threadPool.AwaitTermination(TimeSpan.FromSeconds(10)); foreach (var future in futures) { Assert.AreEqual(true, future.GetValueOrDefault()); } }); // print those events not received foreach (var eventList in events) { foreach (var theEvent in eventList.Cast <SupportBean>()) { if (!listener.Beans.Contains(theEvent)) { Log.Info("Expected event was not received, event " + theEvent); } } } Assert.That(listener.Beans.Count, Is.EqualTo(numRepeats * numThreads)); Assert.That(delta, Is.LessThan(500), "delta=" + delta); }
private void TrySend(EPServiceProvider epService, SupportMTUpdateListener listener, int numThreads, int numRepeats) { // set time to 0 epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); var threadPool = Executors.NewFixedThreadPool(numThreads); var future = new Future <bool> [numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new SendEventCallable(i, epService, new GeneratorIterator(numRepeats)); future[i] = threadPool.Submit(callable); } // Advance time window every 100 milliseconds for 1 second for (var i = 0; i < 10; i++) { epService.EPRuntime.SendEvent(new CurrentTimeEvent(i * 1000)); Thread.Sleep(100); } threadPool.Shutdown(); threadPool.AwaitTermination(10, TimeUnit.SECONDS); for (var i = 0; i < numThreads; i++) { Assert.IsTrue(future[i].GetValueOrDefault()); } // set time to a large value epService.EPRuntime.SendEvent(new CurrentTimeEvent(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); listener.Reset(); }
private void TrySend(int numThreads, int numRepeats) { // set time to 0 _engine.EPRuntime.SendEvent(new CurrentTimeEvent(0)); var threadPool = Executors.NewFixedThreadPool(numThreads); var future = new Future <object> [numThreads]; for (int i = 0; i < numThreads; i++) { var callable = new SendEventCallable(i, _engine, EventGenerator.MakeEvents(numRepeats)); future[i] = threadPool.Submit(callable); } // Advance time window every 100 milliseconds for 1 second for (int i = 0; i < 10; i++) { _engine.EPRuntime.SendEvent(new CurrentTimeEvent(i * 1000)); Thread.Sleep(100); } threadPool.Shutdown(); threadPool.AwaitTermination(TimeSpan.FromSeconds(10)); for (int i = 0; i < numThreads; i++) { Assert.IsTrue(future[i].GetValueOrDefault().AsBoolean()); } // set time to a large value _engine.EPRuntime.SendEvent(new CurrentTimeEvent(10000000000L)); // Assert results int totalExpected = numThreads * numRepeats; // assert new data EventBean[] resultNewData = _listener.GetNewDataListFlattened(); Assert.AreEqual(totalExpected, resultNewData.Length); IDictionary <int, IList <String> > resultsNewData = SortPerIntKey(resultNewData); AssertResult(numRepeats, numThreads, resultsNewData); // assert old data EventBean[] resultOldData = _listener.GetOldDataListFlattened(); Assert.AreEqual(totalExpected, resultOldData.Length); IDictionary <int, IList <String> > resultsOldData = SortPerIntKey(resultOldData); AssertResult(numRepeats, numThreads, resultsOldData); _listener.Reset(); }
private void TryThreadSafetyHistoricalJoin(int numThreads, int numRepeats) { var listener = new MyListener(); _engine.EPAdministrator.GetStatement("select").Events += listener.Update; 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(partition.ToString(), 0)); } } var threadPool = Executors.NewFixedThreadPool(numThreads); var futures = new Future <object> [numThreads]; for (var i = 0; i < numThreads; i++) { var callable = new SendEventCallable(i, _engine, events[i].GetEnumerator()); futures[i] = threadPool.Submit(callable); } threadPool.Shutdown(); threadPool.AwaitTermination(TimeSpan.FromSeconds(10)); foreach (var future in futures) { Assert.AreEqual(true, future.GetValueOrDefault()); } Assert.AreEqual(numRepeats * numThreads, listener.Count); }
private void TryThreadSafetyHistoricalJoin(EPServiceProvider epService, int numThreads, int numRepeats) { var listener = new MyListener(); epService.EPAdministrator.GetStatement("select").Events += listener.Update; var events = new IList <object> [numThreads]; for (int threadNum = 0; threadNum < numThreads; threadNum++) { events[threadNum] = new List <object>(); for (int eventNum = 0; eventNum < numRepeats; eventNum++) { // range: 1 to 1000 int partition = eventNum + 1; events[threadNum].Add(new SupportBean(Convert.ToString(partition), 0)); } } var threadPool = Executors.NewFixedThreadPool(numThreads); var futures = new Future <bool> [numThreads]; for (int i = 0; i < numThreads; i++) { var callable = new SendEventCallable(i, epService, events[i].GetEnumerator()); futures[i] = threadPool.Submit(callable); } foreach (var future in futures) { Assert.AreEqual(true, future.GetValue(TimeSpan.FromSeconds(60))); } threadPool.Shutdown(); threadPool.AwaitTermination(10, TimeUnit.SECONDS); Assert.AreEqual(numRepeats * numThreads, listener.Count); }