Example #1
0
        public void TestMetricsJMX()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.MetricsReporting.IsEnableMetricsReporting = true;
            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();

            epService.EPRuntime.SendEvent(new CurrentTimeEvent(DateTimeParser.ParseDefaultMSec("2002-05-01T08:00:00.000")));
            epService.EPAdministrator.Configuration.AddEventType <SupportBean>();

            epService.EPAdministrator.CreateEPL("select * from pattern [every a=SupportBean(TheString like 'A%') -> b=SupportBean(TheString like 'B') where timer:within(a.IntPrimitive)]");
            epService.EPRuntime.SendEvent(new SupportBean("A1", 10));
            epService.EPRuntime.SendEvent(new SupportBean("A2", 60));

            AssertEngineJMX();

            epService.Dispose();

            //AssertNoEngineJMX();

            config = SupportConfigFactory.GetConfiguration();
            config.EngineDefaults.MetricsReporting.IsEnableMetricsReporting = false;
            epService = EPServiceProviderManager.GetDefaultProvider(config);
            epService.Initialize();

            //AssertNoEngineJMX();

            epService.Dispose();
        }
        public void TestDefaultEngine()
        {
            Assert.AreEqual("default", EPServiceProviderManager.GetDefaultProvider().URI);
            var engineDefault = EPServiceProviderManager.GetDefaultProvider();

            Assert.IsTrue(engineDefault.EPRuntime.IsExternalClockingEnabled);

            var engine = EPServiceProviderManager.GetProvider("default");

            Assert.AreSame(engineDefault, engine);

            engine = EPServiceProviderManager.GetProvider(null);
            Assert.AreSame(engineDefault, engine);

            engine = EPServiceProviderManager.GetProvider(null, SupportConfigFactory.GetConfiguration());
            Assert.AreSame(engineDefault, engine);

            var uris = EPServiceProviderManager.ProviderURIs;

            Assert.IsTrue(uris.Contains("default"));

            _epService.Dispose();
            try {
                var temp = _epService.EPRuntime;
                Assert.Fail();
            }
            catch (EPServiceDestroyedException) {
                // expected
            }
            try {
                var temp = _epService.EPAdministrator;
                Assert.Fail();
            }
            catch (EPServiceDestroyedException) {
                // expected
            }
            EPAssertionUtil.AssertNotContains(EPServiceProviderManager.ProviderURIs, "default");

            // test destroy
            var config    = SupportConfigFactory.GetConfiguration();
            var uriOne    = GetType().FullName + "_1";
            var engineOne = EPServiceProviderManager.GetProvider(uriOne, config);
            var uriTwo    = GetType().FullName + "_2";
            var engineTwo = EPServiceProviderManager.GetProvider(uriTwo, config);

            EPAssertionUtil.AssertContains(EPServiceProviderManager.ProviderURIs, uriOne, uriTwo);
            Assert.IsNotNull(EPServiceProviderManager.GetExistingProvider(uriOne));
            Assert.IsNotNull(EPServiceProviderManager.GetExistingProvider(uriTwo));

            engineOne.Dispose();
            EPAssertionUtil.AssertNotContains(EPServiceProviderManager.ProviderURIs, uriOne);
            EPAssertionUtil.AssertContains(EPServiceProviderManager.ProviderURIs, uriTwo);
            Assert.IsNull(EPServiceProviderManager.GetExistingProvider(uriOne));

            engineTwo.Dispose();
            EPAssertionUtil.AssertNotContains(EPServiceProviderManager.ProviderURIs, uriOne, uriTwo);
            Assert.IsNull(EPServiceProviderManager.GetExistingProvider(uriTwo));
        }
        public void TestOp()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.ThreadingConfig.IsInternalTimerEnabled       = false;
            config.EngineDefaults.ExpressionConfig.IsUdfCache                  = false;
            config.EngineDefaults.ThreadingConfig.IsThreadPoolOutbound         = true;
            config.EngineDefaults.ThreadingConfig.ThreadPoolOutboundNumThreads = 5;
            config.AddEventType <SupportBean>();

            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();

            var         listener = new SupportListenerSleeping(200);
            EPStatement stmt     = epService.EPAdministrator.CreateEPL("select * from SupportBean");

            stmt.Events += listener.Update;

            long delta = PerformanceObserver.TimeMillis(
                delegate {
                for (int i = 0; i < 5; i++)
                {
                    epService.EPRuntime.SendEvent(new SupportBean());
                }
            });

            Assert.IsTrue(delta < 100, "Delta is " + delta);

            Thread.Sleep(1000);
            Assert.AreEqual(5, listener.NewEvents.Count);

            epService.Dispose();
        }
Example #4
0
        public override void Run(EPServiceProvider defaultEPService)
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.Threading.IsInternalTimerEnabled = true;
            config.EngineDefaults.TimeSource.TimeUnit = TimeUnit.MICROSECONDS;

            try {
                EPServiceProviderManager
                .GetProvider(SupportContainer.Instance, this.GetType().Name, config)
                .Initialize();
                Assert.Fail();
            } catch (ConfigurationException ex) {
                SupportMessageAssertUtil.AssertMessage(ex, "Internal timer requires millisecond time resolution");
            }

            config.EngineDefaults.Threading.IsInternalTimerEnabled = false;
            EPServiceProvider epService = EPServiceProviderManager
                                          .GetProvider(SupportContainer.Instance, this.GetType().Name, config);

            try {
                epService.EPRuntime.SendEvent(new TimerControlEvent(TimerControlEvent.ClockTypeEnum.CLOCK_INTERNAL));
                Assert.Fail();
            } catch (EPException ex) {
                SupportMessageAssertUtil.AssertMessage(ex, "Internal timer requires millisecond time resolution");
            }

            epService.Dispose();
        }
        public void TestGetInstance()
        {
            Configuration configuration = new Configuration();

            configuration.EngineDefaults.Threading.IsInternalTimerEnabled = true;

            EPServiceProvider runtimeDef1 = EPServiceProviderManager.GetDefaultProvider();
            EPServiceProvider runtimeA1   = EPServiceProviderManager.GetProvider("A");
            EPServiceProvider runtimeB    = EPServiceProviderManager.GetProvider("B");
            EPServiceProvider runtimeA2   = EPServiceProviderManager.GetProvider("A");
            EPServiceProvider runtimeDef2 = EPServiceProviderManager.GetDefaultProvider(configuration);
            EPServiceProvider runtimeA3   = EPServiceProviderManager.GetProvider("A", configuration);

            Assert.NotNull(runtimeDef1);
            Assert.NotNull(runtimeA1);
            Assert.NotNull(runtimeB);
            Assert.IsTrue(runtimeDef1 == runtimeDef2);
            Assert.IsTrue(runtimeA1 == runtimeA2);
            Assert.IsTrue(runtimeA1 == runtimeA3);
            Assert.IsFalse(runtimeA1 == runtimeDef1);
            Assert.IsFalse(runtimeA1 == runtimeB);

            Assert.AreEqual("A", runtimeA1.URI);
            Assert.AreEqual("A", runtimeA2.URI);
            Assert.AreEqual("B", runtimeB.URI);
            Assert.AreEqual(EPServiceProviderConstants.DEFAULT_ENGINE_URI, runtimeDef1.URI);
            Assert.AreEqual(EPServiceProviderConstants.DEFAULT_ENGINE_URI, runtimeDef2.URI);

            runtimeDef1.Dispose();
            runtimeA1.Dispose();
            runtimeB.Dispose();
            runtimeA2.Dispose();
            runtimeDef2.Dispose();
            runtimeA3.Dispose();
        }
Example #6
0
        public void TestSensorQuery()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.AddEventType("Sensor", typeof(Sensor));
            EPServiceProvider epService = EPServiceProviderManager.GetProvider("testSensorQuery", config);

            bool useGroup = true;
            SupportUpdateListener listener = new SupportUpdateListener();

            if (useGroup)
            {
                // 0.69 sec for 100k
                String stmtString = "select * from Sensor.std:groupwin(type).win:length(10000000).stat:weighted_avg(measurement, confidence)";
                //String stmtString = "SELECT * FROM Sensor.std:groupwin(type).win:length(1000).stat:weighted_avg('measurement','confidence')";
                EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtString);
                stmt.Events += listener.Update;
            }
            else
            {
                // 0.53 sec for 100k
                for (int i = 0; i < 10; i++)
                {
                    String      stmtString = "SELECT * FROM Sensor(type='A" + i + "').win:length(1000000).stat:weighted_avg(measurement,confidence)";
                    EPStatement stmt       = epService.EPAdministrator.CreateEPL(stmtString);
                    stmt.Events += listener.Update;
                }
            }

            // prime
            for (int i = 0; i < 100; i++)
            {
                epService.EPRuntime.SendEvent(new Sensor("A", "1", i, i));
            }

            // measure
            long numEvents = 10000;
            long delta     = PerformanceObserver.TimeMillis(
                () =>
            {
                for (int i = 0; i < numEvents; i++)
                {
                    //int modulo = i % 10;
                    int modulo  = 1;
                    String type = "A" + modulo;
                    epService.EPRuntime.SendEvent(new Sensor(type, "1", i, i));

                    if (i % 1000 == 0)
                    {
                        //Console.Out.WriteLine("Send " + i + " events");
                        listener.Reset();
                    }
                }
            });

            // Console.Out.WriteLine("delta=" + delta);
            Assert.IsTrue(delta < 1000);

            epService.Dispose();
        }
Example #7
0
        private void TryFinalClass(CodeGenerationEnum codeGeneration)
        {
            var config    = SupportConfigFactory.GetConfiguration();
            var legacyDef = new ConfigurationEventTypeLegacy();

            legacyDef.AccessorStyle  = AccessorStyleEnum.NATIVE;
            legacyDef.CodeGeneration = codeGeneration;
            config.AddEventType("MyFinalEvent", typeof(SupportBeanFinal).FullName, legacyDef);

            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            var statementText = "select IntPrimitive " +
                                "from " + typeof(SupportBeanFinal).FullName + "#length(5)";

            var statement = _epService.EPAdministrator.CreateEPL(statementText);
            var listener  = new SupportUpdateListener();

            statement.Events += listener.Update;

            var theEvent = new SupportBeanFinal(10);

            _epService.EPRuntime.SendEvent(theEvent);
            Assert.AreEqual(10, listener.LastNewData[0].Get("IntPrimitive"));

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
            _epService.Dispose();
        }
        private void RunAssertion(ConfigurationEngineDefaults.FilterServiceProfile profile)
        {
            Configuration configuration = new Configuration();

            configuration.EngineDefaults.ExecutionConfig.FilterServiceProfile = profile;
            string            engineURI = this.GetType().Name + "_" + profile;
            EPServiceProvider engine    = EPServiceProviderManager.GetProvider(engineURI, configuration);

            engine.EPAdministrator.Configuration.AddEventType(typeof(MyEvent));

            engine.EPAdministrator.CreateEPL("create context MyContext start @now end after 100 milliseconds");
            SupportUpdateListener[] listeners = new SupportUpdateListener[100];
            for (int i = 0; i < 100; i++)
            {
                listeners[i] = new SupportUpdateListener();
                EPStatement stmt = engine.EPAdministrator.CreateEPL("context MyContext select FieldOne, count(*) as cnt from MyEvent " +
                                                                    "group by FieldOne output last when terminated");
                stmt.Events += listeners[i].Update;
            }

            int eventCount = 100000; // keep this divisible by 1000

            for (int i = 0; i < eventCount; i++)
            {
                string group = (eventCount % 1000).ToString();
                engine.EPRuntime.SendEvent(new MyEvent(i.ToString(), group));
            }

            Thread.Sleep(2000);
            engine.Dispose();

            AssertReceived(eventCount, listeners);
        }
Example #9
0
        public void TestMapEvents()
        {
            Configuration configuration          = SupportConfigFactory.GetConfiguration();
            IDictionary <String, Object> typeMap = new Dictionary <String, Object>();

            typeMap["int"]    = typeof(int);
            typeMap["string"] = typeof(string);
            configuration.AddEventType("mapEvent", typeMap);
            _epService = EPServiceProviderManager.GetDefaultProvider(configuration);
            _epService.Initialize();

            String text = "select *, string||string as concat from mapEvent.win:length(5)";

            EPStatement statement = _epService.EPAdministrator.CreateEPL(text);

            statement.Events += _listener.Update;

            // The map to send into the runtime
            IDictionary <String, Object> props = new Dictionary <String, Object>();

            props["int"]    = 1;
            props["string"] = "xx";
            _epService.EPRuntime.SendEvent(props, "mapEvent");

            // The map of expected results
            IDictionary <String, Object> properties = new Dictionary <String, Object>();

            properties["int"]    = 1;
            properties["string"] = "xx";
            properties["concat"] = "xxxx";

            AssertProperties(properties, _listener);

            _epService.Dispose();
        }
Example #10
0
        public void TestGetInstance()
        {
            Configuration configuration = SupportConfigFactory.GetConfiguration();

            EPServiceProvider runtimeDef1 = EPServiceProviderManager.GetDefaultProvider();
            EPServiceProvider runtimeA1   = EPServiceProviderManager.GetProvider("A");
            EPServiceProvider runtimeB    = EPServiceProviderManager.GetProvider("B");
            EPServiceProvider runtimeA2   = EPServiceProviderManager.GetProvider("A");
            EPServiceProvider runtimeDef2 = EPServiceProviderManager.GetDefaultProvider(configuration);
            EPServiceProvider runtimeA3   = EPServiceProviderManager.GetProvider("A", configuration);

            Assert.NotNull(runtimeDef1);
            Assert.NotNull(runtimeA1);
            Assert.NotNull(runtimeB);
            Assert.IsTrue(runtimeDef1 == runtimeDef2);
            Assert.IsTrue(runtimeA1 == runtimeA2);
            Assert.IsTrue(runtimeA1 == runtimeA3);
            Assert.IsFalse(runtimeA1 == runtimeDef1);
            Assert.IsFalse(runtimeA1 == runtimeB);

            Assert.AreEqual("A", runtimeA1.URI);
            Assert.AreEqual("A", runtimeA2.URI);
            Assert.AreEqual("B", runtimeB.URI);
            Assert.AreEqual(EPServiceProviderConstants.DEFAULT_ENGINE_URI, runtimeDef1.URI);
            Assert.AreEqual(EPServiceProviderConstants.DEFAULT_ENGINE_URI, runtimeDef2.URI);

            runtimeDef1.Dispose();
            runtimeA1.Dispose();
            runtimeB.Dispose();
            runtimeA2.Dispose();
            runtimeDef2.Dispose();
            runtimeA3.Dispose();
        }
Example #11
0
 public void TearDown()
 {
     if (InstrumentationHelper.ENABLED)
     {
         InstrumentationHelper.EndTest();
     }
     _epService.Dispose();
 }
Example #12
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();
            }
        }
 protected virtual void Dispose(bool disposing)
 {
     if (!disposing || _engine == null)
     {
         return;
     }
     _engine.Dispose();
     _engine = null;
 }
Example #14
0
 public void TearDown()
 {
     if (InstrumentationHelper.ENABLED)
     {
         InstrumentationHelper.EndTest();
     }
     _listener = null;
     _epService.Dispose();
     SupportSQLColumnTypeConversion.Reset();
 }
Example #15
0
        public void TestDestroyObtainTwice()
        {
            Configuration cf = SupportConfigFactory.GetConfiguration();

            cf.AddPluginLoader("AP", typeof(SupportPluginLoader).FullName, null);
            EPServiceProviderManager.GetProvider("TestAdapterLoader", cf);
            EPServiceProvider ep = EPServiceProviderManager.GetProvider("TestAdapterLoader");

            ep.Dispose();
            Assert.AreEqual(1, SupportPluginLoader.Destroys.Count);
        }
        private void TrySend(int numThreads, int numEvents, bool isPreserveOrder, ConfigurationEngineDefaults.ThreadingConfig.Locking?locking)
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.Threading.IsListenerDispatchPreserveOrder = isPreserveOrder;
            config.EngineDefaults.Threading.ListenerDispatchLocking         = locking.GetValueOrDefault();

            EPServiceProvider engine = EPServiceProviderManager.GetProvider(
                SupportContainer.Instance, this.GetType().Name, config);

            engine.Initialize();

            // setup statements
            EPStatement stmtInsert = engine.EPAdministrator.CreateEPL("select count(*) as cnt from " + typeof(SupportBean).FullName);
            var         listener   = new SupportMTUpdateListener();

            stmtInsert.Events += listener.Update;

            // execute
            var threadPool = Executors.NewFixedThreadPool(numThreads);
            var future     = new Future <bool> [numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                future[i] = threadPool.Submit(new SendEventCallable(i, engine, new GeneratorIterator(numEvents)));
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(10, TimeUnit.SECONDS);

            for (int i = 0; i < numThreads; i++)
            {
                Assert.IsTrue(future[i].GetValueOrDefault());
            }

            EventBean[] events = listener.GetNewDataListFlattened();
            var         result = new long[events.Length];

            for (int i = 0; i < events.Length; i++)
            {
                result[i] = (long)events[i].Get("cnt");
            }
            //Log.Info(".trySend result=" + CompatExtensions.Render(result));

            // assert result
            Assert.AreEqual(numEvents * numThreads, events.Length);
            for (int i = 0; i < numEvents * numThreads; i++)
            {
                Assert.AreEqual(result[i], (long)i + 1);
            }

            engine.Dispose();
        }
        private void RunAssertionPatternFollowedBy(ConfigurationEngineDefaults.FilterServiceProfile profile)
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.AddEventType("S0", typeof(SupportBean_S0));
            String            engineURI = GetType().Name + "_" + profile;
            EPServiceProvider epService = EPServiceProviderManager.GetProvider(engineURI, config);

            epService.Initialize();

            String[] epls =
            {
                "select sa.Id,sb.Id,sc.Id,sd.Id from pattern [(sa=S0(Id=0)->sb=S0(Id=1)) or (sc=S0(Id=1)->sd=S0(Id=0))]",
                "select sa.Id,sb.Id,sc.Id,sd.Id from pattern [(sa=S0(Id=1)->sb=S0(Id=2)) or (sc=S0(Id=2)->sd=S0(Id=1))]",
                "select sa.Id,sb.Id,sc.Id,sd.Id from pattern [(sa=S0(Id=2)->sb=S0(Id=3)) or (sc=S0(Id=3)->sd=S0(Id=2))]",
                "select sa.Id,sb.Id,sc.Id,sd.Id from pattern [(sa=S0(Id=3)->sb=S0(Id=4)) or (sc=S0(Id=4)->sd=S0(Id=3))]",
                "select sa.Id,sb.Id,sc.Id,sd.Id from pattern [(sa=S0(Id=4)->sb=S0(Id=5)) or (sc=S0(Id=5)->sd=S0(Id=4))]",
                "select sa.Id,sb.Id,sc.Id,sd.Id from pattern [(sa=S0(Id=5)->sb=S0(Id=6)) or (sc=S0(Id=6)->sd=S0(Id=5))]",
                "select sa.Id,sb.Id,sc.Id,sd.Id from pattern [(sa=S0(Id=6)->sb=S0(Id=7)) or (sc=S0(Id=7)->sd=S0(Id=6))]",
                "select sa.Id,sb.Id,sc.Id,sd.Id from pattern [(sa=S0(Id=7)->sb=S0(Id=8)) or (sc=S0(Id=8)->sd=S0(Id=7))]",
                "select sa.Id,sb.Id,sc.Id,sd.Id from pattern [(sa=S0(Id=8)->sb=S0(Id=9)) or (sc=S0(Id=9)->sd=S0(Id=8))]"
            };

            for (int i = 0; i < 100; i++)
            {
                var listener = new SupportMTUpdateListener();
                var stmts    = new EPStatement[epls.Length];
                for (int j = 0; j < epls.Length; j++)
                {
                    stmts[j]         = epService.EPAdministrator.CreateEPL(epls[j]);
                    stmts[j].Events += listener.Update;
                }

                var threadOneValues = new int[] { 0, 2, 4, 6, 8 };
                var threadTwoValues = new int[] { 1, 3, 5, 7, 9 };
                var threadArray     = new[] { threadOneValues, threadTwoValues };

                Parallel.ForEach(
                    threadArray,
                    threadValues => ExecuteSender(epService.EPRuntime, threadValues));

                EventBean[] events = listener.GetNewDataListFlattened();
                Assert.AreEqual(9, events.Length);

                for (int j = 0; j < epls.Length; j++)
                {
                    stmts[j].Dispose();
                }
            }

            epService.Dispose();
        }
        private void RunAssertionDestroyObtainTwice()
        {
            SupportPluginLoader.Reset();

            Configuration cf = SupportConfigFactory.GetConfiguration();

            cf.AddPluginLoader("AP", typeof(SupportPluginLoader).FullName, null);
            EPServiceProviderManager.GetProvider(SupportContainer.Instance, "ExecClientAdapterLoader", cf);
            EPServiceProvider ep = EPServiceProviderManager.GetProvider("ExecClientAdapterLoader");

            ep.Dispose();
            Assert.AreEqual(1, SupportPluginLoader.Destroys.Count);
        }
        private void RunAssertionListenerStateChange()
        {
            var               listener      = new SupportServiceStateListener();
            Configuration     configuration = SupportConfigFactory.GetConfiguration();
            EPServiceProvider epService     = EPServiceProviderManager.GetProvider(
                SupportContainer.Instance, this.GetType().Name + "__listenerstatechange", configuration);

            epService.ServiceInitialized      += listener.OnEPServiceInitialized;
            epService.ServiceDestroyRequested += listener.OnEPServiceDestroyRequested;
            epService.Dispose();
            Assert.AreSame(epService, listener.AssertOneGetAndResetDestroyedEvents());

            epService.Initialize();
            Assert.AreSame(epService, listener.AssertOneGetAndResetInitializedEvents());

            epService.RemoveAllServiceStateEventHandlers();
            epService.Initialize();
            Assert.IsTrue(listener.InitializedEvents.IsEmpty());

            epService.ServiceInitialized      += listener.OnEPServiceInitialized;
            epService.ServiceDestroyRequested += listener.OnEPServiceDestroyRequested;
            var listenerTwo = new SupportServiceStateListener();

            epService.ServiceInitialized      += listenerTwo.OnEPServiceInitialized;
            epService.ServiceDestroyRequested += listenerTwo.OnEPServiceDestroyRequested;
            epService.Initialize();
            Assert.AreSame(epService, listener.AssertOneGetAndResetInitializedEvents());
            Assert.AreSame(epService, listenerTwo.AssertOneGetAndResetInitializedEvents());

            epService.ServiceInitialized      -= listener.OnEPServiceInitialized;
            epService.ServiceDestroyRequested -= listener.OnEPServiceDestroyRequested;
            epService.Initialize();
            Assert.AreSame(epService, listenerTwo.AssertOneGetAndResetInitializedEvents());
            Assert.IsTrue(listener.InitializedEvents.IsEmpty());

            epService.Dispose();
        }
        public void TestSensorQuery()
        {
            Configuration configuration = GetConfiguration();

            configuration.EngineDefaults.ViewResourcesConfig.IsAllowMultipleExpiryPolicies = true;
            EPServiceProvider epService = EPServiceProviderManager.GetProvider("testSensorQuery", configuration);

            epService.Initialize();
            MatchListener listener = new MatchListener();

            String stmtString =
                "SELECT max(high.type) as type, \n" +
                " max(high.measurement) as highMeasurement, max(high.confidence) as confidenceOfHigh, max(high.device) as deviceOfHigh\n" +
                ",min(low.measurement) as lowMeasurement, min(low.confidence) as confidenceOfLow, min(low.device) as deviceOfLow\n" +
                "FROM\n" +
                " Sensor.std:groupwin(type).win:time(1 hour).std:unique(device).ext:sort(1, measurement desc) as high " +
                ",Sensor.std:groupwin(type).win:time(1 hour).std:unique(device).ext:sort(1, measurement asc) as low ";

            EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtString);

            Log.Info(stmtString);
            stmt.Events += (sender, args) => listener.Update(args.NewEvents, args.OldEvents);

            EPRuntime     runtime = epService.EPRuntime;
            List <Sensor> events  = new List <Sensor>();

            events.Add(new Sensor("Temperature", "Device1", 68.0, 96.5));
            events.Add(new Sensor("Temperature", "Device2", 65.0, 98.5));
            events.Add(new Sensor("Temperature", "Device1", 62.0, 95.3));
            events.Add(new Sensor("Temperature", "Device2", 71.3, 99.3));
            foreach (Sensor theEvent in events)
            {
                LogEvent(theEvent);
                runtime.SendEvent(theEvent);
            }
            EventBean lastEvent = listener.LastEventBean;

            Assert.IsTrue(lastEvent != null);
            Assert.AreEqual(62.0, lastEvent.Get("lowMeasurement"));
            Assert.AreEqual("Device1", lastEvent.Get("deviceOfLow"));
            Assert.AreEqual(95.3, lastEvent.Get("confidenceOfLow"));
            Assert.AreEqual(71.3, lastEvent.Get("highMeasurement"));
            Assert.AreEqual("Device2", lastEvent.Get("deviceOfHigh"));
            Assert.AreEqual(99.3, lastEvent.Get("confidenceOfHigh"));

            epService.Dispose();
        }
Example #21
0
        public void TestOp()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.ThreadingConfig.IsInternalTimerEnabled        = true;
            config.EngineDefaults.ExpressionConfig.IsUdfCache                   = false;
            config.EngineDefaults.ThreadingConfig.IsThreadPoolRouteExec         = true;
            config.EngineDefaults.ThreadingConfig.ThreadPoolRouteExecNumThreads = 5;
            config.AddEventType <SupportBean>();
            config.AddImport(typeof(SupportStaticMethodLib).FullName);

            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();

            Log.Debug("Creating statements");
            int countStatements = 100;
            SupportListenerTimerHRes listener = new SupportListenerTimerHRes();

            for (int i = 0; i < countStatements; i++)
            {
                EPStatement innerStmt = epService.EPAdministrator.CreateEPL("select SupportStaticMethodLib.Sleep(10) from SupportBean");
                innerStmt.Events += listener.Update;
            }

            Log.Info("Sending trigger event");
            long delta = PerformanceObserver.TimeMillis(() => epService.EPRuntime.SendEvent(new SupportBean()));

            Assert.LessOrEqual(delta, 100, "Delta is " + delta);

            Thread.Sleep(2000);
            Assert.AreEqual(100, listener.NewEvents.Count);
            listener.NewEvents.Clear();

            // destroy all statements
            epService.EPAdministrator.DestroyAllStatements();
            EPStatement stmt = epService.EPAdministrator.CreateEPL("select SupportStaticMethodLib.Sleep(10) from SupportBean, SupportBean");

            stmt.Events += listener.Update;
            epService.EPRuntime.SendEvent(new SupportBean());
            Thread.Sleep(100);
            Assert.AreEqual(1, listener.NewEvents.Count);

            epService.Dispose();
        }
Example #22
0
        public void Run()
        {
            Log.Info("Setting up engine instance.");

            var container = ContainerExtensions.CreateDefaultContainer();

            Configuration config = new Configuration(container);

            config.EngineDefaults.EventMeta.DefaultEventRepresentation = EventUnderlyingType.MAP; // use Map-type events for testing
            config.AddPlugInVirtualDataWindow("sample", "samplevdw", typeof(SampleVirtualDataWindowFactory).FullName);
            config.AddEventTypeAutoName(typeof(SampleVirtualDataWindowMain).Namespace);           // import all event classes

            EPServiceProvider epService = EPServiceProviderManager.GetProvider(container, "LargeExternalDataExample", config);

            // First: Create an event type for rows of the external data - here the example use a Map-based event and any of the other types (POJO, XML) can be used as well.
            // Populate event property names and types.
            // Note: the type must match the data returned by virtual data window indexes.
            epService.EPAdministrator.CreateEPL("create schema SampleEvent as (key1 string, key2 string, value1 int, value2 double)");

            Log.Info("Creating named window with virtual.");

            // Create Named Window holding SampleEvent instances
            epService.EPAdministrator.CreateEPL("create window MySampleWindow.sample:samplevdw() as SampleEvent");

            // Example subquery
            Log.Info("Running subquery example.");
            RunSubquerySample(epService);

            // Example joins
            Log.Info("Running join example.");
            RunJoinSample(epService);

            // Sample FAF
            Log.Info("Running fire-and-forget query example.");
            RunSampleFireAndForgetQuery(epService);

            // Sample On-Merge
            Log.Info("Running on-merge example.");
            RunSampleOnMerge(epService);

            // Cleanup
            Log.Info("Destroying engine instance, sample completed successfully.");
            epService.Dispose();
        }
Example #23
0
        public void TryNativeBeanAccessor(CodeGenerationEnum codeGeneration)
        {
            var config    = SupportConfigFactory.GetConfiguration();
            var legacyDef = new ConfigurationEventTypeLegacy();

            legacyDef.AccessorStyle  = AccessorStyleEnum.NATIVE;
            legacyDef.CodeGeneration = codeGeneration;
            legacyDef.AddFieldProperty("explicitFInt", "fieldIntPrimitive");
            legacyDef.AddMethodProperty("explicitMGetInt", "GetIntPrimitive");
            legacyDef.AddMethodProperty("explicitMReadInt", "ReadIntPrimitive");
            config.AddEventType("MyLegacyEvent", typeof(SupportLegacyBeanInt).FullName, legacyDef);

            _epService = EPServiceProviderManager.GetDefaultProvider(config);
            _epService.Initialize();
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName);
            }

            var statementText = "select IntPrimitive, explicitFInt, explicitMGetInt, explicitMReadInt " +
                                " from MyLegacyEvent#length(5)";

            var statement = _epService.EPAdministrator.CreateEPL(statementText);
            var listener  = new SupportUpdateListener();

            statement.Events += listener.Update;
            var eventType = statement.EventType;

            var theEvent = new SupportLegacyBeanInt(10);

            _epService.EPRuntime.SendEvent(theEvent);

            foreach (var name in new String[] { "IntPrimitive", "explicitFInt", "explicitMGetInt", "explicitMReadInt" })
            {
                Assert.AreEqual(typeof(int), eventType.GetPropertyType(name));
                Assert.AreEqual(10, listener.LastNewData[0].Get(name));
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.EndTest();
            }
            _epService.Dispose();
        }
Example #24
0
        public void TestPrimitivesTypes()
        {
            _properties            = new Properties();
            _properties["MyInt"]   = typeof(int).FullName;
            _properties["byteArr"] = typeof(byte[]).FullName;
            _properties["MyInt2"]  = "int";
            _properties["double"]  = "double";
            _properties["boolean"] = "boolean";
            _properties["long"]    = "long";
            _properties["astring"] = "string";

            Configuration configuration = SupportConfigFactory.GetConfiguration();

            configuration.AddEventType("MyPrimMapEvent", _properties);

            _epService = EPServiceProviderManager.GetProvider("testPrimitivesTypes", configuration);

            _epService.Dispose();
        }
Example #25
0
        public void TearDown()
        {
            _listener             = null;
            _listenerTwo          = null;
            _listenerEngineMetric = null;
            _listenerStmtMetric   = null;

            try
            {
                if (_epService != null)
                {
                    _epService.Dispose();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
        private void RunAssertionAdapterLoader()
        {
            SupportPluginLoader.Reset();
            // Assure destroy order ESPER-489

            var props = new Properties();

            props.Put("name", "val");
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.AddPluginLoader("MyLoader", typeof(SupportPluginLoader).FullName, props);

            props = new Properties();
            props.Put("name2", "val2");
            config.AddPluginLoader("MyLoader2", typeof(SupportPluginLoader).FullName, props);

            EPServiceProvider service = EPServiceProviderManager.GetProvider(
                SupportContainer.Instance, "ExecClientAdapterLoader", config);

            Assert.AreEqual(2, SupportPluginLoader.Names.Count);
            Assert.AreEqual(2, SupportPluginLoader.PostInitializes.Count);
            Assert.AreEqual("MyLoader", SupportPluginLoader.Names[0]);
            Assert.AreEqual("MyLoader2", SupportPluginLoader.Names[1]);
            Assert.AreEqual("val", SupportPluginLoader.Props[0].Get("name"));
            Assert.AreEqual("val2", SupportPluginLoader.Props[1].Get("name2"));

            Object loader = service.Directory.Lookup("plugin-loader/MyLoader");

            Assert.IsTrue(loader is SupportPluginLoader);
            loader = service.Directory.Lookup("plugin-loader/MyLoader2");
            Assert.IsTrue(loader is SupportPluginLoader);

            SupportPluginLoader.PostInitializes.Clear();
            SupportPluginLoader.Names.Clear();
            service.Initialize();
            Assert.AreEqual(2, SupportPluginLoader.PostInitializes.Count);
            Assert.AreEqual(2, SupportPluginLoader.Names.Count);

            service.Dispose();
            Assert.AreEqual(2, SupportPluginLoader.Destroys.Count);
            Assert.AreEqual("val2", SupportPluginLoader.Destroys[0].Get("name2"));
            Assert.AreEqual("val", SupportPluginLoader.Destroys[1].Get("name"));
        }
        private void RunAssertionStatementStateChange()
        {
            EPServiceProvider stateChangeEngine = EPServiceProviderManager.GetProvider(
                SupportContainer.Instance, this.GetType().Name + "_statechange",
                SupportConfigFactory.GetConfiguration());
            EPServiceProviderSPI spi = (EPServiceProviderSPI)stateChangeEngine;

            var observer = new SupportStmtLifecycleObserver();

            spi.StatementLifecycleSvc.LifecycleEvent += observer.Observe;
            var listener = new SupportStatementStateListener();

            stateChangeEngine.StatementCreate      += listener.OnStatementCreate;
            stateChangeEngine.StatementStateChange += listener.OnStatementStateChange;

            EPStatement stmt = stateChangeEngine.EPAdministrator.CreateEPL("select * from " + typeof(SupportBean).FullName);

            Assert.AreEqual("CREATE;STATECHANGE;", observer.EventsAsString);
            Assert.AreEqual(stmt, listener.AssertOneGetAndResetCreatedEvents());
            Assert.AreEqual(stmt, listener.AssertOneGetAndResetStateChangeEvents());

            observer.Flush();
            stmt.Stop();
            Assert.AreEqual("STATECHANGE;", observer.EventsAsString);
            Assert.AreEqual(stmt.Name, observer.Events[0].Statement.Name);
            Assert.AreEqual(stmt, listener.AssertOneGetAndResetStateChangeEvents());

            observer.Flush();
            stmt.Events += (sender, args) => { };
            Assert.AreEqual("LISTENER_ADD;", observer.EventsAsString);
            Assert.IsNotNull(observer.LastContext);
            Assert.IsTrue(observer.LastContext[0] is UpdateEventHandler);

            observer.Flush();
            stmt.RemoveAllEventHandlers();
            Assert.AreEqual(StatementLifecycleEvent.LifecycleEventType.LISTENER_REMOVE_ALL.ToString() + ";", observer.EventsAsString);

            stmt.Dispose();
            Assert.AreEqual(stmt, listener.AssertOneGetAndResetStateChangeEvents());

            stateChangeEngine.Dispose();
        }
Example #28
0
        public void TestWithAdapterLoader()
        {
            // Assure destroy order ESPER-489
            Configuration config = SupportConfigFactory.GetConfiguration();

            Properties props = new Properties();

            props["name"] = "val";
            config.AddPluginLoader("MyLoader", typeof(SupportPluginLoader).FullName, props);

            props          = new Properties();
            props["name2"] = "val2";
            config.AddPluginLoader("MyLoader2", typeof(SupportPluginLoader).FullName, props);

            EPServiceProvider service = EPServiceProviderManager.GetProvider("TestAdapterLoader", config);

            Assert.AreEqual(2, SupportPluginLoader.Names.Count);
            Assert.AreEqual(2, SupportPluginLoader.PostInitializes.Count);
            Assert.AreEqual("MyLoader", SupportPluginLoader.Names[0]);
            Assert.AreEqual("MyLoader2", SupportPluginLoader.Names[1]);
            Assert.AreEqual("val", SupportPluginLoader.Props[0].Get("name"));
            Assert.AreEqual("val2", SupportPluginLoader.Props[1].Get("name2"));

            EPServiceProviderSPI spi = (EPServiceProviderSPI)service;
            Object loader            = spi.EngineEnvContext.Lookup("plugin-loader/MyLoader");

            Assert.IsTrue(loader is SupportPluginLoader);
            loader = spi.EngineEnvContext.Lookup("plugin-loader/MyLoader2");
            Assert.IsTrue(loader is SupportPluginLoader);

            SupportPluginLoader.PostInitializes.Clear();
            SupportPluginLoader.Names.Clear();
            service.Initialize();
            Assert.AreEqual(2, SupportPluginLoader.PostInitializes.Count);
            Assert.AreEqual(2, SupportPluginLoader.Names.Count);

            service.Dispose();
            Assert.AreEqual(2, SupportPluginLoader.Destroys.Count);
            Assert.AreEqual("val2", SupportPluginLoader.Destroys[0].Get("name2"));
            Assert.AreEqual("val", SupportPluginLoader.Destroys[1].Get("name"));
        }
Example #29
0
        private void RunAssertionIteratorMultiStmtViewShare()
        {
            Configuration config = SupportConfigFactory.GetConfiguration();

            config.EngineDefaults.ViewResources.IsShareViews = true;
            EPServiceProvider engine = EPServiceProviderManager.GetProvider(
                SupportContainer.Instance, typeof(ExecMTStmtIterate).Name, config);

            var stmt = new EPStatement[3];

            for (int i = 0; i < stmt.Length; i++)
            {
                string name     = "Stmt_" + i;
                string stmtText = "@Name('" + name + "') select TheString from " + typeof(SupportBean).FullName + "#time(5 min)";
                stmt[i] = engine.EPAdministrator.CreateEPL(stmtText);
            }

            TrySend(engine, 4, 10, stmt);

            engine.Dispose();
        }
Example #30
0
        public void TestFastShutdown()
        {
            Configuration config = new Configuration();

            config.EngineDefaults.ThreadingConfig.IsThreadPoolInbound         = true;
            config.EngineDefaults.ThreadingConfig.ThreadPoolInboundNumThreads = 2;
            config.AddEventType <MyEvent>();
            config.AddPlugInSingleRowFunction("sleepaLittle", GetType().FullName, "SleepaLittle");
            EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config);

            epService.Initialize();

            EPStatement stmt = epService.EPAdministrator.CreateEPL("select sleepaLittle(100) from MyEvent");

            stmt.Subscriber = new MySubscriber();
            for (int i = 0; i < 10000; i++)
            {
                epService.EPRuntime.SendEvent(new MyEvent());
            }
            epService.Dispose();
        }