Exemple #1
0
func TestUpdateChunkserver(t *testing.T) {
	conn, err := getConn()
	chunkserver := new(metadata.Chunkserver)

	chunkserver.GroupId = uint16(1)
	chunkserver.Ip = "127.0.0.1"
	chunkserver.Port = 5444
	chunkserver.Status = 0
	chunkserver.TotalFreeSpace = int64(65)
	chunkserver.MaxFreeSpace = int64(1231231231231234534)

	err = conn.UpdateChunkserver(chunkserver)
	if err != nil {
		t.Fatal(err)
	}
}
Exemple #2
0
func TestNotExistChunkserver(t *testing.T) {
	conn, err := getConn()
	chunkserver := new(metadata.Chunkserver)

	chunkserver.GroupId = uint16(3)
	chunkserver.Ip = "127.0.0.1"
	chunkserver.Port = 5444
	chunkserver.Status = 0
	chunkserver.TotalFreeSpace = int64(45465465)
	chunkserver.MaxFreeSpace = int64(123123123123123)

	exist, err := conn.IsExistChunkserver(chunkserver)
	if err != nil {
		t.Fatal(err)
	}
	t.Log("exist:", exist)
}
Exemple #3
0
func initChunkserverHandler(resp http.ResponseWriter, req *http.Request) {
	reqData, err := ioutil.ReadAll(req.Body)
	defer req.Body.Close()
	if err != nil {
		util.HandleError(resp, "", err, http.StatusBadRequest)
		return
	}
	log.Infof("[initserverHandler] read reqData %v", string(reqData))

	var jsonMap map[string]interface{}
	err = json.Unmarshal(reqData, &jsonMap)
	if err != nil {
		util.HandleError(resp, "", err, http.StatusBadRequest)
		return
	}
	log.Infof("[initserverHandler] change json to map %v", jsonMap)

	groupId := uint16((jsonMap["GroupId"]).(float64))
	ip := jsonMap["Ip"].(string)
	port := int((jsonMap["Port"]).(float64))
	chunkserver := new(metadata.Chunkserver)
	chunkserver.GroupId = groupId
	chunkserver.Ip = ip
	chunkserver.Port = port
	chunkserver.Status = INIT_STATUS
	chunkserver.TotalFreeSpace = 0
	chunkserver.MaxFreeSpace = 0
	chunkserver.PendingWrites = 0
	chunkserver.WritingCount = 0
	chunkserver.DataDir = ""
	chunkserver.ReadingCount = 0
	chunkserver.TotalChunks = 0
	chunkserver.ConnectionsCount = 0

	err = addChunkserver(chunkserver)
	if err != nil {
		util.HandleError(resp, "", err, http.StatusInternalServerError)
		return
	}

	util.Response(nil, http.StatusOK, resp)
}
Exemple #4
0
func TestAddChunkserver(t *testing.T) {
	conn, err := getConn()

	chunkserver := new(metadata.Chunkserver)
	chunkserver.GroupId = uint16(65535)
	chunkserver.Ip = "127.0.0.1"
	chunkserver.Port = 5444
	chunkserver.Status = 0
	chunkserver.TotalFreeSpace = int64(45465465)
	chunkserver.MaxFreeSpace = int64(123123123123123)
	chunkserver.PendingWrites = 1
	chunkserver.WritingCount = 1
	chunkserver.DataDir = "/export/"
	chunkserver.ReadingCount = 1
	chunkserver.TotalChunks = 1
	chunkserver.ConnectionsCount = 1

	err = conn.AddChunkserver(chunkserver)
	if err != nil {
		t.Fatal(err)
	}
}