diff --git a/analytics-service/src/main/resources/application.yml b/analytics-service/src/main/resources/application.yml index 4107191d3b8b8ce452288a637a0d280b10279cd6..0d8314a45e4849e6a75b6e4d00e9cc6dd20e3455 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 ff454ec2f3e6e0b3a491b9ae87972cb247c0aab1..97f0b4d013c2a2715377f499f71bb09814137ee3 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 6e77ce0f4b56d4938c89398465387a4081045c9b..4755acc0ed8f5b2f6fe417e589906269b944a8ee 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 0f973f0af593f32ae9f962b6993383498932e754..7dd14d24ea53ca6b1be99985dfd9e5a3ab1e305b 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 } ]