Ejemplo n.º 1
0
func (s *TestSuite) aggregateSlowLog(input, output string, utcOffset time.Duration) (got event.Result, expect event.Result) {
	bytes, err := ioutil.ReadFile(path.Join(s.result, "/", output))
	if err != nil {
		l.Fatal(err)
	}
	expect = event.Result{}
	if err := json.Unmarshal(bytes, &expect); err != nil {
		l.Fatal(err)
	}

	file, err := os.Open(path.Join(s.sample, "/", input))
	if err != nil {
		l.Fatal(err)
	}
	p := parser.NewSlowLogParser(file, log.Options{})
	if err != nil {
		l.Fatal(err)
	}
	go p.Start()
	a := event.NewAggregator(s.examples, utcOffset, 10)
	for e := range p.EventChan() {
		f := query.Fingerprint(e.Query)
		id := query.Id(f)
		a.AddEvent(e, id, f)
	}
	got = a.Finalize()
	return got, expect
}
Ejemplo n.º 2
0
func (s *TestSuite) TestId(t *C) {
	var f string

	f = "hello world"
	t.Check(
		query.Id(f),
		Equals,
		"93CB22BB8F5ACDC3",
	)

	f = "select sourcetable, if(f.lastcontent = ?, f.lastupdate, f.lastcontent) as lastactivity, f.totalcount as activity, type.class as type, (f.nodeoptions & ?) as nounsubscribe from node as f inner join contenttype as type on type.contenttypeid = f.contenttypeid inner join subscribed as sd on sd.did = f.nodeid and sd.userid = ? union all select f.name as title, f.userid as keyval, ? as sourcetable, ifnull(f.lastpost, f.joindate) as lastactivity, f.posts as activity, ? as type, ? as nounsubscribe from user as f inner join userlist as ul on ul.relationid = f.userid and ul.userid = ? where ul.type = ? and ul.aq = ? order by title limit ?"
	t.Check(
		query.Id(f),
		Equals,
		"DB9EF18846547B8C",
	)

	f = "select sleep(?) from n"
	t.Check(
		query.Id(f),
		Equals,
		"7F7D57ACDD8A346E",
	)
}