From 4c07bc4e7c8dc8d8138e08502e453c598020c7d8 Mon Sep 17 00:00:00 2001 From: anthdm Date: Thu, 11 Jan 2024 21:01:54 +0100 Subject: [PATCH] fixed failing test --- actor/engine_test.go | 2 +- examples/cluster/member_1/main.go | 3 +++ examples/cluster/member_2/main.go | 19 ++++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/actor/engine_test.go b/actor/engine_test.go index c1a2f8c..c2f3612 100644 --- a/actor/engine_test.go +++ b/actor/engine_test.go @@ -38,7 +38,7 @@ func newTickReceiver(wg *sync.WaitGroup) Producer { } func TestSpawnWithContext(t *testing.T) { - e, _ := NewEngine(nil) + e, _ := NewEngine(NewEngineConfig()) type key struct { key string } diff --git a/examples/cluster/member_1/main.go b/examples/cluster/member_1/main.go index ecad953..2174f35 100644 --- a/examples/cluster/member_1/main.go +++ b/examples/cluster/member_1/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "log" "github.com/anthdm/hollywood/actor" @@ -23,6 +24,8 @@ func main() { eventPID := c.Engine().SpawnFunc(func(ctx *actor.Context) { switch msg := ctx.Message().(type) { + case cluster.ActivationEvent: + fmt.Println("got activation event") case cluster.MemberJoinEvent: if msg.Member.ID == "B" { config := cluster.NewActivationConfig(). diff --git a/examples/cluster/member_2/main.go b/examples/cluster/member_2/main.go index 8d36030..5c839a8 100644 --- a/examples/cluster/member_2/main.go +++ b/examples/cluster/member_2/main.go @@ -1,8 +1,11 @@ package main import ( + "fmt" "log" + "reflect" + "github.com/anthdm/hollywood/actor" "github.com/anthdm/hollywood/cluster" "github.com/anthdm/hollywood/examples/cluster/shared" ) @@ -13,11 +16,21 @@ func main() { WithID("B"). WithListenAddr("127.0.0.1:3001"). WithRegion("us-west") - cluster, err := cluster.New(config) + c, err := cluster.New(config) if err != nil { log.Fatal(err) } - cluster.RegisterKind("playerSession", shared.NewPlayer, nil) - cluster.Start() + eventPID := c.Engine().SpawnFunc(func(ctx *actor.Context) { + switch msg := ctx.Message().(type) { + case *cluster.Activation: + fmt.Println("got activation event", msg) + default: + fmt.Println("got", reflect.TypeOf(msg)) + } + }, "event") + + c.Engine().Subscribe(eventPID) + c.RegisterKind("playerSession", shared.NewPlayer, nil) + c.Start() select {} }