Skip to content

Commit

Permalink
Remove support for deprecated methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Mar 25, 2024
1 parent 6946e42 commit 9f4bfb6
Show file tree
Hide file tree
Showing 14 changed files with 2 additions and 1,980 deletions.
20 changes: 0 additions & 20 deletions handlerconfigurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,6 @@ func (c *handlerConfigurer) route(r dogma.Route) {
}
}

func (c *handlerConfigurer) ConsumesCommandType(m dogma.Message) {
c.route(dogma.HandlesCommandRoute{Type: reflect.TypeOf(m)})
}

func (c *handlerConfigurer) ConsumesEventType(m dogma.Message) {
c.route(dogma.HandlesEventRoute{Type: reflect.TypeOf(m)})
}

func (c *handlerConfigurer) ProducesCommandType(m dogma.Message) {
c.route(dogma.ExecutesCommandRoute{Type: reflect.TypeOf(m)})
}

func (c *handlerConfigurer) ProducesEventType(m dogma.Message) {
c.route(dogma.RecordsEventRoute{Type: reflect.TypeOf(m)})
}

func (c *handlerConfigurer) SchedulesTimeoutType(m dogma.Message) {
c.route(dogma.SchedulesTimeoutRoute{Type: reflect.TypeOf(m)})
}

func (c *handlerConfigurer) consumes(t reflect.Type, r message.Role, verb string) {
mt := message.TypeFromReflect(t)
c.guardAgainstConflictingRoles(mt, r)
Expand Down
56 changes: 1 addition & 55 deletions static/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,49 +294,14 @@ func addHandlerFromConfigureMethod(
hdr.MessageNamesValue.Produced,
hdr.MessageNamesValue.Consumed,
)
case "ConsumesCommandType":
addMessageFromArguments(
args,
hdr.MessageNamesValue.Consumed,
message.CommandRole,
)
case "ConsumesEventType":
addMessageFromArguments(
args,
hdr.MessageNamesValue.Consumed,
message.EventRole,
)
case "ProducesCommandType":
addMessageFromArguments(
args,
hdr.MessageNamesValue.Produced,
message.CommandRole,
)
case "ProducesEventType":
addMessageFromArguments(
args,
hdr.MessageNamesValue.Produced,
message.EventRole,
)
case "SchedulesTimeoutType":
addMessageFromArguments(
args,
hdr.MessageNamesValue.Consumed,
message.TimeoutRole,
)
addMessageFromArguments(
args,
hdr.MessageNamesValue.Produced,
message.TimeoutRole,
)
}
}

hs.Add(hdr)
}

// addMessagesFromRoutes analyzes the arguments in a call to a configurer's
// method Routes() to populate the messages that are produced and consumed by
// Routes() method to populate the messages that are produced and consumed by
// the handler.
func addMessagesFromRoutes(
args []ssa.Value,
Expand Down Expand Up @@ -474,25 +439,6 @@ func recurseSSAValues(
}
}

// addMessageFromArguments analyzes args to deduce the type of a message.
// It assumes that the message is always the first argument.
//
// If the first argument is not a pointer to ssa.MakeInterface instruction, this
// function has no effect; otherwise the message type is added to nr using the
// role given by r.
func addMessageFromArguments(
args []ssa.Value,
nr message.NameRoles,
r message.Role,
) {
if mi, ok := args[0].(*ssa.MakeInterface); ok {
nr.Add(
message.NameFromType(mi.X.Type()),
r,
)
}
}

// pkgOfNamedType returns the package in which typ is declared.
//
// It panics if typ is not a named type or a pointer to a named type.
Expand Down
255 changes: 1 addition & 254 deletions static/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,261 +671,8 @@ var _ = Describe("func FromPackages() (handler analysis)", func() {
))
})
})

When("deprecated configurer methods are called", func() {
It("returns a single configuration for each handler type", func() {
cfg := packages.Config{
Mode: packages.LoadAllSyntax,
Dir: "testdata/handlers/deprecated/single",
}

pkgs := loadPackages(cfg)

apps := FromPackages(pkgs)
Expect(apps).To(HaveLen(1))
Expect(apps[0].Handlers().Aggregates()).To(HaveLen(1))
Expect(apps[0].Handlers().Processes()).To(HaveLen(1))
Expect(apps[0].Handlers().Projections()).To(HaveLen(1))
Expect(apps[0].Handlers().Integrations()).To(HaveLen(1))

aggregate := apps[0].Handlers().Aggregates()[0]
Expect(aggregate.Identity()).To(
Equal(
configkit.Identity{
Name: "<aggregate>",
Key: "bf11e5eb-8cda-4498-a12e-35bf224aade7",
},
),
)
Expect(aggregate.TypeName()).To(
Equal(
"github.com/dogmatiq/configkit/static/testdata/handlers/deprecated/single.AggregateHandler",
),
)
Expect(aggregate.HandlerType()).To(Equal(configkit.AggregateHandlerType))

Expect(aggregate.MessageNames()).To(Equal(
configkit.EntityMessageNames{
Consumed: message.NameRoles{
cfixtures.MessageATypeName: message.CommandRole,
cfixtures.MessageBTypeName: message.CommandRole,
},
Produced: message.NameRoles{
cfixtures.MessageCTypeName: message.EventRole,
cfixtures.MessageDTypeName: message.EventRole,
},
},
))

process := apps[0].Handlers().Processes()[0]
Expect(process.Identity()).To(
Equal(
configkit.Identity{
Name: "<process>",
Key: "b1ed1327-01fd-44ce-9cb8-c25a560e4c92",
},
),
)
Expect(process.TypeName()).To(
Equal(
"github.com/dogmatiq/configkit/static/testdata/handlers/deprecated/single.ProcessHandler",
),
)
Expect(process.HandlerType()).To(Equal(configkit.ProcessHandlerType))

Expect(process.MessageNames()).To(Equal(
configkit.EntityMessageNames{
Consumed: message.NameRoles{
cfixtures.MessageATypeName: message.EventRole,
cfixtures.MessageBTypeName: message.EventRole,
cfixtures.MessageETypeName: message.TimeoutRole,
cfixtures.MessageFTypeName: message.TimeoutRole,
},
Produced: message.NameRoles{
cfixtures.MessageCTypeName: message.CommandRole,
cfixtures.MessageDTypeName: message.CommandRole,
cfixtures.MessageETypeName: message.TimeoutRole,
cfixtures.MessageFTypeName: message.TimeoutRole,
},
},
))

projection := apps[0].Handlers().Projections()[0]
Expect(projection.Identity()).To(
Equal(
configkit.Identity{
Name: "<projection>",
Key: "91fc1201-5c47-40e7-ae10-ea3c96f7264d",
},
),
)
Expect(projection.TypeName()).To(
Equal(
"github.com/dogmatiq/configkit/static/testdata/handlers/deprecated/single.ProjectionHandler",
),
)
Expect(projection.HandlerType()).To(Equal(configkit.ProjectionHandlerType))

Expect(projection.MessageNames()).To(Equal(
configkit.EntityMessageNames{
Consumed: message.NameRoles{
cfixtures.MessageATypeName: message.EventRole,
cfixtures.MessageBTypeName: message.EventRole,
},
Produced: message.NameRoles{},
},
))

integration := apps[0].Handlers().Integrations()[0]
Expect(integration.Identity()).To(
Equal(
configkit.Identity{
Name: "<integration>",
Key: "ad1ab39c-f497-4c85-89b7-72f62d2d6c28",
},
),
)
Expect(integration.TypeName()).To(
Equal(
"github.com/dogmatiq/configkit/static/testdata/handlers/deprecated/single.IntegrationHandler",
),
)
Expect(integration.HandlerType()).To(Equal(configkit.IntegrationHandlerType))

Expect(integration.MessageNames()).To(Equal(
configkit.EntityMessageNames{
Consumed: message.NameRoles{
cfixtures.MessageATypeName: message.CommandRole,
cfixtures.MessageBTypeName: message.CommandRole,
},
Produced: message.NameRoles{
cfixtures.MessageCTypeName: message.EventRole,
cfixtures.MessageDTypeName: message.EventRole,
},
},
))
})

When("a nil value is passed as a message", func() {
It("does not add the message to the handler configuration", func() {
cfg := packages.Config{
Mode: packages.LoadAllSyntax,
Dir: "testdata/handlers/deprecated/nil-message",
}

pkgs := loadPackages(cfg)

apps := FromPackages(pkgs)
Expect(apps).To(HaveLen(1))
Expect(apps[0].Handlers().Aggregates()).To(HaveLen(1))

aggregate := apps[0].Handlers().Aggregates()[0]
Expect(aggregate.Identity()).To(
Equal(
configkit.Identity{
Name: "<nil-message-aggregate>",
Key: "da31f2cf-40c8-439e-aadc-042e30100908",
},
),
)
Expect(aggregate.TypeName()).To(
Equal(
"github.com/dogmatiq/configkit/static/testdata/handlers/deprecated/nil-message.AggregateHandler",
),
)
Expect(aggregate.HandlerType()).To(Equal(configkit.AggregateHandlerType))
Expect(aggregate.MessageNames()).To(Equal(
configkit.EntityMessageNames{
Consumed: message.NameRoles{
cfixtures.MessageATypeName: message.CommandRole,
},
Produced: message.NameRoles{
cfixtures.MessageBTypeName: message.EventRole,
},
},
))

progress := apps[0].Handlers().Processes()[0]
Expect(progress.Identity()).To(
Equal(
configkit.Identity{
Name: "<nil-message-process>",
Key: "16dea3ff-095f-4788-b632-3c6dd6903417",
},
),
)
Expect(progress.TypeName()).To(
Equal(
"github.com/dogmatiq/configkit/static/testdata/handlers/deprecated/nil-message.ProcessHandler",
),
)
Expect(progress.HandlerType()).To(Equal(configkit.ProcessHandlerType))
Expect(progress.MessageNames()).To(Equal(
configkit.EntityMessageNames{
Consumed: message.NameRoles{
cfixtures.MessageATypeName: message.EventRole,
cfixtures.MessageCTypeName: message.TimeoutRole,
},
Produced: message.NameRoles{
cfixtures.MessageBTypeName: message.CommandRole,
cfixtures.MessageCTypeName: message.TimeoutRole,
},
},
))

projection := apps[0].Handlers().Projections()[0]
Expect(projection.Identity()).To(
Equal(
configkit.Identity{
Name: "<nil-message-projection>",
Key: "ccaff8ea-f3c4-4d5c-8216-cb408b792998",
},
),
)
Expect(projection.TypeName()).To(
Equal(
"github.com/dogmatiq/configkit/static/testdata/handlers/deprecated/nil-message.ProjectionHandler",
),
)
Expect(projection.HandlerType()).To(Equal(configkit.ProjectionHandlerType))
Expect(projection.MessageNames()).To(Equal(
configkit.EntityMessageNames{
Consumed: message.NameRoles{
cfixtures.MessageATypeName: message.EventRole,
},
Produced: message.NameRoles{},
},
))

integration := apps[0].Handlers().Integrations()[0]
Expect(integration.Identity()).To(
Equal(
configkit.Identity{
Name: "<nil-message-integration>",
Key: "6042d127-d64c-4bfa-88ca-a6b1e0055759",
},
),
)
Expect(integration.TypeName()).To(
Equal(
"github.com/dogmatiq/configkit/static/testdata/handlers/deprecated/nil-message.IntegrationHandler",
),
)
Expect(integration.HandlerType()).To(Equal(configkit.IntegrationHandlerType))
Expect(integration.MessageNames()).To(Equal(
configkit.EntityMessageNames{
Consumed: message.NameRoles{
cfixtures.MessageATypeName: message.CommandRole,
},
Produced: message.NameRoles{
cfixtures.MessageBTypeName: message.EventRole,
},
},
))
})
})
})
})

When("the application multiple handlers of each type", func() {
It("returns all of the handler configurations", func() {
cfg := packages.Config{
Expand Down
Loading

0 comments on commit 9f4bfb6

Please sign in to comment.