DiskStoreValidator implements ConfigurationValidator<DiskStore> { @Override public void validate(CacheElementOperation operation, DiskStore config) throws IllegalArgumentException { switch (operation) { case CREATE: case UPDATE: checkRequiredItems(config); checkValueRanges(config); break; case DELETE: validateDelete(config); } }  @Override void validate(CacheElementOperation operation, DiskStore config);  }
@Test public void diskStoreNameIsRequired() { diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore); diskStore.setName(null); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Diskstore name is required"); }
@Test public void atLeastOneDirectoryIsDefined() { diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore); diskStore.setDirectories(null); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("At least one DiskDir element required"); }
@Test public void diskUsageCriticalPercentageMustBeBetweenZeroAndOneHundred() { diskStore.setDiskUsageCriticalPercentage(95F); diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore); diskStore.setDiskUsageCriticalPercentage(-1F); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining( "Disk usage critical percentage must be set to a value between 0-100"); diskStore.setDiskUsageCriticalPercentage(101F); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining( "Disk usage critical percentage must be set to a value between 0-100"); }
@Test public void diskUsageWarningPercentageMustBeBetweenZeroAndOneHundred() { diskStore.setDiskUsageWarningPercentage(95F); diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore); diskStore.setDiskUsageWarningPercentage(-1F); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Disk usage warning percentage must be set to a value between 0-100"); diskStore.setDiskUsageWarningPercentage(101F); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Disk usage warning percentage must be set to a value between 0-100"); }
@Test public void compactionThresholdMustBeBetweenZeroAndOneHundres() { diskStore.setCompactionThreshold(95); diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore); diskStore.setCompactionThreshold(-1); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("CompactionThreshold has to be set to a value between 0-100."); diskStore.setCompactionThreshold(101); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("CompactionThreshold has to be set to a value between 0-100."); }
@Test public void maxOplogSizeInBytesMustBePositiveNumber() { diskStore.setMaxOplogSizeInBytes(Long.MAX_VALUE); diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore); diskStore.setMaxOplogSizeInBytes(-1L); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining( "Maximum Oplog size specified has to be a non-negative number and the value given"); }
@Test public void queueSizeMustBePositiveNumber() { diskStore.setQueueSize(Integer.MAX_VALUE); diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore); diskStore.setQueueSize(-1); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining( "Queue size specified has to be a non-negative number and the value given"); }
@Test public void writeBufferSizeMustBePositiveNumber() { diskStore.setWriteBufferSize(Integer.MAX_VALUE); diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore); diskStore.setWriteBufferSize(-1); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining( "Write buffer size specified has to be a non-negative number and the value given"); }
@Test public void dirSizesMustBePositiveNumber() { diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore); diskDir.setDirSize(-1); diskStore.setDirectories(Collections.singletonList(diskDir)); assertThatThrownBy(() -> diskStoreValidator.validate(CacheElementOperation.CREATE, diskStore)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Dir size cannot be negative :"); }