Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

Commit

Permalink
Update to latest TCK (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvlugter authored Dec 18, 2020
1 parent 11a84a3 commit 005c956
Show file tree
Hide file tree
Showing 15 changed files with 552 additions and 442 deletions.
6 changes: 4 additions & 2 deletions cloudstate/discovery/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ func (s *EntityDiscoveryServer) RegisterCRDTEntity(entity *crdt.Entity, config p
return fmt.Errorf("failed to resolveFileDescriptor for DescriptorConfig: %+v: %w", config, err)
}
s.entitySpec.Entities = append(s.entitySpec.Entities, &protocol.Entity{
EntityType: protocol.CRDT,
ServiceName: entity.ServiceName.String(),
EntityType: protocol.CRDT,
ServiceName: entity.ServiceName.String(),
PersistenceId: entity.ServiceName.String(), // make sure CRDT entities have unique keys per service

})
return s.updateSpec()
}
Expand Down
6 changes: 6 additions & 0 deletions cloudstate/eventsourced/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func (c *Context) resetSnapshotEvery() {
c.shouldSnapshot = false
}

func (c *Context) reset() {
c.failed = nil
c.forward = nil
c.sideEffects = nil
}

// marshalEventsAny marshals and the clears events emitted through the context.
func (c *Context) marshalEventsAny() ([]*any.Any, error) {
events := make([]*any.Any, len(c.events))
Expand Down
1 change: 1 addition & 0 deletions cloudstate/eventsourced/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func (s *Server) handle(stream entity.EventSourced_HandleServer) error {
switch m := msg.GetMessage().(type) {
case *entity.EventSourcedStreamIn_Command:
err := r.handleCommand(m.Command)
r.context.reset()
if err == nil {
continue
}
Expand Down
8 changes: 8 additions & 0 deletions cloudstate/value/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,11 @@ func (c *Context) Update(state *any.Any, err error) error {
c.state = state
return nil
}

func (c *Context) reset() {
c.update = false
c.delete = false
c.forward = nil
c.failure = nil
c.sideEffects = nil
}
4 changes: 1 addition & 3 deletions cloudstate/value/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ func (s *Server) Handle(stream entity.ValueEntity_HandleServer) error {
if err != nil {
return err
}
c.update = false
c.delete = false
c.failure = nil
c.reset()
case *entity.ValueEntityStreamIn_Init:
if EntityID(m.Init.EntityId) == c.EntityID {
return errors.New("duplicate init message for the same entity")
Expand Down
21 changes: 19 additions & 2 deletions protobuf/tck/cloudstate/tck/model/eventsourced.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ syntax = "proto3";
package cloudstate.tck.model;

import "cloudstate/entity_key.proto";
import "google/api/annotations.proto";

option java_package = "io.cloudstate.tck.model";
option go_package = "github.com/cloudstateio/go-support/tck/eventsourced;eventsourced";
Expand All @@ -40,17 +41,33 @@ option go_package = "github.com/cloudstateio/go-support/tck/eventsourced;eventso
// - Forwarding and side effects must always be made to the second service `EventSourcedTwo`.
//
service EventSourcedTckModel {
rpc Process(Request) returns (Response);
rpc Process(Request) returns (Response) {
option (google.api.http) = {
post: "/tck/model/eventsourced/{id}",
body: "*"
};
}
}

//
// The `EventSourcedTwo` service is only for verifying forward actions and side effects.
// The `Call` method is not required to do anything, and may simply return an empty `Response` message.
// The `Call` method is not required to do anything, and must return an empty `Response` message.
//
service EventSourcedTwo {
rpc Call(Request) returns (Response);
}

//
// The `EventSourcedConfigured` service is for testing entity configuration from the language support:
//
// - The entity persistence-id must be `event-sourced-configured`.
// - The passivation strategy must be set with a timeout of 100 millis.
// - The `Call` method is not required to do anything, and must return an empty `Response` message.
//
// service EventSourcedConfigured {
// rpc Call(Request) returns (Response);
// }

//
// A `Request` message contains any actions that the entity should process.
// Actions must be processed in order. Any actions after a `Fail` may be ignored.
Expand Down
13 changes: 10 additions & 3 deletions protobuf/tck/cloudstate/tck/model/tck_action.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ syntax = "proto3";

package cloudstate.tck.model.action;

import "google/api/annotations.proto";

option java_package = "io.cloudstate.tck.model";
option go_package = "github.com/cloudstateio/go-support/tck/action;action";

Expand All @@ -41,15 +43,20 @@ option go_package = "github.com/cloudstateio/go-support/tck/action;action";
// - Forwarding and side effects must always be made to the second service `ActionTwo`.
//
service ActionTckModel {
rpc ProcessUnary(Request) returns (Response);
rpc ProcessUnary(Request) returns (Response) {
option (google.api.http) = {
post: "/tck/model/action/unary",
body: "*"
};
}
rpc ProcessStreamedIn(stream Request) returns (Response);
rpc ProcessStreamedOut(Request) returns (stream Response);
rpc ProcessStreamed(stream Request) returns (stream Response);
}

//
// The `ActionTwo` service is only for verifying forwards and side effects.
// The `Call` method is not required to do anything, and may simply return an empty `Response` message.
// The `Call` method is not required to do anything, and must return an empty `Response` message.
//
service ActionTwo {
rpc Call(OtherRequest) returns (Response);
Expand Down Expand Up @@ -131,4 +138,4 @@ message Response {
//
message OtherRequest {
string id = 1;
}
}
25 changes: 22 additions & 3 deletions protobuf/tck/cloudstate/tck/model/tck_valueentity.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ syntax = "proto3";
package cloudstate.tck.model.valueentity;

import "cloudstate/entity_key.proto";
import "google/api/annotations.proto";

option java_package = "io.cloudstate.tck.model.valueentity";
option go_package = "github.com/cloudstateio/go-support/tck/valueentity;valueentity";
Expand All @@ -38,17 +39,35 @@ option go_package = "github.com/cloudstateio/go-support/tck/valueentity;valueent
// - Forwarding and side effects must always be made to the second service `ValueEntityTwo`.
//
service ValueEntityTckModel {
rpc Process(Request) returns (Response);
rpc Process(Request) returns (Response) {
option (google.api.http) = {
post: "/tck/model/entity/{id}",
body: "*"
};
}
}

//
// The `ValueBasedTwo` service is only for verifying forward actions and side effects.
// The `Call` method is not required to do anything, and may simply return an empty `Response` message.
//
// - The entity persistence-id must be `value-entity-tck-model-two`.
// - The `Call` method is not required to do anything, and must return an empty `Response` message.
//
service ValueEntityTwo {
rpc Call(Request) returns (Response);
}

//
// The `ValueEntityConfigured` service is for testing entity configuration from the language support:
//
// - The entity persistence-id must be `value-entity-configured`.
// - The passivation strategy must be set with a timeout of 100 millis.
// - The `Call` method is not required to do anything, and must return an empty `Response` message.
//
// service ValueEntityConfigured {
// rpc Call(Request) returns (Response);
// }

//
// A `Request` message contains any actions that the entity should process.
// Actions must be processed in order. Any actions after a `Fail` may be ignored.
Expand Down Expand Up @@ -126,4 +145,4 @@ message Response {
//
message Persisted {
string value = 1;
}
}
21 changes: 19 additions & 2 deletions protobuf/tck/tck_crdt2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ syntax = "proto3";
package cloudstate.tck.model.crdt;

import "cloudstate/entity_key.proto";
import "google/api/annotations.proto";

option java_package = "io.cloudstate.tck.model";
option go_package = "github.com/cloudstateio/go-support/tck/crdt2;crdt2";
Expand All @@ -42,18 +43,34 @@ option go_package = "github.com/cloudstateio/go-support/tck/crdt2;crdt2";
// - The `ProcessStreamed` method must stream the current state in a `Response`, on any changes.
// - A `StreamedRequest` message may have an end state, an update to apply on stream cancellation, or side effects.
service CrdtTckModel {
rpc Process(Request) returns (Response);
rpc Process(Request) returns (Response) {
option (google.api.http) = {
post: "/tck/model/crdt/{id}",
body: "*"
};
}
rpc ProcessStreamed(StreamedRequest) returns (stream Response);
}

//
// The `CrdtTwo` service is only for verifying forwards and side effects.
// The `Call` method is not required to do anything, and may simply return an empty `Response` message.
// The only action the `Call` method is expected to handle is a delete action, and otherwise
// the `Call` method is not required to do anything, and must return an empty `Response` message.
//
service CrdtTwo {
rpc Call(Request) returns (Response);
}

//
// The `CrdtConfigured` service is for testing entity configuration from the language support:
//
// - The passivation strategy must be set with a timeout of 100 millis.
// - The `Call` method is not required to do anything, and must return an empty `Response` message.
//
// service CrdtConfigured {
// rpc Call(Request) returns (Response);
// }

//
// A `Request` message contains any actions that the entity should process.
// Actions must be processed in order. Any actions after a `Fail` may be ignored.
Expand Down
5 changes: 5 additions & 0 deletions tck/action/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,10 @@ func NewTestModelTwo() action.EntityHandler {
}

func (m *TestModelTwo) HandleCommand(ctx *action.Context, name string, msg proto.Message) error {
resp, err := encoding.MarshalAny(&Response{})
if err != nil {
return err
}
ctx.RespondWith(resp)
return nil
}
Loading

0 comments on commit 005c956

Please sign in to comment.