Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test on direct get with subject filter #5953

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions server/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22486,6 +22486,52 @@ func TestJetStreamDirectGetBatch(t *testing.T) {
checkResponses(sub, 3, "foo.foo", "foo.bar", "foo.baz", _EMPTY_)
}

func TestJetStreamDirectGetBatchFiltered(t *testing.T) {
s := RunBasicJetStreamServer(t)
defer s.Shutdown()

nc, js := jsClientConnect(t, s)
defer nc.Close()

_, err := js.AddStream(&nats.StreamConfig{
Name: "TEST",
Subjects: []string{"a", "b"},
MaxMsgsPerSubject: -1,
AllowDirect: true,
})
require_NoError(t, err)

js.Publish("a", []byte("HELLO"))
js.Publish("b", []byte("WORLD"))
js.Publish("a", []byte("AGAIN"))

si, err := js.StreamInfo("TEST")
require_NoError(t, err)
require_Equal(t, 3, si.State.Msgs)

// Direct subjects.
sendRequest := func(mreq *JSApiMsgGetRequest) *nats.Subscription {
t.Helper()
req, _ := json.Marshal(mreq)
// We will get multiple responses so can't do normal request.
reply := nats.NewInbox()
sub, err := nc.SubscribeSync(reply)
require_NoError(t, err)
err = nc.PublishRequest("$JS.API.DIRECT.GET.TEST", reply, req)
require_NoError(t, err)
return sub
}

// Run some simple tests.
sub := sendRequest(&JSApiMsgGetRequest{Seq: 1, Batch: 1, MultiLastFor: []string{"a", "b"}})
defer sub.Unsubscribe()
msg, err := sub.NextMsg(10 * time.Millisecond)
require_NoError(t, err)
require_Equal(t, "1", msg.Header.Get(JSSequence))
Copy link
Member Author

@aricart aricart Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derekcollison Expected the first message to be sequence 1 - tried with the request being 0 as well. But first message here is always sequence 2 - b

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main issue is that currently the filter for the subjects triggers as a last for subject - but need an option that is simply a subject filter without last semantics. Perhaps this could be aligned with consumer semantics where last_per_subject is a boolean, and we just have a filter_subjects that specifies the filter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use NextFor to walk through messages. The one you are using is only for last by subject.

require_Equal(t, "2", msg.Header.Get(JSNumPending))
require_Equal(t, "a", msg.Header.Get(JSSubject))
}

func TestJetStreamDirectGetBatchMaxBytes(t *testing.T) {
s := RunBasicJetStreamServer(t)
defer s.Shutdown()
Expand Down