You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/02/02 19:01:32 UTC
svn commit: r617850 - in /commons/proper/math/trunk:
src/java/org/apache/commons/math/random/
src/test/org/apache/commons/math/random/ xdocs/
Author: luc
Date: Sat Feb 2 10:01:29 2008
New Revision: 617850
URL: http://svn.apache.org/viewvc?rev=617850&view=rev
Log:
throw EOFException when using empty files with ValueServer in replay and digest modes
JIRA: MATH-185
Added:
commons/proper/math/trunk/src/test/org/apache/commons/math/random/emptyFile.txt (with props)
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
commons/proper/math/trunk/src/java/org/apache/commons/math/random/ValueServer.java
commons/proper/math/trunk/src/test/org/apache/commons/math/random/ValueServerTest.java
commons/proper/math/trunk/xdocs/changes.xml
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java?rev=617850&r1=617849&r2=617850&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java Sat Feb 2 10:01:29 2008
@@ -17,6 +17,7 @@
package org.apache.commons.math.random;
+import java.io.EOFException;
import java.io.Serializable;
import java.io.BufferedReader;
import java.io.FileReader;
@@ -130,6 +131,9 @@
da.computeStats();
} catch (Exception e) {
throw new IOException(e.getMessage());
+ }
+ if (sampleStats.getN() == 0) {
+ throw new EOFException("URL " + url + " contains no data");
}
in = new BufferedReader(new InputStreamReader(url.openStream()));
fillBinStats(in);
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/random/ValueServer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/random/ValueServer.java?rev=617850&r1=617849&r2=617850&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/random/ValueServer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/random/ValueServer.java Sat Feb 2 10:01:29 2008
@@ -17,6 +17,7 @@
package org.apache.commons.math.random;
import java.io.BufferedReader;
+import java.io.EOFException;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.URL;
@@ -308,7 +309,9 @@
* replay file open.</p>
* <p>
* The <code>valuesFileURL</code> will be closed and reopened to wrap around
- * from EOF to BOF if EOF is encountered.</p>
+ * from EOF to BOF if EOF is encountered. EOFException (which is a kind of
+ * IOException) may still be thrown if the <code>valuesFileURL</code> is
+ * empty.</p>
*
* @return next value from the replay file
* @throws IOException if there is a problem reading from the file
@@ -321,9 +324,12 @@
resetReplayFile();
}
if ((str = filePointer.readLine()) == null) {
+ // we have probably reached end of file, wrap around from EOF to BOF
closeReplayFile();
resetReplayFile();
- str = filePointer.readLine();
+ if ((str = filePointer.readLine()) == null) {
+ throw new EOFException("URL " + valuesFileURL + " contains no data");
+ }
}
return Double.valueOf(str).doubleValue();
}
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/random/ValueServerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/random/ValueServerTest.java?rev=617850&r1=617849&r2=617850&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/random/ValueServerTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/random/ValueServerTest.java Sat Feb 2 10:01:29 2008
@@ -18,6 +18,8 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+
+import java.io.EOFException;
import java.net.URL;
import org.apache.commons.math.RetryTestCase;
@@ -98,7 +100,35 @@
fail("Expecting IllegalStateException");
} catch (IllegalStateException ex) {;}
}
-
+
+ public void testEmptyReplayFile() {
+ try {
+ URL url = getClass().getResource("emptyFile.txt");
+ vs.setMode(ValueServer.REPLAY_MODE);
+ vs.setValuesFileURL(url);
+ vs.getNext();
+ fail("an exception should have been thrown");
+ } catch (EOFException eof) {
+ // expected behavior
+ } catch (Exception e) {
+ fail("wrong exception caught");
+ }
+ }
+
+ public void testEmptyDigestFile() {
+ try {
+ URL url = getClass().getResource("emptyFile.txt");
+ vs.setMode(ValueServer.DIGEST_MODE);
+ vs.setValuesFileURL(url);
+ vs.computeDistribution();
+ fail("an exception should have been thrown");
+ } catch (EOFException eof) {
+ // expected behavior
+ } catch (Exception e) {
+ fail("wrong exception caught");
+ }
+ }
+
/**
* Test ValueServer REPLAY_MODE using values in testData file.<br>
* Check that the values 1,2,1001,1002 match data file values 1 and 2.
Added: commons/proper/math/trunk/src/test/org/apache/commons/math/random/emptyFile.txt
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/random/emptyFile.txt?rev=617850&view=auto
==============================================================================
(empty)
Propchange: commons/proper/math/trunk/src/test/org/apache/commons/math/random/emptyFile.txt
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/proper/math/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/xdocs/changes.xml?rev=617850&r1=617849&r2=617850&view=diff
==============================================================================
--- commons/proper/math/trunk/xdocs/changes.xml (original)
+++ commons/proper/math/trunk/xdocs/changes.xml Sat Feb 2 10:01:29 2008
@@ -139,6 +139,10 @@
<action dev="luc" type="fix" issue="MATH-182">
Add integer overflow checks in Fraction constructor using double parameter.
</action>
+ <action dev="luc" type="fix" issue="MATH-185">
+ Throw EOFException when using empty files with ValueServer in replay and
+ digest modes.
+ </action>
</release>
<release version="1.1" date="2005-12-17"
description="This is a maintenance release containing bug fixes and enhancements.