context: ///////////////////////////////////////////////////////////////////////////////////////
  // Copyright (C) 2006-2015 Esper Team. All rights reserved.                           /
  // http://esper.codehaus.org                                                          /
  // ---------------------------------------------------------------------------------- /
  // The software in this package is published under the terms of the GPL license       /
  // a copy of which has been included with this distribution in the license.txt file.  /
  ///////////////////////////////////////////////////////////////////////////////////////
  
  using System.Collections.Generic;
  
  using com.espertech.esper.common.client.soda;
  using com.espertech.esper.common.@internal.support;
  using com.espertech.esper.compat.collections;
  using com.espertech.esper.regressionlib.framework;
  
  using NUnit.Framework;
  
  namespace com.espertech.esper.regressionlib.suite.epl.other
  {
      public class EPLOtherIStreamRStreamKeywords
      {
          public static IList<RegressionExecution> Executions()
          {
              IList<RegressionExecution> execs = new List<RegressionExecution>();
              WithRStreamOnlyOM(execs);
              WithRStreamOnlyCompile(execs);
              WithRStreamOnly(execs);
              WithRStreamInsertInto(execs);
              WithRStreamInsertIntoRStream(execs);
              WithRStreamJoin(execs);
              WithIStreamOnly(execs);
              WithIStreamInsertIntoRStream(execs);
              WithIStreamJoin(execs);
              WithRStreamOutputSnapshot(execs);
              return execs;
          }
  
          public static IList<RegressionExecution> WithRStreamOutputSnapshot(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherRStreamOutputSnapshot());
              return execs;
          }
  
          public static IList<RegressionExecution> WithIStreamJoin(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherIStreamJoin());
              return execs;
          }
  
          public static IList<RegressionExecution> WithIStreamInsertIntoRStream(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherIStreamInsertIntoRStream());
              return execs;
          }
  
          public static IList<RegressionExecution> WithIStreamOnly(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherIStreamOnly());
              return execs;
          }
  
          public static IList<RegressionExecution> WithRStreamJoin(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherRStreamJoin());
              return execs;
          }
  
          public static IList<RegressionExecution> WithRStreamInsertIntoRStream(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherRStreamInsertIntoRStream());
              return execs;
          }
  
          public static IList<RegressionExecution> WithRStreamInsertInto(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherRStreamInsertInto());
              return execs;
          }
  
          public static IList<RegressionExecution> WithRStreamOnly(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherRStreamOnly());
              return execs;
          }
  
          public static IList<RegressionExecution> WithRStreamOnlyCompile(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherRStreamOnlyCompile());
              return execs;
          }
  
          public static IList<RegressionExecution> WithRStreamOnlyOM(IList<RegressionExecution> execs = null)
          {
              execs = execs ?? new List<RegressionExecution>();
              execs.Add(new EPLOtherRStreamOnlyOM());
              return execs;
          }
  
          private static void SendEvents(
              RegressionEnvironment env,
              string[] stringValue)
          {
              for (var i = 0; i < stringValue.Length; i++) {
                  SendEvent(env, stringValue[i], 2);
              }
          }
  
          private static object SendEvent(
              RegressionEnvironment env,
              string stringValue,
              int intPrimitive)
          {
              var theEvent = new SupportBean();
              theEvent.TheString = stringValue;
              theEvent.IntPrimitive = intPrimitive;
              env.SendEventBean(theEvent);
              return theEvent;
          }
  
          internal class EPLOtherRStreamOutputSnapshot : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  string epl = "select rstream * from SupportBean#time(30 minutes) output snapshot";
                  env.CompileDeploy(epl).UndeployAll();
              }
          }
  
          internal class EPLOtherRStreamOnlyOM : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  var stmtText = "select rstream * from SupportBean#length(3)";
                  var model = new EPStatementObjectModel();
                  model.SelectClause = SelectClause.CreateWildcard(StreamSelector.RSTREAM_ONLY);
                  var fromClause = FromClause.Create(
                      FilterStream.Create("SupportBean").AddView(View.Create("length", Expressions.Constant(3))));
                  model.FromClause = fromClause;
                  model = env.CopyMayFail(model);
  
                  Assert.AreEqual(stmtText, model.ToEPL());
                  model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                  env.CompileDeploy(model).AddListener("s0");
  
                  var theEvent = SendEvent(env, "a", 2);
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
  
                  SendEvents(env, new[] {"a", "b"});
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
  
                  SendEvent(env, "d", 2);
                  Assert.AreSame(theEvent, env.Listener("s0").LastNewData[0].Underlying); // receive 'a' as new data
                  Assert.IsNull(env.Listener("s0").LastOldData); // receive no more old data
  
                  env.UndeployAll();
              }
          }
  
          internal class EPLOtherRStreamOnlyCompile : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  var stmtText = "select rstream * from SupportBean#length(3)";
                  var model = env.EplToModel(stmtText);
                  model = env.CopyMayFail(model);
  
                  Assert.AreEqual(stmtText, model.ToEPL());
                  model.Annotations = Collections.SingletonList(AnnotationPart.NameAnnotation("s0"));
                  env.CompileDeploy(model).AddListener("s0");
  
                  var theEvent = SendEvent(env, "a", 2);
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
  
                  SendEvents(env, new[] {"a", "b"});
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
  
                  SendEvent(env, "d", 2);
                  Assert.AreSame(theEvent, env.Listener("s0").LastNewData[0].Underlying); // receive 'a' as new data
                  Assert.IsNull(env.Listener("s0").LastOldData); // receive no more old data
  
                  env.UndeployAll();
              }
          }
  
          internal class EPLOtherRStreamOnly : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  env.CompileDeploy("@Name('s0') select rstream * from SupportBean#length(3)").AddListener("s0");
  
                  var theEvent = SendEvent(env, "a", 2);
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
  
                  SendEvents(env, new[] {"a", "b"});
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
  
                  SendEvent(env, "d", 2);
                  Assert.AreSame(theEvent, env.Listener("s0").LastNewData[0].Underlying); // receive 'a' as new data
                  Assert.IsNull(env.Listener("s0").LastOldData); // receive no more old data
  
                  env.UndeployAll();
              }
          }
  
          internal class EPLOtherRStreamInsertInto : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
                  var path = new RegressionPath();
                  env.CompileDeploy(
                      "@Name('s0') insert into NextStream " +
                      "select rstream S0.TheString as TheString from SupportBean#length(3) as S0",
                      path);
                  env.AddListener("s0");
                  env.CompileDeploy("@Name('ii') select * from NextStream", path).AddListener("ii");
  
                  SendEvent(env, "a", 2);
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
                  Assert.AreEqual(
                      "a",
                      env.Listener("ii").AssertOneGetNewAndReset().Get("TheString")); // insert into unchanged
  
                  SendEvents(env, new[] {"b", "c"});
                  Assert.IsFalse(env.Listener("s0").IsInvoked);
                  Assert.AreEqual(2, env.Listener("ii").NewDataList.Count); // insert into unchanged
                  env.Listener("ii").Reset();
  
                  SendEvent(env, "d", 2);
                  Assert.AreSame("a", env.Listener("s0").LastNewData[0].Get("TheString")); // receive 'a' as new data
                  Assert.IsNull(env.Listener("s0").LastOldData); // receive no more old data
                  Assert.AreEqual("d", env.Listener("ii").LastNewData[0].Get("TheString")); // insert into unchanged
                  Assert.IsNull(env.Listener("ii").LastOldData); // receive no old data in insert into
  
                  env.UndeployAll();
              }
          }
  
          internal class EPLOtherRStreamInsertIntoRStream : RegressionExecution
          {
              public void Run(RegressionEnvironment env)
              {
  
gt:                 var path = new RegressionPath();