Repository: reef Updated Branches: refs/heads/contextcheck [created] ead50ea6d
hi Project: http://git-wip-us.apache.org/repos/asf/reef/repo Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/62168b28 Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/62168b28 Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/62168b28 Branch: refs/heads/contextcheck Commit: 62168b286b4d3e0508d5dd897dce6fa45100f7a9 Parents: c27ea42 Author: Dhruv <[email protected]> Authored: Wed Mar 23 10:32:03 2016 -0700 Committer: Dhruv <[email protected]> Committed: Wed Mar 23 10:32:03 2016 -0700 ---------------------------------------------------------------------- .../Org.Apache.REEF.Bridge.vcxproj.user | 4 + .../Functional/ContextStacking/ContextInput.cs | 37 ++++++ .../ContextStacking/ContextStackingDriver.cs | 115 +++++++++++++++++++ .../Functional/ContextStacking/ContextStart.cs | 42 +++++++ .../ContextStacking/TestContextStacking.cs | 87 ++++++++++++++ .../Org.Apache.REEF.Tests.csproj | 4 + lang/cs/Org.Apache.REEF.sln | Bin 34618 -> 34622 bytes 7 files changed, 289 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/reef/blob/62168b28/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj.user ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj.user b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj.user new file mode 100644 index 0000000..ef5ff2a --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Bridge/Org.Apache.REEF.Bridge.vcxproj.user @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup /> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/62168b28/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextInput.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextInput.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextInput.cs new file mode 100644 index 0000000..d6b6876 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextInput.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Tests.Functional.ContextStacking +{ + internal interface IContextInput<T> + { + int Counter(); + } + + internal class ContextInput<T> : IContextInput<T> + { + private static readonly Logger Logger = Logger.GetLogger(typeof(ContextInput<T>)); + private static int s_staticCounter = 0; + + [Inject] + internal ContextInput() + { + s_staticCounter++; + Logger.Log(Level.Info, string.Format("Entering context input constructor with counter {0}", s_staticCounter)); + if (s_staticCounter == 2) + { + throw new Exception("Entered the constructor twice"); + } + } + + public int Counter() + { + return s_staticCounter; + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/62168b28/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextStackingDriver.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextStackingDriver.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextStackingDriver.cs new file mode 100644 index 0000000..a3c5c6f --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextStackingDriver.cs @@ -0,0 +1,115 @@ +// 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; +using System.Globalization; +using Org.Apache.REEF.Common.Context; +using Org.Apache.REEF.Common.Events; +using Org.Apache.REEF.Common.Services; +using Org.Apache.REEF.Common.Tasks; +using Org.Apache.REEF.Driver; +using Org.Apache.REEF.Driver.Context; +using Org.Apache.REEF.Driver.Evaluator; +using Org.Apache.REEF.Driver.Task; +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.Tests.Functional.Messaging; +using Org.Apache.REEF.Utilities; +using Org.Apache.REEF.Utilities.Diagnostics; +using Org.Apache.REEF.Utilities.Logging; +using IRunningTask = Org.Apache.REEF.Driver.Task.IRunningTask; + +namespace Org.Apache.REEF.Tests.Functional.ContextStacking +{ + public class ContextStackingDriver : + IObserver<IAllocatedEvaluator>, + IObserver<IActiveContext>, + IObserver<IDriverStarted> + { + public const int NumberOfEvaluator = 1; + private static readonly Logger Logger = Logger.GetLogger(typeof(ContextStackingDriver)); + private readonly IEvaluatorRequestor _evaluatorRequestor; + + [Inject] + public ContextStackingDriver(IEvaluatorRequestor evaluatorRequestor) + { + _evaluatorRequestor = evaluatorRequestor; + } + public void OnNext(IAllocatedEvaluator eval) + { + var contextConf = + ContextConfiguration.ConfigurationModule.Set(ContextConfiguration.Identifier, "Stage1").Build(); + + var serviceConf = + TangFactory.GetTang() + .NewConfigurationBuilder(ServiceConfiguration.ConfigurationModule.Build()) + .BindSetEntry<ContextConfigurationOptions.StartHandlers, ContextStart<int>, IObserver<IContextStart>>( + GenericType<ContextConfigurationOptions.StartHandlers>.Class, + GenericType<ContextStart<int>>.Class) + .BindImplementation(GenericType<IContextInput<int>>.Class, GenericType<ContextInput<int>>.Class) + .Build(); + + eval.SubmitContextAndService(contextConf, serviceConf); + } + + public void OnNext(IActiveContext context) + { + if (context.Id.Equals("Stage1")) + { + var contextConf = + ContextConfiguration.ConfigurationModule.Set(ContextConfiguration.Identifier, "Stage2").Build(); + context.SubmitContext(contextConf); + } + else + { + if (context.Id.Equals("Stage2")) + { + Logger.Log(Level.Info, "Activated both contexts. Exiting"); + context.Dispose(); + } + else + { + throw new Exception("Invalid context ID"); + } + } + } + + public void OnNext(IDriverStarted value) + { + var request = + _evaluatorRequestor.NewBuilder() + .SetNumber(NumberOfEvaluator) + .SetMegabytes(512) + .SetCores(2) + .SetRackName("WonderlandRack") + .SetEvaluatorBatchId("TaskContextStack") + .Build(); + _evaluatorRequestor.Submit(request); + } + + public void OnCompleted() + { + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/62168b28/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextStart.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextStart.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextStart.cs new file mode 100644 index 0000000..f601816 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/ContextStart.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Org.Apache.REEF.Common.Events; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Utilities.Logging; + +namespace Org.Apache.REEF.Tests.Functional.ContextStacking +{ + internal class ContextStart<T> : IObserver<IContextStart> + { + private static readonly Logger Logger = Logger.GetLogger(typeof(ContextStart<T>)); + private static int s_counter = 0; + + [Inject] + private ContextStart(IContextInput<T> contextInput) + { + s_counter++; + Logger.Log(Level.Info, string.Format("Entering context start constructor with counter {0}", s_counter)); + if (s_counter == 2) + { + throw new Exception("Entered the constructor twice"); + } + } + + public void OnNext(IContextStart value) + { + } + + public void OnError(Exception error) + { + throw new NotImplementedException(); + } + + public void OnCompleted() + { + throw new NotImplementedException(); + } + } +} http://git-wip-us.apache.org/repos/asf/reef/blob/62168b28/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/TestContextStacking.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/TestContextStacking.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/TestContextStacking.cs new file mode 100644 index 0000000..363bc58 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tests/Functional/ContextStacking/TestContextStacking.cs @@ -0,0 +1,87 @@ +// 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; +using System.Collections.Generic; +using Org.Apache.REEF.Driver; +using Org.Apache.REEF.Driver.Bridge; +using Org.Apache.REEF.Driver.Defaults; +using Org.Apache.REEF.Network.Naming; +using Org.Apache.REEF.Tang.Implementations.Configuration; +using Org.Apache.REEF.Tang.Implementations.Tang; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Util; +using Org.Apache.REEF.Utilities.Logging; +using Xunit; + +namespace Org.Apache.REEF.Tests.Functional.ContextStacking +{ + [Collection("FunctionalTests")] + public class TestContextStacking : ReefFunctionalTest + { + public TestContextStacking() + { + CleanUp(); + Init(); + } + + /// <summary> + /// This test is to test if the context stack works or not. Specifically constructor of + /// ContextStartHandler of base context and service should be called only once + /// </summary> + [Fact] + [Trait("Priority", "1")] + [Trait("Category", "FunctionalGated")] + [Trait("Description", "Test comtext stacking")] + public void TestReefContextStacking() + { + string testFolder = DefaultRuntimeFolder + Guid.NewGuid(); + CleanUp(testFolder); + TestRun(DriverConfigurations(), typeof(ContextStackingDriver), 1, "simpleHandler", "local", testFolder); + ValidateSuccessForLocalRuntime(1, testFolder: testFolder); + + var messages = new List<string>(); + messages.Add("Activated both contexts. Exiting"); + ValidateMessageSuccessfullyLogged(messages, "driver", DriverStdout, testFolder, 0); + + var messages2 = new List<string>(); + messages.Add("Entering context input constructor with counter 1"); + messages.Add("Entering context start constructor with counter 1"); + ValidateMessageSuccessfullyLogged(messages2, "Node-*", EvaluatorStdout, testFolder, 0); + + CleanUp(testFolder); + } + + public IConfiguration DriverConfigurations() + { + IConfiguration driverConfig = DriverConfiguration.ConfigurationModule + .Set(DriverConfiguration.OnDriverStarted, GenericType<ContextStackingDriver>.Class) + .Set(DriverConfiguration.OnEvaluatorAllocated, GenericType<ContextStackingDriver>.Class) + .Set(DriverConfiguration.OnContextActive, GenericType<ContextStackingDriver>.Class) + .Set(DriverConfiguration.CustomTraceListeners, GenericType<DefaultCustomTraceListener>.Class) + .Set(DriverConfiguration.CustomTraceLevel, Level.Info.ToString()) + .Build(); + + IConfiguration taskConfig = TangFactory.GetTang().NewConfigurationBuilder() + .BindSetEntry<DriverBridgeConfigurationOptions.SetOfAssemblies, string>(typeof(ContextInput<>).Assembly.GetName().Name) + .BindSetEntry<DriverBridgeConfigurationOptions.SetOfAssemblies, string>(typeof(NameClient).Assembly.GetName().Name) + .Build(); + + return Configurations.Merge(driverConfig, taskConfig); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/reef/blob/62168b28/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj b/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj index 0bc15e6..4b11e63 100644 --- a/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj +++ b/lang/cs/Org.Apache.REEF.Tests/Org.Apache.REEF.Tests.csproj @@ -82,7 +82,11 @@ under the License. <Compile Include="Functional\Bridge\TestSimpleContext.cs" /> <Compile Include="Functional\Bridge\TestSimpleEventHandlers.cs" /> <Compile Include="Functional\Bridge\TestSuspendTask.cs" /> + <Compile Include="Functional\ContextStacking\ContextInput.cs" /> + <Compile Include="Functional\ContextStacking\ContextStart.cs" /> <Compile Include="Functional\Driver\DriverTestStartHandler.cs" /> + <Compile Include="Functional\ContextStacking\ContextStackingDriver.cs" /> + <Compile Include="Functional\ContextStacking\TestContextStacking.cs" /> <Compile Include="Functional\RuntimeName\EvaluatorRequestingDriver.cs" /> <Compile Include="Functional\Driver\TestDriver.cs" /> <Compile Include="Functional\Messaging\MessageDriver.cs" /> http://git-wip-us.apache.org/repos/asf/reef/blob/62168b28/lang/cs/Org.Apache.REEF.sln ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.sln b/lang/cs/Org.Apache.REEF.sln index 41932c1..c35d469 100644 Binary files a/lang/cs/Org.Apache.REEF.sln and b/lang/cs/Org.Apache.REEF.sln differ
