コード例 #1
0
ファイル: benchmark_test.go プロジェクト: henryanand/vitess
func readEvents(b *testing.B, filename string) <-chan proto.BinlogEvent {
	events := make(chan proto.BinlogEvent)
	go func() {
		defer close(events)

		file, err := os.Open(filename)
		if err != nil {
			b.Fatalf("can't open file %s: %v", filename, err)
		}
		defer file.Close()

		// skip binlog magic header
		file.Seek(4, os.SEEK_SET)

		for {
			// read event header
			header := make([]byte, 19)
			if _, err := file.Read(header); err != nil {
				return
			}
			// get total event size
			size := binary.LittleEndian.Uint32(header[9 : 9+4])
			// read the rest of the event
			buf := make([]byte, size)
			copy(buf[:19], header)
			if _, err := file.Read(buf[19:]); err != nil {
				return
			}
			// convert to a BinlogEvent
			events <- mysqlctl.NewGoogleBinlogEvent(buf)
		}
	}()
	return events
}
コード例 #2
0
func sendTestEvents(channel chan<- proto.BinlogEvent, events [][]byte) {
	for _, buf := range events {
		channel <- mysqlctl.NewGoogleBinlogEvent(buf)
	}
	close(channel)
}