* occurs (should not happen)
* @throws InterruptedException if the sleep is interrupted
*/
@Test
public final void testFailedConnection() throws IOException, InterruptedException {
OtpSelf self;
PeerNode remote;
Connection c;
DefaultConnectionPolicy connectionPolicy;
final Date d0 = new Date();
Date d1, d2;
TimeUnit.MILLISECONDS.sleep(10);
// wrong cookie:
self = new OtpSelf("testFailedConnection",
ConnectionFactory.getInstance().getCookie() + "someWrongCookieValue");
remote = new PeerNode(ConnectionFactory.getInstance().getNodes().get(0).getNode().node());
connectionPolicy = new DefaultConnectionPolicy(remote);
connectionPolicy.setMaxRetries(0);
try {
c = new Connection(self, connectionPolicy);
// this should have failed!
fail();
c.close();
} catch (final Exception e) {
}
assertEquals(1, remote.getFailureCount());
d1 = remote.getLastFailedConnect();
assertNotNull(d1);
assertTrue(d0.getTime() < d1.getTime());
TimeUnit.MILLISECONDS.sleep(10);
try {
c = new Connection(self, connectionPolicy);
// this should have failed!
fail();
c.close();
} catch (final Exception e) {
}
assertEquals(2, remote.getFailureCount());
d2 = remote.getLastFailedConnect();
assertNotNull(d2);
assertTrue(d0.getTime() < d2.getTime());
assertTrue(d1.getTime() < d2.getTime());
TimeUnit.MILLISECONDS.sleep(10);
// unknown host name:
self = new OtpSelf("testFailedConnection",
ConnectionFactory.getInstance().getCookie());
remote = new PeerNode(ConnectionFactory.getInstance().getNodes().get(0).getNode().node() + "noneExistingHost");
connectionPolicy = new DefaultConnectionPolicy(remote);
connectionPolicy.setMaxRetries(0);
try {
c = new Connection(self, connectionPolicy);
// this should have failed!
fail();
c.close();
} catch (final Exception e) {
}
assertEquals(1, remote.getFailureCount());
d1 = remote.getLastFailedConnect();
assertNotNull(d1);
assertTrue(d0.getTime() < d1.getTime());
TimeUnit.MILLISECONDS.sleep(10);
try {
c = new Connection(self, connectionPolicy);
// this should have failed!
fail();
c.close();
} catch (final Exception e) {
}
assertEquals(2, remote.getFailureCount());
d2 = remote.getLastFailedConnect();
assertNotNull(d2);
assertTrue(d0.getTime() < d2.getTime());
assertTrue(d1.getTime() < d2.getTime());
TimeUnit.MILLISECONDS.sleep(10);
// non-existing node name:
self = new OtpSelf("testFailedConnection",
ConnectionFactory.getInstance().getCookie());
remote = new PeerNode("noneExistingNode" + ConnectionFactory.getInstance().getNodes().get(0).getNode().node());
connectionPolicy = new DefaultConnectionPolicy(remote);
connectionPolicy.setMaxRetries(0);
try {