Skip to content

Commit

Permalink
Merge pull request #84 from UlfBj/master
Browse files Browse the repository at this point in the history
Test client updates
  • Loading branch information
UlfBj authored Jan 24, 2025
2 parents b69afec + 3710a1c commit 07bcab4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
17 changes: 10 additions & 7 deletions client/client-1.0/testClient/testClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"net/http"
"net/url"
"os"
// "strconv"
"strconv"
"strings"

"fmt"
Expand Down Expand Up @@ -53,6 +53,7 @@ const (
)

var doneChannel []chan bool
var maxEvents int

var httpCommandList []string
var wsCommandList []string
Expand Down Expand Up @@ -187,10 +188,10 @@ func performWsCommand(command string, conn *websocket.Conn) {
}
fmt.Printf("Notification: %s\n", string(event))
events++
if events == 2 {
if events == maxEvents {
subscriptionId := utils.ExtractSubscriptionId(jsonResponse)
unsubReq := `{"action":"unsubscribe", "subscriptionId":"` + subscriptionId + `", "requestId":"123"}`
fmt.Printf("Two events received. Terminating subscription session\n")
fmt.Printf(strconv.Itoa(maxEvents)+" events received. Terminating subscription session\n")
performWsCommand(unsubReq, conn)
return
}
Expand Down Expand Up @@ -304,10 +305,10 @@ var publishHandler MQTT.MessageHandler = func(client MQTT.Client, msg MQTT.Messa
}
fmt.Printf("Event=%s\n", string(msg.Payload()))
events++
if events == 3 {
if events == maxEvents+1 {
subscriptionId := utils.ExtractSubscriptionId(string(msg.Payload()))
unsubReq := `{"action":"unsubscribe", "subscriptionId":"` + subscriptionId + `", "requestId":"123"}`
fmt.Printf("Two events received. Unsubscribing to subscription session\n")
fmt.Printf(strconv.Itoa(maxEvents)+" events received. Unsubscribing to subscription session\n")
publishVissV2Request(brokerSocket, unsubReq, clientTopic, serverTopic)
events = 0
}
Expand Down Expand Up @@ -411,10 +412,10 @@ func performGrpcCommand(vssRequest string, client pb.VISSClient) {
events++
vssResponse := utils.SubscribeStreamPbToJson(pbResponse)
fmt.Printf("Received response:%s\n", vssResponse)
if events == 3 {
if events == maxEvents+1 {
subscriptionId := utils.ExtractSubscriptionId(vssResponse)
unsubReq := `{"action":"unsubscribe", "subscriptionId":"` + subscriptionId + `", "requestId":"123"}`
fmt.Printf("Two events received. Terminating subscription session\n")
fmt.Printf(strconv.Itoa(maxEvents)+" events received. Terminating subscription session\n")
performGrpcCommand(unsubReq, client)
break
}
Expand Down Expand Up @@ -466,6 +467,7 @@ func main() {
// Create flags
// prot := parser.Selector("p", "protocol", []string{"http", "ws"}, &argparse.Options{Required: false,
// Help: "Protocol must be either http or websocket", Default: "ws"})
maxEvnts := parser.Int("m", "maxEvents", &argparse.Options{Required: false, Help: "Max subscription events before unsubscribe", Default: 2})
logFile := parser.Flag("", "logfile", &argparse.Options{Required: false, Help: "outputs to logfile in ./logs folder"})
logLevel := parser.Selector("", "loglevel", []string{"trace", "debug", "info", "warn", "error", "fatal", "panic"}, &argparse.Options{
Required: false,
Expand All @@ -479,6 +481,7 @@ func main() {
//exits due to required info not provided by user
os.Exit(1)
}
maxEvents = *maxEvnts

utils.InitLog("testClient-log.txt", "./logs", *logFile, *logLevel) //used in utils functions...

Expand Down
32 changes: 22 additions & 10 deletions client/client-1.0/testClient/testRequests.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
},
{
"action": "set",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"path": "Vehicle.TripMeterReading",
"value": "true"
}
],
"ws": [
{
"action": "get",
"path": "Vehicle.Speed",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"requestId": "232"
},
{
Expand All @@ -50,26 +50,38 @@
},
{
"action": "set",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"path": "Vehicle.TripMeterReading",
"value": "true",
"requestId": "245"
},
{
"action": "subscribe",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"path": "Vehicle.Speed",
"filter": {
"variant": "timebased",
"parameter": {
"period": "1000"
}
},
"requestId": "246"
},
{
"action": "subscribe",
"path": "Vehicle.Speed",
"filter": {
"variant": "change",
"parameter": {
"logic-op": "lt",
"diff": "-1"
}
},
"requestId": "247"
}
],
"mqtt": [
{
"action": "get",
"path": "Vehicle.Speed",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"requestId": "232"
},
{
Expand All @@ -91,13 +103,13 @@
},
{
"action": "set",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"path": "Vehicle.TripMeterReading",
"value": "true",
"requestId": "245"
},
{
"action": "subscribe",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"path": "Vehicle.Speed",
"filter": {
"variant": "timebased",
"parameter": {
Expand All @@ -110,7 +122,7 @@
"grpc": [
{
"action": "get",
"path": "Vehicle.Speed",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"requestId": "232"
},
{
Expand All @@ -132,13 +144,13 @@
},
{
"action": "set",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"path": "Vehicle.TripMeterReading",
"value": "true",
"requestId": "245"
},
{
"action": "subscribe",
"path": "Vehicle.Cabin.Door.Row1.DriverSide.IsOpen",
"path": "Vehicle.Speed",
"filter": {
"variant": "timebased",
"parameter": {
Expand Down
9 changes: 4 additions & 5 deletions feeder/feeder-template/feederv3/feederv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ func initVSSInterfaceMgr(inputChan chan DomainData, outputChan chan DomainData)
for {
select {
case outData := <-outputChan:
if outData.Name == "Vehicle.TripMeterReading" {
utils.Info.Printf("Data written to statestorage: Name=%s, Value=%s", outData.Name, outData.Value)
}
if len(outData.Name) == 0 {
continue
}
Expand All @@ -189,6 +186,7 @@ if outData.Name == "Vehicle.TripMeterReading" {
if onNotificationList(outData.Name) != -1 {
message := `{"action": "subscription", "path":"` + outData.Name + `"}`
udsChan <- message
utils.Info.Printf("Server notified that data written to %s", outData.Name)
}
}
}
Expand Down Expand Up @@ -238,9 +236,10 @@ func udsReader(conn net.Conn, inputChan chan DomainData, udsChan chan string) {
n, err := conn.Read(buf)
if err != nil {
utils.Error.Printf("udsReader:Read failed, err = %s", err)
time.Sleep(1 * time.Second)
continue
}
// utils.Info.Printf("udsReader:Server message: %s", string(buf[:n]))
utils.Info.Printf("udsReader:Message from server: %s", string(buf[:n]))
if n > 8192 {
utils.Error.Printf("udsReader:Max message size of 8192 chars exceeded. Message dropped")
continue
Expand Down Expand Up @@ -298,7 +297,7 @@ func udsWriter(conn net.Conn, udsChan chan string) {
for {
select {
case message := <-udsChan:
utils.Info.Printf("udsWriter:Server message: %s", message)
utils.Info.Printf("udsWriter:Message to server: %s", message)
_, err := conn.Write([]byte(message))
if err != nil {
utils.Error.Printf("udsWriter:Write failed, err = %s", err)
Expand Down
2 changes: 1 addition & 1 deletion runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ startme() {

sleep 3s
echo "Starting testClient"
screen -S testClient bash -c "pushd client/client-1.0/testClient && go build && ./testClient && popd"
screen -S testClient bash -c "pushd client/client-1.0/testClient && go build && ./testClient -m 4 && popd"

screen -list
}
Expand Down
4 changes: 2 additions & 2 deletions server/vissv2server/serviceMgr/serviceMgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func evaluateChangeFilter(opValue string, latestValue string, currentValue strin
func compareValues(logicOp string, latestValue string, currentValue string, diff string) bool {
latestValueType := utils.AnalyzeValueType(latestValue)
if latestValueType != utils.AnalyzeValueType(currentValue) {
utils.Error.Printf("compareValues: Incompatible types, latVal=%s, curVal=%s", latestValue, currentValue)
utils.Error.Printf("compareValues: Incompatible types, latVal=%s (type=%d), curVal=%s (type=%d)", latestValue, latestValueType, currentValue, utils.AnalyzeValueType(currentValue))
return false
}
switch latestValueType {
Expand Down Expand Up @@ -524,7 +524,7 @@ func getVehicleData(path string) string { // returns {"value":"Y", "ts":"Z"}
}
return `{"value":"` + value + `", "ts":"` + timestamp + `"}`
case "redis":
utils.Info.Printf(path)
// utils.Info.Printf(path)
dp, err := redisClient.Get(path).Result()
if err != nil {
if err.Error() != "redis: nil" {
Expand Down
5 changes: 5 additions & 0 deletions tutorial/content/build-system/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ If some logdata looks incorrect the operator can hit ctrl-C to terminate the tes
and instead inspect the log files for the server and the feeder, found in the log directory of their respective start directories.
It is up to the operator to evaluate whether the logs look correct or not,
so it might be a good idea to run the script before doing any modifications lo learn how correct logs looks like.
All subscribe sessions are automatically unsubscribed after 4 events have been received.
This number is set in runTest.sh by the CLI parameter "-m 4". Other numbers of event can be set by editing this number.

Issue the following command in the root directory to run the tests:
```
Expand All @@ -84,6 +86,9 @@ When the testing is completed the script should be run to terminate the server a
```
$ ./runtest.sh stopme
```
The file testRequests.json can be edited to add or remove test cases.
It is up to the operator to ensure that subscribe trigger conditions will be met by the simulated data that the feeder injects.
This data can be modified in the tripdata.json file in the feederv3 directory.

### Transport protocols
The following transport protocols are supported
Expand Down
3 changes: 3 additions & 0 deletions utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ func isFloatType(value string) bool {
if err != nil {
return false
}
if fVal == 0 {
return true
}
if fVal < 0 {
fVal = fVal * -1.0
}
Expand Down

0 comments on commit 07bcab4

Please sign in to comment.