Skip to content

Commit 00aac8a

Browse files
author
Tim Middleton
authored
Minor test and example enhancements for composite processor (#36)
* Minor test and example enhancements for composite processor * Minor update for session timeout
1 parent 00ac429 commit 00aac8a

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

examples/events/cache/people_listen/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"fmt"
1515
"github.com/oracle/coherence-go-client/coherence"
1616
"log"
17+
"os"
1718
"time"
1819
)
1920

@@ -39,6 +40,13 @@ func main() {
3940

4041
defer session.Close()
4142

43+
session.AddSessionLifecycleListener(
44+
coherence.NewSessionLifecycleListener().
45+
OnClosed(func(event coherence.SessionLifecycleEvent) {
46+
log.Println("session closed, exiting")
47+
os.Exit(0)
48+
}))
49+
4250
// create a new NamedMap of Person with key int
4351
namedMap, err := coherence.GetNamedMap[int, Person](session, "people")
4452
if err != nil {

examples/processors/main.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ func main() {
6767
}
6868
fmt.Println("Person is", *person)
6969

70+
var updated *bool
7071
// update the age to 68
71-
if _, err = coherence.Invoke[int, Person, bool](ctx, namedMap, 1, processors.Update("age", 68)); err != nil {
72+
if updated, err = coherence.Invoke[int, Person, bool](ctx, namedMap, 1, processors.Update("age", 68)); err != nil {
7273
panic(err)
7374
}
7475

76+
fmt.Println("Updated = ", *updated)
77+
7578
// get the Person
7679
person, err = namedMap.Get(ctx, 1)
7780
if err != nil {
@@ -116,4 +119,16 @@ func main() {
116119
fmt.Println("Person is", se.Value)
117120
}
118121
}
122+
123+
// updating multiple values using composite processors to update person one age to 67 and un-retire them.
124+
// this will return an array of booleans to indicate each update
125+
var proc = processors.Update("age", 67).AndThen(processors.Update("retired", false))
126+
127+
type result [2]bool
128+
var updated2 *result
129+
updated2, err = coherence.Invoke[int, Person, result](ctx, namedMap, 1, proc)
130+
if err != nil {
131+
panic(err)
132+
}
133+
fmt.Println("Boolean updates are", updated2[0], updated2[0])
119134
}

test/e2e/standalone/processor_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,22 @@ func RunTestInvokeUpdater(t *testing.T, namedMap coherence.NamedMap[int, Person]
422422
g.Expect(err).ShouldNot(gomega.HaveOccurred())
423423
g.Expect(result).To(gomega.Not(gomega.BeNil()))
424424
g.Expect(result.Age).To(gomega.Equal(20))
425+
426+
// invoke multiple processors
427+
type result2 [2]bool
428+
var updated *result2
429+
proc := processors.Update("age", 22).AndThen(processors.Update("name", "James Brown"))
430+
updated, err = coherence.Invoke[int, Person, result2](ctx, namedMap, 1, proc)
431+
g.Expect(err).ShouldNot(gomega.HaveOccurred())
432+
g.Expect(len(updated)).To(gomega.Equal(2))
433+
g.Expect(updated[0]).To(gomega.Equal(true))
434+
g.Expect(updated[1]).To(gomega.Equal(true))
435+
436+
result, err = namedMap.Get(ctx, 1)
437+
g.Expect(err).ShouldNot(gomega.HaveOccurred())
438+
g.Expect(result).To(gomega.Not(gomega.BeNil()))
439+
g.Expect(result.Age).To(gomega.Equal(22))
440+
g.Expect(result.Name).To(gomega.Equal("James Brown"))
425441
}
426442

427443
func RunTestInvokeConditionalPutAll(t *testing.T, namedMap coherence.NamedMap[int, Person]) {

0 commit comments

Comments
 (0)