public void SucessfulRequest() { var stockStreamConv = new StockHistoryRequestConversation(); stockStreamConv.SetInitialState(new StockHistoryRequestState(stockStreamConv)); ConversationManager.AddConversation(stockStreamConv); string conversationId = stockStreamConv.Id; //Verify conversation exists in Conversation Manager Assert.IsTrue(ConversationManager.ConversationExists(conversationId)); //Create fake response message and process it var stockStreamResponse = new TcpEnvelope(new StockHistoryResponseMessage() { MessageID = "123-abc" }); stockStreamResponse.Contents.ConversationID = stockStreamConv.Id; ConversationManager.ProcessIncomingMessage(stockStreamResponse); //Conversation over but we hold onto the done state for a little //in case we need to handle a retry. Ensure it has not yet been //removed from Conversation Manager Assert.IsTrue(ConversationManager.ConversationExists(conversationId)); var retrycount = Config.GetInt(Config.DEFAULT_RETRY_COUNT); var timeout = Config.GetInt(Config.DEFAULT_TIMEOUT); Thread.Sleep((int)((retrycount * 2) * timeout * 1.5)); //Conversation should have cleaned itself up now... Assert.IsFalse(ConversationManager.ConversationExists(conversationId)); }
public void RequestSucceed() { string RequestConvId = "5-562"; string RequestMessageId = "5-7-1654"; string ClientIp = "192.168.1.31"; int ClientPort = 5682; var RequestMessage = new StockHistoryRequestMessage() { ConversationID = RequestConvId, MessageID = RequestMessageId }; Envelope Request = new TcpEnvelope(RequestMessage, ClientIp, ClientPort); var localConv = ConversationManager.GetConversation(RequestConvId); Assert.IsNull(localConv); Assert.IsNull(mock); var numClients = ClientManager.Clients.Count; ConversationManager.ProcessIncomingMessage(Request); localConv = ConversationManager.GetConversation(RequestConvId); Assert.IsNotNull(localConv); Assert.IsTrue(localConv.CurrentState is ConversationDoneState); mock.Verify(state => state.Prepare(), Times.Once); mock.Verify(state => state.Send(), Times.Once); mock.Verify(state => state.HandleTimeout(), Times.Never); }
public override Envelope Prepare() { var mes = MessageFactory.GetMessage <StockHistoryRequestMessage>(Config.GetClientProcessNumber(), 0); mes.ConversationID = Conversation.Id; var stockServerIp = Config.GetString(Config.STOCK_SERVER_IP); var stockSerevrPort = Config.GetInt(Config.STOCK_SERVER_TCP_PORT); var stockServer = new IPEndPoint(IPAddress.Parse(stockServerIp), stockSerevrPort); ComService.AddTcpClient(0, stockServer); var env = new TcpEnvelope(mes, stockServerIp, stockSerevrPort); return(env); }
public override Envelope Prepare() { Log.Debug($"{nameof(Prepare)} (enter)"); var responseMessage = MessageFactory.GetMessage <StockHistoryResponseMessage>(Config.GetInt(Config.STOCK_SERVER_PROCESS_NUM), 0) as StockHistoryResponseMessage; responseMessage.ConversationID = Conversation.Id; responseMessage.RecentHistory = StockData.GetRecentHistory(TicksRequested); var responseEnvelope = new TcpEnvelope(responseMessage) { To = this.To, Key = TcpKey }; Log.Debug($"{nameof(Prepare)} (exit)"); return(responseEnvelope); }
public override Envelope Prepare() { Log.Debug($"{nameof(Prepare)} (enter)"); Envelope env = null; //Build request message var processNum = Config.GetInt(Config.BROKER_PROCESS_NUM); var message = MessageFactory.GetMessage <StockHistoryRequestMessage>(processNum, 0); message.ConversationID = Conversation.Id; var stockServerIp = Config.GetString(Config.STOCK_SERVER_IP); var stockSerevrPort = Config.GetInt(Config.STOCK_SERVER_TCP_PORT); var address = new IPEndPoint(IPAddress.Parse(stockServerIp), stockSerevrPort); ComService.AddTcpClient(0, address); env = new TcpEnvelope(message, Config.GetString(Config.STOCK_SERVER_IP), Config.GetInt(Config.STOCK_SERVER_TCP_PORT)); Log.Debug($"{nameof(Prepare)} (exit)"); return(env); }
public StockHistoryResponseState(TcpEnvelope env, Conversation conversation) : base(env, conversation, null) { TcpKey = env.Key; TicksRequested = (env.Contents as StockHistoryRequestMessage).TicksRequested; }