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

Function TestJetStreamCrossAccountMirrorsAndSources

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

Source from the content-addressed store, hash-verified

4548}
4549
4550func TestJetStreamCrossAccountMirrorsAndSources(t *testing.T) {
4551 conf := createConfFile(t, []byte(`
4552 listen: 127.0.0.1:-1
4553 no_auth_user: rip
4554 jetstream: {max_mem_store: 64GB, max_file_store: 10TB}
4555 accounts {
4556 JS {
4557 jetstream: enabled
4558 users = [ { user: "rip", pass: "pass" } ]
4559 exports [
4560 { service: "$JS.API.CONSUMER.>" } # To create internal consumers to mirror/source.
4561 { stream: "RI.DELIVER.SYNC.>" } # For the mirror/source consumers sending to IA via delivery subject.
4562 ]
4563 }
4564 IA {
4565 jetstream: enabled
4566 users = [ { user: "dlc", pass: "pass" } ]
4567 imports [
4568 { service: { account: JS, subject: "$JS.API.CONSUMER.>"}, to: "RI.JS.API.CONSUMER.>" }
4569 { stream: { account: JS, subject: "RI.DELIVER.SYNC.>"} }
4570 ]
4571 }
4572 $SYS { users = [ { user: "admin", pass: "s3cr3t!" } ] }
4573 }
4574 `))
4575 defer os.Remove(conf)
4576
4577 s, _ := RunServerWithConfig(conf)
4578 defer shutdownJSServerAndRemoveStorage(t, s)
4579
4580 nc1, js1 := jsClient(t, s, nats.UserInfo("rip", "pass"))
4581 defer nc1.Close()
4582
4583 var err error
4584
4585 _, err = js1.AddStream(&nats.StreamConfig{
4586 Name: "TEST",
4587 Replicas: 1,
4588 })
4589 if err != nil {
4590 t.Fatal(err)
4591 }
4592
4593 const (
4594 toSend = 100
4595 publishSubj = "TEST"
4596 sourceName = "MY_SOURCE_TEST"
4597 mirrorName = "MY_MIRROR_TEST"
4598 )
4599 for i := 0; i < toSend; i++ {
4600 data := []byte(fmt.Sprintf("OK %d", i))
4601 if _, err := js1.Publish(publishSubj, data); err != nil {
4602 t.Fatalf("Unexpected publish error: %v", err)
4603 }
4604 }
4605
4606 nc2, js2 := jsClient(t, s, nats.UserInfo("dlc", "pass"))
4607 defer nc2.Close()

Callers

nothing calls this directly

Calls 15

checkSubsPendingFunction · 0.85
FatalfMethod · 0.80
ErrorfMethod · 0.80
UnsubscribeMethod · 0.80
NextMsgMethod · 0.80
createConfFileFunction · 0.70
RunServerWithConfigFunction · 0.70
jsClientFunction · 0.70
checkForFunction · 0.70
AddStreamMethod · 0.65
PublishMethod · 0.65

Tested by

no test coverage detected