Skip to content

Commit

Permalink
Use enginekit/config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Oct 11, 2024
1 parent 19c54bb commit ff84dc5
Show file tree
Hide file tree
Showing 53 changed files with 549 additions and 570 deletions.
32 changes: 16 additions & 16 deletions action.advancetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"time"

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/enginekit/config"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
. "github.com/dogmatiq/testkit"
"github.com/dogmatiq/testkit/engine"
Expand Down Expand Up @@ -55,11 +55,11 @@ var _ = g.Describe("func AdvanceTime()", func() {
gm.Expect(buf.Facts()).To(gm.ContainElement(
fact.TickCycleBegun{
EngineTime: startTime.Add(2 * time.Second),
EnabledHandlerTypes: map[configkit.HandlerType]bool{
configkit.AggregateHandlerType: true,
configkit.IntegrationHandlerType: false,
configkit.ProcessHandlerType: true,
configkit.ProjectionHandlerType: false,
EnabledHandlerTypes: map[config.HandlerType]bool{
config.AggregateHandlerType: true,
config.IntegrationHandlerType: false,
config.ProcessHandlerType: true,
config.ProjectionHandlerType: false,
},
EnabledHandlers: map[string]bool{},
},
Expand Down Expand Up @@ -114,11 +114,11 @@ var _ = g.Describe("func AdvanceTime()", func() {
gm.Expect(buf.Facts()).To(gm.ContainElement(
fact.TickCycleBegun{
EngineTime: targetTime,
EnabledHandlerTypes: map[configkit.HandlerType]bool{
configkit.AggregateHandlerType: true,
configkit.IntegrationHandlerType: false,
configkit.ProcessHandlerType: true,
configkit.ProjectionHandlerType: false,
EnabledHandlerTypes: map[config.HandlerType]bool{
config.AggregateHandlerType: true,
config.IntegrationHandlerType: false,
config.ProcessHandlerType: true,
config.ProjectionHandlerType: false,
},
EnabledHandlers: map[string]bool{},
},
Expand All @@ -145,11 +145,11 @@ var _ = g.Describe("func AdvanceTime()", func() {
gm.Expect(buf.Facts()).To(gm.ContainElement(
fact.TickCycleBegun{
EngineTime: startTime.Add(3 * time.Second),
EnabledHandlerTypes: map[configkit.HandlerType]bool{
configkit.AggregateHandlerType: true,
configkit.IntegrationHandlerType: false,
configkit.ProcessHandlerType: true,
configkit.ProjectionHandlerType: false,
EnabledHandlerTypes: map[config.HandlerType]bool{
config.AggregateHandlerType: true,
config.IntegrationHandlerType: false,
config.ProcessHandlerType: true,
config.ProjectionHandlerType: false,
},
EnabledHandlers: map[string]bool{},
},
Expand Down
2 changes: 1 addition & 1 deletion action.call.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (a callAction) Location() location.Location {
}

func (a callAction) ConfigurePredicate(o *PredicateOptions) {
o.MatchDispatchCycleStartedFacts = true
o.MatchDispatchCycleBegun = true
}

func (a callAction) Do(_ context.Context, s ActionScope) error {
Expand Down
12 changes: 6 additions & 6 deletions action.call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"time"

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/enginekit/config"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
. "github.com/dogmatiq/testkit"
"github.com/dogmatiq/testkit/engine"
Expand Down Expand Up @@ -77,11 +77,11 @@ var _ = g.Describe("func Call()", func() {
CreatedAt: startTime,
},
EngineTime: startTime,
EnabledHandlerTypes: map[configkit.HandlerType]bool{
configkit.AggregateHandlerType: true,
configkit.IntegrationHandlerType: false,
configkit.ProcessHandlerType: true,
configkit.ProjectionHandlerType: false,
EnabledHandlerTypes: map[config.HandlerType]bool{
config.AggregateHandlerType: true,
config.IntegrationHandlerType: false,
config.ProcessHandlerType: true,
config.ProjectionHandlerType: false,
},
EnabledHandlers: map[string]bool{},
},
Expand Down
12 changes: 6 additions & 6 deletions action.dispatch.command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package testkit_test
import (
"time"

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/enginekit/config"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
. "github.com/dogmatiq/testkit"
"github.com/dogmatiq/testkit/engine"
Expand Down Expand Up @@ -70,11 +70,11 @@ var _ = g.Describe("func ExecuteCommand()", func() {
CreatedAt: startTime,
},
EngineTime: startTime,
EnabledHandlerTypes: map[configkit.HandlerType]bool{
configkit.AggregateHandlerType: true,
configkit.IntegrationHandlerType: false,
configkit.ProcessHandlerType: true,
configkit.ProjectionHandlerType: false,
EnabledHandlerTypes: map[config.HandlerType]bool{
config.AggregateHandlerType: true,
config.IntegrationHandlerType: false,
config.ProcessHandlerType: true,
config.ProjectionHandlerType: false,
},
EnabledHandlers: map[string]bool{},
},
Expand Down
12 changes: 6 additions & 6 deletions action.dispatch.event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"time"

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/enginekit/config"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
. "github.com/dogmatiq/testkit"
"github.com/dogmatiq/testkit/engine"
Expand Down Expand Up @@ -77,11 +77,11 @@ var _ = g.Describe("func RecordEvent()", func() {
CreatedAt: startTime,
},
EngineTime: startTime,
EnabledHandlerTypes: map[configkit.HandlerType]bool{
configkit.AggregateHandlerType: true,
configkit.IntegrationHandlerType: false,
configkit.ProcessHandlerType: true,
configkit.ProjectionHandlerType: false,
EnabledHandlerTypes: map[config.HandlerType]bool{
config.AggregateHandlerType: true,
config.IntegrationHandlerType: false,
config.ProcessHandlerType: true,
config.ProjectionHandlerType: false,
},
EnabledHandlers: map[string]bool{},
},
Expand Down
2 changes: 1 addition & 1 deletion action.dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (a dispatchAction) Do(ctx context.Context, s ActionScope) error {
// report, not just returning an error.
//
// See https://github.com/dogmatiq/testkit/issues/162
if _, ok := s.App.MessageTypes()[mt]; !ok {
if !s.App.RouteSet().HasMessageType(mt) {
return inflect.Errorf(
mt.Kind(),
"cannot <produce> <message>, %s is a not a recognized message type",
Expand Down
4 changes: 2 additions & 2 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/enginekit/config"
"github.com/dogmatiq/testkit/engine"
"github.com/dogmatiq/testkit/location"
)
Expand Down Expand Up @@ -35,7 +35,7 @@ type Action interface {
// inspected and manipulated by Action implementations.
type ActionScope struct {
// App is the application being tested.
App configkit.RichApplication
App *config.Application

// VirtualClock is the time that the Test uses as the engine time for the
// NEXT Action.
Expand Down
70 changes: 0 additions & 70 deletions engine/configurer.go

This file was deleted.

4 changes: 2 additions & 2 deletions engine/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/enginekit/config"
"github.com/dogmatiq/testkit/envelope"
"github.com/dogmatiq/testkit/fact"
)
Expand All @@ -14,7 +14,7 @@ import (
type controller interface {
// HandlerConfig returns the config of the handler that is managed by this
// controller.
HandlerConfig() configkit.RichHandler
HandlerConfig() config.Handler

// Tick instructs the controller to perform an implementation-defined
// "tick".
Expand Down
64 changes: 51 additions & 13 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import (
"context"
"fmt"

"github.com/dogmatiq/configkit"
"github.com/dogmatiq/cosyne"
"github.com/dogmatiq/dogma"
"github.com/dogmatiq/enginekit/config"
"github.com/dogmatiq/enginekit/message"
"github.com/dogmatiq/testkit/engine/internal/aggregate"
"github.com/dogmatiq/testkit/engine/internal/integration"
"github.com/dogmatiq/testkit/engine/internal/process"
"github.com/dogmatiq/testkit/engine/internal/projection"
"github.com/dogmatiq/testkit/envelope"
"github.com/dogmatiq/testkit/fact"
"github.com/dogmatiq/testkit/internal/validation"
Expand All @@ -29,7 +33,9 @@ type Engine struct {
}

// New returns a new engine that uses the given app configuration.
func New(app configkit.RichApplication, options ...Option) (_ *Engine, err error) {
func New(app *config.Application, options ...Option) (_ *Engine, err error) {
app = config.MustNormalize(app, config.WithImplementations())

eo := newEngineOptions(options)

e := &Engine{
Expand All @@ -38,23 +44,42 @@ func New(app configkit.RichApplication, options ...Option) (_ *Engine, err error
resetters: eo.resetters,
}

cfgr := &configurer{
options: eo,
engine: e,
}

ctx := context.Background()

if err := app.AcceptRichVisitor(ctx, cfgr); err != nil {
return nil, err
for _, h := range app.ConfiguredHandlers {
config.SwitchByHandlerTypeOf(
h,
func(h *config.Aggregate) {
e.registerController(&aggregate.Controller{
Config: h,
MessageIDs: &e.messageIDs,
})
},
func(h *config.Process) {
e.registerController(&process.Controller{
Config: h,
MessageIDs: &e.messageIDs,
})
},
func(h *config.Integration) {
e.registerController(&integration.Controller{
Config: h,
MessageIDs: &e.messageIDs,
})
},
func(h *config.Projection) {
e.registerController(&projection.Controller{
Config: h,
CompactDuringHandling: eo.compactDuringHandling,
})
},
)
}

return e, nil
}

// MustNew returns a new engine that uses the given app configuration, or panics
// if unable to do so.
func MustNew(app configkit.RichApplication, options ...Option) *Engine {
func MustNew(app *config.Application, options ...Option) *Engine {
e, err := New(app, options...)
if err != nil {
panic(err)
Expand Down Expand Up @@ -343,7 +368,7 @@ func (e *Engine) handle(
// skipHandler returns true if a specific handler should be skipped during a
// call to Dispatch() or Tick().
func (e *Engine) skipHandler(
h configkit.Handler,
h config.Handler,
oo *operationOptions,
) (bool, fact.HandlerSkipReason) {
if en, ok := oo.enabledHandlers[h.Identity().Name]; ok {
Expand All @@ -357,3 +382,16 @@ func (e *Engine) skipHandler(
en := oo.enabledHandlerTypes[h.HandlerType()]
return !en, fact.HandlerTypeDisabled
}

func (e *Engine) registerController(c controller) {
cfg := c.HandlerConfig()

e.controllers[cfg.Identity().Name] = c

for mt := range cfg.
RouteSet().
Filter(config.WithRouteDirectionFilter(config.InboundDirection)).
MessageTypes() {
e.routes[mt] = append(e.routes[mt], c)
}
}
Loading

0 comments on commit ff84dc5

Please sign in to comment.