-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new relative age logic with unit tests
- Loading branch information
1 parent
9dfe2fc
commit ea8f0ee
Showing
3 changed files
with
441 additions
and
0 deletions.
There are no files selected for viewing
247 changes: 247 additions & 0 deletions
247
...nt/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { deserializer } from '../form'; | ||
import { absoluteTimingToRelativeTiming } from './absolute_timing_to_relative_timing'; | ||
|
||
describe('absoluteTimingToRelativeTiming', () => { | ||
describe('policy that never deletes data (keep forever)', () => { | ||
test('always hot', () => { | ||
expect( | ||
absoluteTimingToRelativeTiming( | ||
deserializer({ | ||
name: 'test', | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
}, | ||
}) | ||
) | ||
).toEqual({ total: 'Forever', hot: 'Forever', warm: undefined, cold: undefined }); | ||
}); | ||
|
||
test('hot, then always warm', () => { | ||
expect( | ||
absoluteTimingToRelativeTiming( | ||
deserializer({ | ||
name: 'test', | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
warm: { | ||
actions: {}, | ||
}, | ||
}, | ||
}) | ||
) | ||
).toEqual({ total: 'Forever', hot: 'Less than a day', warm: 'Forever', cold: undefined }); | ||
}); | ||
|
||
test('hot, then warm, then always cold', () => { | ||
expect( | ||
absoluteTimingToRelativeTiming( | ||
deserializer({ | ||
name: 'test', | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
warm: { | ||
min_age: '1M', | ||
actions: {}, | ||
}, | ||
cold: { | ||
min_age: '34d', | ||
actions: {}, | ||
}, | ||
}, | ||
}) | ||
) | ||
).toEqual({ | ||
total: 'Forever', | ||
hot: 'At least 30 days', | ||
warm: 'At least 4 days', | ||
cold: 'Forever', | ||
}); | ||
}); | ||
|
||
test('hot, then always cold', () => { | ||
expect( | ||
absoluteTimingToRelativeTiming( | ||
deserializer({ | ||
name: 'test', | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
cold: { | ||
min_age: '34d', | ||
actions: {}, | ||
}, | ||
}, | ||
}) | ||
) | ||
).toEqual({ total: 'Forever', hot: 'At least 34 days', warm: undefined, cold: 'Forever' }); | ||
}); | ||
}); | ||
|
||
describe('policy that deletes data', () => { | ||
test('hot, then delete', () => { | ||
expect( | ||
absoluteTimingToRelativeTiming( | ||
deserializer({ | ||
name: 'test', | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
delete: { | ||
min_age: '1M', | ||
actions: {}, | ||
}, | ||
}, | ||
}) | ||
) | ||
).toEqual({ | ||
total: 'At least 30 days', | ||
hot: 'At least 30 days', | ||
warm: undefined, | ||
cold: undefined, | ||
}); | ||
}); | ||
|
||
test('hot, then warm, then delete', () => { | ||
expect( | ||
absoluteTimingToRelativeTiming( | ||
deserializer({ | ||
name: 'test', | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
warm: { | ||
min_age: '24d', | ||
actions: {}, | ||
}, | ||
delete: { | ||
min_age: '1M', | ||
actions: {}, | ||
}, | ||
}, | ||
}) | ||
) | ||
).toEqual({ | ||
total: 'At least 30 days', | ||
hot: 'At least 24 days', | ||
warm: 'At least 6 days', | ||
cold: undefined, | ||
}); | ||
}); | ||
|
||
test('hot, then warm, then cold, then delete', () => { | ||
expect( | ||
absoluteTimingToRelativeTiming( | ||
deserializer({ | ||
name: 'test', | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
warm: { | ||
min_age: '24d', | ||
actions: {}, | ||
}, | ||
cold: { | ||
min_age: '2M', | ||
actions: {}, | ||
}, | ||
delete: { | ||
min_age: '2d', | ||
actions: {}, | ||
}, | ||
}, | ||
}) | ||
) | ||
).toEqual({ | ||
total: 'At least 61 days', | ||
hot: 'At least 24 days', | ||
warm: 'At least 37 days', | ||
cold: 'Less than a day', | ||
}); | ||
}); | ||
|
||
test('hot, then cold, then delete', () => { | ||
expect( | ||
absoluteTimingToRelativeTiming( | ||
deserializer({ | ||
name: 'test', | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
cold: { | ||
min_age: '2M', | ||
actions: {}, | ||
}, | ||
delete: { | ||
min_age: '2d', | ||
actions: {}, | ||
}, | ||
}, | ||
}) | ||
) | ||
).toEqual({ | ||
total: 'At least 61 days', | ||
hot: 'At least 61 days', | ||
warm: undefined, | ||
cold: 'Less than a day', | ||
}); | ||
}); | ||
|
||
test('hot, then long warm, then short cold, then delete', () => { | ||
expect( | ||
absoluteTimingToRelativeTiming( | ||
deserializer({ | ||
name: 'test', | ||
phases: { | ||
hot: { | ||
min_age: '0ms', | ||
actions: {}, | ||
}, | ||
warm: { | ||
min_age: '2M', | ||
actions: {}, | ||
}, | ||
cold: { | ||
min_age: '1d', | ||
actions: {}, | ||
}, | ||
delete: { | ||
min_age: '2d', | ||
actions: {}, | ||
}, | ||
}, | ||
}) | ||
) | ||
).toEqual({ | ||
total: 'At least 61 days', | ||
hot: 'At least 61 days', | ||
warm: 'Less than a day', | ||
cold: 'Less than a day', | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.