MCPcopy
hub / github.com/nats-io/nats.go / testJetStreamFetchOptions

Function testJetStreamFetchOptions

test/js_test.go:7780–8050  ·  view source on GitHub ↗
(t *testing.T, srvs ...*jsServer)

Source from the content-addressed store, hash-verified

7778}
7779
7780func testJetStreamFetchOptions(t *testing.T, srvs ...*jsServer) {
7781 srv := srvs[0]
7782 nc, js := jsClient(t, srv.Server)
7783 defer nc.Close()
7784
7785 var err error
7786
7787 subject := "WQ"
7788 _, err = js.AddStream(&nats.StreamConfig{
7789 Name: subject,
7790 Replicas: 1,
7791 })
7792 if err != nil {
7793 t.Fatal(err)
7794 }
7795
7796 sendMsgs := func(t *testing.T, totalMsgs int) {
7797 t.Helper()
7798 for i := 0; i < totalMsgs; i++ {
7799 payload := fmt.Sprintf("i:%d", i)
7800 _, err := js.Publish(subject, []byte(payload))
7801 if err != nil {
7802 t.Errorf("Unexpected error: %v", err)
7803 }
7804 }
7805 }
7806
7807 t.Run("max request batch", func(t *testing.T) {
7808 defer js.PurgeStream(subject)
7809
7810 sub, err := js.PullSubscribe(subject, "max-request-batch", nats.MaxRequestBatch(2))
7811 if err != nil {
7812 t.Fatal(err)
7813 }
7814 defer sub.Unsubscribe()
7815 if _, err := sub.Fetch(10); err == nil || !strings.Contains(err.Error(), "MaxRequestBatch of 2") {
7816 t.Fatalf("Expected error about max request batch size, got %v", err)
7817 }
7818 })
7819
7820 t.Run("max request max bytes", func(t *testing.T) {
7821 defer js.PurgeStream(subject)
7822
7823 sub, err := js.PullSubscribe(subject, "max-request-max-bytes", nats.MaxRequestMaxBytes(100))
7824 if err != nil {
7825 t.Fatal(err)
7826 }
7827 defer sub.Unsubscribe()
7828
7829 if _, err := sub.Fetch(10, nats.PullMaxBytes(200)); err == nil || !strings.Contains(err.Error(), "MaxRequestMaxBytes of 100") {
7830 t.Fatalf("Expected error about max request max bytes, got %v", err)
7831 }
7832 })
7833
7834 t.Run("max request expires", func(t *testing.T) {
7835 defer js.PurgeStream(subject)
7836
7837 sub, err := js.PullSubscribe(subject, "max-request-expires", nats.MaxRequestExpires(50*time.Millisecond))

Callers

nothing calls this directly

Calls 15

ErrorfMethod · 0.80
UnsubscribeMethod · 0.80
FatalfMethod · 0.80
AckSyncMethod · 0.80
jsClientFunction · 0.70
checkForFunction · 0.70
AddStreamMethod · 0.65
PublishMethod · 0.65
PurgeStreamMethod · 0.65
PullSubscribeMethod · 0.65
FetchMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected