From 24faeb3c56731f8d32bca9b0d52552828f358367 Mon Sep 17 00:00:00 2001 From: hdt3213 Date: Sat, 30 Apr 2022 19:23:49 +0800 Subject: [PATCH] fix test suite --- database/doc.go | 19 +++++++++++++++++++ database/string_test.go | 18 ++---------------- 2 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 database/doc.go diff --git a/database/doc.go b/database/doc.go new file mode 100644 index 0000000..985fd71 --- /dev/null +++ b/database/doc.go @@ -0,0 +1,19 @@ +package database + +/* +[MultiDB](https://github.com/HDT3213/godis/blob/master/database/database.go) is an implemention of interface [DB](https://github.com/HDT3213/godis/blob/master/interface/database/db.go). + +[server.Handler](https://github.com/HDT3213/godis/blob/master/redis/server/server.go) holds an instance of MultiDB as storage engine, and pass command line to MultiDB through db.Exec method. + +MultiDB is a multi-database engine which supports `SELECT` command. Besides multiple database instance, it holds pubsub.Hub and aof.Handler for publish-subscription and AOF persistence. + +MultiDB.Exec is the main entry for MultiDB, it handles authentication, publish-subscription, aof as well as system commands itself, and invoke Exec function of selected db for other commands. + +[godis.DB.Exec](https://github.com/HDT3213/godis/blob/master/database/single_db.go) handles transaction control command (such as watch, multi, exec) itself, and invokes DB.execNormalCommand to handle normal commands. The word, normal command, is commands which read or write limited keys, can execute within transaction, and supports rollback. For example, get, set, lpush are normal commands, while flushdb, keys are not. + +[RegisterCommand](https://github.com/HDT3213/godis/blob/master/database/router.go) is used for registering normal command. A normal command requires three functions: + +- ExecFunc: The function that actually executes the command, such as [execHSet](https://github.com/HDT3213/godis/blob/master/database/hash.go) +- PrepareFunc executes before ExecFunc, it analysises command line and returns read/written keys for lock +- UndoFunc invoked in transaction only, it generates undo log in case need rollback in transaction +*/ diff --git a/database/string_test.go b/database/string_test.go index eb8c57c..617b5ee 100644 --- a/database/string_test.go +++ b/database/string_test.go @@ -622,14 +622,7 @@ func TestGetRange_StringExist_StartIdxIncorrectFormat(t *testing.T) { incorrectValue := "incorrect" actual := testDB.Exec(nil, utils.ToCmdLine("GetRange", key, incorrectValue, fmt.Sprint(0))) - val, ok := actual.(*protocol.StandardErrReply) - if !ok { - t.Errorf("expect standart bulk protocol, get: %s", string(actual.ToBytes())) - return - } - - errorMsg := fmt.Sprintf("strconv.ParseInt: parsing \"%s\": invalid syntax", incorrectValue) - asserts.AssertErrReply(t, val, errorMsg) + asserts.AssertErrReply(t, actual, "-ERR value is not an integer or out of range") } func TestGetRange_StringExist_EndIdxIncorrectFormat(t *testing.T) { @@ -639,14 +632,7 @@ func TestGetRange_StringExist_EndIdxIncorrectFormat(t *testing.T) { incorrectValue := "incorrect" actual := testDB.Exec(nil, utils.ToCmdLine("GetRange", key, fmt.Sprint(0), incorrectValue)) - val, ok := actual.(*protocol.StandardErrReply) - if !ok { - t.Errorf("expect standart bulk protocol, get: %s", string(actual.ToBytes())) - return - } - - errorMsg := fmt.Sprintf("strconv.ParseInt: parsing \"%s\": invalid syntax", incorrectValue) - asserts.AssertErrReply(t, val, errorMsg) + asserts.AssertErrReply(t, actual, "ERR value is not an integer or out of range") } func TestSetBit(t *testing.T) {