github.com/swiftstack/ProxyFS@v0.0.0-20210203235616-4017c267d62f/retryrpc/rpctest/ping.go (about) 1 // Copyright (c) 2015-2021, NVIDIA CORPORATION. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package rpctest 5 6 // Simple ping for testing the RPC layer 7 import ( 8 "bytes" 9 "fmt" 10 11 "github.com/swiftstack/ProxyFS/blunder" 12 ) 13 14 func encodeErrno(e *error) { 15 if *e != nil { 16 *e = fmt.Errorf("errno: %d", blunder.Errno(*e)) 17 } 18 } 19 20 // RpcPing simply does a len on the message path and returns the result 21 func (s *Server) RpcPing(in *PingReq, reply *PingReply) (err error) { 22 23 reply.Message = fmt.Sprintf("pong %d bytes", len(in.Message)) 24 return nil 25 } 26 27 var largeStr string = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" 28 29 // RpcPingLarge simply does a len on the message path and returns the result 30 // along with a larger buffer. 31 func (s *Server) RpcPingLarge(in *PingReq, reply *PingReply) (err error) { 32 33 buf := bytes.Buffer{} 34 p := fmt.Sprintf("pong %d bytes", len(in.Message)) 35 buf.WriteString(p) 36 for i := 0; i < 1000; i++ { 37 buf.WriteString(largeStr) 38 } 39 40 reply.Message = fmt.Sprintf("%v", buf.String()) 41 return nil 42 } 43 44 // RpcPingWithError returns an error 45 func (s *Server) RpcPingWithError(in *PingReq, reply *PingReply) (err error) { 46 err = blunder.AddError(err, blunder.NotFoundError) 47 encodeErrno(&err) 48 reply.Message = fmt.Sprintf("pong %d bytes", len(in.Message)) 49 return err 50 }