Skip to content

Commit

Permalink
rename sender.FailOver()
Browse files Browse the repository at this point in the history
  • Loading branch information
karenychen committed Jul 8, 2024
1 parent b963774 commit f1cc680
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions v2/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,21 @@ func (d *Sender) AzSender() AzServiceBusSender {
return d.sbSender
}

// FailOver sets the underlying azservicebus.Sender instance to the provided one.
// This is used when the traffic needs to be failed over to a different sender instance.
// SetAzSender sets the underlying azservicebus.Sender instance to the provided one.
// All ongoing send operations will continue to use the old sender instance,
// while new send operations will use the new sender instance.
func (d *Sender) FailOver(sender AzServiceBusSender) {
func (d *Sender) SetAzSender(sender AzServiceBusSender) {
d.mu.Lock()
defer d.mu.Unlock()
d.sbSender = sender
}

// Deprecated: use SetAzSender.
// FailOver sets the underlying azservicebus.Sender instance to the provided one.
func (d *Sender) FailOver(sender AzServiceBusSender) {
d.SetAzSender(sender)
}

// SetMessageId sets the ServiceBus message's ID to a user-specified value
func SetMessageId(messageId *string) func(msg *azservicebus.Message) error {
return func(msg *azservicebus.Message) error {
Expand Down
10 changes: 5 additions & 5 deletions v2/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,18 @@ func TestSender_AzSender(t *testing.T) {
g.Expect(sender.AzSender()).To(Equal(azSender))
}

func TestSender_FailOver(t *testing.T) {
func TestSender_SetAzSender(t *testing.T) {
g := NewWithT(t)
azSender := &fakeAzSender{SendMessageErr: fmt.Errorf("msg send failure")}
sender := NewSender(azSender, nil)
err := sender.SendMessage(context.Background(), "test")
g.Expect(err).To(HaveOccurred())
sender.FailOver(&fakeAzSender{})
sender.SetAzSender(&fakeAzSender{})
err = sender.SendMessage(context.Background(), "test")
g.Expect(err).ToNot(HaveOccurred())
}

func TestSender_ConcurrentSendAndFailOver(t *testing.T) {
func TestSender_ConcurrentSendAndSetAzSender(t *testing.T) {
g := NewWithT(t)
azSender1 := &fakeAzSender{}
azSender2 := &fakeAzSender{}
Expand All @@ -294,9 +294,9 @@ func TestSender_ConcurrentSendAndFailOver(t *testing.T) {
g.Expect(err).ToNot(HaveOccurred())
}(i)
}
// call FailOver in the middle
// call SetAzSender in the middle
time.Sleep(5 * time.Millisecond)
sender.FailOver(azSender2)
sender.SetAzSender(azSender2)
// wait for all goroutines to finish
wg.Wait()
// check that some messages were sent with the first sender and some with the second
Expand Down

0 comments on commit f1cc680

Please sign in to comment.