public void TestViewComputedValues() { // Set up feed for sum view SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 3); stream.AddView(_myView); // Send a first event, checkNew values EventBean marketData = MakeBean("IBM", 70, 1000); stream.Insert(marketData); CheckOld(Double.NaN); CheckNew(Double.NaN); // Send a second event, checkNew values marketData = MakeBean("IBM", 70.5, 1500); stream.Insert(marketData); CheckOld(Double.NaN); CheckNew(1); // Send a third event, checkNew values marketData = MakeBean("IBM", 70.1, 1200); stream.Insert(marketData); CheckOld(1); CheckNew(0.97622104); // Send a 4th event, this time the first event should be gone, checkNew values marketData = MakeBean("IBM", 70.25, 1000); stream.Insert(marketData); CheckOld(0.97622104); CheckNew(0.70463404); }
public void TestUpdate() { // Set up a feed for the view under test - it will have a depth of 3 trades var stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 3); stream.AddView(_myGroupByView); // Send old a new events var newEvents = new EventBean[] { MakeTradeBean("IBM", 70), MakeTradeBean("GE", 10) }; var oldEvents = new EventBean[] { MakeTradeBean("IBM", 65), MakeTradeBean("GE", 9) }; _myGroupByView.Update(newEvents, oldEvents); Assert.AreEqual(2, SupportBeanClassView.Instances.Count); var child_1 = SupportBeanClassView.Instances[0]; var child_2 = SupportBeanClassView.Instances[1]; SupportViewDataChecker.CheckOldData(child_1, new EventBean[] { oldEvents[0] }); SupportViewDataChecker.CheckNewData(child_1, new EventBean[] { newEvents[0] }); SupportViewDataChecker.CheckOldData(child_2, new EventBean[] { oldEvents[1] }); SupportViewDataChecker.CheckNewData(child_2, new EventBean[] { newEvents[1] }); newEvents = new EventBean[] { MakeTradeBean("IBM", 71), MakeTradeBean("GE", 11) }; oldEvents = new EventBean[] { MakeTradeBean("IBM", 70), MakeTradeBean("GE", 10) }; _myGroupByView.Update(newEvents, oldEvents); SupportViewDataChecker.CheckOldData(child_1, new EventBean[] { oldEvents[0] }); SupportViewDataChecker.CheckNewData(child_1, new EventBean[] { newEvents[0] }); SupportViewDataChecker.CheckOldData(child_2, new EventBean[] { oldEvents[1] }); SupportViewDataChecker.CheckNewData(child_2, new EventBean[] { newEvents[1] }); }
public void TestViewComputedValues() { // Set up feed for sum view SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 3); stream.AddView(_myView); // Send a first event, checkNew values EventBean marketData = MakeBean("IBM", 70, 1000); stream.Insert(marketData); CheckOld(Double.NaN, Double.NaN); CheckNew(Double.NaN, Double.NaN); // Send a second event, checkNew values marketData = MakeBean("IBM", 70.5, 1500); stream.Insert(marketData); CheckOld(Double.NaN, Double.NaN); CheckNew(1000, -69000); // Send a third event, checkNew values marketData = MakeBean("IBM", 70.1, 1200); stream.Insert(marketData); CheckOld(1000, -69000); CheckNew(928.5714286, -63952.380953); // Send a 4th event, this time the first event should be gone, checkNew values marketData = MakeBean("IBM", 70.25, 1000); stream.Insert(marketData); CheckOld(928.5714286, -63952.380953); CheckNew(877.5510204, -60443.877555); }
public void TestMakeSubviews() { EventStream eventStream = new SupportStreamImpl(typeof(SupportMarketDataBean), 4); var expressions = SupportExprNodeFactory.MakeIdentNodesMD("Symbol"); GroupByView groupView = new GroupByViewImpl(_agentInstanceContext, expressions, ExprNodeUtility.GetEvaluators(expressions)); eventStream.AddView(groupView); var groupByValue = new Object[] { "IBM" }; // Invalid for no child nodes try { GroupByViewImpl.MakeSubViews(groupView, "Symbol".Split(','), groupByValue, _agentInstanceContext); Assert.IsTrue(false); } catch (EPException) { // Expected exception } // Invalid for child node is a merge node - doesn't make sense to group and merge only var mergeViewOne = new MergeView(_agentInstanceContext, SupportExprNodeFactory.MakeIdentNodesMD("Symbol"), null, false); groupView.AddView(mergeViewOne); try { GroupByViewImpl.MakeSubViews(groupView, "Symbol".Split(','), groupByValue, _agentInstanceContext); Assert.IsTrue(false); } catch (EPException) { // Expected exception } // Add a size view parent of merge view groupView = new GroupByViewImpl(_agentInstanceContext, expressions, ExprNodeUtility.GetEvaluators(expressions)); var firstElementView_1 = new FirstElementView(null); groupView.AddView(firstElementView_1); groupView.Parent = eventStream; mergeViewOne = new MergeView(_agentInstanceContext, SupportExprNodeFactory.MakeIdentNodesMD("Symbol"), null, false); firstElementView_1.AddView(mergeViewOne); var subViews = GroupByViewImpl.MakeSubViews(groupView, "Symbol".Split(','), groupByValue, _agentInstanceContext); Assert.IsTrue(subViews is FirstElementView); Assert.IsTrue(subViews != firstElementView_1); var firstEleView = (FirstElementView)subViews; Assert.AreEqual(1, firstEleView.Views.Length); Assert.IsTrue(firstEleView.Views[0] is AddPropertyValueView); var md = (AddPropertyValueView)firstEleView.Views[0]; Assert.AreEqual(1, md.Views.Length); Assert.IsTrue(md.Views[0] == mergeViewOne); }
public void TestViewPush() { // Reset instance lists of child views SupportBeanClassView.Instances.Clear(); SupportMapView.Instances.Clear(); // Set up a feed for the view under test - it will have a depth of 3 trades var stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 3); stream.AddView(_myGroupByView); var tradeBeans = new EventBean[10]; // Send an IBM symbol event tradeBeans[0] = MakeTradeBean("IBM", 70); stream.Insert(tradeBeans[0]); // Expect 1 new beanclass view instance and check its data Assert.AreEqual(1, SupportBeanClassView.Instances.Count); var child_1 = SupportBeanClassView.Instances[0]; SupportViewDataChecker.CheckOldData(child_1, null); SupportViewDataChecker.CheckNewData(child_1, new EventBean[] { tradeBeans[0] }); // Check the data of the ultimate receiver SupportViewDataChecker.CheckOldData(_ultimateChildView, null); SupportViewDataChecker.CheckNewData(_ultimateChildView, new EventBean[] { tradeBeans[0] }); }
public void TestViewComputedValues() { // Set up feed for sum view SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 3); stream.AddView(_myView); // Send a first event, check values EventBean marketData = MakeBean("IBM", 10, 1000); stream.Insert(marketData); CheckOld(Double.NaN); CheckNew(10); // Send a second event, check values marketData = MakeBean("IBM", 11, 2000); stream.Insert(marketData); CheckOld(10); CheckNew(10.66666667); // Send a third event, check values marketData = MakeBean("IBM", 10.5, 1500); stream.Insert(marketData); CheckOld(10.66666667); CheckNew(10.61111111); // Send a 4th event, this time the first event should be gone marketData = MakeBean("IBM", 9.5, 600); stream.Insert(marketData); CheckOld(10.61111111); CheckNew(10.59756098); }
public void TestViewComputedValues() { // Set up feed for sum view var stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 3); stream.AddView(_myView); // Send two events to the stream Assert.IsTrue(_childView.LastNewData == null); // Send a first event, checkNew values var marketData = MakeBean("IBM", 10, 0); stream.Insert(marketData); CheckOld(0, 0, Double.NaN, Double.NaN, Double.NaN, Double.NaN); CheckNew(1, 10, 10, 0, Double.NaN, Double.NaN); // Send a second event, checkNew values marketData = MakeBean("IBM", 12, 0); stream.Insert(marketData); CheckOld(1, 10, 10, 0, Double.NaN, Double.NaN); CheckNew(2, 22, 11, 1, Math.Sqrt(2.0), 2); // Send a third event, checkNew values marketData = MakeBean("IBM", 9.5, 0); stream.Insert(marketData); CheckOld(2, 22, 11, 1, Math.Sqrt(2.0), 2); CheckNew(3, 31.5, 10.5, 1.08012345, 1.322875656, 1.75); // Send a 4th event, this time the first event should be gone, checkNew values marketData = MakeBean("IBM", 9, 0); stream.Insert(marketData); CheckOld(3, 31.5, 10.5, 1.08012345, 1.322875656, 1.75); CheckNew(3, 30.5, 10.16666667, 1.312334646, 1.607275127, 2.583333333); }
public void TestViewTwoProperties() { // Set up a sort windows that sorts on two properties ExprNode[] expressions = SupportExprNodeFactory.MakeIdentNodesMD("Volume", "Price"); _myView = new SortWindowView(new SortWindowViewFactory(), expressions, ExprNodeUtility.GetEvaluators(expressions), new bool[] { false, true }, 5, null, false, null); _childView = new SupportBeanClassView(typeof(SupportMarketDataBean)); _myView.AddView(_childView); // Set up a feed for the view under test - the depth is 10 events so bean[10] will cause bean[0] to go old SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 10); stream.AddView(_myView); EventBean[] bean = new EventBean[12]; bean[0] = MakeBean(20d, 1000); stream.Insert(bean[0]); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[0] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[0] }, _myView.GetEnumerator()); bean[1] = MakeBean(19d, 800); bean[2] = MakeBean(18d, 1200); stream.Insert(new EventBean[] { bean[1], bean[2] }); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[1], bean[2] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[1], bean[0], bean[2] }, _myView.GetEnumerator()); bean[3] = MakeBean(17d, 1200); bean[4] = MakeBean(16d, 1000); bean[5] = MakeBean(15d, 1400); bean[6] = MakeBean(14d, 1100); stream.Insert(new EventBean[] { bean[3], bean[4], bean[5], bean[6] }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { bean[5], bean[3] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[3], bean[4], bean[5], bean[6] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[1], bean[0], bean[4], bean[6], bean[2] }, _myView.GetEnumerator()); bean[7] = MakeBean(13d, 800); bean[8] = MakeBean(12d, 700); bean[9] = MakeBean(11d, 1200); stream.Insert(new EventBean[] { bean[7], bean[8], bean[9] }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { bean[9], bean[2], bean[6] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[7], bean[8], bean[9] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[8], bean[1], bean[7], bean[0], bean[4] }, _myView.GetEnumerator()); bean[10] = MakeBean(10d, 1050); stream.Insert(new EventBean[] { bean[10] }); // Thus bean[0] will be old data ! SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { bean[0] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[10] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[8], bean[1], bean[7], bean[4], bean[10] }, _myView.GetEnumerator()); bean[11] = MakeBean(2000); stream.Insert(new EventBean[] { bean[11] }); // Thus bean[1] will be old data ! SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { bean[1] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[11] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[8], bean[7], bean[4], bean[10], bean[11] }, _myView.GetEnumerator()); }
public void TestViewOneProperty() { // Set up a feed for the view under test - the depth is 10 events so bean[10] will cause bean[0] to go old SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 10); stream.AddView(_myView); EventBean[] bean = new EventBean[12]; bean[0] = MakeBean(1000); stream.Insert(bean[0]); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[0] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[0] }, _myView.GetEnumerator()); bean[1] = MakeBean(800); bean[2] = MakeBean(1200); stream.Insert(new EventBean[] { bean[1], bean[2] }); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[1], bean[2] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[1], bean[0], bean[2] }, _myView.GetEnumerator()); bean[3] = MakeBean(1200); bean[4] = MakeBean(1000); bean[5] = MakeBean(1400); bean[6] = MakeBean(1100); stream.Insert(new EventBean[] { bean[3], bean[4], bean[5], bean[6] }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { bean[5], bean[2] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[3], bean[4], bean[5], bean[6] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[1], bean[4], bean[0], bean[6], bean[3] }, _myView.GetEnumerator()); bean[7] = MakeBean(800); bean[8] = MakeBean(700); bean[9] = MakeBean(1200); stream.Insert(new EventBean[] { bean[7], bean[8], bean[9] }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { bean[3], bean[9], bean[6] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[7], bean[8], bean[9] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[8], bean[7], bean[1], bean[4], bean[0] }, _myView.GetEnumerator()); bean[10] = MakeBean(1050); stream.Insert(new EventBean[] { bean[10] }); // Thus bean[0] will be old data ! SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { bean[0] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[10] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[8], bean[7], bean[1], bean[4], bean[10] }, _myView.GetEnumerator()); bean[11] = MakeBean(2000); stream.Insert(new EventBean[] { bean[11] }); // Thus bean[1] will be old data ! SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { bean[1] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { bean[11] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { bean[8], bean[7], bean[4], bean[10], bean[11] }, _myView.GetEnumerator()); }
public void TestViewPush() { // Set up a feed for the view under test - it will have a depth of 3 trades SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 3); stream.AddView(_myView); EventBean[] tradeBeans = new EventBean[10]; // Send some events tradeBeans[0] = MakeTradeBean("IBM", 70); stream.Insert(tradeBeans[0]); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { tradeBeans[0] }, _myView.GetEnumerator()); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { tradeBeans[0] }); // Send 2 more events tradeBeans[1] = MakeTradeBean("IBM", 75); tradeBeans[2] = MakeTradeBean("CSCO", 100); stream.Insert(new EventBean[] { tradeBeans[1], tradeBeans[2] }); EPAssertionUtil.AssertEqualsAnyOrder(new EventBean[] { tradeBeans[1], tradeBeans[2] }, _myView.ToArray()); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { tradeBeans[0] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { tradeBeans[1], tradeBeans[2] }); // And 1 more events tradeBeans[3] = MakeTradeBean("CSCO", 99); stream.Insert(new EventBean[] { tradeBeans[3] }); EPAssertionUtil.AssertEqualsAnyOrder(new EventBean[] { tradeBeans[1], tradeBeans[3] }, _myView.ToArray()); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { tradeBeans[2] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { tradeBeans[3] }); // And 3 more events, that throws CSCO out as the stream size was 3 tradeBeans[4] = MakeTradeBean("MSFT", 55); tradeBeans[5] = MakeTradeBean("IBM", 77); tradeBeans[6] = MakeTradeBean("IBM", 78); stream.Insert(new EventBean[] { tradeBeans[4], tradeBeans[5], tradeBeans[6] }); EPAssertionUtil.AssertEqualsAnyOrder(new EventBean[] { tradeBeans[6], tradeBeans[4] }, _myView.ToArray()); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { tradeBeans[1], tradeBeans[5], tradeBeans[3] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { tradeBeans[4], tradeBeans[5], tradeBeans[6] }); // Yes the event is both in old and new data // Post as old data an event --> unique event is thrown away and posted as old data _myView.Update(null, new EventBean[] { tradeBeans[6] }); EPAssertionUtil.AssertEqualsAnyOrder(new EventBean[] { tradeBeans[4] }, _myView.ToArray()); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { tradeBeans[6] }); SupportViewDataChecker.CheckNewData(_childView, null); }
public void TestViewPush() { // Set up a feed for the view under test - it will have a depth of 5 trades SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportBean_A), 5); stream.AddView(_myView); CheckIterator(0); // View just counts the number of events received, removing those removed in the prior view as old data stream.Insert(MakeBeans("a", 1)); CheckOldData(0); CheckNewData(1); CheckIterator(1); stream.Insert(MakeBeans("b", 2)); CheckOldData(1); CheckNewData(3); CheckIterator(3); // The EventStream has a depth of 3, it will expire the first message now, ie. will keep the size of 3, always stream.Insert(MakeBeans("c", 1)); CheckOldData(3); CheckNewData(4); CheckIterator(4); stream.Insert(MakeBeans("d", 1)); CheckOldData(4); CheckNewData(5); CheckIterator(5); stream.Insert(MakeBeans("e", 2)); Assert.IsNull(_childView.LastNewData); Assert.IsNull(_childView.LastOldData); CheckIterator(5); stream.Insert(MakeBeans("f", 1)); Assert.IsNull(_childView.LastNewData); Assert.IsNull(_childView.LastOldData); CheckIterator(5); }
public void TestViewPush() { // Set up a feed for the view under test - it will have a depth of 3 trades SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportBean_A), 3); stream.AddView(_myView); IDictionary <String, EventBean> events = EventFactoryHelper.MakeEventMap( new String[] { "a0", "a1", "b0", "c0", "c1", "c2", "d0", "e0" }); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, null); EPAssertionUtil.AssertEqualsExactOrder(null, _myView.GetEnumerator()); // View should keep the last element for iteration, should report new data as it arrives stream.Insert(new EventBean[] { events.Get("a0"), events.Get("a1") }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { events.Get("a0") }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { events.Get("a0"), events.Get("a1") }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { events.Get("a1") }, _myView.GetEnumerator()); stream.Insert(new EventBean[] { events.Get("b0") }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { events.Get("a1") }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { events.Get("b0") }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { events.Get("b0") }, _myView.GetEnumerator()); stream.Insert(new EventBean[] { events.Get("c0"), events.Get("c1"), events.Get("c2") }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { events.Get("b0"), events.Get("c0"), events.Get("c1") }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { events.Get("c0"), events.Get("c1"), events.Get("c2") }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { events.Get("c2") }, _myView.GetEnumerator()); stream.Insert(new EventBean[] { events.Get("d0") }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { events.Get("c2") }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { events.Get("d0") }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { events.Get("d0") }, _myView.GetEnumerator()); stream.Insert(new EventBean[] { events.Get("e0") }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { events.Get("d0") }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { events.Get("e0") }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { events.Get("e0") }, _myView.GetEnumerator()); }
public void TestViewPush() { var stream = new SupportStreamImpl(typeof(SupportMarketDataBean), 2); stream.AddView(_myView); var tradeBeans = new EventBean[10]; // Send events, expect just forwarded tradeBeans[0] = MakeTradeBean("IBM", 70); stream.Insert(tradeBeans[0]); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { tradeBeans[0] }); // Send some more events, expect forwarded tradeBeans[1] = MakeTradeBean("GE", 90); tradeBeans[2] = MakeTradeBean("CSCO", 20); stream.Insert(new EventBean[] { tradeBeans[1], tradeBeans[2] }); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { tradeBeans[0] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { tradeBeans[1], tradeBeans[2] }); }
public void TestViewPush() { // Set up a feed for the view under test - it will have a depth of 3 trades SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportBean_A), 3); stream.AddView(_myView); IDictionary <String, EventBean> events = EventFactoryHelper.MakeEventMap( new String[] { "a0", "b0", "b1", "c0", "c1", "d0", "e0", "e1", "e2", "f0", "f1", "g0", "g1", "g2", "g3", "g4", "h0", "h1", "h2", "h3", "h4", "h5", "h6", "i0" }); stream.Insert(MakeArray(events, new String[] { "a0" })); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, null); EPAssertionUtil.AssertEqualsExactOrder(MakeArray(events, new String[] { "a0" }), _myView.GetEnumerator()); stream.Insert(MakeArray(events, new String[] { "b0", "b1" })); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, null); EPAssertionUtil.AssertEqualsExactOrder(MakeArray(events, new String[] { "a0", "b0", "b1" }), _myView.GetEnumerator()); stream.Insert(MakeArray(events, new String[] { "c0", "c1" })); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, MakeArray(events, new String[] { "a0", "b0", "b1", "c0", "c1" })); EPAssertionUtil.AssertEqualsExactOrder(null, _myView.GetEnumerator()); // Send further events, expect to get events back that fall out of the window, i.e. prior batch stream.Insert(MakeArray(events, new String[] { "d0" })); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, null); EPAssertionUtil.AssertEqualsExactOrder(MakeArray(events, new String[] { "d0" }), _myView.GetEnumerator()); stream.Insert(MakeArray(events, new String[] { "e0", "e1", "e2" })); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, null); EPAssertionUtil.AssertEqualsExactOrder(MakeArray(events, new String[] { "d0", "e0", "e1", "e2" }), _myView.GetEnumerator()); stream.Insert(MakeArray(events, new String[] { "f0", "f1" })); SupportViewDataChecker.CheckOldData(_childView, MakeArray(events, new String[] { "a0", "b0", "b1", "c0", "c1" })); SupportViewDataChecker.CheckNewData(_childView, MakeArray(events, new String[] { "d0", "e0", "e1", "e2", "f0", "f1" })); EPAssertionUtil.AssertEqualsExactOrder(null, _myView.GetEnumerator()); // Push as many events as the window takes stream.Insert(MakeArray(events, new String[] { "g0", "g1", "g2", "g3", "g4" })); SupportViewDataChecker.CheckOldData(_childView, MakeArray(events, new String[] { "d0", "e0", "e1", "e2", "f0", "f1" })); SupportViewDataChecker.CheckNewData(_childView, MakeArray(events, new String[] { "g0", "g1", "g2", "g3", "g4" })); EPAssertionUtil.AssertEqualsExactOrder(null, _myView.GetEnumerator()); // Push 2 more events then the window takes stream.Insert(MakeArray(events, new String[] { "h0", "h1", "h2", "h3", "h4", "h5", "h6" })); SupportViewDataChecker.CheckOldData(_childView, MakeArray(events, new String[] { "g0", "g1", "g2", "g3", "g4" })); SupportViewDataChecker.CheckNewData(_childView, MakeArray(events, new String[] { "h0", "h1", "h2", "h3", "h4", "h5", "h6" })); EPAssertionUtil.AssertEqualsExactOrder(null, _myView.GetEnumerator()); // Push 1 last event stream.Insert(MakeArray(events, new String[] { "i0" })); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, null); EPAssertionUtil.AssertEqualsExactOrder(MakeArray(events, new String[] { "i0" }), _myView.GetEnumerator()); }
public void TestViewPush() { // Set up a feed for the view under test - it will have a depth of 3 trades SupportStreamImpl stream = new SupportStreamImpl(typeof(SupportBean), 3); stream.AddView(_myView); EventBean[] a = MakeBeans("a", 10000, 1); stream.Insert(a); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { a[0] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { a[0] }, _myView.GetEnumerator()); EventBean[] b = MakeBeans("b", 10500, 2); stream.Insert(b); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { b[0], b[1] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { a[0], b[0], b[1] }, _myView.GetEnumerator()); EventBean[] c = MakeBeans("c", 10900, 1); stream.Insert(c); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { c[0] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { a[0], b[0], b[1], c[0] }, _myView.GetEnumerator()); EventBean[] d = MakeBeans("d", 10999, 1); stream.Insert(d); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { d[0] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { a[0], b[0], b[1], c[0], d[0] }, _myView.GetEnumerator()); EventBean[] e = MakeBeans("e", 11000, 2); stream.Insert(e); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { a[0] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { e[0], e[1] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { b[0], b[1], c[0], d[0], e[0], e[1] }, _myView.GetEnumerator()); EventBean[] f = MakeBeans("f", 11500, 1); stream.Insert(f); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { b[0], b[1] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { f[0] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { c[0], d[0], e[0], e[1], f[0] }, _myView.GetEnumerator()); EventBean[] g = MakeBeans("g", 11899, 1); stream.Insert(g); SupportViewDataChecker.CheckOldData(_childView, null); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { g[0] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { c[0], d[0], e[0], e[1], f[0], g[0] }, _myView.GetEnumerator()); EventBean[] h = MakeBeans("h", 11999, 3); stream.Insert(h); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { c[0], d[0] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { h[0], h[1], h[2] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { e[0], e[1], f[0], g[0], h[0], h[1], h[2] }, _myView.GetEnumerator()); EventBean[] i = MakeBeans("i", 13001, 1); stream.Insert(i); SupportViewDataChecker.CheckOldData(_childView, new EventBean[] { e[0], e[1], f[0], g[0], h[0], h[1], h[2] }); SupportViewDataChecker.CheckNewData(_childView, new EventBean[] { i[0] }); EPAssertionUtil.AssertEqualsExactOrder(new EventBean[] { i[0] }, _myView.GetEnumerator()); }
public void TestMatch() { SupportStreamImpl stream = new SupportStreamImpl(TEST_CLASS, 10); IList <ViewFactory> viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); // No views under stream, no matches Pair <Viewable, IList <View> > result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(stream, result.First); Assert.AreEqual(3, viewFactories.Count); Assert.AreEqual(0, result.Second.Count); // One top view under the stream that doesn't match SupportBeanClassView testView = new SupportBeanClassView(TEST_CLASS); stream.AddView(new FirstElementView(null)); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(stream, result.First); Assert.AreEqual(3, viewFactories.Count); Assert.AreEqual(0, result.Second.Count); // Another top view under the stream that doesn't matche again testView = new SupportBeanClassView(TEST_CLASS); stream.AddView(new LengthWindowView(SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(), null, 999, null)); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(stream, result.First); Assert.AreEqual(3, viewFactories.Count); Assert.AreEqual(0, result.Second.Count); // One top view under the stream that does actually match LengthWindowView myLengthWindowView = new LengthWindowView(SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(), null, 1000, null); stream.AddView(myLengthWindowView); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(myLengthWindowView, result.First); Assert.AreEqual(2, viewFactories.Count); Assert.AreEqual(1, result.Second.Count); Assert.AreEqual(myLengthWindowView, result.Second[0]); // One child view under the top view that does not match testView = new SupportBeanClassView(TEST_CLASS); viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); EventType type = UnivariateStatisticsView.CreateEventType(SupportStatementContextFactory.MakeContext(), null, 1); UnivariateStatisticsViewFactory factory = new UnivariateStatisticsViewFactory(); factory.EventType = type; factory.FieldExpression = SupportExprNodeFactory.MakeIdentNodeBean("LongBoxed"); myLengthWindowView.AddView(new UnivariateStatisticsView(factory, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext())); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(1, result.Second.Count); Assert.AreEqual(myLengthWindowView, result.Second[0]); Assert.AreEqual(myLengthWindowView, result.First); Assert.AreEqual(2, viewFactories.Count); // Add child view under the top view that does match viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); UnivariateStatisticsViewFactory factoryTwo = new UnivariateStatisticsViewFactory(); factoryTwo.EventType = type; factoryTwo.FieldExpression = SupportExprNodeFactory.MakeIdentNodeBean("IntPrimitive"); UnivariateStatisticsView myUnivarView = new UnivariateStatisticsView(factoryTwo, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext()); myLengthWindowView.AddView(myUnivarView); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(myUnivarView, result.First); Assert.AreEqual(1, viewFactories.Count); // Add ultimate child view under the child view that does match viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); LastElementView lastElementView = new LastElementView(null); myUnivarView.AddView(lastElementView); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(lastElementView, result.First); Assert.AreEqual(0, viewFactories.Count); }