pcm-participant/ai/service/algorithm_test.go

147 lines
3.8 KiB
Go

package service
import (
"context"
"fmt"
"github.com/smartystreets/goconvey/convey"
"gitlink.org.cn/JointCloud/jcs/storagekit/types"
"gitlink.org.cn/JointCloud/pcm-participant-ai/algorithm"
aicom "gitlink.org.cn/JointCloud/pcm-participant-ai/common"
aiconf "gitlink.org.cn/JointCloud/pcm-participant-ai/config"
"gitlink.org.cn/JointCloud/pcm-participant-ai/platform"
"gitlink.org.cn/JointCloud/pcm-participant-octopus"
openI "gitlink.org.cn/JointCloud/pcm-participant-openi"
"gitlink.org.cn/JointCloud/pcm-participant-openi/common"
"testing"
"time"
)
func TestGet(t *testing.T) {
convey.Convey(aiconf.Octopus, t, func() {
o, err := octopus.New(aiconf.Cfg[aiconf.Octopus].URL, aiconf.Cfg[aiconf.Octopus].Username, aiconf.Cfg[aiconf.Octopus].Password, aiconf.Octopus, platform.Id(123))
if err != nil {
fmt.Println(err)
return
}
alg := NewAlgorithm(o.Alg)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
convey.Convey("Train", func() {
result, _ := alg.All(ctx, nil)
alg, err := result.Algorithms()
if err != nil {
fmt.Println(err.Error())
}
convey.So(err, convey.ShouldBeNil)
convey.So(alg, convey.ShouldNotBeEmpty)
})
})
convey.Convey(aiconf.OpenI, t, func() {
o, _ := openI.New(aiconf.Cfg[aiconf.OpenI].Username, aiconf.Cfg[aiconf.OpenI].Password, aiconf.Cfg[aiconf.OpenI].APIKey, aiconf.OpenI, platform.Id(123), aiconf.Cfg[aiconf.OpenI].DataRepo)
common.InitClient()
alg := NewAlgorithm(o.Alg)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
convey.Convey("All", func() {
f := algorithm.NewFilter().SetName("pytorch-cnn-cifar10-dcu")
result, _ := alg.All(ctx, f)
alg, err := result.Algorithms()
if err != nil {
fmt.Println(err.Error())
}
convey.So(err, convey.ShouldBeNil)
convey.So(alg, convey.ShouldHaveLength, 1)
})
convey.Convey("Train", func() {
result, _ := alg.All(ctx, nil)
alg, err := result.Algorithms()
if err != nil {
fmt.Println(err.Error())
}
convey.So(err, convey.ShouldBeNil)
convey.So(alg, convey.ShouldNotBeEmpty)
})
convey.Convey("Train Params Find spec with CodeRepository", func() {
result, err := alg.TrainParam(ctx, &AlgorithmParam{Name: "pytorch-cnn-cifar10-dcu"})
if err != nil {
fmt.Println(err.Error())
}
convey.So(err, convey.ShouldBeNil)
convey.So(result, convey.ShouldNotBeNil)
res, ok := result.(*algorithm.CodeRepository)
convey.So(ok, convey.ShouldBeTrue)
convey.So(res, convey.ShouldNotBeNil)
})
})
}
func TestCreate(t *testing.T) {
convey.Convey("Create Algorithm", t, func() {
//o, _ := openI.New("nudt-ysz", "", "8cff1d2db9171462c02901d086d13221389fd082", platform.Id(123), "data")
//common.InitClient()
oct, _ := octopus.New(aiconf.Cfg[aiconf.Octopus].URL, aiconf.Cfg[aiconf.Octopus].Username, aiconf.Cfg[aiconf.Octopus].Password, aiconf.Octopus, platform.Id(123))
alg := NewAlgorithm(oct.Alg)
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second)
defer cancel()
var (
name = "test123456"
desc = "test123456"
)
src := &aicom.Source{
Jcs: &types.JcsBase{
UserID: 1,
PackageId: 1089,
},
}
convey.Convey("OpenI", func() {
op := &algorithm.OpenI{
BootFile: "123.txt",
DefaultBranch: "master",
}
param := &algorithm.CreateParam{
Name: name,
Desc: desc,
Src: src,
Param: op,
}
_, err := alg.Create(ctx, param)
if err != nil {
fmt.Println(err.Error())
}
convey.So(err, convey.ShouldBeNil)
})
convey.Convey("octopus", func() {
param := &algorithm.CreateParam{
Name: name,
Desc: desc,
Src: src,
}
_, err := alg.Create(ctx, param)
if err != nil {
fmt.Println(err.Error())
}
convey.So(err, convey.ShouldBeNil)
})
})
}