// All zero values func (s *AggregatorTestSuite) TestC000(t *C) { interval := int64(60) a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool) go a.Start() defer a.Stop() // Ts in c000 is 2009-11-10 23:00:00. t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00") file := sample + "/c000.json" if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } file = sample + "/c000-n.json" if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } got := test.WaitMmReport(s.dataChan) t.Assert(got, NotNil) t.Check(got.Ts, Equals, t1) t.Check(uint64(got.Duration), Equals, uint64(interval)) expect := &mm.Report{} if err := test.LoadMmReport(sample+"/c000r.json", expect); err != nil { t.Fatal("c000r.json ", err) } if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok { t.Fatal(diff) } }
func (s *AggregatorTestSuite) TestC002(t *C) { interval := int64(300) a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool) go a.Start() defer a.Stop() // Ts in c002-1 is 2009-11-10 23:00:00. t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00") for i := 1; i <= 5; i++ { file := fmt.Sprintf("%s/c002-%d.json", sample, i) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } } // Next interval causes 1st to be reported. file := fmt.Sprintf("%s/c002-n.json", sample) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } got := test.WaitMmReport(s.dataChan) t.Assert(got, NotNil) t.Check(got.Ts, Equals, t1) t.Check(uint64(got.Duration), Equals, uint64(interval)) expect := &mm.Report{} if err := test.LoadMmReport(sample+"/c002r.json", expect); err != nil { t.Fatal("c002r.json ", err) } if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok { t.Fatal(diff) } }
// COUNTER func (s *AggregatorTestSuite) TestC003(t *C) { interval := int64(5) a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool) go a.Start() defer a.Stop() // Ts in c003 is 2009-11-10 23:00:00. t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00") for i := 1; i <= 5; i++ { file := fmt.Sprintf("%s/c003-%d.json", sample, i) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } } // Next interval causes 1st to be reported. file := fmt.Sprintf("%s/c003-n.json", sample) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } /** * Pretend we're monitoring Bytes_sents every second: * first val = 100 * prev this diff val/s * next val 100 200 100 100 * next val 200 400 200 200 * next val 400 800 400 400 * next val 800 1600 800 800 * * So min bytes/s = 100, max = 800, avg = 375. These are * the values in c003r.json. */ got := test.WaitMmReport(s.dataChan) t.Assert(got, NotNil) t.Check(got.Ts, Equals, t1) t.Check(uint64(got.Duration), Equals, uint64(interval)) expect := &mm.Report{} if err := test.LoadMmReport(sample+"/c003r.json", expect); err != nil { t.Fatal("c003r.json ", err) } if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok { t.Fatal(diff) } }
func (s *AggregatorTestSuite) TestC003Lost(t *C) { interval := int64(5) a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool) go a.Start() defer a.Stop() // Ts in c003 is 2009-11-10 23:00:00. t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00") // The full sequence is files 1-5, but we send only 1 and 5, // simulating monitor failure during 2-4. More below... file := fmt.Sprintf("%s/c003-1.json", sample) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } file = fmt.Sprintf("%s/c003-5.json", sample) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } // Next interval causes 1st to be reported. file = fmt.Sprintf("%s/c003-n.json", sample) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } /** * Values we did get are 100 and 1600 and ts 00 to 04. So that looks like * 1500 bytes / 4s = 375. And since there was only 1 interval, we expect * 375 for all stat values. */ got := test.WaitMmReport(s.dataChan) t.Assert(got, NotNil) t.Check(got.Ts, Equals, t1) t.Check(uint64(got.Duration), Equals, uint64(interval)) expect := &mm.Report{} if err := test.LoadMmReport(sample+"/c003rlost.json", expect); err != nil { t.Fatal("c003r.json ", err) } if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok { test.Dump(got.Stats) test.Dump(expect.Stats) t.Fatal(diff) } }
func (s *AggregatorTestSuite) TestC001(t *C) { interval := int64(300) a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool) go a.Start() defer a.Stop() // Load collection from file and send to aggregator. if err := sendCollection(sample+"/c001-1.json", s.collectionChan); err != nil { t.Fatal(err) } // Ts in c001 is 2009-11-10 23:00:00. t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00") got := test.WaitMmReport(s.dataChan) if got != nil { t.Error("No report before 2nd interval, got: %+v", got) } // Ts in c001 is 2009-11-10 23:05:01, 1s into the next interval. if err := sendCollection(sample+"/c001-2.json", s.collectionChan); err != nil { t.Fatal(err) } got = test.WaitMmReport(s.dataChan) t.Assert(got, NotNil) t.Check(got.Ts, Equals, t1) t.Check(uint64(got.Duration), Equals, uint64(interval)) expect := &mm.Report{} if err := test.LoadMmReport(sample+"/c001r.json", expect); err != nil { t.Fatal(err) } t.Check(got.Ts, Equals, t1) if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok { test.Dump(got.Stats) test.Dump(expect.Stats) t.Fatal(diff) } }
// COUNTER func (s *AggregatorTestSuite) TestC003(t *C) { interval := int64(5) a := mm.NewAggregator(s.logger, interval, s.collectionChan, s.spool) go a.Start() defer a.Stop() // Ts in c003 is 2009-11-10 23:00:00. t1, _ := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00") for i := 1; i <= 5; i++ { file := fmt.Sprintf("%s/c003-%d.json", sample, i) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } } // Next interval causes 1st to be reported. file := fmt.Sprintf("%s/c003-n.json", sample) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } /** * Pretend we're monitoring Bytes_sents every second: * first val = 100 * prev this diff val/s * next val 100 200 100 100 * next val 200 400 200 200 * next val 400 800 400 400 * next val 800 1600 800 800 * * So min bytes/s = 100, max = 800, avg = 375. These are * the values in c003r.json. */ got := test.WaitMmReport(s.dataChan) t.Assert(got, NotNil) t.Check(got.Ts, Equals, t1) t.Check(uint64(got.Duration), Equals, uint64(interval)) expect := &mm.Report{} if err := test.LoadMmReport(sample+"/c003r.json", expect); err != nil { t.Fatal("c003r.json ", err) } if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok { t.Fatal(diff) } // Get the collected stats // As got.Stats[0].Stats is a map, we run this empty 'for' loop just to get // the stats for the first key in the map, into the stats variable. var stats *mm.Stats for _, stats = range got.Stats[0].Stats { } // First time, stats.Cnt must be equal to the number of seconds in the interval // minus 1 because the first value is used to bootstrap the aggregator t.Check(int64(stats.Cnt), Equals, interval-1) // Let's complete the second interval for i := 6; i <= 9; i++ { file := fmt.Sprintf("%s/c003-%d.json", sample, i) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } } // Sample #10 will be in the 3rd interval, so the 2nd will be reported file = fmt.Sprintf("%s/c003-%d.json", sample, 10) if err := sendCollection(file, s.collectionChan); err != nil { t.Fatal(file, err) } got = test.WaitMmReport(s.dataChan) t.Assert(got, NotNil) // Get the collected stats for _, stats = range got.Stats[0].Stats { } // stats.Cnt must be equal to the number of seconds in the interval t.Check(int64(stats.Cnt), Equals, interval) if err := test.LoadMmReport(sample+"/c003r2.json", expect); err != nil { t.Fatal("c003r2.json ", err) } if ok, diff := test.IsDeeply(got.Stats, expect.Stats); !ok { t.Fatal(diff) } }