etcd/raft/example_test.go

48 lines
1.2 KiB
Go
Raw Normal View History

2016-05-13 06:49:15 +03:00
// Copyright 2015 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2014-08-23 02:45:39 +04:00
package raft
2014-08-28 05:53:18 +04:00
import (
pb "github.com/coreos/etcd/raft/raftpb"
)
2014-09-16 04:35:02 +04:00
func applyToStore(ents []pb.Entry) {}
func sendMessages(msgs []pb.Message) {}
func saveStateToDisk(st pb.HardState) {}
func saveToDisk(ents []pb.Entry) {}
2014-08-23 02:45:39 +04:00
func ExampleNode() {
2015-03-24 07:19:03 +03:00
c := &Config{}
n := StartNode(c, nil)
defer n.Stop()
2014-08-23 02:45:39 +04:00
2014-08-24 03:06:55 +04:00
// stuff to n happens in other goroutines
2014-08-23 02:45:39 +04:00
2014-08-23 03:53:56 +04:00
// the last known state
2014-09-16 04:35:02 +04:00
var prev pb.HardState
2014-08-23 02:45:39 +04:00
for {
2016-02-01 08:42:39 +03:00
// Ready blocks until there is new state ready.
rd := <-n.Ready()
if !isHardStateEqual(prev, rd.HardState) {
2014-09-16 04:35:02 +04:00
saveStateToDisk(rd.HardState)
prev = rd.HardState
2014-08-23 02:45:39 +04:00
}
2014-08-27 03:19:49 +04:00
saveToDisk(rd.Entries)
go applyToStore(rd.CommittedEntries)
sendMessages(rd.Messages)
2014-08-23 02:45:39 +04:00
}
}