github.com/matrixorigin/matrixone@v0.7.0/pkg/taskservice/mysql_task_storage_test.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package taskservice
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/pb/task"
    21  	"github.com/stretchr/testify/assert"
    22  )
    23  
    24  func TestBuildWhereClause(t *testing.T) {
    25  	cases := []struct {
    26  		condition conditions
    27  
    28  		expected string
    29  	}{
    30  		{
    31  			condition: conditions{
    32  				hasTaskIDCond: true,
    33  				taskIDOp:      EQ,
    34  				taskID:        1,
    35  			},
    36  			expected: "task_id=1",
    37  		},
    38  		{
    39  			condition: conditions{
    40  				hasTaskIDCond:       true,
    41  				taskIDOp:            EQ,
    42  				taskID:              1,
    43  				hasTaskRunnerCond:   true,
    44  				taskRunnerOp:        EQ,
    45  				taskRunner:          "abc",
    46  				hasTaskStatusCond:   true,
    47  				taskStatusOp:        EQ,
    48  				taskStatus:          task.TaskStatus_Created,
    49  				hasTaskEpochCond:    true,
    50  				taskEpochOp:         LE,
    51  				taskEpoch:           100,
    52  				hasTaskParentIDCond: true,
    53  				taskParentTaskIDOp:  GE,
    54  				taskParentTaskID:    "ab",
    55  				hasTaskExecutorCond: true,
    56  				taskExecutorOp:      GE,
    57  				taskExecutor:        1,
    58  			},
    59  			expected: "task_id=1 AND task_runner='abc' AND task_status=0 AND task_epoch<=100 AND task_parent_id>='ab' AND task_metadata_executor>=1",
    60  		},
    61  		{
    62  			condition: conditions{
    63  				hasTaskRunnerCond:   true,
    64  				taskRunnerOp:        EQ,
    65  				taskRunner:          "abc",
    66  				hasTaskStatusCond:   true,
    67  				taskStatusOp:        EQ,
    68  				taskStatus:          task.TaskStatus_Created,
    69  				hasTaskParentIDCond: true,
    70  				taskParentTaskIDOp:  GE,
    71  				taskParentTaskID:    "ab",
    72  				hasTaskExecutorCond: true,
    73  				taskExecutorOp:      LE,
    74  				taskExecutor:        1,
    75  			},
    76  			expected: "task_runner='abc' AND task_status=0 AND task_parent_id>='ab' AND task_metadata_executor<=1",
    77  		},
    78  	}
    79  
    80  	for _, c := range cases {
    81  		result := buildWhereClause(c.condition)
    82  		assert.Equal(t, c.expected, result)
    83  	}
    84  }