internal BufferTimeAndSizeSubscriber(ISubscriber <IList <T> > actual, int maxSize, TimeSpan timespan, TimedWorker worker, int capacityHint) { this.actual = actual; this.maxSize = maxSize; this.timespan = timespan; this.worker = worker; this.queue = new SpscLinkedArrayQueue <BufferWork>(capacityHint); this.buffer = new List <T>(); }
static void CreateControlConsole() { // Define an interval TimeSpan interval = TimeSpan.FromMilliseconds(500); // Create the console IConsole control = ConsoleAsync.CreateConsole("Control Console"); // Add quit command control.AddCommand("quit", (writer, list) => ConsoleAsync.Quit()); // Create worker from builtin type TimedWorker ConsoleWorker controlWorker = new TimedWorker(interval, (writer, span) => { // Clear console and write title and info writer.Clear(); writer.Info("CONTROL CONSOLE").NewLine(); writer.Muted("Elapsed: {0}", span).NewLine().NewLine(); // Cicle workers foreach (TestWorker worker in workers) { // Calculate percentage of success over 60 characters int success = (60 * worker.Successes + 1) / (worker.Successes + worker.Failures + 1); int failure = 60 - success; // Write worker name fitted on 16 char (to make bars aligned) writer.Text(worker.Name.Fit(16)); // Write success bar writer.Success("".Fit(success, '\u25A0')); // Write error bar writer.Error("".Fit(failure, '\u25A0')); writer.NewLine(); } // Write a message and commands help writer.NewLine().NewLine().NewLine().Info("Available commands").NewLine(); writer.Text(@" suspend : suspend worker (not in control console) resume : resume worker (not in control console) quit : close application (in any console) "); }); // Add worker to control console control.AddWorker(controlWorker); }
static void Main(string[] args) { Console.WriteLine("Adding elements to list"); List <WorkItem> workItems = new List <WorkItem>(100); for (int i = 0; i < 1000; i++) { workItems.Add(new WorkItem { TimeStamp = DateTime.Now.AddMilliseconds(i * 300) }); } var tw = new TimedWorker(); tw.Process(workItems); Console.ReadLine(); }
/// <summary> /// Creates an instance of the conformance tester for an IUT stepper. /// </summary> /// <param name="model">given model stepper</param> /// <param name="impl">given implementation stepper</param> public ConformanceTester(IStrategy model, IStepper impl) { this.model = model; this.impl = impl; //set the callback in the implementation //if the implementation implements IAsyncStepper IAsyncStepper implWithObs = impl as IAsyncStepper; if (implWithObs != null) { TimedQueue <Action> obs = new TimedQueue <Action>(); this.observations = obs; implWithObs.SetObserver(obs.Enqueue); } this.testResultNotifier = this.DefaultTestResultNotifier; this.testerActionTimeout = delegate(IState state, CompoundTerm action) { return(defaultTimeSpan); }; this.testerActionSymbols = model.ActionSymbols; this.cleanupActionSymbols = Set <Symbol> .EmptySet; this.internalActionSymbols = Set <Symbol> .EmptySet; this.RandomSeed = new Random().Next(); this.worker = new TimedWorker(); }
public ConnectivityTester() { _worker = new TimedWorker(); _worker.QueueForever(TestInternetAccess, TimeSpan.FromSeconds(5)); _worker.Start(); }
internal DelaySubscriber(ISubscriber <T> actual, TimeSpan delay, TimedWorker worker) { this.actual = actual; this.delay = delay; this.worker = worker; }
/// <summary> /// Call RunTestCase runsCnt times, reset in between runs. /// </summary> /// <exception cref="ConformanceTesterException">Is thrown when Run does not finish normally</exception> public void Run() { bool reset = false; try { int run = 0; while ((runsCnt <= 0) || run < runsCnt) { TestResult testResult = RunTestCase(run); // Tests results summary metrics if (testResult.verdict == Verdict.Failure) { ++totalFailedTests; } // Requirements metrics totalExecutedRequirements = totalExecutedRequirements.Union(testResult.executedRequirements); if (!this.testResultNotifier(testResult)) { Reset(); //Metrics AddMetricsToEndOfLog(); return; } Reset(); run += 1; // Tests results summary metrics totalExecutedTests = run; } // Metrics AddMetricsToEndOfLog(); } catch (Exception e) { if (e.Message != "Reset failed.") { reset = true; } if (e is ConformanceTesterException) { throw; } throw new ConformanceTesterException("Run failed. " + e.Message); } finally { //dispose of the worker thread pool worker.Dispose(); if (reset) { Reset(); } worker = null; } }