-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
459 additions
and
32 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
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
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
52 changes: 26 additions & 26 deletions
52
tests/endtoend/eventhub_batch_functions/get_eventhub_batch_triggered/function.json
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 |
---|---|---|
@@ -1,27 +1,27 @@ | ||
{ | ||
"scriptFile": "__init__.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"authLevel": "anonymous", | ||
"methods": [ | ||
"get" | ||
], | ||
"name": "req" | ||
}, | ||
{ | ||
"direction": "in", | ||
"type": "table", | ||
"name": "testEntities", | ||
"partitionKey": "WillBePopulated", | ||
"tableName": "EventHubBatchTest", | ||
"connection": "AzureWebJobsStorage" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
{ | ||
"scriptFile": "__init__.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"authLevel": "anonymous", | ||
"methods": [ | ||
"get" | ||
], | ||
"name": "req" | ||
}, | ||
{ | ||
"direction": "in", | ||
"type": "table", | ||
"name": "testEntities", | ||
"partitionKey": "WillBePopulated", | ||
"tableName": "EventHubBatchTest", | ||
"connection": "AzureWebJobsStorage" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/endtoend/eventhub_batch_functions/get_metadata_batch_triggered/__init__.py
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,10 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import azure.functions as func | ||
|
||
|
||
# Retrieve the event data from storage blob and return it as Http response | ||
def main(req: func.HttpRequest, file: func.InputStream) -> str: | ||
return func.HttpResponse(body=file.read().decode('utf-8'), | ||
status_code=200, | ||
mimetype='application/json') |
22 changes: 22 additions & 0 deletions
22
tests/endtoend/eventhub_batch_functions/get_metadata_batch_triggered/function.json
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,22 @@ | ||
{ | ||
"scriptFile": "__init__.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "blob", | ||
"direction": "in", | ||
"name": "file", | ||
"connection": "AzureWebJobsStorage", | ||
"path": "python-worker-tests/test-metadata-batch-triggered.txt" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/endtoend/eventhub_batch_functions/metadata_multiple/__init__.py
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,24 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import typing | ||
import json | ||
import azure.functions as func | ||
|
||
|
||
# This is an actual EventHub trigger which handles Eventhub events in batches. | ||
# It serializes multiple event data into a json and store it into a blob. | ||
def main(events: typing.List[func.EventHubEvent]) -> bytes: | ||
event_list = [] | ||
for event in events: | ||
event_dict: typing.Mapping[str, typing.Any] = { | ||
'body': event.get_body().decode('utf-8'), | ||
'enqueued_time': event.enqueued_time.isoformat(), | ||
'partition_key': event.partition_key, | ||
'sequence_number': event.sequence_number, | ||
'offset': event.offset, | ||
'metadata': event.metadata | ||
} | ||
event_list.append(event_dict) | ||
|
||
return json.dumps(event_list) |
21 changes: 21 additions & 0 deletions
21
tests/endtoend/eventhub_batch_functions/metadata_multiple/function.json
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 @@ | ||
{ | ||
"scriptFile": "__init__.py", | ||
"bindings": [ | ||
{ | ||
"type": "eventHubTrigger", | ||
"name": "events", | ||
"direction": "in", | ||
"cardinality": "many", | ||
"dataType": "binary", | ||
"eventHubName": "python-worker-ci-eventhub-batch-metadata", | ||
"connection": "AzureWebJobsEventHubConnectionString" | ||
}, | ||
{ | ||
"type": "blob", | ||
"direction": "out", | ||
"name": "$return", | ||
"connection": "AzureWebJobsStorage", | ||
"path": "python-worker-tests/test-metadata-batch-triggered.txt" | ||
} | ||
] | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/endtoend/eventhub_batch_functions/metadata_output_batch/__init__.py
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,36 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
import json | ||
|
||
import azure.functions as func | ||
from azure.eventhub import EventHubProducerClient, EventData | ||
|
||
|
||
# An HttpTrigger to generating EventHub event from azure-eventhub SDK. | ||
# Events generated from azure-eventhub contain the full metadata. | ||
def main(req: func.HttpRequest): | ||
# Get event count from http request query parameter | ||
count = int(req.params.get('count', '1')) | ||
|
||
# Parse event metadata from http request | ||
json_string = req.get_body().decode('utf-8') | ||
event_dict = json.loads(json_string) | ||
|
||
# Create an EventHub Client and event batch | ||
client = EventHubProducerClient.from_connection_string( | ||
os.getenv('AzureWebJobsEventHubConnectionString'), | ||
eventhub_name='python-worker-ci-eventhub-batch-metadata') | ||
|
||
# Generate new event based on http request with full metadata | ||
event_data_batch = client.create_batch() | ||
random_number = int(event_dict.get('body', '0')) | ||
for i in range(count): | ||
event_data_batch.add(EventData(str(random_number + i))) | ||
|
||
# Send out event into event hub | ||
with client: | ||
client.send_batch(event_data_batch) | ||
|
||
return f'OK' |
15 changes: 15 additions & 0 deletions
15
tests/endtoend/eventhub_batch_functions/metadata_output_batch/function.json
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,15 @@ | ||
{ | ||
"scriptFile": "__init__.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"direction": "out", | ||
"name": "$return", | ||
"type": "http" | ||
} | ||
] | ||
} |
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
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
10 changes: 10 additions & 0 deletions
10
tests/endtoend/eventhub_functions/get_metadata_triggered/__init__.py
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,10 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import azure.functions as func | ||
|
||
|
||
# Retrieve the event data from storage blob and return it as Http response | ||
async def main(req: func.HttpRequest, file: func.InputStream) -> str: | ||
return func.HttpResponse(body=file.read().decode('utf-8'), | ||
status_code=200, | ||
mimetype='application/json') |
22 changes: 22 additions & 0 deletions
22
tests/endtoend/eventhub_functions/get_metadata_triggered/function.json
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,22 @@ | ||
{ | ||
"scriptFile": "__init__.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "blob", | ||
"direction": "in", | ||
"name": "file", | ||
"connection": "AzureWebJobsStorage", | ||
"path": "python-worker-tests/test-metadata-triggered.txt" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/endtoend/eventhub_functions/metadata_output/__init__.py
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,35 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
import json | ||
|
||
import azure.functions as func | ||
from azure.eventhub import EventData | ||
from azure.eventhub.aio import EventHubProducerClient | ||
|
||
|
||
# An HttpTrigger to generating EventHub event from azure-eventhub SDK. | ||
# Events generated from azure-eventhub contain the full metadata. | ||
async def main(req: func.HttpRequest): | ||
|
||
# Parse event metadata from http request | ||
json_string = req.get_body().decode('utf-8') | ||
event_dict = json.loads(json_string) | ||
|
||
# Create an EventHub Client and event batch | ||
client = EventHubProducerClient.from_connection_string( | ||
os.getenv('AzureWebJobsEventHubConnectionString'), | ||
eventhub_name='python-worker-ci-eventhub-one-metadata') | ||
|
||
# Generate new event based on http request with full metadata | ||
event_data_batch = await client.create_batch() | ||
event_data_batch.add(EventData(event_dict.get('body'))) | ||
|
||
# Send out event into event hub | ||
try: | ||
await client.send_batch(event_data_batch) | ||
finally: | ||
await client.close() | ||
|
||
return f'OK' |
16 changes: 16 additions & 0 deletions
16
tests/endtoend/eventhub_functions/metadata_output/function.json
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,16 @@ | ||
{ | ||
"scriptFile": "__init__.py", | ||
|
||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"direction": "out", | ||
"name": "$return", | ||
"type": "http" | ||
} | ||
] | ||
} |
Oops, something went wrong.