Skip to content

Commit

Permalink
add the test for TairString、TairHash and TairSzset
Browse files Browse the repository at this point in the history
Signed-off-by: liyaojie <[email protected]>
  • Loading branch information
lyj199907 authored and suxb201 committed Aug 25, 2023
1 parent 8e1cd0f commit 88df70b
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 14 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
strategy:
matrix:
redis-version: [ "2.8", "3.0", "4.0", "5.0", "6.0", "7.0" ]
fail-fast: false
container: ubuntu:latest
steps:
- name: Git checkout
Expand All @@ -30,6 +31,45 @@ jobs:
cp src/redis-server bin/redis-server
echo "$GITHUB_WORKSPACE/redis/bin" >> $GITHUB_PATH
- name: clone and make TairString Module
if: contains( '5.0, 6.0, 7.0', matrix.redis-version)
run: |
cd $GITHUB_WORKSPACE
apt-get install -y cmake
git clone https://github.com/tair-opensource/TairString.git
cd TairString
mkdir build
cd build
cmake ../ && make -j
cp $GITHUB_WORKSPACE/TairString/lib/tairstring_module.so /lib
- name: clone and make TairHash Module
if: contains( '5.0, 6.0, 7.0', matrix.redis-version)
run: |
cd $GITHUB_WORKSPACE
git clone https://github.com/tair-opensource/TairHash.git
cd TairHash
mkdir build
cd build
cmake ../ && make -j
cp $GITHUB_WORKSPACE/TairHash/lib/tairhash_module.so /lib


- name: clone and make TairZset Module
if: contains( '5.0, 6.0, 7.0', matrix.redis-version)
run: |
cd $GITHUB_WORKSPACE
git clone https://github.com/tair-opensource/TairZset.git
cd TairZset
mkdir build
cd build
cmake ../ && make -j
cp $GITHUB_WORKSPACE/TairZset/lib/tairzset_module.so /lib
- name: Setup Python
uses: actions/setup-python@v4
with:
Expand Down
22 changes: 11 additions & 11 deletions internal/commands/table.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package commands

var containers = map[string]bool{
"MODULE": true,
"CLUSTER": true,
"XGROUP": true,
"XINFO": true,
"COMMAND": true,
"SLOWLOG": true,
"OBJECT": true,
"MEMORY": true,
"CONFIG": true,
"FUNCTION": true,
"CONFIG": true,
"MODULE": true,
"MEMORY": true,
"LATENCY": true,
"XINFO": true,
"CLIENT": true,
"SENTINEL": true,
"PUBSUB": true,
"SCRIPT": true,
"ACL": true,
"CLUSTER": true,
"CLIENT": true,
"XGROUP": true,
"PUBSUB": true,
"OBJECT": true,
"SENTINEL": true,
"SLOWLOG": true,
}
var redisCommands = map[string]redisCommand{
"LLEN": {
Expand Down
55 changes: 55 additions & 0 deletions scripts/table.json
Original file line number Diff line number Diff line change
Expand Up @@ -3582,7 +3582,62 @@
}
}
]
},
"TairHash": {
"EXHSET": [
{
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
}
]
},
"TairString": {
"EXSET": [
{
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
}
]
},
"TairZset": {
"EXZADD ": [
{
"begin_search": {
"index": {
"pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
}
]
}

},
"container": [
"MODULE",
Expand Down
3 changes: 3 additions & 0 deletions tests/helpers/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from .select import SelectChecker
from .string import StringChecker
from .tair_string import TairStringChecker
from .tair_hash import TairHashChecker
from .tair_zset import TairZsetChecker
55 changes: 55 additions & 0 deletions tests/helpers/commands/tair_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pybbt

from helpers.commands.checker import Checker
from helpers.redis import Redis
from helpers.constant import REDIS_SERVER_VERSION


class TairHashChecker(Checker):
PREFIX = "tairHash"

def __init__(self):
self.cnt = 0

def add_data(self, r: Redis, cross_slots_cmd: bool):
if REDIS_SERVER_VERSION < 5.0:
return
p = r.pipeline()
# different parameters type
p.execute_command("EXHSET",f"{self.PREFIX}_{self.cnt}", "field", "value")
p.execute_command("EXHSET",f"{self.PREFIX}_{self.cnt}_ABS", "field_abs", "value_abs", "ABS", 2)
p.execute_command("EXHSET",f"{self.PREFIX}_{self.cnt}_EX", "field_ex", "value_ex", "EX", 20000)

# different key
# different field
p.execute_command("EXHSET",f"{self.PREFIX}_{self.cnt}_ALL_01", "field_all_01", "value_all_01", "EX", 20000, "ABS", 2)
p.execute_command("EXHSET",f"{self.PREFIX}_{self.cnt}_ALL_01", "field_all_02", "value_all_02", "EX", 20000, "ABS", 3)

p.execute_command("EXHSET",f"{self.PREFIX}_{self.cnt}_ALL_02", "field_all_01", "value_all_01", "EX", 20000, "ABS", 2)
p.execute_command("EXHSET",f"{self.PREFIX}_{self.cnt}_ALL_02", "field_all_02", "value_all_02", "EX", 20000, "ABS", 3)

ret = p.execute()
# pybbt.ASSERT_EQ(ret, [b"1", b"1", b"1", b"1",b"1", b"1",b"1"])
pybbt.ASSERT_EQ(ret, [1, 1, 1, 1, 1, 1, 1])

self.cnt += 1

def check_data(self, r: Redis, cross_slots_cmd: bool):
if REDIS_SERVER_VERSION < 5.0:
return
for i in range(self.cnt):
p = r.pipeline()

p.execute_command("EXHGET",f"{self.PREFIX}_{i}", "field")
p.execute_command("EXHGET",f"{self.PREFIX}_{i}_ABS", "field_abs")
p.execute_command("EXHGET",f"{self.PREFIX}_{i}_EX", "field_ex")

p.execute_command("EXHGET",f"{self.PREFIX}_{i}_ALL_01", "field_all_01")
p.execute_command("EXHGET",f"{self.PREFIX}_{i}_ALL_01", "field_all_02")

p.execute_command("EXHGET",f"{self.PREFIX}_{i}_ALL_02", "field_all_01")
p.execute_command("EXHGET",f"{self.PREFIX}_{i}_ALL_02", "field_all_02")

ret = p.execute()
# 需要确定一下如果一个命令返回多个值是如何封装的
pybbt.ASSERT_EQ(ret, [b"value", b"value_abs", b"value_ex", b"value_all_01", b"value_all_02", b"value_all_01", b"value_all_02",])
43 changes: 43 additions & 0 deletions tests/helpers/commands/tair_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pybbt

from helpers.commands.checker import Checker
from helpers.redis import Redis
from helpers.constant import REDIS_SERVER_VERSION


class TairStringChecker(Checker):
PREFIX = "tairString"

def __init__(self):
self.cnt = 0

def add_data(self, r: Redis, cross_slots_cmd: bool):
if REDIS_SERVER_VERSION < 5.0:
return
p = r.pipeline()
# different parameters type
p.execute_command("EXSET",f"{self.PREFIX}_{self.cnt}_ABS", "abs_value", "VER",2)
p.execute_command("EXSET",f"{self.PREFIX}_{self.cnt}_FLAGS", "flags_value", "FLAGS", 2)
p.execute_command("Exset",f"{self.PREFIX}_{self.cnt}_EX", "ex_value", "EX", 20000)

# different key
p.execute_command("Exset",f"{self.PREFIX}_{self.cnt}_ALL_01", "all_value_01", "EX", 20000, "ABS", 3, "FLAGS", 4)
p.execute_command("Exset",f"{self.PREFIX}_{self.cnt}_ALL_02", "all_value_02", "EX", 20000, "ABS", 4, "FLAGS", 5)
ret = p.execute()
pybbt.ASSERT_EQ(ret, [b"OK", b"OK", b"OK", b"OK", b"OK"])
self.cnt += 1

def check_data(self, r: Redis, cross_slots_cmd: bool):
if REDIS_SERVER_VERSION < 5.0:
return
for i in range(self.cnt):
p = r.pipeline()

p.execute_command("EXGET",f"{self.PREFIX}_{i}_ABS")
p.execute_command("EXGET",f"{self.PREFIX}_{i}_FLAGS", "WITHFLAGS")
p.execute_command("EXGET",f"{self.PREFIX}_{i}_EX")
p.execute_command("EXGET",f"{self.PREFIX}_{i}_ALL_01", "WITHFLAGS")
p.execute_command("EXGET",f"{self.PREFIX}_{i}_ALL_02", "WITHFLAGS")

ret = p.execute()
pybbt.ASSERT_EQ(ret, [[b"abs_value", 1], [b"flags_value", 1, 2], [b"ex_value", 1], [b"all_value_01", 3, 4], [b"all_value_02", 4, 5]])
47 changes: 47 additions & 0 deletions tests/helpers/commands/tair_zset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pybbt

from helpers.commands.checker import Checker
from helpers.redis import Redis
from helpers.constant import REDIS_SERVER_VERSION


class TairZsetChecker(Checker):
PREFIX = "tairZset"

def __init__(self):
self.cnt = 0

def add_data(self, r: Redis, cross_slots_cmd: bool):
if REDIS_SERVER_VERSION < 5.0:
return
p = r.pipeline()

# different key
# int or float
p.execute_command("EXZADD",f"{self.PREFIX}_{self.cnt}_key01", "1.1#1.2", "mem01","2.2#2.3", "mem02")
p.execute_command("EXZADD",f"{self.PREFIX}_{self.cnt}_key01", "3.3#3.4", "mem03","4.4#4.5", "mem04")
p.execute_command("EXZADD",f"{self.PREFIX}_{self.cnt}_key02", "1.1#1.2", "mem01")
p.execute_command("EXZADD",f"{self.PREFIX}_{self.cnt}_key02", "2.2#2.3", "mem02")
ret = p.execute()
pybbt.ASSERT_EQ(ret, [2, 2, 1, 1])

self.cnt += 1

def check_data(self, r: Redis, cross_slots_cmd: bool):
if REDIS_SERVER_VERSION < 5.0:
return
for i in range(self.cnt):
p = r.pipeline()
p.execute_command("EXZSCORE",f"{self.PREFIX}_{i}_key01", "mem01")
p.execute_command("EXZSCORE",f"{self.PREFIX}_{i}_key01", "mem02")
p.execute_command("EXZSCORE",f"{self.PREFIX}_{i}_key01", "mem03")
p.execute_command("EXZSCORE",f"{self.PREFIX}_{i}_key01", "mem04")
p.execute_command("EXZSCORE",f"{self.PREFIX}_{i}_key02", "mem01")
p.execute_command("EXZSCORE",f"{self.PREFIX}_{i}_key02", "mem02")

ret = p.execute()
pybbt.ASSERT_EQ(ret,
[b'1.1000000000000001#1.2',
b'2.2000000000000002#2.2999999999999998', b'3.2999999999999998#3.3999999999999999',
b'4.4000000000000004#4.5', b'1.1000000000000001#1.2',
b'2.2000000000000002#2.2999999999999998'] )
7 changes: 6 additions & 1 deletion tests/helpers/data_inserter.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from helpers.commands import SelectChecker, StringChecker
from helpers.commands import SelectChecker, StringChecker, TairStringChecker, TairHashChecker, TairZsetChecker
from helpers.redis import Redis
from helpers.constant import PATH_REDIS_SERVER, REDIS_SERVER_VERSION


class DataInserter:
def __init__(self, ):
self.checkers = [
StringChecker(),
SelectChecker(),
TairStringChecker(),
TairHashChecker(),
TairZsetChecker(),
]


def add_data(self, r: Redis, cross_slots_cmd: bool):
for checker in self.checkers:
checker.add_data(r, cross_slots_cmd)
Expand Down
12 changes: 10 additions & 2 deletions tests/helpers/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ def __init__(self, args=None):
self.port = get_free_port()
self.dir = f"{self.case_ctx.dir}/redis_{self.port}"
args.extend(["--port", str(self.port)])
self.server = pybbt.Launcher(args=[PATH_REDIS_SERVER] + args, work_dir=self.dir)

if REDIS_SERVER_VERSION > 4.0:
args.extend(["--loadmodule", "tairstring_module.so"])
args.extend(["--loadmodule", "tairhash_module.so"])
args.extend(["--loadmodule", "tairzset_module.so"])
self.server = pybbt.Launcher(args=[PATH_REDIS_SERVER] + args, work_dir=self.dir)
else:
self.server = pybbt.Launcher(args=[PATH_REDIS_SERVER] + args, work_dir=self.dir)

self._wait_start()
self.client = redis.Redis(host=self.host, port=self.port)
self.case_ctx.add_exit_hook(lambda: self.server.stop())
Expand Down Expand Up @@ -58,4 +66,4 @@ def is_cluster(self):
return self.client.info()["cluster_enabled"]

def dbsize(self):
return self.client.dbsize()
return self.client.dbsize()

0 comments on commit 88df70b

Please sign in to comment.