Skip to content

Commit

Permalink
refactor: rename client Kill method to Stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tochemey committed Jun 22, 2024
1 parent cf1431a commit 410a42d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The project adheres to [Semantic Versioning](https://semver.org) and [Convention

## Table of Content

- [Go-Akt](#go-akt)
- [Table of Content](#table-of-content)
- [Design Principles](#design-principles)
- [Use Cases](#use-cases)
- [Installation](#installation)
Expand All @@ -47,6 +49,8 @@ The project adheres to [Semantic Versioning](https://semver.org) and [Convention
- [Testkit](#testkit)
- [API](#api)
- [Client](#client)
- [Balancer strategies](#balancer-strategies)
- [Features](#features-1)
- [Clustering](#clustering)
- [Operations Guide](#operations-guide)
- [Redeployment](#redeployment)
Expand Down Expand Up @@ -315,13 +319,15 @@ To test that an actor receive and respond to messages one will have to:
3. Create an instance of test probe: `probe := testkit.NewProbe(ctx)` where `ctx` is a go context
4. Use the probe to send a message to the actor under test. Example: `probe.Send(pinger, new(testpb.Ping))`
5. Assert that the actor under test has received the message and responded as expected using the probe methods:
- `ExpectMessage(message proto.Message) proto.Message`: asserts that the message received from the test actor is the expected one
- `ExpectMessageWithin(duration time.Duration, message proto.Message) proto.Message`: asserts that the message received from the test actor is the expected one within a time duration
- `ExpectNoMessage()`: asserts that no message is expected
- `ExpectAnyMessage() proto.Message`: asserts that any message is expected
- `ExpectAnyMessageWithin(duration time.Duration) proto.Message`: asserts that any message within a time duration
- `ExpectMessageOfType(messageType protoreflect.MessageType)`: asserts the expectation of a given message type
- `ExpectMessageOfTypeWithin(duration time.Duration, messageType protoreflect.MessageType)`: asserts the expectation of a given message type within a time duration

- `ExpectMessage(message proto.Message) proto.Message`: asserts that the message received from the test actor is the expected one
- `ExpectMessageWithin(duration time.Duration, message proto.Message) proto.Message`: asserts that the message received from the test actor is the expected one within a time duration
- `ExpectNoMessage()`: asserts that no message is expected
- `ExpectAnyMessage() proto.Message`: asserts that any message is expected
- `ExpectAnyMessageWithin(duration time.Duration) proto.Message`: asserts that any message within a time duration
- `ExpectMessageOfType(messageType protoreflect.MessageType)`: asserts the expectation of a given message type
- `ExpectMessageOfTypeWithin(duration time.Duration, messageType protoreflect.MessageType)`: asserts the expectation of a given message type within a time duration

6. Make sure to shut down the testkit and the probe. Example: `probe.Stop()`, `testkit.Shutdown(ctx)` where `ctx` is a go context. These two calls can be in a tear down after all tests run.

To help implement unit tests in GoAkt-based applications. See [Testkit](./testkit)
Expand All @@ -345,9 +351,9 @@ The API interface helps interact with a Go-Akt actor system as kind of client. T

## Client

The Go-Akt client facilitates interaction with a specified Go-Akt cluster, contingent upon the activation of cluster mode.
The client operates without knowledge of the specific node within the cluster that will process the request.
This feature is particularly beneficial when interfacing with a Go-Akt cluster from an external system.
The Go-Akt client facilitates interaction with a specified Go-Akt cluster, contingent upon the activation of cluster mode.
The client operates without knowledge of the specific node within the cluster that will process the request.
This feature is particularly beneficial when interfacing with a Go-Akt cluster from an external system.
Go-Akt client is equipped with a mini load-balancer that helps route requests to the appropriate node.

### Balancer strategies
Expand All @@ -356,11 +362,11 @@ Go-Akt client is equipped with a mini load-balancer that helps route requests to
- [Random](./client/random.go) - a given node is chosen randomly
- [Least Load](./client/least_load.go) - the node with the least number of actors is chosen

### Features:
### Features

- `Kinds` - to list all the actor kinds in the cluster
- `Spawn` - to spawn an actor in the cluster
- `Kill` - to kill/stop an actor in the cluster
- `Stop` - to kill/stop an actor in the cluster
- `Ask` - to send a message to a given actor in the cluster and expect a response
- `Tell` - to send a fire-forget message to a given actor in the cluster
- `Whereis` - to locate and get the address of a given actor
Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ func (x *Client) Ask(ctx context.Context, actor *Actor, message proto.Message) (
return response.UnmarshalNew()
}

// Kill kills a given actor in the Client
func (x *Client) Kill(ctx context.Context, actor *Actor) error {
// Stop stops or kills a given actor in the Client
func (x *Client) Stop(ctx context.Context, actor *Actor) error {
x.locker.Lock()
remoteHost, remotePort := x.getNextRemotingHostAndPort()
x.locker.Unlock()
Expand Down
8 changes: 4 additions & 4 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestClient(t *testing.T) {
err = client.Tell(ctx, actor, new(testspb.TestSend))
require.NoError(t, err)

err = client.Kill(ctx, actor)
err = client.Stop(ctx, actor)
require.NoError(t, err)

t.Cleanup(func() {
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestClient(t *testing.T) {
err = client.Tell(ctx, actor, new(testspb.TestSend))
require.NoError(t, err)

err = client.Kill(ctx, actor)
err = client.Stop(ctx, actor)
require.NoError(t, err)

t.Cleanup(func() {
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestClient(t *testing.T) {
err = client.Tell(ctx, actor, new(testspb.TestSend))
require.NoError(t, err)

err = client.Kill(ctx, actor)
err = client.Stop(ctx, actor)
require.NoError(t, err)

t.Cleanup(func() {
Expand Down Expand Up @@ -341,7 +341,7 @@ func TestClient(t *testing.T) {
err = client.Tell(ctx, actor, new(testspb.TestSend))
require.NoError(t, err)

err = client.Kill(ctx, actor)
err = client.Stop(ctx, actor)
require.NoError(t, err)

t.Cleanup(func() {
Expand Down

0 comments on commit 410a42d

Please sign in to comment.