예제 #1
0
        public async Task LoggingBus_should_stop_all_loggers_on_termination()
        {
            var system = ActorSystem.Create("TestSystem", ConfigurationFactory.Default());

            system.EventStream.Subscribe(TestActor, typeof(Debug));
            await system.Terminate();

            var shutdownInitiated = ExpectMsg <Debug>(TestKitSettings.DefaultTimeout);

            shutdownInitiated.Message.ShouldBe("System shutdown initiated");

            var loggerStarted = ExpectMsg <Debug>(TestKitSettings.DefaultTimeout);

            loggerStarted.Message.ShouldBe("Shutting down: StandardOutLogger started");
            loggerStarted.LogClass.ShouldBe(typeof(EventStream));
            loggerStarted.LogSource.ShouldBe(typeof(EventStream).Name);

            var loggerStopped = ExpectMsg <Debug>(TestKitSettings.DefaultTimeout);

            loggerStopped.Message.ShouldBe("All default loggers stopped");
            loggerStopped.LogClass.ShouldBe(typeof(EventStream));
            loggerStopped.LogSource.ShouldBe(typeof(EventStream).Name);

            ExpectNoMsg(TimeSpan.FromSeconds(1));
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActorSystemImpl"/> class.
 /// </summary>
 /// <param name="name">The name given to the actor system.</param>
 public ActorSystemImpl(string name)
     : this(
         name,
         ConfigurationFactory.Default(),
         ActorSystemSetup.Empty,
         Option <Props> .None)
 {
 }
예제 #3
0
        public static Config Config()
        {
            var address = TestUtils.TemporaryServerAddress();

            return(ConfigurationFactory.ParseString($@"        
            akka {{
              loglevel = INFO
              actor {{
                provider = remote
                serialize-messages = off
              }}
              remote.dot-netty.tcp {{
                port = {address.Port}
                hostname = ""{address.Address}""
              }}
            }}")
                   .WithFallback(ConfigurationFactory.Default()));
        }
예제 #4
0
        public static ActorSystem CreateActorSystem()
        {
            var address = TestUtils.TemporaryServerAddress();
            var config  = ConfigurationFactory.ParseString($@"        
            akka {{
              loglevel = INFO
              actor {{
                provider = remote
                serialize-messages = off
              }}
              remote.dot-netty.tcp {{
                port = {address.Port}
                hostname = ""{address.Address}""
              }}
            }}")
                          .WithFallback(ConfigurationFactory.Default());

            var system = ActorSystem.Create("remote-system-2", config);

            return(system);
        }
예제 #5
0
        public MemoryEventAdaptersSpec()
        {
            var config = ConfigurationFactory.ParseString(@"
akka.persistence.journal {
  plugin = ""akka.persistence.journal.inmem""


  # adapters defined for all plugins
  common-event-adapter-bindings {
  }

  inmem {
    # showcases re-using and concating configuration of adapters

    event-adapters {
      example  = """ + typeof(ExampleEventAdapter).FullName + @", Akka.Persistence.Tests""
      marker   = """ + typeof(MarkerInterfaceAdapter).FullName + @", Akka.Persistence.Tests""
      precise  = """ + typeof(PreciseAdapter).FullName + @", Akka.Persistence.Tests""
      reader  = """ + typeof(ReaderAdapter).FullName + @", Akka.Persistence.Tests""
      writer  = """ + typeof(WriterAdapter).FullName + @", Akka.Persistence.Tests""
      another-reader  = """ + typeof(AnotherReaderAdapter).FullName + @", Akka.Persistence.Tests""
    }
    event-adapter-bindings = {
      """ + typeof(IEventMarkerInterface).FullName + @", Akka.Persistence.Tests"" = marker
      ""System.String"" = example
      """ + typeof(PreciseAdapterEvent).FullName + @", Akka.Persistence.Tests"" = precise
      """ + typeof(ReadMeEvent).FullName + @", Akka.Persistence.Tests"" = reader
      """ + typeof(WriteMeEvent).FullName + @", Akka.Persistence.Tests"" = writer
      """ + typeof(ReadMeTwiceEvent).FullName + @", Akka.Persistence.Tests"" = [reader, another-reader]
      """ + typeof(ReadWriteEvent).FullName + @", Akka.Persistence.Tests"" = [reader, another-reader, writer]
    }
  }
}").WithFallback(ConfigurationFactory.Default());

            _extendedActorSystem = (ExtendedActorSystem)Sys;
            _memoryConfig        = config.GetConfig("akka.persistence.journal.inmem");
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActorSystemImpl"/> class.
 /// </summary>
 /// <param name="name">The name given to the actor system.</param>
 public ActorSystemImpl(string name)
     : this(name, ConfigurationFactory.Default())
 {
 }
예제 #7
0
 public ConfigurationSpec(ITestOutputHelper output) : base(ConfigurationFactory.Default(), output)
 {
 }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Settings" /> class.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <param name="config">The configuration.</param>
        /// <exception cref="ConfigurationException">
        /// This exception is thrown if the 'akka.actor.provider' configuration item is not a valid type name or a valid actor ref provider.
        /// </exception>
        public Settings(ActorSystem system, Config config)
        {
            _userConfig     = config;
            _fallbackConfig = ConfigurationFactory.Default();
            RebuildConfig();

            System = system;

            ConfigVersion = Config.GetString("akka.version", null);
            ProviderClass = GetProviderClass(Config.GetString("akka.actor.provider", null));
            var providerType = Type.GetType(ProviderClass);

            if (providerType == null)
            {
                throw new ConfigurationException($"'akka.actor.provider' is not a valid type name : '{ProviderClass}'");
            }
            if (!typeof(IActorRefProvider).IsAssignableFrom(providerType))
            {
                throw new ConfigurationException($"'akka.actor.provider' is not a valid actor ref provider: '{ProviderClass}'");
            }

            SupervisorStrategyClass = Config.GetString("akka.actor.guardian-supervisor-strategy", null);

            AskTimeout           = Config.GetTimeSpan("akka.actor.ask-timeout", null, allowInfinite: true);
            CreationTimeout      = Config.GetTimeSpan("akka.actor.creation-timeout", null);
            UnstartedPushTimeout = Config.GetTimeSpan("akka.actor.unstarted-push-timeout", null);

            SerializeAllMessages = Config.GetBoolean("akka.actor.serialize-messages", false);
            SerializeAllCreators = Config.GetBoolean("akka.actor.serialize-creators", false);

            LogLevel           = Config.GetString("akka.loglevel", null);
            StdoutLogLevel     = Config.GetString("akka.stdout-loglevel", null);
            Loggers            = Config.GetStringList("akka.loggers", new string[] { });
            LoggersDispatcher  = Config.GetString("akka.loggers-dispatcher", null);
            LoggerStartTimeout = Config.GetTimeSpan("akka.logger-startup-timeout", null);

            //handled
            LogConfigOnStart = Config.GetBoolean("akka.log-config-on-start", false);
            LogDeadLetters   = 0;
            switch (Config.GetString("akka.log-dead-letters", null))
            {
            case "on":
            case "true":
            case "yes":
                LogDeadLetters = int.MaxValue;
                break;

            case "off":
            case "false":
            case "no":
                LogDeadLetters = 0;
                break;

            default:
                LogDeadLetters = Config.GetInt("akka.log-dead-letters", 0);
                break;
            }
            LogDeadLettersDuringShutdown = Config.GetBoolean("akka.log-dead-letters-during-shutdown", false);
            AddLoggingReceive            = Config.GetBoolean("akka.actor.debug.receive", false);
            DebugAutoReceive             = Config.GetBoolean("akka.actor.debug.autoreceive", false);
            DebugLifecycle              = Config.GetBoolean("akka.actor.debug.lifecycle", false);
            FsmDebugEvent               = Config.GetBoolean("akka.actor.debug.fsm", false);
            DebugEventStream            = Config.GetBoolean("akka.actor.debug.event-stream", false);
            DebugUnhandledMessage       = Config.GetBoolean("akka.actor.debug.unhandled", false);
            DebugRouterMisconfiguration = Config.GetBoolean("akka.actor.debug.router-misconfiguration", false);
            Home = Config.GetString("akka.home", "");
            DefaultVirtualNodesFactor = Config.GetInt("akka.actor.deployment.default.virtual-nodes-factor", 0);

            SchedulerClass           = Config.GetString("akka.scheduler.implementation", null);
            SchedulerShutdownTimeout = Config.GetTimeSpan("akka.scheduler.shutdown-timeout", null);

            CoordinatedShutdownTerminateActorSystem      = Config.GetBoolean("akka.coordinated-shutdown.terminate-actor-system");
            CoordinatedShutdownRunByActorSystemTerminate = Config.GetBoolean("akka.coordinated-shutdown.run-by-actor-system-terminate");

            if (CoordinatedShutdownRunByActorSystemTerminate && !CoordinatedShutdownTerminateActorSystem)
            {
                throw new ConfigurationException(
                          "akka.coordinated-shutdown.run-by-actor-system-terminate=on and " +
                          "akka.coordinated-shutdown.terminate-actor-system=off is not a supported configuration combination.");
            }

            //TODO: dunno.. we don't have FiniteStateMachines, don't know what the rest is

            /*
             *  final val SchedulerClass: String = getString("akka.scheduler.implementation")
             *  final val Daemonicity: Boolean = getBoolean("akka.daemonic")
             *  final val DefaultVirtualNodesFactor: Int = getInt("akka.actor.deployment.default.virtual-nodes-factor")
             */
        }
예제 #9
0
        static void Main(string[] args)
        {
            using (var system = ActorSystem.Create("persistent-benchmark", config.WithFallback(ConfigurationFactory.Default())))
            {
                Console.WriteLine("Performance benchmark starting...");

                var actors = new IActorRef[ActorCount];
                for (int i = 0; i < ActorCount; i++)
                {
                    var pid = "a-" + i;
                    actors[i] = system.ActorOf(Props.Create(() => new PerformanceTestActor(pid)));
                }

                Task.WaitAll(actors.Select(a => a.Ask <Done>(Init.Instance)).Cast <Task>().ToArray());

                Console.WriteLine("All actors have been initialized...");

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                for (int i = 0; i < MessagesPerActor; i++)
                {
                    for (int j = 0; j < ActorCount; j++)
                    {
                        actors[j].Tell(new Store(1));
                    }
                }

                var finished = new Task[ActorCount];
                for (int i = 0; i < ActorCount; i++)
                {
                    finished[i] = actors[i].Ask <Finished>(Finish.Instance);
                }

                Task.WaitAll(finished);

                var elapsed = stopwatch.ElapsedMilliseconds;

                Console.WriteLine($"{ActorCount} actors stored {MessagesPerActor} events each in {elapsed/1000.0} sec. Average: {ActorCount*MessagesPerActor*1000.0/elapsed} events/sec");

                foreach (Task <Finished> task in finished)
                {
                    if (!task.IsCompleted || task.Result.State != MessagesPerActor)
                    {
                        throw new IllegalStateException("Actor's state was invalid");
                    }
                }
            }

            Console.ReadLine();
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Settings" /> class.
        /// </summary>
        /// <param name="system">The system.</param>
        /// <param name="config">The configuration.</param>
        /// <param name="setup">The setup class used to help bootstrap the <see cref="ActorSystem"/></param>
        /// <exception cref="ConfigurationException">
        /// This exception is thrown if the 'akka.actor.provider' configuration item is not a valid type name or a valid actor ref provider.
        /// </exception>
        public Settings(ActorSystem system, Config config, ActorSystemSetup setup)
        {
            Setup           = setup;
            _userConfig     = config;
            _fallbackConfig = ConfigurationFactory.Default();
            RebuildConfig();

            System = system;

            var providerSelectionSetup = Setup.Get <BootstrapSetup>()
                                         .FlatSelect(_ => _.ActorRefProvider)
                                         .Select(_ => _.Fqn)
                                         .GetOrElse(Config.GetString("akka.actor.provider", null));

            ProviderSelectionType = ProviderSelection.GetProvider(providerSelectionSetup);

            ConfigVersion = Config.GetString("akka.version", null);
            ProviderClass = ProviderSelectionType.Fqn;
            HasCluster    = ProviderSelectionType.HasCluster;

            var providerType = Type.GetType(ProviderClass);

            if (providerType == null)
            {
                throw new ConfigurationException($"'akka.actor.provider' is not a valid type name : '{ProviderClass}'");
            }
            if (!typeof(IActorRefProvider).IsAssignableFrom(providerType))
            {
                throw new ConfigurationException($"'akka.actor.provider' is not a valid actor ref provider: '{ProviderClass}'");
            }

            SupervisorStrategyClass = Config.GetString("akka.actor.guardian-supervisor-strategy", null);

            AskTimeout           = Config.GetTimeSpan("akka.actor.ask-timeout", null, allowInfinite: true);
            CreationTimeout      = Config.GetTimeSpan("akka.actor.creation-timeout", null);
            UnstartedPushTimeout = Config.GetTimeSpan("akka.actor.unstarted-push-timeout", null);

            SerializeAllMessages = Config.GetBoolean("akka.actor.serialize-messages", false);
            SerializeAllCreators = Config.GetBoolean("akka.actor.serialize-creators", false);

            LogLevel           = Config.GetString("akka.loglevel", null);
            StdoutLogLevel     = Config.GetString("akka.stdout-loglevel", null);
            Loggers            = Config.GetStringList("akka.loggers", new string[] { });
            LoggersDispatcher  = Config.GetString("akka.loggers-dispatcher", null);
            LoggerStartTimeout = Config.GetTimeSpan("akka.logger-startup-timeout", null);
            LoggerAsyncStart   = Config.GetBoolean("akka.logger-async-start", false);

            //handled
            LogConfigOnStart = Config.GetBoolean("akka.log-config-on-start", false);
            LogDeadLetters   = 0;
            switch (Config.GetString("akka.log-dead-letters", null))
            {
            case "on":
            case "true":
            case "yes":
                LogDeadLetters = int.MaxValue;
                break;

            case "off":
            case "false":
            case "no":
                LogDeadLetters = 0;
                break;

            default:
                LogDeadLetters = Config.GetInt("akka.log-dead-letters", 0);
                break;
            }
            LogDeadLettersDuringShutdown = Config.GetBoolean("akka.log-dead-letters-during-shutdown", false);

            const string key = "akka.log-dead-letters-suspend-duration";

            LogDeadLettersSuspendDuration = Config.GetString(key, null) == "infinite" ? Timeout.InfiniteTimeSpan : Config.GetTimeSpan(key);

            AddLoggingReceive           = Config.GetBoolean("akka.actor.debug.receive", false);
            DebugAutoReceive            = Config.GetBoolean("akka.actor.debug.autoreceive", false);
            DebugLifecycle              = Config.GetBoolean("akka.actor.debug.lifecycle", false);
            FsmDebugEvent               = Config.GetBoolean("akka.actor.debug.fsm", false);
            DebugEventStream            = Config.GetBoolean("akka.actor.debug.event-stream", false);
            DebugUnhandledMessage       = Config.GetBoolean("akka.actor.debug.unhandled", false);
            DebugRouterMisconfiguration = Config.GetBoolean("akka.actor.debug.router-misconfiguration", false);
            Home = Config.GetString("akka.home", "");
            DefaultVirtualNodesFactor = Config.GetInt("akka.actor.deployment.default.virtual-nodes-factor", 0);

            SchedulerClass           = Config.GetString("akka.scheduler.implementation", null);
            SchedulerShutdownTimeout = Config.GetTimeSpan("akka.scheduler.shutdown-timeout", null);

            CoordinatedShutdownTerminateActorSystem      = Config.GetBoolean("akka.coordinated-shutdown.terminate-actor-system");
            CoordinatedShutdownRunByActorSystemTerminate = Config.GetBoolean("akka.coordinated-shutdown.run-by-actor-system-terminate");

            if (CoordinatedShutdownRunByActorSystemTerminate && !CoordinatedShutdownTerminateActorSystem)
            {
                throw new ConfigurationException(
                          "akka.coordinated-shutdown.run-by-actor-system-terminate=on and " +
                          "akka.coordinated-shutdown.terminate-actor-system=off is not a supported configuration combination.");
            }
        }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActorSystemImpl"/> class.
 /// </summary>
 /// <param name="name">The name given to the actor system.</param>
 public ActorSystemImpl(string name)
     : this(name, ConfigurationFactory.Default(), ActorSystemSetup.Empty)
 {
 }
예제 #12
0
 /// <summary>
 /// Creates a new <see cref="ActorSystem"/> with the specified name.
 /// </summary>
 /// <param name="name">The name of the actor system to create. The name must be uri friendly.
 /// <remarks>Must contain only word characters (i.e. [a-zA-Z0-9] plus non-leading '-'</remarks>
 /// </param>
 /// <returns>A newly created actor system with the given name.</returns>
 public static ActorSystem Create(string name)
 {
     return(CreateAndStartSystem(name, ConfigurationFactory.Default()));
 }