Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
c583b728
Unverified
Commit
c583b728
authored
7 years ago
by
Sébastien Blin
Browse files
Options
Downloads
Patches
Plain Diff
tests: add testListen for DhtProxyTester
parent
7f943e07
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/dhtproxytester.cpp
+57
-5
57 additions, 5 deletions
tests/dhtproxytester.cpp
tests/dhtproxytester.h
+5
-0
5 additions, 0 deletions
tests/dhtproxytester.h
with
62 additions
and
5 deletions
tests/dhtproxytester.cpp
+
57
−
5
View file @
c583b728
...
@@ -51,27 +51,79 @@ DhtProxyTester::tearDown() {
...
@@ -51,27 +51,79 @@ DhtProxyTester::tearDown() {
nodePeer
.
join
();
nodePeer
.
join
();
nodeClient
->
join
();
nodeClient
->
join
();
server
->
stop
();
server
->
stop
();
server
=
nullptr
;
nodeProxy
->
join
();
nodeProxy
->
join
();
}
}
void
void
DhtProxyTester
::
testGetPut
()
{
DhtProxyTester
::
testGetPut
()
{
auto
cv
=
std
::
make_shared
<
std
::
condition_variable
>
();
bool
done
=
false
;
std
::
condition_variable
cv
;
std
::
mutex
cv_m
;
std
::
mutex
cv_m
;
auto
key
=
dht
::
InfoHash
::
get
(
"GLaDOs"
);
auto
key
=
dht
::
InfoHash
::
get
(
"GLaDOs"
);
dht
::
Value
val
{
"He
i
! It's been a long time. How have you been?"
};
dht
::
Value
val
{
"He
y
! It's been a long time. How have you been?"
};
auto
val_data
=
val
.
data
;
auto
val_data
=
val
.
data
;
nodePeer
.
put
(
key
,
std
::
move
(
val
),
[
cv
](
bool
)
{
nodePeer
.
put
(
key
,
std
::
move
(
val
),
[
&
](
bool
)
{
cv
->
notify_all
();
done
=
true
;
cv
.
notify_all
();
});
});
std
::
unique_lock
<
std
::
mutex
>
lk
(
cv_m
);
std
::
unique_lock
<
std
::
mutex
>
lk
(
cv_m
);
cv
->
wait_for
(
lk
,
std
::
chrono
::
seconds
(
10
));
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
10
)
,
[
&
]{
return
done
;
}
);
auto
vals
=
nodeClient
->
get
(
key
).
get
();
auto
vals
=
nodeClient
->
get
(
key
).
get
();
CPPUNIT_ASSERT
(
not
vals
.
empty
());
CPPUNIT_ASSERT
(
not
vals
.
empty
());
CPPUNIT_ASSERT
(
vals
.
front
()
->
data
==
val_data
);
CPPUNIT_ASSERT
(
vals
.
front
()
->
data
==
val_data
);
}
}
void
DhtProxyTester
::
testListen
()
{
bool
done
=
false
;
std
::
condition_variable
cv
;
std
::
mutex
cv_m
;
std
::
unique_lock
<
std
::
mutex
>
lk
(
cv_m
);
auto
key
=
dht
::
InfoHash
::
get
(
"GLaDOs"
);
// If a peer send a value, the listen operation from the client
// should retrieve this value
dht
::
Value
firstVal
{
"Hey! It's been a long time. How have you been?"
};
auto
firstVal_data
=
firstVal
.
data
;
nodePeer
.
put
(
key
,
std
::
move
(
firstVal
),
[
&
](
bool
)
{
done
=
true
;
cv
.
notify_all
();
});
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
10
),
[
&
]{
return
done
;
});
done
=
false
;
auto
values
=
std
::
vector
<
dht
::
Blob
>
();
nodeClient
->
listen
(
key
,
[
&
](
const
std
::
vector
<
std
::
shared_ptr
<
dht
::
Value
>>&
v
,
bool
)
{
for
(
const
auto
&
value
:
v
)
values
.
emplace_back
(
value
->
data
);
done
=
true
;
cv
.
notify_all
();
return
true
;
});
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
10
),
[
&
]{
return
done
;
});
done
=
false
;
// Here values should contains 2 values
CPPUNIT_ASSERT_EQUAL
(
static_cast
<
int
>
(
values
.
size
()),
1
);
CPPUNIT_ASSERT
(
values
.
front
()
==
firstVal_data
);
// And the listen should retrieve futures values
// All values
dht
::
Value
secondVal
{
"You're a monster"
};
auto
secondVal_data
=
secondVal
.
data
;
nodePeer
.
put
(
key
,
std
::
move
(
secondVal
),
[
&
](
bool
)
{
done
=
true
;
cv
.
notify_all
();
});
cv
.
wait_for
(
lk
,
std
::
chrono
::
seconds
(
10
),
[
&
]{
return
done
;
});
// Here values should contains 3 values
CPPUNIT_ASSERT_EQUAL
(
static_cast
<
int
>
(
values
.
size
()),
2
);
CPPUNIT_ASSERT
(
values
.
back
()
==
secondVal_data
);
}
}
// namespace test
}
// namespace test
This diff is collapsed.
Click to expand it.
tests/dhtproxytester.h
+
5
−
0
View file @
c583b728
...
@@ -31,6 +31,7 @@ namespace test {
...
@@ -31,6 +31,7 @@ namespace test {
class
DhtProxyTester
:
public
CppUnit
::
TestFixture
{
class
DhtProxyTester
:
public
CppUnit
::
TestFixture
{
CPPUNIT_TEST_SUITE
(
DhtProxyTester
);
CPPUNIT_TEST_SUITE
(
DhtProxyTester
);
CPPUNIT_TEST
(
testGetPut
);
CPPUNIT_TEST
(
testGetPut
);
CPPUNIT_TEST
(
testListen
);
CPPUNIT_TEST_SUITE_END
();
CPPUNIT_TEST_SUITE_END
();
public:
public:
...
@@ -47,6 +48,10 @@ class DhtProxyTester : public CppUnit::TestFixture {
...
@@ -47,6 +48,10 @@ class DhtProxyTester : public CppUnit::TestFixture {
* Test get and put methods
* Test get and put methods
*/
*/
void
testGetPut
();
void
testGetPut
();
/**
* Test listen
*/
void
testListen
();
private:
private:
dht
::
DhtRunner
nodePeer
{};
dht
::
DhtRunner
nodePeer
{};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment