-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Rust 2 step message receive code to C++ (#6349)
* Integrate Rust 2 step message receive code to C++ * If receiving a delivery failed, transmit the error to the message channel if at all possible
- Loading branch information
1 parent
aa19507
commit 91fd49e
Showing
14 changed files
with
675 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
sdk/core/azure-core-amqp/src/impl/rust_amqp/rust_amqp/azure_core_amqp/Test-Cleanup.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
# cspell: ignore JOBID | ||
|
||
. "$PSScriptRoot\..\..\..\eng\common\scripts\common.ps1" | ||
|
||
Write-Host "Test Broker output:" | ||
Receive-Job -Id $env:TEST_BROKER_JOBID | ||
|
||
# Check if the test broker job is still running | ||
$job = Get-Job -Id $env:TEST_BROKER_JOBID | ||
if ($job.State -ne "Running") { | ||
Write-Host "Test broker terminated unexpectedly." | ||
exit 1 | ||
} | ||
|
||
# Stop the test broker job started in Test-Setup.ps1 | ||
Write-Host "Stopping test broker" | ||
Stop-Job -Id $env:TEST_BROKER_JOBID | ||
Remove-Job -Id $env:TEST_BROKER_JOBID | ||
Write-Host "Test broker stopped." |
69 changes: 69 additions & 0 deletions
69
sdk/core/azure-core-amqp/src/impl/rust_amqp/rust_amqp/azure_core_amqp/Test-Setup.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
# cspell: ignore JOBID depsfile | ||
|
||
|
||
# Load common ES scripts | ||
. "$PSScriptRoot\..\..\..\eng\common\scripts\common.ps1" | ||
|
||
# Create the test binary *outside* the repo root to avoid polluting the repo. | ||
$WorkingDirectory = ([System.IO.Path]::Combine($RepoRoot, "../TestArtifacts")) | ||
|
||
# Create the working directory if it does not exist. | ||
Write-Host "Using Working Directory $WorkingDirectory" | ||
|
||
if (-not (Test-Path $WorkingDirectory)) { | ||
Write-Host "Working directory does not exist, creating working directory: $WorkingDirectory" | ||
New-Item -ItemType Directory -Path $WorkingDirectory | ||
} | ||
|
||
Write-Host "Setting current directory to working directory: $WorkingDirectory" | ||
Push-Location -Path $WorkingDirectory | ||
|
||
# Clone and build the Test Amqp Broker. | ||
try { | ||
|
||
$repositoryUrl = "https://github.com/Azure/azure-amqp.git" | ||
# We would like to use the "hotfix" branch because that is current, but unfortunately it references System.Net.Security version 4.0.0 | ||
$repositoryBranch = "master" | ||
$cloneCommand = "git clone $repositoryUrl --branch $repositoryBranch" | ||
|
||
Write-Host "Cloning repository from $repositoryUrl..." | ||
Invoke-LoggedCommand $cloneCommand | ||
|
||
Set-Location -Path "./azure-amqp/test/TestAmqpBroker" | ||
|
||
Invoke-LoggedCommand "dotnet build -p RollForward=LatestMajor --framework net6.0" | ||
if (!$? -ne 0) { | ||
Write-Error "Failed to build TestAmqpBroker." | ||
exit 1 | ||
} | ||
|
||
Write-Host "Test broker built successfully." | ||
|
||
# now that the Test broker has been built, launch the broker on a local address. | ||
$env:TEST_BROKER_ADDRESS = 'amqp://127.0.0.1:25672' | ||
|
||
Write-Host "Starting test broker listening on ${env:TEST_BROKER_ADDRESS} ..." | ||
|
||
Set-Location -Path $WorkingDirectory/azure-amqp/bin/Debug/TestAmqpBroker/net6.0 | ||
|
||
$job = dotnet exec ./TestAmqpBroker.dll ${env:TEST_BROKER_ADDRESS} /headless & | ||
|
||
$env:TEST_BROKER_JOBID = $job.Id | ||
|
||
Write-Host "Waiting for test broker to start..." | ||
Start-Sleep -Seconds 3 | ||
|
||
Write-Host "Job Output after wait:" | ||
Receive-Job $job.Id | ||
|
||
$job = Get-Job -Id $env:TEST_BROKER_JOBID | ||
if ($job.State -ne "Running") { | ||
Write-Host "Test broker failed to start." | ||
exit 1 | ||
} | ||
} | ||
finally { | ||
Pop-Location | ||
} |
82 changes: 82 additions & 0 deletions
82
sdk/core/azure-core-amqp/src/impl/rust_amqp/rust_amqp/azure_core_amqp/examples/connection.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights reserved | ||
// Licensed under the MIT license. | ||
|
||
// These tests assume that the AmqpTestBroker is running on localhost:25672. | ||
// The AmqpTestBroker can be installed by the following steps: | ||
// 1. Clone the repository: | ||
// git clone https://github.com/Azure/azure-amqp | ||
// 2. Build the project: | ||
// dotnet build | ||
// 3. Run the broker: | ||
// dotnet run --project .\test\TestAmqpBroker\TestAmqpBroker.csproj --framework net462 amqp://localhost:25672 | ||
// 4. Run the tests (from the root of the azure-sdk-for-rust repository): | ||
// cargo run --example connection --package azure_core_amqp | ||
|
||
use azure_core::Url; | ||
use azure_core_amqp::{ | ||
connection::{AmqpConnection, AmqpConnectionApis}, | ||
value::AmqpSymbol, | ||
}; | ||
|
||
async fn amqp_connection_open() { | ||
let connection = AmqpConnection::new(); | ||
|
||
let url = Url::parse("amqp://localhost:25672").unwrap(); | ||
connection | ||
.open("test".to_string(), url, None) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
async fn amqp_connection_open_with_error() { | ||
let connection = AmqpConnection::new(); | ||
let url = Url::parse("amqp://localhost:32767").unwrap(); | ||
assert!(connection | ||
.open("test".to_string(), url, None) | ||
.await | ||
.is_err()); | ||
} | ||
|
||
async fn amqp_connection_close() { | ||
let connection = AmqpConnection::new(); | ||
let url = Url::parse("amqp://localhost:25672").unwrap(); | ||
connection | ||
.open("test".to_string(), url, None) | ||
.await | ||
.unwrap(); | ||
connection.close().await.unwrap(); | ||
} | ||
|
||
async fn amqp_connection_close_with_error() { | ||
let connection = AmqpConnection::new(); | ||
let url = Url::parse("amqp://localhost:25672").unwrap(); | ||
connection | ||
.open("test".to_string(), url, None) | ||
.await | ||
.unwrap(); | ||
let res = connection | ||
.close_with_error( | ||
AmqpSymbol::from("amqp:internal-error"), | ||
Some("Internal error.".to_string()), | ||
None, | ||
) | ||
.await; | ||
match res { | ||
Ok(_) => {} | ||
Err(err) => { | ||
assert!(err.to_string().contains("Internal error.")); | ||
} | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
pub async fn main() { | ||
tracing_subscriber::fmt::init(); | ||
|
||
tokio::join!( | ||
amqp_connection_open(), | ||
amqp_connection_open_with_error(), | ||
amqp_connection_close(), | ||
amqp_connection_close_with_error() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.