-
Notifications
You must be signed in to change notification settings - Fork 9
/
request_reply_message_publisher_test.go
576 lines (509 loc) · 24.4 KB
/
request_reply_message_publisher_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
// pubsubplus-go-client
//
// Copyright 2021-2024 Solace Corporation. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package test
import (
"fmt"
"time"
"solace.dev/go/messaging"
"solace.dev/go/messaging/pkg/solace"
"solace.dev/go/messaging/pkg/solace/config"
"solace.dev/go/messaging/pkg/solace/message"
"solace.dev/go/messaging/pkg/solace/metrics"
"solace.dev/go/messaging/pkg/solace/resource"
"solace.dev/go/messaging/test/helpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("RequestReplyPublisher", func() {
var messagingService solace.MessagingService
BeforeEach(func() {
builder := messaging.NewMessagingServiceBuilder().FromConfigurationProvider(helpers.DefaultConfiguration())
messagingService = helpers.BuildMessagingService(builder)
})
Describe("Builder verification", func() {
invalidConfigurations := map[string]config.PublisherPropertyMap{
"invalid backpressure configuration": {
config.PublisherPropertyBackPressureStrategy: "not a strategy",
},
"invalid backpressure configuration type": {
config.PublisherPropertyBackPressureStrategy: 1234,
},
"invalid backpressure buffer size type": {
config.PublisherPropertyBackPressureBufferCapacity: "asdf",
},
}
for key, val := range invalidConfigurations {
invalidConfiguration := val
It("fails to build with "+key, func() {
_, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().FromConfigurationProvider(invalidConfiguration).Build()
helpers.ValidateError(err, &solace.IllegalArgumentError{})
})
}
invalidBufferCapacity := map[string]config.PublisherPropertyMap{
"invalid backpressure capacity in reject": {
config.PublisherPropertyBackPressureStrategy: config.PublisherPropertyBackPressureStrategyBufferRejectWhenFull,
config.PublisherPropertyBackPressureBufferCapacity: -1,
},
"invalid backpressure capacity in wait": {
config.PublisherPropertyBackPressureStrategy: config.PublisherPropertyBackPressureStrategyBufferWaitWhenFull,
config.PublisherPropertyBackPressureBufferCapacity: 0,
},
}
for key, val := range invalidBufferCapacity {
invalidConfiguration := val
It("fails to build with "+key, func() {
_, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().FromConfigurationProvider(invalidConfiguration).Build()
helpers.ValidateError(err, &solace.InvalidConfigurationError{})
})
}
requiredProperties := map[string]config.PublisherPropertyMap{
"nil backpressure configuration": {
config.PublisherPropertyBackPressureStrategy: nil,
},
"nil buffer size": {
config.PublisherPropertyBackPressureBufferCapacity: nil,
},
}
for key, value := range requiredProperties {
invalidConfiguration := value
It("should error with "+key, func() {
_, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().FromConfigurationProvider(invalidConfiguration).Build()
helpers.ValidateError(err, &solace.InvalidConfigurationError{}, "required property")
})
}
validConfigurations := map[string]config.PublisherPropertyMap{
"valid backpressure configuration": {
config.PublisherPropertyBackPressureStrategy: config.PublisherPropertyBackPressureStrategyBufferWaitWhenFull,
},
"valid backpressure configuration type": {
config.PublisherPropertyBackPressureStrategy: config.PublisherPropertyBackPressureStrategyBufferRejectWhenFull,
},
"valid backpressure buffer size type": {
config.PublisherPropertyBackPressureBufferCapacity: 50,
},
}
for key, val := range validConfigurations {
validConfiguration := val
It("succeeds to build with "+key, func() {
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().FromConfigurationProvider(validConfiguration).Build()
expected := &solace.IllegalArgumentError{}
Expect(publisher).ShouldNot(Equal(nil))
Expect(publisher.IsRunning()).To(BeFalse()) // running state should be false
ExpectWithOffset(2, err).ToNot(HaveOccurred(), "Expected error to not have occurred")
ExpectWithOffset(2, err).ToNot(BeAssignableToTypeOf(expected), fmt.Sprintf("Expected error of type %T to not be assignable of type %T", err, expected))
})
}
It("can print the builder to a string and see the pointer", func() {
builder := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder()
str := fmt.Sprint(builder)
Expect(str).ToNot(BeEmpty())
Expect(str).To(ContainSubstring(fmt.Sprintf("%p", builder)))
})
// this may be a duplicate test but won't hurt to add it here for Request-Reply
It("can print a topic to a string", func() {
topicString := "request-reply-try-me"
topic := resource.TopicOf(topicString)
Expect(topic.String()).To(ContainSubstring(topicString))
})
})
Context("with a connected messaging service", func() {
var messageBuilder solace.OutboundMessageBuilder
BeforeEach(func() {
helpers.ConnectMessagingService(messagingService)
messageBuilder = messagingService.MessageBuilder()
})
AfterEach(func() {
if messagingService.IsConnected() {
helpers.DisconnectMessagingService(messagingService)
}
})
It("can print the publisher to a string and see the pointer", func() {
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred())
str := fmt.Sprint(publisher)
Expect(str).ToNot(BeEmpty())
Expect(str).To(ContainSubstring(fmt.Sprintf("%p", publisher)))
})
Describe("request-reply publisher termination tests", func() {
publishTopic := resource.TopicOf("hello/world")
topicSubscription := resource.TopicSubscriptionOf("hello/world")
largeByteArray := make([]byte, 16384)
timeOut := 5 * time.Second
// A handler for the request-reply publisher
publisherReplyHandler := func(message message.InboundMessage, userContext interface{}, err error) {
if err == nil { // Good, a reply was received
Expect(message).ToNot(BeNil())
} else {
// message should be nil
Expect(message).To(BeNil())
Expect(err).ToNot(BeNil())
}
}
// A helper function to saturate a given publisher (fill up its internal buffers).
// Counts the number of published messages at the given int pointer
// Returns a channel that is closed when the publisher receives an error from a call to Publish
// Returns a channel that can be closed when the test completes, ie. if an error occurred
publisherSaturation := func(publisher solace.RequestReplyMessagePublisher, bufferSize uint, publishedMessages *int) (publisherSaturated, publisherComplete, testComplete chan struct{}) {
isSaturated := false
publisherSaturated = make(chan struct{})
publisherComplete = make(chan struct{})
testComplete = make(chan struct{})
toPublish, err := messageBuilder.BuildWithByteArrayPayload(largeByteArray)
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
loop:
for {
select {
case <-testComplete:
break loop
default:
}
err := publisher.Publish(toPublish, publisherReplyHandler, publishTopic, timeOut, nil /* properties */, nil /* usercontext */)
if err != nil {
Expect(err).To(BeAssignableToTypeOf(&solace.IllegalStateError{}))
break loop
} else {
(*publishedMessages)++
}
// buffer is at least halfway filled
if !isSaturated && (uint(*publishedMessages) > bufferSize/2) {
close(publisherSaturated)
isSaturated = true
}
}
close(publisherComplete)
}()
return publisherSaturated, publisherComplete, testComplete
}
It("should publish all messages on graceful termination (no waiting for reply messages)", func() {
publishedMessages := 0
bufferSize := uint(1000)
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().OnBackPressureWait(bufferSize).Build()
Expect(err).ToNot(HaveOccurred())
err = publisher.Start()
Expect(err).ToNot(HaveOccurred())
defer publisher.Terminate(0)
publisherSaturated, publisherComplete, testComplete := publisherSaturation(publisher, bufferSize, &publishedMessages)
defer close(testComplete)
// allow the goroutine above to saturate the publisher
select {
case <-publisherComplete:
// block until publish complete
Fail("Expected publisher to not be complete")
case <-publisherSaturated:
// allow the goroutine above to saturate the publisher (at least halfway filled)
case <-time.After(2 * time.Second):
// should not timeout while saturating the publisher
Fail("Not expected to timeout while saturating publisher; Should not get here")
}
publisherTerminate := publisher.TerminateAsync(30 * time.Second)
select {
case <-publisherComplete:
// success
case <-publisherTerminate:
Fail("expected publisher to complete prior to termination completion")
case <-time.After(15 * time.Second):
Fail("timed out waiting for publisher to complete")
}
select {
case err := <-publisherTerminate:
Expect(err).ToNot(HaveOccurred())
case <-time.After(15 * time.Second):
Fail("timed out waiting for publisher to terminate")
}
Expect(publisher.IsTerminated()).To(BeTrue())
// to account for the reply messages too
Expect(messagingService.Metrics().GetValue(metrics.DirectMessagesSent)).To(BeNumerically("==", publishedMessages))
})
It("should have undelivered messages on ungraceful termination (no waiting for reply messages)", func() {
publishedMessages := 0
bufferSize := uint(5000)
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().OnBackPressureWait(bufferSize).Build()
Expect(err).ToNot(HaveOccurred())
err = publisher.Start()
Expect(err).ToNot(HaveOccurred())
defer publisher.Terminate(0)
publisherSaturated, publisherComplete, testComplete := publisherSaturation(publisher, bufferSize, &publishedMessages)
defer close(testComplete)
// allow the goroutine above to saturate the publisher
select {
case <-publisherComplete:
// block until publish complete
Fail("Expected publisher to not be complete")
case <-publisherSaturated:
// allow the goroutine above to saturate the publisher (at least halfway filled)
case <-time.After(5 * time.Second):
// should not timeout while saturating the publisher
Fail("Not expected to timeout while saturating publisher; Should not get here")
}
publisherTerminate := publisher.TerminateAsync(0 * time.Second)
Eventually(publisherTerminate).Should(Receive(&err))
helpers.ValidateError(err, &solace.IncompleteMessageDeliveryError{})
Eventually(publisherComplete).Should(BeClosed())
Expect(publisher.IsTerminated()).To(BeTrue())
directSent := messagingService.Metrics().GetValue(metrics.DirectMessagesSent)
directDropped := messagingService.Metrics().GetValue(metrics.PublishMessagesTerminationDiscarded)
Expect(directSent).To(BeNumerically("<", publishedMessages))
Expect(directDropped).To(BeNumerically(">", 0))
Expect(directSent + directDropped).To(BeNumerically("==", publishedMessages))
})
It("should have undelivered messages on unsolicited termination of messaging service", func() {
publishedMessages := 0
bufferSize := uint(10000)
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().OnBackPressureWait(bufferSize).Build()
Expect(err).ToNot(HaveOccurred())
err = publisher.Start()
Expect(err).ToNot(HaveOccurred())
defer publisher.Terminate(0)
terminationListenerCalled := make(chan solace.TerminationEvent)
publisher.SetTerminationNotificationListener(func(te solace.TerminationEvent) {
terminationListenerCalled <- te
})
_, publisherComplete, testComplete := publisherSaturation(publisher, bufferSize, &publishedMessages)
defer close(testComplete)
shutdownTime := time.Now()
helpers.ForceDisconnectViaSEMPv2(messagingService)
Eventually(publisherComplete).Should(BeClosed())
Eventually(publisher.IsTerminated).Should(BeTrue())
select {
case te := <-terminationListenerCalled:
Expect(te.GetTimestamp()).To(BeTemporally(">", shutdownTime))
Expect(te.GetTimestamp()).To(BeTemporally("<", time.Now()))
// Expect(te.GetCause()).To(BeAssignableToTypeOf(&solace.NativeError{}))
// SOL-66163: a race condition in CCSMP may cause the error to be nil
// helpers.ValidateNativeError(te.GetCause(), subcode.CommunicationError)
Expect(te.GetMessage()).To(ContainSubstring("Publisher"))
case <-time.After(100 * time.Millisecond):
Fail("timed out waiting for termination listener to be called")
}
publishSent := messagingService.Metrics().GetValue(metrics.DirectMessagesSent)
Expect(publishSent).To(BeNumerically("<", publishedMessages))
})
It("should have undelivered messages on messaging service shutdown/disconnection", func() {
publishedMessages := 0
bufferSize := uint(100)
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().OnBackPressureWait(bufferSize).Build()
Expect(err).ToNot(HaveOccurred())
err = publisher.Start()
Expect(err).ToNot(HaveOccurred())
defer publisher.Terminate(0)
terminationListenerCalled := make(chan solace.TerminationEvent)
publisher.SetTerminationNotificationListener(func(te solace.TerminationEvent) {
terminationListenerCalled <- te
})
_, publisherComplete, testComplete := publisherSaturation(publisher, bufferSize, &publishedMessages)
defer close(testComplete)
shutdownTime := time.Now()
helpers.DisconnectMessagingService(messagingService)
Eventually(publisherComplete).Should(BeClosed())
Eventually(publisher.IsTerminated).Should(BeTrue())
select {
case te := <-terminationListenerCalled:
Expect(te.GetTimestamp()).To(BeTemporally(">", shutdownTime))
Expect(te.GetTimestamp()).To(BeTemporally("<", time.Now()))
Expect(te.GetCause()).To(BeAssignableToTypeOf(&solace.ServiceUnreachableError{}))
case <-time.After(100 * time.Millisecond):
Fail("timed out waiting for termination listener to be called")
}
publishSent := messagingService.Metrics().GetValue(metrics.DirectMessagesSent)
Expect(publishSent).To(BeNumerically("<", publishedMessages))
})
startFunctions := map[string](func(publisher solace.RequestReplyMessagePublisher) <-chan error){
"sync": func(publisher solace.RequestReplyMessagePublisher) <-chan error {
c := make(chan error)
go func() {
c <- publisher.Start()
}()
return c
},
"async": func(publisher solace.RequestReplyMessagePublisher) <-chan error {
return publisher.StartAsync()
},
"callback": func(publisher solace.RequestReplyMessagePublisher) <-chan error {
c := make(chan error)
publisher.StartAsyncCallback(func(dmp solace.RequestReplyMessagePublisher, e error) {
defer GinkgoRecover()
Expect(dmp).To(Equal(publisher))
c <- e
})
return c
},
}
// gracePeriod := 5 * time.Second
terminateFunctions := map[string](func(publisher solace.RequestReplyMessagePublisher, gracePeriod time.Duration) <-chan error){
"sync": func(publisher solace.RequestReplyMessagePublisher, gracePeriod time.Duration) <-chan error {
c := make(chan error)
go func() {
c <- publisher.Terminate(gracePeriod)
}()
return c
},
"async": func(publisher solace.RequestReplyMessagePublisher, gracePeriod time.Duration) <-chan error {
return publisher.TerminateAsync(gracePeriod)
},
"callback": func(publisher solace.RequestReplyMessagePublisher, gracePeriod time.Duration) <-chan error {
c := make(chan error)
publisher.TerminateAsyncCallback(gracePeriod, func(e error) {
c <- e
})
return c
},
}
// for the success paths
for startName, fn := range startFunctions {
for terminateName, fn2 := range terminateFunctions {
start := fn
terminate := fn2
It("can start and terminate with start "+startName+" and terminate "+terminateName+" with subscribed reply receiver on topic", func() {
// build a request replier
receiver := helpers.NewRequestReplyMessageReceiver(messagingService, topicSubscription)
helpers.StartRequestReplyMessageReceiverWithDefault(messagingService, receiver)
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred())
// check that not started
helpers.ValidateReadyState(publisher, false, false, false, false)
// start and check state
Eventually(start(publisher)).Should(Receive(Not(HaveOccurred())))
helpers.ValidateReadyState(publisher, true, true, false, false)
// try using publisher
publisher.PublishString("hello world", publisherReplyHandler, publishTopic, timeOut, nil /* usercontext */)
Eventually(func() int64 {
return helpers.GetClient(messagingService).DataRxMsgCount
}).Should(BeNumerically("==", 2))
// terminate and check state
Eventually(terminate(publisher, 5*time.Second)).Should(Receive(Not(HaveOccurred())))
helpers.ValidateReadyState(publisher, false, false, false, true)
receiver.Terminate(1 * time.Second) // terminate the receiver
})
It("can start and terminate idempotently with start "+startName+" and terminate "+terminateName+" with subscribed reply receiver on topic", func() {
// build a request replier
receiver := helpers.NewRequestReplyMessageReceiver(messagingService, topicSubscription)
helpers.StartRequestReplyMessageReceiverWithDefault(messagingService, receiver)
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred())
// check that not started
helpers.ValidateReadyState(publisher, false, false, false, false)
// start and check state
c1 := start(publisher)
c2 := start(publisher)
Eventually(c1).Should(Receive(Not(HaveOccurred())))
Eventually(c2).Should(Receive(Not(HaveOccurred())))
helpers.ValidateReadyState(publisher, true, true, false, false)
// try using publisher
publisher.PublishString("hello world", publisherReplyHandler, publishTopic, timeOut, nil /* usercontext */)
Eventually(func() int64 {
return helpers.GetClient(messagingService).DataRxMsgCount
}).Should(BeNumerically("==", 2))
// terminate and check state
c1 = terminate(publisher, 5*time.Second)
c2 = terminate(publisher, 5*time.Second)
Eventually(c1).Should(Receive(Not(HaveOccurred())))
Eventually(c2).Should(Receive(Not(HaveOccurred())))
helpers.ValidateReadyState(publisher, false, false, false, true)
c1 = start(publisher)
c2 = start(publisher)
Eventually(c1).Should(Receive(BeAssignableToTypeOf(&solace.IllegalStateError{})))
Eventually(c2).Should(Receive(BeAssignableToTypeOf(&solace.IllegalStateError{})))
receiver.Terminate(1 * time.Second) // terminate the receiver
})
It("can start and terminate with start "+startName+" and terminate "+terminateName+" without subscribed reply receiver and zero grace period", func() {
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred())
// check that not started
helpers.ValidateReadyState(publisher, false, false, false, false)
// start and check state
Eventually(start(publisher)).Should(Receive(Not(HaveOccurred())))
helpers.ValidateReadyState(publisher, true, true, false, false)
// try using publisher
publisher.PublishString("hello world", publisherReplyHandler, publishTopic, timeOut, nil /* usercontext */)
Eventually(func() int64 {
return helpers.GetClient(messagingService).DataRxMsgCount
}).Should(BeNumerically("==", 1))
// terminate and check state
Eventually(terminate(publisher, 0*time.Second)).Should(Receive(Not(HaveOccurred())))
helpers.ValidateReadyState(publisher, false, false, false, true)
})
It("can start and terminate with start "+startName+" and terminate "+terminateName+" without subscribed reply receiver and > 0 grace period", func() {
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred())
// check that not started
helpers.ValidateReadyState(publisher, false, false, false, false)
// start and check state
Eventually(start(publisher)).Should(Receive(Not(HaveOccurred())))
helpers.ValidateReadyState(publisher, true, true, false, false)
// try using publisher
publisher.PublishString("hello world", publisherReplyHandler, publishTopic, timeOut, nil /* usercontext */)
Eventually(func() int64 {
return helpers.GetClient(messagingService).DataRxMsgCount
}).Should(BeNumerically("==", 1))
// terminate and check state
terminateChan := terminate(publisher, 5*time.Second)
Eventually(terminateChan, "5000ms").Should(Receive(BeNil()))
helpers.ValidateReadyState(publisher, false, false, false, true)
})
}
}
// more success paths
for terminateName, fn := range terminateFunctions {
terminate := fn
It("should be able to terminate when not started using terminate "+terminateName, func() {
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred(), "Encountered error while building request-reply publisher")
Eventually(terminate(publisher, 5*time.Second)).Should(Receive(BeNil()))
Expect(publisher.IsTerminated()).To(BeTrue())
helpers.ValidateError(publisher.Start(), &solace.IllegalStateError{})
})
}
// failure paths
It("should fail to publish on unstarted publisher", func() {
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred(), "Encountered error while building request-reply publisher")
helpers.ValidateError(
publisher.Publish(helpers.NewMessage(messagingService), publisherReplyHandler, publishTopic, timeOut, nil /* properties */, nil /* usercontext */),
&solace.IllegalStateError{},
)
})
It("should fail to publish on terminated publisher", func() {
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred(), "Encountered error while building request-reply publisher")
Expect(publisher.Start()).ToNot(HaveOccurred())
Expect(publisher.Terminate(gracePeriod)).ToNot(HaveOccurred())
helpers.ValidateError(publisher.Publish(helpers.NewMessage(messagingService), publisherReplyHandler, publishTopic, timeOut, nil /* properties */, nil /* usercontext */), &solace.IllegalStateError{})
})
// for the failure paths
for startName, fn := range startFunctions {
start := fn
It("should fail to start when messaging service is disconnected using start "+startName, func() {
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred())
messagingService.Disconnect()
Eventually(start(publisher)).Should(Receive(&err))
Expect(err).To(HaveOccurred())
Expect(err).To(BeAssignableToTypeOf(&solace.IllegalStateError{}))
})
It("should fail to start when messaging service is down using start "+startName, func() {
publisher, err := messagingService.RequestReply().CreateRequestReplyMessagePublisherBuilder().Build()
Expect(err).ToNot(HaveOccurred())
helpers.ForceDisconnectViaSEMPv2(messagingService)
Eventually(messagingService.IsConnected).Should(BeFalse())
Expect(messagingService.Disconnect()).ToNot(HaveOccurred())
helpers.ValidateChannelError(start(publisher), &solace.IllegalStateError{})
})
}
})
})
})