Skip to content

Commit

Permalink
Merge pull request asynkron#327 from yangdiangzb/fix-typos-and-redund…
Browse files Browse the repository at this point in the history
…ant-stuff

fix typos, remove redundant import alias, type, and whitespaces.
  • Loading branch information
bryanpkc committed Jun 19, 2019
2 parents 59f8a13 + e7cc7b4 commit 46c416c
Show file tree
Hide file tree
Showing 39 changed files with 36 additions and 69 deletions.
4 changes: 2 additions & 2 deletions actor/actor_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (ctx *actorContext) AwaitFuture(f *Future, cont func(res interface{}, err e
message := ctx.messageOrEnvelope
// invoke the callback when the future completes
f.continueWith(func(res interface{}, err error) {
// send the wrapped callaback as a continuation message to self
// send the wrapped callback as a continuation message to self
ctx.self.sendSystemMessage(&continuation{
f: wrapper,
message: message,
Expand Down Expand Up @@ -354,7 +354,7 @@ func (ctx *actorContext) SpawnPrefix(props *Props, prefix string) *PID {

func (ctx *actorContext) SpawnNamed(props *Props, name string) (*PID, error) {
if props.guardianStrategy != nil {
panic(errors.New("Props used to spawn child cannot have GuardianStrategy"))
panic(errors.New("props used to spawn child cannot have GuardianStrategy"))
}

var pid *PID
Expand Down
9 changes: 4 additions & 5 deletions actor/actor_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func TestActorContext_Stop(t *testing.T) {
o.AssertExpectations(t)
}

func TestActorContext_SendMessage_WithSenderdMiddleware(t *testing.T) {
// Define a local context with no-op sender middlware
func TestActorContext_SendMessage_WithSenderMiddleware(t *testing.T) {
// Define a local context with no-op sender middleware
mw := func(next SenderFunc) SenderFunc {
return func(ctx SenderContext, target *PID, envelope *MessageEnvelope) {
next(ctx, target, envelope)
Expand Down Expand Up @@ -144,7 +144,6 @@ func TestActorContext_Respond(t *testing.T) {
}

func TestActorContext_Forward(t *testing.T) {

// Defined a respond actor
// It simply respond the string message
responder := rootContext.Spawn(PropsFromFunc(func(ctx Context) {
Expand Down Expand Up @@ -193,15 +192,15 @@ func BenchmarkActorContext_ProcessMessageWithMiddleware(b *testing.B) {
}

func benchmarkActorContext_SpawnWithMiddlewareN(n int, b *testing.B) {
middlwareFn := func(next SenderFunc) SenderFunc {
middlewareFn := func(next SenderFunc) SenderFunc {
return func(ctx SenderContext, pid *PID, env *MessageEnvelope) {
next(ctx, pid, env)
}
}

props := PropsFromProducer(nullProducer)
for i := 0; i < n; i++ {
props = props.WithSenderMiddleware(middlwareFn)
props = props.WithSenderMiddleware(middlewareFn)
}

parent := &actorContext{self: NewLocalPID("foo"), props: props}
Expand Down
4 changes: 2 additions & 2 deletions actor/actor_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

// Demonstrates how to create an actor using a function literal and how to send a message asynchronously
func Example() {
var context *actor.RootContext = actor.EmptyRootContext
var props *actor.Props = actor.PropsFromFunc(func(c actor.Context) {
var context = actor.EmptyRootContext
var props = actor.PropsFromFunc(func(c actor.Context) {
if msg, ok := c.Message().(string); ok {
fmt.Println(msg) // outputs "Hello World"
}
Expand Down
1 change: 0 additions & 1 deletion actor/child_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func NewCreateChildThenStopActor() Actor {
}

func TestActorCanStopChildren(t *testing.T) {

actor := rootContext.Spawn(PropsFromProducer(NewCreateChildThenStopActor))
count := 10
for i := 0; i < count; i++ {
Expand Down
6 changes: 3 additions & 3 deletions actor/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type guardianProcess struct {
}

func (g *guardianProcess) SendUserMessage(pid *PID, message interface{}) {
panic(errors.New("Guardian actor cannot receive any user messages"))
panic(errors.New("guardian actor cannot receive any user messages"))
}

func (g *guardianProcess) SendSystemMessage(pid *PID, message interface{}) {
Expand All @@ -56,11 +56,11 @@ func (g *guardianProcess) Stop(pid *PID) {
}

func (g *guardianProcess) Children() []*PID {
panic(errors.New("Guardian does not hold its children PIDs"))
panic(errors.New("guardian does not hold its children PIDs"))
}

func (*guardianProcess) EscalateFailure(reason interface{}, message interface{}) {
panic(errors.New("Guardian cannot escalate failure"))
panic(errors.New("guardian cannot escalate failure"))
}

func (*guardianProcess) RestartChildren(pids ...*PID) {
Expand Down
2 changes: 1 addition & 1 deletion actor/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package actor

import "github.com/AsynkronIT/protoactor-go/mailbox"

// An AutoReceiveMessage is a special kind of user message that will be handled in some way automatially by the actor
// An AutoReceiveMessage is a special kind of user message that will be handled in some way automatically by the actor
type AutoReceiveMessage interface {
AutoReceiveMessage()
}
Expand Down
2 changes: 0 additions & 2 deletions actor/middleware/opentracing/sendermiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
)

func SenderMiddleware() actor.SenderMiddleware {

return func(next actor.SenderFunc) actor.SenderFunc {
return func(c actor.SenderContext, target *actor.PID, envelope *actor.MessageEnvelope) {

span := getActiveSpan(c.Self())

if span == nil {
Expand Down
1 change: 0 additions & 1 deletion actor/middleware/propagator/middlewarepropagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

func TestPropagator(t *testing.T) {

mutex := &sync.Mutex{}
spawningCounter := 0

Expand Down
2 changes: 1 addition & 1 deletion actor/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (props *Props) WithSupervisor(supervisor SupervisorStrategy) *Props {
return props
}

// Assign one or more middlewares to the props
// Assign one or more middleware to the props
func (props *Props) WithReceiverMiddleware(middleware ...ReceiverMiddleware) *Props {
props.receiverMiddleware = append(props.receiverMiddleware, middleware...)

Expand Down
1 change: 0 additions & 1 deletion actor/strategy_all_for_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (strategy *allForOneStrategy) HandleFailure(supervisor Supervisor, child *P
}

func (strategy *allForOneStrategy) shouldStop(rs *RestartStatistics) bool {

// supervisor says this child may not restart
if strategy.maxNrOfRetries == 0 {
return true
Expand Down
1 change: 0 additions & 1 deletion actor/strategy_one_for_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func (strategy *oneForOne) HandleFailure(supervisor Supervisor, child *PID, rs *
}

func (strategy *oneForOne) shouldStop(rs *RestartStatistics) bool {

// supervisor says this child may not restart
if strategy.maxNrOfRetries == 0 {
return true
Expand Down
3 changes: 1 addition & 2 deletions actor/supervision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (e *Expector) ExpectMsg(expected interface{}, t *testing.T) {
}

func (e *Expector) ExpectNoMsg(t *testing.T) {

select {
case actual := <-e.C:
at := reflect.TypeOf(actual)
Expand All @@ -82,7 +81,7 @@ func (e *Expector) ExpectNoMsg(t *testing.T) {
}
}

func TestActorStopsAfterXRestars(t *testing.T) {
func TestActorStopsAfterXRestarts(t *testing.T) {
m, e := NewObserver()
props := PropsFromProducer(func() Actor { return &failingChildActor{} }).WithReceiverMiddleware(m)
child := rootContext.Spawn(props)
Expand Down
5 changes: 4 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/AsynkronIT/protoactor-go/actor"
"github.com/AsynkronIT/protoactor-go/remote"
proto "github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/proto"
)

// Reference imports to suppress errors if they are not otherwise used.
Expand Down Expand Up @@ -106,6 +106,7 @@ func main() {
}
exit:
}

func spawnEcho() {
echoPID, _ = rootContext.SpawnNamed(actor.PropsFromFunc(func(ctx actor.Context) {
switch msg := ctx.Message().(type) {
Expand All @@ -122,6 +123,7 @@ func spawnEcho() {

}), "echo")
}

func watch(line string) {
parts := strings.SplitN(line, " ", 2)

Expand All @@ -139,6 +141,7 @@ func watch(line string) {
})
}
}

func tell(line string) {
parts := strings.SplitN(line, " ", 4)

Expand Down
2 changes: 1 addition & 1 deletion cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var cfg *ClusterConfig

var rootContext *actor.RootContext = actor.EmptyRootContext
var rootContext = actor.EmptyRootContext

func Start(clusterName, address string, provider ClusterProvider) {
StartWithConfig(NewClusterConfig(clusterName, address, provider))
Expand Down
5 changes: 1 addition & 4 deletions cluster/consul/consul_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func (p *ConsulProvider) deregisterService() error {
}

func (p *ConsulProvider) registerMember() error {

txn := api.KVTxnOps{}

// register a unique ID for the current process
Expand Down Expand Up @@ -227,7 +226,6 @@ func (p *ConsulProvider) blockingStatusChange() {
}

func (p *ConsulProvider) notifyStatuses() {

statuses, meta, err := p.client.Health().Service(p.clusterName, "", false, &api.QueryOptions{
WaitIndex: p.index,
WaitTime: p.blockingWaitTime,
Expand Down Expand Up @@ -272,14 +270,13 @@ func (p *ConsulProvider) notifyStatuses() {
}
// the reason why we want this in a batch and not as individual messages is that
// if we have an atomic batch, we can calculate what nodes have left the cluster
// passing events one by one, we can't know if someone left or just havent changed status for a long time
// passing events one by one, we can't know if someone left or just haven't changed status for a long time

// publish the current cluster topology onto the event stream
eventstream.Publish(res)
}

func (p *ConsulProvider) MonitorMemberStatusChanges() {

go func() {
for !p.shutdown {
p.notifyStatuses()
Expand Down
2 changes: 0 additions & 2 deletions cluster/member_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func (ml *memberListValue) getActivatorMember(kind string) string {
}

func (ml *memberListValue) updateClusterTopology(m interface{}) {

ml.mutex.Lock()
defer ml.mutex.Unlock()

Expand Down Expand Up @@ -108,7 +107,6 @@ func (ml *memberListValue) updateClusterTopology(m interface{}) {
}

func (ml *memberListValue) updateAndNotify(new *MemberStatus, old *MemberStatus) {

if new == nil && old == nil {
// ignore, not possible
return
Expand Down
4 changes: 1 addition & 3 deletions cluster/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ func (state *partitionActor) terminated(msg *actor.Terminated) {
}

func (state *partitionActor) memberRejoined(msg *MemberRejoinedEvent, context actor.Context) {

memberAddress := msg.Name()

plog.Info("Member rejoined", log.String("kind", state.kind), log.String("name", memberAddress))
Expand All @@ -236,7 +235,6 @@ func (state *partitionActor) memberRejoined(msg *MemberRejoinedEvent, context ac
}

func (state *partitionActor) memberLeft(msg *MemberLeftEvent, context actor.Context) {

memberAddress := msg.Name()

plog.Info("Member left", log.String("kind", state.kind), log.String("name", memberAddress))
Expand Down Expand Up @@ -291,7 +289,7 @@ func (state *partitionActor) transferOwnership(actorID string, address string, c
Pid: pid,
Name: actorID,
})
// we can safely delete this entry as the consisntent hash no longer points to us
// we can safely delete this entry as the consistent hash no longer points to us
delete(state.partition, actorID)
delete(state.keyNameMap, pid.String())
context.Unwatch(pid)
Expand Down
1 change: 0 additions & 1 deletion cluster/rendezvous.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func NewRendezvous(memberStrategy MemberStrategy) *Rendezvous {
// Get returns the node with the highest score for the given key. If this Hash
// has no nodes, an empty string is returned.
func (r *Rendezvous) GetByRdv(key string) string {

members := r.m.GetAllMembers()
l := len(members)

Expand Down
1 change: 0 additions & 1 deletion cluster/weighted/weighted_round_robin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewWeightedRoundRobin(memberStrategy cluster.MemberStrategy) *WeightedRound
}

func (r *WeightedRoundRobin) GetByRoundRobin() string {

members := r.m.GetAllMembers()
l := len(members)

Expand Down
3 changes: 0 additions & 3 deletions cluster/weighted/weighted_round_robin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "testing"
var wrr = NewWeightedRoundRobin(nil)

func BenchmarkGCD40(b *testing.B) {

val := []int{4, 4, 8, 6, 12, 30, 50, 150, 124, 124, 52, 66, 68, 168, 190, 244, 690, 400, 120, 520, 4, 4, 8, 6, 12, 30, 50, 150, 124, 124, 52, 66, 68, 168, 190, 244, 690, 400, 120, 520}

for n := 0; n < b.N; n++ {
Expand All @@ -14,7 +13,6 @@ func BenchmarkGCD40(b *testing.B) {
}

func BenchmarkGCD20(b *testing.B) {

val := []int{4, 4, 8, 6, 12, 30, 50, 150, 124, 124, 52, 66, 68, 168, 190, 244, 690, 400, 120, 520}

for n := 0; n < b.N; n++ {
Expand All @@ -23,7 +21,6 @@ func BenchmarkGCD20(b *testing.B) {
}

func BenchmarkGCD2(b *testing.B) {

val := []int{4, 520}

for n := 0; n < b.N; n++ {
Expand Down
4 changes: 0 additions & 4 deletions examples/cluster-metrics/member/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import (
"github.com/AsynkronIT/protoactor-go/remote"
)

const (
timeout = 1 * time.Second
)

// Logger is message middleware which logs messages before continuing to the next middleware
func Logger(next actor.ReceiverFunc) actor.ReceiverFunc {
fn := func(context actor.ReceiverContext, env *actor.MessageEnvelope) {
Expand Down
1 change: 0 additions & 1 deletion examples/cluster-metrics/seed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func Logger(next actor.ReceiverFunc) actor.ReceiverFunc {
}

func main() {

// this node knows about Hello kind
remote.Register("Hello", actor.PropsFromProducer(func() actor.Actor {
return &shared.HelloActor{}
Expand Down
4 changes: 0 additions & 4 deletions examples/cluster/member/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import (
"github.com/AsynkronIT/protoactor-go/remote"
)

const (
timeout = 1 * time.Second
)

func main() {
// this node knows about Hello kind
remote.Register("Hello", actor.PropsFromProducer(func() actor.Actor {
Expand Down
1 change: 0 additions & 1 deletion examples/cluster/seed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

func main() {

// this node knows about Hello kind
remote.Register("Hello", actor.PropsFromProducer(func() actor.Actor {
return &shared.HelloActor{}
Expand Down
2 changes: 0 additions & 2 deletions examples/inprocessbenchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ type Start struct {
Sender *actor.PID
}

// type Started struct{}

type pingActor struct {
count int
wgStop *sync.WaitGroup
Expand Down
3 changes: 1 addition & 2 deletions examples/receivetimeout/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ type NoInfluence string
func (NoInfluence) NotInfluenceReceiveTimeout() {}

func main() {

log.Println("Reveive timeout test")
log.Println("Receive timeout test")

c := 0

Expand Down
1 change: 0 additions & 1 deletion examples/remoteheader/node1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func main() {

remote.Start("127.0.0.1:8081")

rootContext := actor.EmptyRootContext
Expand Down
1 change: 0 additions & 1 deletion examples/remoterouting/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func newRemote(bind, name string) {
}

func main() {

runtime.GOMAXPROCS(runtime.NumCPU())
runtime.GC()

Expand Down
Loading

0 comments on commit 46c416c

Please sign in to comment.