I need to do some failover test in my app that uses spring JMS. I want to simulate broken TCP connection. Spring framework has two implementations of ConnectionFactory
interface (SingleConnectionFactory
and CachingConnectionFactory
) and both of them cache connection. According to documentation they "... ignore calls to close()
". So that I cannot debug and close that connection. I also don't have access to tools like wireshark and have no access to physical machine to unplug cable. Is there any way that I can simulate "interrupted connection"?
Asked
Active
Viewed 296 times
0

M. Deinum
- 115,695
- 22
- 220
- 224

Daniel Urbaniak
- 117
- 7
1 Answers
1
Call resetConnection()
.
/**
* Reset the underlying shared Connection, to be reinitialized on next access.
*/
public void resetConnection() {
synchronized (this.connectionMonitor) {
if (this.target != null) {
closeConnection(this.target);
}
this.target = null;
this.connection = null;
}
}

Gary Russell
- 166,535
- 14
- 146
- 179
-
Wow. It works. I even noticed that also destroy() method called on factory do that or closeConnection() inherited from SingleConnectionFactory. Before I did it on connection directly so it was not working. Thanks – Daniel Urbaniak Jul 11 '18 at 10:31