public void Create() { this.brokerIsRunning = BrokerRunning.IsRunningWithEmptyQueues(ROUTE); this.brokerIsRunning.Apply(); var connectionFactory = new CachingConnectionFactory(); connectionFactory.Port = BrokerTestUtils.GetPort(); this.template = new RabbitTemplate(connectionFactory); }
public void TearDown() { environment.Apply(); if (environment.IsActive()) { var brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(NODE_NAME); brokerAdmin.StopNode(); } }
public void DeclareQueue() { this.brokerIsRunning.Apply(); var connectionFactory = new CachingConnectionFactory(); connectionFactory.ChannelCacheSize = this.concurrentConsumers; connectionFactory.Port = BrokerTestUtils.GetPort(); this.template.ConnectionFactory = connectionFactory; }
public void CreateConnectionFactory() { this.brokerIsRunning = BrokerRunning.IsRunningWithEmptyQueues(this.queue); this.brokerIsRunning.Apply(); var connectionFactory = new CachingConnectionFactory(); connectionFactory.ChannelCacheSize = this.concurrentConsumers; connectionFactory.Port = BrokerTestUtils.GetPort(); this.template.ConnectionFactory = connectionFactory; }
public void Init() { environment.Apply(); this.brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(NODE_NAME); var status = this.brokerAdmin.GetStatus(); if (!status.IsRunning) { this.brokerAdmin.StartBrokerApplication(); } }
public void DeclareQueue() { // if (repeat.isInitialized()) { // // Important to prevent concurrent re-initialization // return; // } this.connectionFactory = new CachingConnectionFactory(); this.connectionFactory.ChannelCacheSize = 4; this.connectionFactory.Port = BrokerTestUtils.GetPort(); this.template.ConnectionFactory = this.connectionFactory; }
public void CreateConnectionFactory() { if (environment.IsActive()) { var connectionFactory = new CachingConnectionFactory(); connectionFactory.ChannelCacheSize = this.concurrentConsumers; connectionFactory.Port = BrokerTestUtils.GetAdminPort(); this.connectionFactory = connectionFactory; this.brokerIsRunning = BrokerRunning.IsRunningWithEmptyQueues(this.queue); this.brokerIsRunning.Apply(); } }
private RabbitTemplate CreateTemplate(int concurrentConsumers) { var template = new RabbitTemplate(); // SingleConnectionFactory connectionFactory = new SingleConnectionFactory(); var connectionFactory = new CachingConnectionFactory(); connectionFactory.ChannelCacheSize = concurrentConsumers; connectionFactory.Port = BrokerTestUtils.GetPort(); template.ConnectionFactory = connectionFactory; return(template); }
public void TestGetQueues() { AbstractConnectionFactory connectionFactory = new SingleConnectionFactory(); connectionFactory.Port = BrokerTestUtils.GetAdminPort(); Queue queue = new RabbitAdmin(connectionFactory).DeclareQueue(); Assert.AreEqual("/", connectionFactory.VirtualHost); List <QueueInfo> queues = this.brokerAdmin.GetQueues(); Assert.AreEqual(queue.Name, queues[0].Name); }
/// <summary>Does the test.</summary> /// <param name="concurrentConsumers">The concurrent consumers.</param> /// <param name="configurer">The configurer.</param> private void DoTest(int concurrentConsumers, IContainerConfigurer configurer) { var messageCount = 10; var template = new RabbitTemplate(); var connectionFactory = new CachingConnectionFactory(); connectionFactory.ChannelCacheSize = concurrentConsumers; connectionFactory.Port = BrokerTestUtils.GetPort(); template.ConnectionFactory = connectionFactory; var messageConverter = new SimpleMessageConverter(); messageConverter.CreateMessageIds = true; template.MessageConverter = messageConverter; for (var i = 0; i < messageCount; i++) { template.ConvertAndSend(queue1.Name, i); template.ConvertAndSend(queue2.Name, i); } var container = new SimpleMessageListenerContainer(connectionFactory); var latch = new CountdownEvent(messageCount * 2); var listener = new MultiplePocoListener(latch); container.MessageListener = new MessageListenerAdapter(listener); container.AcknowledgeMode = AcknowledgeModeUtils.AcknowledgeMode.Auto; container.ChannelTransacted = true; container.ConcurrentConsumers = concurrentConsumers; configurer.Configure(container); container.AfterPropertiesSet(); container.Start(); try { var timeout = Math.Min((1 + messageCount) / concurrentConsumers, 50); Logger.Info("Timeout: " + timeout); var waited = latch.Wait(timeout * 1000); Logger.Info("All messages recovered: " + waited); Assert.AreEqual(concurrentConsumers, container.ActiveConsumerCount); Assert.True(waited, "Timed out waiting for messages"); } catch (ThreadInterruptedException e) { Thread.CurrentThread.Interrupt(); throw new ThreadStateException("unexpected interruption"); } finally { container.Shutdown(); Assert.AreEqual(0, container.ActiveConsumerCount); } Assert.Null(template.ReceiveAndConvert(queue1.Name)); Assert.Null(template.ReceiveAndConvert(queue2.Name)); }
public void TestDoubleDeclarationOfAutodeleteQueue() { // No error expected here: the queue is autodeleted when the last consumer is cancelled, but this one never has // any consumers. var connectionFactory1 = new CachingConnectionFactory(); connectionFactory1.Port = BrokerTestUtils.GetPort(); var connectionFactory2 = new CachingConnectionFactory(); connectionFactory2.Port = BrokerTestUtils.GetPort(); var queue = new Queue("test.queue", false, false, true); new RabbitAdmin(connectionFactory1).DeclareQueue(queue); new RabbitAdmin(connectionFactory2).DeclareQueue(queue); connectionFactory1.Dispose(); connectionFactory2.Dispose(); }
public void SetUp() { try { if (environment.IsActive()) { // Set up broker admin for non-root user this.brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(); // "rabbit@LOCALHOST", 5672); this.brokerAdmin.StartNode(); } } catch (Exception ex) { Logger.Error("An error occurred during SetUp", ex); Assert.Fail("An error occurred during SetUp."); } }
/// <summary>Creates the template.</summary> /// <param name="concurrentConsumers">The concurrent consumers.</param> /// <returns>The template.</returns> private RabbitTemplate CreateTemplate(int concurrentConsumers) { var template = new RabbitTemplate(); var connectionFactory = new CachingConnectionFactory(); connectionFactory.ChannelCacheSize = concurrentConsumers; connectionFactory.Port = BrokerTestUtils.GetPort(); template.ConnectionFactory = connectionFactory; if (this.messageConverter == null) { var internalmessageConverter = new SimpleMessageConverter(); internalmessageConverter.CreateMessageIds = true; this.messageConverter = internalmessageConverter; } template.MessageConverter = this.messageConverter; return(template); }
public void RepeatLifecycle() { for (var i = 1; i <= 20; i++) { this.TestStopAndStartBroker(); Thread.Sleep(200); // if (i % 5 == 0) // { Logger.Debug("i = " + i); // } } var brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(NODE_NAME); brokerAdmin.StopNode(); }
public void TestTransactionalLowLevel() { var template = new RabbitTemplate(); var connectionFactory = new CachingConnectionFactory(); connectionFactory.Port = BrokerTestUtils.GetPort(); template.ConnectionFactory = connectionFactory; var blockingQueueConsumer = new BlockingQueueConsumer(connectionFactory, new DefaultMessagePropertiesConverter(), new ActiveObjectCounter <BlockingQueueConsumer>(), AcknowledgeModeUtils.AcknowledgeMode.Auto, true, 1, queue.Name); blockingQueueConsumer.Start(); connectionFactory.Dispose(); // TODO: make this into a proper assertion. An exception can be thrown here by the Rabbit client and printed to // stderr without being rethrown (so hard to make a test fail). blockingQueueConsumer.Stop(); Assert.IsNull(template.ReceiveAndConvert(queue.Name)); }
public void TestStartNode() { // Set up broker admin for non-root user var brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(NODE_NAME); var status = brokerAdmin.GetStatus(); try { // Stop it if it is already running if (status.IsReady) { brokerAdmin.StopBrokerApplication(); Thread.Sleep(1000); } } catch (OtpException e) { // Not useful for test. } status = brokerAdmin.GetStatus(); if (!status.IsRunning) { brokerAdmin.StartBrokerApplication(); } status = brokerAdmin.GetStatus(); try { Assert.False(status.Nodes == null || status.Nodes.Count < 1, "Broker node did not start. Check logs for hints."); Assert.True(status.IsRunning, "Broker node not running. Check logs for hints."); Assert.True(status.IsReady, "Broker application not running. Check logs for hints."); Thread.Sleep(1000); brokerAdmin.StopBrokerApplication(); Thread.Sleep(1000); } finally { brokerAdmin.StopNode(); } }
public void TestArgumentsQueue() { var queue = this.objectFactory.GetObject <Queue>("arguments"); Assert.IsNotNull(queue); var template = new RabbitTemplate(new CachingConnectionFactory(BrokerTestUtils.GetPort())); var rabbitAdmin = new RabbitAdmin(template.ConnectionFactory); rabbitAdmin.DeleteQueue(queue.Name); rabbitAdmin.DeclareQueue(queue); Assert.AreEqual(100L, queue.Arguments["x-message-ttl"]); template.ConvertAndSend(queue.Name, "message"); Thread.Sleep(200); var result = (string)template.ReceiveAndConvert(queue.Name); Assert.AreEqual(null, result); }
public void TestStopAndStartBroker() { // Set up broker admin for non-root user var brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(NODE_NAME); var status = brokerAdmin.GetStatus(); status = brokerAdmin.GetStatus(); if (!status.IsRunning) { brokerAdmin.StartBrokerApplication(); } brokerAdmin.StopBrokerApplication(); status = brokerAdmin.GetStatus(); Assert.AreEqual(0, status.RunningNodes.Count); brokerAdmin.StartBrokerApplication(); status = brokerAdmin.GetStatus(); this.AssertBrokerAppRunning(status); }
public void IntegrationTestsUserCrudWithModuleAdapter() { try { var adapter = new Dictionary <string, string>(); // Switch two functions with identical inputs! adapter.Add("rabbit_auth_backend_internal%add_user", "rabbit_auth_backend_internal%change_password"); adapter.Add("rabbit_auth_backend_internal%change_password", "rabbit_auth_backend_internal%add_user"); this.brokerAdmin.ModuleAdapter = adapter; var users = this.brokerAdmin.ListUsers(); if (users.Contains("joe")) { this.brokerAdmin.DeleteUser("joe"); } Thread.Sleep(1000); this.brokerAdmin.ChangeUserPassword("joe", "sales"); Thread.Sleep(1000); this.brokerAdmin.AddUser("joe", "trader"); Thread.Sleep(1000); users = this.brokerAdmin.ListUsers(); if (users.Contains("joe")) { Thread.Sleep(1000); this.brokerAdmin.DeleteUser("joe"); } } catch (Exception ex) { Logger.Error("An error occurred", ex); throw; } finally { // Need to ensure that we reset the module adapter that we swizzled with above, otherwise our other tests will be unreliable. this.brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(); } }
public void Init() { this.factory.HostName = Dns.GetHostName().ToUpper(); this.factory.Port = BrokerTestUtils.GetPort(); this.conn = this.factory.CreateConnection(); this.noTxChannel = this.conn.CreateModel(); this.txChannel = this.conn.CreateModel(); // Note: the Java client includes a convenience method with one int argument that sets the prefetchSize to 0 and global to false. this.txChannel.BasicQos(0, 1, false); this.txChannel.TxSelect(); try { this.noTxChannel.QueueDelete("test.queue"); } catch (Exception e) { this.noTxChannel = this.conn.CreateModel(); } this.noTxChannel.QueueDeclare("test.queue", true, false, false, null); }
public void FixtureSetUp() { NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler)); try { if (Environment.IsActive()) { // Set up broker admin for non-root user this.brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(); // "rabbit@LOCALHOST", 5672); this.brokerAdmin.StartNode(); } } catch (Exception ex) { Logger.Error("An error occurred during SetUp", ex); Assert.Fail("An error occurred during SetUp."); } if (!this.brokerFederated.Apply()) { Assert.Ignore("Rabbit broker is not running. Ignoring integration test fixture."); } }
public void End() { var brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(NODE_NAME); brokerAdmin.StopNode(); }
public void SetUp() { this.connectionFactory = new CachingConnectionFactory(); this.brokerIsRunning = BrokerRunning.IsRunning(); this.connectionFactory.Port = BrokerTestUtils.GetPort(); }
/// <summary> /// Initializes a new instance of the <see cref="RabbitAdminIntegrationTests"/> class. /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> public RabbitAdminIntegrationTests() { this.connectionFactory.Port = BrokerTestUtils.GetPort(); }