Silvan b5564572bc
feat(eventstore): increase parallel write capabilities (#5940)
This implementation increases parallel write capabilities of the eventstore.
Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and  [06](https://zitadel.com/docs/support/advisory/a10006).
The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`.
If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
2023-10-19 12:19:10 +02:00

82 lines
1.7 KiB
Go

package models
import (
"testing"
"time"
)
func TestObjectRoot_AppendEvent(t *testing.T) {
type fields struct {
ID string
Sequence uint64
CreationDate time.Time
ChangeDate time.Time
}
type args struct {
event *Event
isNewRoot bool
}
tests := []struct {
name string
fields fields
args args
}{
{
"new root",
fields{},
args{
&Event{
AggregateID: "aggID",
Seq: 34555,
CreationDate: time.Now(),
},
true,
},
},
{
"existing root",
fields{
"agg",
234,
time.Now().Add(-24 * time.Hour),
time.Now().Add(-12 * time.Hour),
},
args{
&Event{
AggregateID: "agg",
Seq: 34555425,
CreationDate: time.Now(),
PreviousSequence: 22,
},
false,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := &ObjectRoot{
AggregateID: tt.fields.ID,
Sequence: tt.fields.Sequence,
CreationDate: tt.fields.CreationDate,
ChangeDate: tt.fields.ChangeDate,
}
o.AppendEvent(tt.args.event)
if tt.args.isNewRoot {
if !o.CreationDate.Equal(tt.args.event.CreationDate) {
t.Error("creationDate should be equal to event on new root")
}
} else {
if o.CreationDate.Equal(o.ChangeDate) {
t.Error("creationDate and changedate should differ")
}
}
if o.Sequence != tt.args.event.Seq {
t.Errorf("sequence not equal to event: event: %d root: %d", tt.args.event.Seq, o.Sequence)
}
if !o.ChangeDate.Equal(tt.args.event.CreationDate) {
t.Errorf("changedate should be equal to event creation date: event: %v root: %v", tt.args.event.CreationDate, o.ChangeDate)
}
})
}
}