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 GetConfig() { config_basekey := fmt.Sprintf("%s::config", hostSignature) current_config, err := golzmq.ZmqRequest(request_socket, "read", config_basekey) if err != nil { gollog.LogIt(LogFile, err.Error()) } if current_config == "" { config_set := []string{ fmt.Sprintf("%s:put_interval,%d", config_basekey, *put_interval), fmt.Sprintf("%s:get_interval,%d", config_basekey, *get_interval), } current_config = strings.Join(config_set, "\n") golzmq.ZmqRequest(request_socket, "push", current_config) } for { config, _ := golzmq.ZmqRequest(request_socket, "read", config_basekey) fmt.Printf("WIP for reflecting %s", config) time.Sleep(time.Duration(*get_interval) * time.Second) } }
func ZmqRead(key_type string, key string) string { rep_port, err_rep_port := strconv.Atoi(*LifeCycleConfig["db_rep_port"]) req_port, err_req_port := strconv.Atoi(*LifeCycleConfig["db_req_port"]) if err_rep_port != nil || err_req_port != nil { golerror.Boohoo("Port parameters to bind, error-ed while conversion to number.", true) } sock := golzmq.ZmqRequestSocket(*LifeCycleConfig["db_uri"], rep_port, req_port) response, _ := golzmq.ZmqRequest(sock, "read", key_type, key) return response }
// 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) }
func PutResult() { var year, day, hour, min, sec int var month time.Month _str := strconv.Itoa for { year, month, day = time.Now().Date() hour, min, sec = time.Now().Clock() result := CheckResult() golzmq.ZmqRequest(request_socket, "push", "tsds-csv", _str(year), _str(int(month)), _str(day), _str(hour), _str(min), _str(sec), result) fmt.Printf("Host: %s\nCSV: %s\n", hostSignature, result) time.Sleep(time.Duration(*put_interval) * time.Second) } }
// 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) }
/* 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) }
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) }
// 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) }