public void TestChainingPicklingWorkerFunction() { var func1 = new PicklingWorkerFunction( new PicklingUdfWrapper <int, string, string>( (number, str) => $"{str}:{number}").Execute); var func2 = new PicklingWorkerFunction( new PicklingUdfWrapper <string, string>( (str) => $"outer1:{str}").Execute); var func3 = new PicklingWorkerFunction( new PicklingUdfWrapper <string, string>( (str) => $"outer2:{str}").Execute); object[] input = { 100, "name" }; // Validate one-level chaining. PicklingWorkerFunction chainedFunc1 = PicklingWorkerFunction.Chain(func1, func2); Assert.Equal("outer1:name:100", chainedFunc1.Func(0, input, new[] { 0, 1 })); // Validate two-level chaining. PicklingWorkerFunction chainedFunc2 = PicklingWorkerFunction.Chain(chainedFunc1, func3); Assert.Equal("outer2:outer1:name:100", chainedFunc2.Func(0, input, new[] { 0, 1 })); }
public void TestPicklingWorkerFunction() { var func = new PicklingWorkerFunction( new PicklingUdfWrapper <string, string>( (str) => str).Execute); string[] input = { "arg1" }; Assert.Equal(input[0], func.Func(0, input, new[] { 0 })); }
public void TestInvalidChainingPickling() { var func1 = new PicklingWorkerFunction( new PicklingUdfWrapper <int, string, string>( (number, str) => $"{str}:{number}").Execute); var func2 = new PicklingWorkerFunction( new PicklingUdfWrapper <string, string>( (str) => $"outer1:{str}").Execute); object[] input = { 100, "name" }; // The order does not align since workerFunction2 is executed first. PicklingWorkerFunction chainedFunc1 = PicklingWorkerFunction.Chain(func2, func1); Assert.ThrowsAny <Exception>(() => chainedFunc1.Func(0, input, new[] { 0, 1 })); }