First commit
This commit is contained in:
37
setup/dbaas/redismodule/tst/include/ut_helpers.hpp
Normal file
37
setup/dbaas/redismodule/tst/include/ut_helpers.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
#ifndef EXSTRING_UT_HELPERS_H_
|
||||
#define EXSTRING_UT_HELPERS_H_
|
||||
|
||||
extern "C" {
|
||||
#include "exstringsStub.h"
|
||||
#include "redismodule.h"
|
||||
}
|
||||
|
||||
#define UT_DUMMY_BUFFER_SIZE 1
|
||||
#define UT_DUMMY_PTR_ADDRESS 1234
|
||||
|
||||
RedisModuleString **createRedisStrVec(size_t size);
|
||||
|
||||
void returnNKeysFromScanSome(long keys);
|
||||
|
||||
#endif
|
37
setup/dbaas/redismodule/tst/mock/include/commonStub.h
Normal file
37
setup/dbaas/redismodule/tst/mock/include/commonStub.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
#ifndef COMMONSTUB_H_
|
||||
#define COMMONSTUB_H_
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#define UT_DUMMY_THREAD_ID 1234
|
||||
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine) (void *), void *arg);
|
||||
|
||||
int pthread_detach(pthread_t thread);
|
||||
|
||||
pthread_t pthread_self(void);
|
||||
|
||||
#endif
|
53
setup/dbaas/redismodule/tst/mock/include/exstringsStub.h
Executable file
53
setup/dbaas/redismodule/tst/mock/include/exstringsStub.h
Executable file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
#ifndef EXSTRINGSTUB_H_
|
||||
#define EXSTRINGSTUB_H_
|
||||
|
||||
|
||||
#include "redismodule.h"
|
||||
|
||||
int setStringGenericCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, const int flag);
|
||||
int SetIE_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int SetNE_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) ;
|
||||
int delStringGenericCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, const int flag);
|
||||
int DelIE_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int DelNE_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int SetPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int SetMPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int SetIEPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int SetIEMPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int SetNEPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int SetNXPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int SetNXMPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int SetXXPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int DelPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int DelMPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int DelIEPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int DelIEMPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int DelNEPub_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int NDel_Atomic_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int NGet_Atomic_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
int NGet_NoAtomic_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
void *NGet_NoAtomic_ThreadMain(void *arg);
|
||||
|
||||
#endif
|
126
setup/dbaas/redismodule/tst/mock/include/redismodule.h
Executable file
126
setup/dbaas/redismodule/tst/mock/include/redismodule.h
Executable file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
#ifndef REDISMODULE_H
|
||||
#define REDISMODULE_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Error status return values. */
|
||||
#define REDISMODULE_OK 0
|
||||
#define REDISMODULE_ERR 1
|
||||
|
||||
/* API versions. */
|
||||
#define REDISMODULE_APIVER_1 1
|
||||
|
||||
/* API flags and constants */
|
||||
#define REDISMODULE_READ (1<<0)
|
||||
#define REDISMODULE_WRITE (1<<1)
|
||||
|
||||
/* Key types. */
|
||||
#define REDISMODULE_KEYTYPE_EMPTY 0
|
||||
#define REDISMODULE_KEYTYPE_STRING 1
|
||||
#define REDISMODULE_KEYTYPE_LIST 2
|
||||
#define REDISMODULE_KEYTYPE_HASH 3
|
||||
#define REDISMODULE_KEYTYPE_SET 4
|
||||
#define REDISMODULE_KEYTYPE_ZSET 5
|
||||
#define REDISMODULE_KEYTYPE_MODULE 6
|
||||
|
||||
/* Reply types. */
|
||||
#define REDISMODULE_REPLY_UNKNOWN -1
|
||||
#define REDISMODULE_REPLY_STRING 0
|
||||
#define REDISMODULE_REPLY_ERROR 1
|
||||
#define REDISMODULE_REPLY_INTEGER 2
|
||||
#define REDISMODULE_REPLY_ARRAY 3
|
||||
#define REDISMODULE_REPLY_NULL 4
|
||||
|
||||
/* Postponed array length. */
|
||||
#define REDISMODULE_POSTPONED_ARRAY_LEN -1
|
||||
|
||||
/* Error messages. */
|
||||
#define REDISMODULE_ERRORMSG_WRONGTYPE "WRONGTYPE Operation against a key holding the wrong kind of value"
|
||||
|
||||
#define REDISMODULE_NOT_USED(V) ((void) V)
|
||||
|
||||
typedef long long mstime_t;
|
||||
|
||||
/* UT dummy definitions for opaque redis types */
|
||||
typedef struct { int dummy; } RedisModuleCtx;
|
||||
typedef struct { int dummy; } RedisModuleKey;
|
||||
typedef struct { int dummy; } RedisModuleString;
|
||||
typedef struct { int dummy; } RedisModuleCallReply;
|
||||
typedef struct { int dummy; } RedisModuleIO;
|
||||
typedef struct { int dummy; } RedisModuleType;
|
||||
typedef struct { int dummy; } RedisModuleDigest;
|
||||
typedef struct { int dummy; } RedisModuleBlockedClient;
|
||||
|
||||
typedef void *(*RedisModuleTypeLoadFunc)(RedisModuleIO *rdb, int encver);
|
||||
typedef void (*RedisModuleTypeSaveFunc)(RedisModuleIO *rdb, void *value);
|
||||
typedef void (*RedisModuleTypeRewriteFunc)(RedisModuleIO *aof, RedisModuleString *key, void *value);
|
||||
typedef size_t (*RedisModuleTypeMemUsageFunc)(const void *value);
|
||||
typedef void (*RedisModuleTypeDigestFunc)(RedisModuleDigest *digest, void *value);
|
||||
typedef void (*RedisModuleTypeFreeFunc)(void *value);
|
||||
|
||||
typedef int (*RedisModuleCmdFunc) (RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
||||
|
||||
int RedisModule_CreateCommand(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc cmdfunc, const char *strflags, int firstkey, int lastkey, int keystep);
|
||||
int RedisModule_WrongArity(RedisModuleCtx *ctx);
|
||||
int RedisModule_ReplyWithLongLong(RedisModuleCtx *ctx, long long ll);
|
||||
void *RedisModule_OpenKey(RedisModuleCtx *ctx, RedisModuleString *keyname, int mode);
|
||||
RedisModuleCallReply *RedisModule_Call(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...);
|
||||
void RedisModule_FreeCallReply(RedisModuleCallReply *reply);
|
||||
int RedisModule_CallReplyType(RedisModuleCallReply *reply);
|
||||
long long RedisModule_CallReplyInteger(RedisModuleCallReply *reply);
|
||||
const char *RedisModule_StringPtrLen(const RedisModuleString *str, size_t *len);
|
||||
int RedisModule_ReplyWithError(RedisModuleCtx *ctx, const char *err);
|
||||
int RedisModule_ReplyWithString(RedisModuleCtx *ctx, RedisModuleString *str);
|
||||
int RedisModule_ReplyWithNull(RedisModuleCtx *ctx);
|
||||
int RedisModule_ReplyWithCallReply(RedisModuleCtx *ctx, RedisModuleCallReply *reply);
|
||||
const char *RedisModule_CallReplyStringPtr(RedisModuleCallReply *reply, size_t *len);
|
||||
RedisModuleString *RedisModule_CreateStringFromCallReply(RedisModuleCallReply *reply);
|
||||
|
||||
int RedisModule_KeyType(RedisModuleKey *kp);
|
||||
void RedisModule_CloseKey(RedisModuleKey *kp);
|
||||
|
||||
int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver);
|
||||
|
||||
size_t RedisModule_CallReplyLength(RedisModuleCallReply *reply);
|
||||
RedisModuleCallReply *RedisModule_CallReplyArrayElement(RedisModuleCallReply *reply, size_t idx);
|
||||
int RedisModule_ReplyWithArray(RedisModuleCtx *ctx, long len);
|
||||
void RedisModule_FreeString(RedisModuleCtx *ctx, RedisModuleString *str);
|
||||
RedisModuleBlockedClient *RedisModule_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(RedisModuleCtx*,void*), long long timeout_ms);
|
||||
int RedisModule_UnblockClient(RedisModuleBlockedClient *bc, void *privdata);
|
||||
int RedisModule_AbortBlock(RedisModuleBlockedClient *bc);
|
||||
RedisModuleString *RedisModule_CreateString(RedisModuleCtx *ctx, const char *ptr, size_t len);
|
||||
void RedisModule_FreeThreadSafeContext(RedisModuleCtx *ctx);
|
||||
int RedisModule_StringToLongLong(const RedisModuleString *str, long long *ll);
|
||||
void RedisModule_ThreadSafeContextLock(RedisModuleCtx *ctx);
|
||||
void RedisModule_ThreadSafeContextUnlock(RedisModuleCtx *ctx);
|
||||
void RedisModule_ReplySetArrayLength(RedisModuleCtx *ctx, long len);
|
||||
RedisModuleCtx *RedisModule_GetThreadSafeContext(RedisModuleBlockedClient *bc);
|
||||
RedisModuleString *RedisModule_CreateStringFromLongLong(RedisModuleCtx *ctx, long long ll);
|
||||
void RedisModule_AutoMemory(RedisModuleCtx *ctx);
|
||||
void *RedisModule_Alloc(size_t bytes);
|
||||
void RedisModule_Free(void *ptr);
|
||||
|
||||
#endif /* REDISMODULE_H */
|
76
setup/dbaas/redismodule/tst/mock/src/commonStub.cpp
Normal file
76
setup/dbaas/redismodule/tst/mock/src/commonStub.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
extern "C" {
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "redismodule.h"
|
||||
#include "commonStub.h"
|
||||
}
|
||||
|
||||
#include <CppUTest/TestHarness.h>
|
||||
#include <CppUTestExt/MockSupport.h>
|
||||
#include <CppUTest/MemoryLeakDetectorMallocMacros.h>
|
||||
|
||||
typedef struct RedisModuleBlockedClientArgs {
|
||||
RedisModuleBlockedClient *bc;
|
||||
RedisModuleString **argv;
|
||||
int argc;
|
||||
} RedisModuleBlockedClientArgs;
|
||||
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine) (void *), void *arg)
|
||||
{
|
||||
(void)thread;
|
||||
(void)attr;
|
||||
(void)start_routine;
|
||||
if (mock().getData("pthread_create_free_block_client_args").getIntValue()) {
|
||||
RedisModuleBlockedClientArgs* bca = (RedisModuleBlockedClientArgs*)arg;
|
||||
free(bca->bc);
|
||||
free(bca);
|
||||
}
|
||||
|
||||
return mock()
|
||||
.actualCall("pthread_create")
|
||||
.returnIntValueOrDefault(0);
|
||||
}
|
||||
|
||||
int pthread_detach(pthread_t thread)
|
||||
{
|
||||
(void)thread;
|
||||
|
||||
return mock()
|
||||
.actualCall("pthread_detach")
|
||||
.returnIntValueOrDefault(0);
|
||||
}
|
||||
|
||||
pthread_t pthread_self(void)
|
||||
{
|
||||
return mock()
|
||||
.actualCall("pthread_self")
|
||||
.returnIntValueOrDefault(UT_DUMMY_THREAD_ID);
|
||||
}
|
360
setup/dbaas/redismodule/tst/mock/src/redismoduleNewStub.cpp
Executable file
360
setup/dbaas/redismodule/tst/mock/src/redismoduleNewStub.cpp
Executable file
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
extern "C" {
|
||||
#include "redismodule.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
}
|
||||
|
||||
#include <CppUTest/TestHarness.h>
|
||||
#include <CppUTestExt/MockSupport.h>
|
||||
|
||||
#include "ut_helpers.hpp"
|
||||
|
||||
RedisModuleCallReply *RedisModule_Call(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)fmt;
|
||||
return (RedisModuleCallReply *)mock().actualCall("RedisModule_Call")
|
||||
.withParameter("cmdname", cmdname)
|
||||
.returnPointerValueOrDefault(malloc(UT_DUMMY_BUFFER_SIZE));
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithString(RedisModuleCtx *ctx, RedisModuleString *str)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)str;
|
||||
return mock()
|
||||
.actualCall("RedisModule_ReplyWithString")
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
RedisModuleString *RedisModule_CreateStringFromCallReply(RedisModuleCallReply *reply)
|
||||
{
|
||||
(void)reply;
|
||||
return (RedisModuleString *)mock().actualCall("RedisModule_CreateStringFromCallReply")
|
||||
.returnPointerValue();
|
||||
}
|
||||
|
||||
void RedisModule_CloseKey(RedisModuleKey *kp)
|
||||
{
|
||||
(void)kp;
|
||||
mock().actualCall("RedisModule_CloseKey");
|
||||
}
|
||||
|
||||
size_t RedisModule_CallReplyLength(RedisModuleCallReply *reply)
|
||||
{
|
||||
(void)reply;
|
||||
return (size_t)mock().actualCall("RedisModule_CallReplyLength")
|
||||
.returnIntValue();
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithArray(RedisModuleCtx *ctx, long len)
|
||||
{
|
||||
(void)ctx;
|
||||
return (int)mock().actualCall("RedisModule_ReplyWithArray")
|
||||
.withParameter("len", len)
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
void RedisModule_ReplySetArrayLength(RedisModuleCtx *ctx, long len)
|
||||
{
|
||||
(void)ctx;
|
||||
mock().actualCall("RedisModule_ReplySetArrayLength")
|
||||
.withParameter("len", len);
|
||||
}
|
||||
|
||||
RedisModuleString *RedisModule_CreateString(RedisModuleCtx *ctx, const char *ptr, size_t len)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)ptr;
|
||||
(void)len;
|
||||
void* buf = malloc(UT_DUMMY_BUFFER_SIZE);
|
||||
return (RedisModuleString *) mock()
|
||||
.actualCall("RedisModule_CreateString")
|
||||
.returnPointerValueOrDefault(buf);
|
||||
}
|
||||
|
||||
RedisModuleString *RedisModule_CreateStringFromLongLong(RedisModuleCtx *ctx, long long ll)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)ll;
|
||||
void* buf = malloc(UT_DUMMY_BUFFER_SIZE);
|
||||
return (RedisModuleString *)mock()
|
||||
.actualCall("RedisModule_CreateStringFromLongLong")
|
||||
.returnPointerValueOrDefault(buf);
|
||||
}
|
||||
|
||||
void RedisModule_AutoMemory(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
mock().actualCall("RedisModule_AutoMemory");
|
||||
}
|
||||
|
||||
void RedisModule_FreeString(RedisModuleCtx *ctx, RedisModuleString *str)
|
||||
{
|
||||
(void)ctx;
|
||||
free(str);
|
||||
mock().actualCall("RedisModule_FreeString");
|
||||
}
|
||||
|
||||
int RedisModule_StringToLongLong(const RedisModuleString *str, long long *ll)
|
||||
{
|
||||
(void)str;
|
||||
return (int)mock().actualCall("RedisModule_StringToLongLong")
|
||||
.withOutputParameter("ll", ll)
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
void RedisModule_FreeCallReply(RedisModuleCallReply *reply)
|
||||
{
|
||||
free(reply);
|
||||
mock().actualCall("RedisModule_FreeCallReply");
|
||||
}
|
||||
|
||||
RedisModuleCallReply *RedisModule_CallReplyArrayElement(RedisModuleCallReply *reply, size_t idx)
|
||||
{
|
||||
(void)reply;
|
||||
(void)idx;
|
||||
return (RedisModuleCallReply *)mock()
|
||||
.actualCall("RedisModule_CallReplyArrayElement")
|
||||
.returnPointerValueOrDefault(NULL);
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithLongLong(RedisModuleCtx *ctx, long long ll)
|
||||
{
|
||||
(void)ctx;
|
||||
return (int)mock()
|
||||
.actualCall("RedisModule_ReplyWithLongLong")
|
||||
.withParameter("ll", (int)ll)
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
long long RedisModule_CallReplyInteger(RedisModuleCallReply *reply)
|
||||
{
|
||||
(void)reply;
|
||||
return (long long)mock()
|
||||
.actualCall("RedisModule_CallReplyInteger")
|
||||
.returnIntValue();
|
||||
}
|
||||
|
||||
int RedisModule_CallReplyType(RedisModuleCallReply *reply)
|
||||
{
|
||||
(void)reply;
|
||||
return (int)mock()
|
||||
.actualCall("RedisModule_CallReplyType")
|
||||
.returnIntValue();
|
||||
}
|
||||
|
||||
int RedisModule_WrongArity(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
return (int)mock()
|
||||
.actualCall("RedisModule_WrongArity")
|
||||
.returnIntValueOrDefault(REDISMODULE_ERR);
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithError(RedisModuleCtx *ctx, const char *err)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)err;
|
||||
return (int)mock()
|
||||
.actualCall("RedisModule_ReplyWithError")
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithCallReply(RedisModuleCtx *ctx, RedisModuleCallReply *reply)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)reply;
|
||||
return (int)mock()
|
||||
.actualCall("RedisModule_ReplyWithCallReply")
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
void *RedisModule_OpenKey(RedisModuleCtx *ctx, RedisModuleString *keyname, int mode)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)keyname;
|
||||
(void)mode;
|
||||
return (void *)mock()
|
||||
.actualCall("RedisModule_OpenKey")
|
||||
.returnPointerValue();
|
||||
}
|
||||
|
||||
int RedisModule_KeyType(RedisModuleKey *kp)
|
||||
{
|
||||
(void)kp;
|
||||
return (int)mock()
|
||||
.actualCall("RedisModule_KeyType")
|
||||
.returnIntValue();
|
||||
}
|
||||
|
||||
const char *RedisModule_StringPtrLen(const RedisModuleString *str, size_t *len)
|
||||
{
|
||||
(void)str;
|
||||
if (len != NULL) {
|
||||
return (const char *)mock()
|
||||
.actualCall("RedisModule_StringPtrLen")
|
||||
.withOutputParameter("len", len)
|
||||
.returnPointerValue();
|
||||
} else {
|
||||
return (const char *)mock()
|
||||
.actualCall("RedisModule_StringPtrLen")
|
||||
.returnPointerValue();
|
||||
}
|
||||
}
|
||||
|
||||
RedisModuleBlockedClient *RedisModule_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback,
|
||||
RedisModuleCmdFunc timeout_callback,
|
||||
void (*free_privdata)(RedisModuleCtx*,void*),
|
||||
long long timeout_ms)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)reply_callback;
|
||||
(void)timeout_callback;
|
||||
(void)free_privdata;
|
||||
(void)timeout_ms;
|
||||
|
||||
void *buf = malloc(UT_DUMMY_BUFFER_SIZE);
|
||||
return (RedisModuleBlockedClient *)mock()
|
||||
.actualCall("RedisModule_BlockClient")
|
||||
.returnPointerValueOrDefault(buf);
|
||||
}
|
||||
|
||||
int RedisModule_UnblockClient(RedisModuleBlockedClient *bc, void *privdata)
|
||||
{
|
||||
(void)privdata;
|
||||
|
||||
free(bc);
|
||||
return (int)mock()
|
||||
.actualCall("RedisModule_UnblockClient")
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
const char *RedisModule_CallReplyStringPtr(RedisModuleCallReply *reply, size_t *len)
|
||||
{
|
||||
(void)reply;
|
||||
(void)len;
|
||||
|
||||
static char cursor_zero_literal[] = "0";
|
||||
return (const char *)mock()
|
||||
.actualCall("RedisModule_CallReplyStringPtr")
|
||||
.returnPointerValueOrDefault(cursor_zero_literal);
|
||||
}
|
||||
|
||||
int RedisModule_AbortBlock(RedisModuleBlockedClient *bc)
|
||||
{
|
||||
free(bc);
|
||||
return mock()
|
||||
.actualCall("RedisModule_AbortBlock")
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithNull(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
return mock()
|
||||
.actualCall("RedisModule_ReplyWithNull")
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
void RedisModule_ThreadSafeContextUnlock(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
int tmp = mock().getData("TimesThreadSafeContextWasUnlocked").getIntValue();
|
||||
mock().setData("TimesThreadSafeContextWasUnlocked", tmp + 1);
|
||||
mock()
|
||||
.actualCall("RedisModule_ThreadSafeContextUnlock");
|
||||
}
|
||||
|
||||
void RedisModule_ThreadSafeContextLock(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
int tmp = mock().getData("TimesThreadSafeContextWasLocked").getIntValue();
|
||||
mock().setData("TimesThreadSafeContextWasLocked", tmp + 1);
|
||||
mock()
|
||||
.actualCall("RedisModule_ThreadSafeContextLock");
|
||||
}
|
||||
|
||||
RedisModuleCtx *RedisModule_GetThreadSafeContext(RedisModuleBlockedClient *bc)
|
||||
{
|
||||
(void)bc;
|
||||
return (RedisModuleCtx *)mock()
|
||||
.actualCall("RedisModule_GetThreadSafeContext")
|
||||
.returnPointerValueOrDefault(0);
|
||||
}
|
||||
|
||||
void RedisModule_FreeThreadSafeContext(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
mock()
|
||||
.actualCall("RedisModule_FreeThreadSafeContext");
|
||||
}
|
||||
|
||||
/* This is included inline inside each Redis module. */
|
||||
int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)name;
|
||||
(void)ver;
|
||||
(void)apiver;
|
||||
|
||||
return mock()
|
||||
.actualCall("RedisModule_Init")
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
int RedisModule_CreateCommand(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc cmdfunc, const char *strflags, int firstkey, int lastkey, int keystep)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)name;
|
||||
(void)cmdfunc;
|
||||
(void)strflags;
|
||||
(void)firstkey;
|
||||
(void)lastkey;
|
||||
(void)keystep;
|
||||
|
||||
return mock()
|
||||
.actualCall("RedisModule_CreateCommand")
|
||||
.returnIntValueOrDefault(REDISMODULE_OK);
|
||||
}
|
||||
|
||||
void *RedisModule_Alloc(size_t bytes)
|
||||
{
|
||||
void *buf = malloc(bytes);
|
||||
return mock()
|
||||
.actualCall("RedisModule_Alloc")
|
||||
.returnPointerValueOrDefault(buf);
|
||||
}
|
||||
|
||||
void RedisModule_Free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
mock()
|
||||
.actualCall("RedisModule_Free");
|
||||
}
|
437
setup/dbaas/redismodule/tst/mock/src/redismoduleStub.cpp
Executable file
437
setup/dbaas/redismodule/tst/mock/src/redismoduleStub.cpp
Executable file
@@ -0,0 +1,437 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
extern "C" {
|
||||
#include "redismodule.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
}
|
||||
|
||||
#include <CppUTest/TestHarness.h>
|
||||
#include <CppUTestExt/MockSupport.h>
|
||||
|
||||
|
||||
int RedisModule_CreateCommand(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc cmdfunc, const char *strflags, int firstkey, int lastkey, int keystep)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)name;
|
||||
(void)cmdfunc;
|
||||
(void)strflags;
|
||||
(void)firstkey;
|
||||
(void)lastkey;
|
||||
(void)keystep;
|
||||
return REDISMODULE_OK;
|
||||
|
||||
}
|
||||
|
||||
int RedisModule_WrongArity(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
mock().setData("RedisModule_WrongArity", 1);
|
||||
return REDISMODULE_ERR;
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithLongLong(RedisModuleCtx *ctx, long long ll)
|
||||
{
|
||||
|
||||
(void)ctx;
|
||||
mock().setData("RedisModule_ReplyWithLongLong", (int)ll);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
void *RedisModule_OpenKey(RedisModuleCtx *ctx, RedisModuleString *keyname, int mode)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)keyname;
|
||||
(void)mode;
|
||||
|
||||
if (mock().hasData("RedisModule_OpenKey_no"))
|
||||
{
|
||||
return (void*)(0);
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_OpenKey_have"))
|
||||
{
|
||||
return (void*)(111111);
|
||||
}
|
||||
|
||||
|
||||
return (void*)(0);
|
||||
}
|
||||
|
||||
RedisModuleCallReply *RedisModule_Call(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)cmdname;
|
||||
(void)fmt;
|
||||
|
||||
if (!strcmp(cmdname, "GET"))
|
||||
mock().setData("GET", 1);
|
||||
else if (!strcmp(cmdname, "SET"))
|
||||
mock().setData("SET", 1);
|
||||
else if (!strcmp(cmdname, "MSET"))
|
||||
mock().setData("MSET", 1);
|
||||
else if (!strcmp(cmdname, "DEL"))
|
||||
mock().setData("DEL", 1);
|
||||
else if (!strcmp(cmdname, "UNLINK"))
|
||||
mock().setData("UNLINK", 1);
|
||||
else if (!strcmp(cmdname, "PUBLISH"))
|
||||
mock().setData("PUBLISH", mock().getData("PUBLISH").getIntValue() + 1);
|
||||
else if (!strcmp(cmdname, "KEYS"))
|
||||
mock().setData("KEYS", 1);
|
||||
else if (!strcmp(cmdname, "MGET"))
|
||||
mock().setData("MGET", 1);
|
||||
else if (!strcmp(cmdname, "SCAN"))
|
||||
mock().setData("SCAN", 1);
|
||||
|
||||
if (mock().hasData("RedisModule_Call_Return_Null"))
|
||||
return NULL;
|
||||
else
|
||||
return (RedisModuleCallReply *)1;
|
||||
}
|
||||
|
||||
void RedisModule_FreeCallReply(RedisModuleCallReply *reply)
|
||||
{
|
||||
(void)reply;
|
||||
mock().setData("RedisModule_FreeCallReply", mock().getData("RedisModule_FreeCallReply").getIntValue()+1);
|
||||
}
|
||||
|
||||
int RedisModule_CallReplyType(RedisModuleCallReply *reply)
|
||||
{
|
||||
|
||||
(void)reply;
|
||||
if (mock().hasData("RedisModule_CallReplyType_null"))
|
||||
{
|
||||
return REDISMODULE_REPLY_NULL;
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_CallReplyType_inter"))
|
||||
{
|
||||
return REDISMODULE_REPLY_INTEGER;
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_CallReplyType_str"))
|
||||
{
|
||||
return REDISMODULE_REPLY_STRING;
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_CallReplyType_err"))
|
||||
{
|
||||
return REDISMODULE_REPLY_ERROR;
|
||||
}
|
||||
|
||||
return REDISMODULE_REPLY_NULL;;
|
||||
|
||||
}
|
||||
|
||||
long long RedisModule_CallReplyInteger(RedisModuleCallReply *reply)
|
||||
{
|
||||
|
||||
(void)reply;
|
||||
return mock().getData("RedisModule_CallReplyInteger").getIntValue();
|
||||
}
|
||||
|
||||
const char *RedisModule_StringPtrLen(const RedisModuleString *str, size_t *len)
|
||||
{
|
||||
|
||||
(void)str;
|
||||
if (len) *len = 5;
|
||||
if (mock().hasData("RedisModule_String_same"))
|
||||
{
|
||||
return "11111";
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_String_nosame"))
|
||||
{
|
||||
return "22222";
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_String_count"))
|
||||
{
|
||||
return "COUNT";
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_String_count1"))
|
||||
{
|
||||
if (len) *len = 6;
|
||||
return "COUNT1";
|
||||
}
|
||||
|
||||
return "11111";
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithError(RedisModuleCtx *ctx, const char *err)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)err;
|
||||
mock().setData("RedisModule_ReplyWithError", 1);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithString(RedisModuleCtx *ctx, RedisModuleString *str)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)str;
|
||||
mock().setData("RedisModule_ReplyWithString", mock().getData("RedisModule_ReplyWithString").getIntValue()+1);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithNull(RedisModuleCtx *ctx)
|
||||
{
|
||||
|
||||
(void)ctx;
|
||||
mock().setData("RedisModule_ReplyWithNull", 1);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithCallReply(RedisModuleCtx *ctx, RedisModuleCallReply *reply)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)reply;
|
||||
mock().setData("RedisModule_ReplyWithCallReply", 1);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
const char *RedisModule_CallReplyStringPtr(RedisModuleCallReply *reply, size_t *len)
|
||||
{
|
||||
(void)reply;
|
||||
|
||||
if (mock().hasData("RedisModule_String_same"))
|
||||
{
|
||||
if (len)
|
||||
*len = 5;
|
||||
return "11111";
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_String_nosame"))
|
||||
{
|
||||
if (len)
|
||||
*len = 6;
|
||||
return "333333";
|
||||
}
|
||||
|
||||
return "11111";
|
||||
}
|
||||
|
||||
RedisModuleString *RedisModule_CreateStringFromCallReply(RedisModuleCallReply *reply)
|
||||
{
|
||||
(void)reply;
|
||||
return (RedisModuleString *)1;
|
||||
}
|
||||
|
||||
|
||||
int RedisModule_KeyType(RedisModuleKey *kp)
|
||||
{
|
||||
|
||||
|
||||
(void)kp;
|
||||
if (mock().hasData("RedisModule_KeyType_empty"))
|
||||
{
|
||||
return REDISMODULE_KEYTYPE_EMPTY;
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_KeyType_str"))
|
||||
{
|
||||
return REDISMODULE_KEYTYPE_STRING;
|
||||
}
|
||||
|
||||
if (mock().hasData("RedisModule_KeyType_set"))
|
||||
{
|
||||
|
||||
return REDISMODULE_KEYTYPE_SET;
|
||||
}
|
||||
|
||||
return REDISMODULE_KEYTYPE_EMPTY;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RedisModule_CloseKey(RedisModuleKey *kp)
|
||||
{
|
||||
(void)kp;
|
||||
mock().actualCall("RedisModule_CloseKey");
|
||||
}
|
||||
|
||||
/* This is included inline inside each Redis module. */
|
||||
int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)name;
|
||||
(void)ver;
|
||||
(void)apiver;
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
size_t RedisModule_CallReplyLength(RedisModuleCallReply *reply)
|
||||
{
|
||||
(void)reply;
|
||||
return mock().getData("RedisModule_CallReplyLength").getIntValue();
|
||||
}
|
||||
|
||||
|
||||
RedisModuleCallReply *RedisModule_CallReplyArrayElement(RedisModuleCallReply *reply, size_t idx)
|
||||
{
|
||||
(void)reply;
|
||||
(void)idx;
|
||||
return (RedisModuleCallReply *)1;
|
||||
}
|
||||
|
||||
int RedisModule_ReplyWithArray(RedisModuleCtx *ctx, long len)
|
||||
{
|
||||
(void)ctx;
|
||||
mock().setData("RedisModule_ReplyWithArray", (int)len);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
void RedisModule_FreeString(RedisModuleCtx *ctx, RedisModuleString *str)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)str;
|
||||
mock().setData("RedisModule_FreeString", mock().getData("RedisModule_FreeString").getIntValue()+1);
|
||||
return;
|
||||
}
|
||||
|
||||
RedisModuleBlockedClient *RedisModule_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(RedisModuleCtx*,void*), long long timeout_ms)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)reply_callback;
|
||||
(void)timeout_callback;
|
||||
(void)free_privdata;
|
||||
(void)timeout_ms;
|
||||
RedisModuleBlockedClient *bc = (RedisModuleBlockedClient*)malloc(sizeof(RedisModuleBlockedClient));
|
||||
mock().setData("RedisModule_BlockClient", 1);
|
||||
return bc;
|
||||
}
|
||||
|
||||
int RedisModule_UnblockClient(RedisModuleBlockedClient *bc, void *privdata)
|
||||
{
|
||||
(void)privdata;
|
||||
free(bc);
|
||||
mock().setData("RedisModule_UnblockClient", mock().getData("RedisModule_UnblockClient").getIntValue()+1);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
int RedisModule_AbortBlock(RedisModuleBlockedClient *bc)
|
||||
{
|
||||
free(bc);
|
||||
mock().setData("RedisModule_AbortBlock", 1);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
RedisModuleString *RedisModule_CreateString(RedisModuleCtx *ctx, const char *ptr, size_t len)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)ptr;
|
||||
(void)len;
|
||||
RedisModuleString *rms = (RedisModuleString*)malloc(sizeof(RedisModuleString));
|
||||
mock().setData("RedisModule_CreateString", mock().getData("RedisModule_CreateString").getIntValue()+1);
|
||||
return rms;
|
||||
}
|
||||
|
||||
void RedisModule_FreeThreadSafeContext(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
mock().setData("RedisModule_FreeThreadSafeContext", 1);
|
||||
return;
|
||||
}
|
||||
|
||||
int RedisModule_StringToLongLong(const RedisModuleString *str, long long *ll)
|
||||
{
|
||||
(void)str;
|
||||
|
||||
int call_no = mock().getData("RedisModule_StringToLongLongCallCount").getIntValue();
|
||||
switch(call_no) {
|
||||
case 0:
|
||||
*ll = mock().getData("RedisModule_StringToLongLongCall_1").getIntValue();
|
||||
break;
|
||||
case 1:
|
||||
*ll = mock().getData("RedisModule_StringToLongLongCall_2").getIntValue();
|
||||
break;
|
||||
default:
|
||||
*ll = mock().getData("RedisModule_StringToLongLongCallDefault").getIntValue();
|
||||
}
|
||||
mock().setData("RedisModule_StringToLongLongCallCount", call_no + 1);
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
void RedisModule_ThreadSafeContextLock(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
mock().setData("RedisModule_ThreadSafeContextLock", 1);
|
||||
return;
|
||||
}
|
||||
|
||||
void RedisModule_ThreadSafeContextUnlock(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
mock().setData("RedisModule_ThreadSafeContextUnlock", 1);
|
||||
return;
|
||||
}
|
||||
|
||||
void RedisModule_ReplySetArrayLength(RedisModuleCtx *ctx, long len)
|
||||
{
|
||||
(void)ctx;
|
||||
mock().setData("RedisModule_ReplySetArrayLength", (int)len);
|
||||
return;
|
||||
}
|
||||
|
||||
RedisModuleCtx *RedisModule_GetThreadSafeContext(RedisModuleBlockedClient *bc)
|
||||
{
|
||||
(void) bc;
|
||||
mock().setData("RedisModule_GetThreadSafeContext", 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RedisModuleString *RedisModule_CreateStringFromLongLong(RedisModuleCtx *ctx, long long ll)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)ll;
|
||||
RedisModuleString *rms = (RedisModuleString*)malloc(sizeof(RedisModuleString));
|
||||
mock().setData("RedisModule_CreateStringFromLongLong", mock().getData("RedisModule_CreateStringFromLongLong").getIntValue()+1);
|
||||
return rms;
|
||||
}
|
||||
|
||||
void RedisModule_AutoMemory(RedisModuleCtx *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
int old = mock().getData("RedisModule_AutoMemory").getIntValue();
|
||||
mock().setData("RedisModule_AutoMemory", old + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
void *RedisModule_Alloc(size_t bytes)
|
||||
{
|
||||
mock()
|
||||
.actualCall("RedisModule_Alloc");
|
||||
return malloc(bytes);
|
||||
}
|
||||
|
||||
void RedisModule_Free(void *ptr)
|
||||
{
|
||||
mock()
|
||||
.actualCall("RedisModule_Free");
|
||||
free(ptr);
|
||||
}
|
164
setup/dbaas/redismodule/tst/src/exstrings_ndel_test.cpp
Normal file
164
setup/dbaas/redismodule/tst/src/exstrings_ndel_test.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "exstringsStub.h"
|
||||
#include "redismodule.h"
|
||||
}
|
||||
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "CppUTestExt/MockSupport.h"
|
||||
|
||||
#include "ut_helpers.hpp"
|
||||
|
||||
void nDelReturnNKeysFromUnlink(int count)
|
||||
{
|
||||
mock()
|
||||
.expectOneCall("RedisModule_CallReplyInteger")
|
||||
.andReturnValue(count);
|
||||
|
||||
}
|
||||
|
||||
TEST_GROUP(exstrings_ndel)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
mock().enable();
|
||||
mock().ignoreOtherCalls();
|
||||
}
|
||||
|
||||
void teardown()
|
||||
{
|
||||
mock().clear();
|
||||
mock().disable();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TEST(exstrings_ndel, ndel_atomic_automemory_enabled)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_AutoMemory");
|
||||
int ret = NDel_Atomic_RedisCommand(&ctx, redisStrVec, 3);
|
||||
mock().checkExpectations();
|
||||
CHECK_EQUAL(ret, REDISMODULE_ERR);
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_ndel, ndel_atomic_command_parameter_parameter_number_incorrect)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_WrongArity");
|
||||
int ret = NDel_Atomic_RedisCommand(&ctx, redisStrVec, 3);
|
||||
mock().checkExpectations();
|
||||
CHECK_EQUAL(ret, REDISMODULE_ERR);
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_ndel, ndel_atomic_command_scan_0_keys_found)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
returnNKeysFromScanSome(0);
|
||||
mock().expectOneCall("RedisModule_ReplyWithLongLong")
|
||||
.withParameter("ll", 0);
|
||||
int ret = NDel_Atomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
mock().checkExpectations();
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_ndel, ndel_atomic_command_scan_3_keys_found_3_keys_deleted)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(3);
|
||||
mock()
|
||||
.expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "UNLINK");
|
||||
nDelReturnNKeysFromUnlink(3);
|
||||
mock().expectOneCall("RedisModule_ReplyWithLongLong")
|
||||
.withParameter("ll", 3);
|
||||
int ret = NDel_Atomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
mock().checkExpectations();
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_ndel, ndel_atomic_command_scan_3_keys_found_0_keys_deleted)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(3);
|
||||
mock()
|
||||
.expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "UNLINK");
|
||||
nDelReturnNKeysFromUnlink(0);
|
||||
mock().expectOneCall("RedisModule_ReplyWithLongLong")
|
||||
.withParameter("ll", 0);
|
||||
int ret = NDel_Atomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
mock().checkExpectations();
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_ndel, ndel_atomic_command_scan_3_keys_found_1_keys_deleted)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(3);
|
||||
mock()
|
||||
.expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "UNLINK");
|
||||
nDelReturnNKeysFromUnlink(1);
|
||||
mock().expectOneCall("RedisModule_ReplyWithLongLong")
|
||||
.withParameter("ll", 1);
|
||||
int ret = NDel_Atomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
mock().checkExpectations();
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
552
setup/dbaas/redismodule/tst/src/exstrings_nget_test.cpp
Normal file
552
setup/dbaas/redismodule/tst/src/exstrings_nget_test.cpp
Normal file
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "exstringsStub.h"
|
||||
#include "redismodule.h"
|
||||
}
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "CppUTestExt/MockSupport.h"
|
||||
|
||||
#include "ut_helpers.hpp"
|
||||
|
||||
TEST_GROUP(exstrings_nget)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
mock().enable();
|
||||
mock().ignoreOtherCalls();
|
||||
}
|
||||
|
||||
void teardown()
|
||||
{
|
||||
mock().clear();
|
||||
mock().disable();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void threadDetachedSuccess()
|
||||
{
|
||||
mock().expectOneCall("pthread_detach")
|
||||
.andReturnValue(0);
|
||||
}
|
||||
|
||||
void nKeysFoundMget(long keys)
|
||||
{
|
||||
for (long i = 0 ; i < keys ; i++) {
|
||||
mock().expectOneCall("RedisModule_CreateStringFromCallReply")
|
||||
.andReturnValue(malloc(UT_DUMMY_BUFFER_SIZE));
|
||||
mock().expectNCalls(2, "RedisModule_ReplyWithString");
|
||||
}
|
||||
}
|
||||
|
||||
void nKeysNotFoundMget(long keys)
|
||||
{
|
||||
void* ptr = NULL;
|
||||
mock().expectNCalls(keys, "RedisModule_CreateStringFromCallReply")
|
||||
.andReturnValue(ptr);
|
||||
mock().expectNoCall("RedisModule_ReplyWithString");
|
||||
}
|
||||
|
||||
void expectNReplies(long count)
|
||||
{
|
||||
mock().expectOneCall("RedisModule_ReplySetArrayLength")
|
||||
.withParameter("len", 2*count);
|
||||
}
|
||||
|
||||
void threadSafeContextLockedAndUnlockedEqualTimes()
|
||||
{
|
||||
int locked = mock().getData("TimesThreadSafeContextWasLocked").getIntValue();
|
||||
int unlocked = mock().getData("TimesThreadSafeContextWasUnlocked").getIntValue();
|
||||
CHECK_EQUAL(locked, unlocked);
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_atomic_automemory_enabled)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
long keys_found_with_scan = 0;
|
||||
|
||||
mock().expectOneCall("RedisModule_AutoMemory");
|
||||
mock().expectOneCall("RedisModule_CallReplyLength")
|
||||
.andReturnValue((int)keys_found_with_scan);
|
||||
int ret = NGet_Atomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
mock().checkExpectations();
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_atomic_command_parameter_number_incorrect)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().expectOneCall("RedisModule_WrongArity");
|
||||
int ret = NGet_Atomic_RedisCommand(&ctx, redisStrVec, 3);
|
||||
CHECK_EQUAL(ret, REDISMODULE_ERR);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_atomic_command_3rd_parameter_was_not_equal_to_COUNT)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(4);
|
||||
const char * not_count_literal = "NOT_COUNT";
|
||||
size_t not_count_len = strlen(not_count_literal);
|
||||
|
||||
mock().expectOneCall("RedisModule_StringPtrLen")
|
||||
.withOutputParameterReturning("len", ¬_count_len, sizeof(size_t))
|
||||
.andReturnValue((void*)not_count_literal);
|
||||
mock().expectOneCall("RedisModule_ReplyWithError");
|
||||
int ret = NGet_Atomic_RedisCommand(&ctx, redisStrVec, 4);
|
||||
CHECK_EQUAL(ret, REDISMODULE_ERR);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_atomic_command_4th_parameter_was_not_integer)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(4);
|
||||
const char * count_literal = "COUNT";
|
||||
size_t count_len = strlen(count_literal);
|
||||
size_t count_number = 123;
|
||||
|
||||
mock().expectOneCall("RedisModule_StringPtrLen")
|
||||
.withOutputParameterReturning("len", &count_len, sizeof(size_t))
|
||||
.andReturnValue((void*)count_literal);
|
||||
mock().expectOneCall("RedisModule_StringToLongLong")
|
||||
.withOutputParameterReturning("ll", &count_number, sizeof(size_t))
|
||||
.andReturnValue(REDISMODULE_ERR);
|
||||
mock().expectOneCall("RedisModule_ReplyWithError");
|
||||
int ret = NGet_Atomic_RedisCommand(&ctx, redisStrVec, 4);
|
||||
CHECK_EQUAL(ret, REDISMODULE_ERR);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_atomic_command_4th_parameter_was_negative)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(4);
|
||||
const char * count_literal = "COUNT";
|
||||
size_t count_len = strlen(count_literal);
|
||||
size_t count_number = -123;
|
||||
|
||||
mock().expectOneCall("RedisModule_StringPtrLen")
|
||||
.withOutputParameterReturning("len", &count_len, sizeof(size_t))
|
||||
.andReturnValue((void*)count_literal);
|
||||
mock().expectOneCall("RedisModule_StringToLongLong")
|
||||
.withOutputParameterReturning("ll", &count_number, sizeof(size_t))
|
||||
.andReturnValue(REDISMODULE_OK);
|
||||
mock().expectOneCall("RedisModule_ReplyWithError");
|
||||
int ret = NGet_Atomic_RedisCommand(&ctx, redisStrVec, 4);
|
||||
CHECK_EQUAL(ret, REDISMODULE_ERR);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_atomic_command_scan_returned_zero_keys)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().expectOneCall("RedisModule_ReplyWithArray")
|
||||
.withParameter("len", (long)REDISMODULE_POSTPONED_ARRAY_LEN);
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(0);
|
||||
expectNReplies(0);
|
||||
mock().expectNoCall("RedisModule_Call");
|
||||
|
||||
int ret = NGet_Atomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_atomic_command_3_keys_scanned_0_keys_mget)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_ReplyWithArray")
|
||||
.withParameter("len", (long)REDISMODULE_POSTPONED_ARRAY_LEN);
|
||||
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "MGET");
|
||||
nKeysNotFoundMget(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
expectNReplies(0);
|
||||
int ret = NGet_Atomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_atomic_command_3_keys_scanned_3_keys_mget)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_ReplyWithArray")
|
||||
.withParameter("len", (long)REDISMODULE_POSTPONED_ARRAY_LEN);
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "MGET");
|
||||
nKeysFoundMget(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
expectNReplies(3);
|
||||
int ret = NGet_Atomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_atomic_command_3_keys_scanned_2_keys_mget)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_ReplyWithArray")
|
||||
.withParameter("len", (long)REDISMODULE_POSTPONED_ARRAY_LEN);
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "MGET");
|
||||
nKeysFoundMget(2);
|
||||
nKeysNotFoundMget(1);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
expectNReplies(2);
|
||||
int ret = NGet_Atomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_automemory_enabled)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().setData("pthread_create_free_block_client_args", 1);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_AutoMemory");
|
||||
|
||||
int ret = NGet_NoAtomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_thread_create_success)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().setData("pthread_create_free_block_client_args", 1);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_BlockClient");
|
||||
mock().expectOneCall("pthread_create");
|
||||
mock().expectNoCall("RedisModule_AbortBlock");
|
||||
|
||||
int ret = NGet_NoAtomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_thread_create_fail)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
mock().expectOneCall("RedisModule_BlockClient");
|
||||
mock().expectOneCall("pthread_create")
|
||||
.andReturnValue(1);
|
||||
mock().expectOneCall("RedisModule_AbortBlock");
|
||||
|
||||
int ret = NGet_NoAtomic_RedisCommand(&ctx, redisStrVec, 2);
|
||||
CHECK_EQUAL(ret, REDISMODULE_OK);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_parameter_number_incorrect)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(4);
|
||||
|
||||
mock().expectOneCall("RedisModule_WrongArity");
|
||||
mock().expectNoCall("RedisModule_BlockClient");
|
||||
|
||||
int ret = NGet_NoAtomic_RedisCommand(&ctx, redisStrVec, 3);
|
||||
|
||||
CHECK_EQUAL(ret, REDISMODULE_ERR);
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_threadmain_3rd_parameter_was_not_equal_to_COUNT)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(4);
|
||||
const char * not_count_literal = "NOT_COUNT";
|
||||
size_t not_count_len = strlen(not_count_literal);
|
||||
|
||||
mock().expectOneCall("RedisModule_StringPtrLen")
|
||||
.withOutputParameterReturning("len", ¬_count_len, sizeof(size_t))
|
||||
.andReturnValue((void*)not_count_literal);
|
||||
mock().expectOneCall("RedisModule_ReplyWithError");
|
||||
mock().expectNoCall("RedisModule_BlockClient");
|
||||
|
||||
int ret = NGet_NoAtomic_RedisCommand(&ctx, redisStrVec, 4);
|
||||
|
||||
CHECK_EQUAL(ret, REDISMODULE_ERR);
|
||||
|
||||
mock().checkExpectations();
|
||||
threadSafeContextLockedAndUnlockedEqualTimes();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_4th_parameter_was_not_integer)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
const char * count_literal = "COUNT";
|
||||
size_t count_len = strlen(count_literal);
|
||||
size_t count_number = -123;
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(4);
|
||||
|
||||
mock().expectOneCall("RedisModule_StringPtrLen")
|
||||
.withOutputParameterReturning("len", &count_len, sizeof(size_t))
|
||||
.andReturnValue((void*)count_literal);
|
||||
mock().expectOneCall("RedisModule_StringToLongLong")
|
||||
.withOutputParameterReturning("ll", &count_number, sizeof(size_t))
|
||||
.andReturnValue(REDISMODULE_OK);
|
||||
mock().expectOneCall("RedisModule_ReplyWithError");
|
||||
|
||||
int ret = NGet_NoAtomic_RedisCommand(&ctx, redisStrVec, 4);
|
||||
|
||||
CHECK_EQUAL(ret, REDISMODULE_ERR);
|
||||
mock().checkExpectations();
|
||||
threadSafeContextLockedAndUnlockedEqualTimes();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
typedef struct RedisModuleBlockedClientArgs {
|
||||
RedisModuleBlockedClient *bc;
|
||||
RedisModuleString **argv;
|
||||
int argc;
|
||||
} RedisModuleBlockedClientArgs;
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_threadmain_3_keys_scanned_3_keys_mget)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleBlockedClientArgs *bca =
|
||||
(RedisModuleBlockedClientArgs*)RedisModule_Alloc(sizeof(RedisModuleBlockedClientArgs));
|
||||
RedisModuleBlockedClient *bc = RedisModule_BlockClient(&ctx,NULL,NULL,NULL,0);
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
bca->bc = bc;
|
||||
bca->argv = redisStrVec;
|
||||
bca->argc = 2;
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
threadDetachedSuccess();
|
||||
mock().expectOneCall("RedisModule_ReplyWithArray")
|
||||
.withParameter("len", (long)REDISMODULE_POSTPONED_ARRAY_LEN);
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "MGET");
|
||||
nKeysFoundMget(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
expectNReplies(3);
|
||||
mock().expectOneCall("RedisModule_FreeThreadSafeContext");
|
||||
mock().expectOneCall("RedisModule_UnblockClient");
|
||||
|
||||
NGet_NoAtomic_ThreadMain((void*)bca);
|
||||
|
||||
mock().checkExpectations();
|
||||
threadSafeContextLockedAndUnlockedEqualTimes();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_threadmain_3_keys_scanned_0_keys_mget)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleBlockedClientArgs *bca = (RedisModuleBlockedClientArgs*)malloc(sizeof(RedisModuleBlockedClientArgs));
|
||||
RedisModuleBlockedClient *bc = RedisModule_BlockClient(&ctx,NULL,NULL,NULL,0);
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
bca->bc = bc;
|
||||
bca->argv = redisStrVec;
|
||||
bca->argc = 2;
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
threadDetachedSuccess();
|
||||
mock().expectOneCall("RedisModule_ReplyWithArray")
|
||||
.withParameter("len", (long)REDISMODULE_POSTPONED_ARRAY_LEN);
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "MGET");
|
||||
nKeysNotFoundMget(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
expectNReplies(0);
|
||||
mock().expectOneCall("RedisModule_FreeThreadSafeContext");
|
||||
mock().expectOneCall("RedisModule_UnblockClient");
|
||||
|
||||
NGet_NoAtomic_ThreadMain((void*)bca);
|
||||
|
||||
mock().checkExpectations();
|
||||
threadSafeContextLockedAndUnlockedEqualTimes();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_threadmain_3_keys_scanned_2_keys_mget)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleBlockedClientArgs *bca = (RedisModuleBlockedClientArgs*)malloc(sizeof(RedisModuleBlockedClientArgs));
|
||||
RedisModuleBlockedClient *bc = RedisModule_BlockClient(&ctx,NULL,NULL,NULL,0);
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
bca->bc = bc;
|
||||
bca->argv = redisStrVec;
|
||||
bca->argc = 2;
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
threadDetachedSuccess();
|
||||
mock().expectOneCall("RedisModule_ReplyWithArray")
|
||||
.withParameter("len", (long)REDISMODULE_POSTPONED_ARRAY_LEN);
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(3);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "MGET");
|
||||
nKeysNotFoundMget(1);
|
||||
nKeysFoundMget(2);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
expectNReplies(2);
|
||||
mock().expectOneCall("RedisModule_FreeThreadSafeContext");
|
||||
mock().expectOneCall("RedisModule_UnblockClient");
|
||||
|
||||
NGet_NoAtomic_ThreadMain((void*)bca);
|
||||
|
||||
mock().checkExpectations();
|
||||
threadSafeContextLockedAndUnlockedEqualTimes();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_threadmain_scan_returned_zero_keys)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleBlockedClientArgs *bca = (RedisModuleBlockedClientArgs*)malloc(sizeof(RedisModuleBlockedClientArgs));
|
||||
RedisModuleBlockedClient *bc = RedisModule_BlockClient(&ctx,NULL,NULL,NULL,0);
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
bca->bc = bc;
|
||||
bca->argv = redisStrVec;
|
||||
bca->argc = 2;
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
threadDetachedSuccess();
|
||||
mock().expectOneCall("RedisModule_ReplyWithArray")
|
||||
.withParameter("len", (long)REDISMODULE_POSTPONED_ARRAY_LEN);
|
||||
mock().expectOneCall("RedisModule_Call")
|
||||
.withParameter("cmdname", "SCAN");
|
||||
returnNKeysFromScanSome(0);
|
||||
mock().expectOneCall("RedisModule_FreeCallReply");
|
||||
mock().expectNoCall("RedisModule_Call");
|
||||
mock().expectOneCall("RedisModule_FreeThreadSafeContext");
|
||||
mock().expectOneCall("RedisModule_UnblockClient");
|
||||
|
||||
NGet_NoAtomic_ThreadMain((void*)bca);
|
||||
|
||||
mock().checkExpectations();
|
||||
threadSafeContextLockedAndUnlockedEqualTimes();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
||||
|
||||
TEST(exstrings_nget, nget_noatomic_threadmain_thread_detached)
|
||||
{
|
||||
RedisModuleCtx ctx;
|
||||
RedisModuleBlockedClientArgs *bca = (RedisModuleBlockedClientArgs*)malloc(sizeof(RedisModuleBlockedClientArgs));
|
||||
RedisModuleBlockedClient *bc = RedisModule_BlockClient(&ctx,NULL,NULL,NULL,0);
|
||||
RedisModuleString ** redisStrVec = createRedisStrVec(2);
|
||||
|
||||
bca->bc = bc;
|
||||
bca->argv = redisStrVec;
|
||||
bca->argc = 2;
|
||||
|
||||
mock().ignoreOtherCalls();
|
||||
threadDetachedSuccess();
|
||||
|
||||
NGet_NoAtomic_ThreadMain((void*)bca);
|
||||
|
||||
mock().checkExpectations();
|
||||
|
||||
delete []redisStrVec;
|
||||
}
|
1691
setup/dbaas/redismodule/tst/src/exstrings_test.cpp
Executable file
1691
setup/dbaas/redismodule/tst/src/exstrings_test.cpp
Executable file
File diff suppressed because it is too large
Load Diff
32
setup/dbaas/redismodule/tst/src/main.cpp
Executable file
32
setup/dbaas/redismodule/tst/src/main.cpp
Executable file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
|
||||
extern "C" {
|
||||
#include <stdio.h>
|
||||
}
|
||||
|
||||
int main(int ac, char** av)
|
||||
{
|
||||
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
|
||||
return CommandLineTestRunner::RunAllTests(ac, av);
|
||||
}
|
48
setup/dbaas/redismodule/tst/src/ut_helpers.cpp
Normal file
48
setup/dbaas/redismodule/tst/src/ut_helpers.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020 Nokia.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This source code is part of the near-RT RIC (RAN Intelligent Controller)
|
||||
* platform project (RICP).
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "redismodule.h"
|
||||
#include "ut_helpers.hpp"
|
||||
|
||||
#include <CppUTest/TestHarness.h>
|
||||
#include <CppUTestExt/MockSupport.h>
|
||||
|
||||
RedisModuleString **createRedisStrVec(size_t size)
|
||||
{
|
||||
RedisModuleString ** redisStrVec = new RedisModuleString*[size];
|
||||
for (size_t i = 0 ; i < size ; i++) {
|
||||
redisStrVec[i] = (RedisModuleString *)UT_DUMMY_PTR_ADDRESS;
|
||||
}
|
||||
return redisStrVec;
|
||||
}
|
||||
|
||||
void returnNKeysFromScanSome(long keys)
|
||||
{
|
||||
mock().expectOneCall("RedisModule_CallReplyLength")
|
||||
.andReturnValue((int)keys);
|
||||
for (long i = 0 ; i < keys ; i++) {
|
||||
mock().expectOneCall("RedisModule_CreateStringFromCallReply")
|
||||
.andReturnValue(malloc(UT_DUMMY_BUFFER_SIZE));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user