Skip to content

Commit

Permalink
fix(aggregate)!: unify types (#11)
Browse files Browse the repository at this point in the history
fix(aggregate)!: splitting of the two aggregate types make
implementations unnecessarily difficult, the `CurrentSequence` method
was integrated into the `Aggregate`-interface which returns `*uint32`.
If the pointer is nil no additional checks are made

ci: verbose output of tests
  • Loading branch information
adlerhurst authored Nov 1, 2023
1 parent ad204b7 commit 9924c91
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: go build -v ./...

- name: Test
run: go test -race -coverprofile=profile.cov ./...
run: go test -race -coverprofile=profile.cov -v ./...

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand Down
5 changes: 2 additions & 3 deletions cockroachdb/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ func prepareIndexes(aggregates []eventstore.Aggregate) *aggregateIndexes {
index = &aggregateIndex{
aggregate: aggregate.ID(),
}
sequenceChecker, ok := aggregate.(eventstore.AggregatePredefinedSequence)
if ok {
if sequence := aggregate.CurrentSequence(); sequence != nil {
index.shouldCheckSequence = true
index.expectedSequence = sequenceChecker.CurrentSequence()
index.expectedSequence = *sequence
}
indexes.aggregates = append(indexes.aggregates, index)
}
Expand Down
9 changes: 2 additions & 7 deletions eventstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@ type Aggregate interface {
ID() TextSubjects
// Commands is the list of write intents
Commands() []Command
}

// AggregatePredefinedSequence is used in storage to determine if the command requires a specific sequence
// If the order doesn't matter the command must not implement this interface
type AggregatePredefinedSequence interface {
Aggregate
// CurrentSequence returns the current sequence of the aggregate
// If the aggregate doesn't care about the current sequence it returns nil
// If it's the first command return 0
// If it's the nth command return the specific sequence
CurrentSequence() uint32
CurrentSequence() *uint32
}

// Action describes the base data of [Command]'s and [Event]'s
Expand Down
20 changes: 6 additions & 14 deletions eventstore_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ var _ Aggregate = (*testUser)(nil)
type testUser struct {
id string
currentSequence uint32
predefinedSequence uint32
predefinedSequence *uint32
commands []Command
}

var _ AggregatePredefinedSequence = (*testUserWithSequence)(nil)

type testUserWithSequence struct {
*testUser
}

// CurrentSequence implements AggregatePredefinedSequence.
func (a *testUserWithSequence) CurrentSequence() uint32 {
return a.testUser.predefinedSequence
// CurrentSequence implements Aggregate.
func (a *testUser) CurrentSequence() *uint32 {
return a.predefinedSequence
}

// Commands implements Aggregate.
Expand All @@ -78,15 +72,13 @@ func newTestUser(id string, opts ...testUserOpt) Aggregate {
for _, opt := range opts {
tu = opt(tu)
}
if tu.predefinedSequence > 0 {
return &testUserWithSequence{tu}
}

return tu
}

func withPredefinedSequence(sequence uint32) testUserOpt {
return func(tu *testUser) *testUser {
tu.predefinedSequence = sequence
tu.predefinedSequence = &sequence
return tu
}
}
Expand Down

0 comments on commit 9924c91

Please sign in to comment.