From bfb3f5cd9585c69f37a6aaebfd7524e764cdadf6 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 22 Apr 2015 09:22:57 +0200 Subject: [PATCH] Retry to delete integration test accounts in the the connection was terminated because of an error, try to re-establish the connection when trying to delete the account. --- .../SmackIntegrationTestFramework.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java index 571d2c1b3..6510395de 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java @@ -466,11 +466,27 @@ public class SmackIntegrationTestFramework { } protected void disconnectAndMaybeDelete(XMPPTCPConnection connection) - throws NoResponseException, XMPPErrorException, NotConnectedException, - InterruptedException { + throws InterruptedException, XMPPException, SmackException, IOException { if (config.registerAccounts) { + final int maxAttempts = 3; AccountManager am = AccountManager.getInstance(connection); - am.deleteAccount(); + int attempts; + for (attempts = 0; attempts < maxAttempts; attempts++) { + try { + am.deleteAccount(); + } catch (NoResponseException | InterruptedException e) { + LOGGER.log(Level.WARNING, "Exception deleting account" , e); + continue; + } catch (NotConnectedException e) { + LOGGER.log(Level.WARNING, "Exception deleting account" , e); + connection.connect().login(); + continue; + } + break; + } + if (attempts > maxAttempts) { + LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection); + } } connection.disconnect(); }