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

Function TestJetStreamManagement

test/js_test.go:2392–3065  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2390}
2391
2392func TestJetStreamManagement(t *testing.T) {
2393 conf := createConfFile(t, []byte(`
2394 listen: 127.0.0.1:-1
2395 jetstream: enabled
2396 accounts: {
2397 A {
2398 users: [{ user: "foo" }]
2399 jetstream: { max_mem: 64MB, max_file: 64MB }
2400 }
2401 }
2402 `))
2403 defer os.Remove(conf)
2404
2405 s, _ := RunServerWithConfig(conf)
2406 defer shutdownJSServerAndRemoveStorage(t, s)
2407
2408 nc, js := jsClient(t, s, nats.UserInfo("foo", ""))
2409 defer nc.Close()
2410
2411 // Create the stream using our client API.
2412 var si *nats.StreamInfo
2413
2414 t.Run("create stream", func(t *testing.T) {
2415 consLimits := nats.StreamConsumerLimits{
2416 MaxAckPending: 100,
2417 InactiveThreshold: 10 * time.Second,
2418 }
2419 cfg := &nats.StreamConfig{
2420 Name: "foo",
2421 Subjects: []string{"foo", "bar", "baz"},
2422 Compression: nats.S2Compression,
2423 ConsumerLimits: nats.StreamConsumerLimits{
2424 MaxAckPending: 100,
2425 InactiveThreshold: 10 * time.Second,
2426 },
2427 FirstSeq: 22,
2428 Metadata: map[string]string{
2429 "foo": "bar",
2430 "baz": "quux",
2431 },
2432 }
2433
2434 si, err := js.AddStream(cfg)
2435 if err != nil {
2436 t.Fatalf("Unexpected error: %v", err)
2437 }
2438 if si == nil || si.Config.Name != "foo" {
2439 t.Fatalf("StreamInfo is not correct %+v", si)
2440 }
2441 if v1, v2 := si.Config.Metadata["foo"], si.Config.Metadata["baz"]; v1 != "bar" || v2 != "quux" {
2442 t.Fatalf("Metadata is not correct %+v", si.Config.Metadata)
2443 }
2444 if si.Config.Compression != nats.S2Compression {
2445 t.Fatalf("Compression is not correct %+v", si.Config.Compression)
2446 }
2447 if si.Config.FirstSeq != 22 {
2448 t.Fatalf("FirstSeq is not correct %+v", si.Config.FirstSeq)
2449 }

Callers

nothing calls this directly

Calls 15

FatalfMethod · 0.80
UnsubscribeMethod · 0.80
NextMsgMethod · 0.80
JetStreamMethod · 0.80
ErrorfMethod · 0.80
createConfFileFunction · 0.70
RunServerWithConfigFunction · 0.70
jsClientFunction · 0.70
AddStreamMethod · 0.65
PublishMethod · 0.65
StreamInfoMethod · 0.65

Tested by

no test coverage detected