Ejemplo n.º 1
0
        public void DelegateThrowsExceptionMatchFilter()
        {
            var topic = TestExecuter.GetTopic();
            var executedBatchCount            = 0;
            var executedLeftKeyDelegateCount  = 0;
            var executedRightKeyDelegateCount = 0;
            var builder = ProcessBuilder.Fluent
                          .ReadFrom(TestData.Person(topic))
                          .JoinBatched(new BatchedJoinMutator(topic, null)
            {
                BatchSize     = 1,
                LookupBuilder = new FilteredRowLookupBuilder()
                {
                    ProcessCreator = filterRows =>
                    {
                        executedBatchCount++;
                        return(TestData.PersonEyeColor(topic));
                    },
                    KeyGenerator = row => { executedRightKeyDelegateCount++; return(row.GenerateKey("personId")); },
                },
                RowKeyGenerator     = row => { executedLeftKeyDelegateCount++; return(row.GenerateKey("id")); },
                NoMatchAction       = new NoMatchAction(MatchMode.Remove),
                MatchFilter         = match => match.GetAs <double>("id") == 7,
                ColumnConfiguration = ColumnCopyConfiguration.StraightCopy("color"),
            });

            var result = TestExecuter.Execute(builder);

            Assert.AreEqual(1, executedBatchCount);
            Assert.AreEqual(0, result.MutatedRows.Count);
            var exceptions = topic.Context.GetExceptions();

            Assert.AreEqual(1, exceptions.Count);
            Assert.IsTrue(exceptions[0] is ProcessExecutionException);
        }
Ejemplo n.º 2
0
        public void DelegateThrowsExceptionLookupBuilderKeyGenerator()
        {
            var topic = TestExecuter.GetTopic();
            var executedLeftKeyDelegateCount  = 0;
            var executedRightKeyDelegateCount = 0;
            var builder = ProcessBuilder.Fluent
                          .ReadFrom(TestData.Person(topic))
                          .Join(new JoinMutator(topic, null)
            {
                LookupBuilder = new RowLookupBuilder()
                {
                    Process      = TestData.PersonEyeColor(topic),
                    KeyGenerator = row => { executedRightKeyDelegateCount++; return(row.GetAs <double>("personId").ToString("D", CultureInfo.InvariantCulture)); },
                },
                RowKeyGenerator     = row => { executedLeftKeyDelegateCount++; return(row.GenerateKey("id")); },
                NoMatchAction       = new NoMatchAction(MatchMode.Remove),
                ColumnConfiguration = ColumnCopyConfiguration.StraightCopy("color"),
            });

            var result = TestExecuter.Execute(builder);

            Assert.AreEqual(0, executedLeftKeyDelegateCount);
            Assert.AreEqual(1, executedRightKeyDelegateCount);
            Assert.AreEqual(0, result.MutatedRows.Count);
            var exceptions = topic.Context.GetExceptions();

            Assert.AreEqual(1, exceptions.Count);
            Assert.IsTrue(exceptions[0] is ProcessExecutionException);
        }
Ejemplo n.º 3
0
        public void NoMatchThrow1()
        {
            var topic = TestExecuter.GetTopic();
            var executedBatchCount = 0;
            var builder            = ProcessBuilder.Fluent
                                     .ReadFrom(TestData.Person(topic))
                                     .JoinBatched(new BatchedJoinMutator(topic, null)
            {
                BatchSize     = 1,
                LookupBuilder = new FilteredRowLookupBuilder()
                {
                    ProcessCreator = filterRows =>
                    {
                        executedBatchCount++;
                        return(TestData.PersonEyeColor(topic));
                    },
                    KeyGenerator = row => row.GenerateKey("personId"),
                },
                RowKeyGenerator     = row => row.GenerateKey("id"),
                NoMatchAction       = new NoMatchAction(MatchMode.Throw),
                ColumnConfiguration = ColumnCopyConfiguration.StraightCopy("color"),
            });

            var result = TestExecuter.Execute(builder);

            Assert.AreEqual(4, executedBatchCount);
            Assert.AreEqual(6, result.MutatedRows.Count);
            Assert.That.ExactMatch(result.MutatedRows, new List <CaseInsensitiveStringKeyDictionary <object> >()
            {
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 0, ["name"] = "A", ["age"] = 17, ["height"] = 160, ["eyeColor"] = "brown", ["countryId"] = 1, ["birthDate"] = new DateTime(2010, 12, 9, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 12, 0, 1, 0), ["color"] = "yellow"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 0, ["name"] = "A", ["age"] = 17, ["height"] = 160, ["eyeColor"] = "brown", ["countryId"] = 1, ["birthDate"] = new DateTime(2010, 12, 9, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 12, 0, 1, 0), ["color"] = "red"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 0, ["name"] = "A", ["age"] = 17, ["height"] = 160, ["eyeColor"] = "brown", ["countryId"] = 1, ["birthDate"] = new DateTime(2010, 12, 9, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 12, 0, 1, 0), ["color"] = "green"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 1, ["name"] = "B", ["age"] = 8, ["height"] = 190, ["countryId"] = 1, ["birthDate"] = new DateTime(2011, 2, 1, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 13, 2, 0, 0), ["color"] = "blue"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 1, ["name"] = "B", ["age"] = 8, ["height"] = 190, ["countryId"] = 1, ["birthDate"] = new DateTime(2011, 2, 1, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 13, 2, 0, 0), ["color"] = "yellow"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 2, ["name"] = "C", ["age"] = 27, ["height"] = 170, ["eyeColor"] = "green", ["countryId"] = 2, ["birthDate"] = new DateTime(2014, 1, 21, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 11, 21, 17, 11, 58, 0), ["color"] = "black"
                }
            });
            var exceptions = topic.Context.GetExceptions();

            Assert.AreEqual(1, exceptions.Count);
            Assert.IsTrue(exceptions[0] is ProcessExecutionException);
        }
Ejemplo n.º 4
0
        public void DelegateThrowsExceptionRowKeyGenerator()
        {
            var topic = TestExecuter.GetTopic();
            var executedLeftKeyDelegateCount  = 0;
            var executedRightKeyDelegateCount = 0;
            var builder = ProcessBuilder.Fluent
                          .ReadFrom(TestData.Person(topic))
                          .Join(new JoinMutator(topic, null)
            {
                LookupBuilder = new RowLookupBuilder()
                {
                    Process      = TestData.PersonEyeColor(topic),
                    KeyGenerator = row => { executedRightKeyDelegateCount++; return(row.GenerateKey("personId")); },
                },
                RowKeyGenerator     = row => { executedLeftKeyDelegateCount++; return(executedLeftKeyDelegateCount < 3 ? row.GenerateKey("id") : row.GetAs <double>("id").ToString("D", CultureInfo.InvariantCulture)); },
                NoMatchAction       = new NoMatchAction(MatchMode.Remove),
                ColumnConfiguration = ColumnCopyConfiguration.StraightCopy("color"),
            });

            var result = TestExecuter.Execute(builder);

            Assert.AreEqual(3, executedLeftKeyDelegateCount);
            Assert.AreEqual(7, executedRightKeyDelegateCount);
            Assert.AreEqual(5, result.MutatedRows.Count);
            Assert.That.ExactMatch(result.MutatedRows, new List <CaseInsensitiveStringKeyDictionary <object> >()
            {
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 0, ["name"] = "A", ["age"] = 17, ["height"] = 160, ["eyeColor"] = "brown", ["countryId"] = 1, ["birthDate"] = new DateTime(2010, 12, 9, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 12, 0, 1, 0), ["color"] = "yellow"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 0, ["name"] = "A", ["age"] = 17, ["height"] = 160, ["eyeColor"] = "brown", ["countryId"] = 1, ["birthDate"] = new DateTime(2010, 12, 9, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 12, 0, 1, 0), ["color"] = "red"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 0, ["name"] = "A", ["age"] = 17, ["height"] = 160, ["eyeColor"] = "brown", ["countryId"] = 1, ["birthDate"] = new DateTime(2010, 12, 9, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 12, 0, 1, 0), ["color"] = "green"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 1, ["name"] = "B", ["age"] = 8, ["height"] = 190, ["countryId"] = 1, ["birthDate"] = new DateTime(2011, 2, 1, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 13, 2, 0, 0), ["color"] = "blue"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 1, ["name"] = "B", ["age"] = 8, ["height"] = 190, ["countryId"] = 1, ["birthDate"] = new DateTime(2011, 2, 1, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 13, 2, 0, 0), ["color"] = "yellow"
                }
            });
            var exceptions = topic.Context.GetExceptions();

            Assert.AreEqual(1, exceptions.Count);
            Assert.IsTrue(exceptions[0] is ProcessExecutionException);
        }
Ejemplo n.º 5
0
        private static IProcessBuilder GetBuilder(ITopic topic, IMemoryAggregationOperation op, ITypeConverter converter)
        {
            var builder = ProcessBuilder.Fluent
                          .ReadFrom(TestData.PersonSortedByName(topic));

            if (converter != null)
            {
                builder = builder
                          .ConvertValue(new InPlaceConvertMutator(topic, null)
                {
                    Columns       = new[] { "age", "height" },
                    TypeConverter = converter,
                });
            }

            return(builder
                   .AggregateOrdered(new SortedMemoryAggregationMutator(topic, null)
            {
                KeyGenerator = row => row.GenerateKey("name"),
                FixColumns = ColumnCopyConfiguration.StraightCopy("name"),
                Operation = op,
            }));
        }
Ejemplo n.º 6
0
        public void NoMatchCustom()
        {
            var topic = TestExecuter.GetTopic();
            var executedBatchCount = 0;
            var builder            = ProcessBuilder.Fluent
                                     .ReadFrom(TestData.Person(topic))
                                     .JoinBatched(new BatchedJoinMutator(topic, null)
            {
                BatchSize     = 4,
                LookupBuilder = new FilteredRowLookupBuilder()
                {
                    ProcessCreator = filterRows =>
                    {
                        executedBatchCount++;
                        return(TestData.PersonEyeColor(topic));
                    },
                    KeyGenerator = row => row.GenerateKey("personId"),
                },
                RowKeyGenerator = row => row.GenerateKey("id"),
                NoMatchAction   = new NoMatchAction(MatchMode.Custom)
                {
                    CustomAction = (proc, row) => row.SetValue("eyeColor", "not found"),
                },
                ColumnConfiguration = ColumnCopyConfiguration.StraightCopy("color"),
            });

            var result = TestExecuter.Execute(builder);

            Assert.AreEqual(2, executedBatchCount);
            Assert.AreEqual(10, result.MutatedRows.Count);
            Assert.That.ExactMatch(result.MutatedRows, new List <CaseInsensitiveStringKeyDictionary <object> >()
            {
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 0, ["name"] = "A", ["age"] = 17, ["height"] = 160, ["eyeColor"] = "brown", ["countryId"] = 1, ["birthDate"] = new DateTime(2010, 12, 9, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 12, 0, 1, 0), ["color"] = "yellow"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 0, ["name"] = "A", ["age"] = 17, ["height"] = 160, ["eyeColor"] = "brown", ["countryId"] = 1, ["birthDate"] = new DateTime(2010, 12, 9, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 12, 0, 1, 0), ["color"] = "red"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 0, ["name"] = "A", ["age"] = 17, ["height"] = 160, ["eyeColor"] = "brown", ["countryId"] = 1, ["birthDate"] = new DateTime(2010, 12, 9, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 12, 0, 1, 0), ["color"] = "green"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 1, ["name"] = "B", ["age"] = 8, ["height"] = 190, ["countryId"] = 1, ["birthDate"] = new DateTime(2011, 2, 1, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 13, 2, 0, 0), ["color"] = "blue"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 1, ["name"] = "B", ["age"] = 8, ["height"] = 190, ["countryId"] = 1, ["birthDate"] = new DateTime(2011, 2, 1, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 12, 19, 13, 2, 0, 0), ["color"] = "yellow"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 2, ["name"] = "C", ["age"] = 27, ["height"] = 170, ["eyeColor"] = "green", ["countryId"] = 2, ["birthDate"] = new DateTime(2014, 1, 21, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2015, 11, 21, 17, 11, 58, 0), ["color"] = "black"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 3, ["name"] = "D", ["age"] = 39, ["height"] = 160, ["eyeColor"] = "not found", ["birthDate"] = "2018.07.11", ["lastChangedTime"] = new DateTime(2017, 8, 1, 4, 9, 1, 0)
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 4, ["name"] = "E", ["age"] = -3, ["height"] = 160, ["countryId"] = 1, ["lastChangedTime"] = new DateTime(2019, 1, 1, 23, 59, 59, 0), ["eyeColor"] = "not found"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 5, ["name"] = "A", ["age"] = 11, ["height"] = 140, ["birthDate"] = new DateTime(2013, 5, 15, 0, 0, 0, 0), ["lastChangedTime"] = new DateTime(2018, 1, 1, 0, 0, 0, 0), ["eyeColor"] = "not found"
                },
                new CaseInsensitiveStringKeyDictionary <object>()
                {
                    ["id"] = 6, ["name"] = "fake", ["height"] = 140, ["countryId"] = 5, ["birthDate"] = new DateTime(2018, 1, 9, 0, 0, 0, 0), ["eyeColor"] = "not found"
                }
            });
            var exceptions = topic.Context.GetExceptions();

            Assert.AreEqual(0, exceptions.Count);
        }