-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the ReliableProducer during the broker restart (#268)
* Closes #265 * add random sleep during the producer restart * check the stream status during the restart * add tests for the reliable producer --------- Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
- Loading branch information
1 parent
9e48184
commit a503d8a
Showing
10 changed files
with
290 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package ha | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/amqp" | ||
. "github.com/rabbitmq/rabbitmq-stream-go-client/pkg/stream" | ||
"sync/atomic" | ||
) | ||
|
||
var _ = Describe("Reliable Producer", func() { | ||
|
||
var ( | ||
envForRProducer *Environment | ||
streamForRProducer string | ||
) | ||
BeforeEach(func() { | ||
testEnv, err := NewEnvironment(nil) | ||
envForRProducer = testEnv | ||
Expect(err).NotTo(HaveOccurred()) | ||
streamForRProducer = uuid.New().String() | ||
err = envForRProducer.DeclareStream(streamForRProducer, nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
AfterEach(func() { | ||
Expect(envForRProducer.DeleteStream(streamForRProducer)).NotTo(HaveOccurred()) | ||
}) | ||
|
||
It("Validate confirm handler", func() { | ||
_, err := NewReliableProducer(envForRProducer, | ||
streamForRProducer, &ProducerOptions{}, nil) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
|
||
It("Create/Confirm and close a Reliable Producer", func() { | ||
signal := make(chan struct{}) | ||
var confirmed int32 | ||
producer, err := NewReliableProducer(envForRProducer, | ||
streamForRProducer, NewProducerOptions(), func(messageConfirm []*ConfirmationStatus) { | ||
for _, confirm := range messageConfirm { | ||
Expect(confirm.IsConfirmed()).To(BeTrue()) | ||
} | ||
if atomic.AddInt32(&confirmed, int32(len(messageConfirm))) == 10 { | ||
signal <- struct{}{} | ||
} | ||
}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
for i := 0; i < 10; i++ { | ||
msg := amqp.NewMessage([]byte("ha")) | ||
err := producer.Send(msg) | ||
Expect(err).NotTo(HaveOccurred()) | ||
} | ||
<-signal | ||
Expect(producer.Close()).NotTo(HaveOccurred()) | ||
}) | ||
|
||
//TODO: The test is commented out because it is not possible to kill the connection from the client side | ||
// the client provider name is not exposed to the user. | ||
// we need to expose it than kill the connection | ||
|
||
//It("restart Reliable Producer in case of killing connection", func() { | ||
// signal := make(chan struct{}) | ||
// var confirmed int32 | ||
// producer, err := NewReliableProducer(envForRProducer, | ||
// streamForRProducer, &ProducerOptions{}, func(messageConfirm []*ConfirmationStatus) { | ||
// for _, confirm := range messageConfirm { | ||
// Expect(confirm.IsConfirmed()).To(BeTrue()) | ||
// } | ||
// if atomic.AddInt32(&confirmed, int32(len(messageConfirm))) == 10 { | ||
// signal <- struct{}{} | ||
// } | ||
// }) | ||
// Expect(err).NotTo(HaveOccurred()) | ||
// | ||
// // kill the connection | ||
// | ||
// for i := 0; i < 10; i++ { | ||
// msg := amqp.NewMessage([]byte("ha")) | ||
// err := producer.Send(msg) | ||
// Expect(err).NotTo(HaveOccurred()) | ||
// } | ||
// <-signal | ||
// Expect(producer.Close()).NotTo(HaveOccurred()) | ||
//}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ha_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestHa(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Ha Suite") | ||
} |
Oops, something went wrong.