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
eef62d04
Commit
eef62d04
authored
Nov 04, 2020
by
Bogdan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created Unit Test for duplicated Transaction
parent
fbb7f1ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
3 deletions
+52
-3
repository.py
...ta-hub/semantic-linking-microservice/app/db/repository.py
+9
-0
MessageHandler.py
...ntic-linking-microservice/app/messaging/MessageHandler.py
+13
-1
MessageHandler.py
...ce-retrieval-microservice/app/messaging/MessageHandler.py
+3
-1
test_MessageHandler.py
...e-retrieval-microservice/app/tests/test_MessageHandler.py
+27
-1
No files found.
src/data-hub/semantic-linking-microservice/app/db/repository.py
View file @
eef62d04
...
@@ -97,4 +97,13 @@ class Repository(MongoRepositoryBase):
...
@@ -97,4 +97,13 @@ class Repository(MongoRepositoryBase):
projection
=
{
'_id'
:
0
})
projection
=
{
'_id'
:
0
})
return
list
(
entries
)
return
list
(
entries
)
def
get_nodes_from_ids
(
self
,
unique_id_list
:
List
)
->
List
[
str
]:
result
=
list
(
super
()
.
get_entries
(
self
.
_transaction_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"UniqueID"
:
{
"$in"
:
unique_id_list
}}))
if
len
(
result
)
>
0
:
return
result
return
None
# endregion
# endregion
src/data-hub/semantic-linking-microservice/app/messaging/MessageHandler.py
View file @
eef62d04
...
@@ -84,18 +84,30 @@ class MessageHandler:
...
@@ -84,18 +84,30 @@ class MessageHandler:
return
return
nodes
=
[]
nodes
=
[]
unique_id_list
=
[]
for
layer
in
layers
:
for
layer
in
layers
:
node
=
{}
node
=
{}
for
prop
in
layer
.
total_properties
:
for
prop
in
layer
.
total_properties
:
node
[
prop
]
=
content
[
"properties"
][
prop
]
node
[
prop
]
=
content
[
"properties"
][
prop
]
node
[
"layer_name"
]
=
layer
.
layer_name
node
[
"layer_name"
]
=
layer
.
layer_name
node
[
"table"
]
=
layer
.
table
node
[
"table"
]
=
layer
.
table
node
[
"use_case"
]
=
layer
.
use_case
node
[
"use_case"
]
=
layer
.
use_case
nodes
.
append
(
node
)
nodes
.
append
(
node
)
unique_id_list
.
append
(
node
[
"UniqueId"
])
#check for duplicates
#TODO EDIT NODES_IN_DB RETURN
nodes_in_db
=
self
.
_repository
.
get_nodes_from_ids
(
unique_id_list
)
if
len
(
nodes_in_db
)
>
0
:
#found duplicates
#remove duplicates from nodes:
for
node
in
nodes
:
if
node
[
"UniqueId"
]
in
nodes_in_db
:
nodes
.
remove
(
node
)
#no duplicates anymore
if
len
(
nodes
)
>
0
:
if
len
(
nodes
)
>
0
:
self
.
_repository
.
add_layer_nodes
(
nodes
)
self
.
_repository
.
add_layer_nodes
(
nodes
)
...
...
src/transaction-hub-in/trace-retrieval-microservice/app/messaging/MessageHandler.py
View file @
eef62d04
...
@@ -179,10 +179,12 @@ class MessageHandler:
...
@@ -179,10 +179,12 @@ class MessageHandler:
try
:
try
:
reference
=
self
.
_mongo_repo
.
get_transaction_with_id
(
transaction
.
id
())
reference
=
self
.
_mongo_repo
.
get_transaction_with_id
(
transaction
.
id
())
if
reference
!=
None
:
if
reference
!=
None
:
LOGGER
.
error
(
"Found duplicate"
)
self
.
_mongo_repo
.
add_duplicated_transaction
(
transaction
)
self
.
_mongo_repo
.
add_duplicated_transaction
(
transaction
)
return
#TODO should return? or continue the message to semantic linking?
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
try
:
try
:
self
.
_mongo_repo
.
add_transaction
(
transaction
)
self
.
_mongo_repo
.
add_transaction
(
transaction
)
...
...
src/transaction-hub-in/trace-retrieval-microservice/app/tests/test_MessageHandler.py
View file @
eef62d04
...
@@ -10,6 +10,7 @@ class DummyMongoRepo:
...
@@ -10,6 +10,7 @@ class DummyMongoRepo:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
added_transactions
=
[]
self
.
added_transactions
=
[]
self
.
duplicated_transactions
=
[]
def
insert_trace
(
self
,
trace
):
def
insert_trace
(
self
,
trace
):
self
.
last_trace
=
trace
self
.
last_trace
=
trace
...
@@ -17,6 +18,22 @@ class DummyMongoRepo:
...
@@ -17,6 +18,22 @@ class DummyMongoRepo:
def
add_transaction
(
self
,
transaction
):
def
add_transaction
(
self
,
transaction
):
self
.
added_transactions
.
append
(
transaction
)
self
.
added_transactions
.
append
(
transaction
)
def
get_transaction_with_id
(
self
,
unique_id
:
str
):
result
=
[]
for
trans
in
self
.
added_transactions
:
transID
=
trans
.
id
()
if
transID
==
unique_id
:
result
.
append
(
trans
)
if
len
(
result
)
>
0
:
return
result
return
None
def
add_duplicated_transaction
(
self
,
transaction
):
self
.
duplicated_transactions
.
append
(
transaction
)
from
messaging.DummyMessageManager
import
DummyMessageManager
as
DummyMessageSender
from
messaging.DummyMessageManager
import
DummyMessageManager
as
DummyMessageSender
from
messaging.dummy_rest_fetcher
import
DummyRestFetcher
from
messaging.dummy_rest_fetcher
import
DummyRestFetcher
...
@@ -37,7 +54,7 @@ class Test_MessageHandler(unittest.TestCase):
...
@@ -37,7 +54,7 @@ class Test_MessageHandler(unittest.TestCase):
{
'type'
:
'blockchain-transaction'
,
{
'type'
:
'blockchain-transaction'
,
'content'
:
'content'
:
{
{
"ApplicationType"
:
"
string
"
,
"ApplicationType"
:
"
paper
"
,
"docType"
:
"string"
,
"docType"
:
"string"
,
"Metadata"
:
{},
"Metadata"
:
{},
"ResourceIds"
:
"string"
,
"ResourceIds"
:
"string"
,
...
@@ -111,5 +128,14 @@ class Test_MessageHandler(unittest.TestCase):
...
@@ -111,5 +128,14 @@ class Test_MessageHandler(unittest.TestCase):
self
.
assertEqual
(
'semantic-linking'
,
self
.
msg_sender
.
last_message
[
'key'
])
self
.
assertEqual
(
'semantic-linking'
,
self
.
msg_sender
.
last_message
[
'key'
])
self
.
assertEqual
(
'new-trace'
,
json
.
loads
(
self
.
msg_sender
.
last_message
[
'msg'
])[
"type"
])
self
.
assertEqual
(
'new-trace'
,
json
.
loads
(
self
.
msg_sender
.
last_message
[
'msg'
])[
"type"
])
def
test_handleblockchain_duplicateTrace
(
self
):
msg
=
self
.
_get_valid_message
()
msg2
=
self
.
_get_valid_message
()
msg
=
eval
(
msg
)
msg2
=
eval
(
msg2
)
self
.
handler
.
handle_blockchain_transaction
(
msg
[
'content'
])
self
.
handler
.
handle_blockchain_transaction
(
msg2
[
'content'
])
self
.
assertEqual
(
len
(
self
.
repo
.
added_transactions
),
len
(
self
.
repo
.
duplicated_transactions
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
\ 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