github.com/pingcap/chaos@v0.0.0-20190710112158-c86faf4b3719/pkg/history/noop.go (about)

     1  package history
     2  
     3  import (
     4  	"encoding/json"
     5  )
     6  
     7  // NoopRequest is a noop request.
     8  type NoopRequest struct {
     9  	// 0 for read, 1 for write
    10  	Op    int
    11  	Value int
    12  }
    13  
    14  // NoopResponse is a noop response.
    15  type NoopResponse struct {
    16  	Value   int
    17  	Ok      bool
    18  	Unknown bool
    19  }
    20  
    21  type action struct {
    22  	proc int64
    23  	op   interface{}
    24  }
    25  
    26  // NoopParser is a noop parser.
    27  type NoopParser struct {
    28  	State int
    29  }
    30  
    31  // OnRequest impls RecordParser.
    32  func (p NoopParser) OnRequest(data json.RawMessage) (interface{}, error) {
    33  	r := NoopRequest{}
    34  	err := json.Unmarshal(data, &r)
    35  	return r, err
    36  }
    37  
    38  // OnResponse impls RecordParser.
    39  func (p NoopParser) OnResponse(data json.RawMessage) (interface{}, error) {
    40  	r := NoopResponse{}
    41  	err := json.Unmarshal(data, &r)
    42  	if r.Unknown {
    43  		return nil, err
    44  	}
    45  	return r, err
    46  }
    47  
    48  // OnNoopResponse impls RecordParser.
    49  func (p NoopParser) OnNoopResponse() interface{} {
    50  	return NoopResponse{Unknown: true}
    51  }
    52  
    53  // OnState impls RecordParser.
    54  func (p NoopParser) OnState(state json.RawMessage) (interface{}, error) {
    55  	return p.State, nil
    56  }