// for JSON val-type
func TestForJSON() {
	golassert.AssertEqual(HttpGet(MultiValPutURL(*httphost, *httpport, "ns-json", "{\"power:first\":\"yay\",\"power:second\":\"way\",\"rower:second\":\"kay\"}")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "power")), "power:first,yay\npower:second,way")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "rower")), "rower:second,kay")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "power")), "Success")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "rower")), "Success")
}
func TestRequestorZeromq() {
	_packet := goshare.Packet{}
	_packet.KeyType = "default"

	_packet.DBAction = "push"
	_packet.HashMap = make(golhashmap.HashMap)
	_packet.HashMap["an0n"] = "ymous"
	strPacket := string(goshare_requestor.RequestPacketBytes(&_packet))
	result, err = golzmq.ZmqRequest(zmqSock, strPacket)
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	_packet.DBAction = "read"
	_packet.KeyList = []string{"an0n"}
	strPacket = string(goshare_requestor.RequestPacketBytes(&_packet))
	result, err = golzmq.ZmqRequest(zmqSock, strPacket)
	expected = "an0n,ymous"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	_packet.DBAction = "delete"
	strPacket = string(goshare_requestor.RequestPacketBytes(&_packet))
	result, err = golzmq.ZmqRequest(zmqSock, strPacket)
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	_packet.DBAction = "read"
	strPacket = string(goshare_requestor.RequestPacketBytes(&_packet))
	result, err = golzmq.ZmqRequest(zmqSock, strPacket)
	expected = "Error for request sent: read default-default an0n"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)
}
// for key-type now
func TestNowKeyType() {
	result, err = golzmq.ZmqRequest(zmqSock, "push", "now", "myname:last:first", "anon")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds", "myname")
	result_length := len(golhashmap.CSVToHashMap(result))
	expected_length := 1
	golassert.AssertEqual(result_length, expected_length)
	golassert.AssertEqual(err, nil)

	time.Sleep(1)

	result, err = golzmq.ZmqRequest(zmqSock, "push", "now", "myname:last", "ymous")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds", "myname")
	result_length = len(golhashmap.CSVToHashMap(result))
	expected_length = 2
	golassert.AssertEqual(result_length, expected_length)
	golassert.AssertEqual(err, nil)
}
func TestReadKey(t *testing.T) {
	setupTestData()

	expected_val := "upstate:2014:January:2:12:1:20,down"
	result_val := golhashmap.HashMapToCSV(ReadKey("upstate:2014:January:2:12:1:20"))
	golassert.AssertEqual(expected_val, result_val)

	abkleveldb.CloseAndDeleteDB(test_dbpath, db)
}
// for tsds key-type
func TestTSDSKeyType() {
	golassert.AssertEqual(HttpGet(TSDSPutURL(*httphost, *httpport, "myname:last", "ymous", "2014", "2", "10", "1", "1", "1")), "Success")
	golassert.AssertEqual(HttpGet(TSDSPutURL(*httphost, *httpport, "myname", "anonymous", "2014", "2", "10", "9", "8", "7")), "Success")
	golassert.AssertEqual(HttpGet(TSDSPutURL(*httphost, *httpport, "myname", "untitled", "2014", "2", "10", "0", "1", "7")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "myname:last")), "myname:last:2014:February:10:1:1:1,ymous")

	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "myname")), "myname:last:2014:February:10:1:1:1,ymous\nmyname:2014:February:10:9:8:7,anonymous\nmyname:2014:February:10:0:1:7,untitled")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "myname:2014:February:10")), "myname:2014:February:10:9:8:7,anonymous\nmyname:2014:February:10:0:1:7,untitled")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "myname")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "myname")), "FATAL Error: (DBTasks) map[\"type\":[\"tsds\"] \"key\":[\"myname\"]]\n")
}
// for now key-type
func TestNowKeyType() {
	csvmap := golhashmap.GetHashMapEngine("csv")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "yname")), "Success")
	golassert.AssertEqual(HttpGet(PutURL(*httphost, *httpport, "now", "yname:last:first", "zodiac")), "Success")
	golassert.AssertEqual(len(csvmap.ToHashMap(HttpGet(GetURL(*httphost, *httpport, "tsds", "yname:last:first")))), 1)
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "yname")), "Success")

	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "myname")), "Success")
	golassert.AssertEqual(HttpGet(PutURL(*httphost, *httpport, "now", "myname:last:first", "ripper")), "Success")
	golassert.AssertEqual(len(csvmap.ToHashMap(HttpGet(GetURL(*httphost, *httpport, "tsds", "myname:last:first")))), 1)
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "myname")), "Success")
}
// for ns key-type
func TestNamespaceKeyType() {
	golassert.AssertEqual(HttpGet(PutURL(*httphost, *httpport, "ns", "myname:last:first", "anon")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "ns", "myname:last:first")), "myname:last:first,anon")
	golassert.AssertEqual(HttpGet(PutURL(*httphost, *httpport, "ns", "myname:last", "ymous")), "Success")
	golassert.AssertEqual(HttpGet(PutURL(*httphost, *httpport, "ns", "myname", "anonymous")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "ns", "myname:last")), "myname:last,ymous\nmyname:last:first,anon")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "ns", "myname")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "ns", "myname:last")), "FATAL Error: (DBTasks) map[\"type\":[\"ns\"] \"key\":[\"myname:last\"]]\n")
}
// for default key-type
func TestDefaultKeyType() {
	golassert.AssertEqual(HttpGet(PutURL(*httphost, *httpport, "default", "myname", "anon")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "default", "myname")), "myname,anon")
	golassert.AssertEqual(HttpGet(PutURL(*httphost, *httpport, "default", "myname", "anonymous")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "default", "myname")), "myname,anonymous")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "default", "myname")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "default", "myname")), "FATAL Error: (DBTasks) map[\"type\":[\"default\"] \"key\":[\"myname\"]]\n")
}
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)
}
// for &parentNS=parent:namespace
func TestWithParentNS() {
	var url string

	url = MultiValPutURL(*httphost, *httpport, "ns-csv-parent", "yname:frend:first,monica")
	golassert.AssertEqual(HttpGet(URLAppendParentNS(url, "animal:people")), "Success")

	url = MultiValPutURL(*httphost, *httpport, "ns-csv-parent", "yname:frend:second,lolita")
	golassert.AssertEqual(HttpGet(URLAppendParentNS(url, "animal:people")), "Success")

	url = URLAppendParentNS(GetURL(*httphost, *httpport, "tsds-csv-parent", "yname:frend"), "animal:people")
	golassert.AssertEqual(HttpGet(url), "animal:people:yname:frend:first,monica\nanimal:people:yname:frend:second,lolita")

	url = URLAppendParentNS(GetURL(*httphost, *httpport, "tsds-csv-parent", "people:yname:frend"), "animal")
	golassert.AssertEqual(HttpGet(url), "animal:people:yname:frend:first,monica\nanimal:people:yname:frend:second,lolita")

	url = GetURL(*httphost, *httpport, "tsds-csv-parent", "animal:people:yname:frend")
	golassert.AssertEqual(HttpGet(url), "animal:people:yname:frend:first,monica\nanimal:people:yname:frend:second,lolita")

	url = URLAppendParentNS(DelURL(*httphost, *httpport, "tsds-csv-parent", "yname"), "animal:people")
	golassert.AssertEqual(HttpGet(url), "Success")
}
Пример #11
0
func ZmqRequest(ip string, ports []int, request string) {
	_socket := golzmq.ZmqRequestSocket(ip, ports)
	val, err := golzmq.ZmqRequest(_socket, request)
	golassert.AssertEqual(err, nil)
	fmt.Println(val)
}
Пример #12
0
// for key-type ns
func TestNSKeyType() {
	result, err = golzmq.ZmqRequest(zmqSock, "push", "ns", "myname:last:first", "anon")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "ns", "myname")
	expected = "myname:last:first,anon"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "push", "ns", "myname:last", "ymous")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "push", "ns", "myname", "anonymous")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "ns", "myname")
	expected = "myname,anonymous\nmyname:last,ymous\nmyname:last:first,anon"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "delete", "ns", "myname")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "ns", "myname")
	expected = "Error for request sent: read ns myname"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)
}
Пример #13
0
// for key-type default
func TestDefaultKeyType() {
	result, err = golzmq.ZmqRequest(zmqSock, "push", "default", "myname", "anon")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "default", "myname")
	expected = "myname,anon"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "default-csv", "myname")
	expected = "myname,anon"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "default-json", "[\"myname\"]")
	expected = "{\"myname\":\"anon\"}"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "push", "default", "myname", "anonymous")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "default", "myname")
	expected = "myname,anonymous"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "delete", "default", "myname")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "delete", "default", "myname")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "default", "myname")
	expected = "Error for request sent: read default myname"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)
}
Пример #14
0
/* for parentNS for key-type */
func TestParentNSValType() {
	result, err = golzmq.ZmqRequest(zmqSock, "push", "ns-default-parent", "people", "myname", "anonymous")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "ns", "people:myname")
	expected = "people:myname,anonymous"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "ns-default-parent", "people", "myname")
	expected = "people:myname,anonymous"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "push", "tsds-csv-parent", "2014", "2", "10", "9", "18", "37", "people", "myname,bob")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds-default-parent", "people", "myname")
	expected = "people:myname,anonymous\npeople:myname:2014:February:10:9:18:37,bob"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "delete", "ns-default-parent", "people", "myname")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds-default-parent", "people", "myname")
	expected = "Error for request sent: read tsds-default-parent people myname"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)
}
Пример #15
0
// for key-type tsds
func TestTSDSKeyType() {
	result, err = golzmq.ZmqRequest(zmqSock, "push", "tsds", "2014", "2", "10", "9", "8", "7", "myname:last:first", "anon")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "ns", "myname")
	expected = "myname:last:first:2014:February:10:9:8:7,anon"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds", "myname")
	expected = "myname:last:first:2014:February:10:9:8:7,anon"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds", "myname:last:first")
	expected = "myname:last:first:2014:February:10:9:8:7,anon"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "push", "tsds", "2014", "2", "10", "9", "18", "37", "myname", "anonymous")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds", "myname")
	expected = "myname:last:first:2014:February:10:9:8:7,anon\nmyname:2014:February:10:9:18:37,anonymous"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "push", "tsds-csv", "2014", "2", "10", "9", "18", "37", "myname,bob\nmyemail,[email protected]")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds", "myname")
	expected = "myname:last:first:2014:February:10:9:8:7,anon\nmyname:2014:February:10:9:18:37,bob"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "push", "tsds-csv", "2014", "2", "10", "9", "18", "37", "myname,alice\nmytxt,\"my email, [email protected]\"")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds", "myemail")
	expected = "myemail:2014:February:10:9:18:37,[email protected]"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds", "mytxt")
	expected = "mytxt:2014:February:10:9:18:37,\"my email, [email protected]\""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "read", "tsds", "myname:2014:February:10")
	expected = "myname:2014:February:10:9:18:37,alice"
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "delete", "ns", "myname")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "delete", "ns", "myemail")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)

	result, err = golzmq.ZmqRequest(zmqSock, "delete", "ns", "mytxt")
	expected = ""
	golassert.AssertEqual(result, expected)
	golassert.AssertEqual(err, nil)
}
// for csv val-type
func TestForCSV() {
	golassert.AssertEqual(HttpGet(MultiTSDSPutURL(*httphost, *httpport, "csv", "yourname:last:first,trudy", "2014", "2", "10", "1", "1", "1")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "yourname:last:first:2014:February")), "yourname:last:first:2014:February:10:1:1:1,trudy")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "yourname")), "Success")

	golassert.AssertEqual(HttpGet(MultiValPutURL(*httphost, *httpport, "ns-csv", "yname:frend:first,monica")), "Success")
	golassert.AssertEqual(HttpGet(MultiValPutURL(*httphost, *httpport, "ns-csv", "yname:frend:second,lolita")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "yname:frend")), "yname:frend:first,monica\nyname:frend:second,lolita")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "yname")), "Success")

	golassert.AssertEqual(HttpGet(MultiValPutURL(*httphost, *httpport, "ns-csv", "yname:frend:first,monica%0D%0Ayname:frend:second,lolita%0D%0Auname:frend:second,juno%0D%0A")), "Success")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "yname:frend")), "yname:frend:first,monica\nyname:frend:second,lolita")
	golassert.AssertEqual(HttpGet(GetURL(*httphost, *httpport, "tsds", "uname:frend")), "uname:frend:second,juno")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "yname")), "Success")
	golassert.AssertEqual(HttpGet(DelURL(*httphost, *httpport, "tsds", "uname")), "Success")
}