public async Task SimpleWaitForWithTimeoutTest() { var facade = new TestFacade(); _ = facade.Schedule(() => { var w = new SimpleWaitForWorkflow(); Roots.Entangle(w); _ = w.Start(); }); await facade.Scheduler.Sync(); var workflow = facade.Resolve <SimpleWaitForWorkflow>(); workflow.ThrownException.ShouldBeNull(); facade.LoadAgain(); await Task.Delay(3000); workflow = facade.Resolve <SimpleWaitForWorkflow>(); workflow.ThrownException.ShouldNotBeNull(); facade.Dispose(); }
public void UntilWorksTest() { var storage = new InMemoryStorageEngine(); var executionEngine = ExecutionEngineFactory.StartNew(storage); executionEngine.Schedule(() => { var holder = new UntilTestHolder(); var task = holder.Start(); Roots.Entangle(holder); Roots.Entangle(task); return(Sync.Next()); }).Wait(); executionEngine.Dispose(); executionEngine = ExecutionEngineFactory.Continue(storage); executionEngine.Schedule(() => { var holder = Roots.Resolve <UntilTestHolder>(); holder.Stop = true; return(Roots.Resolve <CTask>()); }).Wait(); var completed = executionEngine.Schedule(() => Roots.Resolve <UntilTestHolder>().Completed).Result; completed.ShouldBe(true); }
public void StartWorkflowOneWithDelayAndWaitForCompletion() { Scheduler.Schedule(() => { var w = new WorkflowOne(); Roots.Entangle(w); _ = w.Do(); }); Thread.Sleep(1000); var workflow = Scheduler.Resolve <WorkflowOne>().Result; Scheduler.Dispose(); workflow.Status.ShouldBe(-1); var facade = ExecutionEngine.ExecutionEngineFactory.Continue(StableStorageEngine); Thread.Sleep(1500); var loadedWorkflow = facade.Resolve <WorkflowOne>().Result; loadedWorkflow.Status.ShouldBe(1); workflow.Status.ShouldBe(-1); facade.Dispose(); }
//[TestMethod] public void SentMessageIsProcessed() { var hostname = "127.0.0.1"; const int port = 10_000; var storage = new InMemoryStorageEngine(); var scheduler1 = ExecutionEngineFactory.StartNew(storage); scheduler1.Schedule(() => { var msgHandler = new MessageHandler(); var connectionListener = new ConnectionServer(hostname, port, msgHandler.Handle); Roots.Entangle(msgHandler); Roots.Entangle(connectionListener); }); var senderId = Guid.Empty; var msgSender = new TestMessageSender(hostname, port, senderId); msgSender.Connect(); msgSender.SendMessage("HELLO".GetUtf8Bytes(), 0); Thread.Sleep(1000); var messageHandler = scheduler1.Resolve <MessageHandler>().Result; var messages = messageHandler.GetMessages(); messages.Count.ShouldBe(1); messages[0].ShouldBe("HELLO"); scheduler1.Do <ConnectionServer>(c => c.Shutdown()); Thread.Sleep(1000); scheduler1.Dispose(); scheduler1 = ExecutionEngineFactory.Continue(storage); messageHandler = scheduler1.Resolve <MessageHandler>().Result; Console.WriteLine(messageHandler); msgSender = new TestMessageSender(hostname, port, senderId); msgSender.Connect(); msgSender.SendMessage("HELLO2".GetUtf8Bytes(), 1); Thread.Sleep(1000); messages = messageHandler.GetMessages(); messages.Count.ShouldBe(2); messages[0].ShouldBe("HELLO"); messages[1].ShouldBe("HELLO2"); scheduler1.Dispose(); }
public static void Do() { var storageEngine = new InMemoryStorageEngine(); var executionEngine = ExecutionEngineFactory.StartNew(storageEngine); executionEngine.Schedule(() => { var network = new Network(); var source = new Source <object>(); Roots.Entangle(source); var proposer = new PaxosProposer(source, network); _ = proposer.StartRound("hello", 0); _ = OutsideFlow(source, network); }); }
public async Task StartWorkflowTwoWithDelayAndWaitForCompletion() { await Scheduler.ScheduleTask(() => { var workflow = new WorkflowTwo { Status = 100 }; Roots.Entangle(workflow); return(Sync.Next(false)); }); var scheduler = ExecutionEngine.ExecutionEngineFactory.Continue(StableStorageEngine); var status = await Scheduler.Schedule(() => Roots.Resolve <WorkflowTwo>().Status); status.ShouldBe(100); scheduler.Dispose(); }
public async Task CreateAndWaitForNonPersistentSleepThatCompletesBeforeSync() { var workflow = new Workflow(false); await Scheduler.Entangle(workflow); _ = Scheduler.Schedule(() => _ = workflow.Do()); await Task.Delay(2000); workflow.IsCompleted().ShouldBeTrue(); Scheduler.Dispose(); LoadAgain(); await Task.Delay(2000); var isCompleted = await Scheduler.Schedule(() => Roots.Resolve <Workflow>().IsCompleted()); isCompleted.ShouldBeFalse(); }
public WaitForWorkflow(int waitForTimeout) { Source = new Source <int>(); WaitFor = Source.WaitFor(5, true, TimeSpan.FromMilliseconds(waitForTimeout)); Roots.Entangle(this); }