Compare commits
4 Commits
change-log
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f72b8c0da1 | |||
| 7765cb32a9 | |||
| 2c495aa3e4 | |||
|
|
b53a553382 |
36
README.md
36
README.md
@@ -1,5 +1,35 @@
|
||||
# xmpploadtesting
|
||||
A tool for testing xmpp servers load
|
||||
# rolling-stock-display-simulation-tool
|
||||
|
||||
A tool for connecting virtual devices to the Rolling Stock platform.
|
||||
Devices need to be registered and credentials prepared in a JSON file
|
||||
put in input.json (or specified in a variablle)
|
||||
|
||||
Sample input.json file structure:
|
||||
|
||||
```
|
||||
[
|
||||
{"username": "DEVICE197", "host": "rolling-stock-sandbox2-openfire.onsmartengineering.com", "port": 5222, "ping": 15, "password": "a32c695ccde9"},
|
||||
{"username": "DEVICE198", "host": "rolling-stock-sandbox2-openfire.onsmartengineering.com", "port": 5222, "ping": 15, "password": "c93f60d35d51"},
|
||||
{"username": "DEVICE199", "host": "rolling-stock-sandbox2-openfire.onsmartengineering.com", "port": 5222, "ping": 15, "password": "ddf4d41f846f"},
|
||||
{"username": "DEVICE200", "host": "rolling-stock-sandbox2-openfire.onsmartengineering.com", "port": 5222, "ping": 15, "password": "07fd03b6fce0"}
|
||||
]
|
||||
```
|
||||
|
||||
The tool sends regular presence messages (with harcoded dummy versions content)
|
||||
and properly responds with "unsupported command" to any command sent to it.
|
||||
|
||||
|
||||
## Usage:
|
||||
|
||||
```./rolling-stock-display-simulation-tool```
|
||||
|
||||
## Building
|
||||
|
||||
If the target system is linux amd-64 based you can just copy the binary and use it.
|
||||
Otherwise build the binary like every other golang binary and then copy it.
|
||||
|
||||
```go build```
|
||||
|
||||
|
||||
## Environment variables
|
||||
|
||||
@@ -13,6 +43,6 @@ A tool for testing xmpp servers load
|
||||
| |
|
||||
| PRESENCE_STATUS_DELAY | NO | 2 min | Delay for online presence message loop |
|
||||
| COMMAND_REPLY_DELAY | NO | 10 sec | Delay for command message reply |
|
||||
| EXECUTE_SIGLE_STATUS_MESSAGE | NO | false | Send one presence stanza message for clients and terminate|
|
||||
| EXECUTE_SINGLE_STATUS_MESSAGE | NO | false | Send one presence stanza message for clients and terminate|
|
||||
| |
|
||||
|
||||
|
||||
@@ -15,8 +15,9 @@ func Load() {
|
||||
CredentialsFileLocation: getEnv("CREDENTIALS_FILE_LOCATION", "input.json"),
|
||||
},
|
||||
GeneralOptions: GeneralOptions{
|
||||
PresenceStatusDelay: int64(getEnvInt("PRESENCE_STATUS_DELAY", 2) * 60),
|
||||
CommandReplyDelay: getEnvInt("COMMAND_REPLY_DELAY", 10),
|
||||
PresenceStatusDelay: int64(getEnvInt("PRESENCE_STATUS_DELAY", 2) * 60),
|
||||
CommandReplyDelay: getEnvInt("COMMAND_REPLY_DELAY", 10),
|
||||
ExecuteSingleStatusMessage: getEnvBool("EXECUTE_SNIGLE_STATUS_MESSAGE"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func getEnvInt(key string, defaultValue int) int {
|
||||
}
|
||||
|
||||
// getEnv extracts the bool value from environment variable
|
||||
func getEnvBool(env string) bool {
|
||||
func mustGetEnvBool(env string) bool {
|
||||
envVal := mustGetEnv(env)
|
||||
value, err := strconv.ParseBool(envVal)
|
||||
|
||||
@@ -45,6 +45,18 @@ func getEnvBool(env string) bool {
|
||||
return value
|
||||
}
|
||||
|
||||
// getEnv extracts the bool value from environment variable
|
||||
func getEnvBool(env string) bool {
|
||||
envVal := getEnv(env, "false")
|
||||
value, err := strconv.ParseBool(envVal)
|
||||
|
||||
if err != nil {
|
||||
value = false
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
// mustGetEnv returns value for give key from environment
|
||||
// if key is not present in environment function will panic
|
||||
func mustGetEnv(key string) string {
|
||||
|
||||
@@ -21,6 +21,7 @@ type Credentials struct {
|
||||
|
||||
// GeneralOptions contains information for general configuration options
|
||||
type GeneralOptions struct {
|
||||
PresenceStatusDelay int64
|
||||
CommandReplyDelay int
|
||||
PresenceStatusDelay int64
|
||||
CommandReplyDelay int
|
||||
ExecuteSingleStatusMessage bool
|
||||
}
|
||||
|
||||
7
go.mod
7
go.mod
@@ -1,8 +1,11 @@
|
||||
module github.com/xmpploadtesting
|
||||
module bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool
|
||||
|
||||
go 1.17
|
||||
|
||||
require gosrc.io/xmpp v0.5.1
|
||||
require (
|
||||
github.com/twinj/uuid v1.0.0
|
||||
gosrc.io/xmpp v0.5.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.1.1 // indirect
|
||||
|
||||
31
main.go
31
main.go
@@ -2,10 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
appConfig "github.com/xmpploadtesting/config"
|
||||
xmppService "github.com/xmpploadtesting/services"
|
||||
appConfig "bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool/config"
|
||||
xmppService "bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool/services"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -19,25 +18,13 @@ func main() {
|
||||
// Send online presence stanza
|
||||
xmppServiceInstance := xmppService.Instance()
|
||||
|
||||
for {
|
||||
|
||||
for _, xmppClient := range xmppServiceInstance.XMPPClients {
|
||||
|
||||
// Send online presence stanza in go rutines
|
||||
go func(xmppClient xmppService.XMPPClient) {
|
||||
err := xmppService.SendOnlinePresenceStanza(xmppClient.Client, xmppClient.Config.Jid)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("There was an error while sending online presence stanza %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
}(xmppClient)
|
||||
|
||||
}
|
||||
// Delay before sending another message
|
||||
time.Sleep(time.Duration(appConfig.AppConfig.GeneralOptions.PresenceStatusDelay * 1000000000))
|
||||
|
||||
// Execute send online presence status message for every client and termintate program
|
||||
if appConfig.AppConfig.GeneralOptions.ExecuteSingleStatusMessage {
|
||||
xmppServiceInstance.ExecuteSingleStatusMessage()
|
||||
log.Println("ExecuteSingleStatusMessage finished, online presente status message sent sucessfuly")
|
||||
return
|
||||
}
|
||||
|
||||
// Keep the servbie running
|
||||
xmppServiceInstance.RunOnlinePresenceStatusIndefinetly()
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -12,8 +12,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
appConfig "bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool/config"
|
||||
"github.com/twinj/uuid"
|
||||
appConfig "github.com/xmpploadtesting/config"
|
||||
"gosrc.io/xmpp"
|
||||
"gosrc.io/xmpp/stanza"
|
||||
)
|
||||
@@ -175,7 +175,7 @@ func Init() {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
statusMesageDelay := int64(rand.Intn(appConfig.AppConfig.GeneralOptions.CommandReplyDelay))
|
||||
log.Printf("DELAYING FOR: %v", statusMesageDelay*1000000000)
|
||||
log.Printf("Delaying client connection for: %v secconds", statusMesageDelay)
|
||||
// Delay For two seccond to allow all clients to connect
|
||||
time.Sleep(time.Duration(statusMesageDelay * 1000000000))
|
||||
|
||||
@@ -197,8 +197,6 @@ func Init() {
|
||||
}()
|
||||
|
||||
}
|
||||
// // Delay For two seccond to allow all clients to connect
|
||||
// time.Sleep(time.Duration(2000000000))
|
||||
// Wait untill all client connections are open sucessfuly
|
||||
wg.Wait()
|
||||
|
||||
@@ -208,7 +206,7 @@ func Init() {
|
||||
func SendOnlinePresenceStanza(client *xmpp.Client, jid string) error {
|
||||
|
||||
statusMesageDelay := int64(rand.Intn(appConfig.AppConfig.GeneralOptions.CommandReplyDelay))
|
||||
log.Printf("DELAYING FOR: %v", statusMesageDelay*1000000000)
|
||||
log.Printf("Delaying online stanza presence message for: %v, secconds", statusMesageDelay*1000000000)
|
||||
// Delay For two seccond to allow all clients to connect
|
||||
time.Sleep(time.Duration(statusMesageDelay * 1000000000))
|
||||
|
||||
@@ -225,6 +223,57 @@ func SendOnlinePresenceStanza(client *xmpp.Client, jid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunOnlinePresenceStatusIndefinetly - keep sending online presence status messages indefinetly for all clients with delay
|
||||
func (xmppService *XMPPService) RunOnlinePresenceStatusIndefinetly() {
|
||||
|
||||
for {
|
||||
for _, xmppClient := range xmppService.XMPPClients {
|
||||
|
||||
// Send online presence stanza in go rutines
|
||||
go func(xmppClient XMPPClient) {
|
||||
err := SendOnlinePresenceStanza(xmppClient.Client, xmppClient.Config.Jid)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("There was an error while sending online presence stanza %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
}(xmppClient)
|
||||
|
||||
}
|
||||
|
||||
// Delay before sending another message
|
||||
time.Sleep(time.Duration(appConfig.AppConfig.GeneralOptions.PresenceStatusDelay * 1000000000))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ExecuteSingleStatusMessage - Wait for all clients to send online presence stanza messages just once
|
||||
func (xmppService *XMPPService) ExecuteSingleStatusMessage() {
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for _, xmppClient := range xmppService.XMPPClients {
|
||||
wg.Add(1)
|
||||
|
||||
// Send online presence stanza in go rutines
|
||||
go func(xmppClient XMPPClient) {
|
||||
defer wg.Done()
|
||||
err := SendOnlinePresenceStanza(xmppClient.Client, xmppClient.Config.Jid)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("There was an error while sending online presence stanza %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
}(xmppClient)
|
||||
}
|
||||
|
||||
// Wait until all clients sent their online prezence staza messages
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func getClientConfigsFromFile(filePath string) ([]ClientCredentials, error) {
|
||||
|
||||
var clientCredentials []ClientCredentials
|
||||
@@ -279,11 +328,11 @@ func handleMessage(s xmpp.Sender, p stanza.Packet) {
|
||||
log.Printf("<%v> unable to unmarshal Command Meassage: %v", msg.To, msg.Body)
|
||||
}
|
||||
if len(commandMessageResponse.Responses) > 0 || len(commandMessage.Commands) > 0 {
|
||||
messageIDUUID := uuid.NewV4().String()
|
||||
// messageIDUUID := uuid.NewV4().String()
|
||||
commandMessageUUID := uuid.NewV4().String()
|
||||
commandMessageResponse.Responses[0].UUID = commandMessageUUID
|
||||
commandMessageResponse.PlayerID = commandMessage.Commands[0].Params.PlayerID
|
||||
commandMessageResponse.MessageID = messageIDUUID
|
||||
commandMessageResponse.MessageID = commandMessage.MessageID
|
||||
|
||||
} else {
|
||||
log.Printf("<%v> There are no commands inside command message : %v", msg.To, commandMessage)
|
||||
|
||||
Reference in New Issue
Block a user