private static void Run() { Log.Logger = LoggerFactory.Logger; Console.WriteLine("AkkaLibrary Test Harness."); var exitEvent = new ManualResetEvent(false); Console.CancelKeyPress += (sender, eventArgs) => { eventArgs.Cancel = true; exitEvent.Set(); }; var pluginSystem = PluginSystemFactory.NewPluginSystem("TestActorSystem", CommonConfigs.BasicConfig()); var registry = pluginSystem.PluginRegistryRef; var system = pluginSystem.System; //=================================================== var config = new TestPluginConfiguration { Name = "test-plugin" }; var testPlugin = pluginSystem.CreatePlugin(config); //=================================================== Console.WriteLine("Press Ctrl+C to terminate."); exitEvent.WaitOne(); var terminateTask = system.Terminate(); var success = terminateTask.Wait(TimeSpan.FromSeconds(5)); Log.Information($"Actor system terminated {(success ? "successfully" : "unsuccessfully")}."); Log.CloseAndFlush(); }
public void ValidatePluginStopError() { TestLogger logger = new TestLogger(); TestPluginConfiguration pluginConfiguration = new TestPluginConfiguration(); pluginConfiguration.AddConfigurationItem(new TestPluginConfigurationItem() { Description = "Stop Error", Assembly = "Host.Tests.Plugin", Type = "Host.Tests.Plugin.OnStopError", BaseDirectory = _baseDirectory }); HostService hostService = new HostService(logger, pluginConfiguration); hostService.OnStart(new string[0]); hostService.OnStop(); Assert.Contains("Stopping Stop Error.", logger.Messages); Assert.IsTrue(logger.Messages.Count(m => m.StartsWith("Stop Error failed to stop.")) == 1); }
public void ValidatePluginStartAndStop() { TestLogger logger = new TestLogger(); TestPluginConfiguration pluginConfiguration = new TestPluginConfiguration(); pluginConfiguration.AddConfigurationItem(new TestPluginConfigurationItem() { Description = "Well Behaved Plugin", Assembly = "Host.Tests.Plugin", Type = "Host.Tests.Plugin.WellBehavedPlugin", BaseDirectory = _baseDirectory }); HostService hostService = new HostService(logger, pluginConfiguration); hostService.OnStart(new string[0]); hostService.OnStop(); Assert.Contains("Well Behaved Plugin started successfully.", logger.Messages); Assert.Contains("Well Behaved Plugin stopped successfully.", logger.Messages); }
public void ValidatePluginStartError() { TestLogger logger = new TestLogger(); TestPluginConfiguration pluginConfiguration = new TestPluginConfiguration(); pluginConfiguration.AddConfigurationItem(new TestPluginConfigurationItem() { Description = "Start Error", Assembly = "Host.Tests.Plugin", Type = "Host.Tests.Plugin.OnStartError", BaseDirectory = _baseDirectory }); HostService hostService = new HostService(logger, pluginConfiguration); var exception = Assert.Catch <AggregateException>(() => hostService.OnStart(new string[0])); Assert.That(exception.Message, Is.EqualTo("One or more plugins failed to start. See inner exceptions for more details.")); Assert.Contains("Error in OnStart", exception.InnerExceptions.Select(e => e.Message).ToList(), "The aggregate exception thrown from the service host should contain all exceptions thrown from plugins."); }