Skip to content

Commit 7860813

Browse files
authored
[Smoke Tests] Refactor Test Resources ARM (Azure#18810)
The focus of these changes is to refactor the test resources ARM template to shift to using the namespace-level connection strings for the Event Hubs resource to allow for a new sample to be added without the need to create additional namespaces or auth rules. This pattern is also more closely aligned with the majority of customer scenarios in real-world use.
1 parent 6e4c8ea commit 7860813

File tree

2 files changed

+20
-52
lines changed

2 files changed

+20
-52
lines changed

common/SmokeTests/SmokeTest/EventHubsTest.cs

100755100644
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ public static async Task RunTests()
3636
Console.WriteLine("1.- Send an Event batch");
3737
Console.WriteLine("2.- Receive those events\n");
3838

39-
var connectionString = Environment.GetEnvironmentVariable("EVENT_HUBS_CONNECTION_STRING");
39+
var connectionString = Environment.GetEnvironmentVariable("EVENT_HUBS_NAMESPACE_CONNECTION_STRING");
40+
var eventHubName = Environment.GetEnvironmentVariable("EVENT_HUBS_TESTHUB_NAME");
4041
var storageConnectionString = Environment.GetEnvironmentVariable("BLOB_CONNECTION_STRING");
4142

4243
try
4344
{
44-
CreateSenderAndReceiver(connectionString, storageConnectionString);
45+
CreateSenderAndReceiver(connectionString, eventHubName, storageConnectionString);
4546
await SendAndReceiveEvents();
4647
}
4748
finally
@@ -52,13 +53,13 @@ public static async Task RunTests()
5253

5354
public static Task Cleanup() => sender.CloseAsync();
5455

55-
private static void CreateSenderAndReceiver(string connectionString, string storageConnectionString)
56+
private static void CreateSenderAndReceiver(string connectionString, string eventHubName, string storageConnectionString)
5657
{
5758
Console.Write("Creating the Sender and Receivers... ");
5859

59-
sender = new EventHubProducerClient(connectionString);
60+
sender = new EventHubProducerClient(connectionString, eventHubName);
6061
storageClient = new BlobContainerClient(storageConnectionString, "mycontainer");
61-
processor = new EventProcessorClient(storageClient, EventHubConsumerClient.DefaultConsumerGroupName, connectionString);
62+
processor = new EventProcessorClient(storageClient, EventHubConsumerClient.DefaultConsumerGroupName, connectionString, eventHubName);
6263
Console.WriteLine("\tdone");
6364
}
6465

@@ -97,7 +98,7 @@ Task processEvent(ProcessEventArgs eventArgs)
9798
{
9899
var bodyReader = new StreamReader(eventArgs.Data.BodyAsStream);
99100
var bodyContents = bodyReader.ReadToEnd();
100-
Console.WriteLine("Recieved Event: {0}", bodyContents);
101+
Console.WriteLine("Received Event: {0}", bodyContents);
101102
}
102103

103104
return Task.CompletedTask;

common/SmokeTests/SmokeTest/test-resources.json

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,22 @@
3232
"keyVaultName": "[format('kv-smk-{0}', parameters('baseName'))]",
3333
"iotHubName": "[format('iot-smoke-{0}', parameters('baseName'))]",
3434
"eventHubNamespaceName": "[format('eh-smoke-{0}', parameters('baseName'))]",
35-
"eventHubName": "myeventhub",
36-
"eventHubAuthorizationRuleName": "RootManageSharedAccessKey",
35+
"eventHubName": "smoketest",
36+
"eventHubsKeyName": "RootManageSharedAccessKey",
37+
"eventHubsAuthRuleResourceId": "[resourceId('Microsoft.EventHub/namespaces/authorizationRules', variables('eventHubNamespaceName'), variables('eventHubsKeyName'))]",
3738
"storageAccountName": "[format('stsmoke{0}', parameters('baseName'))]"
3839
},
3940
"resources": [
4041
{
41-
"type": "Microsoft.EventHub/namespaces",
42-
"apiVersion": "2018-01-01-preview",
42+
"apiVersion": "2015-08-01",
4343
"name": "[variables('eventHubNamespaceName')]",
44+
"type": "Microsoft.EventHub/Namespaces",
4445
"location": "[parameters('location')]",
4546
"sku": {
46-
"name": "Basic",
47-
"tier": "Basic",
48-
"capacity": 1
47+
"name": "Standard",
48+
"tier": "Standard"
4949
},
5050
"properties": {
51-
"zoneRedundant": false,
52-
"isAutoInflateEnabled": false,
53-
"maximumThroughputUnits": 0,
54-
"kafkaEnabled": false
5551
}
5652
},
5753
{
@@ -158,22 +154,6 @@
158154
"accessTier": "Hot"
159155
}
160156
},
161-
{
162-
"type": "Microsoft.EventHub/namespaces/AuthorizationRules",
163-
"apiVersion": "2017-04-01",
164-
"name": "[format('{0}/{1}', variables('eventHubNamespaceName'), variables('eventHubAuthorizationRuleName'))]",
165-
"location": "[parameters('location')]",
166-
"dependsOn": [
167-
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNamespaceName'))]"
168-
],
169-
"properties": {
170-
"rights": [
171-
"Listen",
172-
"Manage",
173-
"Send"
174-
]
175-
}
176-
},
177157
{
178158
"type": "Microsoft.EventHub/namespaces/eventhubs",
179159
"apiVersion": "2017-04-01",
@@ -207,23 +187,6 @@
207187
}
208188
}
209189
},
210-
{
211-
"type": "Microsoft.EventHub/namespaces/eventhubs/authorizationRules",
212-
"apiVersion": "2017-04-01",
213-
"name": "[concat(variables('eventHubNamespaceName'), '/myeventhub/Test')]",
214-
"location": "[parameters('location')]",
215-
"dependsOn": [
216-
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', variables('eventHubNamespaceName'), 'myeventhub')]",
217-
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubNamespaceName'))]"
218-
],
219-
"properties": {
220-
"rights": [
221-
"Manage",
222-
"Listen",
223-
"Send"
224-
]
225-
}
226-
},
227190
{
228191
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
229192
"apiVersion": "2019-06-01",
@@ -277,9 +240,13 @@
277240
"type": "string",
278241
"value": "[reference(variables('keyVaultName')).vaultUri]"
279242
},
280-
"EVENT_HUBS_CONNECTION_STRING": {
243+
"EVENT_HUBS_NAMESPACE_CONNECTION_STRING": {
244+
"type": "string",
245+
"value": "[listkeys(variables('eventHubsAuthRuleResourceId'), '2015-08-01').primaryConnectionString]"
246+
},
247+
"EVENT_HUBS_TESTHUB_NAME": {
281248
"type": "string",
282-
"value": "[listKeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('eventHubNamespaceName'), variables('eventHubName'), 'Test'), '2017-04-01').primaryConnectionString]"
249+
"value": "[variables('eventHubName')]"
283250
},
284251
"BLOB_CONNECTION_STRING": {
285252
"type": "string",

0 commit comments

Comments
 (0)