Ejemplo n.º 1
0
        private void RunAssertionGetSetAPI(EPServiceProvider epService)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecContextVariables)))
            {
                return;
            }

            epService.EPAdministrator.CreateEPL("create context MyCtx as initiated by SupportBean_S0 s0 terminated after 24 hours");
            epService.EPAdministrator.CreateEPL("context MyCtx create variable int mycontextvar = 5");
            epService.EPAdministrator.CreateEPL("context MyCtx on SupportBean(TheString = context.s0.p00) set mycontextvar = IntPrimitive");

            epService.EPRuntime.SendEvent(new SupportBean_S0(0, "P1"));    // allocate partition P1
            AssertVariableValues(epService, 0, 5);

            epService.EPRuntime.SetVariableValue(Collections.SingletonDataMap("mycontextvar", 10), 0);
            AssertVariableValues(epService, 0, 10);

            epService.EPRuntime.SendEvent(new SupportBean_S0(0, "P2"));    // allocate partition P2
            AssertVariableValues(epService, 1, 5);

            epService.EPRuntime.SetVariableValue(Collections.SingletonDataMap("mycontextvar", 11), 1);
            AssertVariableValues(epService, 1, 11);

            // global variable - trying to set via context partition selection
            epService.EPAdministrator.CreateEPL("create variable int myglobarvar = 0");
            try {
                epService.EPRuntime.SetVariableValue(Collections.SingletonDataMap("myglobarvar", 11), 0);
                Assert.Fail();
            } catch (VariableNotFoundException ex) {
                Assert.AreEqual("Variable by name 'myglobarvar' is a global variable and not context-partitioned", ex.Message);
            }

            // global variable - trying to get via context partition selection
            try {
                epService.EPRuntime.GetVariableValue(Collections.SingletonSet("myglobarvar"), new SupportSelectorById(1));
                Assert.Fail();
            } catch (VariableNotFoundException ex) {
                Assert.AreEqual("Variable by name 'myglobarvar' is a global variable and not context-partitioned", ex.Message);
            }

            epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 2
0
        private void RunAssertionLengthBatchSize3And2Staggered(EPServiceProvider epService, SupportBean[] events)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecViewLengthBatch)))
            {
                return;
            }

            EPStatement stmt = epService.EPAdministrator.CreateEPL(
                "select irstream * from " + typeof(SupportBean).FullName + "#length_batch(3)#length_batch(2)");
            var listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SendEvent(events[0], epService);
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertEqualsExactOrderUnderlying(null, stmt.GetEnumerator());

            SendEvent(events[1], epService);
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertEqualsExactOrderUnderlying(null, stmt.GetEnumerator());

            SendEvent(events[2], epService);
            EPAssertionUtil.AssertUnderlyingPerRow(listener.AssertInvokedAndReset(), new SupportBean[] { events[0], events[1], events[2] }, null);
            EPAssertionUtil.AssertEqualsExactOrderUnderlying(null, stmt.GetEnumerator());

            SendEvent(events[3], epService);
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertEqualsExactOrderUnderlying(null, stmt.GetEnumerator());

            SendEvent(events[4], epService);
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertEqualsExactOrderUnderlying(null, stmt.GetEnumerator());

            SendEvent(events[5], epService);
            EPAssertionUtil.AssertUnderlyingPerRow(listener.AssertInvokedAndReset(),
                                                   new SupportBean[] { events[3], events[4], events[5] },
                                                   new SupportBean[] { events[0], events[1], events[2] });
            EPAssertionUtil.AssertEqualsExactOrderUnderlying(null, stmt.GetEnumerator());

            stmt.Dispose();
        }
Ejemplo n.º 3
0
        public override void Run(EPServiceProvider epService)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecClientThreadedConfigRoute)))
            {
                return;
            }

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

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

            Log.Info("Sending trigger event");
            long start = PerformanceObserver.NanoTime;

            epService.EPRuntime.SendEvent(new SupportBean());
            long end   = PerformanceObserver.NanoTime;
            long delta = (end - start) / 1000000;

            Assert.IsTrue(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);
        }
Ejemplo n.º 4
0
        public override void Run(EPServiceProvider epService)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecEventXMLSchemaEventReplace)))
            {
                return;
            }

            string      stmtSelectWild = "select * from TestXMLSchemaType";
            EPStatement wildStmt       = epService.EPAdministrator.CreateEPL(stmtSelectWild);
            EventType   type           = wildStmt.EventType;

            SupportEventTypeAssertionUtil.AssertConsistency(type);

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("nested1", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("prop4", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("nested3", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("customProp", typeof(double?), null, false, false, false, false, false),
            }, type.PropertyDescriptors);

            // update type and replace
            _eventTypeMeta.SchemaResource = SupportContainer.Instance.ResourceManager().ResolveResourceURL(CLASSLOADER_SCHEMA_VERSION2_URI).ToString();
            _eventTypeMeta.AddXPathProperty("countProp", "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathResultType.Number);
            epService.EPAdministrator.Configuration.ReplaceXMLEventType("TestXMLSchemaType", _eventTypeMeta);

            wildStmt = epService.EPAdministrator.CreateEPL(stmtSelectWild);
            type     = wildStmt.EventType;
            SupportEventTypeAssertionUtil.AssertConsistency(type);

            EPAssertionUtil.AssertEqualsAnyOrder(new EventPropertyDescriptor[] {
                new EventPropertyDescriptor("nested1", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("prop4", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("prop5", typeof(string), typeof(char), false, false, true, false, false),
                new EventPropertyDescriptor("nested3", typeof(XmlNode), null, false, false, false, false, true),
                new EventPropertyDescriptor("customProp", typeof(double?), null, false, false, false, false, false),
                new EventPropertyDescriptor("countProp", typeof(double?), null, false, false, false, false, false),
            }, type.PropertyDescriptors);
        }
Ejemplo n.º 5
0
        private void RunAssertionCreateStmt(EPServiceProvider epService)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecClientIsolationUnit)))
            {
                return;
            }

            EPServiceProviderIsolated unit = epService.GetEPServiceIsolated("i1");

            SendTimerUnisolated(epService, 100000);
            SendTimerIso(1000, unit);

            var         fields   = new string[] { "ct" };
            EPStatement stmt     = unit.EPAdministrator.CreateEPL("select current_timestamp() as ct from pattern[every timer:interval(10)]", null, null);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SendTimerIso(10999, unit);
            Assert.IsFalse(listener.IsInvoked);

            SendTimerIso(11000, unit);
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 11000L });

            SendTimerIso(15000, unit);

            unit.EPAdministrator.RemoveStatement(stmt);

            SendTimerIso(21000, unit);
            Assert.IsFalse(listener.IsInvoked);

            SendTimerUnisolated(epService, 106000);
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 106000L });

            unit.Dispose();
            epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 6
0
        private void RunAssertionSubscriberNamedWindowConsumerIterate(EPServiceProvider epService)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecClientIsolationUnit)))
            {
                return;
            }

            epService.EPAdministrator.CreateEPL("create window MyWindow#keepall as select * from SupportBean");
            epService.EPAdministrator.CreateEPL("insert into MyWindow select * from SupportBean");
            epService.EPRuntime.SendEvent(new SupportBean("E1", 1));

            EPServiceProviderIsolated isolatedService = epService.GetEPServiceIsolated("isolatedStmts");

            isolatedService.EPRuntime.SendEvent(new CurrentTimeEvent(DateTimeHelper.CurrentTimeMillis));

            var         subscriber = new SupportSubscriber();
            EPStatement stmtOne    = epService.EPAdministrator.CreateEPL("select * from SupportBean");

            stmtOne.Subscriber = subscriber;

            EPStatement stmtTwo = isolatedService.EPAdministrator.CreateEPL("select * from MyWindow", null, null);

            isolatedService.EPAdministrator.AddStatement(stmtOne);

            IEnumerator <EventBean> iter = stmtTwo.GetEnumerator();

            while (iter.MoveNext())
            {
                EventBean theEvent = iter.Current;
                isolatedService.EPRuntime.SendEvent(theEvent.Underlying);
            }

            Assert.IsTrue(subscriber.IsInvoked);

            epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 7
0
        private void RunAssertionSuspend(EPServiceProvider epService)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecClientIsolationUnit)))
            {
                return;
            }

            SendTimerUnisolated(epService, 1000);
            var         fields   = new string[] { "TheString" };
            string      epl      = "select irstream TheString from SupportBean#time(10)";
            EPStatement stmt     = epService.EPAdministrator.CreateEPL(epl);
            var         listener = new SupportUpdateListener();

            stmt.Events += listener.Update;

            SendTimerUnisolated(epService, 2000);
            epService.EPRuntime.SendEvent(new SupportBean("E1", 0));

            SendTimerUnisolated(epService, 3000);
            epService.EPRuntime.SendEvent(new SupportBean("E2", 0));

            SendTimerUnisolated(epService, 7000);
            epService.EPRuntime.SendEvent(new SupportBean("E3", 0));

            SendTimerUnisolated(epService, 8000);
            EPStatement stmtTwo = epService.EPAdministrator.CreateEPL("select 'x' as TheString from pattern [timer:interval(10)]");

            stmtTwo.Events += listener.Update;

            EPServiceProviderIsolated unit = epService.GetEPServiceIsolated("i1");

            unit.EPAdministrator.AddStatement(new EPStatement[] { stmt, stmtTwo });
            EPAssertionUtil.AssertEqualsAnyOrder(new string[] { stmt.Name, stmtTwo.Name }, unit.EPAdministrator.StatementNames);
            Assert.AreEqual("i1", stmt.ServiceIsolated);
            Assert.AreEqual("i1", stmt.ServiceIsolated);

            listener.Reset();
            epService.EPRuntime.SendEvent(new SupportBean("E4", 0));
            SendTimerUnisolated(epService, 15000);
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1" }, new object[] { "E2" }, new object[] { "E3" } });

            unit.EPAdministrator.RemoveStatement(new EPStatement[] { stmt, stmtTwo });
            EPAssertionUtil.AssertEqualsAnyOrder(new string[0], unit.EPAdministrator.StatementNames);
            Assert.IsNull(stmt.ServiceIsolated);
            Assert.IsNull(stmt.ServiceIsolated);

            SendTimerUnisolated(epService, 18999);
            Assert.IsFalse(listener.IsInvoked);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E1" }, new object[] { "E2" }, new object[] { "E3" } });

            SendTimerUnisolated(epService, 19000);
            EPAssertionUtil.AssertProps(listener.AssertOneGetOldAndReset(), fields, new object[] { "E1" });
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E2" }, new object[] { "E3" } });

            SendTimerUnisolated(epService, 23999);
            EPAssertionUtil.AssertProps(listener.AssertOneGetOldAndReset(), fields, new object[] { "E2" });
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E3" } });

            SendTimerUnisolated(epService, 24000);
            EPAssertionUtil.AssertProps(listener.AssertOneGetOldAndReset(), fields, new object[] { "E3" });
            EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, null);

            SendTimerUnisolated(epService, 25000);
            EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "x" });

            unit.Dispose();
            epService.EPAdministrator.DestroyAllStatements();
        }
Ejemplo n.º 8
0
        private void RunAssertionIsolateMultiple(EPServiceProvider epService)
        {
            if (SupportConfigFactory.SkipTest(typeof(ExecClientIsolationUnit)))
            {
                return;
            }

            var fields    = new string[] { "TheString", "sumi" };
            int count     = 4;
            var listeners = new SupportUpdateListener[count];

            for (int i = 0; i < count; i++)
            {
                string epl = "@Name('S" + i + "') select TheString, sum(IntPrimitive) as sumi from SupportBean(TheString='" + i + "')#time(10)";
                listeners[i] = new SupportUpdateListener();
                epService.EPAdministrator.CreateEPL(epl).Events += listeners[i].Update;
            }

            var statements = new EPStatement[2];

            statements[0] = epService.EPAdministrator.GetStatement("S0");
            statements[1] = epService.EPAdministrator.GetStatement("S2");

            EPServiceProviderIsolated unit = epService.GetEPServiceIsolated("i1");

            unit.EPAdministrator.AddStatement(statements);

            // send to unisolated
            for (int i = 0; i < count; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBean(Convert.ToString(i), i));
            }
            Assert.IsFalse(listeners[0].IsInvoked);
            Assert.IsFalse(listeners[2].IsInvoked);
            EPAssertionUtil.AssertProps(listeners[1].AssertOneGetNewAndReset(), fields, new object[] { "1", 1 });
            EPAssertionUtil.AssertProps(listeners[3].AssertOneGetNewAndReset(), fields, new object[] { "3", 3 });

            // send to isolated
            for (int i = 0; i < count; i++)
            {
                unit.EPRuntime.SendEvent(new SupportBean(Convert.ToString(i), i));
            }
            Assert.IsFalse(listeners[1].IsInvoked);
            Assert.IsFalse(listeners[3].IsInvoked);
            EPAssertionUtil.AssertProps(listeners[0].AssertOneGetNewAndReset(), fields, new object[] { "0", 0 });
            EPAssertionUtil.AssertProps(listeners[2].AssertOneGetNewAndReset(), fields, new object[] { "2", 2 });

            unit.EPRuntime.SendEvent(new SupportBean(Convert.ToString(2), 2));
            EPAssertionUtil.AssertProps(listeners[2].AssertOneGetNewAndReset(), fields, new object[] { "2", 4 });

            // return
            unit.EPAdministrator.RemoveStatement(statements);

            // send to unisolated
            for (int i = 0; i < count; i++)
            {
                epService.EPRuntime.SendEvent(new SupportBean(Convert.ToString(i), i));
            }
            EPAssertionUtil.AssertProps(listeners[0].AssertOneGetNewAndReset(), fields, new object[] { "0", 0 });
            EPAssertionUtil.AssertProps(listeners[1].AssertOneGetNewAndReset(), fields, new object[] { "1", 2 });
            EPAssertionUtil.AssertProps(listeners[2].AssertOneGetNewAndReset(), fields, new object[] { "2", 6 });
            EPAssertionUtil.AssertProps(listeners[3].AssertOneGetNewAndReset(), fields, new object[] { "3", 6 });

            // send to isolated
            for (int i = 0; i < count; i++)
            {
                unit.EPRuntime.SendEvent(new SupportBean(Convert.ToString(i), i));
                Assert.IsFalse(listeners[i].IsInvoked);
            }

            unit.Dispose();
            epService.EPAdministrator.DestroyAllStatements();
        }