Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed bug in Eventhubs live tests
  • Loading branch information
LarryOsterman committed Jan 24, 2024
commit 82b18b8cd8aac1eb81490cc1e027bd3efb36311c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ namespace Azure { namespace Messaging { namespace EventHubs {
/// Returns the partition ID associated with this ProcessorPartitionClient.
std::string PartitionId() const { return m_partitionId; }

/** Closes the partition client. */
void Close(Core::Context const& context)
/** @brief Closes the partition client.
*
* @param context The context to pass to the close operation.
*/
void Close(Core::Context const& context = {})
{
if (m_cleanupFunc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <azure/core/internal/json/json.hpp>
#include <azure/core/platform.hpp>
#include <azure/core/response.hpp>
#include <azure/identity/default_azure_credential.hpp>
#include <azure/identity/azure_cli_credential.hpp>

#include <memory>
#include <sstream>
Expand All @@ -35,7 +35,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
tokenContext.Scopes = {"https://management.azure.com/.default"};
perRetrypolicies.emplace_back(
std::make_unique<Azure::Core::Http::Policies::_internal::BearerTokenAuthenticationPolicy>(
std::make_unique<Azure::Identity::DefaultAzureCredential>(), tokenContext));
std::make_unique<Azure::Identity::AzureCliCredential>(), tokenContext));
}
std::vector<std::unique_ptr<Azure::Core::Http::Policies::HttpPolicy>> perCallpolicies;
options.Telemetry.ApplicationId = "eventhubs.test";
Expand All @@ -48,35 +48,6 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
std::move(perCallpolicies));
}

Azure::Core::Json::_internal::json ParseAzureCliOutput(std::string const& cliOutput)
{
GTEST_LOG_(INFO) << "Azure CLI output: " << cliOutput;
std::string jsonOutput = cliOutput;
if (jsonOutput.find("WARNING:") == 0)
{
// Erase the warning from the CLI.
jsonOutput = jsonOutput.erase(0, cliOutput.find('\n') + 1);
}
if (jsonOutput.find("DEBUG:") == 0)
{
// Erase the warning from the CLI.
GTEST_LOG_(WARNING) << "Azure CLI debug output: " << jsonOutput;
jsonOutput = jsonOutput.erase(0, cliOutput.find('\n') + 1);
}
if (jsonOutput.find("ERROR:") == 0)
{
throw std::runtime_error("Error processing Azure CLI: " + jsonOutput);
}
if (jsonOutput.empty())
{
return {};
}
else
{
return Azure::Core::Json::_internal::json::parse(jsonOutput);
}
}

EventHubsManagement::EventHubsCreateOrUpdateOperation EventHubsManagement::CreateNamespace(
std::string const& namespaceName,
EventHubsPricingTier pricingTier,
Expand Down Expand Up @@ -435,8 +406,8 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
std::string const& resourceGroup,
std::string const& subscriptionId,
Azure::Core::Context const& context)
: m_name(name), m_resourceGroup(resourceGroup),
m_subscriptionId(subscriptionId), m_pipeline{pipeline}
: m_name(name), m_resourceGroup(resourceGroup), m_subscriptionId(subscriptionId),
m_pipeline{pipeline}
{
Azure::Core::Url requestUrl(
"https://management.azure.com/subscriptions/" + Azure::Core::Url::Encode(m_subscriptionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,17 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace Test {
while (!partitionClients.empty())
{
auto partitionClientIterator = partitionClients.begin();
auto partitionClient = partitionClientIterator->second;
std::shared_ptr<ProcessorPartitionClient> partitionClient;
if (partitionClientIterator != partitionClients.end())
{
partitionClient = partitionClientIterator->second;
partitionClients.erase(partitionClientIterator);
}
partitionClient->Close(context);
// Don't re-use the context variable here, because it's been canceled.
if (partitionClient)
{
partitionClient->Close();
}
}

processor.Stop();
Expand Down