mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
chore(master): turn off logging of testing in docker
Signed-off-by: slasher <shenjie1@oppo.com>
This commit is contained in:
parent
98a9f5b07f
commit
481fd33b9e
@ -563,6 +563,8 @@ services:
|
||||
set -e;
|
||||
mkdir -p ${CFSROOT}/docker/bin &&
|
||||
cd ${CFSROOT} && make testcover
|
||||
environment:
|
||||
- DOCKER_TESTING_LOG_OFF="on"
|
||||
|
||||
build_libsdkpre:
|
||||
image: ${IMAGE}
|
||||
|
||||
@ -233,9 +233,11 @@ func createMasterServer(cfgJSON string) (server *Server, err error) {
|
||||
default:
|
||||
level = log.ErrorLevel
|
||||
}
|
||||
if _, err = log.InitLog(logDir, "master", level, nil, log.DefaultLogLeftSpaceLimit); err != nil {
|
||||
fmt.Println("Fatal: failed to start the cubefs daemon - ", err)
|
||||
return
|
||||
if mocktest.LogOn {
|
||||
if _, err = log.InitLog(logDir, "master", level, nil, log.DefaultLogLeftSpaceLimit); err != nil {
|
||||
fmt.Println("Fatal: failed to start the cubefs daemon - ", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if profPort != "" {
|
||||
go func() {
|
||||
@ -268,7 +270,6 @@ func addMetaServer(addr, zoneName string) *mocktest.MockMetaServer {
|
||||
func TestSetMetaNodeThreshold(t *testing.T) {
|
||||
threshold := 0.5
|
||||
reqURL := fmt.Sprintf("%v%v?threshold=%v", hostAddr, proto.AdminSetMetaNodeThreshold, threshold)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
if server.cluster.cfg.MetaNodeThreshold != float32(threshold) {
|
||||
t.Errorf("set metanode threshold to %v failed", threshold)
|
||||
@ -295,13 +296,11 @@ func TestSetDisableAutoAlloc(t *testing.T) {
|
||||
|
||||
func TestGetCluster(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v", hostAddr, proto.AdminGetCluster)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
func TestGetIpAndClusterName(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v", hostAddr, proto.AdminGetIP)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
@ -323,7 +322,7 @@ func processWithFatalV2(url string, success bool, req map[string]interface{}, t
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
assert.Nil(t, err)
|
||||
|
||||
t.Log(string(body), reqURL)
|
||||
mocktest.Log(t, string(body), reqURL)
|
||||
|
||||
reply = &httpReply{}
|
||||
err = json.Unmarshal(body, reply)
|
||||
@ -340,19 +339,20 @@ func processWithFatalV2(url string, success bool, req map[string]interface{}, t
|
||||
}
|
||||
|
||||
func process(reqURL string, t *testing.T) (reply *proto.HTTPReply) {
|
||||
mocktest.Log(t, reqURL)
|
||||
resp, err := http.Get(reqURL)
|
||||
if err != nil {
|
||||
t.Errorf("err is %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(resp.StatusCode)
|
||||
mocktest.Println(resp.StatusCode)
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Errorf("err is %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(body))
|
||||
mocktest.Println(string(body))
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("status code[%v]", resp.StatusCode)
|
||||
return
|
||||
@ -378,20 +378,20 @@ func TestDisk(t *testing.T) {
|
||||
func decommissionDisk(addr, path string, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?addr=%v&disk=%v",
|
||||
hostAddr, proto.DecommissionDisk, addr, path)
|
||||
fmt.Println(reqURL)
|
||||
mocktest.Log(t, reqURL)
|
||||
resp, err := http.Get(reqURL)
|
||||
if err != nil {
|
||||
t.Errorf("err is %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(resp.StatusCode)
|
||||
mocktest.Println(resp.StatusCode)
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Errorf("err is %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(body))
|
||||
mocktest.Println(string(body))
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("status code[%v]", resp.StatusCode)
|
||||
return
|
||||
@ -577,7 +577,7 @@ func setVolCapacity(capacity uint64, url string, t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("update capacity to %d success\n", capacity)
|
||||
mocktest.Printf("update capacity to %d success\n", capacity)
|
||||
}
|
||||
|
||||
func buildAuthKey(owner string) string {
|
||||
@ -595,7 +595,6 @@ func TestGetVolSimpleInfo(t *testing.T) {
|
||||
func TestCreateVol(t *testing.T) {
|
||||
name := "test_create_vol"
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v&replicas=3&type=extent&capacity=100&owner=cfstest&zoneName=%v", hostAddr, proto.AdminCreateVol, name, testZone2)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
userInfo, err := server.user.getUserInfo("cfstest")
|
||||
if err != nil {
|
||||
@ -805,13 +804,11 @@ func TestRemoveMetaReplica(t *testing.T) {
|
||||
|
||||
func TestClusterStat(t *testing.T) {
|
||||
reqUrl := fmt.Sprintf("%v%v", hostAddr, proto.AdminClusterStat)
|
||||
fmt.Println(reqUrl)
|
||||
process(reqUrl, t)
|
||||
}
|
||||
|
||||
func TestListVols(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?keywords=%v", hostAddr, proto.AdminListVols, commonVolName)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
@ -946,6 +943,7 @@ func TestUpdateZoneStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func post(reqURL string, data []byte, t *testing.T) (reply *proto.HTTPReply) {
|
||||
mocktest.Log(t, reqURL)
|
||||
reader := bytes.NewReader(data)
|
||||
req, err := http.NewRequest(http.MethodPost, reqURL, reader)
|
||||
if err != nil {
|
||||
@ -957,14 +955,14 @@ func post(reqURL string, data []byte, t *testing.T) (reply *proto.HTTPReply) {
|
||||
t.Errorf("post err: %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(resp.StatusCode)
|
||||
mocktest.Println(resp.StatusCode)
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Errorf("err is %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(body))
|
||||
mocktest.Println(string(body))
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("status code[%v]", resp.StatusCode)
|
||||
return
|
||||
@ -989,13 +987,11 @@ func TestCreateUser(t *testing.T) {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(reqURL)
|
||||
post(reqURL, data, t)
|
||||
}
|
||||
|
||||
func TestGetUser(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?user=%v", hostAddr, proto.UserGetInfo, testUserID)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
@ -1007,7 +1003,6 @@ func TestUpdateUser(t *testing.T) {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(reqURL)
|
||||
post(reqURL, data, t)
|
||||
userInfo, err := server.user.getUserInfo(testUserID)
|
||||
if err != nil {
|
||||
@ -1034,7 +1029,6 @@ func TestUpdateUser(t *testing.T) {
|
||||
|
||||
func TestGetAKInfo(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?ak=%v", hostAddr, proto.UserGetAKInfo, ak)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
@ -1046,7 +1040,6 @@ func TestUpdatePolicy(t *testing.T) {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(reqURL)
|
||||
post(reqURL, data, t)
|
||||
userInfo, err := server.user.getUserInfo(testUserID)
|
||||
if err != nil {
|
||||
@ -1067,7 +1060,6 @@ func TestRemovePolicy(t *testing.T) {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(reqURL)
|
||||
post(reqURL, data, t)
|
||||
userInfo, err := server.user.getUserInfo(testUserID)
|
||||
if err != nil {
|
||||
@ -1088,7 +1080,6 @@ func TestTransferVol(t *testing.T) {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(reqURL)
|
||||
post(reqURL, data, t)
|
||||
userInfo1, err := server.user.getUserInfo(testUserID)
|
||||
if err != nil {
|
||||
@ -1126,7 +1117,6 @@ func TestDeleteVolPolicy(t *testing.T) {
|
||||
return
|
||||
}
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v", hostAddr, proto.UserDeleteVolPolicy, commonVolName)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
userInfo1, err := server.user.getUserInfo(testUserID)
|
||||
if err != nil {
|
||||
@ -1150,13 +1140,11 @@ func TestDeleteVolPolicy(t *testing.T) {
|
||||
|
||||
func TestListUser(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?keywords=%v", hostAddr, proto.UserList, "test")
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
func TestDeleteUser(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?user=%v", hostAddr, proto.UserDelete, testUserID)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
if _, err := server.user.getUserInfo(testUserID); err != proto.ErrUserNotExists {
|
||||
t.Errorf("expect err ErrUserNotExists, but err is %v", err)
|
||||
@ -1166,23 +1154,19 @@ func TestDeleteUser(t *testing.T) {
|
||||
|
||||
func TestListUsersOfVol(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v", hostAddr, proto.UsersOfVol, "test_create_vol")
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
func TestListNodeSets(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v", hostAddr, proto.GetAllNodeSets)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
|
||||
reqURL = fmt.Sprintf("%v%v?zoneName=%v", hostAddr, proto.GetAllNodeSets, testZone2)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
func TestGetNodeSets(t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?nodesetId=1", hostAddr, proto.GetNodeSet)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
|
||||
@ -2,9 +2,10 @@ package master
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
)
|
||||
|
||||
func TestDataNode(t *testing.T) {
|
||||
@ -36,12 +37,10 @@ func TestDataNode(t *testing.T) {
|
||||
|
||||
func getDataNodeInfo(addr string, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?addr=%v", hostAddr, proto.GetDataNode, addr)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
func decommissionDataNode(addr string, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?addr=%v", hostAddr, proto.DecommissionDataNode, addr)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
@ -30,7 +30,6 @@ func createDataPartition(vol *Vol, count int, t *testing.T) {
|
||||
oldCount := len(vol.dataPartitions.partitions)
|
||||
reqURL := fmt.Sprintf("%v%v?count=%v&name=%v&type=extent",
|
||||
hostAddr, proto.AdminCreateDataPartition, count, vol.Name)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
|
||||
newCount := len(vol.dataPartitions.partitions)
|
||||
@ -45,7 +44,6 @@ func createDataPartition(vol *Vol, count int, t *testing.T) {
|
||||
func getDataPartition(id uint64, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?id=%v",
|
||||
hostAddr, proto.AdminGetDataPartition, id)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
@ -54,7 +52,6 @@ func decommissionDataPartition(dp *DataPartition, t *testing.T) {
|
||||
offlineAddr := dp.Hosts[0]
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v&id=%v&addr=%v",
|
||||
hostAddr, proto.AdminDecommissionDataPartition, dp.VolName, dp.PartitionID, offlineAddr)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
if contains(dp.Hosts, offlineAddr) {
|
||||
t.Errorf("decommissionDataPartition failed,offlineAddr[%v],hosts[%v]", offlineAddr, dp.Hosts)
|
||||
|
||||
@ -28,7 +28,6 @@ func SelfIncreaseIdAllocTest(t *testing.T, allocator *IDAllocator, allocFunc fun
|
||||
if newId < id {
|
||||
t.Errorf("id should be uniqued and self-increased")
|
||||
}
|
||||
t.Logf("new id is %v", newId)
|
||||
id = newId
|
||||
}
|
||||
allocator.restore()
|
||||
|
||||
@ -2,14 +2,15 @@ package master
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cubefs/cubefs/raftstore/raftstore_db"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
rproto "github.com/cubefs/cubefs/depends/tiglabs/raft/proto"
|
||||
"github.com/cubefs/cubefs/master/mocktest"
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
"github.com/cubefs/cubefs/raftstore/raftstore_db"
|
||||
raftstore "github.com/cubefs/cubefs/raftstore/raftstore_db"
|
||||
)
|
||||
|
||||
@ -173,24 +174,23 @@ func snapshotTest(t *testing.T) {
|
||||
func addRaftServerTest(addRaftAddr string, id uint64, t *testing.T) {
|
||||
//don't pass id test
|
||||
reqURL := fmt.Sprintf("%v%v?id=&addr=%v", hostAddr, proto.AddRaftNode, addRaftAddr)
|
||||
fmt.Println(reqURL)
|
||||
mocktest.Println(reqURL)
|
||||
resp, err := http.Get(reqURL)
|
||||
if err != nil {
|
||||
t.Errorf("err is %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(resp.StatusCode)
|
||||
mocktest.Println(resp.StatusCode)
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Errorf("err is %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(body))
|
||||
mocktest.Println(string(body))
|
||||
}
|
||||
|
||||
func removeRaftServerTest(removeRaftAddr string, id uint64, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?id=%v&addr=%v", hostAddr, proto.RemoveRaftNode, id, removeRaftAddr)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
@ -2,9 +2,10 @@ package master
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
)
|
||||
|
||||
func TestMetaNode(t *testing.T) {
|
||||
@ -23,12 +24,10 @@ func TestMetaNode(t *testing.T) {
|
||||
|
||||
func getMetaNodeInfo(addr string, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?addr=%v", hostAddr, proto.GetMetaNode, addr)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
func decommissionMetaNode(addr string, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?addr=%v", hostAddr, proto.DecommissionMetaNode, addr)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
@ -40,7 +40,6 @@ func createMetaPartition(vol *Vol, t *testing.T) {
|
||||
start = mp.Start + metaPartitionInodeIdStep
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v&start=%v",
|
||||
hostAddr, proto.AdminCreateMetaPartition, vol.Name, start)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
|
||||
if start < mp.MaxInodeID {
|
||||
@ -71,13 +70,11 @@ func createMetaPartition(vol *Vol, t *testing.T) {
|
||||
func getMetaPartition(volName string, id uint64, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v&id=%v",
|
||||
hostAddr, proto.ClientMetaPartition, volName, id)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
func loadMetaPartitionTest(vol *Vol, id uint64, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v&id=%v", hostAddr, proto.AdminLoadMetaPartition, vol.Name, id)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
@ -85,7 +82,6 @@ func decommissionMetaPartition(vol *Vol, id uint64, t *testing.T) {
|
||||
server.cluster.checkMetaNodeHeartbeat()
|
||||
time.Sleep(5 * time.Second)
|
||||
reqURL := fmt.Sprintf("%v%v", hostAddr, proto.AdminGetCluster)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
vol, err := server.cluster.getVol(vol.Name)
|
||||
if err != nil {
|
||||
@ -100,7 +96,6 @@ func decommissionMetaPartition(vol *Vol, id uint64, t *testing.T) {
|
||||
offlineAddr := mp.Hosts[0]
|
||||
reqURL = fmt.Sprintf("%v%v?name=%v&id=%v&addr=%v",
|
||||
hostAddr, proto.AdminDecommissionMetaPartition, vol.Name, id, offlineAddr)
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
mp, err = server.cluster.getMetaPartitionByID(id)
|
||||
if err != nil {
|
||||
|
||||
@ -123,28 +123,28 @@ func (mds *MockDataServer) serveConn(rc net.Conn) {
|
||||
switch req.Opcode {
|
||||
case proto.OpCreateDataPartition:
|
||||
err = mds.handleCreateDataPartition(conn, req, adminTask)
|
||||
fmt.Printf("data node [%v] create data partition,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
Printf("data node [%v] create data partition,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
case proto.OpDeleteDataPartition:
|
||||
err = mds.handleDeleteDataPartition(conn, req)
|
||||
fmt.Printf("data node [%v] delete data partition,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
Printf("data node [%v] delete data partition,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
case proto.OpDataNodeHeartbeat:
|
||||
err = mds.handleHeartbeats(conn, req, adminTask)
|
||||
fmt.Printf("data node [%v] report heartbeat to master,err:%v\n", mds.TcpAddr, err)
|
||||
Printf("data node [%v] report heartbeat to master,err:%v\n", mds.TcpAddr, err)
|
||||
case proto.OpLoadDataPartition:
|
||||
err = mds.handleLoadDataPartition(conn, req, adminTask)
|
||||
fmt.Printf("data node [%v] load data partition,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
Printf("data node [%v] load data partition,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
case proto.OpDecommissionDataPartition:
|
||||
err = mds.handleDecommissionDataPartition(conn, req, adminTask)
|
||||
fmt.Printf("data node [%v] decommission data partition,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
Printf("data node [%v] decommission data partition,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
case proto.OpAddDataPartitionRaftMember:
|
||||
err = mds.handleAddDataPartitionRaftMember(conn, req, adminTask)
|
||||
fmt.Printf("data node [%v] add data partition raft member,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
Printf("data node [%v] add data partition raft member,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
case proto.OpRemoveDataPartitionRaftMember:
|
||||
err = mds.handleRemoveDataPartitionRaftMember(conn, req, adminTask)
|
||||
fmt.Printf("data node [%v] remove data partition raft member,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
Printf("data node [%v] remove data partition raft member,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
case proto.OpDataPartitionTryToLeader:
|
||||
err = mds.handleTryToLeader(conn, req, adminTask)
|
||||
fmt.Printf("data node [%v] try to leader,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
Printf("data node [%v] try to leader,id[%v],err:%v\n", mds.TcpAddr, adminTask.ID, err)
|
||||
default:
|
||||
fmt.Printf("unknown code [%v]\n", req.Opcode)
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ func (mms *MockMetaServer) start() {
|
||||
}
|
||||
|
||||
func (mms *MockMetaServer) serveConn(rc net.Conn) {
|
||||
fmt.Printf("remote[%v],local[%v]\n", rc.RemoteAddr(), rc.LocalAddr())
|
||||
Printf("remote[%v],local[%v]\n", rc.RemoteAddr(), rc.LocalAddr())
|
||||
conn, ok := rc.(*net.TCPConn)
|
||||
if !ok {
|
||||
rc.Close()
|
||||
@ -99,7 +99,7 @@ func (mms *MockMetaServer) serveConn(rc net.Conn) {
|
||||
fmt.Printf("remote [%v] err is [%v]\n", conn.RemoteAddr(), err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("remote [%v] req [%v]\n", conn.RemoteAddr(), req.GetOpMsg())
|
||||
Printf("remote [%v] req [%v]\n", conn.RemoteAddr(), req.GetOpMsg())
|
||||
adminTask := &proto.AdminTask{}
|
||||
decode := json.NewDecoder(bytes.NewBuffer(req.Data))
|
||||
decode.UseNumber()
|
||||
@ -110,31 +110,31 @@ func (mms *MockMetaServer) serveConn(rc net.Conn) {
|
||||
switch req.Opcode {
|
||||
case proto.OpCreateMetaPartition:
|
||||
err = mms.handleCreateMetaPartition(conn, req, adminTask)
|
||||
fmt.Printf("meta node [%v] create meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
Printf("meta node [%v] create meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
case proto.OpMetaNodeHeartbeat:
|
||||
err = mms.handleHeartbeats(conn, req, adminTask)
|
||||
fmt.Printf("meta node [%v] heartbeat,err:%v\n", mms.TcpAddr, err)
|
||||
Printf("meta node [%v] heartbeat,err:%v\n", mms.TcpAddr, err)
|
||||
case proto.OpDeleteMetaPartition:
|
||||
err = mms.handleDeleteMetaPartition(conn, req, adminTask)
|
||||
fmt.Printf("meta node [%v] delete meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
Printf("meta node [%v] delete meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
case proto.OpUpdateMetaPartition:
|
||||
err = mms.handleUpdateMetaPartition(conn, req, adminTask)
|
||||
fmt.Printf("meta node [%v] update meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
Printf("meta node [%v] update meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
case proto.OpLoadMetaPartition:
|
||||
err = mms.handleLoadMetaPartition(conn, req, adminTask)
|
||||
fmt.Printf("meta node [%v] load meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
Printf("meta node [%v] load meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
case proto.OpDecommissionMetaPartition:
|
||||
err = mms.handleDecommissionMetaPartition(conn, req, adminTask)
|
||||
fmt.Printf("meta node [%v] offline meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
Printf("meta node [%v] offline meta partition,err:%v\n", mms.TcpAddr, err)
|
||||
case proto.OpAddMetaPartitionRaftMember:
|
||||
err = mms.handleAddMetaPartitionRaftMember(conn, req, adminTask)
|
||||
fmt.Printf("meta node [%v] add data partition raft member,id[%v],err:%v\n", mms.TcpAddr, adminTask.ID, err)
|
||||
Printf("meta node [%v] add data partition raft member,id[%v],err:%v\n", mms.TcpAddr, adminTask.ID, err)
|
||||
case proto.OpRemoveMetaPartitionRaftMember:
|
||||
err = mms.handleRemoveMetaPartitionRaftMember(conn, req, adminTask)
|
||||
fmt.Printf("meta node [%v] remove data partition raft member,id[%v],err:%v\n", mms.TcpAddr, adminTask.ID, err)
|
||||
Printf("meta node [%v] remove data partition raft member,id[%v],err:%v\n", mms.TcpAddr, adminTask.ID, err)
|
||||
case proto.OpMetaPartitionTryToLeader:
|
||||
err = mms.handleTryToLeader(conn, req, adminTask)
|
||||
fmt.Printf("meta node [%v] try to leader,id[%v],err:%v\n", mms.TcpAddr, adminTask.ID, err)
|
||||
Printf("meta node [%v] try to leader,id[%v],err:%v\n", mms.TcpAddr, adminTask.ID, err)
|
||||
default:
|
||||
fmt.Printf("unknown code [%v]\n", req.Opcode)
|
||||
}
|
||||
|
||||
@ -2,8 +2,12 @@ package mocktest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cubefs/cubefs/proto"
|
||||
@ -14,6 +18,32 @@ const (
|
||||
hostAddr = "127.0.0.1:8080"
|
||||
)
|
||||
|
||||
var (
|
||||
LogOn = os.Getenv("DOCKER_TESTING_LOG_OFF") == ""
|
||||
Print = fmt.Print
|
||||
Printf = fmt.Printf
|
||||
Println = fmt.Println
|
||||
)
|
||||
|
||||
func init() {
|
||||
if !LogOn {
|
||||
SetOutput(io.Discard)
|
||||
}
|
||||
}
|
||||
|
||||
// SetOutput reset fmt output writer.
|
||||
func SetOutput(w io.Writer) {
|
||||
Print = func(a ...interface{}) (int, error) { return fmt.Fprint(w, a...) }
|
||||
Printf = func(format string, a ...interface{}) (int, error) { return fmt.Fprintf(w, format, a...) }
|
||||
Println = func(a ...interface{}) (int, error) { return fmt.Fprintln(w, a...) }
|
||||
}
|
||||
|
||||
func Log(tb testing.TB, a ...interface{}) {
|
||||
if LogOn {
|
||||
tb.Log(a...)
|
||||
}
|
||||
}
|
||||
|
||||
func responseAckOKToMaster(conn net.Conn, p *proto.Packet, data []byte) error {
|
||||
if len(data) != 0 {
|
||||
p.PacketOkWithBody(data)
|
||||
|
||||
@ -24,6 +24,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cubefs/cubefs/master/mocktest"
|
||||
"github.com/cubefs/cubefs/util"
|
||||
)
|
||||
|
||||
@ -44,13 +45,13 @@ func writeMetaNode(sb *strings.Builder, node *MetaNode) {
|
||||
func printDataNode(t *testing.T, node *DataNode) {
|
||||
sb := strings.Builder{}
|
||||
writeDataNode(&sb, node)
|
||||
t.Log(sb.String())
|
||||
mocktest.Log(t, sb.String())
|
||||
}
|
||||
|
||||
func printMetaNode(t *testing.T, node *MetaNode) {
|
||||
sb := strings.Builder{}
|
||||
writeMetaNode(&sb, node)
|
||||
t.Log(sb.String())
|
||||
mocktest.Log(t, sb.String())
|
||||
}
|
||||
|
||||
func printNodesetAndDataNodes(t *testing.T, nset *nodeSet) {
|
||||
@ -150,7 +151,7 @@ func DataNodeSelectorTest(t *testing.T, selector NodeSelector, expectedNode *Dat
|
||||
t.Errorf("failed to get zone %v", err)
|
||||
return nil
|
||||
}
|
||||
t.Log("List nodesets of zone")
|
||||
mocktest.Log(t, "List nodesets of zone")
|
||||
printNodesetsOfZone(t, zone)
|
||||
nsc := zone.getAllNodeSet()
|
||||
if nsc.Len() == 0 {
|
||||
@ -158,14 +159,14 @@ func DataNodeSelectorTest(t *testing.T, selector NodeSelector, expectedNode *Dat
|
||||
return nil
|
||||
}
|
||||
nset := nsc[0]
|
||||
t.Logf("List datanodes of nodeset %v", nset.ID)
|
||||
mocktest.Log(t, "List datanodes of nodeset", nset.ID)
|
||||
printNodesetAndDataNodes(t, nset)
|
||||
_, peer, err := selector.Select(nset, nil, 1)
|
||||
if err != nil {
|
||||
t.Errorf("%v failed to select nodes %v", selector.GetName(), err)
|
||||
return nil
|
||||
}
|
||||
t.Log("List selected nodes:")
|
||||
mocktest.Log(t, "List selected nodes:")
|
||||
for i := 0; i < len(peer); i++ {
|
||||
nodeVal, ok := nset.dataNodes.Load(peer[i].Addr)
|
||||
if !ok {
|
||||
@ -195,18 +196,18 @@ func MetaNodeSelectorTest(t *testing.T, selector NodeSelector, expectedNode *Met
|
||||
t.Errorf("failed to get zone %v", err)
|
||||
return nil
|
||||
}
|
||||
t.Log("List nodesets of zone")
|
||||
mocktest.Log(t, "List nodesets of zone")
|
||||
printNodesetsOfZone(t, zone)
|
||||
nsc := zone.getAllNodeSet()
|
||||
nset := nsc[0]
|
||||
t.Logf("List metanodes of nodeset %v", nset.ID)
|
||||
mocktest.Log(t, "List metanodes of nodeset", nset.ID)
|
||||
printNodesetAndMetaNodes(t, nset)
|
||||
_, peer, err := selector.Select(nset, nil, 1)
|
||||
if err != nil {
|
||||
t.Errorf("%v failed to select nodes %v", selector.GetName(), err)
|
||||
return nil
|
||||
}
|
||||
t.Log("List selected nodes:")
|
||||
mocktest.Log(t, "List selected nodes:")
|
||||
for i := 0; i < len(peer); i++ {
|
||||
nodeVal, ok := nset.metaNodes.Load(peer[i].Addr)
|
||||
if !ok {
|
||||
@ -234,7 +235,7 @@ func printNodeSelectTimes(t *testing.T, times map[uint64]int) {
|
||||
for id, time := range times {
|
||||
sb.WriteString(fmt.Sprintf("Node %v select times %v\n", id, time))
|
||||
}
|
||||
t.Log(sb.String())
|
||||
mocktest.Log(t, sb.String())
|
||||
}
|
||||
|
||||
func TestCarryWeightNodeSelector(t *testing.T) {
|
||||
@ -317,14 +318,14 @@ func TestRoundRobinNodeSelector(t *testing.T) {
|
||||
}
|
||||
selector := NewRoundRobinNodeSelector(DataNodeType)
|
||||
for i, node := range dataNodes {
|
||||
t.Logf("Select DataNode Round %v", i)
|
||||
mocktest.Log(t, "Select DataNode Round", i)
|
||||
if DataNodeSelectorTest(t, selector, node) == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
selector = NewRoundRobinNodeSelector(MetaNodeType)
|
||||
for i, node := range metaNodes {
|
||||
t.Logf("Select MetaNode Round %v", i)
|
||||
mocktest.Log(t, "Select MetaNode Round", i)
|
||||
if MetaNodeSelectorTest(t, selector, node) == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cubefs/cubefs/master/mocktest"
|
||||
"github.com/cubefs/cubefs/util"
|
||||
)
|
||||
|
||||
@ -43,7 +44,7 @@ func printNodesetsOfZone(t *testing.T, zone *Zone) {
|
||||
func printNodeset(t *testing.T, nset *nodeSet) {
|
||||
sb := strings.Builder{}
|
||||
writeNodeset(&sb, nset)
|
||||
t.Logf(sb.String())
|
||||
mocktest.Log(t, sb.String())
|
||||
}
|
||||
|
||||
func NodesetSelectorTest(t *testing.T, selector NodesetSelector) {
|
||||
@ -139,7 +140,7 @@ func nodesetSelectorBench(selector NodesetSelector, nsc nodeSetCollection, onSel
|
||||
|
||||
func printNodesetSelectTimes(t *testing.T, times map[uint64]int) {
|
||||
for id, count := range times {
|
||||
t.Logf("Nodeset %v select %v times", id, count)
|
||||
mocktest.Log(t, fmt.Sprintf("Nodeset %v select %v times", id, count))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package master
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -63,7 +62,7 @@ func TestSingleZone(t *testing.T) {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(newHosts)
|
||||
t.Log(newHosts)
|
||||
topo.deleteDataNode(createDataNodeForTopo(mds1Addr, zoneName, nodeSet))
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ func TestCheckVol(t *testing.T) {
|
||||
commonVol.checkMetaPartitions(server.cluster)
|
||||
commonVol.checkDataPartitions(server.cluster)
|
||||
log.LogFlush()
|
||||
fmt.Printf("writable data partitions[%v]\n", commonVol.dataPartitions.readableAndWritableCnt)
|
||||
t.Logf("writable data partitions[%v]\n", commonVol.dataPartitions.readableAndWritableCnt)
|
||||
}
|
||||
|
||||
func TestVol(t *testing.T) {
|
||||
@ -196,9 +196,6 @@ func buildUrl(host, op string, kv map[string]interface{}) string {
|
||||
for k, v := range kv {
|
||||
url += fmt.Sprintf("%s=%v&", k, v)
|
||||
}
|
||||
|
||||
fmt.Println(url)
|
||||
|
||||
return url[:len(url)-1]
|
||||
}
|
||||
|
||||
@ -310,14 +307,11 @@ func getSimpleVol(name string, success bool, t *testing.T) *proto.SimpleVolView
|
||||
|
||||
func getVol(name string, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v&authKey=%v", hostAddr, proto.ClientVol, name, buildAuthKey("cfs"))
|
||||
fmt.Println(reqURL)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
func statVol(name string, t *testing.T) {
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v",
|
||||
hostAddr, proto.ClientVolStat, name)
|
||||
fmt.Println(reqURL)
|
||||
reqURL := fmt.Sprintf("%v%v?name=%v", hostAddr, proto.ClientVolStat, name)
|
||||
process(reqURL, t)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user