From fd6f7dd1bacfdcb3969fe95ea82a8d43d8941911 Mon Sep 17 00:00:00 2001 From: amulyavarote <91495930+amulyavarote@users.noreply.github.com> Date: Sun, 6 Mar 2022 22:49:15 -0800 Subject: [PATCH] Added tests for service invocation (#576) * Added tests for service invocation Signed-off-by: Amulya Varote * Removed go binary files Signed-off-by: Amulya Varote Co-authored-by: Amulya Varote --- service_invocation/csharp/http/README.md | 98 ++++++++++++------- service_invocation/go/http/README.md | 89 ++++++++++------- service_invocation/go/http/checkout/app.go | 2 +- .../go/http/order-processor/app.go | 3 +- service_invocation/javascript/http/README.md | 90 ++++++++++------- service_invocation/python/http/README.md | 96 +++++++++++------- .../python/http/checkout/app.py | 4 +- 7 files changed, 235 insertions(+), 147 deletions(-) diff --git a/service_invocation/csharp/http/README.md b/service_invocation/csharp/http/README.md index f4714dac..2ab8d5ca 100644 --- a/service_invocation/csharp/http/README.md +++ b/service_invocation/csharp/http/README.md @@ -12,57 +12,79 @@ And one order processor service: - Dotnet order-processor service `order-processor` -### Run Dotnet checkout with Dapr +### Run Dotnet order-processor with Dapr -1. Open a new terminal window and navigate to the `checkout` directory: - -```bash -cd checkout -``` - -2. Install dependencies: +1. Open a new terminal window and navigate to `order-processor` directory and install dependencies: ```bash +cd service_invocation/csharp/http/order-processor dotnet restore dotnet build ``` -3. Run the Dotnet checkout app with Dapr: + + +2. Run the Dotnet order-processor app with Dapr: + + + +```bash +cd service_invocation/csharp/http/order-processor +dapr run --app-port 7001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- dotnet run +``` + + + +### Run Dotnet checkout with Dapr + +1. Open a new terminal window and navigate to the `checkout` directory and install dependencies: + + + +```bash +cd service_invocation/csharp/http/checkout +dotnet restore +dotnet build +``` + + + +2. Run the Dotnet checkout app with Dapr: + + ```bash +cd service_invocation/csharp/http/checkout dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- dotnet run ``` - -### Run Dotnet order-processor with Dapr - -1. Open a new terminal window and navigate to `order-processor` directory: - -```bash -cd order-processor -``` - -2. Install dependencies: - - - -```bash -dotnet restore -dotnet build -``` - -3. Run the Dotnet order-processor app with Dapr: - -```bash -dapr run --app-port 6001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- dotnet run -``` - - + \ No newline at end of file diff --git a/service_invocation/go/http/README.md b/service_invocation/go/http/README.md index 682ed3c7..0731bc35 100644 --- a/service_invocation/go/http/README.md +++ b/service_invocation/go/http/README.md @@ -12,55 +12,76 @@ And one order processor service: - Go order-processor service `order-processor` -### Run Go checkout with Dapr - -1. Open a new terminal window and navigate to `checkout` directory: - -```bash -cd checkout -``` - -2. Install dependencies: - - - -```bash -go build app.go -``` - -3. Run the Go checkout app with Dapr: - -```bash -dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- go run app.go -``` - - ### Run Go order-processor with Dapr 1. Open a new terminal window and navigate to `order-processor` directory: -```bash -cd order-processor -``` - -2. Install dependencies: - ```bash +cd service_invocation/go/http/order-processor go build app.go ``` + + 3. Run the Go order-processor app with Dapr: + + ```bash +cd service_invocation/go/http/order-processor dapr run --app-port 6001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- go run app.go ``` + +### Run Go checkout with Dapr + +1. Open a new terminal window and navigate to `checkout` directory: + + + +```bash +cd service_invocation/go/http/checkout +go build app.go +``` + + +2. Run the Go checkout app with Dapr: + + + +```bash +cd service_invocation/go/http/checkout +dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- go run app.go +``` + + \ No newline at end of file diff --git a/service_invocation/go/http/checkout/app.go b/service_invocation/go/http/checkout/app.go index ced383dd..a9172451 100644 --- a/service_invocation/go/http/checkout/app.go +++ b/service_invocation/go/http/checkout/app.go @@ -43,6 +43,6 @@ func main() { log.Fatal(err) } - log.Println("Order passed: ", string(result)) + fmt.Println("Order passed: ", string(result)) } } diff --git a/service_invocation/go/http/order-processor/app.go b/service_invocation/go/http/order-processor/app.go index 8ea56e64..37fc75fb 100644 --- a/service_invocation/go/http/order-processor/app.go +++ b/service_invocation/go/http/order-processor/app.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "io/ioutil" "log" "net/http" @@ -14,7 +15,7 @@ func getOrder(w http.ResponseWriter, r *http.Request) { if err != nil { log.Fatal(err) } - log.Printf("Order received : %s", string(data)) + fmt.Println("Order received : ", string(data)) obj, err := json.Marshal(string(data)) if err != nil { log.Println("Error in reading the result obj") diff --git a/service_invocation/javascript/http/README.md b/service_invocation/javascript/http/README.md index 82cfbed6..b255ab46 100644 --- a/service_invocation/javascript/http/README.md +++ b/service_invocation/javascript/http/README.md @@ -12,55 +12,77 @@ And one order-processor service: - Node order-processor service `order-processor` -### Run Node checkout with Dapr +### Run Node order-processor with Dapr -1. Open a new terminal window and navigate to `checkout` directory: - -```bash -cd checkout -``` - -2. Install dependencies: +1. Open a new terminal window and navigate to `order-processor` directory and install dependencies: ```bash +cd service_invocation/javascript/http/order-processor npm install ``` -3. Run the Node checkout app with Dapr: - -```bash -dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- npm start -``` - -### Run Node order-processor with Dapr - -1. Open a new terminal window and navigate to `order-processor` directory: - -```bash -cd order-processor -``` - -2. Install dependencies: - - - -```bash -npm install -``` 3. Run the Node order-processor app with Dapr: + + ```bash -dapr run --app-port 6001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- npm start +cd service_invocation/javascript/http/order-processor +dapr run --app-port 5001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- npm start ``` + +### Run Node checkout with Dapr + +1. Open a new terminal window and navigate to `checkout` directory and install dependencies: + + + +```bash +cd service_invocation/javascript/http/checkout +npm install +``` + + + +2. Run the Node checkout app with Dapr: + + + +```bash +cd service_invocation/javascript/http/checkout +dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- npm start +``` + + \ No newline at end of file diff --git a/service_invocation/python/http/README.md b/service_invocation/python/http/README.md index d9725044..2185ed57 100644 --- a/service_invocation/python/http/README.md +++ b/service_invocation/python/http/README.md @@ -12,55 +12,77 @@ And one order processor service: - Python order-processor service `order-processor` -### Run Python checkout with Dapr +### Run Python order-processor with Dapr -1. Open a new terminal window and navigate to `checkout` directory: - -```bash -cd checkout -``` - -2. Install dependencies: +1. Open a new terminal window and navigate to `order-processor` directory and install dependencies: ```bash +cd service_invocation/python/http/order-processor pip3 install -r requirements.txt ``` -3. Run the Python checkout app with Dapr: + + +2. Run the Python order-processor app with Dapr: + + + +```bash +cd service_invocation/python/http/order-processor +dapr run --app-port 5001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- python3 app.py +``` + + + +### Run Python checkout with Dapr + +1. Open a new terminal window and navigate to `checkout` directory and install dependencies: + + + +```bash +cd service_invocation/python/http/checkout +pip3 install -r requirements.txt +``` + + + +2. Run the Python checkout app with Dapr: + + ```bash +cd service_invocation/python/http/checkout dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- python3 app.py ``` - -### Run Python order-processor with Dapr - -1. Open a new terminal window and navigate to `order-processor` directory: - -```bash -cd order-processor -``` - -2. Install dependencies: - - - -```bash -pip3 install -r requirements.txt -``` - -3. Run the Python order-processor app with Dapr: - -```bash -dapr run --app-port 6001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- python3 app.py -``` - - + \ No newline at end of file diff --git a/service_invocation/python/http/checkout/app.py b/service_invocation/python/http/checkout/app.py index d2487cb4..9127ac40 100644 --- a/service_invocation/python/http/checkout/app.py +++ b/service_invocation/python/http/checkout/app.py @@ -11,7 +11,7 @@ base_url = os.getenv('BASE_URL', 'http://localhost') + ':' + os.getenv( # Adding app id as part of the header headers = {'dapr-app-id': 'order-processor'} -for i in range(1, 10): +for i in range(1, 11): order = {'orderId': i} # Invoking a service @@ -20,6 +20,6 @@ for i in range(1, 10): data=json.dumps(order), headers=headers ) - logging.info('Order passed: ' + json.dumps(order)) + print('Order passed: ' + json.dumps(order)) time.sleep(1)