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

Function TestJetStreamConsumerConfigReplicasAndMemStorage

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

Source from the content-addressed store, hash-verified

9761}
9762
9763func TestJetStreamConsumerConfigReplicasAndMemStorage(t *testing.T) {
9764 withJSCluster(t, "CR", 3, func(t *testing.T, nodes ...*jsServer) {
9765 nc, js := jsClient(t, nodes[0].Server)
9766 defer nc.Close()
9767
9768 if _, err := js.AddStream(&nats.StreamConfig{
9769 Name: "CR",
9770 Subjects: []string{"foo"},
9771 Replicas: 3,
9772 }); err != nil {
9773 t.Fatalf("Error adding stream: %v", err)
9774 }
9775
9776 // We can't really check if the consumer ends-up with memory storage or not.
9777 // We are simply going to create a NATS subscription on the request subject
9778 // and make sure that the request contains "mem_storage:true".
9779 sub, err := nc.SubscribeSync("$JS.API.CONSUMER.CREATE.CR.dur")
9780 if err != nil {
9781 t.Fatalf("Error on subscribe: %v", err)
9782 }
9783
9784 ci, err := js.AddConsumer("CR", &nats.ConsumerConfig{
9785 Durable: "dur",
9786 DeliverSubject: "bar",
9787 Replicas: 1,
9788 MemoryStorage: true,
9789 })
9790 if err != nil {
9791 t.Fatalf("Error adding consumer: %v", err)
9792 }
9793 if n := len(ci.Cluster.Replicas); n > 0 {
9794 t.Fatalf("Expected replicas to be 1, got %+v", ci.Cluster)
9795 }
9796 msg, err := sub.NextMsg(time.Second)
9797 if err != nil {
9798 t.Fatalf("Error on next msg: %v", err)
9799 }
9800 if str := string(msg.Data); !strings.Contains(str, "mem_storage\":true") {
9801 t.Fatalf("Does not look like the request asked for memory storage: %s", str)
9802 }
9803 })
9804}
9805
9806func TestJetStreamRePublish(t *testing.T) {
9807 s := RunBasicJetStreamServer()

Callers

nothing calls this directly

Calls 8

FatalfMethod · 0.80
NextMsgMethod · 0.80
withJSClusterFunction · 0.70
jsClientFunction · 0.70
AddStreamMethod · 0.65
SubscribeSyncMethod · 0.65
AddConsumerMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected