Browse Source

raft: use Equal in example

Blake Mizerany 11 years ago
parent
commit
c312d6efad
3 changed files with 41 additions and 2 deletions
  1. 1 2
      raft2/example_test.go
  2. 39 0
      raft2/state.pb.go
  3. 1 0
      raft2/state.proto

+ 1 - 2
raft2/example_test.go

@@ -10,7 +10,6 @@ func applyToStore(ents []Entry)        {}
 func sendMessages(msgs []Message)      {}
 func saveStateToDisk(st State)         {}
 func saveToDisk(ents []Entry)          {}
-func stateChanged(prev, st State) bool { return false }
 
 func Example_Node() {
 	n := Start(context.Background(), "", 0, 0)
@@ -26,7 +25,7 @@ func Example_Node() {
 			log.Fatal(err)
 		}
 
-		if stateChanged(prev, st) {
+		if prev.Equal(st) {
 			saveStateToDisk(st)
 			prev = st
 		}

+ 39 - 0
raft2/state.pb.go

@@ -22,6 +22,8 @@ import math "math"
 import io "io"
 import code_google_com_p_gogoprotobuf_proto "code.google.com/p/gogoprotobuf/proto"
 
+import bytes "bytes"
+
 // Reference proto, json, and math imports to suppress error if they are not otherwise used.
 var _ = proto.Marshal
 var _ = &json.SyntaxError{}
@@ -228,3 +230,40 @@ func encodeVarintState(data []byte, offset int, v uint64) int {
 	data[offset] = uint8(v)
 	return offset + 1
 }
+func (this *State) Equal(that interface{}) bool {
+	if that == nil {
+		if this == nil {
+			return true
+		}
+		return false
+	}
+
+	that1, ok := that.(*State)
+	if !ok {
+		return false
+	}
+	if that1 == nil {
+		if this == nil {
+			return true
+		}
+		return false
+	} else if this == nil {
+		return false
+	}
+	if this.Term != that1.Term {
+		return false
+	}
+	if this.Vote != that1.Vote {
+		return false
+	}
+	if this.Commit != that1.Commit {
+		return false
+	}
+	if this.LastIndex != that1.LastIndex {
+		return false
+	}
+	if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
+		return false
+	}
+	return true
+}

+ 1 - 0
raft2/state.proto

@@ -6,6 +6,7 @@ option (gogoproto.marshaler_all) = true;
 option (gogoproto.sizer_all) = true;
 option (gogoproto.unmarshaler_all) = true;
 option (gogoproto.goproto_getters_all) = false;
+option (gogoproto.equal_all) = true;
 
 message State {
 	required int64 term   = 1 [(gogoproto.nullable) = false];