public async void SetStatusAsync_CallsConsulClient() { var clientMoq = new Mock <IConsulClient>(); var agentMoq = new Mock <IAgentEndpoint>(); clientMoq.Setup(c => c.Agent).Returns(agentMoq.Object); var opts = new ConsulDiscoveryOptions(); var sch = new TtlScheduler(opts, clientMoq.Object); var builder = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { { "spring:application:name", "foobar" } }); var config = builder.Build(); var registration = ConsulRegistration.CreateRegistration(config, opts); var reg = new ConsulServiceRegistry(clientMoq.Object, opts, sch); await reg.SetStatusAsync(registration, "Up"); agentMoq.Verify(a => a.DisableServiceMaintenance(registration.InstanceId, default(CancellationToken)), Times.Once); await reg.SetStatusAsync(registration, "Out_of_Service"); agentMoq.Verify(a => a.EnableServiceMaintenance(registration.InstanceId, "OUT_OF_SERVICE", default(CancellationToken)), Times.Once); }
public async void DeregisterAsync_CallsServiceDeregister_RemovesHeartbeatFromScheduler() { var clientMoq = new Mock <IConsulClient>(); var agentMoq = new Mock <IAgentEndpoint>(); clientMoq.Setup(c => c.Agent).Returns(agentMoq.Object); var opts = new ConsulDiscoveryOptions(); var sch = new TtlScheduler(opts, clientMoq.Object); var reg = new ConsulServiceRegistry(clientMoq.Object, opts, sch); var builder = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { { "spring:application:name", "foobar" } }); var config = builder.Build(); var registration = ConsulRegistration.CreateRegistration(config, opts); await reg.RegisterAsync(registration); agentMoq.Verify(a => a.ServiceRegister(registration.Service, default(CancellationToken)), Times.Once); Assert.Single(sch._serviceHeartbeats); Assert.Contains(registration.InstanceId, sch._serviceHeartbeats.Keys); await reg.DeregisterAsync(registration); agentMoq.Verify(a => a.ServiceDeregister(registration.Service.ID, default(CancellationToken)), Times.Once); Assert.Empty(sch._serviceHeartbeats); }
public void DeegisterAsync_ThrowsOnNull() { var clientMoq = new Mock <IConsulClient>(); var agentMoq = new Mock <IAgentEndpoint>(); clientMoq.Setup(c => c.Agent).Returns(agentMoq.Object); var opts = new ConsulDiscoveryOptions(); var sch = new TtlScheduler(opts, clientMoq.Object); var reg = new ConsulServiceRegistry(clientMoq.Object, opts, sch); Assert.ThrowsAsync <ArgumentNullException>(() => reg.DeregisterAsync(null)); }
public async void GetStatusAsync_ReturnsExpected() { var opts = new ConsulDiscoveryOptions(); var builder = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { { "spring:application:name", "foobar" } }); var config = builder.Build(); var registration = ConsulRegistration.CreateRegistration(config, opts); var queryResult = new QueryResult <HealthCheck[]>() { Response = new HealthCheck[] { new HealthCheck() { ServiceID = registration.InstanceId, Name = "Service Maintenance Mode" }, new HealthCheck() { ServiceID = "foobar", Name = "Service Maintenance Mode" } } }; var result = Task.FromResult(queryResult); var clientMoq = new Mock <IConsulClient>(); var healthMoq = new Mock <IHealthEndpoint>(); clientMoq.Setup(c => c.Health).Returns(healthMoq.Object); healthMoq.Setup(h => h.Checks(registration.ServiceId, QueryOptions.Default, default(CancellationToken))).Returns(result); var sch = new TtlScheduler(opts, clientMoq.Object); var reg = new ConsulServiceRegistry(clientMoq.Object, opts, sch); var ret = await reg.GetStatusAsync(registration); Assert.Equal("OUT_OF_SERVICE", ret); }
public async Task ServiceRegistrationConsulNotAccessible() { var clientMock = new Mock <IConsulClient>(); clientMock .Setup(c => c.Agent.ServiceRegister(It.IsAny <AgentServiceRegistration>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new WriteResult { StatusCode = HttpStatusCode.NotFound })); IServiceRegistry registry = new ConsulServiceRegistry(clientMock.Object, this._loggerFactory); var registration = new ConsulServiceRegistration(this._agentServiceRegistration, TimeSpan.FromSeconds(10), this._loggerFactory.CreateLogger <ConsulServiceRegistryTest>()); var exceptions = await Record.ExceptionAsync(() => registry.RegisterServiceAsync(registration)); exceptions.ShouldBeNull(); clientMock.Verify(client => client.Agent.ServiceRegister(this._agentServiceRegistration, default(CancellationToken)), Times.Once); }
public void SetStatusAsync_ThrowsInvalidStatus() { var clientMoq = new Mock <IConsulClient>(); var agentMoq = new Mock <IAgentEndpoint>(); clientMoq.Setup(c => c.Agent).Returns(agentMoq.Object); var opts = new ConsulDiscoveryOptions(); var sch = new TtlScheduler(opts, clientMoq.Object); var builder = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { { "spring:application:name", "foobar" } }); var config = builder.Build(); var registration = ConsulRegistration.CreateRegistration(config, opts); var reg = new ConsulServiceRegistry(clientMoq.Object, opts, sch); Assert.ThrowsAsync <ArgumentException>(() => reg.SetStatusAsync(registration, string.Empty)); }
static void Main(string[] args) { var localXmlFileLocalActorPath = Environment.CurrentDirectory + @"\\XmlConfiguration\\LocalActor.xml"; var localXmlFileLocalActorConfiguration = LocalXmlFileActorConfiguration.Load(localXmlFileLocalActorPath); var localActor = new RpcActor(localXmlFileLocalActorConfiguration); var consul = new ConsulClient((c) => { c.Address = new Uri("http://*****:*****@"^notify(\d*)$").Success) { var match = Regex.Match(text, @"notify(\d*)$"); int totalCalls = 0; if (!int.TryParse(match.Groups[1].Value, out totalCalls)) { totalCalls = 1; } for (int i = 0; i < totalCalls; i++) { NotifyOrderDelivered(orderEventClient); } } else { _log.WarnFormat("Cannot parse the operation for input [{0}].", text); } } catch (Exception ex) { _log.Error(ex.Message, ex); } } rpcNode.Shutdown(); }