private IRequestPipeline CreatePipeline( Func <IEnumerable <Uri>, IConnectionPool> setupPool, Func <ConnectionSettings, ConnectionSettings> settingsSelector = null, IDateTimeProvider dateTimeProvider = null) { var pool = setupPool(new[] { TestClient.CreateNode(), TestClient.CreateNode(9201) }); var settings = new ConnectionSettings(pool, TestClient.CreateConnection()); settings = settingsSelector?.Invoke(settings) ?? settings; return(new FixedPipelineFactory(settings, dateTimeProvider ?? DateTimeProvider.Default).Pipeline); }
/// <summary> /// Assigns the role to be played by this test case. The test parameters are fully specified in the /// assignment message. When this method return the test case will be ready to execute. /// </summary> /// /// <param name="role"> The role to be played; sender or receiver. </param> /// <param name="assignRoleMessage"> The role assingment message, contains the full test parameters. </param> public void AssignRole(Roles role, IMessage assignRoleMessage) { log.Debug("public void AssignRole(Roles role = " + role + ", Message assignRoleMessage = " + assignRoleMessage + "): called"); // Reset the message count for a new test. messageCount = 0; // Take note of the role to be played. this.role = role; // Create a new connection to pass the test messages on. connection = TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); // Extract and retain the test parameters. numMessages = assignRoleMessage.Headers.GetInt("P2P_NUM_MESSAGES"); string queueAndKeyName = assignRoleMessage.Headers.GetString("P2P_QUEUE_AND_KEY_NAME"); channel.DeclareQueue(queueAndKeyName, false, true, true); channel.Bind(queueAndKeyName, ExchangeNameDefaults.DIRECT, queueAndKeyName); sendDestination = queueAndKeyName; log.Debug("numMessages = " + numMessages); log.Debug("sendDestination = " + sendDestination); log.Debug("role = " + role); switch (role) { // Check if the sender role is being assigned, and set up a message producer if so. case Roles.SENDER: publisher = channel.CreatePublisherBuilder() .WithExchangeName(ExchangeNameDefaults.DIRECT) .WithRoutingKey(sendDestination) .Create(); break; // Otherwise the receiver role is being assigned, so set this up to listen for messages. case Roles.RECEIVER: IMessageConsumer consumer = channel.CreateConsumerBuilder(sendDestination).Create(); consumer.OnMessage += new MessageReceivedDelegate(OnMessage); break; } connection.Start(); }
public void AssignRole(Roles role, IMessage assignRoleMessage) { log.Info("public void assignRole(Roles role = " + role + ", IMessage assignRoleMessage = " + assignRoleMessage + "): called"); // Reset the message count for a new test. messageCount = 0; // Take note of the role to be played. this.role = role; // Extract and retain the test parameters. numMessages = assignRoleMessage.Headers.GetInt("PUBSUB_NUM_MESSAGES"); messageSize = assignRoleMessage.Headers.GetInt("messageSize"); numReceivers = assignRoleMessage.Headers.GetInt("PUBSUB_NUM_RECEIVERS"); string sendKey = assignRoleMessage.Headers.GetString("PUBSUB_KEY"); sendDestination = sendKey; log.Info("numMessages = " + numMessages); log.Info("messageSize = " + messageSize); log.Info("sendKey = " + sendKey); log.Info("role = " + role); switch (role) { // Check if the sender role is being assigned, and set up a single message producer if so. case Roles.SENDER: // Create a new connection to pass the test messages on. connection = new IConnection[1]; channel = new IChannel[1]; connection[0] = TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); channel[0] = connection[0].CreateChannel(false, AcknowledgeMode.AutoAcknowledge); // Extract and retain the test parameters. publisher = channel[0].CreatePublisherBuilder() .WithExchangeName(ExchangeNameDefaults.TOPIC) .WithRoutingKey(sendDestination) .WithMandatory(false) .WithImmediate(false) .Create(); break; // Otherwise the receiver role is being assigned, so set this up to listen for messages on the required number // of receiver connections. case Roles.RECEIVER: // Create the required number of receiver connections. connection = new IConnection[numReceivers]; channel = new IChannel[numReceivers]; for (int i = 0; i < numReceivers; i++) { connection[i] = TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); channel[i] = connection[i].CreateChannel(false, AcknowledgeMode.AutoAcknowledge); IMessageConsumer consumer = channel[i].CreateConsumerBuilder(sendDestination).Create(); consumer.OnMessage += new MessageReceivedDelegate(OnMessage); } break; } // Start all the connection dispatcher threads running. foreach (IConnection con in connection) { con.Start(); } }