forked from nats-io/jsm.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_pager_test.go
66 lines (54 loc) · 1.15 KB
/
stream_pager_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
package jsm_test
import (
"context"
"fmt"
"testing"
"time"
"github.com/nats-io/jsm.go"
)
func TestPager(t *testing.T) {
srv, nc, mgr := startJSServer(t)
defer srv.Shutdown()
defer nc.Flush()
str, err := mgr.NewStream("PAGERTEST", jsm.Subjects("js.in.pager"))
if err != nil {
t.Fatalf("stream create failed: %s", err)
}
for i := 1; i <= 200; i++ {
_, err = nc.Request("js.in.pager", []byte(fmt.Sprintf("message %d", i)), time.Second)
if err != nil {
t.Fatalf("publish failed: %s", err)
}
}
pgr, err := str.PageContents(jsm.PagerSize(25))
if err != nil {
t.Fatalf("pager creation failed: %s", err)
}
defer pgr.Close()
seen := 0
pages := 0
for {
_, last, err := pgr.NextMsg(context.Background())
if err != nil && last && seen == 200 && pages == 8 {
break
}
if err != nil {
t.Fatalf("next failed seen %d pages %d: %s", seen, pages, err)
}
seen++
if last {
pages++
}
}
err = pgr.Close()
if err != nil {
t.Fatalf("close failed")
}
known, err := str.ConsumerNames()
if err != nil {
t.Fatalf("consumer named failed: %s", err)
}
if len(known) != 0 {
t.Fatalf("expected no consumers got %v", known)
}
}