* limitations under the License.
*
*******************************************************************************/
-package scoringmgr_test
-
-//$ touch resourceservice/resourceservice.c
-
-import (
- "context"
- "fmt"
- "log"
- "net/http"
- "testing"
- "time"
-
- "gopkg.in/sconf/ini.v0"
- "gopkg.in/sconf/sconf.v0"
-
- confdescription "configuremgr/description"
- restapi "restapi/v1"
- scoringmgr "scoringmgr"
- mockscoringmgr "scoringmgr/mock"
-)
-
-func TestBasicMockScoringMgrMySumLib(t *testing.T) {
-
- //interface
- iscoringmgr := scoringmgr.Init()
- iscoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd
- iscoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
- iscoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd
- iscoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd
- iscoringmgr.Ch = make(chan interface{}, 1024)
-
- //start
- iscoringmgr.Listening()
- iscoringmgr.IStartResourceService()
-
- //setting
- time.Sleep(time.Duration(1) * time.Second)
- appNmae := "ls"
- libName := "mysum"
- libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
- confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
- cfg := new(confdescription.Doc)
- sconf.Must(cfg).Read(ini.File(confPath))
- log.Println(cfg)
- scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
-
- //working on
- time.Sleep(time.Duration(3) * time.Second)
- scoreValue, _ := iscoringmgr.IGetScore("mock", "mock")
- log.Printf("scorevalue : %f\n", scoreValue)
-
- //release
- iscoringmgr.IStopResourceService()
- iscoringmgr.RemoveLib(appNmae)
- time.Sleep(time.Duration(1) * time.Second)
-}
-
-func TestBasicMockScoringMgrMySumLibGetScoreLocal(t *testing.T) {
-
- //interface
- iscoringmgr := scoringmgr.Init()
- iscoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd
- iscoringmgr.IGetScore = scoringmgr.GetScore
- iscoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd
- iscoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd
- iscoringmgr.Ch = make(chan interface{}, 1024)
-
- //start
- iscoringmgr.Listening()
- iscoringmgr.IStartResourceService()
-
- //setting
- time.Sleep(time.Duration(1) * time.Second)
- appName := "ls"
- libName := "mysum"
- libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
- confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
- cfg := new(confdescription.Doc)
- sconf.Must(cfg).Read(ini.File(confPath))
- log.Println(cfg)
- scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
-
- //working on
- time.Sleep(time.Duration(3) * time.Second)
- scoreValue, _ := iscoringmgr.IGetScore("localhost", "mysum")
- log.Printf("scorevalue : %f\n", scoreValue)
-
- //release
- iscoringmgr.IStopResourceService()
- iscoringmgr.RemoveLib(appName)
- time.Sleep(time.Duration(1) * time.Second)
-}
-
-func TestBasicMockScoringMgrMySumLibGetScoreRemote(t *testing.T) {
-
- //interface
- iscoringmgr := scoringmgr.Init()
- iscoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd
- iscoringmgr.IGetScore = scoringmgr.GetScore
- iscoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd
- iscoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd
- iscoringmgr.Ch = make(chan interface{}, 1024)
-
- //start
- iscoringmgr.Listening()
- iscoringmgr.IStartResourceService()
- router := restapi.NewRouter()
- server := &http.Server{Addr: fmt.Sprintf(":%d", 56001), Handler: router}
- go server.ListenAndServe()
- time.Sleep(time.Duration(1) * time.Second)
-
- //setting
- appName := "ls"
- libName := "mysum"
- libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
- confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
- cfg := new(confdescription.Doc)
- sconf.Must(cfg).Read(ini.File(confPath))
- log.Println(cfg)
- scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
- time.Sleep(time.Duration(3) * time.Second)
-
- //working on
- scoreValue, _ := iscoringmgr.IGetScore("127.0.0.1", "mysum")
- log.Printf("scorevalue : %f\n", scoreValue)
- time.Sleep(time.Duration(1) * time.Second)
-
- //release
- iscoringmgr.IStopResourceService()
- iscoringmgr.RemoveLib(appName)
- if err := server.Shutdown(context.TODO()); err != nil {
- panic(err)
- }
- time.Sleep(time.Duration(1) * time.Second)
-}
-
-func TestScoringMgrMyScoringLib(t *testing.T) {
-
- //interface
- iscoringmgr := scoringmgr.Init()
- iscoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
- iscoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
- iscoringmgr.IStartResourceService = scoringmgr.StartResourceService
- iscoringmgr.IStopResourceService = scoringmgr.StopResourceService
- iscoringmgr.Ch = make(chan interface{}, 1024)
-
- //start
- iscoringmgr.Listening()
- iscoringmgr.IStartResourceService()
- time.Sleep(time.Duration(1) * time.Second)
-
- //setting
- appName := "ls"
- libName := "myscoring"
- libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
- confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
- cfg := new(confdescription.Doc)
- sconf.Must(cfg).Read(ini.File(confPath))
- log.Println(cfg)
- scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
-
- //working on
- time.Sleep(time.Duration(3) * time.Second)
- scoreValue, _ := iscoringmgr.IGetScore("mock", "mock")
- log.Printf("scorevalue : %f\n", scoreValue)
-
- //release
- iscoringmgr.IStopResourceService()
- iscoringmgr.RemoveLib(appName)
- time.Sleep(time.Duration(1) * time.Second)
-
-}
-func TestScoringMgrMyScoringLibGetScoreLocal(t *testing.T) {
-
- //interface
- iscoringmgr := scoringmgr.Init()
- iscoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
- iscoringmgr.IGetScore = scoringmgr.GetScore
- iscoringmgr.IStartResourceService = scoringmgr.StartResourceService
- iscoringmgr.IStopResourceService = scoringmgr.StopResourceService
- iscoringmgr.Ch = make(chan interface{}, 1024)
-
- //start
- iscoringmgr.Listening()
- iscoringmgr.IStartResourceService()
- time.Sleep(time.Duration(1) * time.Second)
-
- //setting
- appName := "ls"
- libName := "myscoring"
- libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
- confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
- cfg := new(confdescription.Doc)
- sconf.Must(cfg).Read(ini.File(confPath))
- log.Println(cfg)
- scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
-
- //working on
- time.Sleep(time.Duration(3) * time.Second)
- scoreValue, _ := iscoringmgr.IGetScore("localhost", "myscoring")
- log.Printf("scorevalue : %f\n", scoreValue)
-
- //release
- iscoringmgr.IStopResourceService()
- iscoringmgr.RemoveLib(appName)
-
- time.Sleep(time.Duration(1) * time.Second)
-
-}
-
-func TestScoringMgrMyScoringLibGetScoreRemote(t *testing.T) {
-
- //interface
- iscoringmgr := scoringmgr.Init()
- iscoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
- iscoringmgr.IGetScore = scoringmgr.GetScore
- iscoringmgr.IStartResourceService = scoringmgr.StartResourceService
- iscoringmgr.IStopResourceService = scoringmgr.StopResourceService
- iscoringmgr.Ch = make(chan interface{}, 1024)
-
- //start
- iscoringmgr.Listening()
- iscoringmgr.IStartResourceService()
- router := restapi.NewRouter()
- server := &http.Server{Addr: fmt.Sprintf(":%d", 56001), Handler: router}
- go server.ListenAndServe()
- time.Sleep(time.Duration(1) * time.Second)
-
- //setting
- appName := "ls"
- libName := "myscoring"
- libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
- confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
- cfg := new(confdescription.Doc)
- sconf.Must(cfg).Read(ini.File(confPath))
- log.Println(cfg)
- scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
-
- //working on
- time.Sleep(time.Duration(3) * time.Second)
- scoreValue, _ := iscoringmgr.IGetScore("127.0.0.1", "myscoring")
- log.Printf("scorevalue : %f\n", scoreValue)
-
- //release
- iscoringmgr.IStopResourceService()
- iscoringmgr.RemoveLib(appName)
- if err := server.Shutdown(context.TODO()); err != nil {
- panic(err)
- }
-
- time.Sleep(time.Duration(1) * time.Second)
-
-}
+ package scoringmgr_test
+
+ //$ touch resourceservice/resourceservice.c
+
+ import (
+ "context"
+ "fmt"
+ "log"
+ "net/http"
+ "testing"
+ "time"
+
+ "gopkg.in/sconf/ini.v0"
+ "gopkg.in/sconf/sconf.v0"
+
+ confdescription "configuremgr/description"
+ restapi "restapi/v1"
+ scoringmgr "scoringmgr"
+ mockscoringmgr "scoringmgr/mock"
+ )
+
+ func TestScoringMgrMyScoringLibRemoveApp(t *testing.T) {
+
+ //interface
+ iscoringmgr := scoringmgr.Init()
+ iscoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
+ iscoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
+ iscoringmgr.IStartResourceService = scoringmgr.StartResourceService
+ iscoringmgr.IStopResourceService = scoringmgr.StopResourceService
+ iscoringmgr.Ch = make(chan interface{}, 1024)
+
+ //start
+ iscoringmgr.Listening()
+ iscoringmgr.IStartResourceService()
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ //setting
+ libName := "myscoring"
+ libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
+ confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
+ cfg := new(confdescription.Doc)
+ sconf.Must(cfg).Read(ini.File(confPath))
+ log.Println(cfg)
+ scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
+
+ //working on
+ time.Sleep(time.Duration(3) * time.Second)
+ scoreValue, _ := iscoringmgr.IGetScore("mock", "mock")
+ log.Printf("scorevalue : %f\n", scoreValue)
+
+ //release
+ iscoringmgr.IStopResourceService()
+ iscoringmgr.RemoveApp(cfg.ServiceInfo.ServiceName)
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ }
+
+ func TestScoringMgrMyScoringLib(t *testing.T) {
+
+ //interface
+ iscoringmgr := scoringmgr.Init()
+ iscoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
+ iscoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock
+ iscoringmgr.IStartResourceService = scoringmgr.StartResourceService
+ iscoringmgr.IStopResourceService = scoringmgr.StopResourceService
+ iscoringmgr.Ch = make(chan interface{}, 1024)
+
+ //start
+ iscoringmgr.Listening()
+ iscoringmgr.IStartResourceService()
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ //setting
+ libName := "myscoring"
+ libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
+ confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
+ cfg := new(confdescription.Doc)
+ sconf.Must(cfg).Read(ini.File(confPath))
+ log.Println("[scoringmgr]", cfg)
+ scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
+
+ //working on
+ time.Sleep(time.Duration(3) * time.Second)
+ scoreValue, _ := iscoringmgr.IGetScore("mock", "mock")
+ log.Printf("[scoringmgr] scorevalue : %f\n", scoreValue)
+
+ //release
+ iscoringmgr.IStopResourceService()
+ iscoringmgr.RemoveAll()
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ }
+
+ func TestScoringMgrMyScoringLibGetScoreLocal(t *testing.T) {
+
+ //interface
+ iscoringmgr := scoringmgr.Init()
+ iscoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
+ iscoringmgr.IGetScore = scoringmgr.GetScore
+ iscoringmgr.IStartResourceService = scoringmgr.StartResourceService
+ iscoringmgr.IStopResourceService = scoringmgr.StopResourceService
+ iscoringmgr.Ch = make(chan interface{}, 1024)
+
+ //start
+ iscoringmgr.Listening()
+ iscoringmgr.IStartResourceService()
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ //setting
+ libName := "myscoring"
+ libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
+ confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
+ cfg := new(confdescription.Doc)
+ sconf.Must(cfg).Read(ini.File(confPath))
+ log.Println(cfg)
+ scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
+
+ //working on
+ time.Sleep(time.Duration(3) * time.Second)
+ scoreValue, _ := iscoringmgr.IGetScore("localhost", "myscoring")
+ log.Printf("scorevalue : %f\n", scoreValue)
+
+ //release
+ iscoringmgr.IStopResourceService()
+ iscoringmgr.RemoveAll()
+
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ }
+
+ func TestScoringMgrMyScoringLibGetScoreRemote(t *testing.T) {
+
+ //interface
+ iscoringmgr := scoringmgr.Init()
+ iscoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
+ iscoringmgr.IGetScore = scoringmgr.GetScore
+ iscoringmgr.IStartResourceService = scoringmgr.StartResourceService
+ iscoringmgr.IStopResourceService = scoringmgr.StopResourceService
+ iscoringmgr.Ch = make(chan interface{}, 1024)
+
+ //start
+ iscoringmgr.Listening()
+ iscoringmgr.IStartResourceService()
+ router := restapi.NewRouter()
+ server := &http.Server{Addr: fmt.Sprintf(":%d", 56001), Handler: router}
+ go server.ListenAndServe()
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+ //setting
+ libName := "myscoring"
+ libPath := fmt.Sprintf("mock/%s/lib%s.so", libName, libName)
+ confPath := fmt.Sprintf("mock/%s/%s.conf", libName, libName)
+ cfg := new(confdescription.Doc)
+ sconf.Must(cfg).Read(ini.File(confPath))
+ log.Println(cfg)
+ scoringmgr.PushLibPath(libPath, cfg, iscoringmgr.Ch)
+
+ //working on
+ time.Sleep(time.Duration(3) * time.Second)
+ scoreValue, _ := iscoringmgr.IGetScore("127.0.0.1", "myscoring")
+ log.Printf("scorevalue : %f\n", scoreValue)
+
+ //release
+ iscoringmgr.IStopResourceService()
+ iscoringmgr.RemoveAll()
+ if err := server.Shutdown(context.TODO()); err != nil {
+ panic(err)
+ }
+
+ time.Sleep(time.Duration(100) * time.Millisecond)
+
+}
\ No newline at end of file