Compare commits
4 Commits
change-log
...
single-mes
| Author | SHA1 | Date | |
|---|---|---|---|
| f72b8c0da1 | |||
| 7765cb32a9 | |||
| 2c495aa3e4 | |||
|
|
b53a553382 |
36
README.md
36
README.md
@@ -1,5 +1,35 @@
|
|||||||
# xmpploadtesting
|
# rolling-stock-display-simulation-tool
|
||||||
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
|
||||||
|
|
||||||
@@ -13,6 +43,6 @@ A tool for testing xmpp servers load
|
|||||||
| |
|
| |
|
||||||
| 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_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"),
|
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"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func getEnvInt(key string, defaultValue int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getEnv extracts the bool value from environment variable
|
// getEnv extracts the bool value from environment variable
|
||||||
func getEnvBool(env string) bool {
|
func mustGetEnvBool(env string) bool {
|
||||||
envVal := mustGetEnv(env)
|
envVal := mustGetEnv(env)
|
||||||
value, err := strconv.ParseBool(envVal)
|
value, err := strconv.ParseBool(envVal)
|
||||||
|
|
||||||
@@ -45,6 +45,18 @@ func getEnvBool(env string) bool {
|
|||||||
return value
|
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
|
// mustGetEnv returns value for give key from environment
|
||||||
// if key is not present in environment function will panic
|
// if key is not present in environment function will panic
|
||||||
func mustGetEnv(key string) string {
|
func mustGetEnv(key string) string {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ 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
7
go.mod
@@ -1,8 +1,11 @@
|
|||||||
module github.com/xmpploadtesting
|
module bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool
|
||||||
|
|
||||||
go 1.17
|
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 (
|
require (
|
||||||
github.com/google/uuid v1.1.1 // indirect
|
github.com/google/uuid v1.1.1 // indirect
|
||||||
|
|||||||
31
main.go
31
main.go
@@ -2,10 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
|
||||||
|
|
||||||
appConfig "github.com/xmpploadtesting/config"
|
appConfig "bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool/config"
|
||||||
xmppService "github.com/xmpploadtesting/services"
|
xmppService "bitbucket.org/outfrontmedia/rolling-stock-display-simulation-tool/services"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -19,25 +18,13 @@ func main() {
|
|||||||
// Send online presence stanza
|
// Send online presence stanza
|
||||||
xmppServiceInstance := xmppService.Instance()
|
xmppServiceInstance := xmppService.Instance()
|
||||||
|
|
||||||
for {
|
// Execute send online presence status message for every client and termintate program
|
||||||
|
if appConfig.AppConfig.GeneralOptions.ExecuteSingleStatusMessage {
|
||||||
for _, xmppClient := range xmppServiceInstance.XMPPClients {
|
xmppServiceInstance.ExecuteSingleStatusMessage()
|
||||||
|
log.Println("ExecuteSingleStatusMessage finished, online presente status message sent sucessfuly")
|
||||||
// Send online presence stanza in go rutines
|
return
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -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,6 +223,57 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user