Exemplo n.º 1
0
        /// <summary>
        /// Constructs a {@code TerminalOp} that implements a mutable reduce on
        /// reference values.
        /// </summary>
        /// @param <T> the type of the input elements </param>
        /// @param <R> the type of the result </param>
        /// <param name="seedFactory"> a factory to produce a new base accumulator </param>
        /// <param name="accumulator"> a function to incorporate an element into an
        ///        accumulator </param>
        /// <param name="reducer"> a function to combine an accumulator into another </param>
        /// <returns> a {@code TerminalOp} implementing the reduction </returns>
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint:
//ORIGINAL LINE: public static <T, R> TerminalOp<T, R> makeRef(java.util.function.Supplier<R> seedFactory, java.util.function.BiConsumer<R, ? base T> accumulator, java.util.function.BiConsumer<R,R> reducer)
        public static TerminalOp <T, R> makeRef <T, R, T1>(Supplier <R> seedFactory, BiConsumer <T1> accumulator, BiConsumer <R, R> reducer)
        {
            Objects.RequireNonNull(seedFactory);
            Objects.RequireNonNull(accumulator);
            Objects.RequireNonNull(reducer);
//JAVA TO C# CONVERTER TODO TASK: Local classes are not converted by Java to C# Converter:
//			class ReducingSink extends Box<R> implements AccumulatingSink<T, R, ReducingSink>
            //		{
            //			@@Override public void begin(long size)
            //			{
            //				state = seedFactory.get();
            //			}
            //
            //			@@Override public void accept(T t)
            //			{
            //				accumulator.accept(state, t);
            //			}
            //
            //			@@Override public void combine(ReducingSink other)
            //			{
            //				reducer.accept(state, other.state);
            //			}
            //		}
            return(new ReduceOpAnonymousInnerClassHelper4());
        }
        public void RunAssertion(
            RegressionEnvironment env,
            string createSchemaEPL,
            BiConsumer <EventType, NullableObject <string> > sender)
        {
            var epl = createSchemaEPL +
                      "@Name('s0') select * from LocalEvent;\n" +
                      "@Name('s1') select Property.Id as c0, exists(Property.Id) as c1, typeof(Property.Id) as c2 from LocalEvent;\n";

            env.CompileDeploy(epl).AddListener("s0").AddListener("s1");
            var eventType = env.Statement("s0").EventType;

            var g0 = eventType.GetGetter("Property.Id");

            sender.Invoke(eventType, new NullableObject <string>("a"));
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            AssertGetter(@event, g0, true, "a");
            AssertProps(env, true, "a");

            sender.Invoke(eventType, new NullableObject <string>(null));
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, true, null);
            AssertProps(env, true, null);

            sender.Invoke(eventType, null);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertProps(env, false, null);

            env.UndeployAll();
        }
        public void RunAssertion(
            RegressionEnvironment env,
            string typeName,
            string createSchemaEPL,
            BiConsumer <EventType, string> sender)
        {
            var epl =
                createSchemaEPL +
                $"@Name('s0') select * from {typeName};\n" +
                $"@Name('s1') select Property as c0, exists(Property) as c1, typeof(Property) as c2 from {typeName};\n";

            env.CompileDeploy(epl).AddListener("s0").AddListener("s1");

            var eventType = env.Statement("s0").EventType;

            var g0 = eventType.GetGetter("Property");

            sender.Invoke(eventType, "a");
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            AssertGetter(@event, g0, "a");
            AssertProps(env, "a");

            sender.Invoke(eventType, null);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, null);
            AssertProps(env, null);

            env.UndeployAll();
        }
        public void TraverseStatementsContains(
            BiConsumer <EPDeployment, EPStatement> consumer,
            string containsIgnoreCase)
        {
            _runtimeSPI.TraverseStatements(
                (
                    deployment,
                    stmt) => {
                var match        = false;
                var searchString = containsIgnoreCase.ToLowerInvariant();
                if (stmt.Name.ToLowerInvariant().Contains(searchString))
                {
                    match = true;
                }

                if (!match)
                {
                    var epl = (string)stmt.GetProperty(StatementProperty.EPL);
                    if ((epl != null) && (epl.ToLowerInvariant().Contains(searchString)))
                    {
                        match = true;
                    }
                }

                if (!match)
                {
                    return;
                }

                consumer.Invoke(deployment, stmt);
            });
        }
Exemplo n.º 5
0
        public void TestUnionResultingInNumber()
        {
            var schema = SchemaBuilder.Record(
                "typename",
                Field("anUnion", Union(IntType(), FloatType())));

            EventType eventType = SupportAvroUtil.MakeAvroSupportEventType(schema);

            AssertPropertyType(typeof(object), null, eventType, "anUnion");

            Consumer <Object> asserterFromDatum = (value) => {
                var datum = new GenericRecord(schema);
                datum.Put("anUnion", value);
                Assert.AreEqual(value, new AvroGenericDataEventBean(datum, eventType).Get("anUnion"));
            };

            asserterFromDatum.Invoke(1);
            asserterFromDatum.Invoke(2f);

            BiConsumer <String, Object> asserterFromJson = (
                json,
                value) => {
                var datum = SupportAvroUtil.ParseQuoted(schema, json);
                Assert.AreEqual(value, new AvroGenericDataEventBean(datum, eventType).Get("anUnion"));
            };

            asserterFromJson.Invoke("{'anUnion':{'int':1}}", 1);
            asserterFromJson.Invoke("{'anUnion':{'float':2}}", 2f);
        }
 public void KeyVisit(
     IntSeqKey controllerPath,
     BiConsumer<object, int> keyAndSubpathOrCPId)
 {
     foreach (var entry in _keys) {
         keyAndSubpathOrCPId.Invoke(entry.Key, entry.Value.SubpathOrCPId);
     }
 }
Exemplo n.º 7
0
 public void EndVisit(
     IntSeqKey controllerPath,
     BiConsumer<ContextControllerInitTermPartitionKey, int> partKeyAndCPId)
 {
     foreach (var entry in endConditions) {
         partKeyAndCPId.Invoke(entry.Value.PartitionKey, entry.Value.SubpathIdOrCPId);
     }
 }
 public void EndVisitConditions(
     IntSeqKey controllerPath,
     BiConsumer<ContextControllerConditionNonHA, int> partKeyAndCPId)
 {
     foreach (var entry in endConditions) {
         partKeyAndCPId.Invoke(entry.Value.TerminationCondition, entry.Value.SubpathIdOrCPId);
     }
 }
Exemplo n.º 9
0
 public static BiConsumer andThen(BiConsumer @this, BiConsumer other)
 {
     if (@this == null || other == null)
     {
         throw new NullPointerException();
     }
     return(new BiConsumerAndThen(@this, other));
 }
Exemplo n.º 10
0
        public void RunAssertion(
            RegressionEnvironment env,
            string createSchemaEPL,
            BiConsumer <EventType, IDictionary <string, string> > sender)
        {
            var path = new RegressionPath();

            env.CompileDeploy(createSchemaEPL, path);

            env.CompileDeploy("@Name('s0') select * from LocalEvent", path).AddListener("s0");
            var eventType = env.Statement("s0").EventType;
            var g0        = eventType.GetGetter("Mapped('a')");
            var g1        = eventType.GetGetter("Mapped('b')");

            var propepl = "@Name('s1') select Mapped('a') as c0, Mapped('b') as c1," +
                          "exists(Mapped('a')) as c2, exists(Mapped('b')) as c3, " +
                          "typeof(Mapped('a')) as c4, typeof(Mapped('b')) as c5 from LocalEvent;\n";

            env.CompileDeploy(propepl, path).AddListener("s1");

            IDictionary <string, string> values = new Dictionary <string, string>();

            values.Put("a", "x");
            values.Put("b", "y");
            sender.Invoke(eventType, values);
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            AssertGetter(@event, g0, true, "x");
            AssertGetter(@event, g1, true, "y");
            AssertProps(env, "x", "y");

            sender.Invoke(eventType, Collections.SingletonMap("a", "x"));
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, true, "x");
            AssertGetter(@event, g1, false, null);
            AssertProps(env, "x", null);

            sender.Invoke(eventType, EmptyDictionary <string, string> .Instance);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertGetter(@event, g1, false, null);
            AssertProps(env, null, null);

            sender.Invoke(eventType, null);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertGetter(@event, g1, false, null);
            AssertProps(env, null, null);

            sender.Invoke(eventType, null);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertGetter(@event, g1, false, null);
            AssertProps(env, null, null);

            env.UndeployAll();
        }
Exemplo n.º 11
0
 private static void RunAssertionSetGet(
     RegressionEnvironment env,
     string deploymentId,
     string variableName,
     object value,
     BiConsumer<object, object> assertion)
 {
     env.Runtime.VariableService.SetVariableValue(deploymentId, variableName, value);
     var returned = env.Runtime.VariableService.GetVariableValue(deploymentId, variableName);
     assertion.Invoke(value, returned);
 }
Exemplo n.º 12
0
 public void TraverseStatements(BiConsumer<EPDeployment, EPStatement> consumer)
 {
     foreach (var deploymentId in DeploymentService.Deployments) {
         var deployment = DeploymentService.GetDeployment(deploymentId);
         if (deployment != null) {
             foreach (var stmt in deployment.Statements) {
                 consumer.Invoke(deployment, stmt);
             }
         }
     }
 }
        public void Run(RegressionEnvironment env)
        {
            // Bean
            BiConsumer <EventType, string> bean = (type, property) => {
                env.SendEventBean(new LocalEvent(property));
            };
            var beanepl = $"@public @buseventtype create schema LocalEvent as {typeof(LocalEvent).MaskTypeName()}";

            RunAssertion(env, beanepl, bean);

            // Map
            BiConsumer <EventType, string> map = (type, property) => {
                env.SendEventMap(Collections.SingletonDataMap("Property", property), "LocalEvent");
            };

            RunAssertion(env, GetEpl("map"), map);

            // Object-array
            BiConsumer <EventType, string> oa = (type, property) => {
                env.SendEventObjectArray(new object[] { property }, "LocalEvent");
            };

            RunAssertion(env, GetEpl("objectarray"), oa);

            // Json
            BiConsumer <EventType, string> json = (type, property) => {
                if (property == null)
                {
                    env.SendEventJson(new JObject(new JProperty("Property", null)).ToString(), "LocalEvent");
                }
                else
                {
                    env.SendEventJson(new JObject(new JProperty("Property", property)).ToString(), "LocalEvent");
                }
            };

            RunAssertion(env, GetEpl("json"), json);

            // Json-Class-Predefined
            var eplJsonPredefined = "@JsonSchema(ClassName='" + typeof(MyLocalJsonProvided).MaskTypeName() + "') @buseventtype @public " +
                                    "create json schema LocalEvent();\n";

            RunAssertion(env, eplJsonPredefined, json);

            // Avro
            BiConsumer <EventType, string> avro = (type, property) => {
                var @event = new GenericRecord(SupportAvroUtil.GetAvroSchema(type).AsRecordSchema());
                @event.Put("Property", property);
                env.SendEventAvro(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("avro"), avro);
        }
Exemplo n.º 14
0
        public void RunAssertion(
            RegressionEnvironment env,
            string createSchemaEPL,
            BiConsumer <EventType, string[]> sender)
        {
            var path = new RegressionPath();

            env.CompileDeploy(createSchemaEPL, path);

            env.CompileDeploy("@Name('s0') select * from LocalEvent", path).AddListener("s0");
            var eventType = env.Statement("s0").EventType;
            var g0        = eventType.GetGetter("Array[0]");
            var g1        = eventType.GetGetter("Array[1]");

            var propepl = "@Name('s1') select Array[0] as c0, Array[1] as c1," +
                          "exists(Array[0]) as c2, exists(Array[1]) as c3, " +
                          "typeof(Array[0]) as c4, typeof(Array[1]) as c5 from LocalEvent;\n";

            env.CompileDeploy(propepl, path).AddListener("s1");

            sender.Invoke(eventType, new string[] { "a", "b" });
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            AssertGetter(@event, g0, true, "a");
            AssertGetter(@event, g1, true, "b");
            AssertProps(env, "a", "b");

            sender.Invoke(eventType, new string[] { "a" });
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, true, "a");
            AssertGetter(@event, g1, false, null);
            AssertProps(env, "a", null);

            sender.Invoke(eventType, new string[0]);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertGetter(@event, g1, false, null);
            AssertProps(env, null, null);

            sender.Invoke(eventType, null);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertGetter(@event, g1, false, null);
            AssertProps(env, null, null);

            sender.Invoke(eventType, null);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertGetter(@event, g1, false, null);
            AssertProps(env, null, null);

            env.UndeployAll();
        }
Exemplo n.º 15
0
 public static void TraverseAnnotations<T>(
     IList<Type> classes, 
     BiConsumer<Type, T> consumer)
     where T : Attribute
 {
     var annotationClass = typeof(T);
     WalkAnnotations(classes, (annotation, clazz) => {
         if (annotation.GetType() == annotationClass) {
             consumer.Invoke(clazz, (T) annotation);
         }
     });
 }
Exemplo n.º 16
0
 public static BiConsumer andThen(BiConsumer @this, BiConsumer other)
 {
     if (@this == null)
     {
         throw new System.NullReferenceException();
     }
     if (other == null)
     {
         throw new System.ArgumentNullException();
     }
     return(new BiConsumerAndThen(@this, other));
 }
 public void TraverseStatementsFilterExpr(
     BiConsumer <EPDeployment, EPStatement> consumer,
     ExprNode filterExpr)
 {
     _runtimeSPI.TraverseStatements(
         (
             deployment,
             stmt) => {
         if (EvaluateStatement(filterExpr, stmt))
         {
             consumer.Invoke(deployment, stmt);
         }
     });
 }
Exemplo n.º 18
0
        public static void DispatchPartition<T>(
            CopyOnWriteList<ContextPartitionStateListener> listeners,
            Supplier<T> supplier,
            BiConsumer<ContextPartitionStateListener, T> consumer)
        {
            if (listeners == null || listeners.IsEmpty()) {
                return;
            }

            T @event = supplier.Invoke();
            foreach (var listener in listeners) {
                consumer.Invoke(listener, @event);
            }
        }
Exemplo n.º 19
0
        public void RunAssertion(
            RegressionEnvironment env,
            string createSchemaEPL,
            BiConsumer <EventType, string> sender)
        {
            env.CompileDeploy(createSchemaEPL + "@Name('s0') select * from LocalEvent[Property];\n").AddListener("s0");
            var eventType = env.Runtime.EventTypeService.GetEventType(env.DeploymentId("s0"), "LocalEvent");

            sender.Invoke(eventType, "a");
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            Assert.AreEqual("a", @event.Get("Id"));

            env.UndeployAll();
        }
Exemplo n.º 20
0
        private void RunAssertion(
            RegressionEnvironment env,
            string createSchemaEPL,
            BiConsumer <EventType, Nullable2Lvl> sender)
        {
            var path = new RegressionPath();

            env.CompileDeploy(createSchemaEPL, path);

            env.CompileDeploy("@Name('s0') select * from LocalEvent", path).AddListener("s0");
            var eventType = env.Statement("s0").EventType;
            var g0        = eventType.GetGetter("Property?.Leaf.Id");

            if (sender == null)
            {
                Assert.IsNull(g0);
                env.UndeployAll();
                return;
            }
            else
            {
                var propepl = "@Name('s1') select Property?.Leaf.Id as c0, exists(Property?.Leaf.Id) as c1, typeof(Property?.Leaf.Id) as c2 from LocalEvent;\n";
                env.CompileDeploy(propepl, path).AddListener("s1");
            }

            sender.Invoke(eventType, new Nullable2Lvl(false, false, "a"));
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            AssertGetter(@event, g0, true, "a");
            AssertProps(env, true, "a");

            sender.Invoke(eventType, new Nullable2Lvl(false, false, null));
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, true, null);
            AssertProps(env, true, null);

            sender.Invoke(eventType, new Nullable2Lvl(false, true, null));
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertProps(env, false, null);

            sender.Invoke(eventType, new Nullable2Lvl(true, false, null));
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertProps(env, false, null);

            env.UndeployAll();
        }
Exemplo n.º 21
0
        public void RunAssertion(
            RegressionEnvironment env,
            string createSchemaEPL,
            BiConsumer <EventType, string[]> sender)
        {
            var epl = createSchemaEPL +
                      "@Name('s0') select * from LocalEvent;\n" +
                      "@Name('s1') select Property[0].Id as c0, Property[1].Id as c1," +
                      " exists(Property[0].Id) as c2, exists(Property[1].Id) as c3," +
                      " typeof(Property[0].Id) as c4, typeof(Property[1].Id) as c5" +
                      " from LocalEvent;\n";

            env.CompileDeploy(epl).AddListener("s0").AddListener("s1");
            var eventType = env.Statement("s0").EventType;

            var g0 = eventType.GetGetter("Property[0].Id");
            var g1 = eventType.GetGetter("Property[1].Id");

            sender.Invoke(eventType, new string[] { "a", "b" });
            var @event = env.Listener("s0").AssertOneGetNewAndReset();

            AssertGetter(@event, g0, true, "a");
            AssertGetter(@event, g1, true, "b");
            AssertProps(env, true, "a", true, "b");

            sender.Invoke(eventType, new string[] { "a" });
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, true, "a");
            AssertGetter(@event, g1, false, null);
            AssertProps(env, true, "a", false, null);

            sender.Invoke(eventType, new string[0]);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertGetter(@event, g1, false, null);
            AssertProps(env, false, null, false, null);

            sender.Invoke(eventType, null);
            @event = env.Listener("s0").AssertOneGetNewAndReset();
            AssertGetter(@event, g0, false, null);
            AssertGetter(@event, g1, false, null);
            AssertProps(env, false, null, false, null);

            env.UndeployAll();
        }
Exemplo n.º 22
0
        public void RunAssertion(
            RegressionEnvironment env,
            string createSchemaEPL,
            BiConsumer <EventType, string[]> sender)
        {
            env.CompileDeploy(
                createSchemaEPL +
                "create constant variable int offsetNum = 0;" +
                "@Name('s0') select Indexed(offsetNum+0) as c0, Indexed(offsetNum+1) as c1 from LocalEvent as e;\n"
                )
            .AddListener("s0");
            var eventType = env.Runtime.EventTypeService.GetEventType(env.DeploymentId("s0"), "LocalEvent");

            sender.Invoke(eventType, new string[] { "a", "b" });
            EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "c0,c1".SplitCsv(), new object[] { "a", "b" });

            env.UndeployAll();
        }
        public void HashVisit(
            IntSeqKey controllerPath,
            BiConsumer<int, int> hashAndCPId)
        {
            if (optionalHashes == null) {
                if (subpathOrCPIdsPreallocate == null) {
                    return;
                }

                for (var i = 0; i < subpathOrCPIdsPreallocate.Length; i++) {
                    hashAndCPId.Invoke(i, subpathOrCPIdsPreallocate[i]);
                }

                return;
            }

            foreach (var entry in optionalHashes) {
                hashAndCPId.Invoke(entry.Key, entry.Value);
            }
        }
Exemplo n.º 24
0
        public void RunAssertion(
            RegressionEnvironment env,
            string createSchemaEPL,
            BiConsumer <EventType, IDictionary <string, string> > sender)
        {
            env.CompileDeploy(
                createSchemaEPL +
                "create constant variable string keyChar = 'a';" +
                "@Name('s0') select Mapped(keyChar||'1') as c0, Mapped(keyChar||'2') as c1 from LocalEvent as e;\n"
                )
            .AddListener("s0");
            var eventType = env.Runtime.EventTypeService.GetEventType(env.DeploymentId("s0"), "LocalEvent");

            IDictionary <string, string> values = new Dictionary <string, string>();

            values.Put("a1", "x");
            values.Put("a2", "y");
            sender.Invoke(eventType, values);
            EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), "c0,c1".SplitCsv(), new object[] { "x", "y" });

            env.UndeployAll();
        }
Exemplo n.º 25
0
        public void TestUnionResultingInObject()
        {
            var schema = SchemaBuilder.Record(
                "typename",
                Field(
                    "anUnion",
                    Union(
                        IntType(),
                        StringType(Property(PROP_STRING_KEY, PROP_STRING_VALUE)),
                        NullType())));

            EventType eventType = SupportAvroUtil.MakeAvroSupportEventType(schema);

            AssertPropertyType(typeof(object), null, eventType, "anUnion");

            Consumer <Object> asserterFromDatum = (value) => {
                var datum = new GenericRecord(schema);
                datum.Put("anUnion", value);
                Assert.AreEqual(value, new AvroGenericDataEventBean(datum, eventType).Get("anUnion"));
            };

            asserterFromDatum.Invoke("a");
            asserterFromDatum.Invoke(1);
            asserterFromDatum.Invoke(null);

            BiConsumer <String, Object> asserterFromJson = (
                json,
                value) => {
                var datum = SupportAvroUtil.ParseQuoted(schema, json);
                Assert.AreEqual(value, new AvroGenericDataEventBean(datum, eventType).Get("anUnion"));
            }
            ;

            asserterFromJson.Invoke("{'anUnion':{'int':1}}", 1);
            asserterFromJson.Invoke("{'anUnion':{'string':'abc'}}", "abc");
            asserterFromJson.Invoke("{'anUnion':null}", null);
        }
        public void HashVisit(
            IntSeqKey controllerPath,
            BiConsumer<int, int> hashAndCPId)
        {
            if (_optionalHashes == null) {
                var mgmtInfo = _mgmt.Get(controllerPath);
                if (mgmtInfo == null || mgmtInfo.SubpathOrCPIdsPreallocate == null) {
                    return;
                }

                var subpathOrCPIds = mgmtInfo.SubpathOrCPIdsPreallocate;
                for (var i = 0; i < subpathOrCPIds.Length; i++) {
                    hashAndCPId.Invoke(i, subpathOrCPIds[i]);
                }

                return;
            }

            foreach (var entry in _optionalHashes) {
                if (controllerPath.IsParentTo(entry.Key)) {
                    hashAndCPId.Invoke(entry.Key.Last, entry.Value);
                }
            }
        }
Exemplo n.º 27
0
        public void Run(RegressionEnvironment env)
        {
            // Bean
            BiConsumer <EventType, Nullable2Lvl> bean = (
                type,
                val) => {
                LocalEvent @event;
                if (val.IsNullAtRoot)
                {
                    @event = new LocalEvent();
                }
                else if (val.IsNullAtInner)
                {
                    @event = new LocalEventSubA(new LocalInnerEvent(null));
                }
                else
                {
                    @event = new LocalEventSubA(new LocalInnerEvent(new LocalLeafEvent(val.Id)));
                }

                env.SendEventBean(@event, "LocalEvent");
            };
            var beanepl = "@public @buseventtype create schema LocalEvent as " +
                          typeof(EventInfraGetterDynamicNested.LocalEvent).MaskTypeName() +
                          ";\n" +
                          "@public @buseventtype create schema LocalEventSubA as " +
                          typeof(EventInfraGetterDynamicNested.LocalEventSubA).MaskTypeName() +
                          ";\n";

            RunAssertion(env, beanepl, bean);

            // Map
            BiConsumer <EventType, Nullable2Lvl> map = (
                type,
                val) => {
                IDictionary <string, object> @event = new LinkedHashMap <string, object>();
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    var inner = Collections.SingletonDataMap("Leaf", null);
                    @event.Put("Property", inner);
                }
                else
                {
                    var leaf  = Collections.SingletonDataMap("Id", val.Id);
                    var inner = Collections.SingletonDataMap("Leaf", leaf);
                    @event.Put("Property", inner);
                }

                env.SendEventMap(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("map"), map);

            // Object-array
            RunAssertion(env, GetEpl("objectarray"), null);

            // Json
            BiConsumer <EventType, Nullable2Lvl> json = (
                type,
                val) => {
                var @event = new JObject();
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    @event.Add("Property", new JObject(new JProperty("Leaf", null)));
                }
                else
                {
                    var leaf  = new JObject(new JProperty("Id", val.Id));
                    var inner = new JObject(new JProperty("Leaf", leaf));
                    @event.Add("Property", inner);
                }

                env.SendEventJson(@event.ToString(), "LocalEvent");
            };

            RunAssertion(env, GetEpl("json"), json);

            // Json-Class-Provided
            var eplJsonProvided = "@JsonSchema(ClassName='" +
                                  typeof(MyLocalJsonProvided).MaskTypeName() +
                                  "') @public @buseventtype create json schema LocalEvent();\n";

            RunAssertion(env, eplJsonProvided, json);

            // Avro
            BiConsumer <EventType, Nullable2Lvl> avro = (
                type,
                val) => {
                var           emptySchema = SchemaBuilder.Record("empty");
                GenericRecord @event;
                if (val.IsNullAtRoot)
                {
                    @event = new GenericRecord(emptySchema);
                }
                else if (val.IsNullAtInner)
                {
                    var inner     = new GenericRecord(emptySchema);
                    var topSchema = SchemaBuilder.Record("name", TypeBuilder.Field("Property", emptySchema));
                    @event = new GenericRecord(topSchema);
                    @event.Put("Property", inner);
                }
                else
                {
                    var leafSchema = SchemaBuilder.Record(
                        "leaf",
                        TypeBuilder.Field(
                            "Id",
                            TypeBuilder.StringType(
                                TypeBuilder.Property(
                                    AvroConstant.PROP_STRING_KEY,
                                    AvroConstant.PROP_STRING_VALUE))));

                    var innerSchema = SchemaBuilder.Record("inner", TypeBuilder.Field("Leaf", leafSchema));
                    var topSchema   = SchemaBuilder.Record("top", TypeBuilder.Field("Property", innerSchema));
                    var leaf        = new GenericRecord(leafSchema);
                    leaf.Put("Id", val.Id);
                    var inner = new GenericRecord(innerSchema);
                    inner.Put("Leaf", leaf);
                    @event = new GenericRecord(topSchema);
                    @event.Put("Property", inner);
                }

                env.SendEventAvro(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("avro"), avro);
        }
Exemplo n.º 28
0
 protected override void VisitPartitions(
     IntSeqKey controllerPath,
     BiConsumer<int, int> hashAndCPId)
 {
     hashSvc.HashVisit(controllerPath, hashAndCPId);
 }
        public void Run(RegressionEnvironment env)
        {
            // Bean
            BiConsumer <EventType, Nullable2Lvl> bean = (
                type,
                val) => {
                LocalEvent @event;
                if (val.IsNullAtRoot)
                {
                    @event = new LocalEvent(null);
                }
                else if (val.IsNullAtInner)
                {
                    @event = new LocalEvent(new LocalInnerEvent(null));
                }
                else
                {
                    @event = new LocalEvent(new LocalInnerEvent(new LocalLeafEvent(val.Id)));
                }

                env.SendEventBean(@event);
            };
            var beanepl = $"@public @buseventtype create schema LocalEvent as {typeof(LocalEvent).MaskTypeName()};\n";

            RunAssertion(env, beanepl, bean);

            // Map
            BiConsumer <EventType, Nullable2Lvl> map = (
                type,
                val) => {
                IDictionary <string, object> @event = new LinkedHashMap <string, object>();
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    var inner = Collections.SingletonDataMap("Leaf", null);
                    @event.Put("Property", inner);
                }
                else
                {
                    var leaf  = Collections.SingletonDataMap("Id", val.Id);
                    var inner = Collections.SingletonDataMap("Leaf", leaf);
                    @event.Put("Property", inner);
                }

                env.SendEventMap(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("map"), map);

            // Object-array
            BiConsumer <EventType, Nullable2Lvl> oa = (
                type,
                val) => {
                var @event = new object[1];
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    var inner = new object[] { null };
                    @event[0] = inner;
                }
                else
                {
                    var leaf  = new object[] { val.Id };
                    var inner = new object[] { leaf };
                    @event[0] = inner;
                }

                env.SendEventObjectArray(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("objectarray"), oa);

            // Json
            BiConsumer <EventType, Nullable2Lvl> json = (
                type,
                val) => {
                var @event = new JObject();
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    @event.Add("Property", new JObject(new JProperty("Leaf", null)));
                }
                else
                {
                    var leaf  = new JObject(new JProperty("Id", val.Id));
                    var inner = new JObject(new JProperty("Leaf", leaf));
                    @event.Add("Property", inner);
                }

                env.SendEventJson(@event.ToString(), "LocalEvent");
            };

            RunAssertion(env, GetEpl("json"), json);

            // Json-Class-Provided
            var eplJsonProvided =
                $"@JsonSchema(ClassName='{typeof(MyLocalJsonProvided).MaskTypeName()}') " +
                "@public @buseventtype create json schema LocalEvent();\n";

            RunAssertion(env, eplJsonProvided, json);

            // Avro
            BiConsumer <EventType, Nullable2Lvl> avro = (
                type,
                val) => {
                var schema = SupportAvroUtil.GetAvroSchema(type);
                var @event = new GenericRecord(schema.AsRecordSchema());
                if (val.IsNullAtRoot)
                {
                    // no change
                }
                else if (val.IsNullAtInner)
                {
                    var inner = new GenericRecord(schema
                                                  .GetField("Property")
                                                  .Schema.AsRecordSchema());
                    @event.Put("Property", inner);
                }
                else
                {
                    var leaf = new GenericRecord(schema
                                                 .GetField("Property")
                                                 .Schema.AsRecordSchema()
                                                 .GetField("Leaf")
                                                 .Schema.AsRecordSchema());
                    leaf.Put("Id", val.Id);
                    var inner = new GenericRecord(schema.GetField("Property").Schema.AsRecordSchema());
                    inner.Put("Leaf", leaf);
                    @event.Put("Property", inner);
                }

                env.SendEventAvro(@event, "LocalEvent");
            };

            RunAssertion(env, GetEpl("avro"), avro);
        }
Exemplo n.º 30
0
 protected override void VisitPartitions(
     IntSeqKey controllerPath,
     BiConsumer<object, int> keyAndSubpathOrCPId)
 {
     keyedSvc.KeyVisit(controllerPath, keyAndSubpathOrCPId);
 }