Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix: BranchingOperation should return all errors from children operations #27

Merged
merged 4 commits into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Rhino.Etl.Core/Operations/BranchingOperation.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Linq;
using Rhino.Etl.Core.Enumerables;
using System.Linq;

namespace Rhino.Etl.Core.Operations
{
using System;
using System.Collections.Generic;

/// <summary>
Expand All @@ -26,7 +27,7 @@ public override IEnumerable<Row> Execute(IEnumerable<Row> rows)

IEnumerable<Row> enumerable = operation.Execute(cloned);

if(enumerable==null)
if (enumerable == null)
continue;

IEnumerator<Row> enumerator = enumerable.GetEnumerator();
Expand All @@ -36,5 +37,25 @@ public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
}
yield break;
}

/// <summary>
/// Get All Errors from child operations
/// </summary>
/// <returns></returns>
public override IEnumerable<Exception> GetAllErrors()
{
foreach (var operation in Operations)
{
foreach (var error in operation.GetAllErrors())
{
yield return error;
}
}

foreach (var error in base.GetAllErrors())
{
yield return error;
}
}
}
}
40 changes: 40 additions & 0 deletions Rhino.Etl.Core/Operations/BranchingOperationWithBug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Rhino.Etl.Core.Enumerables;
using System.Linq;

namespace Rhino.Etl.Core.Operations
{
using System.Collections.Generic;

/// <summary>
/// Branch the current pipeline flow into all its inputs
/// </summary>
public class BranchingOperationWithBug : AbstractBranchingOperation
{
/// <summary>
/// Executes this operation, sending the input of this operation
/// to all its child operations
/// </summary>
/// <param name="rows">The rows.</param>
/// <returns></returns>
public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
var copiedRows = new CachingEnumerable<Row>(rows);

foreach (IOperation operation in Operations)
{
var cloned = copiedRows.Select(r => r.Clone());

IEnumerable<Row> enumerable = operation.Execute(cloned);

if (enumerable == null)
continue;

IEnumerator<Row> enumerator = enumerable.GetEnumerator();
#pragma warning disable 642
while (enumerator.MoveNext()) ;
#pragma warning restore 642
}
yield break;
}
}
}
1 change: 1 addition & 0 deletions Rhino.Etl.Core/Rhino.Etl.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Compile Include="Operations\AbstractJoinOperation.cs" />
<Compile Include="Operations\AbstractSortedAggregationOperation.cs" />
<Compile Include="Operations\BranchingOperation.cs" />
<Compile Include="Operations\BranchingOperationWithBug.cs" />
<Compile Include="Operations\JoinType.cs" />
<Compile Include="Operations\MultiThreadedBranchingOperation.cs" />
<Compile Include="Operations\NestedLoopsJoinOperation.cs" />
Expand Down
78 changes: 39 additions & 39 deletions Rhino.Etl.Tests/Aggregation/AggregationFixture.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
namespace Rhino.Etl.Tests.Aggregation
{
using System.Collections.Generic;
using Core;
using Xunit;


public class AggregationFixture : BaseAggregationFixture
{
[Fact]
public void AggregateRowCount()
{
using (RowCount rowCount = new RowCount())
{
IEnumerable<Row> result = rowCount.Execute(rows);
List<Row> items = new List<Row>(result);
Assert.Equal(1, items.Count);
Assert.Equal(6, items[0]["count"]);
}
}

[Fact]
public void AggregateCostPerProduct()
{
using (CostPerProductAggregation aggregation = new CostPerProductAggregation())
{
IEnumerable<Row> result = aggregation.Execute(rows);
List<Row> items = new List<Row>(result);
Assert.Equal(3, items.Count);
Assert.Equal("milk", items[0]["name"]);
Assert.Equal("sugar", items[1]["name"]);
Assert.Equal("coffee", items[2]["name"]);

Assert.Equal(30, items[0]["cost"]);
Assert.Equal(28, items[1]["cost"]);
Assert.Equal(6, items[2]["cost"]);
}
namespace Rhino.Etl.Tests.Aggregation
{
using System.Collections.Generic;
using Core;
using Xunit;
public class AggregationFixture : BaseAggregationFixture
{
[Fact]
public void AggregateRowCount()
{
using (RowCount rowCount = new RowCount())
{
IEnumerable<Row> result = rowCount.Execute(rows);
List<Row> items = new List<Row>(result);
Assert.Equal(1, items.Count);
Assert.Equal(6, items[0]["count"]);
}
}
[Fact]
public void AggregateCostPerProduct()
{
using (CostPerProductAggregation aggregation = new CostPerProductAggregation())
{
IEnumerable<Row> result = aggregation.Execute(rows);
List<Row> items = new List<Row>(result);
Assert.Equal(3, items.Count);
Assert.Equal("milk", items[0]["name"]);
Assert.Equal("sugar", items[1]["name"]);
Assert.Equal("coffee", items[2]["name"]);
Assert.Equal(30, items[0]["cost"]);
Assert.Equal(28, items[1]["cost"]);
Assert.Equal(6, items[2]["cost"]);
}
}

[Fact]
Expand All @@ -55,6 +55,6 @@ public void SortedAggregateCostPerProduct()
Assert.Equal(6, items[2]["cost"]);
Assert.Equal(3, items[3]["cost"]);
}
}
}
}
}
}
82 changes: 41 additions & 41 deletions Rhino.Etl.Tests/BaseFibonacciTest.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
using System.Data;
using Xunit;
using Rhino.Etl.Core.Infrastructure;

namespace Rhino.Etl.Tests
{
public class BaseFibonacciTest
{
public BaseFibonacciTest()
{
Use.Transaction("test", delegate(IDbCommand cmd)
{
cmd.CommandText =
@"
if object_id('Fibonacci') is not null
drop table Fibonacci
create table Fibonacci ( id int );
";
cmd.ExecuteNonQuery();
});
}

protected static void Assert25ThFibonacci()
{
int max = Use.Transaction("test", delegate(IDbCommand cmd)
{
cmd.CommandText = "SELECT MAX(id) FROM Fibonacci";
return (int) cmd.ExecuteScalar();
});
Assert.Equal(75025, max);
}

protected static void AssertFibonacciTableEmpty()
{
int count = Use.Transaction("test", delegate(IDbCommand cmd)
{
cmd.CommandText = "SELECT count(id) FROM Fibonacci";
return (int) cmd.ExecuteScalar();
});
Assert.Equal(0, count);
}
}
using Xunit;
using Rhino.Etl.Core.Infrastructure;
namespace Rhino.Etl.Tests
{
public class BaseFibonacciTest
{
public BaseFibonacciTest()
{
Use.Transaction("test", delegate(IDbCommand cmd)
{
cmd.CommandText =
@"
if object_id('Fibonacci') is not null
drop table Fibonacci
create table Fibonacci ( id int );
";
cmd.ExecuteNonQuery();
});
}
protected static void Assert25ThFibonacci()
{
int max = Use.Transaction("test", delegate(IDbCommand cmd)
{
cmd.CommandText = "SELECT MAX(id) FROM Fibonacci";
return (int) cmd.ExecuteScalar();
});
Assert.Equal(75025, max);
}
protected static void AssertFibonacciTableEmpty()
{
int count = Use.Transaction("test", delegate(IDbCommand cmd)
{
cmd.CommandText = "SELECT count(id) FROM Fibonacci";
return (int) cmd.ExecuteScalar();
});
Assert.Equal(0, count);
}
}
}
36 changes: 36 additions & 0 deletions Rhino.Etl.Tests/Branches/BranchingOperationFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Rhino.Etl.Core;
using Rhino.Etl.Core.Operations;
using Rhino.Mocks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit;

namespace Rhino.Etl.Tests.Branches
{
public class BranchingOperationFixture
{
[Fact]
public void TheOldBranchingOperationDoesNotReportErrors()
{
using (var process = new BranchingOperationProcess<BranchingOperationWithBug>())
{
process.Execute();
var errors = process.GetAllErrors().Count();
Assert.Equal(0, errors);
}
}

[Fact]
public void TheNewBranchingOperationReportsErrors()
{
using (var process = new BranchingOperationProcess<BranchingOperation>())
{
process.Execute();
var errors = process.GetAllErrors().Count();
Assert.NotEqual(0, errors);
}
}
}
}
Loading