-
Notifications
You must be signed in to change notification settings - Fork 28
/
query_supervisor_test.go
101 lines (83 loc) · 2.02 KB
/
query_supervisor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2018-Present Couchbase, Inc.
//
// Use of this software is governed by the Business Source License included
// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
// in that file, in accordance with the Business Source License, use of this
// software will be governed by the Apache License, Version 2.0, included in
// the file licenses/APL2.txt.
package cbft
import (
"testing"
"github.com/blevesearch/bleve/v2"
)
func TestQuerySupervisor(t *testing.T) {
// initial set
for i := 0; i < 50; i++ {
querySupervisor.AddEntry(nil)
}
done := make(chan struct{})
// inserts' routine
go func() {
for i := 0; i < 100; i++ {
querySupervisor.AddEntry(nil)
}
done <- struct{}{}
}()
// deletes' routine
go func() {
for i := uint64(1); i <= 50; i++ {
querySupervisor.DeleteEntry(i)
}
done <- struct{}{}
}()
<-done
<-done
if querySupervisor.id != 150 {
t.Errorf("ID: %v, not expected!", querySupervisor.id)
}
if querySupervisor.Count() != 100 {
t.Errorf("Count: %v, not expected!", querySupervisor.Count())
}
if _, ok := querySupervisor.ExecutionTime(querySupervisor.id); !ok {
t.Errorf("Expected id: %v to exist!", querySupervisor.id)
}
}
func BenchmarkListLongerThan(b *testing.B) {
for i := 0; i < 100; i++ {
querySupervisor.AddEntry(&QuerySupervisorContext{
Query: bleve.NewMatchQuery("test"),
Cancel: nil,
Size: 10,
From: 0,
Timeout: 10,
IndexName: "dummy",
})
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
done := make(chan struct{})
// reads' routine
go func() {
for i := 0; i < 50; i++ {
_, _ = querySupervisor.ListLongerThanWithQueryCount(0, "")
}
done <- struct{}{}
}()
// inserts' routine
go func() {
for i := 0; i < 100; i++ {
querySupervisor.AddEntry(&QuerySupervisorContext{
Query: bleve.NewMatchQuery("test"),
Cancel: nil,
Size: 10,
From: 0,
Timeout: 10,
IndexName: "dummy",
})
}
done <- struct{}{}
}()
<-done
<-done
}
}