Documentation
¶
Overview ¶
loadgen/iterators.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
Connect() error
Disconnect()
// Publish now returns a boolean indicating if the publish was successful, along with an error.
Publish(ctx context.Context, device *Device) (bool, error)
}
Client defines the interface for a client that can publish messages.
type Device ¶
type Device struct {
ID string
MessageRate float64
PayloadGenerator PayloadGenerator
}
Device represents a single simulated device in the load test.
type LoadGenerator ¶
type LoadGenerator struct {
// contains filtered or unexported fields
}
LoadGenerator orchestrates the load test.
func NewLoadGenerator ¶
func NewLoadGenerator(client Client, devices []*Device, logger *slog.Logger) *LoadGenerator
NewLoadGenerator creates a new LoadGenerator.
func (*LoadGenerator) ExpectedMessagesForDuration ¶
func (lg *LoadGenerator) ExpectedMessagesForDuration(duration time.Duration) int
ExpectedMessagesForDuration calculates the exact number of messages that will be sent by all devices for a given duration, based on the "publish-then-tick" logic.
type MqttClient ¶
type MqttClient struct {
// contains filtered or unexported fields
}
MqttClient implements the Client interface for MQTT.
func (*MqttClient) Connect ¶
func (c *MqttClient) Connect() error
Connect establishes a connection to the MQTT broker.
func (*MqttClient) Disconnect ¶
func (c *MqttClient) Disconnect()
Disconnect closes the connection to the MQTT broker.
type PayloadGenerator ¶
PayloadGenerator defines the interface for generating message payloads.
type ReplayPayloadGenerator ¶
type ReplayPayloadGenerator struct {
// contains filtered or unexported fields
}
ReplayPayloadGenerator implements loadgen.PayloadGenerator for replaying pre-loaded messages. It allows the load generator to "publish" messages that have already been read from GCS.
func NewReplayPayloadGenerator ¶
func NewReplayPayloadGenerator(messages [][]byte) *ReplayPayloadGenerator
NewReplayPayloadGenerator creates a new generator from a slice of raw message payloads.
func (*ReplayPayloadGenerator) GeneratePayload ¶
func (r *ReplayPayloadGenerator) GeneratePayload(device *Device) ([]byte, error)
GeneratePayload returns the next pre-loaded payload. It's called by the load generator to get the message to publish. It returns io.EOF when no more messages are available.
type Sequence ¶
type Sequence struct {
// contains filtered or unexported fields
}
Sequence provides a thread-safe iterator for generating sequential integers, useful for message counters in payloads.
func NewSequence ¶
NewSequence creates a new sequence starting at the given value. The first call to Next() will return startValue.