public void should_read_non_acked_messages_since_oldest() { var peerId = new PeerId("PeerId"); var now = DateTime.UtcNow; var oldestNonAckedMessageTimestamp = now.AddHours(-2).AddMilliseconds(1); var transportMessages = new[] { CreateTransportMessage(peerId), CreateTransportMessage(peerId), CreateTransportMessage(peerId), }; var reader = CreateReader(peerId, oldestNonAckedMessageTimestamp); // first bucket - all acked InsertPersistentMessage(peerId, now.AddHours(-2), x => x.IsAcked = true); InsertPersistentMessage(peerId, oldestNonAckedMessageTimestamp, UpdatePersistentMessageWithNonAckedTransportMessage(transportMessages[0])); InsertPersistentMessage(peerId, now.AddHours(-2).AddMilliseconds(2), x => x.IsAcked = true); // second bucket - with non acked InsertPersistentMessage(peerId, now.AddHours(-1), x => x.IsAcked = true); InsertPersistentMessage(peerId, now.AddHours(-1).AddMilliseconds(1), UpdatePersistentMessageWithNonAckedTransportMessage(transportMessages[1])); InsertPersistentMessage(peerId, now.AddHours(-1).AddMilliseconds(2), x => x.IsAcked = true); // third bucket - with non acked InsertPersistentMessage(peerId, now.AddMilliseconds(-3), x => x.IsAcked = true); InsertPersistentMessage(peerId, now.AddMilliseconds(-2), UpdatePersistentMessageWithNonAckedTransportMessage(transportMessages[2])); InsertPersistentMessage(peerId, now.AddMilliseconds(-1), x => x.IsAcked = true); var nonAckedMessages = reader.GetUnackedMessages().ToList(); nonAckedMessages.Count.ShouldEqual(3); for (var i = 0; i < nonAckedMessages.Count; i++) { var transportMessage = TransportMessageDeserializer.Deserialize(nonAckedMessages[i]); transportMessage.DeepCompare(transportMessages[i]).ShouldBeTrue(); } }
public async Task Polling_From_Start_Works() { // Given: uint httpErrorDelay = 12345; var pollingPolicy = PollingDelays.DefaultPollingErrorDelays; pollingPolicy[HttpChannelPoller.PollingError.ErrorMakingHttpRequest] = httpErrorDelay; var loc = Path.Combine( TestContext.CurrentContext.TestDirectory, "http-responses\\sample.json"); var content = File.ReadAllText(loc); var testResponses = new List <Either <HttpError, string> >() { new Either <HttpError, string>(content) }; var initialPollState = BasicInitialPollState(pollingPolicy); Either <DeserializeError, TransportMessage> DeserializeTransportMessage(string s) => TransportMessageDeserializer.Deserialize( s, new Dictionary <string, Type> { { TestMessage.MessageName, typeof(TestMessage) } }); // When: PollState newPollStateTask = await MessageEndpointPoller.Execute( initialPollState, new TestHttpService(testResponses), new CancellationToken(), GetHandlerForMessageType, DeserializeTransportMessage); // Then //Assert.AreEqual(httpErrorDelay, newPollStateTask.DelayMs); Assert.AreEqual(4, TestMessageHandler.Counter); }
private static void Main(string[] args) { Logger.Trace("Start"); var cts = new CancellationTokenSource(); var ct = cts.Token; Either <DeserializeError, TransportMessage> DeserializeTransportMessage(string s) => TransportMessageDeserializer.Deserialize(s, MessageEndpointRepository.GetMessageTypeLookup()); foreach (var endpoint in GetMessageEndpoints()) { var messageEndpointState = new MessageEndpointState( endpoint.Channel, endpoint.LastSuccessfullyProcessedMessage, endpoint.Name); IHttpService ServiceCreator() => new HttpService(new UriBuilder( endpoint.Channel.HttpChannelBase.Scheme, endpoint.Channel.HttpChannelBase.Host, endpoint.Channel.HttpChannelBase.Port).Uri); MessageEndpointPoller.MainInfinitePollerAsync( messageEndpointState, HandlerFactory.GetHandlerForMessageType, DeserializeTransportMessage, endpoint.DefaultDelayMs, endpoint.PollingErrorDelays, ServiceCreator, ct); } Console.WriteLine("press enter to stop"); Console.Read(); cts.Cancel(); Logger.Trace("End"); }
private static TransportMessage DeserializeTransportMessage(byte[] row) => TransportMessageDeserializer.Deserialize(row);
private static TransportMessage CreatePersistentMessageFromRow(Row row) { return(TransportMessageDeserializer.Deserialize(row.GetValue <byte[]>("TransportMessage"))); }
public async Task When_Polling_Results_In_An_Http_Error_The_Returned_PollState_Has_Delay_Set_To_The_Specified_Http_Error_Delay() { // Given: uint httpErrorDelay = 12345; var pollingPolicy = PollingDelays.DefaultPollingErrorDelays; pollingPolicy[HttpChannelPoller.PollingError.ErrorMakingHttpRequest] = httpErrorDelay; var testResponses = new List <Either <HttpError, string> >() { new Either <HttpError, string>(new HttpError(HttpStatusCode.BadRequest)) }; Func <string, Either <DeserializeError, TransportMessage> > deserializeTransportMessage = s => TransportMessageDeserializer.Deserialize(s, new Dictionary <string, Type> { { TestMessage.MessageName, typeof(TestMessage) } }); var initialPollState = BasicInitialPollState(pollingPolicy); // When: PollState newPollStateTask = await MessageEndpointPoller.Execute( initialPollState, new TestHttpService(testResponses), new CancellationToken(), GetHandlerForMessageType, deserializeTransportMessage); // Then Assert.NotNull(newPollStateTask); Assert.AreEqual(httpErrorDelay, newPollStateTask.DelayMs); }