github.com/swiftstack/proxyfs@v0.0.0-20201223034610-5434d919416e/retryrpc/rpctest/ping.go (about)

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