Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
c3a32399
Commit
c3a32399
authored
Mar 16, 2021
by
Bogdan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bugfix/duplicate-trace' into develop
parents
eb6c6e13
cd5c2e2d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
11 deletions
+65
-11
repository.py
...n/trace-retrieval-microservice/app/database/repository.py
+2
-2
MessageHandler.py
...ce-retrieval-microservice/app/messaging/MessageHandler.py
+7
-6
test_MessageHandler.py
...e-retrieval-microservice/app/tests/test_MessageHandler.py
+19
-0
upload_data.py
tools/reddit-upload/upload_data.py
+37
-3
No files found.
src/transaction-hub-in/trace-retrieval-microservice/app/database/repository.py
View file @
c3a32399
...
@@ -44,8 +44,8 @@ class Repository(MongoRepositoryBase):
...
@@ -44,8 +44,8 @@ class Repository(MongoRepositoryBase):
def
get_transaction_with_id
(
self
,
unique_id
:
str
)
->
Transaction
:
def
get_transaction_with_id
(
self
,
unique_id
:
str
)
->
Transaction
:
result
=
list
(
super
()
.
get_entries
(
self
.
_transaction_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"UniqueID"
:
unique_id
}))
result
=
list
(
super
()
.
get_entries
(
self
.
_transaction_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"UniqueID"
:
unique_id
}))
if
len
(
result
)
=
=
1
:
if
len
(
result
)
>
=
1
:
return
Transaction
.
from_serializable_dict
(
result
[
0
]
)
return
Transaction
.
from_serializable_dict
(
result
)
return
None
return
None
...
...
src/transaction-hub-in/trace-retrieval-microservice/app/messaging/MessageHandler.py
View file @
c3a32399
...
@@ -180,12 +180,13 @@ class MessageHandler:
...
@@ -180,12 +180,13 @@ class MessageHandler:
#check for duplicates
#check for duplicates
try
:
try
:
reference
=
self
.
_mongo_repo
.
get_transaction_with_id
(
transaction
.
id
())
references
=
self
.
_mongo_repo
.
get_transaction_with_id
(
transaction
.
id
())
if
reference
!=
None
:
if
references
!=
None
:
if
(
reference
[
0
]
.
table
==
transaction
.
table
)
and
(
reference
[
0
]
.
use_case
==
transaction
.
use_case
):
for
item
in
references
:
LOGGER
.
error
(
"Found duplicate"
)
if
(
item
.
table
==
transaction
.
table
)
and
(
item
.
use_case
==
transaction
.
use_case
):
self
.
_mongo_repo
.
add_duplicated_transaction
(
transaction
)
LOGGER
.
error
(
"Found duplicate"
)
return
self
.
_mongo_repo
.
add_duplicated_transaction
(
transaction
)
return
except
ValueError
as
e
:
except
ValueError
as
e
:
LOGGER
.
error
(
f
"{e}, could not insert duplicated node."
)
LOGGER
.
error
(
f
"{e}, could not insert duplicated node."
)
return
return
...
...
src/transaction-hub-in/trace-retrieval-microservice/app/tests/test_MessageHandler.py
View file @
c3a32399
...
@@ -178,6 +178,7 @@ class Test_MessageHandler(unittest.TestCase):
...
@@ -178,6 +178,7 @@ class Test_MessageHandler(unittest.TestCase):
self
.
handler
.
handle_blockchain_transaction
(
msg
[
'content'
])
self
.
handler
.
handle_blockchain_transaction
(
msg
[
'content'
])
self
.
handler
.
handle_blockchain_transaction
(
msg2
[
'content'
])
self
.
handler
.
handle_blockchain_transaction
(
msg2
[
'content'
])
self
.
assertEqual
(
len
(
self
.
repo
.
added_transactions
),
len
(
self
.
repo
.
duplicated_transactions
))
self
.
assertEqual
(
len
(
self
.
repo
.
added_transactions
),
len
(
self
.
repo
.
duplicated_transactions
))
self
.
assertEqual
(
len
(
self
.
repo
.
added_transactions
),
1
)
def
test_handleBlockchainTransaction_duplicateTraceDifferentTable_bothTransactionsAddedAsUnique
(
self
):
def
test_handleBlockchainTransaction_duplicateTraceDifferentTable_bothTransactionsAddedAsUnique
(
self
):
msg
=
self
.
_get_valid_message
()
msg
=
self
.
_get_valid_message
()
...
@@ -197,5 +198,23 @@ class Test_MessageHandler(unittest.TestCase):
...
@@ -197,5 +198,23 @@ class Test_MessageHandler(unittest.TestCase):
self
.
handler
.
handle_blockchain_transaction
(
msg2
[
'content'
])
self
.
handler
.
handle_blockchain_transaction
(
msg2
[
'content'
])
self
.
assertEqual
(
len
(
self
.
repo
.
added_transactions
),
2
)
self
.
assertEqual
(
len
(
self
.
repo
.
added_transactions
),
2
)
def
test_handleBlockchainTransaction_multipleTransactions_3AddedUnique2Duplicate
(
self
):
msg
=
self
.
_get_valid_message
()
msg2
=
self
.
_get_valid_message2
()
msg3
=
self
.
_get_valid_message3
()
msg4
=
self
.
_get_valid_message3
()
msg5
=
self
.
_get_valid_message3
()
msg
=
eval
(
msg
)
msg2
=
eval
(
msg2
)
msg3
=
eval
(
msg3
)
msg4
=
eval
(
msg4
)
msg5
=
eval
(
msg5
)
self
.
handler
.
handle_blockchain_transaction
(
msg
[
'content'
])
self
.
handler
.
handle_blockchain_transaction
(
msg2
[
'content'
])
self
.
handler
.
handle_blockchain_transaction
(
msg3
[
'content'
])
self
.
handler
.
handle_blockchain_transaction
(
msg4
[
'content'
])
self
.
handler
.
handle_blockchain_transaction
(
msg5
[
'content'
])
self
.
assertEqual
(
len
(
self
.
repo
.
added_transactions
),
3
)
self
.
assertEqual
(
len
(
self
.
repo
.
duplicated_transactions
),
2
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
\ No newline at end of file
tools/reddit-upload/upload_data.py
View file @
c3a32399
...
@@ -18,7 +18,7 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
...
@@ -18,7 +18,7 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def
send_transaction_to_rest_gateway
(
transaction
:
dict
):
def
send_transaction_to_rest_gateway
(
transaction
:
dict
):
# token from Rest Gateway to authorize
# token from Rest Gateway to authorize
JWT_TOKEN
=
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InJlZ3VsYXJAaXRlYy5hYXUuYXQiLCJjcmVhdGVkX2F0IjoiMjAyMS0wM
i0wOCAxMzo0NzoxOC40NzUxMjEiLCJ2YWxpZF91bnRpbCI6IjIwMjEtMDItMDkgMTM6NDc6MTguNDc1MTIxIn0.DWY9c0X2XQJDz0Ef35-k1IVY6GWf00ogaVOCeX8Irlo
'
JWT_TOKEN
=
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InJlZ3VsYXJAaXRlYy5hYXUuYXQiLCJjcmVhdGVkX2F0IjoiMjAyMS0wM
y0xNiAxMzoxNDoyMS42MDc1NjciLCJ2YWxpZF91bnRpbCI6IjIwMjEtMDMtMTcgMTM6MTQ6MjEuNjA3NTY3In0.ZGObriEDWYo1BgiYN3pQSosS7UuNrq10GSCSjmRHSAw
'
res
=
requests
.
post
(
res
=
requests
.
post
(
url
=
'https://articonf1.itec.aau.at:30401/api/trace'
,
url
=
'https://articonf1.itec.aau.at:30401/api/trace'
,
...
@@ -47,15 +47,49 @@ if __name__ == '__main__':
...
@@ -47,15 +47,49 @@ if __name__ == '__main__':
transaction
[
'ApplicationType'
]
=
'reddit'
transaction
[
'ApplicationType'
]
=
'reddit'
transaction
[
'docType'
]
=
'reddit'
transaction
[
'docType'
]
=
'reddit'
for
key
,
value
in
obj_dict
.
items
():
for
key
,
value
in
obj_dict
.
items
():
transaction
[
key
]
=
value
transaction
[
key
]
=
value
#####################TEEEEEEEEEEST###########
transaction
=
{
#"type": "blockchain-transaction",
"ApplicationType"
:
"debug"
,
"docType"
:
"pizza"
,
"id"
:
1
,
"name"
:
"MEXICAANA"
,
"dough"
:
{
"type"
:
"wheat"
,
"spinach"
:
False
},
"toppings"
:
[
{
"name"
:
"Tomato Sauce"
,
"price"
:
1.00
},
{
"name"
:
"Cheese"
,
"price"
:
0.50
},
{
"name"
:
"Chilli Oil"
,
"price"
:
0.50
},
{
"name"
:
"Peppers"
,
"price"
:
1.50
}
]
}
###################FIN TEEEEST ###############
send_transaction_to_rest_gateway
(
transaction
)
send_transaction_to_rest_gateway
(
transaction
)
summ
+=
1
summ
+=
1
if
(
summ
%
1000
==
0
):
if
(
summ
%
1000
==
0
):
print
(
"Uploaded "
+
str
(
summ
)
+
" transactions."
)
print
(
"Uploaded "
+
str
(
summ
)
+
" transactions."
)
if
summ
>=
1
:
break
print
(
"TOTAL Uploaded "
+
str
(
summ
)
+
" transactions."
)
print
(
"TOTAL Uploaded "
+
str
(
summ
)
+
" transactions."
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment