forked from testground/sync-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
71 lines (61 loc) · 2.38 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package sync
import (
"context"
"io"
)
// Service is the implementation of a sync service. This service must support synchronization
// actions such as pub-sub and barriers.
type Service interface {
io.Closer
Publish(ctx context.Context, topic string, payload interface{}) (seq int, err error)
Subscribe(ctx context.Context, topic string) (*subscription, error)
Barrier(ctx context.Context, state string, target int) error
SignalEntry(ctx context.Context, state string) (after int, err error)
}
// PublishRequest represents a publish request.
type PublishRequest struct {
Topic string `json:"topic"`
Payload interface{} `json:"payload"`
}
// PublishResponse represents a publish response.
type PublishResponse struct {
Seq int `json:"seq"`
}
// SubscribeRequest represents a subscribe request.
type SubscribeRequest struct {
Topic string `json:"topic"`
}
// BarrierRequest represents a barrier response.
type BarrierRequest struct {
State string `json:"state"`
Target int `json:"target"`
}
// SignalEntryRequest represents a signal entry request.
type SignalEntryRequest struct {
State string `json:"state"`
}
// SignalEntryResponse represents a signal entry response.
type SignalEntryResponse struct {
Seq int `json:"seq"`
}
// Request represents a request from the test instance to the sync service.
// The request ID must be present and one of the requests must be non-nil.
// The ID will be used on further responses.
type Request struct {
ID string `json:"id"`
IsCancel bool `json:"is_cancel"`
PublishRequest *PublishRequest `json:"publish,omitempty"`
SubscribeRequest *SubscribeRequest `json:"subscribe,omitempty"`
BarrierRequest *BarrierRequest `json:"barrier,omitempty"`
SignalEntryRequest *SignalEntryRequest `json:"signal_entry,omitempty"`
}
// Response represents a response from the sync service to a test instance.
// The response ID must be present and one of the response types of Error must
// be non-nil. The ID is the same as the request ID.
type Response struct {
ID string `json:"id"`
Error string `json:"error"`
PublishResponse *PublishResponse `json:"publish"`
SubscribeResponse string `json:"subscribe"` // JSON encoded subscribe response.
SignalEntryResponse *SignalEntryResponse `json:"signal_entry"`
}