public void FailoverTransportFailOnSendMessageTest() { Uri uri = new Uri("failover:(mock://localhost:61616?transport.failOnCreate=true)?" + "transport.useExponentialBackOff=false&transport.maxReconnectAttempts=3&transport.initialReconnectDelay=100"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.Command = OnCommand; transport.Exception = OnException; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.UseExponentialBackOff); Assert.AreEqual(3, failover.MaxReconnectAttempts); Assert.AreEqual(100, failover.InitialReconnectDelay); transport.Start(); ActiveMQMessage message = new ActiveMQMessage(); Assert.Throws <IOException>(delegate() { transport.Oneway(message); }, "Oneway call should block and then throw."); Assert.IsNotEmpty(this.exceptions); Assert.IsFalse(failover.IsConnected); } }
public void FailoverTransportWithBackupsTest() { Uri uri = new Uri("failover:(mock://localhost:61616,mock://localhost:61618)?randomize=false&backup=true"); FailoverTransportFactory factory = new FailoverTransportFactory(); ITransport transport = factory.CreateTransport(uri); Assert.IsNotNull(transport); transport.Command = new CommandHandler(OnCommand); transport.Exception = new ExceptionHandler(OnException); FailoverTransport failover = (FailoverTransport)transport.Narrow(typeof(FailoverTransport)); Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); Assert.IsTrue(failover.Backup); transport.Start(); Thread.Sleep(1000); Assert.IsTrue(failover.IsConnected); transport.Stop(); transport.Dispose(); }
public async Task OpenWireCommandsTest() { Uri uri = new Uri("failover:(mock://localhost:61616)?transport.randomize=false"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.CommandAsync = OnCommand; transport.Exception = OnException; transport.Resumed = OnResumed; transport.Interrupted = OnInterrupted; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); await transport.StartAsync(); Thread.Sleep(1000); Assert.IsTrue(failover.IsConnected); ConnectionInfo connection = createConnection(); await transport.RequestAsync(connection); SessionInfo session1 = createSession(connection); await transport.RequestAsync(session1); SessionInfo session2 = createSession(connection); await transport.RequestAsync(session2); ConsumerInfo consumer1 = createConsumer(session1); await transport.RequestAsync(consumer1); ConsumerInfo consumer2 = createConsumer(session1); await transport.RequestAsync(consumer2); ConsumerInfo consumer3 = createConsumer(session2); await transport.RequestAsync(consumer3); ProducerInfo producer1 = createProducer(session2); await transport.RequestAsync(producer1); // Remove the Producers disposeOf(transport, producer1); // Remove the Consumers disposeOf(transport, consumer1); disposeOf(transport, consumer2); disposeOf(transport, consumer3); // Remove the Session instances. disposeOf(transport, session1); disposeOf(transport, session2); // Indicate that we are done. ShutdownInfo shutdown = new ShutdownInfo(); transport.Oneway(shutdown); } }
public void FailoverTransportCreateFailOnCreateTest() { Uri uri = new Uri("failover:(mock://localhost:61616?transport.failOnCreate=true)?" + "useExponentialBackOff=false&maxReconnectAttempts=3&initialReconnectDelay=100"); FailoverTransportFactory factory = new FailoverTransportFactory(); ITransport transport = factory.CreateTransport(uri); Assert.IsNotNull(transport); transport.Command = new CommandHandler(OnCommand); transport.Exception = new ExceptionHandler(OnException); FailoverTransport failover = (FailoverTransport)transport.Narrow(typeof(FailoverTransport)); Assert.IsNotNull(failover); Assert.IsTrue(failover.MaxReconnectAttempts == 3); transport.Start(); Thread.Sleep(2000); Assert.IsNotEmpty(this.exceptions); Assert.IsFalse(failover.IsConnected); transport.Stop(); transport.Dispose(); }
public void FailoverTransportSendOnewayTimeoutTest() { Uri uri = new Uri( "failover:(mock://localhost:61616?transport.failOnCreate=true)?transport.timeout=1000"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.CommandAsync = OnCommand; transport.Exception = OnException; transport.Resumed = OnResumed; transport.Interrupted = OnInterrupted; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.AreEqual(1000, failover.Timeout); transport.Start(); Thread.Sleep(1000); ActiveMQMessage message = new ActiveMQMessage(); Assert.Throws <IOException>(delegate() { transport.Oneway(message); }); } }
public void FailoverTransportFailingBackupsTest() { Uri uri = new Uri( "failover:(mock://localhost:61616," + "mock://localhost:61618?transport.failOnCreate=true)?transport.randomize=false&transport.backup=true"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.CommandAsync = OnCommand; transport.Exception = OnException; transport.Resumed = OnResumed; transport.Interrupted = OnInterrupted; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); Assert.IsTrue(failover.Backup); transport.Start(); Thread.Sleep(2000); Assert.IsTrue(failover.IsConnected); } }
public void FailoverTransportCreateFailOnCreateTest2() { Uri uri = new Uri("failover:(mock://localhost:61616?transport.failOnCreate=true)?" + "transport.useExponentialBackOff=false&transport.startupMaxReconnectAttempts=3&transport.initialReconnectDelay=100"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.CommandAsync = OnCommand; transport.Exception = OnException; transport.Resumed = OnResumed; transport.Interrupted = OnInterrupted; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.UseExponentialBackOff); Assert.AreEqual(3, failover.StartupMaxReconnectAttempts); Assert.AreEqual(100, failover.InitialReconnectDelay); transport.Start(); Thread.Sleep(2000); Assert.IsNotEmpty(this.exceptions); Assert.IsFalse(failover.IsConnected); } }
public void FailoverTransportSendOnewayFailTest() { Uri uri = new Uri( "failover:(mock://localhost:61616?transport.failOnSendMessage=true," + "mock://localhost:61618)?transport.randomize=false"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.CommandAsync = OnCommand; transport.Exception = OnException; transport.Resumed = OnResumed; transport.Interrupted = OnInterrupted; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); failover.Resumed = OnResumed; transport.Start(); Thread.Sleep(1000); Assert.IsTrue(failover.IsConnected); // Ensure the current mock transport has the correct outgoing command handler MockTransport mock = transport.Narrow(typeof(MockTransport)) as MockTransport; Assert.IsNotNull(mock); Assert.AreEqual(61616, mock.RemoteAddress.Port); VerifyCommandHandlerSetting(transport, mock); mock.OutgoingCommand = OnOutgoingCommand; ActiveMQMessage message = new ActiveMQMessage(); int numMessages = 4; for (int i = 0; i < numMessages; ++i) { transport.Oneway(message); // Make sure we switched to second failover mock = transport.Narrow(typeof(MockTransport)) as MockTransport; Assert.IsNotNull(mock); Assert.AreEqual(61618, mock.RemoteAddress.Port); } Thread.Sleep(1000); Assert.AreEqual(numMessages, this.sent.Count); } }
public void FailoverTransportSendRequestFailTest() { Uri uri = new Uri( "failover:(mock://localhost:61616?failOnSendMessage=true," + "mock://localhost:61618)?randomize=false"); FailoverTransportFactory factory = new FailoverTransportFactory(); ITransport transport = factory.CreateTransport(uri); Assert.IsNotNull(transport); transport.Command = new CommandHandler(OnCommand); transport.Exception = new ExceptionHandler(OnException); FailoverTransport failover = (FailoverTransport)transport.Narrow(typeof(FailoverTransport)); Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); transport.Start(); Thread.Sleep(1000); Assert.IsTrue(failover.IsConnected); MockTransport mock = null; while (mock == null) { mock = (MockTransport)transport.Narrow(typeof(MockTransport)); } mock.OutgoingCommand = new CommandHandler(OnCommand); ActiveMQMessage message = new ActiveMQMessage(); transport.Request(message); transport.Request(message); transport.Request(message); transport.Request(message); Thread.Sleep(1000); Assert.IsTrue(this.received.Count == 4); transport.Stop(); transport.Dispose(); }
public void FailoverTransportSendOnewayMessageTest() { int numMessages = 1000; Uri uri = new Uri( "failover:(mock://localhost:61616)?randomize=false"); FailoverTransportFactory factory = new FailoverTransportFactory(); ITransport transport = factory.CreateTransport(uri); Assert.IsNotNull(transport); transport.Command = new CommandHandler(OnCommand); transport.Exception = new ExceptionHandler(OnException); FailoverTransport failover = (FailoverTransport)transport.Narrow(typeof(FailoverTransport)); Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); transport.Start(); Thread.Sleep(1000); Assert.IsTrue(failover.IsConnected); MockTransport mock = null; while (mock == null) { mock = (MockTransport)transport.Narrow(typeof(MockTransport)); } mock.OutgoingCommand = new CommandHandler(OnCommand); ActiveMQMessage message = new ActiveMQMessage(); for (int i = 0; i < numMessages; ++i) { transport.Oneway(message); } Thread.Sleep(2000); Assert.IsTrue(this.received.Count == numMessages); transport.Stop(); transport.Dispose(); }
public void TestPriorityBackupConfigPriorityURIsList() { Uri uri = new Uri("failover:(mock://localhost:61616,mock://localhost:61618)" + "?transport.randomize=false&transport.priorityBackup=true&" + "transport.priorityURIs=mock://localhost:61616,mock://localhost:61618"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.CommandAsync = OnCommand; transport.Exception = OnException; transport.Resumed = OnResumed; transport.Interrupted = OnInterrupted; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize, "Randomize should be false"); Assert.IsTrue(failover.PriorityBackup, "Prioirity Backup not set."); String priorityURIs = failover.PriorityURIs; String[] tokens = priorityURIs.Split(new Char[] { ',' }); Assert.AreEqual(2, tokens.Length, "Bad priorityURIs string: " + priorityURIs); transport.Start(); for (int i = 0; i < MAX_ATTEMPTS; ++i) { if (failover.IsConnected) { break; } Thread.Sleep(100); } Assert.IsTrue(failover.IsConnected); Assert.IsTrue(failover.IsConnectedToPriority); } }
public void FailoverTransportCreateTest() { Uri uri = new Uri("failover:(mock://localhost:61616)?transport.randomize=false"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.Command = OnCommand; transport.Exception = OnException; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); transport.Start(); Thread.Sleep(1000); Assert.IsTrue(failover.IsConnected); } }
public void FailoverTransportSendOnewayTimeoutTest() { Uri uri = new Uri( "failover:(mock://localhost:61616?failOnCreate=true)?timeout=1000"); FailoverTransportFactory factory = new FailoverTransportFactory(); ITransport transport = factory.CreateTransport(uri); Assert.IsNotNull(transport); transport.Command = new CommandHandler(OnCommand); transport.Exception = new ExceptionHandler(OnException); FailoverTransport failover = (FailoverTransport)transport.Narrow(typeof(FailoverTransport)); Assert.IsNotNull(failover); Assert.AreEqual(1000, failover.Timeout); transport.Start(); Thread.Sleep(1000); ActiveMQMessage message = new ActiveMQMessage(); try { transport.Oneway(message); Assert.Fail("Should have thrown an IOException after timeout."); } catch { } transport.Stop(); transport.Dispose(); }
public void FailoverTransportCreateTest() { Uri uri = new Uri("failover:(mock://localhost:61616)?transport.randomize=false"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.CommandAsync = OnCommand; transport.Exception = OnException; transport.Resumed = OnResumed; transport.Interrupted = OnInterrupted; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover, "Failed to create Transport"); Assert.IsFalse(failover.Randomize, "Failed to properly set Randomize flag"); transport.Start(); Thread.Sleep(2000); Assert.IsTrue(failover.IsConnected, "Transport should be connected"); } }
public void FailoverTransportFailOnSendMessageTest() { Uri uri = new Uri("failover:(mock://localhost:61616?transport.failOnCreate=true)?" + "useExponentialBackOff=false&maxReconnectAttempts=3&initialReconnectDelay=100"); FailoverTransportFactory factory = new FailoverTransportFactory(); ITransport transport = factory.CreateTransport(uri); Assert.IsNotNull(transport); transport.Command = new CommandHandler(OnCommand); transport.Exception = new ExceptionHandler(OnException); FailoverTransport failover = (FailoverTransport)transport.Narrow(typeof(FailoverTransport)); Assert.IsNotNull(failover); Assert.IsTrue(failover.MaxReconnectAttempts == 3); transport.Start(); try{ ActiveMQMessage message = new ActiveMQMessage(); transport.Oneway(message); Assert.Fail("Oneway call should block and then throw."); } catch (Exception) { } Assert.IsNotEmpty(this.exceptions); Assert.IsFalse(failover.IsConnected); transport.Stop(); transport.Dispose(); }
public void TestPriorityBackupConfig() { Uri uri = new Uri("failover:(mock://localhost:61616,mock://localhost:61618)" + "?transport.randomize=false&transport.priorityBackup=true"); FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.Command = OnCommand; transport.Exception = OnException; transport.Resumed = OnResumed; transport.Interrupted = OnInterrupted; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize, "Randomize should be false"); Assert.IsTrue(failover.PriorityBackup, "Prioirity Backup not set."); transport.Start(); for (int i = 0; i < MAX_ATTEMPTS; ++i) { if (failover.IsConnected) { break; } Thread.Sleep(100); } Assert.IsTrue(failover.IsConnected); Assert.IsTrue(failover.IsConnectedToPriority); } }
public void TestFailoverTransportConnectionControlHandling() { Uri uri = new Uri("failover:(mock://localhost:61613)?transport.randomize=false"); string reconnectTo = "mock://localhost:61616?transport.name=Reconnected"; string connectedBrokers = "mock://localhost:61617?transport.name=Broker1," + "mock://localhost:61618?transport.name=Broker2"; FailoverTransportFactory factory = new FailoverTransportFactory(); using (ITransport transport = factory.CreateTransport(uri)) { Assert.IsNotNull(transport); transport.Command = OnCommand; transport.Exception = OnException; FailoverTransport failover = transport.Narrow(typeof(FailoverTransport)) as FailoverTransport; Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); failover.Resumed = OnResumed; const int MAX_ATTEMPTS = 50; transport.Start(); for (int i = 0; i < MAX_ATTEMPTS; ++i) { if (failover.IsConnected) { break; } Thread.Sleep(100); } Assert.IsTrue(failover.IsConnected); // Ensure the current mock transport has the correct outgoing command handler MockTransport mock = transport.Narrow(typeof(MockTransport)) as MockTransport; Assert.IsNotNull(mock); Assert.AreEqual(61613, mock.RemoteAddress.Port); VerifyCommandHandlerSetting(transport, mock); mock.OutgoingCommand = OnOutgoingCommand; mock.InjectCommand(new ConnectionControl() { FaultTolerant = true, ReconnectTo = reconnectTo, ConnectedBrokers = connectedBrokers }); // Give a bit of time for the Command to actually be processed. Thread.Sleep(2000); failover.Remove(true, "mock://localhost:61613"); mock = null; for (int i = 0; i < MAX_ATTEMPTS; ++i) { mock = transport.Narrow(typeof(MockTransport)) as MockTransport; if (mock != null) { break; } Thread.Sleep(100); } Assert.IsNotNull(mock, "Error reconnecting to failover broker."); Assert.AreEqual(61616, mock.RemoteAddress.Port); Assert.AreEqual("Reconnected", mock.Name); } }
public void OpenWireCommandsTest() { Uri uri = new Uri("failover:(mock://localhost:61616)?randomize=false"); FailoverTransportFactory factory = new FailoverTransportFactory(); ITransport transport = factory.CreateTransport(uri); Assert.IsNotNull(transport); transport.Command = new CommandHandler(OnCommand); transport.Exception = new ExceptionHandler(OnException); FailoverTransport failover = (FailoverTransport)transport.Narrow(typeof(FailoverTransport)); Assert.IsNotNull(failover); Assert.IsFalse(failover.Randomize); transport.Start(); Thread.Sleep(1000); Assert.IsTrue(failover.IsConnected); ConnectionInfo connection = createConnection(); transport.Request(connection); SessionInfo session1 = createSession(connection); transport.Request(session1); SessionInfo session2 = createSession(connection); transport.Request(session2); ConsumerInfo consumer1 = createConsumer(session1); transport.Request(consumer1); ConsumerInfo consumer2 = createConsumer(session1); transport.Request(consumer2); ConsumerInfo consumer3 = createConsumer(session2); transport.Request(consumer3); ProducerInfo producer1 = createProducer(session2); transport.Request(producer1); // Remove the Producers disposeOf(producer1, transport); // Remove the Consumers disposeOf(consumer1, transport); disposeOf(consumer2, transport); disposeOf(consumer3, transport); // Remove the Session instances. disposeOf(session1, transport); disposeOf(session2, transport); // Indicate that we are done. ShutdownInfo shutdown = new ShutdownInfo(); transport.Oneway(shutdown); transport.Stop(); transport.Dispose(); }