Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases to verify the support for zset data type #1362

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions integration_tests/commands/http/command_getkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ func TestCommandGetKeys(t *testing.T) {
},
expected: []interface{}{[]interface{}{"1 2 3 4 5 6 7"}},
},
{
name: "MSET command",
commands: []HTTPCommand{
{Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "MSET", "keys": []interface{}{"key1 key2"}, "values": []interface{}{" val1 val2"}}},
},
expected: []interface{}{[]interface{}{"key1 key2"}},
},
// Skipping these tests until multishards cmds supported by http
//{
// name: "MSET command",
// commands: []HTTPCommand{
// {Command: "COMMAND/GETKEYS", Body: map[string]interface{}{"key": "MSET", "keys": []interface{}{"key1 key2"}, "values": []interface{}{" val1 val2"}}},
// },
// expected: []interface{}{"ERR invalid command specified"},
//},
{
name: "Expire command",
commands: []HTTPCommand{
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/commands/http/command_rename_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//go:build ignore
// +build ignore

// Ignored as multishard commands not supported by HTTP
package http

import (
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/commands/http/copy_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//go:build ignore
// +build ignore

// Ignored as multishard commands not supported by HTTP
package http

import (
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/commands/http/dbsize_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//go:build ignore
// +build ignore

// Ignored as multishard commands not supported by HTTP
package http

import (
Expand Down
1 change: 1 addition & 0 deletions integration_tests/commands/http/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ func TestJsonStrlen(t *testing.T) {
}

func TestJSONMGET(t *testing.T) {
t.Skip("Skipping this test until multishards cmds supported by http")
exec := NewHTTPCommandExecutor()
setupData := map[string]string{
"xx": `["hehhhe","hello"]`,
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/commands/http/keys_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//go:build ignore
// +build ignore

// Ignored as multishard commands not supported by HTTP
package http

import (
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/commands/http/mget_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//go:build ignore
// +build ignore

// Ignored as multishard commands not supported by HTTP
package http

import (
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/commands/http/mset_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//go:build ignore
// +build ignore

// Ignored as multishard commands not supported by HTTP
package http

import (
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/commands/http/object_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//go:build ignore
// +build ignore

// Ignored as multishard commands not supported by HTTP
package http

import (
Expand Down
229 changes: 115 additions & 114 deletions integration_tests/commands/http/set_data_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,120 +159,121 @@ func TestSetDataCmd(t *testing.T) {
assert_type: []string{"equal", "array", "equal", "array"},
expected: []interface{}{float64(3), []any{string("bar"), string("baz"), string("bax")}, float64(0), []any{string("bar"), string("baz"), string("bax")}},
},
{
name: "SADD & SDIFF",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo2", "value": "baz"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo2", "value": "bax"}},
{Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
},
assert_type: []string{"equal", "equal", "equal", "equal", "array"},
expected: []interface{}{float64(1), float64(1), float64(1), float64(1), []any{string("bar")}},
},
{
name: "SADD & SDIFF with non-existing subsequent key",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
{Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
},
assert_type: []string{"equal", "equal", "array"},
expected: []interface{}{float64(1), float64(1), []any{string("bar"), string("baz")}},
},
{
name: "SADD & SDIFF with wrong key type",
commands: []HTTPCommand{
{Command: "SET", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
},
assert_type: []string{"equal", "equal"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
{
name: "SADD & SDIFF with subsequent key of wrong type",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
{Command: "SET", Body: map[string]interface{}{"key": "foo2", "value": "bar"}},
{Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
},
assert_type: []string{"equal", "equal", "equal", "equal"},
expected: []interface{}{float64(1), float64(1), "OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
{
name: "SADD & SDIFF with non-existing first key",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
{Command: "SDIFF", Body: map[string]interface{}{"key1": "foo2", "key2": "foo"}},
},
assert_type: []string{"equal", "equal", "array"},
expected: []interface{}{float64(1), float64(1), []any{}},
},
{
name: "SADD & SDIFF with one key",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
{Command: "SDIFF", Body: map[string]interface{}{"key": "foo"}},
},
assert_type: []string{"equal", "equal", "array"},
expected: []interface{}{float64(1), float64(1), []any{string("bar"), string("baz")}},
},
{
name: "SADD & SINTER",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo2", "value": "baz"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo2", "value": "bax"}},
{Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
},
assert_type: []string{"equal", "equal", "equal", "equal", "array"},
expected: []interface{}{float64(1), float64(1), float64(1), float64(1), []any{string("baz")}},
},
{
name: "SADD & SINTER with non-existing subsequent key",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
{Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
},
assert_type: []string{"equal", "equal", "array"},
expected: []interface{}{float64(1), float64(1), []any{}},
},
{
name: "SADD & SINTER with wrong key type",
commands: []HTTPCommand{
{Command: "SET", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
},
assert_type: []string{"equal", "equal"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
{
name: "SADD & SINTER with subsequent key of wrong type",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
{Command: "SET", Body: map[string]interface{}{"key": "foo2", "value": "bar"}},
{Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
},
assert_type: []string{"equal", "equal", "equal", "equal"},
expected: []interface{}{float64(1), float64(1), "OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
{
name: "SADD & SINTER with single key",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
{Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
{Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo"}}},
},
assert_type: []string{"equal", "equal", "array"},
expected: []interface{}{float64(1), float64(1), []any{string("bar"), string("baz")}},
},
// Skipping these tests until multishards cmds supported by http
//{
// name: "SADD & SDIFF",
// commands: []HTTPCommand{
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo2", "value": "baz"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo2", "value": "bax"}},
// {Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
// },
// assert_type: []string{"equal", "equal", "equal", "equal", "array"},
// expected: []interface{}{float64(1), float64(1), float64(1), float64(1), []any{string("bar")}},
//},
//{
// name: "SADD & SDIFF with non-existing subsequent key",
// commands: []HTTPCommand{
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
// {Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
// },
// assert_type: []string{"equal", "equal", "array"},
// expected: []interface{}{float64(1), float64(1), []any{string("bar"), string("baz")}},
//},
//{
// name: "SADD & SDIFF with wrong key type",
// commands: []HTTPCommand{
// {Command: "SET", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
// },
// assert_type: []string{"equal", "equal"},
// expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
//},
//{
// name: "SADD & SDIFF with subsequent key of wrong type",
// commands: []HTTPCommand{
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
// {Command: "SET", Body: map[string]interface{}{"key": "foo2", "value": "bar"}},
// {Command: "SDIFF", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
// },
// assert_type: []string{"equal", "equal", "equal", "equal"},
// expected: []interface{}{float64(1), float64(1), "OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
//},
//{
// name: "SADD & SDIFF with non-existing first key",
// commands: []HTTPCommand{
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
// {Command: "SDIFF", Body: map[string]interface{}{"key1": "foo2", "key2": "foo"}},
// },
// assert_type: []string{"equal", "equal", "array"},
// expected: []interface{}{float64(1), float64(1), []any{}},
//},
//{
// name: "SADD & SDIFF with one key",
// commands: []HTTPCommand{
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
// {Command: "SDIFF", Body: map[string]interface{}{"key": "foo"}},
// },
// assert_type: []string{"equal", "equal", "array"},
// expected: []interface{}{float64(1), float64(1), []any{string("bar"), string("baz")}},
//},
//{
// name: "SADD & SINTER",
// commands: []HTTPCommand{
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo2", "value": "baz"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo2", "value": "bax"}},
// {Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
// },
// assert_type: []string{"equal", "equal", "equal", "equal", "array"},
// expected: []interface{}{float64(1), float64(1), float64(1), float64(1), []any{string("baz")}},
//},
//{
// name: "SADD & SINTER with non-existing subsequent key",
// commands: []HTTPCommand{
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
// {Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
// },
// assert_type: []string{"equal", "equal", "array"},
// expected: []interface{}{float64(1), float64(1), []any{}},
//},
//{
// name: "SADD & SINTER with wrong key type",
// commands: []HTTPCommand{
// {Command: "SET", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
// },
// assert_type: []string{"equal", "equal"},
// expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
//},
//{
// name: "SADD & SINTER with subsequent key of wrong type",
// commands: []HTTPCommand{
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
// {Command: "SET", Body: map[string]interface{}{"key": "foo2", "value": "bar"}},
// {Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo", "foo2"}}},
// },
// assert_type: []string{"equal", "equal", "equal", "equal"},
// expected: []interface{}{float64(1), float64(1), "OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
//},
//{
// name: "SADD & SINTER with single key",
// commands: []HTTPCommand{
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "bar"}},
// {Command: "SADD", Body: map[string]interface{}{"key": "foo", "value": "baz"}},
// {Command: "SINTER", Body: map[string]interface{}{"values": []interface{}{"foo"}}},
// },
// assert_type: []string{"equal", "equal", "array"},
// expected: []interface{}{float64(1), float64(1), []any{string("bar"), string("baz")}},
//},
}

defer exec.FireCommand(HTTPCommand{
Expand Down
7 changes: 3 additions & 4 deletions integration_tests/commands/http/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (
"sync"
"time"

"github.com/dicedb/dice/internal/server/utils"
"github.com/dicedb/dice/internal/server/httpws"

"github.com/dicedb/dice/config"
derrors "github.com/dicedb/dice/internal/errors"
"github.com/dicedb/dice/internal/querymanager"
"github.com/dicedb/dice/internal/server"
"github.com/dicedb/dice/internal/shard"
dstore "github.com/dicedb/dice/internal/store"
)
Expand Down Expand Up @@ -88,7 +87,7 @@ func (e *HTTPCommandExecutor) FireCommand(cmd HTTPCommand) (interface{}, error)
defer resp.Body.Close()

if cmd.Command != "Q.WATCH" {
var result utils.HTTPResponse
var result httpws.HTTPResponse
err = json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
return nil, err
Expand Down Expand Up @@ -119,7 +118,7 @@ func RunHTTPServer(ctx context.Context, wg *sync.WaitGroup, opt TestServerOption
queryWatcherLocal := querymanager.NewQueryManager()
config.DiceConfig.HTTP.Port = opt.Port
// Initialize the HTTPServer
testServer := server.NewHTTPServer(shardManager, nil)
testServer := httpws.NewHTTPServer(shardManager, nil)
// Inform the user that the server is starting
fmt.Println("Starting the test server on port", config.DiceConfig.HTTP.Port)
shardManagerCtx, cancelShardManager := context.WithCancel(ctx)
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/commands/http/touch_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//go:build ignore
// +build ignore

// Ignored as multishard commands not supported by HTTP
package http

import (
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/commands/resp/command_getkeys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var getKeysTestCases = []struct {
{"Get command", "get key", []interface{}{"key"}},
{"TTL command", "ttl key", []interface{}{"key"}},
{"Del command", "del 1 2 3 4 5 6", []interface{}{"1", "2", "3", "4", "5", "6"}},
{"MSET command", "MSET key1 val1 key2 val2", []interface{}{"key1", "key2"}},
// TODO: Fix this for multi shard support
//{"MSET command", "MSET key1 val1 key2 val2", []interface{}{"key1", "key2"}},
{"Expire command", "expire key time extra", []interface{}{"key"}},
{"Ping command", "ping", "ERR the command has no key arguments"},
{"Invalid Get command", "get", "ERR invalid number of arguments specified for command"},
Expand Down
8 changes: 8 additions & 0 deletions integration_tests/commands/resp/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ func TestType(t *testing.T) {
// commands: []string{"SET key1 \"foobar\"", "SET key2 \"abcdef\"", "TYPE dest"},
// expected: []interface{}{"OK", "OK", "string"},
// },
{
name: "TYPE for key with Zset value",
commands: []string{
"ZADD myzetset 1 'one' 2 'two'",
"TYPE myzetset",
},
expected: []interface{}{int64(2), "zset"},
},
}

for _, tc := range testCases {
Expand Down
Loading
Loading