@@ -82,11 +82,7 @@ func TestBasicTopicAnonPubSub(t *testing.T) {
8282 g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
8383 log .Println ("Publisher created" , pub1 )
8484
85- for i := 1 ; i <= 1_000 ; i ++ {
86- status , err2 := pub1 .Publish (ctx , fmt .Sprintf ("my-value-%d" , i ))
87- g .Expect (err2 ).ShouldNot (gomega .HaveOccurred ())
88- g .Expect (status ).ShouldNot (gomega .BeNil ())
89- }
85+ publishEntriesString (g , pub1 , 1_000 )
9086
9187 utils .Sleep (5 )
9288
@@ -122,11 +118,7 @@ func TestCreatePubSubWithoutCreatingTopic(t *testing.T) {
122118 g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
123119 log .Println ("Publisher created" , pub1 )
124120
125- for i := 1 ; i <= 1_000 ; i ++ {
126- status , err2 := pub1 .Publish (ctx , fmt .Sprintf ("my-value-%d" , i ))
127- g .Expect (err2 ).ShouldNot (gomega .HaveOccurred ())
128- g .Expect (status ).ShouldNot (gomega .BeNil ())
129- }
121+ publishEntriesString (g , pub1 , 1_000 )
130122
131123 utils .Sleep (5 )
132124
@@ -137,7 +129,7 @@ func TestCreatePubSubWithoutCreatingTopic(t *testing.T) {
137129 err = pub1 .Close (ctx )
138130 g .Expect (err ).Should (gomega .HaveOccurred ())
139131
140- // get teh topic so we can destroy
132+ // get the topic so we can destroy
141133 topic1 , err := coherence .GetNamedTopic [string ](ctx , session1 , topicName , topic .WithChannelCount (17 ))
142134 g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
143135
@@ -169,6 +161,42 @@ func TestSubscriberWithFilter(t *testing.T) {
169161 g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
170162 log .Println ("Subscriber created" , sub1 )
171163
164+ runTest [string ](g , topic1 , sub1 )
165+ }
166+
167+ func TestSubscriberWithTransformer (t * testing.T ) {
168+ var (
169+ g = gomega .NewWithT (t )
170+ err error
171+ session1 * coherence.Session
172+ topic1 coherence.NamedTopic [utils.Person ]
173+ ctx = context .Background ()
174+ )
175+
176+ const topicName = "my-topic-anon-transformer"
177+
178+ session1 , err = utils .GetSession (coherence .WithRequestTimeout (300 * time .Second ))
179+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
180+ defer session1 .Close ()
181+
182+ // create a topic that will just return a name from the utils.Person using a transformer
183+ topic1 , err = coherence .GetNamedTopic [utils.Person ](ctx , session1 , topicName , topic .WithChannelCount (17 ))
184+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
185+ log .Println (topic1 )
186+
187+ extractor := extractors.Extract [string ]("name" )
188+ // create a subscriber with a transformer, this
189+ sub1 , err := coherence .CreatSubscriberWithTransformer (ctx , session1 , topicName , extractor ,
190+ subscriber .WithFilter (filters .GreaterEqual (extractors.Extract [int ]("age" ), 10 )))
191+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
192+ log .Println ("Subscriber created" , sub1 )
193+
194+ runTest [string ](g , topic1 , sub1 )
195+ }
196+
197+ func runTest [E any ](g * gomega.WithT , topic1 coherence.NamedTopic [utils.Person ], s coherence.Subscriber [E ]) {
198+ ctx := context .Background ()
199+
172200 pub1 , err := topic1 .CreatePublisher (context .Background ())
173201 g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
174202 log .Println ("Publisher created" , pub1 )
@@ -186,6 +214,47 @@ func TestSubscriberWithFilter(t *testing.T) {
186214
187215 utils .Sleep (5 )
188216
217+ err = s .Close (ctx )
218+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
219+
220+ err = s .Close (ctx )
221+ g .Expect (err ).Should (gomega .HaveOccurred ())
222+ }
223+
224+ func TestSubscriberWithTransformerAndFilter (t * testing.T ) {
225+ var (
226+ g = gomega .NewWithT (t )
227+ err error
228+ session1 * coherence.Session
229+ topic1 coherence.NamedTopic [utils.Person ]
230+ ctx = context .Background ()
231+ )
232+
233+ const topicName = "my-topic-anon-transformer"
234+
235+ session1 , err = utils .GetSession (coherence .WithRequestTimeout (300 * time .Second ))
236+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
237+ defer session1 .Close ()
238+
239+ // create a topic that will just return a name from the utils.Person using a transformer
240+ topic1 , err = coherence .GetNamedTopic [utils.Person ](ctx , session1 , topicName , topic .WithChannelCount (17 ))
241+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
242+ log .Println (topic1 )
243+
244+ extractor := extractors.Extract [string ]("name" )
245+ // create a subscriber with a transformer, this
246+ sub1 , err := coherence .CreatSubscriberWithTransformer (ctx , session1 , topicName , extractor )
247+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
248+ log .Println ("Subscriber created" , sub1 )
249+
250+ pub1 , err := topic1 .CreatePublisher (context .Background ())
251+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
252+ log .Println ("Publisher created" , pub1 )
253+
254+ publishEntriesPerson (g , pub1 , 1_000 )
255+
256+ utils .Sleep (5 )
257+
189258 err = sub1 .Close (ctx )
190259 g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
191260
@@ -195,3 +264,26 @@ func TestSubscriberWithFilter(t *testing.T) {
195264 err = topic1 .Destroy (ctx )
196265 g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
197266}
267+
268+ func publishEntriesPerson (g * gomega.WithT , pub coherence.Publisher [utils.Person ], count int ) {
269+ ctx := context .Background ()
270+ for i := 1 ; i <= count ; i ++ {
271+ p := utils.Person {
272+ ID : i ,
273+ Name : fmt .Sprintf ("my-value-%d" , i ),
274+ Age : 10 + i ,
275+ }
276+ status , err2 := pub .Publish (ctx , p )
277+ g .Expect (err2 ).ShouldNot (gomega .HaveOccurred ())
278+ g .Expect (status ).ShouldNot (gomega .BeNil ())
279+ }
280+ }
281+
282+ func publishEntriesString (g * gomega.WithT , pub coherence.Publisher [string ], count int ) {
283+ ctx := context .Background ()
284+ for i := 1 ; i <= count ; i ++ {
285+ status , err2 := pub .Publish (ctx , fmt .Sprintf ("value-%d" , i ))
286+ g .Expect (err2 ).ShouldNot (gomega .HaveOccurred ())
287+ g .Expect (status ).ShouldNot (gomega .BeNil ())
288+ }
289+ }
0 commit comments