Ejemplo n.º 1
0
		public void ReportsBasicRuntimeStatistics()
		{
			var container = new WindsorContainer();

			container.Register(
				Component.For<IServiceHost>().Forward<MultitaskingServiceHost>().Instance(new MultitaskingServiceHost()));

			container.Register(Component.For<IHostedService>().Forward<FakeHostedService>().Instance(new FakeHostedService()));

			var runtime = new BasicFabric(container);

			var settings = new FabricRuntimeSettings();

			settings.ServiceHost.WithDefault(typeof(MultitaskingServiceHost));
			settings.HostedServices.WithDefault(new List<Type> { typeof(FakeHostedService) });

			runtime.Initialize(settings);

			runtime.Start();

			Assert.AreEqual(FabricRuntimeState.Started, runtime.State);
			Assert.AreEqual(FabricRuntimeState.Started, runtime.GetStatistics().RuntimeState);
			Assert.AreEqual(typeof(MultitaskingServiceHost), runtime.GetStatistics().ConfiguredServiceHost);
			Assert.AreEqual(typeof(FakeHostedService), runtime.GetStatistics().ConfiguredHostedServices[0]);
		}
Ejemplo n.º 2
0
		public void ReportsErrorsThrownByHostedServices()
		{
			var container = new WindsorContainer();

			container.Register(
				Component.For<IServiceHost>().Forward<MultitaskingServiceHost>().Instance(new MultitaskingServiceHost()));

			container.Register(
				Component.For<IHostedService>().Forward<FailingHostedService>().Instance(new FailingHostedService()));

			var runtime = new BasicFabric(container);

			var settings = new FabricRuntimeSettings();

			settings.ServiceHost.WithDefault(typeof(MultitaskingServiceHost));
			settings.HostedServices.WithDefault(new List<Type> { typeof(FailingHostedService) });

			runtime.Initialize(settings);

			runtime.Start();

			Assert.AreEqual(FabricRuntimeState.Started, runtime.State);

			Thread.Sleep(100); // let the exception have a chance to be thrown and caught

			var exceptions = runtime.GetExceptionsThrownByHostedServices();

			Assert.AreEqual(1, exceptions.Count);
		}
Ejemplo n.º 3
0
		private FabricRuntimeSettings getFabricSettings()
		{
			var fabricSettings = new FabricRuntimeSettings();

			fabricSettings.ServiceHost.WithDefault(typeof(MultitaskingServiceHost));
			fabricSettings.HostedServices.WithDefault(new List<Type> { typeof(CommandHost) });

			var messageChannel = new AzureMessageChannel(new JsonMessageSerializer());

			fabricSettings.InputChannel.WithDefault(messageChannel);
			fabricSettings.ErrorChannel.WithDefault(messageChannel);

			return fabricSettings;
		}
Ejemplo n.º 4
0
		public void ErrorFreeWithValidConfig()
		{
			var container = new WindsorContainer();

			container.Register(
				Component.For<IServiceHost>().Forward<MultitaskingServiceHost>().Instance(new MultitaskingServiceHost()));

			container.Register(Component.For<IHostedService>().Forward<FakeHostedService>().Instance(new FakeHostedService()));

			var runtime = new BasicFabric(container);

			var settings = new FabricRuntimeSettings();

			settings.ServiceHost.WithDefault(typeof(MultitaskingServiceHost));
			settings.HostedServices.WithDefault(new List<Type> { typeof(FakeHostedService) });

			runtime.Initialize(settings);
		}
Ejemplo n.º 5
0
		public void ThrowsWhenServiceHostNotResolvable()
		{
			var container = new WindsorContainer();

			var runtime = new BasicFabric(container);

			var settings = new FabricRuntimeSettings();

			settings.ServiceHost.WithDefault(GetType());
			settings.HostedServices.WithDefault(new List<Type> { GetType() });

			runtime.Initialize(settings);
		}
Ejemplo n.º 6
0
		public void ThrowsWhenHostedServiceNotResolvable()
		{
			var container = new WindsorContainer();

			container.Register(
				Component.For<IServiceHost>().Forward<MultitaskingServiceHost>().Instance(new MultitaskingServiceHost()));

			var runtime = new BasicFabric(container);

			var settings = new FabricRuntimeSettings();

			settings.ServiceHost.WithDefault(typeof(MultitaskingServiceHost));
			settings.HostedServices.WithDefault(new List<Type> { GetType() });

			runtime.Initialize(settings);

			runtime.Start();
		}
Ejemplo n.º 7
0
		public void ThrowsWhenConfigIsMissingServiceHost()
		{
			var container = new WindsorContainer();

			var runtime = new BasicFabric(container);

			var settings = new FabricRuntimeSettings();

			settings.HostedServices.WithDefault(new List<Type>());

			runtime.Initialize(settings);
		}