Skip to content

Commit a17f0b4

Browse files
authored
[Smoke Tests] Sample: IoT Hub Connection String Translation (Azure#11388)
The focus of these changes is to adjust the base infrastructure for the smoke tests and extend it to allow for integration of the cross-service samples. The sample demonstrating querying IoT Hub for an Event Hubs connection string has been integrated as part of the test suite.
1 parent 35d7fb1 commit a17f0b4

File tree

12 files changed

+125
-235
lines changed

12 files changed

+125
-235
lines changed

common/SmokeTests/SmokeTest.sln

100644100755
-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ Global
1515
{F406BDFE-913D-4ED1-8C97-928128DA0F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
1616
{F406BDFE-913D-4ED1-8C97-928128DA0F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
1717
{F406BDFE-913D-4ED1-8C97-928128DA0F7D}.Release|Any CPU.Build.0 = Release|Any CPU
18-
{89D7E7D6-0C87-4E12-87AC-B51EC63F7C22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19-
{89D7E7D6-0C87-4E12-87AC-B51EC63F7C22}.Debug|Any CPU.Build.0 = Debug|Any CPU
20-
{89D7E7D6-0C87-4E12-87AC-B51EC63F7C22}.Release|Any CPU.ActiveCfg = Release|Any CPU
21-
{89D7E7D6-0C87-4E12-87AC-B51EC63F7C22}.Release|Any CPU.Build.0 = Release|Any CPU
2218
EndGlobalSection
2319
GlobalSection(SolutionProperties) = preSolution
2420
HideSolutionNode = FALSE

common/SmokeTests/SmokeTest/CosmosDBTest.cs

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static async Task RunTests()
6767
await CreateDatabase();
6868
await CreateCollection();
6969
await CreateDocuments();
70-
await ExecuteSimpleQuery();
70+
ExecuteSimpleQuery();
7171
await DeleteDatabase();
7272
}
7373

@@ -117,7 +117,7 @@ private static async Task CreateDocuments()
117117
}
118118
}
119119
});
120-
120+
121121
//The items must NOT exists in the collection
122122
foreach (Planet planet in planets)
123123
{
@@ -130,7 +130,7 @@ private static async Task CreateDocuments()
130130
/// <summary>
131131
/// The query retrieve all planets, this is going to verify that planets match
132132
/// </summary>
133-
private static async Task ExecuteSimpleQuery(){
133+
private static void ExecuteSimpleQuery(){
134134
Console.Write("Querying... ");
135135
IQueryable<Planet> planetarySqlQuery = client.CreateDocumentQuery<Planet>(UriFactory.CreateDocumentCollectionUri(DataBaseName, CollectionName), "SELECT * FROM c");
136136

common/SmokeTests/SmokeTest/EventHubsTest.cs

100644100755
+11-12
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@ public static async Task RunTests()
3939
var connectionString = Environment.GetEnvironmentVariable("EVENT_HUBS_CONNECTION_STRING");
4040
var storageConnectionString = Environment.GetEnvironmentVariable("BLOB_CONNECTION_STRING");
4141

42-
await CreateSenderAndReceiver(connectionString, storageConnectionString);
43-
await SendAndReceiveEvents();
42+
try
43+
{
44+
CreateSenderAndReceiver(connectionString, storageConnectionString);
45+
await SendAndReceiveEvents();
46+
}
47+
finally
48+
{
49+
await Cleanup();
50+
}
4451
}
4552

46-
private static async Task<string> GetPartitionId(string connectionString)
47-
{
48-
var client = new EventHubProducerClient(connectionString);
49-
var result = (await client.GetPartitionIdsAsync()).First();
50-
await client.DisposeAsync();
51-
return result;
52-
}
53+
public static Task Cleanup() => sender.CloseAsync();
5354

54-
private static async Task CreateSenderAndReceiver(string connectionString, string storageConnectionString)
55+
private static void CreateSenderAndReceiver(string connectionString, string storageConnectionString)
5556
{
5657
Console.Write("Creating the Sender and Receivers... ");
5758

@@ -79,8 +80,6 @@ private static async Task SendAndReceiveEvents()
7980
eventBatch.TryAdd(ev);
8081
}
8182

82-
await sender.SendAsync(eventBatch);
83-
8483
Console.Write("Ready to send a batch of " + eventBatch.Count.ToString() + " events... ");
8584
await sender.SendAsync(eventBatch);
8685
Console.Write("Sent\n");

common/SmokeTests/SmokeTest/Program.cs

100644100755
+13-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// ------------------------------------
2-
// Copyright(c) Microsoft Corporation.
1+

2+
// Copyright (c) Microsoft Corporation. All rights reserved.
33
// Licensed under the MIT License.
4-
// ------------------------------------
5-
// ------------------------------------
4+
65
using System;
76
using System.Threading.Tasks;
7+
using SmokeTest.Samples;
88

99
namespace SmokeTest
1010
{
@@ -22,6 +22,15 @@ static async Task<int> Main(string[] args)
2222
// https://github.com/Azure/azure-sdk-for-net/issues/11297
2323
// await CosmosDBTest.RunTests();
2424

25+
Console.WriteLine();
26+
Console.WriteLine("LIBRARY TESTS COMPLETE");
27+
Console.WriteLine();
28+
Console.WriteLine("SMOKE TEST FOR TRACK 2 SAMPLES");
29+
30+
await IotHubConnectionTests.RunTests();
31+
32+
Console.WriteLine("SAMPLES TESTS COMPLETE");
33+
Console.WriteLine();
2534
return 0;
2635
}
2736
}

common/SmokeTests/SmokeTest/Properties/Resources.Designer.cs

-63
This file was deleted.

common/SmokeTests/SmokeTest/Properties/Resources.resx

-121
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
namespace SmokeTest.Samples
5+
{
6+
public static class IotHubConnectionTests
7+
{
8+
public static async Task RunTests()
9+
{
10+
Console.WriteLine("---------------------------------------------");
11+
Console.WriteLine("SAMPLE: IoT Hub Connection String Translation");
12+
Console.WriteLine("---------------------------------------------");
13+
Console.WriteLine("Functionalities to test: 2");
14+
Console.WriteLine("\t1.- Query IoT Hub for an Event Hubs connection string");
15+
Console.WriteLine("\t2.- Validate the connection string is accepted by Event Hubs");
16+
17+
var connectionString = Environment.GetEnvironmentVariable("IOTHUB_CONNECTION_STRING");
18+
var retVal = await IotHubToEventHubsSample.Program.Main(new[] { connectionString });
19+
20+
if (retVal != 0)
21+
{
22+
throw new ApplicationException($"{ nameof(IotHubConnectionTests) } failed!");
23+
}
24+
}
25+
}
26+
}

common/SmokeTests/SmokeTest/SmokeTest.csproj

100644100755
+18-21
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
1+
<Project Sdk="Microsoft.NET.Sdk">
32
<PropertyGroup>
43
<OutputType>Exe</OutputType>
54
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
5+
<LangVersion>latest</LangVersion>
6+
<StartupObject>SmokeTest.Program</StartupObject>
67
</PropertyGroup>
78

8-
<ItemGroup>
9-
<PackageReference Include="Azure.Core" Version="1.0.2-dev.*" />
10-
<PackageReference Include="Azure.Identity" Version="1.0.0-dev.*" />
11-
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.0.0-dev.*" />
12-
<PackageReference Include="Azure.Messaging.EventHubs.Processor" Version="5.0.1-dev.*" />
13-
<PackageReference Include="Azure.Security.Keyvault.Secrets" Version="4.0.0-dev.*" />
14-
<PackageReference Include="Azure.Storage.Blobs" Version="12.0.0-dev.*" />
15-
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.10.0" />
9+
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
10+
<Reference Include="System" />
11+
<Reference Include="Microsoft.CSharp" />
1612
</ItemGroup>
1713

1814
<ItemGroup>
19-
<Compile Update="Properties\Resources.Designer.cs">
20-
<DesignTime>True</DesignTime>
21-
<AutoGen>True</AutoGen>
22-
<DependentUpon>Resources.resx</DependentUpon>
23-
</Compile>
15+
<PackageReference Include="Azure.Core" Version="1.3.0-dev.*" />
16+
<PackageReference Include="Azure.Identity" Version="1.2.0-dev.*" />
17+
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.1.0-dev.*" />
18+
<PackageReference Include="Azure.Messaging.EventHubs.Processor" Version="5.1.0-dev.*" />
19+
<PackageReference Include="Azure.Security.Keyvault.Secrets" Version="4.1.0-dev.*" />
20+
<PackageReference Include="Azure.Storage.Blobs" Version="12.5.0-dev.*" />
21+
<PackageReference Include="Microsoft.Azure.Amqp" Version="2.4.3" />
22+
<PackageReference Include="Microsoft.Azure.Devices" Version="1.20.1" />
23+
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.10.0" />
2424
</ItemGroup>
2525

26+
<!-- Sample: IoT Hub Connection String Translation -->
2627
<ItemGroup>
27-
<EmbeddedResource Update="Properties\Resources.resx">
28-
<Generator>ResXFileCodeGenerator</Generator>
29-
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
30-
</EmbeddedResource>
28+
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\samples\iothub-connect-to-eventhubs\**\*.cs" Link="Samples\IoTHubConnection\SharedSource\%(Filename)%(Extension)" />
3129
</ItemGroup>
32-
33-
</Project>
30+
</Project>

common/SmokeTests/SmokeTest/Update-Dependencies.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $PACKAGE_REFERENCE_XPATH = '//Project/ItemGroup/PackageReference'
2020
# Matches the dev.yyyymmdd portion of the version string
2121
$DEV_DATE_REGEX = 'dev\.(\d{8})'
2222

23-
$NIGHTLY_FEED_NAME = 'NighlyFeed'
23+
$NIGHTLY_FEED_NAME = 'NightlyFeed'
2424
$NIGHTLY_FEED_URL = 'https://azuresdkartifacts.blob.core.windows.net/azure-sdk-for-net/index.json'
2525

2626
function Log-Warning($message) {

0 commit comments

Comments
 (0)