Skip to content

Commit

Permalink
ISPN-16230 Time units instead of millisecods
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Sep 10, 2024
1 parent 1fce9cd commit e45e3f8
Show file tree
Hide file tree
Showing 16 changed files with 477 additions and 372 deletions.
11 changes: 11 additions & 0 deletions src/__tests__/services/convertToTimeQuantity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { TimeUnits } from '@services/infinispanRefData';
import { convertToTimeQuantity } from '@utils/convertToTimeQuantity';

describe('Convert to Time Quantity', () => {
test('from value and unit to time quantity', () => {
expect(convertToTimeQuantity(23, TimeUnits.milliseconds)).toStrictEqual('23ms');
expect(convertToTimeQuantity(23, TimeUnits.seconds)).toStrictEqual('23s');
expect(convertToTimeQuantity(23, TimeUnits.minutes)).toStrictEqual('23m');
expect(convertToTimeQuantity(23, TimeUnits.hours)).toStrictEqual('23h');
});
});
48 changes: 37 additions & 11 deletions src/app/Caches/Create/AdvancedOptionsConfigurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
Grid,
GridItem,
HelperText,
HelperTextItem,
HelperTextItem, InputGroup, InputGroupItem,
Switch,
TextInput
} from '@patternfly/react-core';
import { StorageType } from '@services/infinispanRefData';
import { StorageType, TimeUnits } from '@services/infinispanRefData';
import { useTranslation } from 'react-i18next';
import TransactionalConfigurationTuning from '@app/Caches/Create/AdvancedTuning/TransactionalConfigurationTuning';
import { useCreateCache } from '@app/services/createCacheHook';
Expand All @@ -31,6 +31,9 @@ const AdvancedOptionsConfigurator = (props: { cacheManager: CacheManager }) => {
const [lockAcquisitionTimeout, setLockAcquisitionTimeout] = useState<number | undefined>(
configuration.advanced.lockAcquisitionTimeout
);
const [lockAcquisitionTimeoutUnit, setLockAcquisitionTimeoutUnit] = useState<string | undefined>(
configuration.advanced.lockAcquisitionTimeoutUnit
);
const [striping, setStriping] = useState<boolean>(configuration.advanced.striping!);
const [aliases, setAliases] = useState<string[]>(configuration.advanced.aliases!);

Expand All @@ -43,12 +46,13 @@ const AdvancedOptionsConfigurator = (props: { cacheManager: CacheManager }) => {
storage: storage,
concurrencyLevel: concurrencyLevel,
lockAcquisitionTimeout: lockAcquisitionTimeout,
lockAcquisitionTimeoutUnit: lockAcquisitionTimeoutUnit,
striping: striping,
aliases: aliases
}
};
});
}, [storage, concurrencyLevel, lockAcquisitionTimeout, striping, aliases]);
}, [storage, concurrencyLevel, lockAcquisitionTimeout, lockAcquisitionTimeoutUnit, striping, aliases]);

const handleConcurrencyLevel = (value) => {
setConcurrencyLevel(value);
Expand Down Expand Up @@ -130,6 +134,7 @@ const AdvancedOptionsConfigurator = (props: { cacheManager: CacheManager }) => {
<HelperTextItem>{t('caches.create.configurations.advanced-options.locking-tooltip')}</HelperTextItem>
</HelperText>
<Grid hasGutter md={4}>
<GridItem span={4}>
<FormGroup
isInline
fieldId="field-concurrency-level"
Expand All @@ -151,6 +156,8 @@ const AdvancedOptionsConfigurator = (props: { cacheManager: CacheManager }) => {
data-cy="concurencyLevel"
/>
</FormGroup>
</GridItem>
<GridItem span={6}>
<FormGroup
isInline
fieldId="field-lock-acquisition-timeout"
Expand All @@ -163,15 +170,34 @@ const AdvancedOptionsConfigurator = (props: { cacheManager: CacheManager }) => {
/>
}
>
<TextInput
placeholder="10"
value={lockAcquisitionTimeout}
type="number"
onChange={(_event, value) => handleLockAcquisitionTimeout(value)}
aria-label="lock-acquisition-timeout-input"
data-cy="lockTimeout"
/>
<InputGroup>
<InputGroupItem>
<Grid>
<GridItem span={8}>
<TextInput
placeholder="10"
value={lockAcquisitionTimeout}
type="number"
onChange={(_event, value) => handleLockAcquisitionTimeout(value)}
aria-label="lock-acquisition-timeout-input"
data-cy="lockTimeout"
/>
</GridItem>
<GridItem span={4}>
<SelectSingle
id={'lockAcquisitionTimeoutUnitSelector'}
placeholder={''}
selected={lockAcquisitionTimeoutUnit || TimeUnits.milliseconds}
options={selectOptionProps(TimeUnits)}
style={{ width: '150px' }}
onSelect={(value) => setLockAcquisitionTimeoutUnit(value)}
/>
</GridItem>
</Grid>
</InputGroupItem>
</InputGroup>
</FormGroup>
</GridItem>
<GridItem span={12}>
<FormGroup fieldId="field-striping">
<Switch
Expand Down
29 changes: 15 additions & 14 deletions src/app/Caches/Create/AdvancedTuning/BackupsCofigurationTuning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useTranslation } from 'react-i18next';
import { useCreateCache } from '@app/services/createCacheHook';
import { PopoverHelp } from '@app/Common/PopoverHelp';
import BackupSiteConfigurator from '@app/Caches/Create/AdvancedTuning/BackupsSiteConfigurator';
import TimeQuantityInputGroup from '@app/Caches/Create/TimeQuantityInputGroup';

const BackupsConfigurationTuning = () => {
const { configuration, setConfiguration } = useCreateCache();
Expand All @@ -25,6 +26,7 @@ const BackupsConfigurationTuning = () => {
);
const [mergePolicy, setMergePolicy] = useState(configuration.advanced.backupSetting?.mergePolicy);
const [maxCleanupDelay, setMaxCleanupDelay] = useState(configuration.advanced.backupSetting?.maxCleanupDelay);
const [maxCleanupDelayUnit, setMaxCleanupDelayUnit] = useState(configuration.advanced.backupSetting?.maxCleanupDelayUnit);
const [tombstoneMapSize, setTombstoneMapSize] = useState(configuration.advanced.backupSetting?.tombstoneMapSize);

useEffect(() => {
Expand All @@ -36,14 +38,15 @@ const BackupsConfigurationTuning = () => {
backupSetting: {
mergePolicy: mergePolicy,
maxCleanupDelay: maxCleanupDelay,
maxCleanupDelayUnit: maxCleanupDelayUnit,
tombstoneMapSize: tombstoneMapSize
},
backupSiteData: backupSiteData,
valid: true
}
};
});
}, [backupSiteData, mergePolicy, maxCleanupDelay, tombstoneMapSize]);
}, [backupSiteData, mergePolicy, maxCleanupDelay, maxCleanupDelayUnit, tombstoneMapSize]);

if (!configuration.feature.cacheFeatureSelected.includes(CacheFeature.BACKUPS)) {
return <div />;
Expand All @@ -66,9 +69,9 @@ const BackupsConfigurationTuning = () => {
<TextInput
placeholder="DEFAULT"
value={mergePolicy}
onChange={(_event, val) => {
val === '' ? setMergePolicy(undefined!) : setMergePolicy(val);
}}
onChange={(_event, val) =>
setMergePolicy(val === ''? undefined! : val)
}
aria-label="merge-policy-input"
/>
</FormGroup>
Expand All @@ -84,15 +87,12 @@ const BackupsConfigurationTuning = () => {
/>
}
>
<TextInput
placeholder="30000"
type="number"
value={maxCleanupDelay}
onChange={(_event, val) => {
isNaN(parseInt(val)) ? setMaxCleanupDelay(undefined!) : setMaxCleanupDelay(parseInt(val));
}}
aria-label="max-cleanup-delay-input"
/>
<TimeQuantityInputGroup name={'maxCleanupDelay'}
defaultValue={'30000'}
value={maxCleanupDelay}
valueModifier={setMaxCleanupDelay}
unit={maxCleanupDelayUnit}
unitModifier={setMaxCleanupDelayUnit}/>
</FormGroup>

<FormGroup
Expand All @@ -111,7 +111,8 @@ const BackupsConfigurationTuning = () => {
type="number"
value={tombstoneMapSize}
onChange={(_event, val) => {
isNaN(parseInt(val)) ? setTombstoneMapSize(undefined!) : setTombstoneMapSize(parseInt(val));
const parsedVal = parseInt(val);
setTombstoneMapSize(isNaN(parsedVal) ? undefined! : parsedVal)
}}
aria-label="tombstone-map-size-input"
/>
Expand Down
Loading

0 comments on commit e45e3f8

Please sign in to comment.