Rename DispatchCtx to Dispatch (#43563)

This commit is contained in:
idafurjes
2021-12-28 17:36:22 +01:00
committed by GitHub
parent 7936c4c522
commit 8e6d6af744
107 changed files with 291 additions and 291 deletions

View File

@@ -27,7 +27,7 @@ type TransactionManager interface {
// Bus type defines the bus interface structure
type Bus interface {
DispatchCtx(ctx context.Context, msg Msg) error
Dispatch(ctx context.Context, msg Msg) error
PublishCtx(ctx context.Context, msg Msg) error
@@ -92,7 +92,7 @@ func (b *InProcBus) SetTransactionManager(tm TransactionManager) {
}
// DispatchCtx function dispatch a message to the bus context.
func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error {
func (b *InProcBus) Dispatch(ctx context.Context, msg Msg) error {
var msgName = reflect.TypeOf(msg).Elem().Name()
span, ctx := opentracing.StartSpanFromContext(ctx, "bus - "+msgName)
@@ -205,8 +205,8 @@ func AddEventListenerCtx(handler HandlerFunc) {
globalBus.AddEventListenerCtx(handler)
}
func DispatchCtx(ctx context.Context, msg Msg) error {
return globalBus.DispatchCtx(ctx, msg)
func Dispatch(ctx context.Context, msg Msg) error {
return globalBus.Dispatch(ctx, msg)
}
func PublishCtx(ctx context.Context, msg Msg) error {

View File

@@ -23,7 +23,7 @@ func TestDispatch(t *testing.T) {
return nil
})
err := bus.DispatchCtx(context.Background(), &testQuery{})
err := bus.Dispatch(context.Background(), &testQuery{})
require.NoError(t, err)
require.True(t, invoked, "expected handler to be called")
@@ -32,7 +32,7 @@ func TestDispatch(t *testing.T) {
func TestDispatch_NoRegisteredHandler(t *testing.T) {
bus := New()
err := bus.DispatchCtx(context.Background(), &testQuery{})
err := bus.Dispatch(context.Background(), &testQuery{})
require.Equal(t, err, ErrHandlerNotFound,
"expected bus to return HandlerNotFound since no handler is registered")
}
@@ -47,7 +47,7 @@ func TestDispatch_ContextHandler(t *testing.T) {
return nil
})
err := bus.DispatchCtx(context.Background(), &testQuery{})
err := bus.Dispatch(context.Background(), &testQuery{})
require.NoError(t, err)
require.True(t, invoked, "expected handler to be called")
@@ -63,7 +63,7 @@ func TestDispatchCtx(t *testing.T) {
return nil
})
err := bus.DispatchCtx(context.Background(), &testQuery{})
err := bus.Dispatch(context.Background(), &testQuery{})
require.NoError(t, err)
require.True(t, invoked, "expected handler to be called")
@@ -79,7 +79,7 @@ func TestDispatchCtx_NoContextHandler(t *testing.T) {
return nil
})
err := bus.DispatchCtx(context.Background(), &testQuery{})
err := bus.Dispatch(context.Background(), &testQuery{})
require.NoError(t, err)
require.True(t, invoked, "expected handler to be called")
@@ -88,7 +88,7 @@ func TestDispatchCtx_NoContextHandler(t *testing.T) {
func TestDispatchCtx_NoRegisteredHandler(t *testing.T) {
bus := New()
err := bus.DispatchCtx(context.Background(), &testQuery{})
err := bus.Dispatch(context.Background(), &testQuery{})
require.Equal(t, err, ErrHandlerNotFound,
"expected bus to return HandlerNotFound since no handler is registered")
}
@@ -105,7 +105,7 @@ func TestQuery(t *testing.T) {
q := &testQuery{}
err := bus.DispatchCtx(context.Background(), q)
err := bus.Dispatch(context.Background(), q)
require.NoError(t, err, "unable to dispatch query")
require.Equal(t, want, q.Resp)
@@ -118,7 +118,7 @@ func TestQuery_HandlerReturnsError(t *testing.T) {
return errors.New("handler error")
})
err := bus.DispatchCtx(context.Background(), &testQuery{})
err := bus.Dispatch(context.Background(), &testQuery{})
require.Error(t, err, "expected error but got none")
}