Skip to content

Commit

Permalink
Merge pull request #25 from torden/develop
Browse files Browse the repository at this point in the history
improve mdbm,mdbm_test,example_test
  • Loading branch information
torden committed Dec 21, 2017
2 parents 12c53c1 + 0cf0824 commit 6fcfe3a
Show file tree
Hide file tree
Showing 7 changed files with 1,140 additions and 284 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ endif
test: clean
@$(CMD_MKDIR) -p $(PATH_REPORT)/raw/ $(PATH_REPORT)/doc/
@$(CMD_ECHO) -e "\033[1;40;32mRun Go Test.\033[01;m\x1b[0m"
@GORACE="log_path=$(PATH_REPORT)/doc/$(PATH_RACE_REPORT)" $(CMD_GO) test -tags unittest -v -test.parallel 4 -race -coverprofile=$(PATH_REPORT)/raw/$(PATH_CONVER_PROFILE)
@GORACE="log_path=$(PATH_REPORT)/doc/$(PATH_RACE_REPORT)" $(CMD_GO) test -v -test.parallel 4 -race -coverprofile=$(PATH_REPORT)/raw/$(PATH_CONVER_PROFILE)
@$(CMD_ECHO) -e "\033[1;40;36mGenerated a report of data race detection in $(PATH_REPORT)/doc/$(PATH_RACE_REPORT).pid\033[01;m\x1b[0m"
@$(CMD_ECHO) -e "\033[1;40;36mDone\033[01;m\x1b[0m"

Expand Down
35 changes: 19 additions & 16 deletions const_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package mdbm_test

const (
loopLimit = 65534
pathTestDBM1 = "/tmp/test1.mdbm"
pathTestDBM2 = "/tmp/test2.mdbm"
pathTestDBM3 = "/tmp/test3.mdbm"
pathTestDBMLarge = "/tmp/test_large.mdbm"
pathTestDBMHash = "/tmp/test_hash.mdbm"
pathTestDBMDup = "/tmp/test_dup.mdbm"
pathTestDBMCache = "/tmp/test_cache.mdbm"
pathTestDBMV2 = "/tmp/test_v2.mdbm"
pathTestDBMLock1 = "/tmp/test_lock1.mdbm"
pathTestDBMDelete = "/tmp/test_delete.mdbm"
pathTestDBMLock2 = "/tmp/test_lock2.mdbm"
pathTestDBMLock3 = "/tmp/test_lock3.mdbm"
pathTestDBMAnyDataType = "/tmp/test_anydatatype.mdbm"
pathTestDBMStr = "/tmp/test_str.mdbm"
pathTestDBMReplace = "/tmp/test_replaced.mdbm"
loopLimit = 65534
pathTestDBM1 = "/tmp/test1.mdbm"
pathTestDBM2 = "/tmp/test2.mdbm"
pathTestDBM3 = "/tmp/test3.mdbm"
pathTestDBMLarge = "/tmp/test_large.mdbm"
pathTestDBMHash = "/tmp/test_hash.mdbm"
pathTestDBMDup = "/tmp/test_dup.mdbm"
pathTestDBMCache = "/tmp/test_cache.mdbm"
pathTestDBMCacheNoneData = "/tmp/test_cache_nonedata.mdbm"
pathTestDBMV2 = "/tmp/test_v2.mdbm"
pathTestDBMLock1 = "/tmp/test_lock1.mdbm"
pathTestDBMDelete = "/tmp/test_delete.mdbm"
pathTestDBMLock2 = "/tmp/test_lock2.mdbm"
pathTestDBMLock3 = "/tmp/test_lock3.mdbm"
pathTestDBMAnyDataType1 = "/tmp/test_anydatatype1.mdbm"
pathTestDBMAnyDataType2 = "/tmp/test_anydatatype2.mdbm"
pathTestDBMStr = "/tmp/test_str.mdbm"
pathTestDBMStrAnyLock = "/tmp/test_str_anylock.mdbm"
pathTestDBMReplace = "/tmp/test_replaced.mdbm"
)
49 changes: 14 additions & 35 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,21 @@ func Example_mdbm_EasyOpen_EasyClose() {
if err != nil {
log.Fatalf("failed mdbm.EasyOpen(%s), err=%v", path, err)
}
fmt.Println(err)

rv, err := dbm.EnableStatOperations(mdbm.StatsTimed)
if err != nil {
log.Fatalf("failed dbm.EnableStatOperations(mdbm.StatsTimed), rv=%d, err=%v", rv, err)
}

fmt.Println(err)
rv, err = dbm.SetStatTimeFunc(mdbm.ClockTsc)
rv, err = dbm.SetStatTimeFunc(mdbm.ClockTSC)
if err != nil {
log.Fatalf("failed dbm.SetStatTimeFunc(mdbm.ClockTsc), rv=%d, err=%v", rv, err)
log.Fatalf("failed dbm.SetStatTimeFunc(mdbm.ClockTSC), rv=%d, err=%v", rv, err)
}

fmt.Println(err)

dbm.EasyClose()
}

// Output:
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
// <nil>
}

func Example_mdbm_Open_Close() {
Expand All @@ -70,7 +45,7 @@ func Example_mdbm_Open_Close() {

_, err = dbm.EnableStatOperations(mdbm.StatsTimed)
fmt.Println(err)
_, err = dbm.SetStatTimeFunc(mdbm.ClockTsc)
_, err = dbm.SetStatTimeFunc(mdbm.ClockTSC)
fmt.Println(err)

dbm.Close()
Expand Down Expand Up @@ -107,9 +82,13 @@ func Example_mdbm_GetErrNo() {

func Example_mdbm_LogMinLevel() {

var err error

dbm := mdbm.NewMDBM()
err := dbm.EasyOpen(pathTestDBM1, 0644)
defer dbm.EasyClose()
if err != nil {
log.Fatalf("failed mdbm.EasyOpen(), err=%v", err)
}

err = dbm.LogMinLevel(mdbm.LogEmerg)
fmt.Println(err)
err = dbm.LogMinLevel(mdbm.LogAlert)
Expand Down Expand Up @@ -219,7 +198,7 @@ func Example_mdbm_IsLocked() {
dbm := mdbm.NewMDBM()
err := dbm.Open(pathTestDBMLock1, mdbm.Create|mdbm.Rdrw|mdbm.RwLocks, 0644, 0, 0)
if err != nil {
log.Fatalf("failed mdbm.EasyOpen(), err=%v", err)
log.Fatalf("failed mdbm.EasyOpen(=%s), err=%v", pathTestDBMLock1, err)
}
fmt.Println("EasyOpen : ", err)

Expand Down Expand Up @@ -247,7 +226,7 @@ func Example_mdbm_LockShared() {
dbm := mdbm.NewMDBM()
err := dbm.Open(pathTestDBMLock1, mdbm.Create|mdbm.Rdrw|mdbm.RwLocks, 0644, 0, 0)
if err != nil {
log.Fatalf("failed mdbm.Open(mdbm.Create|mdbm.Rdrw|mdbm.RwLocks), err=%v", err)
log.Fatalf("failed mdbm.Open(%s, mdbm.Create|mdbm.Rdrw|mdbm.RwLocks), err=%v", pathTestDBMLock1, err)
}
fmt.Println("EasyOpen : ", err)

Expand Down Expand Up @@ -329,7 +308,7 @@ func Example_mdbm_MyLockReset() {
// Unlock : operation not permitted
}

func Example_mdbm_ReplaceDB() {
func Example_mdbm_ReplaceFile() {

dbm := mdbm.NewMDBM()

Expand Down Expand Up @@ -1278,7 +1257,7 @@ func Example_mdbm_SetCacheMode() {

var rv int
dbm := mdbm.NewMDBM()
err := dbm.EasyOpen(pathTestDBMCache, 0644)
err := dbm.EasyOpen(pathTestDBMCacheNoneData, 0644)
if err != nil {
log.Fatalf("failed mdbm.EasyOpen(), err=%v", err)
}
Expand Down Expand Up @@ -1720,7 +1699,7 @@ func Example_mdbm_SetStatTimeFunc() {

fmt.Println(rv, err)

rv, err = dbm.SetStatTimeFunc(mdbm.ClockTsc)
rv, err = dbm.SetStatTimeFunc(mdbm.ClockTSC)
if err != nil {
log.Fatalf("rv=%d, err=%v", rv, err)
}
Expand Down
1 change: 0 additions & 1 deletion mdbm-binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ extern char *get_mdbm_fetch_str_with_lock(MDBM *db, const char *key, int locktyp
}

retval = mdbm_fetch_str(db, key);

common_unlock_func(db, &lockkey, locktype, lockflags);
return retval;
}
Expand Down
Loading

0 comments on commit 6fcfe3a

Please sign in to comment.