daria-malkova commented on a change in pull request #16891:
URL: https://github.com/apache/beam/pull/16891#discussion_r814650097



##########
File path: playground/backend/internal/code_processing/code_processing_test.go
##########
@@ -61,16 +68,26 @@ func TestMain(m *testing.M) {
 
 func setup() {
        // create configs for java
-       err := os.MkdirAll("configs", fs.ModePerm)
+       err := os.MkdirAll(configFolder, fs.ModePerm)
        if err != nil {
                panic(err)
        }
-       filePath := filepath.Join("configs", pb.Sdk_SDK_JAVA.String()+".json")
+       filePath := filepath.Join(configFolder, 
pb.Sdk_SDK_JAVA.String()+".json")

Review comment:
       ".json" -> constant

##########
File path: playground/backend/internal/code_processing/code_processing_test.go
##########
@@ -962,36 +1096,78 @@ func Test_runStep(t *testing.T) {
                pipelineOptions      string
                pipelineLifeCycleCtx context.Context
                cancelChannel        chan bool
+               createExecFile       bool
        }
        tests := []struct {
-               name string
-               args args
-               code string
+               name           string
+               args           args
+               code           string
+               expectedStatus pb.Status
        }{
                {
-                       name: "Test run step working without an error",
+                       name: "Test run step working on python sdk",

Review comment:
       ditto

##########
File path: playground/backend/internal/code_processing/code_processing_test.go
##########
@@ -908,51 +1009,84 @@ func Test_compileStep(t *testing.T) {
                cancelChannel        chan bool
        }
        tests := []struct {
-               name string
-               args args
-               want *executors.Executor
-               code string
+               name           string
+               args           args
+               code           string
+               expectedStatus pb.Status
        }{
                {
-                       name: "Test compilation step working without an error",
+                       name: "Test compilation step working on java sdk",

Review comment:
       working -> finishes successfully

##########
File path: playground/backend/internal/code_processing/code_processing_test.go
##########
@@ -1004,3 +1180,354 @@ func syncMapLen(syncMap *sync.Map) int {
        })
        return length
 }
+
+func TestGetGraph(t *testing.T) {
+       ctx := context.Background()
+       pipelineId1 := uuid.New()
+       graph := "GRAPH"
+       err := cacheService.SetValue(ctx, pipelineId1, cache.Graph, graph)
+       if err != nil {
+               return
+       }
+       pipelineId2 := uuid.New()
+       err = cacheService.SetValue(ctx, pipelineId2, cache.Graph, 1)
+       if err != nil {
+               return
+       }
+       type args struct {
+               ctx          context.Context
+               cacheService cache.Cache
+               key          uuid.UUID
+               errorTitle   string
+       }
+       tests := []struct {
+               name    string
+               args    args
+               want    string
+               wantErr bool
+       }{
+               {
+                       name: "Get graph when key exist in cache",
+                       args: args{
+                               ctx:          context.Background(),
+                               cacheService: cacheService,
+                               key:          pipelineId1,
+                               errorTitle:   "error",
+                       },
+                       want:    graph,
+                       wantErr: false,
+               },
+               {
+                       name: "Get graph when key doesn't exist in cache",
+                       args: args{
+                               ctx:          context.Background(),
+                               cacheService: cacheService,
+                               key:          uuid.New(),
+                               errorTitle:   "error",
+                       },
+                       want:    "",
+                       wantErr: true,
+               },
+               {
+                       name: "Get graph when value from cache by key couldn't 
be converted to a string",
+                       args: args{
+                               ctx:          context.Background(),
+                               cacheService: cacheService,
+                               key:          pipelineId2,
+                               errorTitle:   "error",
+                       },
+                       want:    "",
+                       wantErr: true,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       got, err := GetGraph(tt.args.ctx, tt.args.cacheService, 
tt.args.key, tt.args.errorTitle)
+                       if (err != nil) != tt.wantErr {
+                               t.Errorf("GetGraph error = %v, wantErr %v", 
err, tt.wantErr)
+                               return
+                       }
+                       if got != tt.want {
+                               t.Errorf("GetGraph got = %v, want %v", got, 
tt.want)
+                       }
+               })
+       }
+}
+
+func Test_processSetupError(t *testing.T) {
+       client, mock := redismock.NewClientMock()
+       pipelineId := uuid.New()
+       errorMessage := "MOCK_ERROR"
+       type args struct {
+               err            error
+               pipelineId     uuid.UUID
+               cacheService   cache.Cache
+               ctxWithTimeout context.Context
+       }
+       tests := []struct {
+               name    string
+               mocks   func()
+               args    args
+               wantErr bool
+       }{
+               {
+                       name: "Error during HSet operation",
+                       mocks: func() {
+                               mock.ExpectHSet(pipelineId.String(), 
"MOCK_VALUE").SetErr(fmt.Errorf(errorMessage))
+                       },
+                       args: args{
+                               err:        fmt.Errorf(errorMessage),
+                               pipelineId: pipelineId,
+                               cacheService: &redis.Cache{
+                                       Client: client,
+                               },
+                               ctxWithTimeout: nil,
+                       },
+                       wantErr: true,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       tt.mocks()
+                       if err := processSetupError(tt.args.err, 
tt.args.pipelineId, tt.args.cacheService, tt.args.ctxWithTimeout); (err != nil) 
!= tt.wantErr {
+                               t.Errorf("processSetupError() error = %v, 
wantErr %v", err, tt.wantErr)
+                       }
+               })
+       }
+}
+
+func Test_processErrorWithSavingOutput(t *testing.T) {
+       client, mock := redismock.NewClientMock()
+       pipelineId := uuid.New()
+       errorMessage := "MOCK_ERROR"
+       subKey := cache.RunOutput
+       type args struct {
+               ctx          context.Context
+               err          error
+               errorOutput  []byte
+               pipelineId   uuid.UUID
+               subKey       cache.SubKey
+               cacheService cache.Cache
+               errorTitle   string
+               newStatus    pb.Status
+       }
+       tests := []struct {
+               name    string
+               mocks   func()
+               args    args
+               wantErr bool
+       }{
+               {
+                       name: "Error during HSet operation",
+                       mocks: func() {
+                               mock.ExpectHSet(pipelineId.String(), 
subKey).SetErr(fmt.Errorf(errorMessage))
+                       },
+                       args: args{
+                               ctx:          context.Background(),
+                               err:          fmt.Errorf(errorMessage),
+                               errorOutput:  nil,
+                               pipelineId:   pipelineId,
+                               subKey:       subKey,
+                               cacheService: &redis.Cache{Client: client},
+                               errorTitle:   "",
+                               newStatus:    0,
+                       },
+                       wantErr: true,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       tt.mocks()
+                       if err := processErrorWithSavingOutput(tt.args.ctx, 
tt.args.err, tt.args.errorOutput, tt.args.pipelineId, tt.args.subKey, 
tt.args.cacheService, tt.args.errorTitle, tt.args.newStatus); (err != nil) != 
tt.wantErr {
+                               t.Errorf("processErrorWithSavingOutput() error 
= %v, wantErr %v", err, tt.wantErr)
+                       }
+               })
+       }
+}
+
+func Test_processRunError(t *testing.T) {
+       client, mock := redismock.NewClientMock()
+       pipelineId := uuid.New()
+       errorMessage := "MOCK_ERROR"
+       subKey := cache.RunError
+       errorChannel := make(chan error, 1)
+       errorChannel <- fmt.Errorf(errorMessage)
+       type args struct {
+               ctx                   context.Context
+               errorChannel          chan error
+               errorOutput           []byte
+               pipelineId            uuid.UUID
+               cacheService          cache.Cache
+               stopReadLogsChannel   chan bool
+               finishReadLogsChannel chan bool
+       }
+       tests := []struct {
+               name    string
+               mocks   func()
+               args    args
+               wantErr bool
+       }{
+               {
+                       name: "Error during HSet operation",
+                       mocks: func() {
+                               mock.ExpectHSet(pipelineId.String(), 
subKey).SetErr(fmt.Errorf(errorMessage))
+                       },
+                       args: args{
+                               ctx:                   context.Background(),
+                               errorChannel:          errorChannel,
+                               errorOutput:           nil,
+                               pipelineId:            pipelineId,
+                               cacheService:          &redis.Cache{Client: 
client},
+                               stopReadLogsChannel:   nil,
+                               finishReadLogsChannel: nil,
+                       },
+                       wantErr: true,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       tt.mocks()
+                       if err := processRunError(tt.args.ctx, 
tt.args.errorChannel, tt.args.errorOutput, tt.args.pipelineId, 
tt.args.cacheService, tt.args.stopReadLogsChannel, 
tt.args.finishReadLogsChannel); (err != nil) != tt.wantErr {
+                               t.Errorf("processRunError() error = %v, wantErr 
%v", err, tt.wantErr)
+                       }
+               })
+       }
+}
+
+func Test_processCompileSuccess(t *testing.T) {
+       client, mock := redismock.NewClientMock()
+       pipelineId := uuid.New()
+       output := "output"
+       cacheMock := &redis.Cache{Client: client}
+       marshalLogs, _ := json.Marshal(cache.Logs)
+       marshalCompileOutput, _ := json.Marshal(cache.CompileOutput)
+       marshalRunOutput, _ := json.Marshal(cache.RunOutput)
+       marshalRunError, _ := json.Marshal(cache.RunError)
+       outputMarshal, _ := json.Marshal(output)
+       marshalEmptyString, _ := json.Marshal("")
+       type args struct {
+               ctx          context.Context
+               output       []byte
+               pipelineId   uuid.UUID
+               cacheService cache.Cache
+       }
+       tests := []struct {
+               name    string
+               mocks   func()
+               args    args
+               wantErr bool
+       }{
+               {
+                       name: "Error during set value to CompileOutput subKey",
+                       mocks: func() {
+                       },
+                       args: args{
+                               ctx:          context.Background(),
+                               output:       []byte(output),
+                               pipelineId:   pipelineId,
+                               cacheService: cacheMock,
+                       },
+                       wantErr: true,
+               },
+               {
+                       name: "Error during set value to RunOutput subKey",
+                       mocks: func() {
+                               mock.ExpectHSet(pipelineId.String(), 
marshalCompileOutput, outputMarshal).SetVal(1)
+                       },
+                       args: args{
+                               ctx:          context.Background(),
+                               output:       []byte(output),
+                               pipelineId:   pipelineId,
+                               cacheService: cacheMock,
+                       },
+                       wantErr: true,
+               },
+               {
+                       name: "Error during set value to RunError subKey",
+                       mocks: func() {
+                               mock.ExpectHSet(pipelineId.String(), 
marshalCompileOutput, outputMarshal).SetVal(1)
+                               mock.ExpectHSet(pipelineId.String(), 
marshalRunOutput, marshalEmptyString).SetVal(1)
+                       },
+                       args: args{
+                               ctx:          context.Background(),
+                               output:       []byte(output),
+                               pipelineId:   pipelineId,
+                               cacheService: cacheMock,
+                       },
+                       wantErr: true,
+               },
+               {
+                       name: "Error during set value to Logs subKey",
+                       mocks: func() {
+                               mock.ExpectHSet(pipelineId.String(), 
marshalCompileOutput, outputMarshal).SetVal(1)
+                               mock.ExpectHSet(pipelineId.String(), 
marshalRunOutput, marshalEmptyString).SetVal(1)
+                               mock.ExpectHSet(pipelineId.String(), 
marshalRunError, marshalEmptyString).SetVal(1)
+                       },
+                       args: args{
+                               ctx:          context.Background(),
+                               output:       []byte(output),
+                               pipelineId:   pipelineId,
+                               cacheService: cacheMock,
+                       },
+                       wantErr: true,
+               },
+               {
+                       name: "Error during set value to Graph subKey",
+                       mocks: func() {
+                               mock.ExpectHSet(pipelineId.String(), 
marshalCompileOutput, outputMarshal).SetVal(1)
+                               mock.ExpectHSet(pipelineId.String(), 
marshalRunOutput, marshalEmptyString).SetVal(1)
+                               mock.ExpectHSet(pipelineId.String(), 
marshalRunError, marshalEmptyString).SetVal(1)
+                               mock.ExpectHSet(pipelineId.String(), 
marshalLogs, marshalEmptyString).SetVal(1)
+                       },
+                       args: args{
+                               ctx:          context.Background(),
+                               output:       []byte(output),
+                               pipelineId:   pipelineId,
+                               cacheService: cacheMock,
+                       },
+                       wantErr: true,
+               },
+       }
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       tt.mocks()
+                       if err := processCompileSuccess(tt.args.ctx, 
tt.args.output, tt.args.pipelineId, tt.args.cacheService); (err != nil) != 
tt.wantErr {
+                               t.Errorf("processCompileSuccess() error = %v, 
wantErr %v", err, tt.wantErr)
+                       }
+               })
+       }
+}
+
+func Test_readGraphFile(t *testing.T) {
+       pipelineLifeCycleCtx, _ := context.WithTimeout(context.Background(), 
1*time.Second)
+       type args struct {
+               pipelineLifeCycleCtx context.Context
+               backgroundCtx        context.Context
+               cacheService         cache.Cache
+               graphFilePath        string
+               pipelineId           uuid.UUID
+       }
+       tests := []struct {
+               name string
+               args args
+       }{
+               {
+                       name: "All success",

Review comment:
       Let's have more descriptive name 

##########
File path: playground/backend/internal/code_processing/code_processing_test.go
##########
@@ -212,26 +234,45 @@ func Test_Process(t *testing.T) {
                        args: args{
                                ctx:             context.Background(),
                                appEnv:          appEnvs,
-                               sdkEnv:          sdkEnv,
+                               sdkEnv:          sdkJavaEnv,
                                pipelineId:      uuid.New(),
                                pipelineOptions: "",
                        },
                },
                {
                        // Test case with calling processCode without any error 
cases.
                        // As a result status into cache should be set as 
Status_STATUS_FINISHED.
-                       name:                  "processing complete 
successfully",
+                       name:                  "Processing complete 
successfully on java sdk",
                        createExecFile:        true,
                        cancelFunc:            false,
-                       code:                  "class HelloWorld {\n    public 
static void main(String[] args) {\n        System.out.println(\"Hello 
world!\");\n    }\n}",
+                       code:                  helloWordJava,
                        expectedStatus:        pb.Status_STATUS_FINISHED,
                        expectedCompileOutput: "",
                        expectedRunOutput:     "Hello world!\n",
                        expectedRunError:      "",
                        args: args{
                                ctx:             context.Background(),
                                appEnv:          appEnvs,
-                               sdkEnv:          sdkEnv,
+                               sdkEnv:          sdkJavaEnv,
+                               pipelineId:      uuid.New(),
+                               pipelineOptions: "",
+                       },
+               },
+               {
+                       // Test case with calling processCode method with 
incorrect go code.
+                       // As a result status into cache should be set as 
Status_STATUS_PREPARATION_ERROR.
+                       name:                  "Prepare step failed",
+                       createExecFile:        true,
+                       code:                  "package main\nimport 
\"fmt\"\nfunc main() {\n    fmt.Println(\"hello world\").\n}\n",

Review comment:
       code -> constant

##########
File path: playground/backend/internal/code_processing/code_processing_test.go
##########
@@ -962,36 +1096,78 @@ func Test_runStep(t *testing.T) {
                pipelineOptions      string
                pipelineLifeCycleCtx context.Context
                cancelChannel        chan bool
+               createExecFile       bool
        }
        tests := []struct {
-               name string
-               args args
-               code string
+               name           string
+               args           args
+               code           string
+               expectedStatus pb.Status
        }{
                {
-                       name: "Test run step working without an error",
+                       name: "Test run step working on python sdk",
                        args: args{
                                ctx:                  context.Background(),
                                cacheService:         cacheService,
-                               pipelineId:           uuid.UUID{},
+                               pipelineId:           uuid.New(),
                                isUnitTest:           false,
-                               sdkEnv:               sdkEnv,
+                               sdkEnv:               sdkPythonEnv,
+                               pipelineOptions:      "",
+                               pipelineLifeCycleCtx: context.Background(),
+                               cancelChannel:        make(chan bool, 1),
+                               createExecFile:       true,
+                       },
+                       code:           helloWordPython,
+                       expectedStatus: pb.Status_STATUS_RUN_ERROR,
+               },
+               {
+                       name: "Test run step working on go sdk",
+                       args: args{
+                               ctx:                  context.Background(),
+                               cacheService:         cacheService,
+                               pipelineId:           uuid.New(),
+                               isUnitTest:           true,
+                               sdkEnv:               sdkGoEnv,
+                               pipelineOptions:      "",
+                               pipelineLifeCycleCtx: context.Background(),
+                               cancelChannel:        make(chan bool, 1),
+                               createExecFile:       true,
+                       },
+                       code:           helloWordGo,
+                       expectedStatus: pb.Status_STATUS_RUN_ERROR,
+               },
+               {
+                       name: "Test run step without preparing files with code",

Review comment:
       success or fail?

##########
File path: playground/backend/internal/code_processing/code_processing_test.go
##########
@@ -962,36 +1096,78 @@ func Test_runStep(t *testing.T) {
                pipelineOptions      string
                pipelineLifeCycleCtx context.Context
                cancelChannel        chan bool
+               createExecFile       bool
        }
        tests := []struct {
-               name string
-               args args
-               code string
+               name           string
+               args           args
+               code           string
+               expectedStatus pb.Status
        }{
                {
-                       name: "Test run step working without an error",
+                       name: "Test run step working on python sdk",
                        args: args{
                                ctx:                  context.Background(),
                                cacheService:         cacheService,
-                               pipelineId:           uuid.UUID{},
+                               pipelineId:           uuid.New(),
                                isUnitTest:           false,
-                               sdkEnv:               sdkEnv,
+                               sdkEnv:               sdkPythonEnv,
+                               pipelineOptions:      "",
+                               pipelineLifeCycleCtx: context.Background(),
+                               cancelChannel:        make(chan bool, 1),
+                               createExecFile:       true,
+                       },
+                       code:           helloWordPython,
+                       expectedStatus: pb.Status_STATUS_RUN_ERROR,
+               },
+               {
+                       name: "Test run step working on go sdk",

Review comment:
       ditto

##########
File path: playground/backend/internal/code_processing/code_processing_test.go
##########
@@ -908,51 +1009,84 @@ func Test_compileStep(t *testing.T) {
                cancelChannel        chan bool
        }
        tests := []struct {
-               name string
-               args args
-               want *executors.Executor
-               code string
+               name           string
+               args           args
+               code           string
+               expectedStatus pb.Status
        }{
                {
-                       name: "Test compilation step working without an error",
+                       name: "Test compilation step working on java sdk",
+                       args: args{
+                               ctx:                  context.Background(),
+                               cacheService:         cacheService,
+                               pipelineId:           uuid.New(),
+                               sdkEnv:               sdkJavaEnv,
+                               isUnitTest:           false,
+                               pipelineLifeCycleCtx: context.Background(),
+                               cancelChannel:        make(chan bool, 1),
+                       },
+                       code:           helloWordJava,
+                       expectedStatus: pb.Status_STATUS_EXECUTING,
+               },
+               {
+                       name: "Test compilation step working on python sdk",

Review comment:
       ditto




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to