public void TestOnDemandAndOnSelect() { String[] fields = new String[] { "TheString", "IntPrimitive" } ; _epService.EPAdministrator.CreateEPL( "create window MyWindow.win:keepall() as select * from SupportBean"); _epService.EPAdministrator.CreateEPL( "insert into MyWindow select * from SupportBean"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); _epService.EPRuntime.SendEvent(new SupportBean("E1", 2)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); String query = "select distinct TheString, IntPrimitive from MyWindow order by TheString, IntPrimitive"; EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery( query); EPAssertionUtil.AssertPropsPerRow(result.Array, fields, new Object[][] { new Object[] { "E1", 1 } , new Object[] { "E1", 2 } , new Object[] { "E2", 2 } } ); EPStatement stmt = _epService.EPAdministrator.CreateEPL( "on SupportBean_A select distinct TheString, IntPrimitive from MyWindow order by TheString, IntPrimitive asc"); stmt.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean_A("x")); EPAssertionUtil.AssertPropsPerRow(_listener.LastNewData, fields, new Object[][] { new Object[] { "E1", 1 } , new Object[] { "E1", 2 } , new Object[] { "E2", 2 } } ); }
private void RunAssertionOnDemandAndOnSelect(EPServiceProvider epService) { var fields = new string[] { "TheString", "IntPrimitive" }; 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)); epService.EPRuntime.SendEvent(new SupportBean("E1", 2)); epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); string query = "select distinct TheString, IntPrimitive from MyWindow order by TheString, IntPrimitive"; EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery(query); EPAssertionUtil.AssertPropsPerRow(result.Array, fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E1", 2 }, new object[] { "E2", 2 } }); EPStatement stmt = epService.EPAdministrator.CreateEPL("on SupportBean_A select distinct TheString, IntPrimitive from MyWindow order by TheString, IntPrimitive asc"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_A("x")); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E1", 2 }, new object[] { "E2", 2 } }); stmt.Dispose(); }
public void TestPerfFAFJoin() { _epService.EPAdministrator.CreateEPL("create window W1#unique(s1) as SSB1"); _epService.EPAdministrator.CreateEPL("insert into W1 select * from SSB1"); _epService.EPAdministrator.CreateEPL("create window W2#unique(s2) as SSB2"); _epService.EPAdministrator.CreateEPL("insert into W2 select * from SSB2"); for (int i = 0; i < 1000; i++) { _epService.EPRuntime.SendEvent(new SupportSimpleBeanOne("A" + i, 0, 0, 0)); _epService.EPRuntime.SendEvent(new SupportSimpleBeanTwo("A" + i, 0, 0, 0)); } long start = Environment.TickCount; for (int i = 0; i < 100; i++) { EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery("select * from W1 as w1, W2 as w2 " + "where w1.s1 = w2.s2"); Assert.AreEqual(1000, result.Array.Length); } long end = Environment.TickCount; long delta = end - start; Log.Debug("Delta = {0}", delta); Assert.That(delta, Is.LessThan(1000), "Delta=" + delta); }
private void RunAssertionCreateIndex(bool namedWindow) { string epl = "@Name('create-ctx') create context SegmentedByCustomer " + " initiated by SupportBean_S0 s0 " + " terminated by SupportBean_S1(p00 = p10);" + "" + "@Name('create-infra') context SegmentedByCustomer\n" + (namedWindow ? "create window MyInfra.win:keepall() as SupportBean;" : "create table MyInfra(TheString string primary key, IntPrimitive int);") + "" + (namedWindow ? "@Name('insert-into-window') insert into MyInfra select TheString, IntPrimitive from SupportBean;" : "@Name('insert-into-table') context SegmentedByCustomer insert into MyInfra select TheString, IntPrimitive from SupportBean;") + "" + "@Name('create-index') context SegmentedByCustomer\n" + "create index MyIndex on MyInfra(IntPrimitive);"; DeploymentResult deployed = epService.EPAdministrator.DeploymentAdmin.ParseDeploy(epl); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "A")); epService.EPRuntime.SendEvent(new SupportBean_S0(2, "B")); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery("select * from MyInfra where IntPrimitive = 1", new ContextPartitionSelector[] { new EPContextPartitionAdminImpl.CPSelectorById(1) }); EPAssertionUtil.AssertPropsPerRow(result.Array, "TheString,IntPrimitive".Split(','), new object[][] { new object[] { "E1", 1 } }); epService.EPRuntime.SendEvent(new SupportBean_S1(3, "A")); epService.EPAdministrator.DeploymentAdmin.Undeploy(deployed.DeploymentId); }
private void RunFAFQuery(EPOnDemandPreparedQuery query, int?expectedValue) { EPOnDemandQueryResult result = query.Execute(); Assert.AreEqual(1, result.Array.Length); Assert.AreEqual(expectedValue, result.Array[0].Get("sumi")); }
private void RunQuery(String epl, String fields, Object[][] expected, ContextPartitionSelector[] selectors) { // try FAF without prepare EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery(epl, selectors); EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.Split(','), expected); // test unparameterized prepare and execute EPOnDemandPreparedQuery preparedQuery = _epService.EPRuntime.PrepareQuery(epl); EPOnDemandQueryResult resultPrepared = preparedQuery.Execute(selectors); EPAssertionUtil.AssertPropsPerRowAnyOrder(resultPrepared.Array, fields.Split(','), expected); // test unparameterized prepare and execute EPOnDemandPreparedQueryParameterized preparedParameterizedQuery = _epService.EPRuntime.PrepareQueryWithParameters(epl); EPOnDemandQueryResult resultPreparedParameterized = _epService.EPRuntime.ExecuteQuery(preparedParameterizedQuery, selectors); EPAssertionUtil.AssertPropsPerRowAnyOrder(resultPreparedParameterized.Array, fields.Split(','), expected); // test SODA prepare and execute EPStatementObjectModel modelForPrepare = _epService.EPAdministrator.CompileEPL(epl); EPOnDemandPreparedQuery preparedQueryModel = _epService.EPRuntime.PrepareQuery(modelForPrepare); EPOnDemandQueryResult resultPreparedModel = preparedQueryModel.Execute(selectors); EPAssertionUtil.AssertPropsPerRowAnyOrder(resultPreparedModel.Array, fields.Split(','), expected); // test model query EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(epl); result = _epService.EPRuntime.ExecuteQuery(model, selectors); EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.Split(','), expected); }
public bool Call() { try { long total = 0; for (int loop = 0; loop < _numRepeats; loop++) { // Insert event into named window SendMarketBean(_threadKey, loop); total++; String selectQuery = "select * from MyWindow where TheString='" + _threadKey + "' and LongPrimitive=" + loop; EPOnDemandQueryResult queryResult = _engine.ExecuteQuery(selectQuery); Assert.AreEqual(1, queryResult.Array.Length); Assert.AreEqual(_threadKey, queryResult.Array[0].Get("TheString")); Assert.AreEqual((long)loop, queryResult.Array[0].Get("LongPrimitive")); } } catch (Exception ex) { log.Error("Error in thread " + Thread.CurrentThread.ManagedThreadId, ex); return(false); } return(true); }
public override void Run(EPServiceProvider epService) { epService.EPAdministrator.CreateEPL("create window W1#unique(s1) as SSB1"); epService.EPAdministrator.CreateEPL("insert into W1 select * from SSB1"); epService.EPAdministrator.CreateEPL("create window W2#unique(s2) as SSB2"); epService.EPAdministrator.CreateEPL("insert into W2 select * from SSB2"); for (int i = 0; i < 1000; i++) { epService.EPRuntime.SendEvent(new SupportSimpleBeanOne("A" + i, 0, 0, 0)); epService.EPRuntime.SendEvent(new SupportSimpleBeanTwo("A" + i, 0, 0, 0)); } long start = PerformanceObserver.MilliTime; for (int i = 0; i < 100; i++) { EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery("select * from W1 as w1, W2 as w2 " + "where w1.s1 = w2.s2"); Assert.AreEqual(1000, result.Array.Length); } long end = PerformanceObserver.MilliTime; long delta = end - start; Log.Info("Delta=" + delta); Assert.IsTrue(delta < 1000, "Delta=" + delta); }
private void AssertFAFOneRowResult(EPServiceProvider epService, string epl, string fields, object[] objects) { EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery(epl); Assert.AreEqual(1, result.Array.Length); EPAssertionUtil.AssertProps(result.Array[0], fields.Split(','), objects); }
public void Run() { Log.Info("Started event send for read"); // warmup try { Thread.Sleep(100); } catch (ThreadInterruptedException) { } try { string eplSelect = "select vartotal.cnt as c0, vartotal.sumint as c1, vartotal.avgint as c2 from MyWindow"; while (!_shutdown) { EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery(eplSelect); long count = result.Array[0].Get("c0").AsLong(); int sumint = result.Array[0].Get("c1").AsInt(); double avgint = result.Array[0].Get("c2").AsDouble(); Assert.AreEqual(2d, avgint); Assert.AreEqual(sumint, count * 2); _numQueries++; } } catch (Exception ex) { Log.Error("Exception encountered: " + ex.Message, ex); _exception = ex; } Log.Info("Completed event send for read"); }
private void RunSampleFireAndForgetQuery(EPServiceProvider epService) { String fireAndForget = "select * from MySampleWindow where key1 = 'sample1' and key2 = 'sample2'"; // see values in SampleVirtualDataWindowIndex EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery(fireAndForget); Log.Info("Fire-and-forget query returned: " + result.Array[0].Get("key1") + " and " + result.Array[0].Get("key2")); // For assertions against expected results please see the regression test suite }
public void TestFAFSelect() { string[] fields = "p0".Split(','); _epService.EPAdministrator.CreateEPL("@Name('TheTable') create table MyTable as (p0 string primary key, thesum sum(int))"); _epService.EPAdministrator.CreateEPL("into table MyTable select TheString, sum(IntPrimitive) as thesum from SupportBean group by TheString"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery("select * from MyTable"); EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields, new object[][] { new object[] { "E1" }, new object[] { "E2" } }); }
public void TestFAFUpdate() { string[] fields = "p0,p1".Split(','); _epService.EPAdministrator.CreateEPL("@Name('TheTable') create table MyTable as (p0 string primary key, p1 string, thesum sum(int))"); _epService.EPAdministrator.CreateEPL("into table MyTable select TheString, sum(IntPrimitive) as thesum from SupportBean group by TheString"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery("update MyTable set p1 = 'ABC'"); EPAssertionUtil.AssertPropsPerRowAnyOrder(_epService.EPAdministrator.GetStatement("TheTable").GetEnumerator(), fields, new object[][] { new object[] { "E1", "ABC" }, new object[] { "E2", "ABC" } }); }
public void TestFAFInsert() { string[] propertyNames = "p0,p1".Split(','); EPStatement stmt = _epService.EPAdministrator.CreateEPL("create table MyTable as (p0 string, p1 int)"); string eplInsertInto = "insert into MyTable (p0, p1) select 'a', 1"; EPOnDemandQueryResult resultOne = _epService.EPRuntime.ExecuteQuery(eplInsertInto); AssertFAFInsertResult(resultOne, propertyNames, stmt); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), propertyNames, new object[][] { new object[] { "a", 1 } }); }
private void RunAssertionFireAndForgetInsertUpdateDelete(object[][] expectedType) { EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery("insert into MyTable(key) values ('dummy')"); AssertEventType(result.EventType, expectedType); result = _epService.EPRuntime.ExecuteQuery("delete from MyTable where key = 'dummy'"); AssertEventType(result.EventType, expectedType); result = _epService.EPRuntime.ExecuteQuery("update MyTable set key='dummy' where key='dummy'"); AssertEventType(result.EventType, expectedType); }
private void RunQueryAll(String epl, String fields, Object[][] expected, int numStreams) { ContextPartitionSelector[] selectors = new ContextPartitionSelector[numStreams]; for (int i = 0; i < numStreams; i++) { selectors[i] = ContextPartitionSelectorAll.INSTANCE; } RunQuery(epl, fields, expected, selectors); // run same query without selector EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery(epl); EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.Split(','), expected); }
private void RunAssertionFAFKeyAndRangePerformance(EPServiceProvider epService, bool namedWindow) { // create window one string eplCreate = namedWindow ? "create window MyInfraFAFKR#keepall as SupportBean" : "create table MyInfraFAFKR (TheString string primary key, IntPrimitive int primary key)"; epService.EPAdministrator.CreateEPL(eplCreate); epService.EPAdministrator.CreateEPL("insert into MyInfraFAFKR select TheString, IntPrimitive from SupportBean"); epService.EPAdministrator.CreateEPL("create index idx1 on MyInfraFAFKR(TheString hash, IntPrimitive btree)"); // insert X rows int maxRows = 10000; //for performance testing change to int maxRows = 100000; for (int i = 0; i < maxRows; i++) { epService.EPRuntime.SendEvent(new SupportBean("A", i)); } RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive not in [3:9997]", 1 + 2 + 9998 + 9999); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive not in [3:9997)", 1 + 2 + 9997 + 9998 + 9999); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive not in (3:9997]", 1 + 2 + 3 + 9998 + 9999); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive not in (3:9997)", 1 + 2 + 3 + 9997 + 9998 + 9999); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'B' and IntPrimitive not in (3:9997)", null); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive between 200 and 202", 603); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive between 202 and 199", 199 + 200 + 201 + 202); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive >= 200 and IntPrimitive <= 202", 603); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive >= 202 and IntPrimitive <= 200", null); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive > 9997", 9998 + 9999); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive >= 9997", 9997 + 9998 + 9999); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive < 5", 4 + 3 + 2 + 1); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive <= 5", 5 + 4 + 3 + 2 + 1); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive in [200:202]", 603); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive in [200:202)", 401); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive in (200:202]", 403); RunFAFAssertion(epService, "select sum(IntPrimitive) as sumi from MyInfraFAFKR where TheString = 'A' and IntPrimitive in (200:202)", 201); // test no value returned EPOnDemandPreparedQuery query = epService.EPRuntime.PrepareQuery("select * from MyInfraFAFKR where TheString = 'A' and IntPrimitive < 0"); EPOnDemandQueryResult result = query.Execute(); Assert.AreEqual(0, result.Array.Length); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MyInfraFAFKR", false); }
public void TestRevision() { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType("SupportBean_S0", typeof(SupportBean_S0)); config.AddEventType("SupportBean_S1", typeof(SupportBean_S1)); ConfigurationRevisionEventType revType = new ConfigurationRevisionEventType(); revType.AddNameBaseEventType("SupportBean_S0"); revType.AddNameDeltaEventType("SupportBean_S1"); revType.KeyPropertyNames = new string[] { "Id" }; revType.PropertyRevision = PropertyRevisionEnum.MERGE_EXISTS; config.AddRevisionEventType("RevType", revType); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, this.GetType(), GetType().FullName); } // widen to long string stmtTextCreate = "create window MyWindowOne.win:keepall() as select * from RevType"; epService.EPAdministrator.CreateEPL(stmtTextCreate); epService.EPAdministrator.CreateEPL("insert into MyWindowOne select * from SupportBean_S0"); epService.EPAdministrator.CreateEPL("insert into MyWindowOne select * from SupportBean_S1"); epService.EPAdministrator.CreateEPL("create index MyWindowOneIndex1 on MyWindowOne(P10)"); epService.EPAdministrator.CreateEPL("create index MyWindowOneIndex2 on MyWindowOne(P00)"); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "P00")); epService.EPRuntime.SendEvent(new SupportBean_S1(1, "P10")); EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery("select * from MyWindowOne where P10='1'"); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
private void RunAssertionFireAndForget(EPServiceProvider epService) { SupportVirtualDW window = RegisterTypeSetMapData(epService); // test no-criteria FAF EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery("select col1 from MyVDW vdw"); AssertIndexSpec(window.LastRequestedIndex, "", ""); Assert.AreEqual("MyVDW", window.LastRequestedIndex.NamedWindowName); Assert.AreEqual(-1, window.LastRequestedIndex.StatementId); Assert.IsNull(window.LastRequestedIndex.StatementName); Assert.IsNotNull(window.LastRequestedIndex.StatementAnnotations); Assert.IsTrue(window.LastRequestedIndex.IsFireAndForget); EPAssertionUtil.AssertProps(result.Array[0], "col1".Split(','), new object[] { "key1" }); EPAssertionUtil.AssertEqualsExactOrder(new Object[0], window.LastAccessKeys); // test single-criteria FAF result = epService.EPRuntime.ExecuteQuery("select col1 from MyVDW vdw where col1='key1'"); AssertIndexSpec(window.LastRequestedIndex, "col1=(System.String)", ""); EPAssertionUtil.AssertProps(result.Array[0], "col1".Split(','), new object[] { "key1" }); EPAssertionUtil.AssertEqualsExactOrder(new object[] { "key1" }, window.LastAccessKeys); // test multi-criteria subquery result = epService.EPRuntime.ExecuteQuery("select col1 from MyVDW vdw where col1='key1' and col2='key2' and col3 between 5 and 15"); AssertIndexSpec(window.LastRequestedIndex, "col1=(System.String)|col2=(System.String)", "col3[,](" + Name.Clean <double>(false) + ")"); EPAssertionUtil.AssertProps(result.Array[0], "col1".Split(','), new object[] { "key1" }); EPAssertionUtil.AssertEqualsAnyOrder(new object[] { "key1", "key2", new VirtualDataWindowKeyRange(5d, 15d) }, window.LastAccessKeys); // test multi-criteria subquery result = epService.EPRuntime.ExecuteQuery("select col1 from MyVDW vdw where col1='key1' and col2>'key0' and col3 between 5 and 15"); AssertIndexSpec(window.LastRequestedIndex, "col1=(System.String)", "col3[,](" + Name.Clean <double>(false) + ")|col2>(System.String)"); EPAssertionUtil.AssertProps(result.Array[0], "col1".Split(','), new object[] { "key1" }); EPAssertionUtil.AssertEqualsAnyOrder(new object[] { "key1", new VirtualDataWindowKeyRange(5d, 15d), "key0" }, window.LastAccessKeys); DestroyStmtsRemoveTypes(epService); }
private void RunAssertionFAFCarEventAndGroupingFunc(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType(typeof(CarEvent)); epService.EPAdministrator.CreateEPL("create window CarWindow#keepall as CarEvent"); epService.EPAdministrator.CreateEPL("insert into CarWindow select * from CarEvent"); epService.EPRuntime.SendEvent(new CarEvent("skoda", "france", 10000)); epService.EPRuntime.SendEvent(new CarEvent("skoda", "germany", 5000)); epService.EPRuntime.SendEvent(new CarEvent("bmw", "france", 100)); epService.EPRuntime.SendEvent(new CarEvent("bmw", "germany", 1000)); epService.EPRuntime.SendEvent(new CarEvent("opel", "france", 7000)); epService.EPRuntime.SendEvent(new CarEvent("opel", "germany", 7000)); string epl = "select name, place, sum(count), grouping(name), grouping(place), grouping_id(name, place) as gid " + "from CarWindow group by grouping sets((name, place),name, place,())"; EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery(epl); Assert.AreEqual(typeof(int?), result.EventType.GetPropertyType("grouping(name)").GetBoxedType()); Assert.AreEqual(typeof(int?), result.EventType.GetPropertyType("gid").GetBoxedType()); var fields = new string[] { "name", "place", "sum(count)", "grouping(name)", "grouping(place)", "gid" }; EPAssertionUtil.AssertPropsPerRow(result.Array, fields, new object[][] { new object[] { "skoda", "france", 10000, 0, 0, 0 }, new object[] { "skoda", "germany", 5000, 0, 0, 0 }, new object[] { "bmw", "france", 100, 0, 0, 0 }, new object[] { "bmw", "germany", 1000, 0, 0, 0 }, new object[] { "opel", "france", 7000, 0, 0, 0 }, new object[] { "opel", "germany", 7000, 0, 0, 0 }, new object[] { "skoda", null, 15000, 0, 1, 1 }, new object[] { "bmw", null, 1100, 0, 1, 1 }, new object[] { "opel", null, 14000, 0, 1, 1 }, new object[] { null, "france", 17100, 1, 0, 2 }, new object[] { null, "germany", 13000, 1, 0, 2 }, new object[] { null, null, 30100, 1, 1, 3 } }); epService.EPAdministrator.DestroyAllStatements(); }
public void TestIntoTableWindowSortedFromJoin() { epService.EPAdministrator.CreateEPL("create table MyTable(" + "thewin window(*) @type('SupportBean')," + "thesort sorted(IntPrimitive desc) @type('SupportBean')" + ")"); epService.EPAdministrator.CreateEPL("into table MyTable " + "select window(sb.*) as thewin, sorted(sb.*) as thesort " + "from SupportBean_S0#lastevent, SupportBean#keepall as sb"); epService.EPRuntime.SendEvent(new SupportBean_S0(1)); SupportBean sb1 = new SupportBean("E1", 1); epService.EPRuntime.SendEvent(sb1); SupportBean sb2 = new SupportBean("E2", 2); epService.EPRuntime.SendEvent(sb2); EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery("select * from MyTable"); EPAssertionUtil.AssertPropsPerRow(result.Array, "thewin,thesort".Split(','), new object[][] { new object[] { new SupportBean[] { sb1, sb2 }, new SupportBean[] { sb2, sb1 } } }); }
private void TryNWQuery(int numRows) { EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery("select * from MyWindow"); Assert.AreEqual(numRows, result.Array.Length); }
private void RunAssertionFireAndForgetSelectStar(object[][] expectedType, object[] rowValues) { EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery("select * from MyTable where key = 'G1'"); AssertEventTypeAndEvent(result.EventType, expectedType, result.Array[0].Underlying, rowValues); }
private void AssertValuesIterate(EPServiceProvider epService, string name, string[] fields, object[][] objects) { EPOnDemandQueryResult result = epService.EPRuntime.ExecuteQuery("select * from " + name); EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields, objects); }
private void AssertFAFInsertResult(EPOnDemandQueryResult resultOne, string[] propertyNames, EPStatement stmt) { Assert.AreEqual(0, resultOne.Array.Length); Assert.AreSame(resultOne.EventType, stmt.EventType); }
public void RunExample(bool isRunFromUnitTest, string engineURI) { int numEventsToLoad = 100000; int numFireAndForgetExecutions = 100; int numOnEventQueryExecutions = 100000; if (isRunFromUnitTest) { numEventsToLoad = 1000; numFireAndForgetExecutions = 5; numOnEventQueryExecutions = 5; } EPServiceProvider epService = EPServiceProviderManager.GetProvider(engineURI); // This example initializes the engine instance as it is running within an overall test suite. // This step would not be required unless re-using the same engine instance with different configurations. epService.Initialize(); // define event type - this example uses Map event representation // IDictionary <String, Object> definition = new LinkedHashMap <String, Object>(); definition.Put("sensor", typeof(string)); definition.Put("temperature", typeof(double)); epService.EPAdministrator.Configuration.AddEventType("SensorEvent", definition); // define a named window to hold the last 1000000 (1M) events // String stmtText = "create window SensorWindow.win:keepall() as select * from SensorEvent"; Log.Info("Creating named window : " + stmtText); epService.EPAdministrator.CreateEPL(stmtText); stmtText = "insert into SensorWindow select * from SensorEvent"; Log.Info("Creating insert statement for named window : " + stmtText); epService.EPAdministrator.CreateEPL(stmtText); // load 1M events // var random = new Random(); String[] sensors = "s1,s2,s3,s4,s5,s6".Split(','); Log.Info("Generating " + numEventsToLoad + " sensor events for the named window"); IList <IDictionary <String, Object> > events = new List <IDictionary <String, Object> >(); for (int i = 0; i < numEventsToLoad; i++) { double temperature = Math.Round(random.NextDouble() * 10, 5, MidpointRounding.AwayFromZero) + 80; String sensor = sensors[random.Next(sensors.Length)]; IDictionary <String, Object> data = new LinkedHashMap <String, Object>(); data.Put("temperature", temperature); data.Put("sensor", sensor); events.Add(data); } Log.Info("Completed generating sensor events"); Log.Info("Sending " + events.Count + " sensor events into engine"); foreach (var @event in events) { epService.EPRuntime.SendEvent(@event, "SensorEvent"); } Log.Info("Completed sending sensor events"); // prepare on-demand query // var sampleTemperature = (double)events[0].Get("temperature"); stmtText = "select * from SensorWindow where temperature = " + sampleTemperature; Log.Info("Preparing fire-and-forget query : " + stmtText); EPOnDemandPreparedQuery onDemandQuery = epService.EPRuntime.PrepareQuery(stmtText); Log.Info("Executing fire-and-forget query " + numFireAndForgetExecutions + " times"); long startTime = Environment.TickCount; for (int i = 0; i < numFireAndForgetExecutions; i++) { EPOnDemandQueryResult result = onDemandQuery.Execute(); if (result.Array.Length != 1) { throw new ApplicationException( "Failed assertion of result, expected a single row returned from query"); } } long endTime = Environment.TickCount; double deltaSec = (endTime - startTime) / 1000.0; Log.Info("Executing fire-and-forget query " + numFireAndForgetExecutions + " times took " + deltaSec + " seconds"); // prepare on-select // IDictionary <String, Object> definitionQuery = new LinkedHashMap <String, Object>(); definitionQuery.Put("querytemp", typeof(double)); epService.EPAdministrator.Configuration.AddEventType("SensorQueryEvent", definitionQuery); stmtText = "on SensorQueryEvent select sensor from SensorWindow where temperature = querytemp"; Log.Info("Creating on-select statement for named window : " + stmtText); EPStatement onSelectStmt = epService.EPAdministrator.CreateEPL(stmtText); onSelectStmt.Subscriber = this; Log.Info("Executing on-select query " + numOnEventQueryExecutions + " times"); startTime = Environment.TickCount; for (int i = 0; i < numOnEventQueryExecutions; i++) { IDictionary <String, Object> queryParams = new Dictionary <String, Object>(); queryParams.Put("querytemp", sampleTemperature); epService.EPRuntime.SendEvent(queryParams, "SensorQueryEvent"); } endTime = Environment.TickCount; deltaSec = (endTime - startTime) / 1000.0; Log.Info("Executing on-select query " + numOnEventQueryExecutions + " times took " + deltaSec + " seconds"); }
private void RunAssertionFAFKeyPerformance(EPServiceProvider epService, bool namedWindow) { // create window one string stmtTextCreateOne = namedWindow ? "create window MyInfraOne#keepall as (f1 string, f2 int)" : "create table MyInfraOne (f1 string primary key, f2 int primary key)"; epService.EPAdministrator.CreateEPL(stmtTextCreateOne); epService.EPAdministrator.CreateEPL("insert into MyInfraOne(f1, f2) select TheString, IntPrimitive from SupportBean"); epService.EPAdministrator.CreateEPL("create index MyInfraOneIndex on MyInfraOne(f1)"); // insert X rows int maxRows = 100; //for performance testing change to int maxRows = 100000; for (int i = 0; i < maxRows; i++) { epService.EPRuntime.SendEvent(new SupportBean("K" + i, i)); } // fire N queries each returning 1 row long start = PerformanceObserver.MilliTime; string queryText = "select * from MyInfraOne where f1='K10'"; EPOnDemandPreparedQuery query = epService.EPRuntime.PrepareQuery(queryText); int loops = 10000; for (int i = 0; i < loops; i++) { EPOnDemandQueryResult resultX = query.Execute(); Assert.AreEqual(1, resultX.Array.Length); Assert.AreEqual("K10", resultX.Array[0].Get("f1")); } long end = PerformanceObserver.MilliTime; long delta = end - start; Assert.IsTrue(delta < 500, "delta=" + delta); // test no value returned queryText = "select * from MyInfraOne where f1='KX'"; query = epService.EPRuntime.PrepareQuery(queryText); EPOnDemandQueryResult result = query.Execute(); Assert.AreEqual(0, result.Array.Length); // test query null queryText = "select * from MyInfraOne where f1=null"; query = epService.EPRuntime.PrepareQuery(queryText); result = query.Execute(); Assert.AreEqual(0, result.Array.Length); // insert null and test null epService.EPRuntime.SendEvent(new SupportBean(null, -2)); result = query.Execute(); Assert.AreEqual(0, result.Array.Length); // test two values epService.EPRuntime.SendEvent(new SupportBean(null, -1)); query = epService.EPRuntime.PrepareQuery("select * from MyInfraOne where f1 is null order by f2 asc"); result = query.Execute(); Assert.AreEqual(2, result.Array.Length); Assert.AreEqual(-2, result.Array[0].Get("f2")); Assert.AreEqual(-1, result.Array[1].Get("f2")); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MyInfraOne", false); }