Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][test] Improve the declare exchange test #1150

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,7 +26,9 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.awaitility.Awaitility;
import org.testng.annotations.Test;

/**
Expand Down Expand Up @@ -121,24 +123,47 @@ private void doTestExchangeDeclaredWithEnumerationEquivalent(Channel channel)
for (BuiltinExchangeType exchangeType : BuiltinExchangeType.values()) {
channel.exchangeDeclare(NAME, exchangeType);
verifyEquivalent(NAME, exchangeType.getType(), false, false, null);
channel.exchangeDelete(NAME);
deleteExchangeWithRetry();

channel.exchangeDeclare(NAME, exchangeType, false);
verifyEquivalent(NAME, exchangeType.getType(), false, false, null);
channel.exchangeDelete(NAME);
deleteExchangeWithRetry();

channel.exchangeDeclare(NAME, exchangeType, false, false, null);
verifyEquivalent(NAME, exchangeType.getType(), false, false, null);
channel.exchangeDelete(NAME);
deleteExchangeWithRetry();

channel.exchangeDeclare(NAME, exchangeType, false, false, false, null);
verifyEquivalent(NAME, exchangeType.getType(), false, false, null);
channel.exchangeDelete(NAME);
deleteExchangeWithRetry();

channel.exchangeDeclareNoWait(NAME, exchangeType, false,
false, false, null);
// no check, this one is asynchronous
channel.exchangeDelete(NAME);
deleteExchangeWithRetry();
}
}

public void deleteExchangeWithRetry() throws IOException {
// the replicator cursor of exchange is created in async way,
// delete the exchange may fail due to non-empty directory error
//
// KeeperErrorCode = Directory not empty for
// /managed-ledgers/public/vhost1/persistent/__amqp_exchange__exchange_test
//
// - /managed-ledgers/public/vhost1/persistent/__amqp_exchange__exchange_test
// - /managed-ledgers/public/vhost1/persistent/__amqp_exchange__exchange_test/__amqp_replicator__exchange_test
Awaitility.await()
.atMost(5, TimeUnit.SECONDS)
.pollInterval(100, TimeUnit.MILLISECONDS)
.until(() -> {
try {
channel.exchangeDelete(NAME);
} catch (Exception e) {
return false;
}
return true;
});
}

}