Documentation ¶
Index ¶
- type Buffer
- type Conduit
- type Hub
- func (h *Hub) AddNetwork(net *Network)
- func (h *Hub) DeliverAll()
- func (h *Hub) DeliverAllEventually(t *testing.T, condition func() bool)
- func (h *Hub) DeliverAllEventuallyUntil(t *testing.T, condition func() bool, waitFor time.Duration, tick time.Duration)
- func (h *Hub) GetNetwork(nodeID flow.Identifier) (*Network, bool)
- type Network
- func (n *Network) DeliverAll(syncOnProcess bool)
- func (n *Network) DeliverAllExcept(syncOnProcess bool, shouldDrop func(*PendingMessage) bool)
- func (n *Network) DeliverSome(syncOnProcess bool, shouldDeliver func(*PendingMessage) bool)
- func (n *Network) GetID() flow.Identifier
- func (n *Network) Register(channel network.Channel, engine network.Engine) (network.Conduit, error)
- func (n *Network) StartConDev(updateInterval time.Duration, recursive bool)
- func (n *Network) StopConDev()
- func (n *Network) Unregister(channel network.Channel) error
- type PendingMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
Buffer buffers all the pending messages to be sent over the mock network from one node to a list of nodes
func (*Buffer) Deliver ¶
func (b *Buffer) Deliver(sendOne func(*PendingMessage) bool)
Deliver delivers all pending messages currently in the buffer using the provided sendOne method. If sendOne returns false, the message was not sent and will remain in the buffer.
func (*Buffer) DeliverRecursive ¶
func (b *Buffer) DeliverRecursive(sendOne func(*PendingMessage))
DeliverRecursive recursively delivers all pending messages using the provided sendOne method until the buffer is empty. If sendOne does not deliver the message, it is permanently dropped.
func (*Buffer) Save ¶
func (b *Buffer) Save(m *PendingMessage)
Save stores a pending message to the buffer
type Conduit ¶
type Conduit struct {
// contains filtered or unexported fields
}
func (*Conduit) Multicast ¶
func (c *Conduit) Multicast(event interface{}, num uint, targetIDs ...flow.Identifier) error
type Hub ¶
type Hub struct { Buffer *Buffer // contains filtered or unexported fields }
Hub is a test helper that mocks a network overlay. It maintains a set of network instances and enables them to directly exchange message over the memory.
func NewNetworkHub ¶
func NewNetworkHub() *Hub
NewNetworkHub creates and returns a new Hub instance.
func (*Hub) AddNetwork ¶
AddNetwork stores the reference of the Network in the Hub, in order for networks to find other networks to send events directly.
func (*Hub) DeliverAll ¶
func (h *Hub) DeliverAll()
DeliverAll delivers all the buffered messages in the Network instances attached to the Hub to their destination. Note that the delivery of messages is done in asynchronous mode, i.e., sender and receiver are synchronized over delivery and not execution of the message.
func (*Hub) DeliverAllEventually ¶
DeliverAllEventually attempts on delivery of all the buffered messages in the Network instances attached to this instance of Hub. Once the delivery is done, it evaluates and returns the condition function. It fails if delivery of all buffered messages in the Network instances attached to this Hub is not getting done within 10 seconds. Note that the delivery of messages is done in asynchronous mode, i.e., sender and receiver are synchronized over delivery and not execution of the message.
func (*Hub) DeliverAllEventuallyUntil ¶
func (h *Hub) DeliverAllEventuallyUntil(t *testing.T, condition func() bool, waitFor time.Duration, tick time.Duration)
DeliverAllEventuallyUntil attempts attempts on delivery of all the buffered messages in the Network instances attached to this instance of Hub. Once the delivery is done, it evaluates and returns the condition function. It fails if delivery of all buffered messages in the Network instances attached to this Hub is not getting done within `waitFor` time interval. It checks the status of message deliveries at every `tick` time interval. Note that the delivery of messages is done in asynchronous mode, i.e., sender and receiver are synchronized over delivery and not execution of the message.
func (*Hub) GetNetwork ¶
func (h *Hub) GetNetwork(nodeID flow.Identifier) (*Network, bool)
GetNetwork returns the Network instance attached to the node ID.
type Network ¶
type Network struct { sync.Mutex mocknetwork.Network // contains filtered or unexported fields }
Network is a mocked Network layer made for testing engine's behavior. It represents the Network layer of a single node. A node can attach several engines of itself to the Network, and hence enabling them send and receive message. When an engine is attached on a Network instance, the mocked Network delivers all engine's events to others using an in-memory delivery mechanism.
func NewNetwork ¶
NewNetwork create a mocked Network. The committee has the identity of the node already, so only `committee` is needed in order for a mock hub to find each other.
func (*Network) DeliverAll ¶
DeliverAll sends all pending messages to the receivers. The receivers might be triggered to forward messages to its peers, so this function will block until all receivers have done their forwarding, and there is no more message in the Network to deliver.
func (*Network) DeliverAllExcept ¶
func (n *Network) DeliverAllExcept(syncOnProcess bool, shouldDrop func(*PendingMessage) bool)
DeliverAllExcept flushes all pending messages in the buffer except those that satisfy the shouldDrop predicate function. All messages that satisfy the shouldDrop predicate are permanently dropped. The message receivers might be triggered to forward some messages to their peers, so this function will block until all receivers have done their forwarding, and there is no more message in the Network to deliver.
If syncOnProcess is true, the sender and receiver are synchronized on processing the message. Otherwise they sync on delivery of the message.
func (*Network) DeliverSome ¶
func (n *Network) DeliverSome(syncOnProcess bool, shouldDeliver func(*PendingMessage) bool)
DeliverSome delivers all messages in the buffer that satisfy the shouldDeliver predicate. Any messages that are not delivered remain in the buffer.
If syncOnProcess is true, the sender and receiver are synchronized on processing the message. Otherwise they sync on delivery of the message.
func (*Network) GetID ¶
func (n *Network) GetID() flow.Identifier
GetID returns the identity of the attached node.
func (*Network) Register ¶
Register registers an Engine of the attached node to the channel via a Conduit, and returns the Conduit instance.
func (*Network) StartConDev ¶
StartConDev starts the continuous delivery mode of the Network. In this mode, the Network continuously checks the nodes' buffer every `updateInterval` milliseconds, and delivers all the pending messages. `recursive` determines whether the delivery is in recursive mode or not
func (*Network) StopConDev ¶
func (n *Network) StopConDev()
StopConDev stops the continuous deliver mode of the Network.
type PendingMessage ¶
type PendingMessage struct { // The sender node id From flow.Identifier Channel network.Channel Event interface{} // The id of the receiver nodes TargetIDs []flow.Identifier }
PendingMessage is a pending message to be sent