orchestrationapi/.go : discovery transcation logic add 77/204377/1
authorjaehoon.hyun <jaehoon.hyun@samsung.com>
Tue, 23 Apr 2019 10:07:25 +0000 (19:07 +0900)
committerjaehoon.hyun <jaehoon.hyun@samsung.com>
Tue, 23 Apr 2019 10:07:25 +0000 (19:07 +0900)
init thread and requestService test
discovery in wifi fail over test

Change-Id: If3038299461d65e2517956b5e105a11a596596e4

src/orchestrationapi/orchestration_api_test.go
src/orchestrationapi/orchstration_api.go

index 42892a9..e8fbbb8 100755 (executable)
@@ -25,14 +25,17 @@ import (
 
        configuremgr "configuremgr"
        confdescription "configuremgr/description"
+
        // mockconfiguremgr "configuremgr/mock"
-       scoringmgr       "scoringmgr"
-       mockscoringmgr   "scoringmgr/mock"
-       discoverymgr     "discoverymgr"
-       securemgr        "securemgr"
-       servicemgr       "servicemgr"
+       discoverymgr "discoverymgr"
+       scoringmgr "scoringmgr"
+       mockscoringmgr "scoringmgr/mock"
+       securemgr "securemgr"
+       servicemgr "servicemgr"
 )
 
+var logPrefixTest = "[orchestrationapi test]"
+
 //jaehoon.hyun , jaehoon.hyun
 func TestConfigureMgrScoringMgrAlreadyScoring2Library(t *testing.T) {
 
@@ -362,9 +365,12 @@ func TestConfigureMgrDiscoveryMgr(t *testing.T) {
 
        //release discoverymgr
        discoverymgr.ExitChan <- 1
+       if discoverymgr.IsNilServer() == true {
+               discoverymgr.ExitPollingOutBoundCh <- 1
+       }
 
        //waiting resource thread stop
-       time.Sleep(time.Duration(100) * time.Millisecond)
+       time.Sleep(time.Duration(1000) * time.Millisecond)
 }
 
 //jaehoon.hyun, chacha
@@ -417,7 +423,7 @@ func TestRequestServiceFunctionServiceMgr(t *testing.T) {
        orcheMock.IConfiguremgr.Done <- true
 
        //waiting resource thread stop
-       time.Sleep(time.Duration(100) * time.Millisecond)
+       time.Sleep(time.Duration(1000) * time.Millisecond)
 }
 
 //daemon92-lee, chacha
@@ -479,6 +485,9 @@ func TestConfigureMgrDiscoveryMgrScoringMgr(t *testing.T) {
 
        //release discoverymgr
        discoverymgr.ExitChan <- 1
+       if discoverymgr.IsNilServer() == true {
+               discoverymgr.ExitPollingOutBoundCh <- 1
+       }
 
        //waiting resource thread stop
        time.Sleep(time.Duration(100) * time.Millisecond)
@@ -538,6 +547,9 @@ func TestConfigureMgrDiscoveryMgrServiceMgr(t *testing.T) {
 
        //release discoverymgr
        discoverymgr.ExitChan <- 1
+       if discoverymgr.IsNilServer() == true {
+               discoverymgr.ExitPollingOutBoundCh <- 1
+       }
 
        //waiting resource thread stop
        time.Sleep(time.Duration(100) * time.Millisecond)
@@ -593,7 +605,96 @@ func TestConfigureMgrDiscoveryMgrScoringMgrServiceMgr(t *testing.T) {
        time.Sleep(time.Duration(100) * time.Millisecond)
 
        //release scoringmgr
-       orcheMock.IScoringmgr.IStartResourceService()
+       orcheMock.IScoringmgr.IStopResourceService()
+       orcheMock.IScoringmgr.RemoveAll()
+
+       //release configuremgr
+       orcheMock.IConfiguremgr.Done <- true
+
+       //release discoverymgr
+       discoverymgr.ExitChan <- 1
+       if discoverymgr.IsNilServer() == true {
+               discoverymgr.ExitPollingOutBoundCh <- 1
+       }
+
+       time.Sleep(time.Duration(100) * time.Millisecond)
+}
+
+//jaehoon.hyun, daemon92-lee, chacha, jaehoon.hyun
+func TestOrchestrationInitThreadAndRequestServiceThread(t *testing.T) {
+
+       orcheMock := Init("")
+       ExitTestChan := make(chan int, 2)
+
+       go func() {
+               //init scenario
+               listeningDir := "/tmp/foo"
+               execCommand(fmt.Sprintf("rm -rf %s", listeningDir))
+               execCommand(fmt.Sprintf("mkdir -p %s", listeningDir))
+               time.Sleep(time.Duration(100) * time.Millisecond)
+
+               orcheMock.IScoringmgr = scoringmgr.Init()
+               orcheMock.IConfiguremgr = configuremgr.Init()
+
+               orcheMock.IScoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface
+               orcheMock.IScoringmgr.IStartResourceService = scoringmgr.StartResourceService
+               orcheMock.IScoringmgr.IStopResourceService = scoringmgr.StopResourceService
+               orcheMock.IScoringmgr.IGetScore = scoringmgr.GetScore
+               orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024)
+
+               orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = discoverymgr.AddNewServiceName
+               orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath
+               orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch
+
+               orcheMock.IDiscoverymgr.GetEndpointDevices = discoverymgr.GetDeviceListWithService
+               orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp
+
+               //1.scoringmgr init
+               orcheMock.IScoringmgr.Listening()
+               orcheMock.IScoringmgr.IStartResourceService()
+
+               //2.configuremgr init
+               go orcheMock.IConfiguremgr.Watch(listeningDir)
+
+               //3.securemgr init
+               securemgr.Init("../securemgr/test/key.txt")
+
+               //4.servicemgr init
+               servicemgr.Init()
+
+               //5.discoverymgr init
+               discoverymgr.InitDiscovery()
+               discoverymgr.GetDeviceList()
+
+               orcheMock.Ready = true
+
+               //user scenario
+               execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/myscoring/", listeningDir))
+               time.Sleep(time.Duration(100) * time.Millisecond)
+
+               log.Println(logPrefixTest, "orchestration init done")
+
+               ExitTestChan <- 1
+
+       }()
+
+       go func() {
+               ret := RequestService("ls", []string{"-al"})
+               if ret != -1 {
+                       t.Fatal("is it wifi on????? plz off and retry test")
+               } else {
+                       log.Println(logPrefixTest, "REEEEEEEEETTTTTTTTT == -1")
+               }
+               time.Sleep(time.Duration(100) * time.Millisecond)
+
+               ExitTestChan <- 1
+       }()
+
+       <-ExitTestChan
+       <-ExitTestChan
+
+       //release scoringmgr
+       orcheMock.IScoringmgr.IStopResourceService()
        orcheMock.IScoringmgr.RemoveAll()
 
        //release configuremgr
@@ -601,6 +702,9 @@ func TestConfigureMgrDiscoveryMgrScoringMgrServiceMgr(t *testing.T) {
 
        //release discoverymgr
        discoverymgr.ExitChan <- 1
+       if discoverymgr.IsNilServer() == true {
+               discoverymgr.ExitPollingOutBoundCh <- 1
+       }
 
        time.Sleep(time.Duration(100) * time.Millisecond)
 }
index 8562d76..8339db7 100755 (executable)
@@ -31,6 +31,7 @@ import (
 )
 
 type Orche struct {
+       Ready         bool
        IScoringmgr   *scoringmgr.Handlers
        IConfiguremgr *configuremgr.ConfigureMgr
 
@@ -62,9 +63,19 @@ var (
        orcheClients = [1024]orcheClient{}
 )
 
+type OrchestrationError int
+
+const (
+       eNotReadyOrchestrationError = ((1 + iota) ^ -1) + 1
+       eTurnOffWifiOrchestrationError
+)
+
+// func (orcheError OrchestrationError) toError() int { return }
+
 func Init(settingPath string) *Orche {
 
        orcheEngine = new(Orche)
+       orcheEngine.Ready = false
 
        return orcheEngine
 
@@ -72,12 +83,19 @@ func Init(settingPath string) *Orche {
 
 func RequestService(appName string, args []string) (handle int) {
 
+       if orcheEngine.Ready == false {
+               return eNotReadyOrchestrationError
+       }
+
        clientID := atomic.LoadInt32(&orchClientID)
        atomic.AddInt32(&orchClientID, 1)
 
        serviceClient := addServiceClient(clientID, appName, args)
        go serviceClient.listenNotify()
-       endpoints := getEndpointDevices(appName)
+       endpoints, err := getEndpointDevices(appName)
+       if err != nil {
+               return eTurnOffWifiOrchestrationError
+       }
        deviceScores := sortByScore(gatheringDevicesScore(endpoints, appName))
 
        if len(deviceScores) > 0 {
@@ -107,9 +125,8 @@ func addServiceClient(clientID int32, appName string, args []string) (client *or
        return
 }
 
-func getEndpointDevices(appName string) (deviceList []string) {
-       deviceList, _ = orcheEngine.IDiscoverymgr.GetEndpointDevices(appName)
-       return
+func getEndpointDevices(appName string) (deviceList []string, err error) {
+       return orcheEngine.IDiscoverymgr.GetEndpointDevices(appName)
 }
 
 func gatheringDevicesScore(endpoints []string, appName string) (deviceScores []deviceScore) {