static async Task Main(string[] args) { /* * Simple demo illustrating the monitoring of local TCP endpoints * that are currently running on the system somewhere. Shuts itself down * if a port leak is detected. */ var actorSystem = ActorSystem.Create("PortDetector", "akka.loglevel = DEBUG"); var supervisor = actorSystem.ActorOf(Props.Create(() => new TcpPortUseSupervisor()), "tcpPorts"); var cmd = PetabridgeCmd.Get(actorSystem); cmd.Start(); //IEnumerable<IPAddress> SocketLeakDetectorSettings settings = new SocketLeakDetectorSettings { }; var tcp = actorSystem.ActorOf(Props.Create(() => new TcpHostActor()), "tcp"); var endpoint = await tcp.Ask <EndPoint>(TcpHostActor.GetInboundEndpoint.Instance, TimeSpan.FromSeconds(3)); var spawner = actorSystem.ActorOf(Props.Create(() => new TcpPortActor(endpoint)), "leaker"); await actorSystem.WhenTerminated; }
public TcpPortUseSupervisorSpecs(ITestOutputHelper output) : base(output: output) { // keep a really short breach duration in order to make testing more expedient _settings = new SocketLeakDetectorSettings(breachDuration: TimeSpan.FromMilliseconds(100), maxPorts: 2, minPorts: 1) { PortCheckInterval = TimeSpan.FromMilliseconds(100) }; }
public void SocketLeakDetectorActor_RollerCoaster() { var portCounts = new[] { 100, 120, 130, 140, 150, 160, 170, 180, 190, 200, 200, 200, 210, 220, 230, 230, 230, 230, 230 }; var newSettings = new SocketLeakDetectorSettings(breachDuration: TimeSpan.FromMilliseconds(100), largeSampleSize: 40); var leakDetector = Sys.ActorOf(Props.Create(() => new SocketLeakDetectorActor(newSettings, TestActor))); foreach (var i in portCounts) { leakDetector.Tell(GenerateCount(i)); } ExpectMsg <TcpPortUseSupervisor.Shutdown>(); }
static async Task Main(string[] args) { // launch seed node var seed = StartNode(9444); var pbm = PetabridgeCmd.Get(seed); pbm.RegisterCommandPalette(ClusterCommands.Instance); pbm.Start(); var settings = new SocketLeakDetectorSettings(maxPorts: 20000); var leakDetector = seed.ActorOf(Props.Create(() => new TcpPortUseSupervisor(settings, new[] { IPAddress.Loopback })), "portMonitor"); // start node that will be quarantined var quarantineNode = StartNode(9555); var node2Addr = Cluster.Get(quarantineNode).SelfAddress; var uid = AddressUidExtension.Uid(quarantineNode); var peanutGallery = Enumerable.Repeat(1, 3).Select(x => StartNode(0)).ToList(); Func <int, bool> checkMembers = i => Cluster.Get(seed).State.Members.Count == i; seed.Log.Info("Waiting for members to join..."); while (!checkMembers(5)) { await Task.Delay(TimeSpan.FromSeconds(2)); } seed.Log.Info("Cluster up."); //Console.WriteLine("Press enter to begin quarantine."); //Console.ReadLine(); RarpFor(seed).Quarantine(node2Addr, uid); await Task.Delay(TimeSpan.FromSeconds(2.5)); seed.ActorSelection(new RootActorPath(node2Addr) / "user" / "silence").Tell("fuber"); //Console.WriteLine("Press enter to terminate quarantined node"); //Console.ReadLine(); //await quarantineNode.Terminate(); seed.WhenTerminated.Wait(); }
public SocketLeakDetectorActorSpecs(ITestOutputHelper output) : base(output: output, config: "akka.loglevel=DEBUG") { // keep a really short breach duration in order to make testing more expedient _settings = new SocketLeakDetectorSettings(breachDuration: TimeSpan.FromMilliseconds(100), maxPorts: 200); }
public SocketScenario(IReadOnlyList <int> socketCounts, SocketLeakDetectorSettings settings, bool shouldFail) { SocketCounts = socketCounts; Settings = settings; ShouldFail = shouldFail; }