mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 00:47:33 +00:00
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.
This commit is contained in:
128
internal/eventstore/v3/event_test.go
Normal file
128
internal/eventstore/v3/event_test.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package eventstore
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
func Test_commandToEvent(t *testing.T) {
|
||||
payload := struct {
|
||||
ID string
|
||||
}{
|
||||
ID: "test",
|
||||
}
|
||||
payloadMarshalled, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal of payload failed: %v", err)
|
||||
}
|
||||
type args struct {
|
||||
sequence *latestSequence
|
||||
command eventstore.Command
|
||||
}
|
||||
type want struct {
|
||||
event *event
|
||||
err func(t *testing.T, err error)
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want want
|
||||
}{
|
||||
{
|
||||
name: "no payload",
|
||||
args: args{
|
||||
sequence: &latestSequence{
|
||||
aggregate: mockAggregate("V3-Red9I"),
|
||||
sequence: 0,
|
||||
},
|
||||
command: &mockCommand{
|
||||
aggregate: mockAggregate("V3-Red9I"),
|
||||
payload: nil,
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
event: mockEvent(
|
||||
mockAggregate("V3-Red9I"),
|
||||
0,
|
||||
nil,
|
||||
).(*event),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "struct payload",
|
||||
args: args{
|
||||
sequence: &latestSequence{
|
||||
aggregate: mockAggregate("V3-Red9I"),
|
||||
sequence: 0,
|
||||
},
|
||||
command: &mockCommand{
|
||||
aggregate: mockAggregate("V3-Red9I"),
|
||||
payload: payload,
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
event: mockEvent(
|
||||
mockAggregate("V3-Red9I"),
|
||||
0,
|
||||
payloadMarshalled,
|
||||
).(*event),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "pointer payload",
|
||||
args: args{
|
||||
sequence: &latestSequence{
|
||||
aggregate: mockAggregate("V3-Red9I"),
|
||||
sequence: 0,
|
||||
},
|
||||
command: &mockCommand{
|
||||
aggregate: mockAggregate("V3-Red9I"),
|
||||
payload: &payload,
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
event: mockEvent(
|
||||
mockAggregate("V3-Red9I"),
|
||||
0,
|
||||
payloadMarshalled,
|
||||
).(*event),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid payload",
|
||||
args: args{
|
||||
sequence: &latestSequence{
|
||||
aggregate: mockAggregate("V3-Red9I"),
|
||||
sequence: 0,
|
||||
},
|
||||
command: &mockCommand{
|
||||
aggregate: mockAggregate("V3-Red9I"),
|
||||
payload: func() {},
|
||||
},
|
||||
},
|
||||
want: want{
|
||||
err: func(t *testing.T, err error) {
|
||||
assert.Error(t, err)
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if tt.want.err == nil {
|
||||
tt.want.err = func(t *testing.T, err error) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := commandToEvent(tt.args.sequence, tt.args.command)
|
||||
|
||||
tt.want.err(t, err)
|
||||
assert.Equal(t, tt.want.event, got)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user