Skip to content

Commit

Permalink
added new relative age logic with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jan 11, 2021
1 parent 9dfe2fc commit ea8f0ee
Show file tree
Hide file tree
Showing 3 changed files with 441 additions and 0 deletions.
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',
});
});
});
});
Loading

0 comments on commit ea8f0ee

Please sign in to comment.