@Test( expected = PolicyViolationException.class ) public void testPolicyYes() throws Exception { DownloadPolicy policy = lookupPolicy(); StorageAsset localFile = getFile(); Properties request = createRequest(); String url = "http: request.setProperty( "url", url ); try { policy.applyPolicy(CachedFailuresPolicy.YES, request, localFile); } catch (PolicyViolationException e) { throw new RuntimeException(e); } urlFailureCache.cacheFailure( url ); request.setProperty( "url", url ); policy.applyPolicy( CachedFailuresPolicy.YES, request, localFile ); }
@Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown cache-failues policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( NO.equals( policySetting ) ) { log.debug( "OK to fetch, check-failures policy set to NO." ); return; } String url = request.getProperty( "url" ); if ( StringUtils.isNotBlank( url ) ) { if ( urlFailureCache.hasFailedBefore( url ) ) { throw new PolicyViolationException( "NO to fetch, check-failures detected previous failure on url: " + url ); } } log.debug( "OK to fetch, check-failures detected no issues." ); }
CachedFailuresPolicy extends AbstractPolicy implements PreDownloadPolicy { @Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown cache-failues policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( NO.equals( policySetting ) ) { log.debug( "OK to fetch, check-failures policy set to NO." ); return; } String url = request.getProperty( "url" ); if ( StringUtils.isNotBlank( url ) ) { if ( urlFailureCache.hasFailedBefore( url ) ) { throw new PolicyViolationException( "NO to fetch, check-failures detected previous failure on url: " + url ); } } log.debug( "OK to fetch, check-failures detected no issues." ); } }
CachedFailuresPolicy extends AbstractPolicy implements PreDownloadPolicy { @Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown cache-failues policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( NO.equals( policySetting ) ) { log.debug( "OK to fetch, check-failures policy set to NO." ); return; } String url = request.getProperty( "url" ); if ( StringUtils.isNotBlank( url ) ) { if ( urlFailureCache.hasFailedBefore( url ) ) { throw new PolicyViolationException( "NO to fetch, check-failures detected previous failure on url: " + url ); } } log.debug( "OK to fetch, check-failures detected no issues." ); } CachedFailuresPolicy(); }
CachedFailuresPolicy extends AbstractPolicy implements PreDownloadPolicy { @Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown cache-failues policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( NO.equals( policySetting ) ) { log.debug( "OK to fetch, check-failures policy set to NO." ); return; } String url = request.getProperty( "url" ); if ( StringUtils.isNotBlank( url ) ) { if ( urlFailureCache.hasFailedBefore( url ) ) { throw new PolicyViolationException( "NO to fetch, check-failures detected previous failure on url: " + url ); } } log.debug( "OK to fetch, check-failures detected no issues." ); } CachedFailuresPolicy(); @Override void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ); @Override PolicyOption getDefaultOption(); @Override String getId(); @Override List<PolicyOption> getOptions(); }
CachedFailuresPolicy extends AbstractPolicy implements PreDownloadPolicy { @Override public void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ) throws PolicyViolationException, PolicyConfigurationException { if ( !options.contains( policySetting ) ) { throw new PolicyConfigurationException( "Unknown cache-failues policy setting [" + policySetting + "], valid settings are [" + StringUtils.join( options.iterator(), "," ) + "]" ); } if ( NO.equals( policySetting ) ) { log.debug( "OK to fetch, check-failures policy set to NO." ); return; } String url = request.getProperty( "url" ); if ( StringUtils.isNotBlank( url ) ) { if ( urlFailureCache.hasFailedBefore( url ) ) { throw new PolicyViolationException( "NO to fetch, check-failures detected previous failure on url: " + url ); } } log.debug( "OK to fetch, check-failures detected no issues." ); } CachedFailuresPolicy(); @Override void applyPolicy( PolicyOption policySetting, Properties request, StorageAsset localFile ); @Override PolicyOption getDefaultOption(); @Override String getId(); @Override List<PolicyOption> getOptions(); static final StandardOption NO; static final StandardOption YES; }