Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
c9cb309a
Commit
c9cb309a
authored
Nov 26, 2019
by
zhujiashun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis_server_protocol: refine UT
parent
3c4d745b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
30 deletions
+44
-30
redis_protocol.cpp
src/brpc/policy/redis_protocol.cpp
+0
-5
CMakeLists.txt
test/CMakeLists.txt
+1
-1
brpc_redis_unittest.cpp
test/brpc_redis_unittest.cpp
+43
-24
No files found.
src/brpc/policy/redis_protocol.cpp
View file @
c9cb309a
...
...
@@ -35,7 +35,6 @@
#include "brpc/redis_command.h"
#include "brpc/policy/redis_protocol.h"
#include "bthread/execution_queue.h"
#include "bthread/countdown_event.h"
namespace
brpc
{
...
...
@@ -182,8 +181,6 @@ int ConsumeTask(RedisConnContext* meta, const RedisMessage& m) {
args
,
&
output
,
done_guard
.
release
());
if
(
result
==
RedisCommandHandler
::
OK
)
{
meta
->
handler_continue
=
NULL
;
}
else
{
LOG
(
ERROR
)
<<
"Unknown handler result="
<<
(
int
)
result
;
}
}
else
{
std
::
string
comm
;
...
...
@@ -201,8 +198,6 @@ int ConsumeTask(RedisConnContext* meta, const RedisMessage& m) {
it
->
second
->
Run
(
args
,
&
output
,
done_guard
.
release
());
if
(
result
==
RedisCommandHandler
::
CONTINUE
)
{
meta
->
handler_continue
=
it
->
second
.
get
();
}
else
{
LOG
(
ERROR
)
<<
"Unknown handler result="
<<
(
int
)
result
;
}
}
}
...
...
test/CMakeLists.txt
View file @
c9cb309a
...
...
@@ -51,7 +51,7 @@ else()
message
(
FATAL_ERROR
"Googletest is not available"
)
endif
()
set
(
CMAKE_CPP_FLAGS
"
${
DEFINE_CLOCK_GETTIME
}
-DBRPC_
ENABLE_CPU_PROFILER -DBRPC_
WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
set
(
CMAKE_CPP_FLAGS
"
${
DEFINE_CLOCK_GETTIME
}
-DBRPC_WITH_GLOG=
${
WITH_GLOG_VAL
}
-DGFLAGS_NS=
${
GFLAGS_NS
}
"
)
set
(
CMAKE_CPP_FLAGS
"
${
CMAKE_CPP_FLAGS
}
-DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__= -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES -D__STRICT_ANSI__ -include
${
PROJECT_SOURCE_DIR
}
/test/sstream_workaround.h"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CPP_FLAGS
}
-O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer"
)
use_cxx11
()
...
...
test/brpc_redis_unittest.cpp
View file @
c9cb309a
...
...
@@ -665,19 +665,23 @@ butil::Mutex s_mutex;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
m
;
std
::
unordered_map
<
std
::
string
,
int64_t
>
int_map
;
void
*
random_sleep
(
void
*
arg
)
{
google
::
protobuf
::
Closure
*
done
=
static_cast
<
google
::
protobuf
::
Closure
*>
(
arg
);
// [50, 100) ms
int
sleep_ms
=
50
+
butil
::
fast_rand_less_than
(
50
);
bthread_usleep
(
sleep_ms
*
1000
);
done
->
Run
();
struct
SleepArgs
{
int
sleep_ms
;
google
::
protobuf
::
Closure
*
done
;
};
void
*
sleep
(
void
*
arg
)
{
SleepArgs
*
args
=
static_cast
<
SleepArgs
*>
(
arg
);
bthread_usleep
(
args
->
sleep_ms
*
1000
);
args
->
done
->
Run
();
delete
args
;
return
NULL
;
}
class
SetCommandHandler
:
public
brpc
::
RedisCommandHandler
{
public
:
SetCommandHandler
(
bool
rand_
sleep
=
false
)
:
_
rand_sleep
(
rand_
sleep
)
{}
SetCommandHandler
(
bool
sleep
=
false
)
:
_
sleep
(
sleep
)
{}
brpc
::
RedisCommandHandler
::
Result
Run
(
const
char
*
args
[],
brpc
::
RedisMessage
*
output
,
...
...
@@ -687,24 +691,29 @@ public:
std
::
string
value
=
args
[
2
];
m
[
key
]
=
value
;
output
->
SetStatus
(
"OK"
);
if
(
_rand_sleep
)
{
if
(
_sleep
)
{
SleepArgs
*
args
=
new
SleepArgs
;
args
->
sleep_ms
=
_sleep_ms
;
args
->
done
=
done_guard
.
release
();
bthread_t
bth
;
bthread_start_background
(
&
bth
,
NULL
,
random_sleep
,
done_guard
.
release
());
EXPECT_EQ
(
0
,
bthread_start_background
(
&
bth
,
NULL
,
sleep
,
args
));
if
(
_sleep_ms
>
20
)
_sleep_ms
-=
20
;
}
return
brpc
::
RedisCommandHandler
::
OK
;
}
RedisCommandHandler
*
New
()
{
_new_count
++
;
return
new
SetCommandHandler
(
_
rand_
sleep
);
}
RedisCommandHandler
*
New
()
{
_new_count
++
;
return
new
SetCommandHandler
(
_sleep
);
}
int
new_count
()
{
return
_new_count
;
}
private
:
int
_sleep_ms
=
100
;
int
_new_count
=
0
;
bool
_
rand_
sleep
=
false
;
bool
_sleep
=
false
;
};
class
GetCommandHandler
:
public
brpc
::
RedisCommandHandler
{
public
:
GetCommandHandler
(
bool
rand_
sleep
=
false
)
:
_
rand_sleep
(
rand_
sleep
)
{}
GetCommandHandler
(
bool
sleep
=
false
)
:
_
sleep
(
sleep
)
{}
brpc
::
RedisCommandHandler
::
Result
Run
(
const
char
*
args
[],
brpc
::
RedisMessage
*
output
,
...
...
@@ -717,24 +726,29 @@ public:
}
else
{
output
->
SetNilString
();
}
if
(
_rand_sleep
)
{
if
(
_sleep
)
{
SleepArgs
*
args
=
new
SleepArgs
;
args
->
sleep_ms
=
_sleep_ms
;
args
->
done
=
done_guard
.
release
();
bthread_t
bth
;
bthread_start_background
(
&
bth
,
NULL
,
random_sleep
,
done_guard
.
release
());
EXPECT_EQ
(
0
,
bthread_start_background
(
&
bth
,
NULL
,
sleep
,
args
));
if
(
_sleep_ms
>
20
)
_sleep_ms
-=
20
;
}
return
brpc
::
RedisCommandHandler
::
OK
;
}
RedisCommandHandler
*
New
()
{
_new_count
++
;
return
new
GetCommandHandler
(
_
rand_
sleep
);
}
RedisCommandHandler
*
New
()
{
_new_count
++
;
return
new
GetCommandHandler
(
_sleep
);
}
int
new_count
()
{
return
_new_count
;
}
private
:
int
_sleep_ms
=
100
;
int
_new_count
=
0
;
bool
_
rand_
sleep
=
false
;
bool
_sleep
=
false
;
};
class
IncrCommandHandler
:
public
brpc
::
RedisCommandHandler
{
public
:
IncrCommandHandler
(
bool
rand_
sleep
=
false
)
:
_
rand_sleep
(
rand_
sleep
)
{}
IncrCommandHandler
(
bool
sleep
=
false
)
:
_
sleep
(
sleep
)
{}
brpc
::
RedisCommandHandler
::
Result
Run
(
const
char
*
args
[],
brpc
::
RedisMessage
*
output
,
...
...
@@ -745,18 +759,23 @@ public:
value
=
++
int_map
[
args
[
1
]];
s_mutex
.
unlock
();
output
->
SetInteger
(
value
);
if
(
_rand_sleep
)
{
if
(
_sleep
)
{
SleepArgs
*
args
=
new
SleepArgs
;
args
->
sleep_ms
=
_sleep_ms
;
args
->
done
=
done_guard
.
release
();
bthread_t
bth
;
bthread_start_background
(
&
bth
,
NULL
,
random_sleep
,
done_guard
.
release
());
EXPECT_EQ
(
0
,
bthread_start_background
(
&
bth
,
NULL
,
sleep
,
args
));
if
(
_sleep_ms
>
20
)
_sleep_ms
-=
20
;
}
return
brpc
::
RedisCommandHandler
::
OK
;
}
RedisCommandHandler
*
New
()
{
_new_count
++
;
return
new
IncrCommandHandler
(
_
rand_
sleep
);
}
RedisCommandHandler
*
New
()
{
_new_count
++
;
return
new
IncrCommandHandler
(
_sleep
);
}
int
new_count
()
{
return
_new_count
;
}
private
:
int
_sleep_ms
=
100
;
int
_new_count
=
0
;
bool
_
rand_
sleep
=
false
;
bool
_sleep
=
false
;
};
class
RedisServiceImpl
:
public
brpc
::
RedisService
{
};
...
...
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