You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2017/03/21 04:59:00 UTC

reef git commit: [REEF-1473] Fix CanRunClrBridgeExampleOnLocalRuntime failures in AppVeyor

Repository: reef
Updated Branches:
  refs/heads/master 9fdaed216 -> e851c4614


[REEF-1473] Fix CanRunClrBridgeExampleOnLocalRuntime failures in AppVeyor

* Add retry in getting driverurl before sending http request
* Not to closet the context until receives client's request and all tasks are
  completed to ensure the web request can be received by the driver before the
  driver is shut down.

JIRA:
  [REEF-1473](https://issues.apache.org/jira/browse/REEF-1473)

Pull Request:
  This closes #1269


Project: http://git-wip-us.apache.org/repos/asf/reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/reef/commit/e851c461
Tree: http://git-wip-us.apache.org/repos/asf/reef/tree/e851c461
Diff: http://git-wip-us.apache.org/repos/asf/reef/diff/e851c461

Branch: refs/heads/master
Commit: e851c4614b518bc9e7f690677f6dbde4f0741e98
Parents: 9fdaed2
Author: Julia Wang <ju...@apache.org>
Authored: Fri Mar 17 18:59:44 2017 -0700
Committer: Markus Weimer <we...@apache.org>
Committed: Mon Mar 20 21:57:30 2017 -0700

----------------------------------------------------------------------
 .../AllHandlers.cs                              |  1 +
 .../HelloTaskCompletedHandler.cs                | 47 ++++++++++++++++++--
 .../Functional/Bridge/TestBridgeClient.cs       | 29 +++++++++---
 3 files changed, 67 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/reef/blob/e851c461/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AllHandlers.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AllHandlers.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AllHandlers.cs
index 3e07cf3..97b3603 100644
--- a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AllHandlers.cs
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/AllHandlers.cs
@@ -59,6 +59,7 @@ namespace Org.Apache.REEF.Examples.AllHandlers
                 .Set(DriverConfiguration.OnTaskCompleted, GenericType<HelloTaskCompletedHandler>.Class)
                 .Set(DriverConfiguration.OnDriverStarted, GenericType<HelloDriverStartHandler>.Class)
                 .Set(DriverConfiguration.OnHttpEvent, GenericType<HelloHttpHandler>.Class)
+                .Set(DriverConfiguration.OnHttpEvent, GenericType<HelloTaskCompletedHandler>.Class)
                 .Set(DriverConfiguration.OnEvaluatorCompleted, GenericType<HelloCompletedEvaluatorHandler>.Class)
                 .Set(DriverConfiguration.CustomTraceListeners, GenericType<DefaultCustomTraceListener>.Class)
                 .Set(DriverConfiguration.CustomTraceLevel, Level.Info.ToString())

http://git-wip-us.apache.org/repos/asf/reef/blob/e851c461/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTaskCompletedHandler.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTaskCompletedHandler.cs b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTaskCompletedHandler.cs
index 4fc14a6..e2d0969 100644
--- a/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTaskCompletedHandler.cs
+++ b/lang/cs/Org.Apache.REEF.Examples.AllHandlers/HelloTaskCompletedHandler.cs
@@ -16,16 +16,27 @@
 // under the License.
 
 using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Net;
+using System.Threading;
+using Org.Apache.REEF.Driver.Bridge;
 using Org.Apache.REEF.Driver.Task;
 using Org.Apache.REEF.Tang.Annotations;
+using Org.Apache.REEF.Utilities;
+using Org.Apache.REEF.Utilities.Logging;
 
 namespace Org.Apache.REEF.Examples.AllHandlers
 {
     /// <summary>
     /// A sample implementation of TaskCompletedHandler
     /// </summary>
-    public sealed class HelloTaskCompletedHandler : IObserver<ICompletedTask>
+    public sealed class HelloTaskCompletedHandler : IObserver<ICompletedTask>, IHttpHandler
     {
+        private static readonly Logger Logger = Logger.GetLogger(typeof(HelloTaskCompletedHandler));
+
+        private readonly IList<ICompletedTask> _completedTasks = new List<ICompletedTask>();
+
         [Inject]
         private HelloTaskCompletedHandler()
         {
@@ -38,9 +49,7 @@ namespace Org.Apache.REEF.Examples.AllHandlers
         public void OnNext(ICompletedTask completedTask)
         {
             Console.WriteLine("Received CompletedTask: {0}", completedTask.Id);
-            using (completedTask.ActiveContext)
-            {
-            }
+            _completedTasks.Add(completedTask);
         }
 
         public void OnError(Exception error)
@@ -52,5 +61,35 @@ namespace Org.Apache.REEF.Examples.AllHandlers
         {
             throw new NotImplementedException();
         }
+
+        public string GetSpecification()
+        {
+            return "CMD";
+        }
+
+        /// <summary>
+        /// It gets HTTP request and close the contexts after receiving all the completed tasks
+        /// </summary>
+        /// <param name="requet"></param>
+        /// <param name="resonse"></param>
+        public void OnHttpRequest(ReefHttpRequest requet, ReefHttpResponse resonse)
+        {
+            var msg = string.Format(CultureInfo.CurrentCulture,
+                      "HelloTaskCompletedHandler OnHttpRequest: URL: {0}, QueryString: {1}, inputStream: {2}.",
+                      requet.Url, requet.Querystring, ByteUtilities.ByteArraysToString(requet.InputStream));
+            Logger.Log(Level.Info, msg);
+            resonse.Status = HttpStatusCode.OK;
+            while (_completedTasks.Count != 2)
+            {
+                Thread.Sleep(1000);
+                Logger.Log(Level.Info, "_completedTasks received:" + _completedTasks.Count);
+            }
+            resonse.OutputStream = ByteUtilities.StringToByteArrays("Stopped!!!");
+            foreach (var t in _completedTasks)
+            {
+                t.ActiveContext.Dispose();
+            }
+            _completedTasks.Clear();
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/reef/blob/e851c461/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestBridgeClient.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestBridgeClient.cs b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestBridgeClient.cs
index be6bfc1..a591334 100644
--- a/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestBridgeClient.cs
+++ b/lang/cs/Org.Apache.REEF.Tests/Functional/Bridge/TestBridgeClient.cs
@@ -40,7 +40,6 @@ namespace Org.Apache.REEF.Tests.Functional.Bridge
         [Trait("Priority", "1")]
         [Trait("Category", "FunctionalGated")]
         [Trait("Description", "Run CLR Bridge on local runtime")]
-        //// TODO[JIRA REEF-1184]: add timeout 180 sec
         public async Task CanRunClrBridgeExampleOnLocalRuntime()
         {
             string testRuntimeFolder = DefaultRuntimeFolder + TestId;
@@ -54,12 +53,30 @@ namespace Org.Apache.REEF.Tests.Functional.Bridge
             string[] a = { runOnYarn ? "yarn" : "local", testRuntimeFolder };
             IJobSubmissionResult driverHttpEndpoint = AllHandlers.Run(a);
 
-            var uri = driverHttpEndpoint.DriverUrl + "NRT/status?a=1&b=2";
-            var strStatus = driverHttpEndpoint.GetUrlResult(uri);
-            Assert.NotNull(strStatus);
-            Assert.True(strStatus.Equals("Byte array returned from HelloHttpHandler in CLR!!!\r\n"));
+            var driverUrl = driverHttpEndpoint.DriverUrl;
 
-            await((JobSubmissionResult)driverHttpEndpoint).TryUntilNoConnection(uri);
+            int retryCount = 1;
+            while (string.IsNullOrEmpty(driverUrl) && retryCount < 10)
+            {
+                driverUrl = driverHttpEndpoint.DriverUrl;
+                retryCount++;
+            }
+
+            if (driverUrl != null)
+            {
+                var uri = driverUrl + "NRT/status?a=1&b=2";
+                var strStatus = driverHttpEndpoint.GetUrlResult(uri);
+                Assert.NotNull(strStatus);
+                Assert.True(strStatus.Equals("Byte array returned from HelloHttpHandler in CLR!!!\r\n"));
+
+                var uri1 = driverUrl + "CMD/Stop?c=1";
+                var strStatus1 = driverHttpEndpoint.GetUrlResult(uri1);
+
+                Assert.NotNull(strStatus1);
+                Assert.True(strStatus1.Equals("Stopped!!!\r\n"));
+
+                await((JobSubmissionResult)driverHttpEndpoint).TryUntilNoConnection(uri);
+            }
         }
     }
 }