public static void SpawnAndKillProcess() { shutdownAll(); ProcessConfig.initialise(); ProcessId pid = spawn <string, string>("SpawnAndKillProcess", () => "", (_, msg) => msg); tell(pid, "1"); kill(pid); tell(pid, "2"); var kids = children(User()); var len = kids.Length; Debug.Assert(len == 0); }
static void Main(string[] args) { ProcessId test = "/disp/broadcast/[/root/user/c,/root/user/b,/root/user/c]"; //RedisCluster.register(); //Cluster.connect("redis", "disp-test", "localhost", "0", "dispatch-role"); ProcessConfig.initialise(); var pida = spawn <int>("A", x => Console.WriteLine("A" + x)); var pidb = spawn <int>("B", x => Console.WriteLine("B" + x)); var pidc = spawn <int>("C", x => Console.WriteLine("C" + x)); Console.WriteLine("Press the numeric keys 1 to 4 to select the type of dispatch"); Console.WriteLine("1. Broadcast"); Console.WriteLine("2. Least busy"); Console.WriteLine("3. Round robin"); Console.WriteLine("4. Random"); int i = 0; while (true) { ProcessId pid = ProcessId.None; switch (Console.ReadKey().KeyChar) { case '1': pid = Dispatch.broadcast(pida, pidb, pidc); break; case '2': pid = Dispatch.leastBusy(pida, pidb, pidc); break; case '3': pid = Dispatch.roundRobin(pida, pidb, pidc); break; case '4': pid = Dispatch.random(pida, pidb, pidc); break; } Console.WriteLine(); if (pid.IsValid) { tell(pid, i); } else { break; } } }
public void SpawnAndKillHierarchy() { lock (sync) { shutdownAll(); Assert.True(Systems.Count == 0); ProcessConfig.initialise(); string value = null; ProcessId parentId; var pid = spawn <Unit, string>("SpawnAndKillHierarchy.TopLevel", () => { parentId = Parent; spawn <string>("SpawnAndKillHierarchy.ChildLevel", msg => value = msg); return(unit); }, (state, msg) => { value = msg; return(state); } ); tell(pid, "1"); Thread.Sleep(10); kill(pid); Thread.Sleep(10); Assert.Throws <ProcessException>(() => { tell(pid, "2"); }); Thread.Sleep(10); Assert.True(value == "1", "Expected 1, actually equals: " + value); Assert.True(children(User()).Length == 0); } }
public void LocalRegisterTest() { lock (sync) { shutdownAll(); Assert.True(Systems.Count == 0); ProcessConfig.initialise(); string value = null; var pid = spawn <string>("reg-proc", msg => value = msg); var regid = register("woooo amazing", pid); Assert.True(regid == "/disp/reg/local-woooo amazing"); tell(regid, "hello"); Thread.Sleep(100); Assert.True(value == "hello"); tell(find("woooo amazing"), "world"); Thread.Sleep(100); Assert.True(value == "world"); deregisterById(pid); Thread.Sleep(100); try { tell(find("woooo amazing"), "noooo"); } catch (Exception e) { Assert.True(e.Message.Contains("No processes in group")); } Thread.Sleep(100); Assert.True(value != "noooo"); } }
static void Main(string[] args) { string fname = args[0]; if (string.IsNullOrEmpty(fname)) { System.Environment.Exit(1); } if (!File.Exists(fname)) { System.Environment.Exit(1); } m_config = Hydrator.HydrateFrom <ProcessConfig>(fname); ImageHelper.ProcessFilesInBackground(null, m_config); }
static void Main(string[] args) { ProcessConfig.initialise(); Process.DeadLetters() .Observe <DeadLetter>() .Subscribe(Console.WriteLine); Process.ProcessSystemLog .Subscribe(Console.WriteLine); FuncCaching.Run(); ClassCaching.Run(); Console.ReadKey(); }
public void ProxyTest1() { lock (ProcessTests.sync) { shutdownAll(); ProcessConfig.initialise(); var pid = spawn <MyProcess>("proxy-test1"); var proxy = proxy <IMyProcess>(pid); proxy.Hello("Hello"); int res = proxy.World("World"); Assert.True(res == 2); } }
private void SaveConfig() { var processConfigs = new List <ProcessConfig>(); foreach (var model in ProcessConfigs) { var pc = new ProcessConfig(); pc.InjectFrom(model); processConfigs.Add(pc); } if (ConfigManager.Instance.SaveConfig(processConfigs)) { LoadConfig(); } }
public async Task <GitBlameOutput[]> Blame(string filePath) { var handler = new GitBlameOutputHandler(); var gitBlame = new ProcessConfig("git", $"blame {filePath} -p", (s, b) => { if (!b) { handler.ReadLine(s); } if (b && !string.IsNullOrEmpty(s)) { Console.WriteLine($"Error git: {s}"); } }, RepositoryPath); await ProcessUtils.RunProcess(gitBlame); return(handler.GetOutputs()); }
public Publisher() { publisherData = new ProcessConfig(); channel = new TcpChannel(); allEvents = new Dictionary <string, List <string> >(); publisherService = new RemotePublisherService(); sequenceNumber = 0; ordertype = ""; freezeList = new List <publisherParameters>(); commands = new List <publisherParameters>(); brokerReplicas = new List <BrokerInterface>(); ChannelServices.RegisterChannel(channel, false); RemotingServices.Marshal(publisherService, "pub", typeof(RemotePublisherService)); publisherService.pub += new DelParametersPub(addPublication); publisherService.freeze += new DelGetSlaveUrl(setFreezeMode); publisherService.unfreeze += new DelGetSlaveUrl(setUnfreeze); }
static void Main(string[] args) { // Log what's going on // ProcessLog.Subscribe(Console.WriteLine); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-subscribe-test", "localhost", "0"); var pid = ProcessId.Top["redis-publish-test"]["user"]["redis-pubsub-random-test"]; // Listen to the published results coming back from the Redis channel subscribe <int>(pid, Console.WriteLine); Console.ReadKey(); }
public void CouldWriteDataStoreConfig() { var path = TestUtils.GetPath(); var pc = new ProcessConfig(path); var init = pc.SaveDataStoreConfig(new DataStoreConfig() { DataStoreDirectory = "G:/DataSpreads" }); Assert.IsTrue(init); init = pc.SaveDataStoreConfig(new DataStoreConfig() { DataStoreDirectory = "G:/DataSpreads" }); Assert.IsFalse(init); }
static void Test1() { ProcessId pong = ProcessId.None; ProcessId ping = ProcessId.None; // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0"); ping = spawn <string>( Name: "ping", Inbox: msg => { Console.WriteLine(msg); tell(pong, "pong", 100 * ms); }, Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"), Flags: ProcessFlags.PersistInbox ); pong = spawn <string>( Name: "pong", Inbox: msg => { Console.WriteLine(msg); tell(ping, "ping", 100 * ms); }, Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"), Flags: ProcessFlags.PersistInbox ); watch(ping, pong); watch(pong, ping); tell(pong, "Running"); Console.WriteLine("Press key to kill ping"); Console.ReadKey(); kill(ping); Console.WriteLine("Press key to exit"); Console.ReadKey(); }
private void RunProcess(ProcessConfig processConfig, Dictionary <string, Task> keyTasks) { var identifier = !string.IsNullOrWhiteSpace(processConfig.Key) ? processConfig.Key : processConfig.FilePath; if (processConfig.DependsOn != null) { foreach (var dependingKey in processConfig.DependsOn) { if (keyTasks.ContainsKey(dependingKey)) { Log.Info($"[{identifier}] Waiting for '{dependingKey}'"); keyTasks[dependingKey].Wait(); } } } Log.Info($"[{identifier}] Starting '{processConfig.FilePath}' in '{processConfig.WorkDir}' with Timeout='{processConfig.Timeout}' {(processConfig.Async ? "Async" : "")}"); var process = new Process { StartInfo = new ProcessStartInfo { WorkingDirectory = processConfig.WorkDir, FileName = processConfig.FilePath, Arguments = processConfig.Args, } }; process.Start(); if (processConfig.Async) { return; } if (processConfig.Timeout == null) { process.WaitForExit(); } else if (!process.WaitForExit((int)processConfig.Timeout.Value.TotalMilliseconds)) { Log.Info($"[{identifier}] Process timed out, killing it"); process.Kill(); } }
public void TestSelectionIds() { lock (ProcessTests.sync) { Process.shutdownAll(); ProcessConfig.initialise(); ProcessId test = "/disp/broadcast/[/root/user/a,/root/user/b,/root/user/c]"; Assert.True(test.Take(1).Name == "disp"); Assert.True(test.Skip(1).Take(1).Name == "broadcast"); Assert.True(test.Skip(2).Take(1).Name == "[/root/user/a,/root/user/b,/root/user/c]"); Assert.True(test.Skip(2).Take(1).IsSelection); Assert.True(test.Skip(2).Take(1).GetSelection().Count() == 3); Assert.True(test.Skip(2).Take(1).GetSelection().First().Path == "/root/user/a"); Assert.True(test.Skip(2).Take(1).GetSelection().Skip(1).First().Path == "/root/user/b"); Assert.True(test.Skip(2).Take(1).GetSelection().Skip(2).First().Path == "/root/user/c"); } }
public async Task <GitLogOutput[]> Log(string filePath, string baseCommit, string headCommit, Range lines) { var handler = new GitLogOutputHandler(); var gitBlame = new ProcessConfig("git", $"log --ancestry-path {baseCommit}..{headCommit} -L {lines.Start},{lines.End}:{filePath}", (s, b) => { if (!b) { handler.ReadLine(s); } if (b && !string.IsNullOrEmpty(s)) { Console.WriteLine($"Error git: {s}"); } }, RepositoryPath); await ProcessUtils.RunProcess(gitBlame); return(handler.GetOutputs()); }
public void AskReply() { lock (sync) { shutdownAll(); Assert.True(Systems.Count == 0); ProcessConfig.initialise(); Assert.True(Systems.Count == 1); var helloServer = spawn <string>("hello-server", msg => { reply("Hello, " + msg); }); var response = ask <string>(helloServer, "Paul"); Assert.True(response == "Hello, Paul"); } }
private bool CheckKernelRunning(ProcessConfig config, out Process kernel) { var kernelPath = config.Kernel.Trim(); var statusPath = Path.Combine(Path.GetDirectoryName(kernelPath) ?? string.Empty, "Status.ini"); const int iterationCount = 60; var parser = new FileIniDataParser(); if (File.Exists(statusPath)) { File.Delete(statusPath); } Directory.SetCurrentDirectory(Path.GetDirectoryName(kernelPath)); kernel = Process.Start(kernelPath); Thread.Sleep(5000); for (var i = 0; i < iterationCount; i++) { try { Thread.Sleep(1100); var data = parser.ReadFile(statusPath); var status = data.Sections["Status"].GetKeyData("Global").Value; switch (status) { case "Ready": return(true); case "Fail": case "Close": return(false); } } catch { Thread.Sleep(500); } } return(false); }
public void StartProcess(ProcessConfig config, Action <ProcessProgress> callback) { if (_progress != null) { throw new InvalidOperationException("The process is already started. Please, use another Service instance."); } _config = config; _callback = callback; _progress = new ProcessProgress() { ProcessId = Guid.NewGuid(), TotalSteps = Math.Abs(config.StepsCount), CurrentStep = 0, TimeSpentSeconds = 0 }; _progress.TotalSteps = config.StepsCount; _timer = new Timer(Invoke, config, 0, config.StepDelay * 1000); _timeStarted = DateTime.Now; }
//public static void RegisteredAskReply() //{ // shutdownAll(); // ProcessConfig.initialise(); // var helloServer = spawn<string>("hello-server", msg => // { // reply("Hello, " + msg); // }); // var hi = register<string>("hi", helloServer); // var response = ask<string>(find("hi"), "Paul"); // Debug.Assert(response == "Hello, Paul"); //} public static void AskReply() { shutdownAll(); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0"); var helloServer = spawn <string>("hello-server", msg => { reply("Hello, " + msg); }, ProcessFlags.PersistInbox); var response = ask <string>(helloServer, "Paul"); Debug.Assert(response == "Hello, Paul"); }
public void SpawnProcess() { lock (sync) { shutdownAll(); Assert.True(Systems.Count == 0); ProcessConfig.initialise(); string value = null; var pid = spawn <string>("SpawnProcess", msg => value = msg); tell(pid, "hello, world"); Thread.Sleep(200); Assert.True(value == "hello, world"); kill(pid); } }
private static void ProxyTesting() { ProcessConfig.initialise(); var pid = ProxyTest(); Console.ReadKey(); Console.WriteLine("done. next to kill process... press a key"); Console.ReadKey(); kill(pid); Console.WriteLine("process is killed. next to shutdown... press a key"); Console.ReadKey(); shutdownAll(); Console.WriteLine("done. any key to quit."); Console.ReadKey(); }
public async Task <string> GetCommonAncestorWithDevelop(string commit) { var result = string.Empty; var development = "develop"; var gitFetch = new ProcessConfig("git", $"merge-base {commit} origin/{development}", (s, b) => { if (!b && !string.IsNullOrEmpty(s)) { result = s; } if (b && !string.IsNullOrEmpty(s)) { Console.WriteLine($"Error git: {s}"); } }, RepositoryPath); await ProcessUtils.RunProcess(gitFetch); await Task.Delay(150); return(result); }
public static void SpawnAndKillHierarchy() { shutdownAll(); ProcessConfig.initialise(); int value = 0; var pid = spawn <int, string>("SpawnAndKillHierarchy.TopLevel", () => { spawn <string>("SpawnAndKillHierarchy.ChildLevel", x => Console.WriteLine(x)); return(0); }, (_, msg) => value = Int32.Parse(msg) ); tell(pid, "1"); kill(pid); tell(pid, "2"); Thread.Sleep(200); Debug.Assert(value == 1, "Expected 1, got " + value); Debug.Assert(children(User()).Length == 0); }
public async Task <GitLogOutput> Log(string commit) { var handler = new GitLogOutputHandler(); var gitBlame = new ProcessConfig("git", $"log --date=rfc -1 {commit}", (s, b) => { if (!b) { handler.ReadLine(s); } if (b && !string.IsNullOrEmpty(s)) { Console.WriteLine($"Error git: {s}"); } }, RepositoryPath); await ProcessUtils.RunProcess(gitBlame); await Task.Delay(250); return(handler.GetOutputs().FirstOrDefault()); }
public static void ProcessStartupError() { shutdownAll(); ProcessConfig.initialise(); try { var pid = spawn <Unit, string>("world", () => failwith <Unit>("Failed!"), (_, __) => _, ProcessFlags.PersistInbox ); ask <Unit>(pid, unit); throw new Exception("Not here"); } catch (ProcessException e) { Debug.Assert(e.Message == "Process issue: Invalid message type for ask (expected System.String)"); } }
public MgiStarterControlModel(ILifetimeScope lifetimeScope, Dispatcher dispatcher, ProcessConfig config) : base(lifetimeScope, dispatcher) { Client = RegisterProperty <Process?>(nameof(Client)).OnChange(UpdateLabel); Kernel = RegisterProperty <Process?>(nameof(Kernel)).OnChange(UpdateLabel); Status = RegisterProperty <string?>(nameof(Status)).OnChange(UpdateLabel); InternalStart = RegisterProperty <bool>(nameof(InternalStart)).OnChange(UpdateLabel); StatusLabel = RegisterProperty <string?>(nameof(StatusLabel)); _localHelper = new LocalHelper(Context); _config = config; _processManager = Context.ActorOf <ProcessManagerActor>("Process-Manager"); var mgiStarting = Context.ActorOf(Context.DI().Props <MgiStartingActor>(), "Mgi-Starter"); Receive <ProcessStateChange>(ProcessStateChangeHandler); Receive <MgiStartingActor.TryStartResponse>(TryStartResponseHandler); Receive <MgiStartingActor.StartStatusUpdate>(StatusUpdate); NewCommad .WithCanExecute(() => InternalStart == false) .WithExecute(() => { InternalStart += true; mgiStarting.Tell(new MgiStartingActor.TryStart(_config, () => { Client.Value?.Kill(true); Kernel.Value?.Kill(true); })); }).ThenRegister("TryStart"); NewCommad .WithCanExecute(() => InternalStart == false && (Client != null || Kernel != null)) .WithExecute(() => { Client.Value?.Kill(true); Kernel.Value?.Kill(true); }).ThenRegister("TryStop"); UpdateLabel(); }
// // Launch a process that adds the int sent in a message to its state // Then calls itself after a second to do the same again. The state value gradually // increases. // // If you stop the sample and restart you'll notice the state has been persisted // static void Main(string[] args) { // Log what's going on // ProcessLog.Subscribe(Console.WriteLine); // Let Language Ext know that Redis exists RedisCluster.register(); // Connect to the Redis cluster ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0"); // Spawn the process var pid = spawn <int, int>("redis-state-sample", Setup, Inbox, ProcessFlags.PersistState); // Subscribe locally to the state changes observeState <int>(pid).Subscribe(Console.WriteLine); // Start it off by sending the first message tell(pid, 1); Console.ReadKey(); }
static void Main(string[] args) { ProcessConfig.initialise(); int pairs = args.Count() == 0 ? 16 : Int32.Parse(args[0]); int msgs = args.Count() == 2 ? Int32.Parse(args[1]) : 10; int sleepForMax = 20; var counters = new Counter[pairs]; InitCounters(pairs, counters, msgs); int sleepFor = sleepForMax; while (sleepFor > 0) { Console.WriteLine("Sleeping for " + sleepFor + " seconds whilst it warms up"); Thread.Sleep(1000); sleepFor--; } Console.WriteLine("Warm up sent " + SumCounters(pairs, counters) + " messages. Running for real now..."); ResetCounters(pairs, counters); Thread.Sleep(1000 * sleepForMax); shutdownAll(); var sum = SumCounters(pairs, counters); Console.WriteLine("" + sum + " messages sent in " + sleepForMax + " seconds."); decimal sps = ((decimal)sum) / ((decimal)sleepForMax); Console.WriteLine("That's " + sps + " messages per second"); Console.ReadKey(); }
public void Stop_DoesNotThrow() { Utils.MethodStart(); foreach (var name in EnumValues.GetString()) { foreach (var affinity in EnumValues.GetLong()) { foreach (var user in EnumValues.GetString()) { Assert.DoesNotThrow(() => { var procConfig = new ProcessConfig(name, affinity, user); var processWatcher = new ProcessWatcher(new List <ProcessConfig>() { procConfig }); processWatcher.Start(); processWatcher.Stop(); }); TestContext.WriteLine($@"Assert.DoesNotThrow(() => new ProcConfig({name}, {affinity}, {user}))"); Assert.DoesNotThrowAsync(async() => await Task.Run(() => { var procConfig = new ProcessConfig(name, affinity, user); var processWatcher = new ProcessWatcher(new List <ProcessConfig>() { procConfig }); processWatcher.Start(); processWatcher.Stop(); })); TestContext.WriteLine($@"Assert.DoesNotThrowAsync(async () => new ProcConfig({name}, {affinity}, {user}))"); } } } Utils.MethodComplete(); }