From c96fefea67e0c9c4d718290921e024d04605d970 Mon Sep 17 00:00:00 2001 From: xkollar3 <xkollar3@fi.muni.cz> Date: Wed, 8 May 2024 15:35:38 +0200 Subject: [PATCH] added more tasks to locust, fixed addressing in etl --- .../src/main/resources/application.yml | 2 +- locustfile.py | 37 +++++++++++++++++-- readme.md | 5 +++ .../initialization_data/accounts.json | 8 ++-- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/analytics-service/src/main/resources/application.yml b/analytics-service/src/main/resources/application.yml index 4107191..0d8314a 100644 --- a/analytics-service/src/main/resources/application.yml +++ b/analytics-service/src/main/resources/application.yml @@ -30,4 +30,4 @@ spring: etl: transaction-service: - url: 'http://localhost:8082/api/transaction-service' \ No newline at end of file + url: 'http://host.docker.internal:8082/api/transaction-service' \ No newline at end of file diff --git a/locustfile.py b/locustfile.py index ff454ec..97f0b4d 100644 --- a/locustfile.py +++ b/locustfile.py @@ -1,15 +1,23 @@ from locust import HttpUser, task, between import json +import random class ObsUser(HttpUser): - host = "http://localhost:8082" + accounts = [ + {"id": "5217d3f7-e716-48ac-8a45-e0c54257d203", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c5", "currencyCode": "CZK"}, + {"id": "2aa6cf23-f3e1-49f0-9c2e-9032400becfa", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c6", "currencyCode": "EUR"}, + {"id": "20451388-9dc6-44d6-b05d-c611071b6862", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c7", "currencyCode": "EUR"}, + {"id": "086aa375-8386-4316-adb3-c10da97038ef", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c7", "currencyCode": "CZK"}, + {"id": "90b3d598-b611-486e-845c-f2234beb1ce2", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c8", "currencyCode": "EUR"}, + {"id": "c7148e7e-8b08-4323-a5fe-2be9b5f32514", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c8", "currencyCode": "EUR", "isBankAccount": True} + ] @task def test_task(self): datajson = { - "withdrawsFromAccountNumber": "bank-1", - "depositsToAccountNumber": "account-1", + "withdrawsFromAccount": "c7148e7e-8b08-4323-a5fe-2be9b5f32514", + "depositsToAccount": "90b3d598-b611-486e-845c-f2234beb1ce2", "withdrawAmount": 1000 } @@ -17,4 +25,25 @@ class ObsUser(HttpUser): response = self.client.post("/api/transaction-service/v1/transactions/transaction/create", data=request, headers={'Content-Type': 'application/json', 'Accept': 'application/json'}) - print(response.json()) \ No newline at end of file + print(response.json()) + + @task(3) # Adjust the weight to define how frequently this task should be executed + def transfer_task(self): + sender_account = random.choice([acc for acc in self.accounts if not acc.get("isBankAccount")]) + receiver_account = random.choice([acc for acc in self.accounts if acc.get("id") != sender_account["id"]]) + + amount = random.randint(10, 1000) # You can adjust the range as per your requirements + + datajson = { + "withdrawsFromAccount": sender_account["id"], + "depositsToAccount": receiver_account["id"], + "withdrawAmount": amount + } + + request = json.dumps(datajson) + + response = self.client.post("/api/transaction-service/v1/transactions/transaction/create", data=request, headers={'Content-Type': 'application/json', 'Accept': 'application/json'}) + + print(response.json()) + + wait_time = between(5, 10) # Adjust the wait time between tasks \ No newline at end of file diff --git a/readme.md b/readme.md index 6e77ce0..4755acc 100644 --- a/readme.md +++ b/readme.md @@ -13,6 +13,11 @@ Now all the services and the databases are running, and you can access them on t - Currency-service: `localhost:8083/currency-service` - Analytics-service: `localhost:8080/api/analytics-service` +locust: we only defined the scenario of creating transactions in locust as it would be only API that the customers would +use frequently +there is defined a scenario when someone deposits money via ATM meaning in the scenario the customer deposits 1000 and +it is deducted +from the banks account ## Use case:  diff --git a/transaction-service/src/main/resources/initialization_data/accounts.json b/transaction-service/src/main/resources/initialization_data/accounts.json index 0f973f0..7dd14d2 100644 --- a/transaction-service/src/main/resources/initialization_data/accounts.json +++ b/transaction-service/src/main/resources/initialization_data/accounts.json @@ -7,12 +7,12 @@ { "id": "2aa6cf23-f3e1-49f0-9c2e-9032400becfa", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c6", - "currencyCode": "eur" + "currencyCode": "EUR" }, { "id": "20451388-9dc6-44d6-b05d-c611071b6862", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c7", - "currencyCode": "eur" + "currencyCode": "EUR" }, { "id": "086aa375-8386-4316-adb3-c10da97038ef", @@ -22,12 +22,12 @@ { "id": "90b3d598-b611-486e-845c-f2234beb1ce2", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c8", - "currencyCode": "eur" + "currencyCode": "EUR" }, { "id": "c7148e7e-8b08-4323-a5fe-2be9b5f32514", "customerId": "4121add0-f5d7-4128-9c8f-e81fa93237c8", - "currencyCode": "eur", + "currencyCode": "EUR", "isBankAccount": true } ] -- GitLab