sync

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2021 License: Apache-2.0, MIT Imports: 15 Imported by: 1

README

Testground Sync Service

Testground logo

Made by Protocol Labs Go version GoDoc CircleCI

This repository contains the service that Testground uses for synchronization between multiple test instances.

Issues

Please report issues in the testground/testground repo.

License

Dual-licensed: MIT, Apache Software License v2, by way of the Permissive License Stack.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BarrierRequest

type BarrierRequest struct {
	State  string `json:"state"`
	Target int    `json:"target"`
}

BarrierRequest represents a barrier response.

type DefaultService

type DefaultService struct {
	// contains filtered or unexported fields
}

func NewDefaultService

func NewDefaultService(ctx context.Context, log *zap.SugaredLogger) (*DefaultService, error)

func (*DefaultService) Barrier

func (s *DefaultService) Barrier(ctx context.Context, state string, target int) error

func (*DefaultService) Close

func (s *DefaultService) Close() error

func (*DefaultService) Publish

func (s *DefaultService) Publish(ctx context.Context, topic string, payload interface{}) (int, error)

func (*DefaultService) SignalEntry

func (s *DefaultService) SignalEntry(ctx context.Context, state string) (int, error)

func (*DefaultService) Subscribe

func (s *DefaultService) Subscribe(ctx context.Context, topic string) (*subscription, error)

type PublishRequest

type PublishRequest struct {
	Topic   string      `json:"topic"`
	Payload interface{} `json:"payload"`
}

PublishRequest represents a publish request.

type PublishResponse

type PublishResponse struct {
	Seq int `json:"seq"`
}

PublishResponse represents a publish response.

type Request

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"`
}

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 Response

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"`
}

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 Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(service Service, port int) (srv *Server, err error)

func (*Server) Addr

func (s *Server) Addr() string

func (*Server) Port

func (s *Server) Port() int

func (*Server) Serve

func (s *Server) Serve() error

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

type Service

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)
}

Service is the implementation of a sync service. This service must support synchronization actions such as pub-sub and barriers.

type SignalEntryRequest

type SignalEntryRequest struct {
	State string `json:"state"`
}

SignalEntryRequest represents a signal entry request.

type SignalEntryResponse

type SignalEntryResponse struct {
	Seq int `json:"seq"`
}

SignalEntryResponse represents a signal entry response.

type SubscribeRequest

type SubscribeRequest struct {
	Topic string `json:"topic"`
}

SubscribeRequest represents a subscribe request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL