コード例 #1
0
        public async Task <RequestVoteResponse> Send(RequestVote requestVote)
        {
            try
            {
                var serverToSendMessageTo = _serviceRegistry.Get(RaftyServiceDiscoveryName.Get()).First(x => x.Id == requestVote.VoterId);
                var json = JsonConvert.SerializeObject(requestVote, Formatting.None, new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.All
                });
                var httpContent = new StringContent(json);
                httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                using (var httpClient = new HttpClient())
                {
                    httpClient.BaseAddress = serverToSendMessageTo.Location;
                    var response = await httpClient.PostAsync(_requestVoteUrl, httpContent);

                    response.EnsureSuccessStatusCode();
                    var content = await response.Content.ReadAsStringAsync();

                    var requestVoteResponse = JsonConvert.DeserializeObject <RequestVoteResponse>(content);
                    return(requestVoteResponse);
                }
            }
            catch (Exception exception)
            {
                _logger.LogError(new EventId(1), exception, "Error in Send(RequestVote requestVote)");
                throw;
            }
        }
コード例 #2
0
ファイル: ServiceRegistryTests.cs プロジェクト: falps/Rafty
 private void GivenAListOfRegisteredServices()
 {
     for (int i = 0; i < 5; i++)
     {
         var registerService = new RegisterService(RaftyServiceDiscoveryName.Get(), Guid.NewGuid(), new Uri($"www.rafty.co.uk:123{i}"));
         _inMemoryServiceRegistry.Register(registerService);
     }
 }
コード例 #3
0
ファイル: ServiceRegistryTests.cs プロジェクト: falps/Rafty
        public void can_register_service()
        {
            var registerService = new RegisterService(RaftyServiceDiscoveryName.Get(), Guid.NewGuid(), new Uri("http://www.rafty.co.uk"));

            this.Given(x => GivenAServiceToRegister(registerService))
            .When(x => WhenIRegisterTheService())
            .Then(x => ThenItIsRegistered())
            .BDDfy();
        }
コード例 #4
0
ファイル: ServiceRegistryTests.cs プロジェクト: falps/Rafty
 private void WhenIGetTheRegisteredServices()
 {
     _result = _inMemoryServiceRegistry.Get(RaftyServiceDiscoveryName.Get());
 }