Added simple http handler for route updates into unittests
Change-Id: Ia8711a773063b5dccf24aa5a312ebd7ab6074e27
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
diff --git a/pkg/control/control.go b/pkg/control/control.go
index fc45f6f..b398daa 100644
--- a/pkg/control/control.go
+++ b/pkg/control/control.go
@@ -38,13 +38,12 @@
var SubDelReqTime time.Duration = 5 * time.Second
type Control struct {
- e2ap *E2ap
- registry *Registry
- rtmgrClient *RtmgrClient
- tracker *Tracker
- timerMap *TimerMap
- rmrSendMutex sync.Mutex
- skipRouteUpdate bool // temp solution to skip routeupdate in unittests
+ e2ap *E2ap
+ registry *Registry
+ rtmgrClient *RtmgrClient
+ tracker *Tracker
+ timerMap *TimerMap
+ rmrSendMutex sync.Mutex
}
type RMRMeid struct {
@@ -95,11 +94,10 @@
rtmgrClient := RtmgrClient{client, handle, deleteHandle}
return &Control{e2ap: new(E2ap),
- registry: registry,
- rtmgrClient: &rtmgrClient,
- tracker: tracker,
- timerMap: timerMap,
- skipRouteUpdate: false,
+ registry: registry,
+ rtmgrClient: &rtmgrClient,
+ tracker: tracker,
+ timerMap: timerMap,
}
}
@@ -188,12 +186,10 @@
subRouteAction := SubRouteInfo{CREATE, *srcAddr, *srcPort, newSubId}
xapp.Logger.Info("SubReq: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
- if c.skipRouteUpdate == false {
- err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
- if err != nil {
- xapp.Logger.Error("SubReq: Failed to update routing manager. Dropping this SubReq msg. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
- return
- }
+ err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
+ if err != nil {
+ xapp.Logger.Error("SubReq: Failed to update routing manager. Dropping this SubReq msg. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
+ return
}
// Setting new subscription ID in the RMR header
@@ -288,13 +284,11 @@
time.Sleep(3 * time.Second)
- if c.skipRouteUpdate == false {
- xapp.Logger.Info("SubFail: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
- subRouteAction := SubRouteInfo{CREATE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
- err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
- if err != nil {
- xapp.Logger.Error("SubFail: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
- }
+ xapp.Logger.Info("SubFail: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
+ subRouteAction := SubRouteInfo{CREATE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
+ err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
+ if err != nil {
+ xapp.Logger.Error("SubFail: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
}
xapp.Logger.Info("SubFail: Deleting transaction record. SubId: %v, Xid: %s", params.SubId, params.Xid)
@@ -479,14 +473,12 @@
time.Sleep(3 * time.Second)
- if c.skipRouteUpdate == false {
- xapp.Logger.Info("SubDelResp: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
- subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
- err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
- if err != nil {
- xapp.Logger.Error("SubDelResp: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
- return
- }
+ xapp.Logger.Info("SubDelResp: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
+ subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
+ err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
+ if err != nil {
+ xapp.Logger.Error("SubDelResp: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
+ return
}
xapp.Logger.Info("SubDelResp: Deleting transaction record. SubId: %v, Xid: %s", params.SubId, params.Xid)
@@ -536,14 +528,12 @@
time.Sleep(3 * time.Second)
- if c.skipRouteUpdate == false {
- xapp.Logger.Info("SubDelFail: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
- subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
- c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
- if err != nil {
- xapp.Logger.Error("SubDelFail: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
- return
- }
+ xapp.Logger.Info("SubDelFail: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
+ subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
+ c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
+ if err != nil {
+ xapp.Logger.Error("SubDelFail: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
+ return
}
xapp.Logger.Info("SubDelFail: Deleting transaction record. SubId: %v, Xid: %s", params.SubId, params.Xid)
diff --git a/pkg/control/main_test.go b/pkg/control/main_test.go
index 3f1284c..f74339e 100644
--- a/pkg/control/main_test.go
+++ b/pkg/control/main_test.go
@@ -24,6 +24,7 @@
"fmt"
"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
"io/ioutil"
+ "net/http"
"os"
"testing"
"time"
@@ -130,30 +131,35 @@
//Cfg creation won't work like this as xapp-frame reads it during init.
//
/*
- cfgstr:=`{
- "local": {
- "host": ":8080"
- },
- "logger": {
- "level": 4
- },
- "rmr": {
- "protPort": "tcp:14560",
- "maxSize": 4096,
- "numWorkers": 1,
- "txMessages": ["RIC_SUB_REQ", "RIC_SUB_DEL_REQ"],
- "rxMessages": ["RIC_SUB_RESP", "RIC_SUB_FAILURE", "RIC_SUB_DEL_RESP", "RIC_SUB_DEL_FAILURE", "RIC_INDICATION"]
- },
- "db": {
- "host": "localhost",
- "port": 6379,
- "namespaces": ["sdl", "rnib"]
- }
- }`
+ cfgstr:=`{
+ "local": {
+ "host": ":8080"
+ },
+ "logger": {
+ "level": 4
+ },
+ "rmr": {
+ "protPort": "tcp:14560",
+ "maxSize": 4096,
+ "numWorkers": 1,
+ "txMessages": ["RIC_SUB_REQ", "RIC_SUB_DEL_REQ"],
+ "rxMessages": ["RIC_SUB_RESP", "RIC_SUB_FAILURE", "RIC_SUB_DEL_RESP", "RIC_SUB_DEL_FAILURE", "RIC_INDICATION"]
+ },
+ "db": {
+ "host": "localhost",
+ "port": 6379,
+ "namespaces": ["sdl", "rnib"]
+ },
+ "rtmgr" : {
+ "HostAddr" : "localhost",
+ "port" : "8989",
+ "baseUrl" : "/"
+ }
+ `
- cfgfilename,_ := testCreateTmpFile(cfgstr)
- defer os.Remove(cfgfilename)
- os.Setenv("CFG_FILE", cfgfilename)
+ cfgfilename,_ := testCreateTmpFile(cfgstr)
+ defer os.Remove(cfgfilename)
+ os.Setenv("CFG_FILE", cfgfilename)
*/
xapp.Logger.Info("Using cfg file %s", os.Getenv("CFG_FILE"))
@@ -189,7 +195,6 @@
os.Setenv("RMR_SRC_ID", "localhost:14560")
c := NewControl()
- c.skipRouteUpdate = true
xapp.SetReadyCB(mainCtrl.ReadyCB, nil)
go xapp.RunWithParams(c, false)
<-mainCtrl.syncChan
@@ -232,6 +237,22 @@
defer os.Remove(e2termrtfilename)
e2termConn = createNewRmrControl("e2termConn", e2termrtfilename, "15560", "RMRE2TERMSTUB")
+ //---------------------------------
+ //
+ //---------------------------------
+ http_handler := func(w http.ResponseWriter, r *http.Request) {
+ xapp.Logger.Info("(http handler) handling")
+ w.WriteHeader(200)
+ }
+
+ go func() {
+ http.HandleFunc("/", http_handler)
+ http.ListenAndServe("localhost:8989", nil)
+ }()
+
+ //---------------------------------
+ //
+ //---------------------------------
code := m.Run()
os.Exit(code)
}
diff --git a/test/config-file.json b/test/config-file.json
index ab0079a..1ff0070 100644
--- a/test/config-file.json
+++ b/test/config-file.json
@@ -16,5 +16,10 @@
"host": "localhost",
"port": 6379,
"namespaces": ["sdl", "rnib"]
+ },
+ "rtmgr" : {
+ "HostAddr" : "localhost",
+ "port" : "8989",
+ "baseUrl" : "/"
}
}