Exemplo n.º 1
0
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)
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
0
func TestReadNSRecursive(t *testing.T) {
	_parentKey, _key, _childKey := "abc", "abc:name", "abc:name:last"
	expectedParentKeyVal := "abc:name,ABC XYZ\nabc:name:first,ABC\nabc:name:last,XYZ"
	expectedKeyVal := "abc:name,ABC XYZ\nabc:name:first,ABC\nabc:name:last,XYZ"
	expectedChildKeyVal := "abc:name:last,XYZ"

	db := abkleveldb.CreateDB(dbpath)
	setupTestData(db)

	resultParentKeyVal := golhashmap.HashMapToCSV(ReadNSRecursive(_parentKey, db))
	resultKeyVal := golhashmap.HashMapToCSV(ReadNSRecursive(_key, db))
	resultChildKeyVal := golhashmap.HashMapToCSV(ReadNSRecursive(_childKey, db))

	golassert.AssertEqualStringArray(
		strings.Split(expectedParentKeyVal, "\n"),
		strings.Split(resultParentKeyVal, "\n"),
	)
	golassert.AssertEqualStringArray(
		strings.Split(expectedKeyVal, "\n"),
		strings.Split(resultKeyVal, "\n"),
	)
	golassert.AssertEqualStringArray(
		strings.Split(expectedChildKeyVal, "\n"),
		strings.Split(resultChildKeyVal, "\n"),
	)

	abkleveldb.CloseAndDeleteDB(dbpath, db)
}
Exemplo n.º 4
0
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)
}
Exemplo n.º 5
0
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)
}
Exemplo n.º 6
0
/*
putting together base engine for GoShare
dbpath, httpuri, httpport, rep_port, req_port *string
*/
func GoShareEngine(config Config) {
	runtime.GOMAXPROCS(runtime.NumCPU())

	// remember it will be same DB instance shared across goshare package
	db = abkleveldb.CreateDB(*config["dbpath"])
	if *config["cpuprofile"] != "" {
		f, err := os.Create(*config["cpuprofile"])
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		go func() {
			time.Sleep(100 * time.Second)
			pprof.StopCPUProfile()
		}()
	}

	_httpport, err_httpport := strconv.Atoi(*config["httpport"])
	_req_port, err_req_port := strconv.Atoi(*config["req_port"])
	_rep_port, err_rep_port := strconv.Atoi(*config["rep_port"])
	if err_httpport == nil && err_rep_port == nil && err_req_port == nil {
		go GoShareHTTP(*config["httpuri"], _httpport)
		go GoShareZMQ(_req_port, _rep_port)
	} else {
		golerror.Boohoo("Port parameters to bind, error-ed while conversion to number.", true)
	}
}
Exemplo n.º 7
0
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)
}
Exemplo n.º 8
0
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 main() {
	startTime := time.Now()
	runtime.GOMAXPROCS(runtime.NumCPU())
	var db *levigo.DB
	fmt.Println("Your DB is referenced at", *dbpath)
	createStartTime := time.Now()
	db = abkleveldb.CreateDB(*dbpath)
	witeMap(db)
	fmt.Println("Writing is over.")
	readMap("127.0.0.1:status:2013:10:26:12", db)
	result := abklevigoNS.ReadNSRecursive("127.0.0.1:status", db)
	readStartTime := time.Now()
	printMapRecursive(result)
	readMap("127.0.0.1:status:2013:10:26", db)
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
	fmt.Printf("\n\nStatistics:\n\tStarted at: %q\n", startTime)
	fmt.Printf("\tCreating DB: %q\n", createStartTime)
	fmt.Printf("\tReading DB: %q\n\tRead For an Hour: %q\n", readStartTime, time.Now())
	fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
	fmt.Println(len(result))
}
Exemplo n.º 10
0
func GoShare() {
	banner()
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Parse()
	db = abkleveldb.CreateDB(*dbpath)
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		go func() {
			time.Sleep(100 * time.Second)
			pprof.StopCPUProfile()
		}()
	}

	// need to go CHAN passing msg to leveldb and back
	go GoShareHTTP(*httpuri, *httpport)
	go GoShareZMQ(*req_port, *rep_port)

	do_you_wanna_continue()
}
Exemplo n.º 11
0
func setupTestData() {
	db = abkleveldb.CreateDB(test_dbpath)
	abkleveldb.PushKeyVal("upstate:2014:January:2:12:1:20", "down", db)
	abklevigoNS.PushNS("upstate:2014:January:2:12:1:20", "down", db)
	abklevigoNS.PushNS("upstate:2014:January:2:12:11:20", "up", db)
}
Exemplo n.º 12
0
func main() {
	var db *levigo.DB
	db = abkleveldb.CreateDB("/tmp/LevelDB02")
	exampleNS(db)
}