public void RemoteExecutorJoinWaitsForPulse() { var remoteServiceMock = new Mock<IRemoteExecutorService>(MockBehavior.Strict); const string MethodResult = "whatever"; var expectedResult = new RemoteExecutorServiceResult() { ExecutorState = ServiceReferences.ExecutorState.Finished, Result = MethodResult }; remoteServiceMock.Setup(rs => rs.Initialize(It.IsAny<byte[]>())).Returns(() => Guid.NewGuid()); remoteServiceMock.Setup(rs => rs.ExecuteAsync(It.IsAny<Guid>(), It.IsAny<object[]>(), It.IsAny<ServiceUri>())).Returns(() => Task.Run(() => { })); remoteServiceMock.Setup(rs => rs.TryJoin(It.IsAny<Guid>())).Returns(expectedResult); var executor = new RemoteExecutor(); executor.Setup(remoteServiceMock.Object, new ServiceUri()); executor.Initialize(() => MethodResult); executor.ExecutorState.ShouldBe(Bluepath.Executor.ExecutorState.NotStarted); executor.Execute(new object[0] { }); executor.ExecutorState.ShouldBe(Bluepath.Executor.ExecutorState.Running); var joinTask = Task.Run(() => { executor.Join(); }); joinTask.Wait(WaitTimeout).ShouldBe(false); executor.Pulse(expectedResult); joinTask.Wait(WaitTimeout).ShouldBe(true); executor.ExecutorState.ShouldBe(Bluepath.Executor.ExecutorState.Finished); executor.Result.ShouldBe(MethodResult); }
/// <summary> /// Invoked after receiving remote callback with 'processing finished' message. /// </summary> /// <param name="result"> /// Result that came along with callback. /// </param> public void Pulse(RemoteExecutorServiceResult result) { lock (this.waitForCallbackLock) { this.callbackReceived = true; // TODO: what do we do in case of second (possibly repeated due to network fault) Pulse? // if(this.callbackResult != null) // { // } // Store callback for retrieval this.callbackResult = result; // Wake up Join which was called before Pulse Monitor.PulseAll(this.waitForCallbackLock); } }
public void ExecuteCallback(Guid eId, RemoteExecutorServiceResult executeResult) { base.ExecuteCallback(eId, executeResult.Convert()); }
// This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. // ReSharper disable once CSharpWarnings::CS1998 public async Task ExecuteCallbackAsync(Guid eId, RemoteExecutorServiceResult executeResult) { this.ExecuteCallback(eId, executeResult); }
public new RemoteExecutorServiceResult TryJoin(Guid eId) { var baseResult = base.TryJoin(eId); var result = new RemoteExecutorServiceResult(); result.ElapsedTime = baseResult.ElapsedTime; result.Error = baseResult.Error; result.ExecutorState = (Bluepath.ServiceReferences.ExecutorState)baseResult.ExecutorState; result.Result = baseResult.Result; return result; }