Author: jawi
Date: Wed Sep 18 13:05:55 2013
New Revision: 1524393
URL: http://svn.apache.org/r1524393
Log:
Fixed a possible timing problem in unit tests with flushing of buffers.
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadCallableImpl.java
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandleImpl.java
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandleImplTest.java
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadCallableImpl.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadCallableImpl.java?rev=1524393&r1=1524392&r2=1524393&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadCallableImpl.java
(original)
+++
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadCallableImpl.java
Wed Sep 18 13:05:55 2013
@@ -65,16 +65,22 @@ final class DownloadCallableImpl impleme
long bytesRead = targetLength, totalBytes = -1L;
int read;
- while (!Thread.currentThread().isInterrupted() && (read =
is.read(buffer)) >= 0) {
- os.write(buffer, 0, read);
- // update local administration...
- bytesRead += read;
- totalBytes = is.getContentSize();
-
- if (m_listener != null) {
- m_listener.progress(bytesRead, totalBytes);
+ try {
+ while (!Thread.currentThread().isInterrupted() && (read =
is.read(buffer)) >= 0) {
+ os.write(buffer, 0, read);
+ // update local administration...
+ bytesRead += read;
+ totalBytes = is.getContentSize();
+
+ if (m_listener != null) {
+ m_listener.progress(bytesRead, totalBytes);
+ }
}
}
+ finally {
+ // Ensure that buffers are flushed in our output stream...
+ os.flush();
+ }
boolean stoppedEarly = Thread.currentThread().isInterrupted() ||
(totalBytes > 0L && bytesRead < totalBytes);
if (stoppedEarly) {
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandleImpl.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandleImpl.java?rev=1524393&r1=1524392&r2=1524393&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandleImpl.java
(original)
+++
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DownloadHandleImpl.java
Wed Sep 18 13:05:55 2013
@@ -43,7 +43,7 @@ class DownloadHandleImpl implements Down
DownloadHandleImpl(DownloadHandlerImpl handler, URL url) {
m_handler = handler;
m_url = url;
-
+
m_file = new File(m_handler.getDataLocation(), getDownloadFileName());
}
@@ -78,18 +78,16 @@ class DownloadHandleImpl implements Down
@Override
public void stop() {
Future<?> future = m_future;
- if (future != null) {
- if (!future.isDone()) {
- future.cancel(true /* mayInterruptIfRunning */);
- }
- }
m_future = null;
+ if (future != null && !future.isDone()) {
+ future.cancel(true /* mayInterruptIfRunning */);
+ }
}
final ConnectionHandler getConnectionHandler() {
return m_handler.getConnectionHandler();
}
-
+
final File getDownloadFile() {
return m_file;
}
Modified:
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandleImplTest.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandleImplTest.java?rev=1524393&r1=1524392&r2=1524393&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandleImplTest.java
(original)
+++
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DownloadHandleImplTest.java
Wed Sep 18 13:05:55 2013
@@ -207,7 +207,8 @@ public class DownloadHandleImplTest exte
long firstFileLength = file.length();
assertTrue(file.exists(), file.getName() + " does not exist?!");
- assertTrue(firstFileLength > 0 && firstFileLength < m_contentLength,
"Nothing downloaded yet for " + file.getName() + "?");
+ assertTrue(firstFileLength > 0, "Nothing downloaded yet for " +
file.getName() + "?");
+ assertTrue(firstFileLength < m_contentLength, "Everything downloaded
for " + file.getName() + "?");
final DownloadHandle handle2 =
downloadHandler.getHandle(m_testContentURL);
// Resume the download, but stop it after reading the first chunk of
data...
@@ -228,7 +229,8 @@ public class DownloadHandleImplTest exte
long secondFileLength = file.length();
- assertTrue(secondFileLength > firstFileLength && secondFileLength <
m_contentLength, "Nothing downloaded yet for " + file.getName() + "?");
+ assertTrue(secondFileLength > firstFileLength, "Nothing downloaded yet
for " + file.getName() + "?");
+ assertTrue(secondFileLength < m_contentLength, "Everything downloaded
for " + file.getName() + "?");
DownloadHandle handle3 = downloadHandler.getHandle(m_testContentURL);
// Resume the download, and finish it...