You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by GitBox <gi...@apache.org> on 2022/09/10 16:33:10 UTC
[GitHub] [incubator-kvrocks] git-hulk opened a new pull request, #846: Move tcl keyspace test cases to Go
git-hulk opened a new pull request, #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846
This closes #841
I think it's a bit wordy to add the directory for only one file, so I used the `keyspace_test.go` instead of `keyspace/keyspace_test.go`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] tisonkun commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
tisonkun commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967741650
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/assert"
Review Comment:
I suggest always using `require` to avoid unnecessary dirty states. We just fail fast.
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ assert.Nil(t, rdb.Set(ctx, key, value, 0).Err())
Review Comment:
```suggestion
require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
```
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ assert.Nil(t, rdb.Set(ctx, key, value, 0).Err())
Review Comment:
ditto others
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967749908
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
+ })
+
+ t.Run("RANDOMKEY", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "foo", "x", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "bar", "y", 0).Err())
+
+ fooSeen := 0
+ barSeen := 0
+ for i := 0; i < 1000; i++ {
+ randomKey := rdb.RandomKey(ctx).Val()
+ if randomKey == "foo" {
+ fooSeen = 1
+ } else if randomKey == "bar" {
+ barSeen = 1
+ }
+ if fooSeen == 1 || barSeen == 1 {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ require.Greater(t, fooSeen+barSeen, 0)
+ })
+
+ t.Run("RANDOMKEY against empty DB", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("RANDOMKEY regression 1", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "x", 10, 0).Err())
+ require.Equal(t, int64(1), rdb.Del(ctx, "x").Val())
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("KEYS * two times with long key, Github issue #1208", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "dlskeriewrioeuwqoirueioqwrueoqwrueqw", "teset", 0).Err())
+ require.Equal(t, []string{"dlskeriewrioeuwqoirueioqwrueoqwrueqw"}, rdb.Keys(ctx, "*").Val())
Review Comment:
Got it, thanks. Just keep those two lines.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] tisonkun commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
tisonkun commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967746224
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
Review Comment:
Does `dbsize scan` asynchorously? Why we need to sleep here?
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
+ })
+
+ t.Run("RANDOMKEY", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "foo", "x", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "bar", "y", 0).Err())
+
+ fooSeen := 0
+ barSeen := 0
+ for i := 0; i < 1000; i++ {
+ randomKey := rdb.RandomKey(ctx).Val()
+ if randomKey == "foo" {
+ fooSeen = 1
+ } else if randomKey == "bar" {
+ barSeen = 1
+ }
+ if fooSeen == 1 || barSeen == 1 {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ require.Greater(t, fooSeen+barSeen, 0)
+ })
+
+ t.Run("RANDOMKEY against empty DB", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("RANDOMKEY regression 1", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "x", 10, 0).Err())
+ require.Equal(t, int64(1), rdb.Del(ctx, "x").Val())
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("KEYS * two times with long key, Github issue #1208", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "dlskeriewrioeuwqoirueioqwrueoqwrueqw", "teset", 0).Err())
+ require.Equal(t, []string{"dlskeriewrioeuwqoirueioqwrueoqwrueqw"}, rdb.Keys(ctx, "*").Val())
Review Comment:
```suggestion
require.Equal(t, []string{"dlskeriewrioeuwqoirueioqwrueoqwrueqw"}, rdb.Keys(ctx, "*").Val())
require.Equal(t, []string{"dlskeriewrioeuwqoirueioqwrueoqwrueqw"}, rdb.Keys(ctx, "*").Val())
```
I think the things to be tested here is "KEYS * two times"
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
Review Comment:
If you use `require.EqualValues`, you don't need to cast between integers. But this is no a requirement. Just for your information and current style is OK for me, too.
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
Review Comment:
Missing
```tcl
test {DBSIZE} {
r dbsize scan
after 100
r dbsize
} {6}
```
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
+ })
+
+ t.Run("RANDOMKEY", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "foo", "x", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "bar", "y", 0).Err())
+
+ fooSeen := 0
+ barSeen := 0
+ for i := 0; i < 1000; i++ {
+ randomKey := rdb.RandomKey(ctx).Val()
+ if randomKey == "foo" {
+ fooSeen = 1
+ } else if randomKey == "bar" {
+ barSeen = 1
+ }
+ if fooSeen == 1 || barSeen == 1 {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ require.Greater(t, fooSeen+barSeen, 0)
+ })
+
+ t.Run("RANDOMKEY against empty DB", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("RANDOMKEY regression 1", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "x", 10, 0).Err())
+ require.Equal(t, int64(1), rdb.Del(ctx, "x").Val())
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("KEYS * two times with long key, Github issue #1208", func(t *testing.T) {
Review Comment:
This is for the Redis issue number?
```suggestion
t.Run("KEYS * two times with long key - Redis Github issue #1208", func(t *testing.T) {
```
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
Review Comment:
```suggestion
util.ErrorRegexp(t, rdb.Do(ctx, "foobaredcommand").Err(), "ERR.*")
```
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
Review Comment:
Missing
```tcl
test {DBSIZE} {
r dbsize scan
after 100
r dbsize
} {6}
```
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
Review Comment:
Missing
```tcl
test {DBSIZE} {
r dbsize scan
after 100
r dbsize
} {6}
```
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
+ })
+
+ t.Run("RANDOMKEY", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "foo", "x", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "bar", "y", 0).Err())
+
+ fooSeen := 0
+ barSeen := 0
+ for i := 0; i < 1000; i++ {
+ randomKey := rdb.RandomKey(ctx).Val()
+ if randomKey == "foo" {
+ fooSeen = 1
+ } else if randomKey == "bar" {
+ barSeen = 1
+ }
+ if fooSeen == 1 || barSeen == 1 {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
Review Comment:
Why do we need to sleep here?
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
+ })
+
+ t.Run("RANDOMKEY", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "foo", "x", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "bar", "y", 0).Err())
+
+ fooSeen := 0
+ barSeen := 0
+ for i := 0; i < 1000; i++ {
+ randomKey := rdb.RandomKey(ctx).Val()
+ if randomKey == "foo" {
+ fooSeen = 1
+ } else if randomKey == "bar" {
+ barSeen = 1
+ }
+ if fooSeen == 1 || barSeen == 1 {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ require.Greater(t, fooSeen+barSeen, 0)
Review Comment:
If you'd like to write as:
```go
if fooSeen == 1 || barSeen == 1 {
break
}
```
I suggest:
```go
for i := 0; i < 1000; i++ {
randomKey := rdb.RandomKey(ctx).Val()
switch randomKey {
case "foo", "bar":
return
}
}
require.Fail(t, "RANDOMKEY never hits foo or bar")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk merged pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk merged PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk commented on PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#issuecomment-1242879735
Thanks for @tisonkun carefully review, will merge after the CI become green.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967748488
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
Review Comment:
Yes, the DB scan is asynchronous, so need to wait a moment. Current behavior is consistent with tcl test cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967748725
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
Review Comment:
Good catch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967745273
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/assert"
Review Comment:
Fixed, you're right that previous steps failed will affect the successor steps in most test cases, so it's better to use require instead of assert.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967748979
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
+ })
+
+ t.Run("RANDOMKEY", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "foo", "x", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "bar", "y", 0).Err())
+
+ fooSeen := 0
+ barSeen := 0
+ for i := 0; i < 1000; i++ {
+ randomKey := rdb.RandomKey(ctx).Val()
+ if randomKey == "foo" {
+ fooSeen = 1
+ } else if randomKey == "bar" {
+ barSeen = 1
+ }
+ if fooSeen == 1 || barSeen == 1 {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ require.Greater(t, fooSeen+barSeen, 0)
+ })
+
+ t.Run("RANDOMKEY against empty DB", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("RANDOMKEY regression 1", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "x", 10, 0).Err())
+ require.Equal(t, int64(1), rdb.Del(ctx, "x").Val())
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("KEYS * two times with long key, Github issue #1208", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "dlskeriewrioeuwqoirueioqwrueoqwrueqw", "teset", 0).Err())
+ require.Equal(t, []string{"dlskeriewrioeuwqoirueioqwrueoqwrueqw"}, rdb.Keys(ctx, "*").Val())
Review Comment:
Yes, I saw this but I think this line should be duplicate.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967745311
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/assert"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ assert.Nil(t, rdb.Set(ctx, key, value, 0).Err())
Review Comment:
all replace with `NoError`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967750061
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
+ })
+
+ t.Run("RANDOMKEY", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "foo", "x", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "bar", "y", 0).Err())
+
+ fooSeen := 0
+ barSeen := 0
+ for i := 0; i < 1000; i++ {
+ randomKey := rdb.RandomKey(ctx).Val()
+ if randomKey == "foo" {
+ fooSeen = 1
+ } else if randomKey == "bar" {
+ barSeen = 1
+ }
+ if fooSeen == 1 || barSeen == 1 {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
Review Comment:
We random by time seed, so it may always get the same seed if requests fast enough. But the case looks good until now, so let's remove the sleep.
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
+ })
+
+ t.Run("RANDOMKEY", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "foo", "x", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "bar", "y", 0).Err())
+
+ fooSeen := 0
+ barSeen := 0
+ for i := 0; i < 1000; i++ {
+ randomKey := rdb.RandomKey(ctx).Val()
+ if randomKey == "foo" {
+ fooSeen = 1
+ } else if randomKey == "bar" {
+ barSeen = 1
+ }
+ if fooSeen == 1 || barSeen == 1 {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
Review Comment:
We random by time seed, so it may always get the same seed if requests fast enough. But the case looks good until now, so let's remove the sleep.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] git-hulk commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
git-hulk commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967749703
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
Review Comment:
This's good suggestion, have done.
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
Review Comment:
This's a good suggestion, have done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-kvrocks] tisonkun commented on a diff in pull request #846: Move tcl keyspace test cases to Go
Posted by GitBox <gi...@apache.org>.
tisonkun commented on code in PR #846:
URL: https://github.com/apache/incubator-kvrocks/pull/846#discussion_r967749497
##########
tests/gocase/unit/keyspace_test.go:
##########
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package unit
+
+import (
+ "context"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+)
+
+func TestKeyspace(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(t, rdb.Close()) }()
+
+ t.Run("DEL against a single item", func(t *testing.T) {
+ key := "x"
+ value := "foo"
+ require.NoError(t, rdb.Set(ctx, key, value, 0).Err())
+ require.Equal(t, value, rdb.Get(ctx, key).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, key).Val())
+ require.Equal(t, "", rdb.Get(ctx, key).Val())
+ })
+
+ t.Run("Vararg DEL", func(t *testing.T) {
+ require.NoError(t, rdb.Set(ctx, "foo1", "a", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo2", "b", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "foo3", "c", 0).Err())
+ require.Equal(t, int64(3), rdb.Del(ctx, "foo1", "foo2", "foo3").Val())
+ require.Equal(t, []interface{}{nil, nil, nil}, rdb.MGet(ctx, "foo1", "foo2", "foo3").Val())
+ })
+
+ t.Run("KEYS with pattern", func(t *testing.T) {
+ for _, key := range []string{"key_x", "key_y", "key_z", "foo_a", "foo_b", "foo_c"} {
+ require.NoError(t, rdb.Set(ctx, key, "hello", 0).Err())
+ }
+ keys := rdb.Keys(ctx, "foo*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c"}, keys)
+ })
+
+ t.Run("KEYS to get all keys", func(t *testing.T) {
+ keys := rdb.Keys(ctx, "*").Val()
+ sort.Slice(keys, func(i, j int) bool {
+ return keys[i] < keys[j]
+ })
+ require.Equal(t, []string{"foo_a", "foo_b", "foo_c", "key_x", "key_y", "key_z"}, keys)
+ })
+
+ t.Run("DEL all keys", func(t *testing.T) {
+ vals := rdb.Keys(ctx, "*").Val()
+ require.Equal(t, int64(len(vals)), rdb.Del(ctx, vals...).Val())
+ require.NoError(t, rdb.Do(ctx, "dbsize", "scan").Err())
+ time.Sleep(100 * time.Millisecond)
+ require.Equal(t, int64(0), rdb.Do(ctx, "dbsize").Val())
+ })
+
+ t.Run("EXISTS", func(t *testing.T) {
+ newKey := "newkey"
+ require.NoError(t, rdb.Set(ctx, newKey, "test", 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, newKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, newKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, newKey).Val())
+ })
+
+ t.Run("Zero length value in key. SET/GET/EXISTS", func(t *testing.T) {
+ emptyKey := "emptykey"
+ require.NoError(t, rdb.Set(ctx, emptyKey, nil, 0).Err())
+ require.Equal(t, int64(1), rdb.Exists(ctx, emptyKey).Val())
+ require.Equal(t, int64(1), rdb.Del(ctx, emptyKey).Val())
+ require.Equal(t, int64(0), rdb.Exists(ctx, emptyKey).Val())
+ })
+
+ t.Run("Commands pipelining", func(t *testing.T) {
+ c := srv.NewTCPClient()
+ defer func() { require.NoError(t, c.Close()) }()
+ require.NoError(t, c.Write("SET k1 xyzk\r\nGET k1\r\nPING\r\n"))
+ r, err := c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+OK", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "$4", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "xyzk", r)
+ r, err = c.ReadLine()
+ require.NoError(t, err)
+ require.Equal(t, "+PONG", r)
+ })
+
+ t.Run("Non existing command", func(t *testing.T) {
+ require.Contains(t, rdb.Do(ctx, "foobaredcommand").Err().Error(), "ERR")
+ })
+
+ t.Run("RANDOMKEY", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "foo", "x", 0).Err())
+ require.NoError(t, rdb.Set(ctx, "bar", "y", 0).Err())
+
+ fooSeen := 0
+ barSeen := 0
+ for i := 0; i < 1000; i++ {
+ randomKey := rdb.RandomKey(ctx).Val()
+ if randomKey == "foo" {
+ fooSeen = 1
+ } else if randomKey == "bar" {
+ barSeen = 1
+ }
+ if fooSeen == 1 || barSeen == 1 {
+ break
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ require.Greater(t, fooSeen+barSeen, 0)
+ })
+
+ t.Run("RANDOMKEY against empty DB", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("RANDOMKEY regression 1", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "x", 10, 0).Err())
+ require.Equal(t, int64(1), rdb.Del(ctx, "x").Val())
+ require.Equal(t, "", rdb.RandomKey(ctx).Val())
+ })
+
+ t.Run("KEYS * two times with long key, Github issue #1208", func(t *testing.T) {
+ rdb.FlushDB(ctx)
+ require.NoError(t, rdb.Set(ctx, "dlskeriewrioeuwqoirueioqwrueoqwrueqw", "teset", 0).Err())
+ require.Equal(t, []string{"dlskeriewrioeuwqoirueioqwrueoqwrueqw"}, rdb.Keys(ctx, "*").Val())
Review Comment:
No. The case is that Redis once encounter an issue that if run `KEY *` twice, it will fail. I tend to keep these two lines or we just rename/remove the test case.
See also https://github.com/redis/redis/issues/1208.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org