-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #735 from emqx/dev/1.1.2
Dev/1.1.2
- Loading branch information
Showing
117 changed files
with
3,936 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kv | ||
|
||
type KeyValue interface { | ||
Open() error | ||
Close() error | ||
// Set key to hold string value if key does not exist otherwise return an error | ||
Setnx(key string, value interface{}) error | ||
// Set key to hold the string value. If key already holds a value, it is overwritten | ||
Set(key string, value interface{}) error | ||
Get(key string, val interface{}) (bool, error) | ||
//Must return *common.Error with NOT_FOUND error | ||
Delete(key string) error | ||
Keys() (keys []string, err error) | ||
Clean() error | ||
} | ||
|
||
func GetDefaultKVStore(fpath string) (ret KeyValue) { | ||
return GetSqliteKVStore(fpath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package kv | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestSqliteKVStore_Funcs(t *testing.T) { | ||
abs, _ := filepath.Abs("test") | ||
if f, _ := os.Stat(abs); f != nil { | ||
os.Remove(abs) | ||
} | ||
|
||
ks := GetSqliteKVStore(abs) | ||
if e := ks.Open(); e != nil { | ||
t.Errorf("Failed to open data %s.", e) | ||
} | ||
|
||
if err := ks.Setnx("foo", "bar"); nil != err { | ||
t.Error(err) | ||
} | ||
|
||
var v string | ||
if ok, _ := ks.Get("foo", &v); ok { | ||
if !reflect.DeepEqual("bar", v) { | ||
t.Error("expect:bar", "get:", v) | ||
} | ||
} else { | ||
t.Errorf("Should not find the foo key.") | ||
} | ||
|
||
if err := ks.Setnx("foo1", "bar1"); nil != err { | ||
t.Error(err) | ||
} | ||
|
||
if err := ks.Set("foo1", "bar2"); nil != err { | ||
t.Error(err) | ||
} | ||
|
||
var v1 string | ||
if ok, _ := ks.Get("foo1", &v1); ok { | ||
if !reflect.DeepEqual("bar2", v1) { | ||
t.Error("expect:bar2", "get:", v1) | ||
} | ||
} else { | ||
t.Errorf("Should not find the foo1 key.") | ||
} | ||
|
||
if keys, e1 := ks.Keys(); e1 != nil { | ||
t.Errorf("Failed to get value: %s.", e1) | ||
} else { | ||
if !reflect.DeepEqual(2, len(keys)) { | ||
t.Error("expect:2", "get:", len(keys)) | ||
} | ||
} | ||
|
||
if e2 := ks.Close(); e2 != nil { | ||
t.Errorf("Failed to close data: %s.", e2) | ||
} | ||
|
||
if err := ks.Open(); nil != err { | ||
t.Error(err) | ||
} | ||
|
||
var v2 string | ||
if ok, _ := ks.Get("foo", &v2); ok { | ||
if !reflect.DeepEqual("bar", v2) { | ||
t.Error("expect:bar", "get:", v) | ||
} | ||
} else { | ||
t.Errorf("Should not find the foo key.") | ||
} | ||
|
||
if err := ks.Delete("foo1"); nil != err { | ||
t.Error(err) | ||
} | ||
|
||
if keys, e1 := ks.Keys(); e1 != nil { | ||
t.Errorf("Failed to get value: %s.", e1) | ||
} else { | ||
reflect.DeepEqual(1, len(keys)) | ||
} | ||
|
||
if err := ks.Clean(); nil != err { | ||
t.Error(err) | ||
} | ||
|
||
if keys, e1 := ks.Keys(); e1 != nil { | ||
t.Errorf("Failed to get value: %s.", e1) | ||
} else { | ||
reflect.DeepEqual(0, len(keys)) | ||
} | ||
|
||
dir, _ := filepath.Split(abs) | ||
abs = path.Join(dir, "sqliteKV.db") | ||
os.Remove(abs) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.