func TestAppendKey(t *testing.T) { db := abkleveldb.CreateDB(dbpath) status := appendKey("abc:name:first", "title", db) expectedVal := "key::abc:name:first:title" resultVal := abkleveldb.GetVal("key::abc:name:first", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } status = appendKey("abc", "name", db) expectedVal = "key::abc:name" resultVal = abkleveldb.GetVal("key::abc", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } status = appendKey("abc", "age", db) expectedVal = "key::abc:name,key::abc:age" resultVal = abkleveldb.GetVal("key::abc", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestCreateNS(t *testing.T) { db := abkleveldb.CreateDB(dbpath) status := CreateNS("abc:name:first", db) expectedVal := "key::abc:name:first" resultVal := abkleveldb.GetVal("key::abc:name", db) if expectedVal != resultVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } status = CreateNS("abc:name:last", db) expectedVal = "key::abc:name:first,key::abc:name:last" resultVal = abkleveldb.GetVal("key::abc:name", db) if expectedVal != resultVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } status = CreateNS("abc:name:last", db) expectedVal = "key::abc:name:first,key::abc:name:last" resultVal = abkleveldb.GetVal("key::abc:name", db) if expectedVal != resultVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestDeleteNSRecursive(t *testing.T) { db := abkleveldb.CreateDB(dbpath) setupTestData(db) status := DeleteNSRecursive("abc", db) expectedVal := "" resultVal := abkleveldb.GetVal("key::abc", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } expectedVal = "" resultVal = abkleveldb.GetVal("key::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } expectedVal = "" resultVal = abkleveldb.GetVal("val::abc:name:first", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } expectedVal = "" resultVal = abkleveldb.GetVal("val::abc:name:last", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestDeleteNSKey(t *testing.T) { db := abkleveldb.CreateDB(dbpath) setupTestData(db) status := DeleteNSKey("abc:name:last", db) expectedVal := "" resultVal := abkleveldb.GetVal("val::abc:name:last", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } expectedVal = "ABC" resultVal = abkleveldb.GetVal("val::abc:name:first", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } status = DeleteNSKey("abc:name:last", db) if !status { t.Error("Fail: Success in deleting non-existent key.") } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func exampleNS(db *levigo.DB) { runtime.GOMAXPROCS(runtime.NumCPU()) fmt.Println("add some data first for a,a:1,a:2,a:1:2,a:2:1,a:3,a:1:1 ~") lns.PushNS("a", "A", db) lns.PushNS("a:1", "A1", db) lns.PushNS("a:2", "A2", db) lns.PushNS("a:1:2", "A12", db) lns.PushNS("a:2:1", "A21", db) lns.PushNS("a:3", "A3", db) lns.PushNS("a:1:1", "A11", db) lns.PushNS("b:2:1", "A11", db) fmt.Println("read some data now ~") read("val::a", db) read("val::a:1", db) read("val::a:2", db) read("val::a:1:2", db) read("val::a:2:1", db) read("val::a:3", db) read("val::a:1:1", db) fmt.Println("super keys~") read("key::a", db) read("key::a:1", db) read("key::a:2", db) read("key::b", db) read("key::b:2", db) var hmap map[string]string hmap = make(map[string]string) hmap = lns.ReadNS("key::a", db) for k, v := range hmap { fmt.Printf("%s => %s\n", k, v) } hmap = lns.ReadNS("key::c", db) for k, v := range hmap { fmt.Printf("%s => %s", k, v) } fmt.Println("read/delete~") fmt.Printf("Recursive under a: %v\n", lns.ReadNSRecursive("a", db)) fmt.Println("before del a:1:2 ~ ", abkleveldb.GetVal("key::a:1", db)) lns.DeleteNSRecursive("a:1:2", db) fmt.Println("after del of a:1:2 ~ ", abkleveldb.GetVal("key::a:1", db)) fmt.Printf("Recursive under a: %v\n", lns.ReadNSRecursive("a", db)) fmt.Println("before del a ~ ", abkleveldb.GetVal("key::a", db)) lns.DeleteNSRecursive("a", db) fmt.Println("after del a ~ ", abkleveldb.GetVal("key::a", db)) fmt.Printf("Recursive under a: %v\n", lns.ReadNSRecursive("a", db)) fmt.Printf("Recursive under b: %v\n", lns.ReadNSRecursive("b", db)) fmt.Println("before del of b ~", abkleveldb.GetVal("key::b", db)) lns.DeleteNS("b", db) fmt.Println("after del of b ~ ", abkleveldb.GetVal("key::b", db)) fmt.Println("after del b:2 ~ ", abkleveldb.GetVal("key::b:2", db)) fmt.Println("after del b:2:1 ~ ", abkleveldb.GetVal("key::b:2:1", db)) fmt.Printf("Recursive under b: %v\n", lns.ReadNSRecursive("b", db)) }
func TestDeleteNSChildren(t *testing.T) { db := abkleveldb.CreateDB(dbpath) setupTestData(db) expectedVal := "ABC XYZ" resultVal := abkleveldb.GetVal("val::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Pre-req is bad.") } status := deleteNSChildren("key::abc:name", db) expectedVal = "" resultVal = abkleveldb.GetVal("val::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } expectedVal = "" resultVal = abkleveldb.GetVal("key::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } expectedVal = "XYZ" resultVal = abkleveldb.GetVal("val::abc:name:last", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } status = deleteNSChildren("key::abc:name:first,key::abc:name:last", db) expectedVal = "" resultVal = abkleveldb.GetVal("val::abc:name:first", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
/* Get value of given key */ func ReadKey(key string) golhashmap.HashMap { var hashmap golhashmap.HashMap hashmap = make(golhashmap.HashMap) val := abkleveldb.GetVal(key, db) if val == "" { return hashmap } hashmap[key] = val return hashmap }
func TestPushNS(t *testing.T) { db := abkleveldb.CreateDB(dbpath) status := PushNS("abc:name", "ABC XYZ", db) expectedVal := "ABC XYZ" resultVal := abkleveldb.GetVal("val::abc:name", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } if !status { t.Error("Fail: Failed Status for", expectedVal) } expectedVal = "key::abc:name" resultVal = abkleveldb.GetVal("key::abc", db) if resultVal != expectedVal { t.Error("Fail: Get", resultVal, "instead of", expectedVal) } abkleveldb.CloseAndDeleteDB(dbpath, db) }
func TestDelKeyNS(t *testing.T) { setupTestData() status := DelKeyNS("upstate:2014") expected_val := "" result_val := abkleveldb.GetVal("val::upstate:2014:January:2:12:1:20", db) if expected_val != result_val { t.Error("Fail: Get", result_val, "instead of", expected_val) } if !status { t.Error("Fail: Wrong status returned by DelKeyNS") } abkleveldb.CloseAndDeleteDB(test_dbpath, db) }
func TestPushKeyValNS(t *testing.T) { setupTestData() expected_val := "right" status := PushKeyValNS("oh:yeah", expected_val) result_val := abkleveldb.GetVal("val::oh:yeah", db) if expected_val != result_val { t.Error("Fail: Get", result_val, "instead of", expected_val) } if !status { t.Error("Fail: Wrong status returned by PushKeyValNS") } abkleveldb.CloseAndDeleteDB(test_dbpath, db) }
func TestPushKeyValTSDS(t *testing.T) { setupTestData() ohtime := goltime.Timestamp{ Year: 2014, Month: 1, Day: 2, Hour: 12, Min: 1, Sec: 20, } status := PushKeyValTSDS("oh", "yeah", ohtime) expected_val := "yeah" result_val := abkleveldb.GetVal("val::oh:2014:January:2:12:1:20", db) if expected_val != result_val { t.Error("Fail: Get", result_val, "instead of", expected_val) } if !status { t.Error("Fail: Wrong status returned by PushKeyValTSDS") } abkleveldb.CloseAndDeleteDB(test_dbpath, db) }
func TestPushKeyValTSDS(t *testing.T) { setupTestData() packet := Packet{} packet.HashMap = make(golhashmap.HashMap) packet.HashMap["oh"] = "yeah" packet.ParentNS = "phrase" packet.TimeDot = goltime.Timestamp{ Year: 2014, Month: 1, Day: 2, Hour: 12, Min: 1, Sec: 20, } packet.KeyType = "tsds" status := PushFromPacket(packet) expected_val := "yeah" result_val := abkleveldb.GetVal("val::oh:2014:January:2:12:1:20", db) golassert.AssertEqual(expected_val, result_val) if !status { t.Error("Fail: Wrong status returned by PushKeyValTSDS") } abkleveldb.CloseAndDeleteDB(test_dbpath, db) }
/* Get value of given key */ func GetVal(key string) string { return abkleveldb.GetVal(key, db) }
func read(key string, db *levigo.DB) string { val := abkleveldb.GetVal(key, db) fmt.Printf("for %s get %s\n", key, val) return val }