MCPcopy Create free account
hub / github.com/AdRoll/baker / Run

Method Run

input/inputtest/random.go:50–79  ·  view source on GitHub ↗
(output chan<- *baker.Data)

Source from the content-addressed store, hash-verified

48}
49
50func (r *Random) Run(output chan<- *baker.Data) error {
51
52 rand := rand.New(rand.NewSource(r.Cfg.RandSeed))
53
54 tlen := 15 * 24 * time.Hour
55 types := []string{"t1", "t2", "t3", "t4"}
56
57 var buf []byte
58 for i := 0; i < r.Cfg.Records; i++ {
59 var ll baker.Record
60
61 var t1 [16]byte
62 rand.Read(t1[:])
63 ll.Set(0, []byte(hex.EncodeToString(t1[:])))
64
65 t2 := time.Date(2015, 8, 1, 15, 0, 0, 0, time.UTC).Add(time.Duration(rand.Int63n(int64(tlen))))
66 ll.Set(1, []byte(strconv.Itoa(int(t2.Unix()))))
67
68 t3 := types[rand.Intn(len(types))]
69 ll.Set(2, []byte(t3))
70
71 buf = ll.ToText(buf)
72 buf = append(buf, '\n')
73 if i%16 == 0 || i == r.Cfg.Records-1 {
74 output <- &baker.Data{Bytes: buf}
75 buf = nil
76 }
77 }
78 return nil
79}
80
81func (r *Random) Stop() {}
82func (r *Random) FreeMem(data *baker.Data) {}

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
ToTextMethod · 0.95
ReadMethod · 0.80
DurationMethod · 0.65

Tested by

no test coverage detected