Skip to content

Commit

Permalink
model: add helper job function and update test.
Browse files Browse the repository at this point in the history
  • Loading branch information
siddontang committed Nov 20, 2015
1 parent d8765ea commit 3d63780
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ func (job *Job) String() string {
job.ID, job.Type, job.State, job.SchemaState, job.SchemaID, job.TableID, job.RawArgs)
}

// IsFinished returns whether job is finished or not.
// If the job state is Done or Cancelled, it is finished.
func (job *Job) IsFinished() bool {
return job.State == JobDone || job.State == JobCancelled
}

// IsRunning returns whether job is still running or not.
func (job *Job) IsRunning() bool {
return job.State == JobRunning
}

// JobState is for job state.
type JobState byte

Expand Down
43 changes: 43 additions & 0 deletions model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,47 @@ func (*testSuite) TestJobCodec(c *C) {
c.Assert(a, DeepEquals, A{Name: "abc"})

c.Assert(len(newJob.String()), Greater, 0)

job.State = JobDone
c.Assert(job.IsFinished(), IsTrue)
c.Assert(job.IsRunning(), IsFalse)
}

func (testSuite) TestState(c *C) {
schemaTbl := []SchemaState{
StateDeleteOnly,
StateWriteOnly,
StateWriteReorganization,
StateDeleteReorganization,
StatePublic,
}

for _, state := range schemaTbl {
c.Assert(len(state.String()), Greater, 0)
}

jobTbl := []JobState{
JobRunning,
JobDone,
JobCancelled,
}

for _, state := range jobTbl {
c.Assert(len(state.String()), Greater, 0)
}

actionTbl := []ActionType{
ActionCreateSchema,
ActionDropSchema,
ActionCreateTable,
ActionDropTable,
ActionAddColumn,
ActionDropColumn,
ActionAddIndex,
ActionDropIndex,
}

for _, action := range actionTbl {
c.Assert(len(action.String()), Greater, 0)
}
}

0 comments on commit 3d63780

Please sign in to comment.