-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from Green-Software-Foundation/aggregation-pe…
…r-unit Aggregation per unit
- Loading branch information
Showing
15 changed files
with
436 additions
and
683 deletions.
There are no files selected for viewing
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
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
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,93 @@ | ||
import {aggregate} from '../../../lib/aggregator'; | ||
|
||
import {STRINGS} from '../../../config'; | ||
|
||
import {ERRORS} from '../../../util/errors'; | ||
|
||
import {UnitKeyName} from '../../../types/units'; | ||
|
||
const {INVALID_AGGREGATION_METHOD, METRIC_MISSING} = STRINGS; | ||
|
||
const {InvalidAggregationParams} = ERRORS; | ||
|
||
describe('lib/aggregator: ', () => { | ||
describe('aggregate(): ', () => { | ||
it('throws error if aggregation method is none.', async () => { | ||
const inputs = [{}]; | ||
const metrics = ['total-resources'] as UnitKeyName[]; | ||
|
||
const expectedMessage = INVALID_AGGREGATION_METHOD('none'); | ||
|
||
expect.assertions(1); | ||
|
||
try { | ||
await aggregate(inputs, metrics); | ||
} catch (error) { | ||
expect(error).toEqual(new InvalidAggregationParams(expectedMessage)); | ||
} | ||
}); | ||
|
||
it('throws error if metric is not found while aggregation.', async () => { | ||
const inputs = [ | ||
{ | ||
'ram-util': 10, | ||
}, | ||
]; | ||
const metrics = ['cpu-util'] as UnitKeyName[]; | ||
|
||
const expectedMessage = METRIC_MISSING(metrics[0], 0); | ||
|
||
expect.assertions(1); | ||
|
||
try { | ||
await aggregate(inputs, metrics); | ||
} catch (error) { | ||
expect(error).toEqual(new InvalidAggregationParams(expectedMessage)); | ||
} | ||
}); | ||
|
||
it('should successfully calculate avg.', async () => { | ||
const inputs = [ | ||
{ | ||
'cpu-util': 10, | ||
}, | ||
{ | ||
'cpu-util': 20, | ||
}, | ||
]; | ||
const metrics = ['cpu-util'] as UnitKeyName[]; | ||
|
||
const expectedKey = `aggregated-${Object.keys(inputs[0])[0]}`; | ||
const expectedValue = (inputs[0]['cpu-util'] + inputs[1]['cpu-util']) / 2; | ||
const expectedResult = { | ||
[`${expectedKey}`]: expectedValue, | ||
}; | ||
|
||
const aggregatedResult = await aggregate(inputs, metrics); | ||
|
||
expect(aggregatedResult).toEqual(expectedResult); | ||
}); | ||
|
||
it('should successfully calculate sum.', async () => { | ||
const inputs = [ | ||
{ | ||
'disk-io': 10, | ||
}, | ||
{ | ||
'disk-io': 20, | ||
}, | ||
]; | ||
const metrics = ['disk-io'] as UnitKeyName[]; | ||
|
||
const expectedKey = `aggregated-${Object.keys(inputs[0])[0]}`; | ||
const expectedValue = inputs[0]['disk-io'] + inputs[1]['disk-io']; | ||
const expectedResult = { | ||
[`${expectedKey}`]: expectedValue, | ||
}; | ||
|
||
const aggregatedResult = await aggregate(inputs, metrics); | ||
|
||
expect(aggregatedResult).toEqual(expectedResult); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.