package orchestrationapi //$ import ( "discoverymgr" "fmt" "os/exec" "testing" "time" configuremgr "configuremgr" confdescription "configuremgr/description" // mockconfiguremgr "configuremgr/mock" scoringmgr "scoringmgr" mockscoringmgr "scoringmgr/mock" // discoverymgr "discoverymgr" servicemgr "servicemgr" ) //jaehoon.hyun , jaehoon.hyun func TestConfigureMgrScoringMgr(t *testing.T) { //make orche orcheMock := Init("") //create modules orcheMock.IScoringmgr = scoringmgr.Init() orcheMock.IConfiguremgr = configuremgr.Init() //scoringmgr interface orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd orcheMock.IScoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd orcheMock.IScoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024) //configuremgr interface orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = PushConfPathDiscoveryDeviceMock orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch //discoverymgr interface orcheMock.IDiscoverymgr.GetEndpointDevices = GetEndpointDevicesMock //servicemgr interface orcheMock.IServicemgr.ExecuteApp = ExecuteAppMock //start scoringmgr orcheMock.IScoringmgr.Listening() orcheMock.IScoringmgr.IStartResourceService() //start configuremgr go orcheMock.IConfiguremgr.Watch("/tmp/foo") //init scenario execCommand("rm -rf /tmp/foo/mysum") time.Sleep(time.Duration(1) * time.Second) //user scenario execCommand(fmt.Sprintf("cp -arR %s %s", "./mock/mysum/", "/tmp/foo")) time.Sleep(time.Duration(3) * time.Second) //release scoringmgr orcheMock.IScoringmgr.IStopResourceService() orcheMock.IScoringmgr.RemoveLib("ls") //release configuremgr orcheMock.IConfiguremgr.Done <- true } func TestConfigureMgrScoringMgrMyScoringLib(t *testing.T) { //make orche orcheMock := new(Orche) //create modules orcheMock.IScoringmgr = scoringmgr.Init() orcheMock.IConfiguremgr = configuremgr.Init() //scoringmgr interface orcheMock.IScoringmgr.IRunningScore = scoringmgr.LoadScoringGeneralInterface orcheMock.IScoringmgr.IStartResourceService = scoringmgr.StartResourceService orcheMock.IScoringmgr.IStopResourceService = scoringmgr.StopResourceService orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024) //configuremgr interface orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = PushConfPathDiscoveryDeviceMock orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch //discoverymgr interface orcheMock.IDiscoverymgr.GetEndpointDevices = GetEndpointDevicesMock //servicemgr interface orcheMock.IServicemgr.ExecuteApp = ExecuteAppMock //start scoringmgr orcheMock.IScoringmgr.Listening() orcheMock.IScoringmgr.IStartResourceService() //start configuremgr go orcheMock.IConfiguremgr.Watch("/tmp/foo") //init scenario execCommand("rm -rf /tmp/foo/myscoring") time.Sleep(time.Duration(1) * time.Second) //user scenario execCommand(fmt.Sprintf("cp -arR %s %s", "./mock/myscoring/", "/tmp/foo")) time.Sleep(time.Duration(3) * time.Second) //release scoringmgr orcheMock.IScoringmgr.IStopResourceService() orcheMock.IScoringmgr.RemoveLib("ls") //release configuremgr orcheMock.IConfiguremgr.Done <- true } //jaehoon.hyun, damon92-lee func TestConfigureMgrDiscoveryMgr(t *testing.T) { orcheMock := Init("") orcheMock.IScoringmgr = scoringmgr.Init() orcheMock.IConfiguremgr = configuremgr.Init() orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd orcheMock.IScoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd orcheMock.IScoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock 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 = ExecuteAppMock discoverymgr.InitDiscovery() //scoringmgr init orcheMock.IScoringmgr.Listening() //configuremgr init go orcheMock.IConfiguremgr.Watch("/tmp/foo") //init scenario execCommand("rm -rf /tmp/foo/mysum") time.Sleep(time.Duration(1) * time.Second) //user scenario execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/mysum/", "/tmp/foo")) time.Sleep(time.Duration(3) * time.Second) RequestService("ls", []string{"-al"}) //resource release time.Sleep(time.Duration(1) * time.Second) orcheMock.IScoringmgr.RemoveLib("ls") orcheMock.IConfiguremgr.Done <- true discoverymgr.ExitChan <- 1 } //jaehoon.hyun, chacha func TestRequestServiceFunctionServiceMgr(t *testing.T) { orcheMock := Init("") orcheMock.IScoringmgr = scoringmgr.Init() orcheMock.IConfiguremgr = configuremgr.Init() orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd orcheMock.IScoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd orcheMock.IScoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024) orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = PushConfPathDiscoveryDeviceMock orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch orcheMock.IDiscoverymgr.GetEndpointDevices = GetEndpointDevicesMock orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp //scoringmgr init orcheMock.IScoringmgr.Listening() //configuremgr init go orcheMock.IConfiguremgr.Watch("/tmp/foo") //servicemgr init servicemgr.Init() //init scenario execCommand("rm -rf /tmp/foo/mysum") time.Sleep(time.Duration(1) * time.Second) //user scenario execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/mysum/", "/tmp/foo")) time.Sleep(time.Duration(3) * time.Second) RequestService("ls", []string{"-al"}) //resource release time.Sleep(time.Duration(1) * time.Second) orcheMock.IScoringmgr.RemoveLib("ls") orcheMock.IConfiguremgr.Done <- true } //daemon92-lee, chacha func testDiscoveryMgrServiceMgr(t *testing.T) { // @TODO } //jaehoon.hyun, daemon92-lee, jaehoon.hyun func TestConfigureMgrDiscoveryMgrScoringMgr(t *testing.T) { orcheMock := Init("") orcheMock.IScoringmgr = scoringmgr.Init() orcheMock.IConfiguremgr = configuremgr.Init() orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd orcheMock.IScoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd orcheMock.IScoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd 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 = ExecuteAppMock //scoringmgr init orcheMock.IScoringmgr.Listening() //configuremgr init go orcheMock.IConfiguremgr.Watch("/tmp/foo") //init scenario execCommand("rm -rf /tmp/foo/mysum") time.Sleep(time.Duration(1) * time.Second) discoverymgr.InitDiscovery() //user scenario execCommand(fmt.Sprintf("cp -ar %s %s", "../scoringmgr/mock/mysum/", "/tmp/foo")) time.Sleep(time.Duration(3) * time.Second) RequestService("ls", []string{"-al"}) //resource release time.Sleep(time.Duration(1) * time.Second) orcheMock.IScoringmgr.RemoveLib("ls") orcheMock.IConfiguremgr.Done <- true discoverymgr.ExitChan <- 1 } //jaehoon.hyun, daemon92-lee, chacha func TestConfigureMgrDiscoveryMgrServiceMgr(t *testing.T) { orcheMock := Init("") orcheMock.IScoringmgr = scoringmgr.Init() orcheMock.IConfiguremgr = configuremgr.Init() orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd orcheMock.IScoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd orcheMock.IScoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd orcheMock.IScoringmgr.IGetScore = mockscoringmgr.GetScoreRandom100Mock 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 discoverymgr.InitDiscovery() servicemgr.Init() //scoringmgr init orcheMock.IScoringmgr.Listening() //init scenario execCommand("rm -rf /tmp/foo/mysum") time.Sleep(time.Duration(1) * time.Second) //configuremgr init go orcheMock.IConfiguremgr.Watch("/tmp/foo") //user scenario execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/mysum/", "/tmp/foo")) time.Sleep(time.Duration(3) * time.Second) RequestService("ls", []string{"-al"}) //resource release time.Sleep(time.Duration(1) * time.Second) orcheMock.IScoringmgr.RemoveLib("ls") orcheMock.IConfiguremgr.Done <- true discoverymgr.ExitChan <- 1 } //jaehoon.hyun, chacha, jaehoon.hyun func TestConfigureMgrServiceMgrScoringMgr(t *testing.T) { orcheMock := Init("") orcheMock.IScoringmgr = scoringmgr.Init() orcheMock.IConfiguremgr = configuremgr.Init() orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd orcheMock.IScoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd orcheMock.IScoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd orcheMock.IScoringmgr.IGetScore = scoringmgr.GetScore orcheMock.IScoringmgr.Ch = make(chan interface{}, 1024) orcheMock.IConfiguremgr.IDiscoveryMgr.PushConfPath = PushConfPathDiscoveryDeviceMock orcheMock.IConfiguremgr.IScoringMgr.PushLibPath = scoringmgr.PushLibPath orcheMock.IConfiguremgr.IScoringMgr.Ch = orcheMock.IScoringmgr.Ch orcheMock.IDiscoverymgr.GetEndpointDevices = GetEndpointDevicesMock orcheMock.IServicemgr.ExecuteApp = servicemgr.ExecuteApp //scoringmgr init orcheMock.IScoringmgr.Listening() //configuremgr init go orcheMock.IConfiguremgr.Watch("/tmp/foo") //init scenario execCommand("rm -rf /tmp/foo/mysum") time.Sleep(time.Duration(1) * time.Second) servicemgr.Init() //user scenario execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/mysum/", "/tmp/foo")) time.Sleep(time.Duration(3) * time.Second) RequestService("ls", []string{"-al"}) //resource release time.Sleep(time.Duration(1) * time.Second) orcheMock.IScoringmgr.RemoveLib("ls") orcheMock.IConfiguremgr.Done <- true } //jaehoon.hyun, daemon92-lee, chacha, jaehoon.hyun func TestConfigureMgrDiscoveryMgrScoringMgrServiceMgr(t *testing.T) { orcheMock := Init("") orcheMock.IScoringmgr = scoringmgr.Init() orcheMock.IConfiguremgr = configuremgr.Init() orcheMock.IScoringmgr.IRunningScore = mockscoringmgr.LoadScoringInterfaceAdd orcheMock.IScoringmgr.IStartResourceService = mockscoringmgr.StartResourceServiceAdd orcheMock.IScoringmgr.IStopResourceService = mockscoringmgr.StopResourceServiceAdd 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 //scoringmgr init orcheMock.IScoringmgr.Listening() //configuremgr init go orcheMock.IConfiguremgr.Watch("/tmp/foo") //init scenario execCommand("rm -rf /tmp/foo/mysum") time.Sleep(time.Duration(1) * time.Second) discoverymgr.InitDiscovery() servicemgr.Init() //user scenario execCommand(fmt.Sprintf("cp -ar %s %s", "./mock/mysum/", "/tmp/foo")) time.Sleep(time.Duration(3) * time.Second) RequestService("ls", []string{"-al"}) //resource release time.Sleep(time.Duration(1) * time.Second) orcheMock.IScoringmgr.RemoveLib("ls") orcheMock.IConfiguremgr.Done <- true discoverymgr.ExitChan <- 1 } func PushConfPathDiscoveryDeviceMock(doc *confdescription.Doc) (err error) { ILog.Println("pushConfPathDiscoveryDeviceMock") ILog.Println(*doc) return } func PushLibPathScoringAppMock(libPath string, doc *confdescription.Doc, handlersCh chan<- interface{}) (err error) { ILog.Println("pushLibPathScoringAppMock") ILog.Println(libPath) return } func GetEndpointDevicesMock(serviceName string) ([]string, error) { DLog.Printf("GetEndpointDevicesMock serviceName: %s\n", serviceName) return []string{"localhost"}, nil } func ExecuteAppMock(target string, name string, args []string, notiChan chan string) (serviceID uint64, err error) { ILog.Println("ExecuteApp") ILog.Println(target) ILog.Println(name) ILog.Println(args) return } func execCommand(command string) { configuremgr.DLog.Println(command) cmd := exec.Command("sh", "-c", command) stdoutStderr, err := cmd.CombinedOutput() configuremgr.DLog.Printf("%s", stdoutStderr) if err != nil { configuremgr.ELog.Fatal(err) } }