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); }