Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
613831f8
Commit
613831f8
authored
Dec 07, 2017
by
Dvir Volk
Browse files
Fix indentation and comment style in testmodule
parent
f27a6423
Changes
1
Show whitespace changes
Inline
Side-by-side
src/modules/testmodule.c
View file @
613831f8
...
@@ -125,6 +125,7 @@ int failTest(RedisModuleCtx *ctx, const char *msg) {
...
@@ -125,6 +125,7 @@ int failTest(RedisModuleCtx *ctx, const char *msg) {
RedisModule_ReplyWithError
(
ctx
,
msg
);
RedisModule_ReplyWithError
(
ctx
,
msg
);
return
REDISMODULE_ERR
;
return
REDISMODULE_ERR
;
}
}
int
TestUnlink
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
int
TestUnlink
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
RedisModule_AutoMemory
(
ctx
);
RedisModule_AutoMemory
(
ctx
);
REDISMODULE_NOT_USED
(
argv
);
REDISMODULE_NOT_USED
(
argv
);
...
@@ -154,10 +155,12 @@ int TestUnlink(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
...
@@ -154,10 +155,12 @@ int TestUnlink(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
}
}
int
NotifyCallback
(
RedisModuleCtx
*
ctx
,
int
type
,
const
char
*
event
,
RedisModuleString
*
key
)
{
int
NotifyCallback
(
RedisModuleCtx
*
ctx
,
int
type
,
const
char
*
event
,
// Increment a counter on the notifications:
RedisModuleString
*
key
)
{
// for each key notified we increment a counter
/* Increment a counter on the notifications: for each key notified we
RedisModule_Log
(
ctx
,
"notice"
,
"Got event type %d, event %s, key %s"
,
type
,
event
,
RedisModule_StringPtrLen
(
key
,
NULL
));
* increment a counter */
RedisModule_Log
(
ctx
,
"notice"
,
"Got event type %d, event %s, key %s"
,
type
,
event
,
RedisModule_StringPtrLen
(
key
,
NULL
));
RedisModule_Call
(
ctx
,
"HINCRBY"
,
"csc"
,
"notifications"
,
key
,
"1"
);
RedisModule_Call
(
ctx
,
"HINCRBY"
,
"csc"
,
"notifications"
,
key
,
"1"
);
return
REDISMODULE_OK
;
return
REDISMODULE_OK
;
...
@@ -170,8 +173,7 @@ int TestNotifications(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
...
@@ -170,8 +173,7 @@ int TestNotifications(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
#define FAIL(msg, ...) \
#define FAIL(msg, ...) \
{ \
{ \
RedisModule_Log(ctx, "warning", "Failed NOTIFY Test. Reason: " #msg, \
RedisModule_Log(ctx, "warning", "Failed NOTIFY Test. Reason: " #msg, ##__VA_ARGS__); \
##__VA_ARGS__); \
goto err; \
goto err; \
}
}
RedisModule_Call
(
ctx
,
"FLUSHDB"
,
""
);
RedisModule_Call
(
ctx
,
"FLUSHDB"
,
""
);
...
@@ -182,21 +184,19 @@ int TestNotifications(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
...
@@ -182,21 +184,19 @@ int TestNotifications(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
RedisModule_Call
(
ctx
,
"SADD"
,
"cc"
,
"bar"
,
"y"
);
RedisModule_Call
(
ctx
,
"SADD"
,
"cc"
,
"bar"
,
"y"
);
RedisModule_Call
(
ctx
,
"HSET"
,
"ccc"
,
"baz"
,
"x"
,
"y"
);
RedisModule_Call
(
ctx
,
"HSET"
,
"ccc"
,
"baz"
,
"x"
,
"y"
);
//
LPUSH should be ignored and not increment any counters
/*
LPUSH should be ignored and not increment any counters
*/
RedisModule_Call
(
ctx
,
"LPUSH"
,
"cc"
,
"l"
,
"y"
);
RedisModule_Call
(
ctx
,
"LPUSH"
,
"cc"
,
"l"
,
"y"
);
RedisModule_Call
(
ctx
,
"LPUSH"
,
"cc"
,
"l"
,
"y"
);
RedisModule_Call
(
ctx
,
"LPUSH"
,
"cc"
,
"l"
,
"y"
);
size_t
sz
;
size_t
sz
;
const
char
*
rep
;
const
char
*
rep
;
RedisModuleCallReply
*
r
=
RedisModuleCallReply
*
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"foo"
);
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"foo"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_STRING
)
{
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_STRING
)
{
FAIL
(
"Wrong or no reply for foo"
);
FAIL
(
"Wrong or no reply for foo"
);
}
else
{
}
else
{
rep
=
RedisModule_CallReplyStringPtr
(
r
,
&
sz
);
rep
=
RedisModule_CallReplyStringPtr
(
r
,
&
sz
);
if
(
sz
!=
1
||
*
rep
!=
'2'
)
{
if
(
sz
!=
1
||
*
rep
!=
'2'
)
{
FAIL
(
"Got reply '%s'. expected '2'"
,
FAIL
(
"Got reply '%s'. expected '2'"
,
RedisModule_CallReplyStringPtr
(
r
,
NULL
));
RedisModule_CallReplyStringPtr
(
r
,
NULL
));
}
}
}
}
...
@@ -219,7 +219,7 @@ int TestNotifications(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
...
@@ -219,7 +219,7 @@ int TestNotifications(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
FAIL
(
"Got reply '%.*s'. expected '1'"
,
sz
,
rep
);
FAIL
(
"Got reply '%.*s'. expected '1'"
,
sz
,
rep
);
}
}
}
}
// f
or l we expect nothing since we didn't subscribe to list events
/* F
or l we expect nothing since we didn't subscribe to list events
*/
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"l"
);
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"l"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_NULL
)
{
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_NULL
)
{
FAIL
(
"Wrong reply for l"
);
FAIL
(
"Wrong reply for l"
);
...
@@ -243,8 +243,8 @@ int TestCtxFlags(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
...
@@ -243,8 +243,8 @@ int TestCtxFlags(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
int
ok
=
1
;
int
ok
=
1
;
const
char
*
errString
=
NULL
;
const
char
*
errString
=
NULL
;
#undef FAIL
#undef FAIL
#define FAIL(msg) \
#define FAIL(msg)
\
{ \
{ \
ok = 0; \
ok = 0; \
errString = msg; \
errString = msg; \
...
@@ -263,15 +263,13 @@ int TestCtxFlags(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
...
@@ -263,15 +263,13 @@ int TestCtxFlags(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
/* Enable AOF to test AOF flags */
/* Enable AOF to test AOF flags */
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"appendonly"
,
"yes"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"appendonly"
,
"yes"
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_AOF
))
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_AOF
))
FAIL
(
"AOF Flag not set after config set"
);
FAIL
(
"AOF Flag not set after config set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_RDB
)
FAIL
(
"RDB Flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_RDB
)
FAIL
(
"RDB Flag was set"
);
/* Enable RDB to test RDB flags */
/* Enable RDB to test RDB flags */
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"save"
,
"900 1"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"save"
,
"900 1"
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_RDB
))
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_RDB
))
FAIL
(
"RDB Flag was not set after config set"
);
FAIL
(
"RDB Flag was not set after config set"
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_MASTER
))
FAIL
(
"Master flag was not set"
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_MASTER
))
FAIL
(
"Master flag was not set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_SLAVE
)
FAIL
(
"Slave flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_SLAVE
)
FAIL
(
"Slave flag was set"
);
...
@@ -279,20 +277,18 @@ int TestCtxFlags(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
...
@@ -279,20 +277,18 @@ int TestCtxFlags(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
if
(
flags
&
REDISMODULE_CTX_FLAGS_CLUSTER
)
FAIL
(
"Cluster flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_CLUSTER
)
FAIL
(
"Cluster flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_MAXMEMORY
)
FAIL
(
"Maxmemory flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_MAXMEMORY
)
FAIL
(
"Maxmemory flag was set"
);
;
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory"
,
"100000000"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory"
,
"100000000"
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_MAXMEMORY
))
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_MAXMEMORY
))
FAIL
(
"Maxmemory flag was not set after config set"
);
FAIL
(
"Maxmemory flag was not set after config set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_EVICT
)
FAIL
(
"Eviction flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_EVICT
)
FAIL
(
"Eviction flag was set"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory-policy"
,
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory-policy"
,
"allkeys-lru"
);
"allkeys-lru"
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_EVICT
))
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_EVICT
))
FAIL
(
"Eviction flag was not set after config set"
);
FAIL
(
"Eviction flag was not set after config set"
);
end:
end:
/* Revert config changes */
/* Revert config changes */
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"appendonly"
,
"no"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"appendonly"
,
"no"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"save"
,
""
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"save"
,
""
);
...
@@ -300,14 +296,12 @@ int TestCtxFlags(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
...
@@ -300,14 +296,12 @@ int TestCtxFlags(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory-policy"
,
"noeviction"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory-policy"
,
"noeviction"
);
if
(
!
ok
)
{
if
(
!
ok
)
{
RedisModule_Log
(
ctx
,
"warning"
,
"Failed CTXFLAGS Test. Reason: %s"
,
RedisModule_Log
(
ctx
,
"warning"
,
"Failed CTXFLAGS Test. Reason: %s"
,
errString
);
errString
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"ERR"
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"ERR"
);
}
}
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"OK"
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"OK"
);
}
}
/* ----------------------------- Test framework ----------------------------- */
/* ----------------------------- Test framework ----------------------------- */
...
...
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