lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject svn commit: r1519865 - in /lucene/dev/branches/branch_4x: ./ dev-tools/ lucene/ lucene/analysis/ lucene/analysis/icu/src/java/org/apache/lucene/collation/ lucene/backwards/ lucene/benchmark/ lucene/classification/ lucene/classification/src/ lucene/code...
Date Tue, 03 Sep 2013 22:06:00 GMT
Author: hossman
Date: Tue Sep  3 22:05:59 2013
New Revision: 1519865

URL: http://svn.apache.org/r1519865
Log:
SOLR-5206: Fixed OpenExchangeRatesOrgProvider to use refreshInterval correctly (merge r1519858)

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/dev-tools/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/BUILD.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/JRE_VERSION_MIGRATION.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/LICENSE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/MIGRATE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/README.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/SYSTEM_REQUIREMENTS.txt   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationKeyFilterFactory.java
  (props changed)
    lucene/dev/branches/branch_4x/lucene/backwards/   (props changed)
    lucene/dev/branches/branch_4x/lucene/benchmark/   (props changed)
    lucene/dev/branches/branch_4x/lucene/build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/ivy.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/classification/src/   (props changed)
    lucene/dev/branches/branch_4x/lucene/codecs/   (props changed)
    lucene/dev/branches/branch_4x/lucene/common-build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
  (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.cfs.zip
  (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.nocfs.zip
  (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.cfs.zip
  (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.nocfs.zip
  (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSort.java
  (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortDocValues.java
  (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java
  (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java
  (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTotalHitCountCollector.java
  (props changed)
    lucene/dev/branches/branch_4x/lucene/demo/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/grouping/   (props changed)
    lucene/dev/branches/branch_4x/lucene/highlighter/   (props changed)
    lucene/dev/branches/branch_4x/lucene/ivy-settings.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/join/   (props changed)
    lucene/dev/branches/branch_4x/lucene/licenses/   (props changed)
    lucene/dev/branches/branch_4x/lucene/memory/   (props changed)
    lucene/dev/branches/branch_4x/lucene/misc/   (props changed)
    lucene/dev/branches/branch_4x/lucene/module-build.xml   (props changed)
    lucene/dev/branches/branch_4x/lucene/queries/   (props changed)
    lucene/dev/branches/branch_4x/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQuerySort.java
  (props changed)
    lucene/dev/branches/branch_4x/lucene/queryparser/   (props changed)
    lucene/dev/branches/branch_4x/lucene/replicator/   (props changed)
    lucene/dev/branches/branch_4x/lucene/sandbox/   (props changed)
    lucene/dev/branches/branch_4x/lucene/site/   (props changed)
    lucene/dev/branches/branch_4x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_4x/lucene/suggest/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/tools/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/LICENSE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/README.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/SYSTEM_REQUIREMENTS.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/build.xml   (props changed)
    lucene/dev/branches/branch_4x/solr/cloud-dev/   (props changed)
    lucene/dev/branches/branch_4x/solr/common-build.xml   (props changed)
    lucene/dev/branches/branch_4x/solr/contrib/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestConfig.java
  (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/OpenExchangeRatesOrgProviderTest.java
    lucene/dev/branches/branch_4x/solr/example/   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpclient-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpclient-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpcore-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpcore-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpmime-LICENSE-ASL.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/licenses/httpmime-NOTICE.txt   (props changed)
    lucene/dev/branches/branch_4x/solr/scripts/   (props changed)
    lucene/dev/branches/branch_4x/solr/site/   (props changed)
    lucene/dev/branches/branch_4x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_4x/solr/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/solr/webapp/   (props changed)

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1519865&r1=1519864&r2=1519865&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Tue Sep  3 22:05:59 2013
@@ -147,6 +147,9 @@ Bug Fixes
 * SOLR-3852: Fixed ZookeeperInfoServlet so that the SolrCloud Admin UI pages will 
   work even if ZK contains nodes with data which are not utf8 text. (hossman)
 
+* SOLR-5206: Fixed OpenExchangeRatesOrgProvider to use refreshInterval correctly
+  (Catalin, hossman)
+
 Optimizations
 ----------------------
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java?rev=1519865&r1=1519864&r2=1519865&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/schema/OpenExchangeRatesOrgProvider.java
Tue Sep  3 22:05:59 2013
@@ -59,7 +59,8 @@ public class OpenExchangeRatesOrgProvide
   protected static final String DEFAULT_REFRESH_INTERVAL    = "1440";
   
   protected String ratesFileLocation;
-  protected int refreshInterval;
+  // configured in minutes, but stored in seconds for quicker math
+  protected int refreshIntervalSeconds;
   protected ResourceLoader resourceLoader;
   
   protected OpenExchangeRates rates;
@@ -84,7 +85,7 @@ public class OpenExchangeRatesOrgProvide
       throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot get exchange rate;
currency was null.");
     }
     
-    if (rates.getTimestamp() + refreshInterval*60*1000 > System.currentTimeMillis()) {
+    if ((rates.getTimestamp() + refreshIntervalSeconds)*1000 < System.currentTimeMillis())
{
       log.debug("Refresh interval has expired. Refreshing exchange rates.");
       reload();
     }
@@ -159,13 +160,14 @@ public class OpenExchangeRatesOrgProvide
       if (null == ratesFileLocation) {
         throw new SolrException(ErrorCode.SERVER_ERROR, "Init param must be specified: "
+ PARAM_RATES_FILE_LOCATION);
       }
-      refreshInterval = Integer.parseInt(getParam(params.get(PARAM_REFRESH_INTERVAL), DEFAULT_REFRESH_INTERVAL));
+      int refreshInterval = Integer.parseInt(getParam(params.get(PARAM_REFRESH_INTERVAL),
DEFAULT_REFRESH_INTERVAL));
       // Force a refresh interval of minimum one hour, since the API does not offer better
resolution
       if (refreshInterval < 60) {
         refreshInterval = 60;
         log.warn("Specified refreshInterval was too small. Setting to 60 minutes which is
the update rate of openexchangerates.org");
       }
       log.info("Initialized with rates="+ratesFileLocation+", refreshInterval="+refreshInterval+".");
+      refreshIntervalSeconds = refreshInterval * 60;
     } catch (SolrException e1) {
       throw e1;
     } catch (Exception e2) {
@@ -191,7 +193,7 @@ public class OpenExchangeRatesOrgProvide
   /**
    * A simple class encapsulating the JSON data from openexchangerates.org
    */
-  class OpenExchangeRates {
+  static class OpenExchangeRates {
     private Map<String, Double> rates;
     private String baseCurrency;
     private long timestamp;
@@ -261,6 +263,12 @@ public class OpenExchangeRatesOrgProvide
     public long getTimestamp() {
       return timestamp;
     }
+    /** Package protected method for test purposes
+     * @lucene.internal
+     */
+    void setTimestamp(long timestamp) {
+      this.timestamp = timestamp;
+    }
 
     public String getDisclaimer() {
       return disclaimer;

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/OpenExchangeRatesOrgProviderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/OpenExchangeRatesOrgProviderTest.java?rev=1519865&r1=1519864&r2=1519865&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/OpenExchangeRatesOrgProviderTest.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/schema/OpenExchangeRatesOrgProviderTest.java
Tue Sep  3 22:05:59 2013
@@ -30,10 +30,13 @@ import java.util.Map;
  * Tests currency field type.
  */
 public class OpenExchangeRatesOrgProviderTest extends SolrTestCaseJ4 {
+  private final static long HARDCODED_TEST_TIMESTAMP = 1332070464L;
+
   OpenExchangeRatesOrgProvider oerp;
   ResourceLoader loader;
   private final Map<String,String> mockParams = new HashMap<String,String>();
 
+
   @Override
   @Before
   public void setUp() throws Exception {
@@ -50,18 +53,22 @@ public class OpenExchangeRatesOrgProvide
   @Test
   public void testInit() throws Exception {
     oerp.init(mockParams);
+    // don't inform, we don't want to hit any of these URLs
+
     assertEquals("Wrong url", 
                  "open-exchange-rates.json", oerp.ratesFileLocation);
-    assertEquals("Wrong default interval", 1440, oerp.refreshInterval);
+    assertEquals("Wrong default interval", (1440*60), oerp.refreshIntervalSeconds);
 
     Map<String,String> params = new HashMap<String,String>();
     params.put(OpenExchangeRatesOrgProvider.PARAM_RATES_FILE_LOCATION, 
                "http://foo.bar/baz");
     params.put(OpenExchangeRatesOrgProvider.PARAM_REFRESH_INTERVAL, "100");
+
     oerp.init(params);
     assertEquals("Wrong param set url", 
                  "http://foo.bar/baz", oerp.ratesFileLocation);
-    assertEquals("Wrong param interval", 100, oerp.refreshInterval);
+    assertEquals("Wrong param interval", (100*60), oerp.refreshIntervalSeconds);
+
   }
 
   @Test
@@ -76,15 +83,31 @@ public class OpenExchangeRatesOrgProvide
     oerp.init(mockParams);
     oerp.inform(loader);
     assertEquals(81.29D, oerp.getExchangeRate("USD", "JPY"), 0.0D);    
+    assertEquals("USD", oerp.rates.getBaseCurrency());
   }
 
   @Test
   public void testReload() {
+    // reminder: interval is in minutes
+    mockParams.put(OpenExchangeRatesOrgProvider.PARAM_REFRESH_INTERVAL, "100");
     oerp.init(mockParams);
     oerp.inform(loader);
-    assertTrue(oerp.reload());
-    assertEquals("USD", oerp.rates.getBaseCurrency());
-    assertEquals(new Long(1332070464L), new Long(oerp.rates.getTimestamp()));
+
+    // reminder: timestamp is in seconds
+    assertEquals(HARDCODED_TEST_TIMESTAMP, oerp.rates.getTimestamp());
+
+    // modify the timestamp to be "current" then fetch a rate and ensure no reload
+    final long currentTimestamp = (long) (System.currentTimeMillis() / 1000);
+    oerp.rates.setTimestamp(currentTimestamp);
+    assertEquals(81.29D, oerp.getExchangeRate("USD", "JPY"), 0.0D);    
+    assertEquals(currentTimestamp, oerp.rates.getTimestamp());
+
+    // roll back clock on timestamp and ensure rate fetch does reload
+    oerp.rates.setTimestamp(currentTimestamp - (101 * 60));
+    assertEquals(81.29D, oerp.getExchangeRate("USD", "JPY"), 0.0D);    
+    assertEquals("timestamp wasn't reset to hardcoded value, indicating no reload",
+                 HARDCODED_TEST_TIMESTAMP, oerp.rates.getTimestamp());
+
   }
 
   @Test(expected=SolrException.class)



Mime
View raw message