Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Concurrency Tests between Array Operations #985

Merged
merged 12 commits into from
Sep 2, 2024
27 changes: 27 additions & 0 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ func FromOperations(pbOps []*api.Operation) ([]operations.Operation, error) {
op, err = fromTreeEdit(decoded.TreeEdit)
case *api.Operation_TreeStyle_:
op, err = fromTreeStyle(decoded.TreeStyle)
case *api.Operation_SetByIndex_:
op, err = fromSetByIndex(decoded.SetByIndex)
default:
return nil, ErrUnsupportedOperation
}
Expand Down Expand Up @@ -539,6 +541,31 @@ func fromTreeStyle(pbTreeStyle *api.Operation_TreeStyle) (*operations.TreeStyle,
), nil
}

func fromSetByIndex(pbSetByIndex *api.Operation_SetByIndex) (*operations.SetByIndex, error) {
parentCreatedAt, err := fromTimeTicket(pbSetByIndex.ParentCreatedAt)
if err != nil {
return nil, err
}
createdAt, err := fromTimeTicket(pbSetByIndex.CreatedAt)
if err != nil {
return nil, err
}
elem, err := fromElement(pbSetByIndex.Value)
if err != nil {
return nil, err
}
executedAt, err := fromTimeTicket(pbSetByIndex.ExecutedAt)
if err != nil {
return nil, err
}
return operations.NewSetByIndex(
parentCreatedAt,
createdAt,
elem,
executedAt,
), nil
}

func fromCreatedAtMapByActor(
pbCreatedAtMapByActor map[string]*api.TimeTicket,
) (map[string]*time.Ticket, error) {
Expand Down
18 changes: 18 additions & 0 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func ToOperations(ops []operations.Operation) ([]*api.Operation, error) {
pbOperation.Body, err = toTreeEdit(op)
case *operations.TreeStyle:
pbOperation.Body, err = toTreeStyle(op)
case *operations.SetByIndex:
pbOperation.Body, err = toSetByIndex(op)
default:
return nil, ErrUnsupportedOperation
}
Expand Down Expand Up @@ -375,6 +377,22 @@ func toTreeStyle(style *operations.TreeStyle) (*api.Operation_TreeStyle_, error)
}, nil
}

func toSetByIndex(setByIndex *operations.SetByIndex) (*api.Operation_SetByIndex_, error) {
pbElem, err := toJSONElementSimple(setByIndex.Value())
if err != nil {
return nil, err
}
cloneot marked this conversation as resolved.
Show resolved Hide resolved

return &api.Operation_SetByIndex_{
SetByIndex: &api.Operation_SetByIndex{
ParentCreatedAt: ToTimeTicket(setByIndex.ParentCreatedAt()),
CreatedAt: ToTimeTicket(setByIndex.CreatedAt()),
Value: pbElem,
ExecutedAt: ToTimeTicket(setByIndex.ExecutedAt()),
},
}, nil
}

func toJSONElementSimple(elem crdt.Element) (*api.JSONElementSimple, error) {
switch elem := elem.(type) {
case *crdt.Object:
Expand Down
36 changes: 36 additions & 0 deletions api/docs/yorkie/v1/admin.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,12 @@ components:
description: ""
title: set
type: object
setByIndex:
$ref: '#/components/schemas/yorkie.v1.Operation.SetByIndex'
additionalProperties: false
description: ""
title: set_by_index
type: object
style:
$ref: '#/components/schemas/yorkie.v1.Operation.Style'
additionalProperties: false
Expand Down Expand Up @@ -1476,6 +1482,36 @@ components:
type: object
title: Set
type: object
yorkie.v1.Operation.SetByIndex:
additionalProperties: false
description: 'NOTE(junseo): `value.created_at` is set to same as `created_at`'
properties:
createdAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: created_at
type: object
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: executed_at
type: object
parentCreatedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: parent_created_at
type: object
value:
$ref: '#/components/schemas/yorkie.v1.JSONElementSimple'
additionalProperties: false
description: ""
title: value
type: object
title: SetByIndex
type: object
yorkie.v1.Operation.Style:
additionalProperties: false
description: ""
Expand Down
36 changes: 36 additions & 0 deletions api/docs/yorkie/v1/resources.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,12 @@ components:
description: ""
title: set
type: object
setByIndex:
$ref: '#/components/schemas/yorkie.v1.Operation.SetByIndex'
additionalProperties: false
description: ""
title: set_by_index
type: object
style:
$ref: '#/components/schemas/yorkie.v1.Operation.Style'
additionalProperties: false
Expand Down Expand Up @@ -985,6 +991,36 @@ components:
type: object
title: Set
type: object
yorkie.v1.Operation.SetByIndex:
additionalProperties: false
description: 'NOTE(junseo): `value.created_at` is set to same as `created_at`'
properties:
createdAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: created_at
type: object
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: executed_at
type: object
parentCreatedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: parent_created_at
type: object
value:
$ref: '#/components/schemas/yorkie.v1.JSONElementSimple'
additionalProperties: false
description: ""
title: value
type: object
title: SetByIndex
type: object
yorkie.v1.Operation.Style:
additionalProperties: false
description: ""
Expand Down
36 changes: 36 additions & 0 deletions api/docs/yorkie/v1/yorkie.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,12 @@ components:
description: ""
title: set
type: object
setByIndex:
$ref: '#/components/schemas/yorkie.v1.Operation.SetByIndex'
additionalProperties: false
description: ""
title: set_by_index
type: object
style:
$ref: '#/components/schemas/yorkie.v1.Operation.Style'
additionalProperties: false
Expand Down Expand Up @@ -969,6 +975,36 @@ components:
type: object
title: Set
type: object
yorkie.v1.Operation.SetByIndex:
additionalProperties: false
description: 'NOTE(junseo): `value.created_at` is set to same as `created_at`'
properties:
createdAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: created_at
type: object
executedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: executed_at
type: object
parentCreatedAt:
$ref: '#/components/schemas/yorkie.v1.TimeTicket'
additionalProperties: false
description: ""
title: parent_created_at
type: object
value:
$ref: '#/components/schemas/yorkie.v1.JSONElementSimple'
additionalProperties: false
description: ""
title: value
type: object
title: SetByIndex
type: object
yorkie.v1.Operation.Style:
additionalProperties: false
description: ""
Expand Down
Loading
Loading