1 Commits

Author SHA1 Message Date
c33b5c5df5 Reverted command message UUID to message ID 2021-09-27 10:41:08 +02:00
8 changed files with 33 additions and 118 deletions

View File

@@ -1,35 +1,5 @@
# rolling-stock-display-simulation-tool # xmpploadtesting
A tool for testing xmpp servers load
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 ## Environment variables
@@ -43,6 +13,6 @@ Otherwise build the binary like every other golang binary and then copy it.
| | | |
| PRESENCE_STATUS_DELAY | NO | 2 min | Delay for online presence message loop | | PRESENCE_STATUS_DELAY | NO | 2 min | Delay for online presence message loop |
| COMMAND_REPLY_DELAY | NO | 10 sec | Delay for command message reply | | COMMAND_REPLY_DELAY | NO | 10 sec | Delay for command message reply |
| EXECUTE_SINGLE_STATUS_MESSAGE | NO | false | Send one presence stanza message for clients and terminate| | EXECUTE_SIGLE_STATUS_MESSAGE | NO | false | Send one presence stanza message for clients and terminate|
| | | |

View File

@@ -15,9 +15,8 @@ func Load() {
CredentialsFileLocation: getEnv("CREDENTIALS_FILE_LOCATION", "input.json"), CredentialsFileLocation: getEnv("CREDENTIALS_FILE_LOCATION", "input.json"),
}, },
GeneralOptions: GeneralOptions{ GeneralOptions: GeneralOptions{
PresenceStatusDelay: int64(getEnvInt("PRESENCE_STATUS_DELAY", 2) * 60), PresenceStatusDelay: int64(getEnvInt("PRESENCE_STATUS_DELAY", 2) * 60),
CommandReplyDelay: getEnvInt("COMMAND_REPLY_DELAY", 10), CommandReplyDelay: getEnvInt("COMMAND_REPLY_DELAY", 10),
ExecuteSingleStatusMessage: getEnvBool("EXECUTE_SNIGLE_STATUS_MESSAGE"),
}, },
} }
} }

View File

@@ -33,21 +33,9 @@ func getEnvInt(key string, defaultValue int) int {
return valInteger return valInteger
} }
// getEnv extracts the bool value from environment variable
func mustGetEnvBool(env string) bool {
envVal := mustGetEnv(env)
value, err := strconv.ParseBool(envVal)
if err != nil {
value = false
}
return value
}
// getEnv extracts the bool value from environment variable // getEnv extracts the bool value from environment variable
func getEnvBool(env string) bool { func getEnvBool(env string) bool {
envVal := getEnv(env, "false") envVal := mustGetEnv(env)
value, err := strconv.ParseBool(envVal) value, err := strconv.ParseBool(envVal)
if err != nil { if err != nil {

View File

@@ -21,7 +21,6 @@ type Credentials struct {
// GeneralOptions contains information for general configuration options // GeneralOptions contains information for general configuration options
type GeneralOptions struct { type GeneralOptions struct {
PresenceStatusDelay int64 PresenceStatusDelay int64
CommandReplyDelay int CommandReplyDelay int
ExecuteSingleStatusMessage bool
} }

7
go.mod
View File

@@ -1,11 +1,8 @@
module bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool module github.com/xmpploadtesting
go 1.17 go 1.17
require ( require gosrc.io/xmpp v0.5.1
github.com/twinj/uuid v1.0.0
gosrc.io/xmpp v0.5.1
)
require ( require (
github.com/google/uuid v1.1.1 // indirect github.com/google/uuid v1.1.1 // indirect

31
main.go
View File

@@ -2,9 +2,10 @@ package main
import ( import (
"log" "log"
"time"
appConfig "bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool/config" appConfig "github.com/xmpploadtesting/config"
xmppService "bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool/services" xmppService "github.com/xmpploadtesting/services"
) )
func main() { func main() {
@@ -18,13 +19,25 @@ func main() {
// Send online presence stanza // Send online presence stanza
xmppServiceInstance := xmppService.Instance() xmppServiceInstance := xmppService.Instance()
// Execute send online presence status message for every client and termintate program for {
if appConfig.AppConfig.GeneralOptions.ExecuteSingleStatusMessage {
xmppServiceInstance.ExecuteSingleStatusMessage() for _, xmppClient := range xmppServiceInstance.XMPPClients {
log.Println("ExecuteSingleStatusMessage finished, online presente status message sent sucessfuly")
return // 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))
} }
// Keep the servbie running
xmppServiceInstance.RunOnlinePresenceStatusIndefinetly()
} }

View File

@@ -12,8 +12,8 @@ import (
"sync" "sync"
"time" "time"
appConfig "bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool/config"
"github.com/twinj/uuid" "github.com/twinj/uuid"
appConfig "github.com/xmpploadtesting/config"
"gosrc.io/xmpp" "gosrc.io/xmpp"
"gosrc.io/xmpp/stanza" "gosrc.io/xmpp/stanza"
) )
@@ -223,57 +223,6 @@ func SendOnlinePresenceStanza(client *xmpp.Client, jid string) error {
return nil 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) { func getClientConfigsFromFile(filePath string) ([]ClientCredentials, error) {
var clientCredentials []ClientCredentials var clientCredentials []ClientCredentials