public void Should_execute_operation_when_AcceptingJobs() { //arrange bool wasCalled = false; var callback = new Action(() => { wasCalled = true; }); //act Executor.Execute(callback); //assert Assert.IsTrue(Executor.AcceptingJobs); Assert.IsTrue(wasCalled); }
protected void ReportError(string errorMessage) { Logger.Error(TAG, errorMessage); _executor.Execute(() => { if (State == WebSocketConnectionState.Error) { return; } State = WebSocketConnectionState.Error; _events.OnWebSocketError(errorMessage); }); }
public ActionResult <string> Execute(QueryParams p) { var s = new XmlSerializer(typeof(DataSet)); string xml; using (var sww = new StringWriter()) { using (var writer = XmlWriter.Create(sww)) { s.Serialize(writer, NormalizeDate(_executor.Execute(p.Query))); xml = sww.ToString(); } } return(Ok(xml)); }
internal Response Excute(Request request) { var requestType = request.requestDescription; IExecutor executor = null; servicesLock.EnterReadLock(); try { methodMaps.TryGetValue(requestType, out executor); } finally { servicesLock.ExitReadLock(); } Response response; if (executor != null) { try { response = executor.Execute(request); response.Id = request.Id; } catch (Exception e) { executorLog.WriteLog("Exception when invoke type : " + executor.GetType().FullName + ", with exception: " + e); response = new ExceptionResponse(request.Id, e); } } else { response = new ExceptionResponse(request.Id, new ServiceNotFoundException(request.ToString())); } return(response); }
public Result Execute(ExprNode node) { if ((node == null) || (node.Expression == null)) { return(new Result(string.Empty)); } IExecutor executor = this.CreateExecutor(node); IExecutor top = executor; this.Push(top); while (top != null) { switch (top.Execute(this)) { case ExecuteAction.End: this.Pop(); break; case ExecuteAction.Exit: return(executor.Result); } top = this.Top; } return(executor.Result); }
protected virtual List <TestResult> ProcessTests( IExecutionContext <TestsInputModel> executionContext, IExecutor executor, IChecker checker, string codeSavePath) { var testResults = new List <TestResult>(); var arguments = new[] { LatestEcmaScriptFeaturesEnabledFlag, codeSavePath }; foreach (var test in executionContext.Input.Tests) { var processExecutionResult = executor.Execute( this.NodeJsExecutablePath, test.Input, executionContext.TimeLimit, executionContext.MemoryLimit, arguments); var testResult = this.ExecuteAndCheckTest( test, processExecutionResult, checker, processExecutionResult.ReceivedOutput); testResults.Add(testResult); } return(testResults); }
public long Run(Stopwatch stopwatch) { var signal = new ManualResetEvent(false); var expectedCount = _batchEventProcessor.Sequence.Value + _iterations; _handler.Reset(signal, _iterations); var processorTask = _executor.Execute(_batchEventProcessor.Run); stopwatch.Start(); var rb = _ringBuffer; for (var i = 0; i < _iterations; i++) { var next = rb.Next(); var @event = rb[next]; for (var j = 0; j < @event.Length; j++) { @event[j] = i; } rb.Publish(next); } signal.WaitOne(); stopwatch.Stop(); WaitForEventProcessorSequence(expectedCount); _batchEventProcessor.Halt(); processorTask.Wait(2000); PerfTestUtil.FailIf(0, _handler.Value, "Handler has not processed any event"); return(_iterations * _arraySize); }
private void Flush() { var toExecute = _queue.DequeueAll(); if (toExecute == null || !toExecute.Any()) { _flushPending = false; return; } var copy = toExecute.ToArray(); _thread.Queue(() => { _executor.Execute(copy); }); lock (_lock) { if (_queue.Count() > 0) { // don't monopolize thread. _thread.Queue(Flush); } else { _flushPending = false; } } }
public void Run() { _currentExecutor = _cmdExecutor; try { _serviceProvider.GetRequiredService <IHistoryProvider>().Initialize(); } catch (Exception ex) { _console.WriteError(ex.ToString()); } const string quoted = @"([""'])(.*?)\1"; const string word = @"\S+"; while (true) { _console.Write(string.Format("\n{0}>", _currentExecutor.GetPrefix())); string line = _console.ReadLine(); if (line.ToLower().Trim() == "exit") { break; } try { var matches = Regex.Matches(line, quoted); List <string> qs = matches.Select(m => m.Value).ToList(); var line1 = Regex.Replace(line, quoted, "'"); var matches1 = Regex.Matches(line1, word); List <string> ags = matches1.Select(m => m.Value).ToList(); int idx = 0; for (int i = 0; i < ags.Count; i++) { if (ags[i] == "'") { ags[i] = qs[idx++].Trim(new char[] { '"', '\'' }); } } if (ags.Count == 0) { continue; } string cmd = ags[0].ToLower().Trim(); ags.RemoveAt(0); var cur = _currentExecutor.Execute(cmd, ags); if (cur != null) { _currentExecutor = cur; } } catch (Exception ex) { _console.WriteError(ex.ToString()); } } }
public static T Execute(IEnumerable <IExecutor <T> > processes, T processItem) { if (processItem == null) { return(default(T)); } IExecutor <T> root = null; IExecutor <T> previous = null; foreach (IExecutor <T> step in _GetNextProcessStep(processes)) { if (root == null) { root = step; } else { previous.Register(step); } previous = step; } return(root == null ? default(T) : root.Execute(processItem)); }
protected virtual ProcessExecutionResult ExecuteNodeJsProcess( ExecutionContext executionContext, IExecutor executor, string input, IEnumerable <string> additionalArguments) { var processExecutionResult = executor.Execute( this.NodeJsExecutablePath, input, executionContext.TimeLimit + this.BaseTimeUsed, executionContext.MemoryLimit + this.BaseMemoryUsed, additionalArguments); // No update of time and memory when the result is TimeLimit or MemoryLimit - show how wasteful the solution is if (processExecutionResult.Type != ProcessExecutionResultType.TimeLimit && processExecutionResult.Type != ProcessExecutionResultType.MemoryLimit) { processExecutionResult.TimeWorked = processExecutionResult.TimeWorked.TotalMilliseconds > this.BaseTimeUsed ? processExecutionResult.TimeWorked - TimeSpan.FromMilliseconds(this.BaseTimeUsed) : TimeSpan.FromMilliseconds(this.BaseTimeUsed); processExecutionResult.MemoryUsed = Math.Max(processExecutionResult.MemoryUsed - this.BaseMemoryUsed, this.BaseMemoryUsed); } return(processExecutionResult); }
public override bool Dispatch(IMessage message) { int sequenceNumber = 1; int sequenceSize = _handlers.Count; foreach (IMessageHandler handler in _handlers) { IMessage messageToSend = (!_applySequence) ? message : MessageBuilder.FromMessage(message) .SetSequenceNumber(sequenceNumber++) .SetSequenceSize(sequenceSize) .Build(); IExecutor executor = TaskExecutor; if (executor != null) { // copy to local variable, because C# does not have real lexical closures. // see http://blogs.msdn.com/abhinaba/archive/2005/10/18/482180.aspx for an // explanation IMessageHandler closure = handler; executor.Execute(delegate { SendMessageToHandler(messageToSend, closure); }); } else { SendMessageToHandler(messageToSend, handler); } } return(true); }
protected override void HandleCore(IExecutor executor) { if (executor == null) { HandleCore(); } if (executor != null || executor.InLoop) { try { Handler.Handle(); Completed(); } catch (Exception ex) { ExceptionCaught(ex); } } else { executor.Execute(() => { try { Handler.Handle(); Completed(); } catch (Exception ex) { ExceptionCaught(ex); } }); } }
public long Run(Stopwatch stopwatch) { var latch = new Barrier(_numEventProcessors + 1); var processorTasks = new List <Task>(); for (var i = 0; i < _numEventProcessors; i++) { _handlers[i].Reset(latch, _batchEventProcessors[i].Sequence.Value + _iterations); processorTasks.Add(_executor.Execute(_batchEventProcessors[i].Run)); } stopwatch.Start(); for (long i = 0; i < _iterations; i++) { var sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = i; _ringBuffer.Publish(sequence); } latch.SignalAndWait(); stopwatch.Stop(); for (var i = 0; i < _numEventProcessors; i++) { _batchEventProcessors[i].Halt(); PerfTestUtil.FailIfNot(_results[i], _handlers[i].Value, $"Result {_results[i]} != {_handlers[i].Value}"); } Task.WaitAll(processorTasks.ToArray()); return(_numEventProcessors * _iterations); }
/// <summary> /// ExecutePaginated sql file most simple /// </summary> static void ExecuteSimple(IExecutor executor) { // create parameter object instance for 2-way-sql var condition = new SqlCondition { MiddleNames = new List <string> { "A", "J", "M" } }; var watch = new Stopwatch(); watch.Start(); // create SqlParse instance var parser = new SqlParser(FilePath, condition); // parse sql file var result = parser.Parse(); watch.Stop(); Console.WriteLine($"time\t{watch.Elapsed}"); watch.Reset(); watch.Start(); Debug.WriteLine($"+++>{result.DebugSql}"); executor.Execute(ConnectionString, result); watch.Stop(); Console.WriteLine($"time\t{watch.Elapsed}"); }
internal Response Excute(Request request) { var response = new Response { Id = request.Id }; var methodDescriptionBuilder = request.RequestDescription; IExecutor executor = null; servicesLock.EnterReadLock(); try { methodMaps.TryGetValue(methodDescriptionBuilder, out executor); } finally { servicesLock.ExitReadLock(); } if (executor == null) { response.ResultException = new MethodNotFoundException(request.ServiceName, request.ReceiverMethod); return(response); } try { response.Result = executor.Execute(request.Parameters); } catch (Exception e) { executorLog.WriteLog("Exception when invoke type : " + executor.GetType().FullName + ", with exception: " + e); response.ResultException = new MethodInvokingException(executor.GetType().FullName, request.ReceiverMethod, e); return(response); } return(response); }
public void DumpResult_RunCommand_CorrectResultInFile() { resulter.DumpResult("Test2", Enumerable.Repeat(executor.Execute("test"), 1)); File.ReadAllText("Test2." + FileResult.FileResultPath).Should() .Be("Done!" + Environment.NewLine + Environment.NewLine); File.Delete("Test2." + FileResult.FileResultPath); }
protected ExecutionResult CompileExecuteAndCheck(ExecutionContext executionContext, Func <CompilerType, string> getCompilerPathFunc, IExecutor executor) { var result = new ExecutionResult(); // Compile the file var compilerResult = this.ExecuteCompiling(executionContext, getCompilerPathFunc, result); if (!compilerResult.IsCompiledSuccessfully) { return(result); } var outputFile = compilerResult.OutputFile; // Execute and check each test IChecker checker = Checker.CreateChecker(executionContext.CheckerAssemblyName, executionContext.CheckerTypeName, executionContext.CheckerParameter); foreach (var test in executionContext.Tests) { var processExecutionResult = executor.Execute(outputFile, test.Input, executionContext.TimeLimit, executionContext.MemoryLimit); var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, processExecutionResult.ReceivedOutput); result.TestResults.Add(testResult); } // Clean our mess File.Delete(outputFile); return(result); }
public long Run(ThroughputSessionContext sessionContext) { long expectedCount = _batchEventProcessor.Sequence.Value + _iterations; _latch.Reset(); _eventHandler.Reset(_latch, expectedCount); var processorTask = _executor.Execute(_batchEventProcessor.Run); _batchEventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5)); sessionContext.Start(); for (long i = 0; i < _iterations; i++) { long sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = i; _ringBuffer.Publish(sequence); } _latch.WaitOne(); sessionContext.Stop(); PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _batchEventProcessor); _batchEventProcessor.Halt(); processorTask.Wait(2000); sessionContext.SetBatchData(_eventHandler.BatchesProcessedCount, _iterations); PerfTestUtil.FailIfNot(_expectedResult, _eventHandler.Value, $"Handler should have processed {_expectedResult} events, but was: {_eventHandler.Value}"); return(_iterations); }
public long Run(Stopwatch stopwatch) { long expectedCount = _batchEventProcessor.Sequence.Value + _iterations; _latch.Reset(); _eventHandler.Reset(_latch, expectedCount); var processorTask = _executor.Execute(_batchEventProcessor.Run); stopwatch.Start(); for (long i = 0; i < _iterations; i++) { long sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = i; _ringBuffer.Publish(sequence); } _latch.WaitOne(); stopwatch.Stop(); PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _batchEventProcessor); _batchEventProcessor.Halt(); processorTask.Wait(2000); PerfTestUtil.FailIfNot(_expectedResult, _eventHandler.Value, $"Handler should have processed {_expectedResult} events, but was: {_eventHandler.Value}"); return(_iterations); }
public Result Execute(ExprNode node) { if ((node == null) || (node.Expression == null)) { return(new Result(string.Empty)); } IExecutor start = this.CreateExecutor(node); IExecutor executor = start; this.Push(executor); while (executor != null) { ExecuteAction result = executor.Execute(this); if (result == ExecuteAction.End) { this.Pop(); } else if (result == ExecuteAction.Exit) { return(start.Result); } executor = this.Top; } return(start.Result); }
protected virtual ProcessExecutionResult ExecuteNodeJsProcess( ExecutionContext executionContext, IExecutor executor, string input, IEnumerable <string> additionalArguments) { var processExecutionResult = executor.Execute( this.NodeJsExecutablePath, input, executionContext.TimeLimit + this.BaseTimeUsed, executionContext.MemoryLimit + this.BaseMemoryUsed, additionalArguments); processExecutionResult.MemoryUsed = Math.Max(processExecutionResult.MemoryUsed - this.BaseMemoryUsed, this.BaseMemoryUsed); // Display the TimeWorked, when the process was killed for being too slow (TotalProcessorTime is still usually under the timeLimit when a process is killed), // otherwise display TotalProcessorTime, so people have an acurate idea of the time their program used if (processExecutionResult.ProcessWasKilled) { processExecutionResult.TimeWorked = processExecutionResult.TimeWorked.TotalMilliseconds > this.BaseTimeUsed ? processExecutionResult.TimeWorked - TimeSpan.FromMilliseconds(this.BaseTimeUsed) : processExecutionResult.TimeWorked; } else { processExecutionResult.TimeWorked = processExecutionResult.TotalProcessorTime.TotalMilliseconds > this.BaseTimeUsed ? processExecutionResult.TotalProcessorTime - TimeSpan.FromMilliseconds(this.BaseTimeUsed) : processExecutionResult.TotalProcessorTime; } return(processExecutionResult); }
public long Run(ThroughputSessionContext sessionContext) { var latch = new ManualResetEvent(false); var expectedCount = _poller.Sequence.Value + _iterations; _pollRunnable.Reset(latch, expectedCount); var processorTask = _executor.Execute(_pollRunnable.Run); sessionContext.Start(); var rb = _ringBuffer; for (var i = 0; i < _iterations; i++) { var next = rb.Next(); rb[next].Value = i; rb.Publish(next); } latch.WaitOne(); sessionContext.Stop(); WaitForEventProcessorSequence(expectedCount); _pollRunnable.Halt(); processorTask.Wait(2000); sessionContext.SetBatchData(_pollRunnable.BatchesProcessedCount.Value, _iterations); PerfTestUtil.FailIfNot(_expectedResult, _pollRunnable.Value, $"Poll runnable should have processed {_expectedResult} but was {_pollRunnable.Value}"); return(_iterations); }
public static T Execute(IEnumerable <IExecutor <T> > processes, T processItem) { if (processItem == null) { return(default(T)); } IExecutor <T> root = null; IExecutor <T> previous = null; foreach (IExecutor <T> rule in _GetRules(processes)) { if (root == null) { root = rule; } else { previous.Register(rule); } previous = rule; } return(root == null ? default(T) : root.Execute(processItem)); }
protected override void PersistEvent(IEnumerable <EventObject> eventObjects, Guid aggregateId, int expectedVersion) { foreach (var snapshotObject in eventObjects) { _transExecutor.NonQuery(Queries.InsertEventSql, new Dictionary <string, object> { { "SourceId", snapshotObject.SourceId }, { "Version", snapshotObject.Version }, { "Timestamp", snapshotObject.Timestamp }, { "Type", snapshotObject.Type }, { "Data", snapshotObject.Data }, }, rowsAffected => { const int expectedRows = 1; if (expectedRows != rowsAffected) { throw new AffectedRowsException(rowsAffected, expectedRows, "事件源"); } }); } _transExecutor.Execute(); }
public long Run(Stopwatch stopwatch) { var signal = new ManualResetEvent(false); var expectedCount = _batchEventProcessor.Sequence.Value + _iterations * _batchSize; _handler.Reset(signal, expectedCount); var processorTask = _executor.Execute(_batchEventProcessor.Run); stopwatch.Start(); var rb = _ringBuffer; for (var i = 0; i < _iterations; i++) { var hi = rb.Next(_batchSize); var lo = hi - (_batchSize - 1); for (var l = lo; l <= hi; l++) { rb[l].Value = (i); } rb.Publish(lo, hi); } signal.WaitOne(); stopwatch.Stop(); PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _batchEventProcessor); _batchEventProcessor.Halt(); processorTask.Wait(2000); PerfTestUtil.FailIfNot(_expectedResult, _handler.Value, $"Handler should have processed {_expectedResult} events, but was: {_handler.Value}"); return(_batchSize * _iterations); }
protected ExecutionResult CompileExecuteAndCheck(ExecutionContext executionContext, Func<CompilerType, string> getCompilerPathFunc, IExecutor executor) { var result = new ExecutionResult(); // Compile the file var compilerPath = getCompilerPathFunc(executionContext.CompilerType); var compilerResult = this.Compile(executionContext.CompilerType, compilerPath, executionContext.AdditionalCompilerArguments, executionContext.Code); result.IsCompiledSuccessfully = compilerResult.IsCompiledSuccessfully; result.CompilerComment = compilerResult.CompilerComment; if (!compilerResult.IsCompiledSuccessfully) { return result; } var outputFile = compilerResult.OutputFile; // Execute and check each test IChecker checker = Checker.CreateChecker(executionContext.CheckerAssemblyName, executionContext.CheckerTypeName, executionContext.CheckerParameter); foreach (var test in executionContext.Tests) { var processExecutionResult = executor.Execute(outputFile, test.Input, executionContext.TimeLimit, executionContext.MemoryLimit); var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, processExecutionResult.ReceivedOutput); result.TestResults.Add(testResult); } // Clean our mess File.Delete(outputFile); return result; }
public override void Execute() { if (executor == null) { throw new ExecuteException("name :" + name + " is not defined"); } executor.Execute(); }
public void Execute_ShouldCreateExecutableContextForExecutables(IExecutor <IExtension> testee) { this.SetupSyntaxReturnsExecutables(); testee.Execute(this.syntax, this.extensions, this.executionContext); A.CallTo(() => this.executionContext.CreateExecutableContext(this.firstExecutable)).MustHaveHappened(); A.CallTo(() => this.executionContext.CreateExecutableContext(this.secondExecutable)).MustHaveHappened(); }
public void Execute_ShouldCreateExecutableContextForExecutables(IExecutor<IExtension> testee) { this.SetupSyntaxReturnsExecutables(); testee.Execute(this.syntax.Object, this.extensions, this.executionContext.Object); this.executionContext.Verify(e => e.CreateExecutableContext(this.firstExecutable.Object)); this.executionContext.Verify(e => e.CreateExecutableContext(this.secondExecutable.Object)); }
public void Execute_ShouldCreateExecutableContextForExecutables(IExecutor <IExtension> testee) { this.SetupSyntaxReturnsExecutables(); testee.Execute(this.syntax.Object, this.extensions, this.executionContext.Object); this.executionContext.Verify(e => e.CreateExecutableContext(this.firstExecutable.Object)); this.executionContext.Verify(e => e.CreateExecutableContext(this.secondExecutable.Object)); }
public void Execute_ShouldExecuteSyntaxWithExtensions(IExecutor <IExtension> testee) { this.SetupSyntaxReturnsExecutables(); testee.Execute(this.syntax, this.extensions, this.executionContext); A.CallTo(() => this.firstExecutable.Execute(A <IEnumerable <IExtension> > ._, A <IExecutableContext> ._)).MustHaveHappened(); A.CallTo(() => this.secondExecutable.Execute(A <IEnumerable <IExtension> > ._, A <IExecutableContext> ._)).MustHaveHappened(); }
public void Execute_ShouldExecuteSyntaxWithExtensions(IExecutor<IExtension> testee) { this.SetupSyntaxReturnsExecutables(); testee.Execute(this.syntax.Object, this.extensions, this.executionContext.Object); this.firstExecutable.Verify(e => e.Execute(this.extensions, It.IsAny<IExecutableContext>())); this.secondExecutable.Verify(e => e.Execute(this.extensions, It.IsAny<IExecutableContext>())); }
public static void ProcessReceive(IExecutor executor, ReceivedEventArgs args) { if(args == null) throw new ArgumentNullException("args"); //如果执行器参数为空,不抛出异常,直接退出 if(executor == null) return; //通过执行器执行当前请求 executor.Execute(args); }
public void Execute_ShouldProvideExecutableContextForExecutables(IExecutor<IExtension> testee) { this.SetupSyntaxReturnsExecutables(); var firstExecutableContext = Mock.Of<IExecutableContext>(); var secondExecutableContext = Mock.Of<IExecutableContext>(); this.executionContext.Setup(e => e.CreateExecutableContext(this.firstExecutable.Object)) .Returns(firstExecutableContext); this.executionContext.Setup(e => e.CreateExecutableContext(this.secondExecutable.Object)) .Returns(secondExecutableContext); testee.Execute(this.syntax.Object, this.extensions, this.executionContext.Object); this.firstExecutable.Verify(e => e.Execute(It.IsAny<IEnumerable<IExtension>>(), firstExecutableContext)); this.secondExecutable.Verify(e => e.Execute(It.IsAny<IEnumerable<IExtension>>(), secondExecutableContext)); }
protected override List<TestResult> ProcessTests(ExecutionContext executionContext, IExecutor executor, IChecker checker, string codeSavePath) { var testResults = new List<TestResult>(); var arguments = new List<string>(); arguments.Add(this.mochaModulePath); arguments.Add(codeSavePath); arguments.AddRange(executionContext.AdditionalCompilerArguments.Split(' ')); foreach (var test in executionContext.Tests) { var processExecutionResult = executor.Execute(this.NodeJsExecutablePath, test.Input, executionContext.TimeLimit, executionContext.MemoryLimit, arguments); var mochaResult = MochaExecutionResult.Parse(processExecutionResult.ReceivedOutput); var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, mochaResult.Passed ? "yes" : string.Format("Unexpected error: {0}", mochaResult.Error)); testResults.Add(testResult); } return testResults; }
protected virtual List<TestResult> ProcessTests(ExecutionContext executionContext, IExecutor executor, IChecker checker, string codeSavePath) { var testResults = new List<TestResult>(); foreach (var test in executionContext.Tests) { var processExecutionResult = executor.Execute(this.NodeJsExecutablePath, test.Input, executionContext.TimeLimit, executionContext.MemoryLimit, new[] { codeSavePath }); var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, processExecutionResult.ReceivedOutput); testResults.Add(testResult); } return testResults; }