Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle unknown index types gracefully in iUtils #18

Merged
merged 2 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/client/factories/iUtils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ moment = require '../../../bower_components/moment/min/moment.min.js'

module.exports = ->
parseTaskId: (taskId) ->
m = taskId.match /^((hadoop_convert_segment)|index_(hadoop|realtime|spark)|(archive))_(.+)_(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z)/
type = m[3]
type ||= m[2]
throw Error("Can't parse #{taskId}") unless m
m = taskId.match(/^(?:(hadoop_convert_segment)|index_(hadoop|realtime|spark)|(archive))_(.+)_(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z)/) || []
{
id: taskId
type
type: m[3] || m[2] || m[1] || 'other'
dataSource: m[4]
dataTime: m[5]
}
Expand Down
66 changes: 66 additions & 0 deletions test/unit/factories/iUtils.spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
iUtilsFactory = require '../../../src/client/factories/iUtils.coffee'

describe '$iUtils', () ->
$iUtils = undefined
$taskTimestamp = '2018-01-01T10:20:30.400Z'

beforeEach ->
$iUtils = iUtilsFactory()

it 'should have a defined $iUtils', () ->
expect($iUtils?).toBeTruthy()

describe 'parseTaskId', () ->
it 'should parse hadoop_convert task', () ->
task = $iUtils.parseTaskId('hadoop_convert_segment_wikipedia_' + $taskTimestamp)
expect(task).toEqual({
id: 'hadoop_convert_segment_wikipedia_' + $taskTimestamp
type: 'hadoop_convert_segment'
dataSource: 'wikipedia'
dataTime: $taskTimestamp
})

it 'should parse index_hadoop task', () ->
task = $iUtils.parseTaskId('index_hadoop_twitter_' + $taskTimestamp)
expect(task).toEqual({
id: 'index_hadoop_twitter_' + $taskTimestamp
type: 'hadoop'
dataSource: 'twitter'
dataTime: $taskTimestamp
})

it 'should parse index_realtime task', () ->
task = $iUtils.parseTaskId('index_realtime_twitter_' + $taskTimestamp)
expect(task).toEqual({
id: 'index_realtime_twitter_' + $taskTimestamp
type: 'realtime'
dataSource: 'twitter'
dataTime: $taskTimestamp
})

it 'should parse index_spark task', () ->
task = $iUtils.parseTaskId('index_spark_twitter_' + $taskTimestamp)
expect(task).toEqual({
id: 'index_spark_twitter_' + $taskTimestamp
type: 'spark'
dataSource: 'twitter'
dataTime: $taskTimestamp
})

it 'should parse archive task', () ->
task = $iUtils.parseTaskId('archive_wikipedia_' + $taskTimestamp)
expect(task).toEqual({
id: 'archive_wikipedia_' + $taskTimestamp
type: 'archive'
dataSource: 'wikipedia'
dataTime: $taskTimestamp
})

it 'should not throw an error if taskId does not match expected pattern', () ->
task = $iUtils.parseTaskId('index_kafka_twitter_1675e770de9a423_hfdhgjko')
expect(task).toEqual({
id: 'index_kafka_twitter_1675e770de9a423_hfdhgjko'
type: 'other'
dataSource: undefined
dataTime: undefined
})