Repository: reef Updated Branches: refs/heads/master b4595db95 -> c4cb3156e
[REEF-650] Introduce example that actually uses IPerMapperConfigs in IMRU This addressed the issue by * Add new example NaturalSum that uses IPerMapperConfigs * Add in-process test for NaturalSum * Move few common classes to higher directory JIRA: [REEF-650](https://issues.apache.org/jira/browse/REEF-650) Pull Request: Closes #1055 Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/c4cb3156 Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/c4cb3156 Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/c4cb3156 Branch: refs/heads/master Commit: c4cb3156eba40679c4ded1e12fdd4edd3c3d9110 Parents: b4595db Author: Jason (Joo Seong) Jeong <[email protected]> Authored: Fri Jun 24 15:39:42 2016 -0700 Committer: Sergey Dudoladov <[email protected]> Committed: Fri Jul 29 15:13:59 2016 -0700 ---------------------------------------------------------------------- .../IntSumReduceFunction.cs | 45 ++++++++ .../MapperCount/IntSumReduceFunction.cs | 45 -------- .../MapperCount/MapperCount.cs | 2 +- .../MapperCount/MapperCountUpdateFunction.cs | 56 ---------- .../NaturalSum/NaturalSum.cs | 104 +++++++++++++++++++ .../NaturalSum/NaturalSumMapFunction.cs | 46 ++++++++ .../NaturalSumPerMapperConfigGenerator.cs | 55 ++++++++++ .../Org.Apache.REEF.IMRU.Examples.csproj | 7 +- .../SingleIterUpdateFunction.cs | 56 ++++++++++ .../NaturalSumTest.cs | 50 +++++++++ .../Org.Apache.REEF.IMRU.Tests.csproj | 1 + 11 files changed, 363 insertions(+), 104 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Examples/IntSumReduceFunction.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Examples/IntSumReduceFunction.cs b/lang/cs/Org.Apache.REEF.IMRU.Examples/IntSumReduceFunction.cs new file mode 100644 index 0000000..1257ebb --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IMRU.Examples/IntSumReduceFunction.cs @@ -0,0 +1,45 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System.Collections.Generic; +using System.Linq; +using Org.Apache.REEF.Network.Group.Operators; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.IMRU.Examples +{ + /// <summary> + /// A reduce function that sums integers. + /// </summary> + public sealed class IntSumReduceFunction : IReduceFunction<int> + { + [Inject] + private IntSumReduceFunction() + { + } + + /// <summary> + /// Reduce function that returns the sum of elements + /// </summary> + /// <param name="elements">List of elements</param> + /// <returns>The sum of elements</returns> + public int Reduce(IEnumerable<int> elements) + { + return elements.Aggregate((x, y) => x + y); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/IntSumReduceFunction.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/IntSumReduceFunction.cs b/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/IntSumReduceFunction.cs deleted file mode 100644 index 2adbc84..0000000 --- a/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/IntSumReduceFunction.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -using System.Collections.Generic; -using System.Linq; -using Org.Apache.REEF.Network.Group.Operators; -using Org.Apache.REEF.Tang.Annotations; - -namespace Org.Apache.REEF.IMRU.Examples.MapperCount -{ - /// <summary> - /// A reduce function that sums integers. - /// </summary> - public sealed class IntSumReduceFunction : IReduceFunction<int> - { - [Inject] - private IntSumReduceFunction() - { - } - - /// <summary> - /// Reduce function that returns the sum of elements - /// </summary> - /// <param name="elements">List of elements</param> - /// <returns>The sum of elements</returns> - public int Reduce(IEnumerable<int> elements) - { - return elements.Aggregate((x, y) => x + y); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/MapperCount.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/MapperCount.cs b/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/MapperCount.cs index a559ff8..7769cf3 100644 --- a/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/MapperCount.cs +++ b/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/MapperCount.cs @@ -58,7 +58,7 @@ namespace Org.Apache.REEF.IMRU.Examples.MapperCount .SetUpdateFunctionConfiguration( IMRUUpdateConfiguration<int, int, int>.ConfigurationModule .Set(IMRUUpdateConfiguration<int, int, int>.UpdateFunction, - GenericType<MapperCountUpdateFunction>.Class) + GenericType<SingleIterUpdateFunction>.Class) .Build()) .SetMapInputCodecConfiguration(IMRUCodecConfiguration<int>.ConfigurationModule .Set(IMRUCodecConfiguration<int>.Codec, GenericType<IntStreamingCodec>.Class) http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/MapperCountUpdateFunction.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/MapperCountUpdateFunction.cs b/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/MapperCountUpdateFunction.cs deleted file mode 100644 index b337892..0000000 --- a/lang/cs/Org.Apache.REEF.IMRU.Examples/MapperCount/MapperCountUpdateFunction.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -using Org.Apache.REEF.IMRU.API; -using Org.Apache.REEF.Tang.Annotations; - -namespace Org.Apache.REEF.IMRU.Examples.MapperCount -{ - /// <summary> - /// The Update function for the mapper counting job. - /// </summary> - /// <remarks> - /// Upon Initialize(), this sends `1` to all Map Function instances. Each of them returns `1`, which shows up as the - /// parameter passed into `Update`. At that point, we can immediately terminate. - /// </remarks> - public sealed class MapperCountUpdateFunction : IUpdateFunction<int, int, int> - { - [Inject] - private MapperCountUpdateFunction() - { - } - - /// <summary> - /// Update function - /// </summary> - /// <param name="input">Input containing sum of all mappers</param> - /// <returns>The Update Result with only result</returns> - public UpdateResult<int, int> Update(int input) - { - return UpdateResult<int, int>.Done(input); - } - - /// <summary> - /// Initialize function. Sends 1 to all mappers - /// </summary> - /// <returns>Map input</returns> - public UpdateResult<int, int> Initialize() - { - return UpdateResult<int, int>.AnotherRound(1); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSum.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSum.cs b/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSum.cs new file mode 100644 index 0000000..dfc0a66 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSum.cs @@ -0,0 +1,104 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System.IO; +using System.Linq; +using Org.Apache.REEF.IMRU.API; +using Org.Apache.REEF.IMRU.OnREEF.ResultHandler; +using Org.Apache.REEF.IO.PartitionedData.Random; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Tang.Implementations.Tang; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Util; +using Org.Apache.REEF.Wake.StreamingCodec.CommonStreamingCodecs; + +namespace Org.Apache.REEF.IMRU.Examples.NaturalSum +{ + /// <summary> + /// A simple IMRU program that caclulates the sum of natural numbers. + /// </summary> + /// <remarks> + /// This example demonstrates the use of <see cref="IPerMapperConfigGenerator"/>. + /// N mappers are instantiated, each given an integer id (1, 2, 3, ... N) with <see cref="NaturalSumPerMapperConfigGenerator"/>. + /// The map functions simply return the mapper's ids, and the ids get summed up via the reduce function and get passed to the updater. + /// The job finishes after this single iteration. + /// Call the <see cref="Run"/> method to run the example with custom parameters. + /// </remarks> + public sealed class NaturalSum + { + private readonly IIMRUClient _imruClient; + + [Inject] + private NaturalSum(IIMRUClient imruClient) + { + _imruClient = imruClient; + } + + /// <summary> + /// Runs the actual natural sum job. + /// </summary> + /// <returns>The result of the natural sum IMRU job.</returns> + public int Run(int numberofMappers, string outputFile, IConfiguration fileSystemConfig) + { + var results = _imruClient.Submit<int, int, int, Stream>( + new IMRUJobDefinitionBuilder() + .SetMapFunctionConfiguration(IMRUMapConfiguration<int, int>.ConfigurationModule + .Set(IMRUMapConfiguration<int, int>.MapFunction, GenericType<NaturalSumMapFunction>.Class) + .Build()) + .SetUpdateFunctionConfiguration( + IMRUUpdateConfiguration<int, int, int>.ConfigurationModule + .Set(IMRUUpdateConfiguration<int, int, int>.UpdateFunction, + GenericType<SingleIterUpdateFunction>.Class) + .Build()) + .SetMapInputCodecConfiguration(IMRUCodecConfiguration<int>.ConfigurationModule + .Set(IMRUCodecConfiguration<int>.Codec, GenericType<IntStreamingCodec>.Class) + .Build()) + .SetPerMapConfigurations(IMRUPerMapperConfigGeneratorConfiguration.ConfigurationModule + .Set(IMRUPerMapperConfigGeneratorConfiguration.PerMapperConfigGenerator, + GenericType<NaturalSumPerMapperConfigGenerator>.Class) + .Build()) + .SetUpdateFunctionCodecsConfiguration(IMRUCodecConfiguration<int>.ConfigurationModule + .Set(IMRUCodecConfiguration<int>.Codec, GenericType<IntStreamingCodec>.Class) + .Build()) + .SetReduceFunctionConfiguration(IMRUReduceFunctionConfiguration<int>.ConfigurationModule + .Set(IMRUReduceFunctionConfiguration<int>.ReduceFunction, + GenericType<IntSumReduceFunction>.Class) + .Build()) + .SetPartitionedDatasetConfiguration( + RandomInputDataConfiguration.ConfigurationModule.Set( + RandomInputDataConfiguration.NumberOfPartitions, + numberofMappers.ToString()).Build()) + .SetResultHandlerConfiguration( + TangFactory.GetTang() + .NewConfigurationBuilder(fileSystemConfig) + .BindImplementation(GenericType<IIMRUResultHandler<int>>.Class, + GenericType<WriteResultHandler<int>>.Class) + .BindNamedParameter(typeof(ResultOutputLocation), outputFile) + .Build()) + .SetJobName("NaturalSum") + .SetNumberOfMappers(numberofMappers) + .Build()); + + if (results != null) + { + return results.First(); + } + + return -1; + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSumMapFunction.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSumMapFunction.cs b/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSumMapFunction.cs new file mode 100644 index 0000000..66a467b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSumMapFunction.cs @@ -0,0 +1,46 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using Org.Apache.REEF.IMRU.API; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.IMRU.Examples.NaturalSum +{ + /// <summary> + /// Map function that returns its mapper id as output. + /// </summary> + internal sealed class NaturalSumMapFunction : IMapFunction<int, int> + { + private readonly int _mapperId; + + [Inject] + private NaturalSumMapFunction([Parameter(typeof(NaturalSumPerMapperConfigGenerator.MapperId))] int mapperId) + { + _mapperId = mapperId; + } + + /// <summary> + /// Map function that ignores the input and returns this mapper's id as output + /// </summary> + /// <param name="mapInput">input given from the Update function, but is not used</param> + /// <returns>id of this mapper</returns> + public int Map(int mapInput) + { + return _mapperId; + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSumPerMapperConfigGenerator.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSumPerMapperConfigGenerator.cs b/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSumPerMapperConfigGenerator.cs new file mode 100644 index 0000000..6bd1b2f --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IMRU.Examples/NaturalSum/NaturalSumPerMapperConfigGenerator.cs @@ -0,0 +1,55 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using System.Globalization; +using Org.Apache.REEF.IMRU.API; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Tang.Implementations.Tang; +using Org.Apache.REEF.Tang.Interface; + +namespace Org.Apache.REEF.IMRU.Examples.NaturalSum +{ + /// <summary> + /// Configuration generator for assiging unique ids to each mapper. + /// </summary> + internal sealed class NaturalSumPerMapperConfigGenerator : IPerMapperConfigGenerator + { + [Inject] + private NaturalSumPerMapperConfigGenerator() + { + } + + /// <summary> + /// Assign unique mapper id to each mapper. Ids start from 1. + /// </summary> + /// <param name="currentPartitionNumber">partition index of current mapper</param> + /// <param name="totalMappers">number of mappers, not used</param> + /// <returns>Configuration for <code>currentPartitionNumber</code>-th mapper</returns> + public IConfiguration GetMapperConfiguration(int currentPartitionNumber, int totalMappers) + { + var mapperId = currentPartitionNumber + 1; + return TangFactory.GetTang().NewConfigurationBuilder() + .BindNamedParameter(typeof(MapperId), mapperId.ToString(CultureInfo.InvariantCulture)) + .Build(); + } + + [NamedParameter("Id number for each mapper")] + internal sealed class MapperId : Name<int> + { + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Examples/Org.Apache.REEF.IMRU.Examples.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Examples/Org.Apache.REEF.IMRU.Examples.csproj b/lang/cs/Org.Apache.REEF.IMRU.Examples/Org.Apache.REEF.IMRU.Examples.csproj index a125811..1a17903 100644 --- a/lang/cs/Org.Apache.REEF.IMRU.Examples/Org.Apache.REEF.IMRU.Examples.csproj +++ b/lang/cs/Org.Apache.REEF.IMRU.Examples/Org.Apache.REEF.IMRU.Examples.csproj @@ -44,9 +44,12 @@ under the License. </ItemGroup> <ItemGroup> <Compile Include="MapperCount\IdentityMapFunction.cs" /> - <Compile Include="MapperCount\IntSumReduceFunction.cs" /> + <Compile Include="IntSumReduceFunction.cs" /> <Compile Include="MapperCount\MapperCount.cs" /> - <Compile Include="MapperCount\MapperCountUpdateFunction.cs" /> + <Compile Include="SingleIterUpdateFunction.cs" /> + <Compile Include="NaturalSum\NaturalSum.cs" /> + <Compile Include="NaturalSum\NaturalSumMapFunction.cs" /> + <Compile Include="NaturalSum\NaturalSumPerMapperConfigGenerator.cs" /> <Compile Include="OnREEFIMRURunTimeConfiguration.cs" /> <Compile Include="PipelinedBroadcastReduce\BroadcastReceiverReduceSenderMapFunction.cs" /> <Compile Include="PipelinedBroadcastReduce\BroadcastReduceConfiguration.cs" /> http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Examples/SingleIterUpdateFunction.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Examples/SingleIterUpdateFunction.cs b/lang/cs/Org.Apache.REEF.IMRU.Examples/SingleIterUpdateFunction.cs new file mode 100644 index 0000000..9bdfb40 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IMRU.Examples/SingleIterUpdateFunction.cs @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using Org.Apache.REEF.IMRU.API; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.IMRU.Examples +{ + /// <summary> + /// A simple Update function for IMRU examples. + /// </summary> + /// <remarks> + /// Upon Initialize(), this sends `1` to all Map Function instances. Each of them returns some result, which shows up as the + /// parameter passed into `Update`. At that point, we can immediately terminate. + /// </remarks> + public sealed class SingleIterUpdateFunction : IUpdateFunction<int, int, int> + { + [Inject] + private SingleIterUpdateFunction() + { + } + + /// <summary> + /// Update function + /// </summary> + /// <param name="input">Input containing sum of all mapper results</param> + /// <returns>The Update Result with only result</returns> + public UpdateResult<int, int> Update(int input) + { + return UpdateResult<int, int>.Done(input); + } + + /// <summary> + /// Initialize function. Sends 1 to all mappers + /// </summary> + /// <returns>Map input</returns> + public UpdateResult<int, int> Initialize() + { + return UpdateResult<int, int>.AnotherRound(1); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Tests/NaturalSumTest.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Tests/NaturalSumTest.cs b/lang/cs/Org.Apache.REEF.IMRU.Tests/NaturalSumTest.cs new file mode 100644 index 0000000..5188f55 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.IMRU.Tests/NaturalSumTest.cs @@ -0,0 +1,50 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +using Org.Apache.REEF.IMRU.Examples.NaturalSum; +using Org.Apache.REEF.IMRU.InProcess; +using Org.Apache.REEF.Tang.Implementations.Tang; +using Xunit; + +namespace Org.Apache.REEF.IMRU.Tests +{ + /// <summary> + /// Tests of the natural sum job. + /// </summary> + public class NaturalSumTest + { + private const int NumberOfMappers = 7; + + /// <summary> + /// Tests the natural sum job using the in-process IMRU implementation. + /// </summary> + [Fact] + public void TestNaturalSumInProcess() + { + var naturalSumJob = + TangFactory.GetTang() + .NewInjector( + InProcessIMRUConfiguration.ConfigurationModule + .Set(InProcessIMRUConfiguration.NumberOfMappers, NumberOfMappers.ToString()) + .Build()) + .GetInstance<NaturalSum>(); + var result = naturalSumJob.Run(NumberOfMappers, string.Empty, TangFactory.GetTang().NewConfigurationBuilder().Build()); + var expected = NumberOfMappers * (NumberOfMappers + 1) / 2; // expected = 1 + 2 + ... + NumberOfMappers + Assert.True(expected == result, string.Format("The result of the run should be {0} but was {1}.", expected, result)); + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/c4cb3156/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj b/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj index 43e8dfe..4ce072b 100644 --- a/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj +++ b/lang/cs/Org.Apache.REEF.IMRU.Tests/Org.Apache.REEF.IMRU.Tests.csproj @@ -49,6 +49,7 @@ under the License. </ItemGroup> <ItemGroup> <Compile Include="MapInputWithControlMessageTests.cs" /> + <Compile Include="NaturalSumTest.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="MapperCountTest.cs" /> <Compile Include="TestActiveContextManager.cs" />
