/** * Retrieves a storage unit for the business object data in the specified storage and validates it. * * @param storageName the storage name * @param businessObjectDataEntity the business object data entity * * @return the storage unit entity */ protected StorageUnitEntity getStorageUnit(String storageName, BusinessObjectDataEntity businessObjectDataEntity) { // Get the storage unit and make sure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storageName, businessObjectDataEntity); // Get the storage unit status. String storageUnitStatus = storageUnitEntity.getStatus().getCode(); // Validate that S3 storage unit is in RESTORED state. if (!StorageUnitStatusEntity.RESTORED.equals(storageUnitStatus)) { throw new IllegalArgumentException(String .format("S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", storageName, StorageUnitStatusEntity.RESTORED, storageUnitStatus, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity))); } return storageUnitEntity; }
/** * Retrieves a storage unit for the business object data in the specified storage and validates it. * * @param storageName the storage name * @param businessObjectDataEntity the business object data entity * * @return the storage unit entity */ protected StorageUnitEntity getStorageUnit(String storageName, BusinessObjectDataEntity businessObjectDataEntity) { // Get the storage unit and make sure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storageName, businessObjectDataEntity); // Get the storage unit status. String storageUnitStatus = storageUnitEntity.getStatus().getCode(); // Validate that S3 storage unit is in RESTORED state. if (!StorageUnitStatusEntity.RESTORED.equals(storageUnitStatus)) { throw new IllegalArgumentException(String .format("S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", storageName, StorageUnitStatusEntity.RESTORED, storageUnitStatus, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity))); } return storageUnitEntity; }
/** * Completes a storage policy transition as per specified storage policy selection. * * @param storagePolicyTransitionParamsDto the storage policy transition DTO that contains parameters needed to complete a storage policy transition */ protected void completeStoragePolicyTransitionImpl(StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto) { // Get the business object data key. BusinessObjectDataKey businessObjectDataKey = storagePolicyTransitionParamsDto.getBusinessObjectDataKey(); // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey); // Validate that business object data status is supported by the storage policy feature. String businessObjectDataStatus = businessObjectDataEntity.getStatus().getCode(); Assert.isTrue(StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES.contains(businessObjectDataStatus), String .format("Business object data status \"%s\" is not supported by the storage policy feature. Business object data: {%s}", businessObjectDataStatus, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); // Retrieve storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storagePolicyTransitionParamsDto.getStorageName(), businessObjectDataEntity); // Validate that storage unit status is ARCHIVING. Assert.isTrue(StorageUnitStatusEntity.ARCHIVING.equals(storageUnitEntity.getStatus().getCode()), String .format("Storage unit status is \"%s\", but must be \"%s\" for storage policy transition to proceed. Storage: {%s}, business object data: {%s}", storageUnitEntity.getStatus().getCode(), StorageUnitStatusEntity.ARCHIVING, storagePolicyTransitionParamsDto.getStorageName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); // Change the storage unit status to ARCHIVED. String reason = StorageUnitStatusEntity.ARCHIVED; storagePolicyTransitionParamsDto.setOldStorageUnitStatus(storageUnitEntity.getStatus().getCode()); storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, reason); storagePolicyTransitionParamsDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode()); }
/** * Completes a storage policy transition as per specified storage policy selection. * * @param storagePolicyTransitionParamsDto the storage policy transition DTO that contains parameters needed to complete a storage policy transition */ protected void completeStoragePolicyTransitionImpl(StoragePolicyTransitionParamsDto storagePolicyTransitionParamsDto) { // Get the business object data key. BusinessObjectDataKey businessObjectDataKey = storagePolicyTransitionParamsDto.getBusinessObjectDataKey(); // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey); // Validate that business object data status is supported by the storage policy feature. String businessObjectDataStatus = businessObjectDataEntity.getStatus().getCode(); Assert.isTrue(StoragePolicySelectorServiceImpl.SUPPORTED_BUSINESS_OBJECT_DATA_STATUSES.contains(businessObjectDataStatus), String .format("Business object data status \"%s\" is not supported by the storage policy feature. Business object data: {%s}", businessObjectDataStatus, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); // Retrieve storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(storagePolicyTransitionParamsDto.getStorageName(), businessObjectDataEntity); // Validate that storage unit status is ARCHIVING. Assert.isTrue(StorageUnitStatusEntity.ARCHIVING.equals(storageUnitEntity.getStatus().getCode()), String .format("Storage unit status is \"%s\", but must be \"%s\" for storage policy transition to proceed. Storage: {%s}, business object data: {%s}", storageUnitEntity.getStatus().getCode(), StorageUnitStatusEntity.ARCHIVING, storagePolicyTransitionParamsDto.getStorageName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey))); // Change the storage unit status to ARCHIVED. String reason = StorageUnitStatusEntity.ARCHIVED; storagePolicyTransitionParamsDto.setOldStorageUnitStatus(storageUnitEntity.getStatus().getCode()); storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, reason); storagePolicyTransitionParamsDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode()); }
@Test public void testGetStorageUnitStorageUnitNotRestored() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a storage unit status entity. StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity(); storageUnitStatusEntity.setCode(STORAGE_UNIT_STATUS); // Create a storage unit entity. StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); storageUnitEntity.setStatus(storageUnitStatusEntity); // Mock the external calls. when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity); when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { expireRestoredBusinessObjectDataHelperServiceImpl.getStorageUnit(STORAGE_NAME, businessObjectDataEntity); } catch (IllegalArgumentException e) { assertEquals(String .format("S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", STORAGE_NAME, StorageUnitStatusEntity.RESTORED, STORAGE_UNIT_STATUS, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageUnitEntityByBusinessObjectDataAndStorageName() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a storage unit entity. StorageUnitEntity storageUnitEntity = new StorageUnitEntity(); // Create a storage entity StorageEntity storageEntity = new StorageEntity(); // Mock the external calls. when(storageDao.getStorageByName(STORAGE_NAME)).thenReturn(storageEntity); when(storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity)).thenReturn(storageUnitEntity); // Call the method under test. StorageUnitEntity result = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Validate the results. assertEquals(storageUnitEntity, result); // Verify the external calls. verify(storageDao).getStorageByName(STORAGE_NAME); verify(storageUnitDao).getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testGetStorageUnitEntityByBusinessObjectDataAndStorageNameStorageUnitNoExists() { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity(); // Create a storage entity StorageEntity storageEntity = new StorageEntity(); // Mock the external calls. when(storageDao.getStorageByName(STORAGE_NAME)).thenReturn(storageEntity); when(storageUnitDao.getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity)).thenReturn(null); when(businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING); // Try to call the method under test. try { storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); fail(); } catch (ObjectNotFoundException e) { assertEquals(String .format("Could not find storage unit in \"%s\" storage for the business object data {%s}.", STORAGE_NAME, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage()); } // Verify the external calls. verify(storageDao).getStorageByName(STORAGE_NAME); verify(storageUnitDao).getStorageUnitByBusinessObjectDataAndStorage(businessObjectDataEntity, storageEntity); verify(businessObjectDataHelper).businessObjectDataEntityAltKeyToString(businessObjectDataEntity); verifyNoMoreInteractionsHelper(); }
@Test public void testPrepareToInitiateRestore() throws Exception { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Get the current time and compute the expected timestamp value. Timestamp currentTime = new Timestamp(System.currentTimeMillis()); Timestamp expectedTimestamp = HerdDateUtils.addDays(currentTime, EXPIRATION_IN_DAYS); // Execute a before step for the initiate a business object data restore request. BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); // Validate that restore expiration time is set correctly on the storage unit. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); assertNotNull(storageUnitEntity.getRestoreExpirationOn()); Long differenceInMilliseconds = storageUnitEntity.getRestoreExpirationOn().getTime() - expectedTimestamp.getTime(); assertTrue(Math.abs(differenceInMilliseconds) < 1000); }
@Test public void testPrepareToInitiateRestoreStorageUnitHasNoStorageFiles() throws Exception { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper .createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey, STORAGE_NAME, S3_BUCKET_NAME, StorageUnitStatusEntity.ARCHIVED, LOCAL_FILES); // Get the storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Remove storage files from the storage unit. storageUnitEntity.getStorageFiles().clear(); // Try to execute a before step for the initiate a business object data restore request when storage unit has no storage files. try { businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, EXPIRATION_IN_DAYS); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has no storage files registered in \"%s\" storage. Business object data: {%s}", STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage()); } }
/** * Completes the expiration of a storage unit. * * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to expire business object data */ protected void completeStorageUnitExpirationImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) { // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey()); // Retrieve the storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity); // Update the storage unit status. String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode(); String reason = StorageUnitStatusEntity.ARCHIVED; storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, reason); // Update the new and old storage unit status values in the DTO. businessObjectDataRestoreDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode()); businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus); }
/** * Completes the expiration of a storage unit. * * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to expire business object data */ protected void completeStorageUnitExpirationImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) { // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey()); // Retrieve the storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity); // Update the storage unit status. String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode(); String reason = StorageUnitStatusEntity.ARCHIVED; storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.ARCHIVED, reason); // Update the new and old storage unit status values in the DTO. businessObjectDataRestoreDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode()); businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus); }
/** * Completes the finalize restore operation. * * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to perform a business object data restore */ protected void completeFinalizeRestoreImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) { // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey()); // Retrieve the storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity); // Retrieve and ensure the RESTORED storage unit status entity exists. StorageUnitStatusEntity newStorageUnitStatusEntity = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(StorageUnitStatusEntity.RESTORED); // Save the old storage unit status value. String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode(); // Update the storage unit status to RESTORED. String reason = StorageUnitStatusEntity.RESTORED; storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, newStorageUnitStatusEntity, reason); // Update the new and old storage unit status values in the business object data restore DTO. businessObjectDataRestoreDto.setNewStorageUnitStatus(newStorageUnitStatusEntity.getCode()); businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus); }
@Test public void testPrepareToFinalizeRestoreStorageUnitHasNoStorageFiles() throws Exception { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper .createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey, STORAGE_NAME, S3_BUCKET_NAME, StorageUnitStatusEntity.RESTORING); // Get the origin storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Remove storage files from the storage unit. storageUnitEntity.getStorageFiles().clear(); // Create a storage unit key. BusinessObjectDataStorageUnitKey glacierStorageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME); // Try to prepare to finalize a restore when storage unit has no storage files. try { businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(glacierStorageUnitKey); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has no storage files registered in \"%s\" storage. Business object data: {%s}", STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage()); } }
/** * Completes the finalize restore operation. * * @param businessObjectDataRestoreDto the DTO that holds various parameters needed to perform a business object data restore */ protected void completeFinalizeRestoreImpl(BusinessObjectDataRestoreDto businessObjectDataRestoreDto) { // Retrieve the business object data and ensure it exists. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataRestoreDto.getBusinessObjectDataKey()); // Retrieve the storage unit and ensure it exists. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity); // Retrieve and ensure the RESTORED storage unit status entity exists. StorageUnitStatusEntity newStorageUnitStatusEntity = storageUnitStatusDaoHelper.getStorageUnitStatusEntity(StorageUnitStatusEntity.RESTORED); // Save the old storage unit status value. String oldStorageUnitStatus = storageUnitEntity.getStatus().getCode(); // Update the storage unit status to RESTORED. String reason = StorageUnitStatusEntity.RESTORED; storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, newStorageUnitStatusEntity, reason); // Update the new and old storage unit status values in the business object data restore DTO. businessObjectDataRestoreDto.setNewStorageUnitStatus(newStorageUnitStatusEntity.getCode()); businessObjectDataRestoreDto.setOldStorageUnitStatus(oldStorageUnitStatus); }
@Test public void testRetryStoragePolicyTransitionStorageUnitHasNoStorageFiles() { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create a storage policy key. StoragePolicyKey storagePolicyKey = new StoragePolicyKey(STORAGE_POLICY_NAMESPACE_CD, STORAGE_POLICY_NAME); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper .createDatabaseEntitiesForRetryStoragePolicyTransitionTesting(businessObjectDataKey, storagePolicyKey, STORAGE_NAME, S3_BUCKET_NAME, StorageUnitStatusEntity.ARCHIVING); // Get the storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Remove storage files from the storage unit. storageUnitEntity.getStorageFiles().clear(); // Try to execute a before step for the retry storage policy transition when storage unit has no storage files. try { businessObjectDataRetryStoragePolicyTransitionHelper .retryStoragePolicyTransition(businessObjectDataKey, new BusinessObjectDataRetryStoragePolicyTransitionRequest(storagePolicyKey)); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("Business object data has no storage files registered in \"%s\" storage. Business object data: {%s}", STORAGE_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(businessObjectDataKey)), e.getMessage()); } }
@Test public void testPrepareToInitiateRestoreMissingOptionalParameters() throws Exception { // Create a business object data key without sub-partition values. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForInitiateRestoreTesting(businessObjectDataKey); // Execute a before step for the initiate a business object data restore request for business object data without sub-partition values. BusinessObjectDataRestoreDto storagePolicyTransitionParamsDto = businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(businessObjectDataKey, NO_EXPIRATION_IN_DAYS); // Validate the returned object. assertEquals(businessObjectDataKey, storagePolicyTransitionParamsDto.getBusinessObjectDataKey()); // Validate that restore expiration time is set correctly on the storage unit. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); assertNotNull(storageUnitEntity.getRestoreExpirationOn()); Long differenceInDays = TimeUnit.DAYS.convert(storageUnitEntity.getRestoreExpirationOn().getTime() - storageUnitEntity.getCreatedOn().getTime(), TimeUnit.MILLISECONDS); assertTrue((Integer) ConfigurationValue.BDATA_RESTORE_EXPIRATION_IN_DAYS_DEFAULT.getDefaultValue() - differenceInDays <= 1); }
storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataRestoreDto.getStorageName(), businessObjectDataEntity);
@Test public void testCompleteFinalizeRestore() throws Exception { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey); // Get the origin storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Validate that the storage unit status is RESTORING. assertEquals(StorageUnitStatusEntity.RESTORING, storageUnitEntity.getStatus().getCode()); // Create a business object data restore DTO. BusinessObjectDataRestoreDto businessObjectDataRestoreDto = new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, Arrays.asList(new StorageFile(TEST_S3_KEY_PREFIX + "/" + LOCAL_FILE, FILE_SIZE_1_KB, NO_ROW_COUNT)), NO_EXCEPTION); // Enable origin storage unit to finalize a restore for business object data. businessObjectDataFinalizeRestoreHelperService.completeFinalizeRestore(businessObjectDataRestoreDto); // Validate that the storage unit status is RESTORED. assertEquals(StorageUnitStatusEntity.RESTORED, storageUnitEntity.getStatus().getCode()); }
@Test public void testPrepareToFinalizeRestore() throws Exception { // Create a business object data key. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create a storage unit key. BusinessObjectDataStorageUnitKey storageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey); // Get the storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Prepare to finalize a restore for the business object data. BusinessObjectDataRestoreDto result = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey); // Validate the returned object. assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, NO_S3_ENDPOINT, S3_BUCKET_NAME, result.getS3KeyPrefix(), NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles()), NO_EXCEPTION), result); }
@Test public void testPrepareToFinalizeRestoreMissingOptionalParameters() throws Exception { // Create a business object data key without sub-partition values. BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION); // Create database entities required for testing. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper.createDatabaseEntitiesForFinalizeRestoreTesting(businessObjectDataKey); // Get the storage unit entity. StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity); // Create a storage unit key. BusinessObjectDataStorageUnitKey storageUnitKey = storageUnitHelper.createStorageUnitKey(businessObjectDataKey, STORAGE_NAME); // Prepare to finalize a restore for business object data without sub-partition values. BusinessObjectDataRestoreDto result = businessObjectDataFinalizeRestoreHelperService.prepareToFinalizeRestore(storageUnitKey); // Validate the returned object. assertEquals(new BusinessObjectDataRestoreDto(businessObjectDataKey, STORAGE_NAME, NO_S3_ENDPOINT, S3_BUCKET_NAME, result.getS3KeyPrefix(), NO_STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS, storageFileHelper.createStorageFilesFromEntities(storageUnitEntity.getStorageFiles()), NO_EXCEPTION), result); }