Documentation
¶
Overview ¶
Package dummymqttd can be used to simulate MODE's MQTT server for testing.
Index ¶
- Constants
- Variables
- func StartDummyMQTTD(ctx context.Context, wg *sync.WaitGroup, cmdCh chan DummyCmd) bool
- func StartDummyMQTTDWithConfig(ctx context.Context, wg *sync.WaitGroup, cmdCh chan DummyCmd, conf DummyConfig) bool
- type DummyClient
- type DummyCmd
- type DummyConfig
- type DummyContext
- type KeyValue
- type KeyValueSync
Constants ¶
const ( KVSyncActionReload = "reload" KVSyncActionSet = "set" KVSyncActionDelete = "delete" )
These are possible values for the KeyValueSync.Action field.
const ( DefaultMqttHost = "localhost" DefaultMqttPort = 1998 )
Variables ¶
var ( DefaultUsers = []string{"good", "1234"} DefaultItems = []*KeyValue{ {Key: "key1", Value: "value1", ModificationTime: time.Now()}, {Key: "key2", Value: "value2", ModificationTime: time.Now()}, } // DummyServerDelayDuration is the amount of time the server will wait before // responding. This can be used to simulate a slow network DummyServerDelayDuration = 3 * time.Second // ServerContext is initialized by either StartDummyMQTTD or StartDummyMQTTDWithConfig ServerContext *DummyContext )
Functions ¶
func StartDummyMQTTD ¶
StartDummyMQTTD is dummy MQTT server. It will run an MQTT server as a goroutine. An optional command channel can be passed in to manipulate the server manipulating test conditions and shutting down. Unlike the v2 dummyMQTTD, this starts goroutines but isn't meant to be run as a goroutine. It will panic if it is unable to start listening.
To end the server, either close the command channel or call cancel() on the context.
Types ¶
type DummyClient ¶
type DummyClient struct {
Subscriptions []string
// contains filtered or unexported fields
}
type DummyCmd ¶
type DummyCmd int
const ( // PublishCmd tells the server to publish on whatever topics a client is subscribed to PublishCmd DummyCmd = iota // PublishKvSync tells the server to publish some kv commands PublishKvSync PublishKvSet PublishKvDelete // PublishCommandCmd tells the server to publish a command PublishCommandCmd // ShutdownCmd shuts the server down ShutdownCmd // DisconnectCmd disconnects all connections DisconnectCmd // SlowdownServerCmd inserts a 3-second delay after receiving the next command SlowdownServerCmd // ResetServerCmd resets the server to normal ResetServerCmd )
type DummyConfig ¶
type DummyContext ¶
type DummyContext struct {
Clients []*DummyClient
// contains filtered or unexported fields
}
type KeyValue ¶
type KeyValue struct {
Key string `json:"key"`
Value interface{} `json:"value"`
ModificationTime time.Time `json:"modificationTime"`
}
KeyValue represents a key-value pair stored in the Device Data Proxy.
type KeyValueSync ¶
type KeyValueSync struct {
Action string `json:"action"`
Revision int `json:"rev"`
Key string `json:"key"`
Value interface{} `json:"value"`
NumItems int `json:"numItems"`
Items []*KeyValue `json:"items"`
}
KeyValueSync is a message received from MODE regarding a device's key-value store (DDP).
- If Action has a value of KVSyncActionReload, the Items field will be populated with all the existing key-value pairs.
- If Action has a value of KVSyncActionSet, the Key and Value fields will be populated with a recently saved key-value pair.
- If Action has a value of KVSyncActionDelete, the Key field will be populated with a recently deleted key.
In all cases, the Revision field indicates the current revision number of the key-value store.