Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

package com.azure.spring.sample.eventhubs.binder;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import java.util.UUID;
Expand All @@ -21,19 +21,17 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = EventHubBinderApplication.class)
@AutoConfigureMockMvc
@ActiveProfiles("manual")
@ExtendWith({OutputCaptureExtension.class, MockitoExtension.class})
public class EventHubBinderApplicationIT {

@Rule
public OutputCaptureRule capture = new OutputCaptureRule();
@Autowired
private MockMvc mvc;

@Test
public void testSendAndReceiveMessage() throws Exception {
public void testSendAndReceiveMessage(CapturedOutput capturedOutput) throws Exception {
Thread.sleep(10000);
String message = UUID.randomUUID().toString();
mvc.perform(post("/messages?message=" + message)).andExpect(status().isOk())
Expand All @@ -43,7 +41,7 @@ public void testSendAndReceiveMessage() throws Exception {
boolean messageReceived = false;
boolean messageCheckpointed = false;
for (int i = 0; i < 100; i++) {
String output = capture.toString();
String output = capturedOutput.toString();
if (!messageReceived && output.contains(messageReceivedLog)) {
messageReceived = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ spring:
cloud:
azure:
eventhub:
connection-string: ${EVENTHUB_CONNECTION_STRING_BINDER}
checkpoint-storage-account: ${STORAGE_ACCOUNT_BINDER}
checkpoint-access-key: ${STORAGE_ACCOUNT_KEY_BINDER}
checkpoint-container: binder-test
connection-string: ${EVENTHUB_CONNECTION_STRING_SAMPLE_EVENTHUBS_BINDER}
checkpoint-storage-account: ${STORAGE_ACCOUNT_SAMPLE_EVENTHUBS_BINDER}
checkpoint-access-key: ${STORAGE_ACCOUNT_KEY_SAMPLE_EVENTHUBS_BINDER}
checkpoint-container: sample-eventhubs-binder
stream:
function:
definition: consume;supply
bindings:
consume-in-0:
destination: binder-test
destination: sample-eventhubs-binder
group: $Default
supply-out-0:
destination: binder-test
destination: sample-eventhubs-binder
eventhub:
bindings:
consume-in-0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
},
"functions": [],
"variables": {
"eventHubsNamespaceName": "[concat(parameters('baseName'),'-binder-eventhub')]",
"eventHubsNamespaceName": "[concat(parameters('baseName'),'-sample-eventhubs-binder')]",
"eventHubsNamespaceKeyName": "RootManageSharedAccessKey",
"storageAccountName": "[concat(substring(toLower(concat(parameters('storageNamePrefix'), uniqueString(resourceGroup().id), 'binder')), 0, 18), 'binder')]",
"storageAccountName": "[substring(toLower(concat(parameters('storageNamePrefix'), uniqueString(resourceGroup().id))), 0, 24)]",
"location": "[resourceGroup().location]"
},
"resources": [
Expand Down Expand Up @@ -55,7 +55,7 @@
{
"type": "Microsoft.EventHub/namespaces/eventhubs",
"apiVersion": "2017-04-01",
"name": "[concat(variables('eventHubsNamespaceName'), '/binder-test')]",
"name": "[concat(variables('eventHubsNamespaceName'), '/sample-eventhubs-binder')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubsNamespaceName'))]"
Expand Down Expand Up @@ -83,10 +83,10 @@
{
"type": "Microsoft.EventHub/namespaces/eventhubs/consumergroups",
"apiVersion": "2017-04-01",
"name": "[concat(variables('eventHubsNamespaceName'), '/binder-test/$Default')]",
"name": "[concat(variables('eventHubsNamespaceName'), '/sample-eventhubs-binder/$Default')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', variables('eventHubsNamespaceName'), 'binder-test')]",
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', variables('eventHubsNamespaceName'), 'sample-eventhubs-binder')]",
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubsNamespaceName'))]"
],
"properties": {}
Expand Down Expand Up @@ -165,7 +165,7 @@
{
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2019-06-01",
"name": "[concat(variables('storageAccountName'), '/default/binder-test')]",
"name": "[concat(variables('storageAccountName'), '/default/sample-eventhubs-binder')]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', variables('storageAccountName'), 'default')]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
Expand All @@ -176,15 +176,15 @@
}
],
"outputs": {
"STORAGE_ACCOUNT_BINDER": {
"STORAGE_ACCOUNT_SAMPLE_EVENTHUBS_BINDER": {
"type": "string",
"value": "[variables('storageAccountName')]"
},
"STORAGE_ACCOUNT_KEY_BINDER": {
"STORAGE_ACCOUNT_KEY_SAMPLE_EVENTHUBS_BINDER": {
"type": "string",
"value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value]"
},
"EVENTHUB_CONNECTION_STRING_BINDER": {
"EVENTHUB_CONNECTION_STRING_SAMPLE_EVENTHUBS_BINDER": {
"type": "string",
"value": "[listKeys(resourceId('Microsoft.EventHub/namespaces/authorizationRules', variables('eventHubsNamespaceName'), variables('eventHubsNamespaceKeyName')), '2017-04-01').primaryConnectionString]"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
spring:
cloud:
azure:
client-id: [service-principal-id]
client-secret: [service-principal-secret]
tenant-id: [tenant-id]
resource-group: [resource-group]
client-id: ${SPRING_CLIENT_ID}
client-secret: ${SPRING_CLIENT_SECRET}
tenant-id: ${SPRING_TENANT_ID}
resource-group: ${SPRING_RESOURCE_GROUP}
subscription-id: ${SPRING_SUBSCRIPTION_ID}
eventhub:
namespace: [eventhub-namespace]
namespace: ${EVENTHUB_NAMESPACE_NAME_SAMPLE_EVENTHUBS_KAFKA}
stream:
function:
definition: consume;supply
bindings:
consume-in-0:
destination: [eventhub-name]
group: [consumer-group]
destination: sample-eventhubs-kafka
group: $Default
supply-out-0:
destination: [the-same-eventhub-name-as-above]
destination: sample-eventhubs-kafka
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

package com.azure.spring.sample.eventhubs.kafka;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.test.web.servlet.MockMvc;

import java.util.UUID;
Expand All @@ -20,18 +20,16 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = EventHubKafkaBinderApplication.class)
@AutoConfigureMockMvc
@ExtendWith({ OutputCaptureExtension.class, MockitoExtension.class})
public class EventHubKafkaBinderApplicationIT {

@Rule
public OutputCaptureRule capture = new OutputCaptureRule();
@Autowired
private MockMvc mvc;

@Test
public void testSendAndReceiveMessage() throws Exception {
public void testSendAndReceiveMessage(CapturedOutput capturedOutput) throws Exception {
Thread.sleep(10000);
String message = UUID.randomUUID().toString();
mvc.perform(post("/messages?message=" + message)).andExpect(status().isOk())
Expand All @@ -40,7 +38,7 @@ public void testSendAndReceiveMessage() throws Exception {

boolean messageReceived = false;
for (int i = 0; i < 100; i++) {
String output = capture.toString();
String output = capturedOutput.toString();
if (output.contains(messageReceivedLog)) {
messageReceived = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ spring:
banner-mode: off
cloud:
azure:
client-id: ${SPRING_CLIENT_ID_KAFKA}
client-secret: ${SPRING_CLIENT_SECRET_KAFKA}
tenant-id: ${SPRING_TENANT_ID_KAFKA}
resource-group: ${SPRING_RESOURCE_GROUP_KAFKA}
subscription-id: ${SPRING_SUBSCRIPTION_ID_KAFKA}
client-id: ${SPRING_CLIENT_ID}
client-secret: ${SPRING_CLIENT_SECRET}
tenant-id: ${SPRING_TENANT_ID}
resource-group: ${SPRING_RESOURCE_GROUP}
subscription-id: ${SPRING_SUBSCRIPTION_ID}
eventhub:
namespace: ${EVENTHUB_NAMESPACE_NAME_KAFKA}
namespace: ${EVENTHUB_NAMESPACE_NAME_SAMPLE_EVENTHUBS_KAFKA}
stream:
function:
definition: consume;supply
bindings:
consume-in-0:
destination: kafka-test
destination: sample-eventhubs-kafka
group: $Default
supply-out-0:
destination: kafka-test
destination: sample-eventhubs-kafka
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"functions": [],
"variables": {
"eventHubsNamespaceName": "[concat(parameters('baseName'),'-kafka-eventhub')]",
"eventHubsNamespaceName": "[concat(parameters('baseName'),'-sample-eventhubs-kafka')]",
"eventHubsNamespaceKeyName": "RootManageSharedAccessKey",
"location": "[resourceGroup().location]"
},
Expand All @@ -43,7 +43,7 @@
{
"type": "Microsoft.EventHub/namespaces/eventhubs",
"apiVersion": "2017-04-01",
"name": "[concat(variables('eventHubsNamespaceName'), '/kafka-test')]",
"name": "[concat(variables('eventHubsNamespaceName'), '/sample-eventhubs-kafka')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubsNamespaceName'))]"
Expand Down Expand Up @@ -71,37 +71,37 @@
{
"type": "Microsoft.EventHub/namespaces/eventhubs/consumergroups",
"apiVersion": "2017-04-01",
"name": "[concat(variables('eventHubsNamespaceName'), '/kafka-test/$Default')]",
"name": "[concat(variables('eventHubsNamespaceName'), '/sample-eventhubs-kafka/$Default')]",
"location": "[variables('location')]",
"dependsOn": [
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', variables('eventHubsNamespaceName'), 'kafka-test')]",
"[resourceId('Microsoft.EventHub/namespaces/eventhubs', variables('eventHubsNamespaceName'), 'sample-eventhubs-kafka')]",
"[resourceId('Microsoft.EventHub/namespaces', variables('eventHubsNamespaceName'))]"
],
"properties": {}
}
],
"outputs": {
"EVENTHUB_NAMESPACE_NAME_KAFKA": {
"EVENTHUB_NAMESPACE_NAME_SAMPLE_EVENTHUBS_KAFKA": {
"type": "string",
"value": "[variables('eventHubsNamespaceName')]"
},
"SPRING_TENANT_ID_KAFKA": {
"SPRING_TENANT_ID": {
"type": "string",
"value": "[parameters('tenantId')]"
},
"SPRING_CLIENT_ID_KAFKA": {
"SPRING_CLIENT_ID": {
"type": "string",
"value": "[parameters('testApplicationId')]"
},
"SPRING_CLIENT_SECRET_KAFKA": {
"SPRING_CLIENT_SECRET": {
"type": "string",
"value": "[parameters('testApplicationSecret')]"
},
"SPRING_RESOURCE_GROUP_KAFKA": {
"SPRING_RESOURCE_GROUP": {
"type": "string",
"value": "[resourceGroup().name]"
},
"SPRING_SUBSCRIPTION_ID_KAFKA": {
"SPRING_SUBSCRIPTION_ID": {
"type": "string",
"value": "[subscription().subscriptionId]"
}
Expand Down
12 changes: 12 additions & 0 deletions sdk/spring/azure-spring-cloud-test-eventhubs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
<artifactId>azure-spring-cloud-stream-binder-test</artifactId>
<version>2.5.0-beta.1</version> <!-- {x-version-update;com.azure.spring:azure-spring-cloud-stream-binder-test;current} -->
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.1</version> <!-- {x-version-update;org.junit.jupiter:junit-jupiter-engine;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.1</version> <!-- {x-version-update;org.junit.vintage:junit-vintage-engine;external_dependency} -->
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
@SpringBootTest(classes = EventHubBinderConsumeErrorIT.TestConfig.class)
@TestPropertySource(properties =
{
"spring.cloud.stream.bindings.consume-in-0.destination=test-eventhub",
"spring.cloud.stream.bindings.supply-out-0.destination=test-eventhub",
"spring.cloud.azure.eventhub.checkpoint-container=test-eventhub"
"spring.cloud.stream.bindings.consume-in-0.destination=test-eventhub-message",
"spring.cloud.stream.bindings.supply-out-0.destination=test-eventhub-message",
"spring.cloud.azure.eventhub.checkpoint-container=test-eventhub-message"
})
public class EventHubBinderConsumeErrorIT {

Expand Down Expand Up @@ -73,7 +73,7 @@ public Consumer<Message<String>> consume() {
};
}

@ServiceActivator(inputChannel = "test-eventhub.$Default.errors")
@ServiceActivator(inputChannel = "test-eventhub-message.$Default.errors")
public void consumeError(Message<?> message) throws InterruptedException {
EXCHANGER.exchange("ERROR!");
}
Expand Down
Loading