|
16 | 16 | package com.rabbitmq.client.test.functional; |
17 | 17 |
|
18 | 18 | import com.rabbitmq.client.*; |
19 | | - |
| 19 | +import com.rabbitmq.client.impl.AbstractCredentialsProvider; |
20 | 20 | import com.rabbitmq.client.impl.NetworkConnection; |
21 | 21 | import com.rabbitmq.client.impl.recovery.*; |
22 | 22 | import com.rabbitmq.client.test.BrokerTestCase; |
|
34 | 34 | import java.util.concurrent.TimeUnit; |
35 | 35 | import java.util.concurrent.TimeoutException; |
36 | 36 | import java.util.concurrent.atomic.AtomicInteger; |
| 37 | +import java.util.concurrent.atomic.AtomicLong; |
37 | 38 | import java.util.concurrent.atomic.AtomicReference; |
38 | 39 |
|
39 | 40 | import static org.junit.Assert.*; |
@@ -121,6 +122,42 @@ public class ConnectionRecovery extends BrokerTestCase { |
121 | 122 | c.abort(); |
122 | 123 | } |
123 | 124 | } |
| 125 | + |
| 126 | + // See https://github.com/rabbitmq/rabbitmq-java-client/pull/350 . We want to request fresh creds when recovering. |
| 127 | + @Test public void connectionRecoveryRequestsCredentialsAgain() throws Exception { |
| 128 | + ConnectionFactory cf = buildConnectionFactoryWithRecoveryEnabled(false); |
| 129 | + final String username = cf.getUsername(); |
| 130 | + final String password = cf.getPassword(); |
| 131 | + final AtomicLong usernameRequested = new AtomicLong(0); |
| 132 | + final AtomicLong passwordRequested = new AtomicLong(0); |
| 133 | + cf.setCredentialsProvider(new AbstractCredentialsProvider() { |
| 134 | + |
| 135 | + @Override |
| 136 | + public String getUsername() { |
| 137 | + usernameRequested.incrementAndGet(); |
| 138 | + return username; |
| 139 | + } |
| 140 | + |
| 141 | + @Override |
| 142 | + public String getPassword() { |
| 143 | + passwordRequested.incrementAndGet(); |
| 144 | + return password; |
| 145 | + } |
| 146 | + }); |
| 147 | + RecoverableConnection c = (RecoverableConnection) cf.newConnection(); |
| 148 | + try { |
| 149 | + assertTrue(c.isOpen()); |
| 150 | + assertEquals(1, usernameRequested.get()); |
| 151 | + assertEquals(1, passwordRequested.get()); |
| 152 | + |
| 153 | + closeAndWaitForRecovery(c); |
| 154 | + assertTrue(c.isOpen()); |
| 155 | + assertEquals(2, usernameRequested.get()); |
| 156 | + assertEquals(2, passwordRequested.get()); |
| 157 | + } finally { |
| 158 | + c.abort(); |
| 159 | + } |
| 160 | + } |
124 | 161 |
|
125 | 162 | // see https://github.com/rabbitmq/rabbitmq-java-client/issues/135 |
126 | 163 | @Test public void thatShutdownHooksOnConnectionFireBeforeRecoveryStarts() throws IOException, InterruptedException { |
|
0 commit comments