You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2017/02/09 22:34:10 UTC

svn commit: r1782409 - /commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServer.java

Author: sebb
Date: Thu Feb  9 22:34:09 2017
New Revision: 1782409

URL: http://svn.apache.org/viewvc?rev=1782409&view=rev
Log:
Allow customisation of the behaviour

Modified:
    commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServer.java

Modified: commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServer.java?rev=1782409&r1=1782408&r2=1782409&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServer.java (original)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/tftp/TFTPServer.java Thu Feb  9 22:34:09 2017
@@ -461,7 +461,7 @@ public class TFTPServer implements Runna
         {
             try
             {
-                transferTftp_ = new TFTP();
+                transferTftp_ = newTFTP();
 
                 transferTftp_.beginBufferedOps();
                 transferTftp_.setDefaultTimeout(socketTimeout_);
@@ -575,7 +575,7 @@ public class TFTPServer implements Runna
 
                         lastSentData = new TFTPDataPacket(trrp.getAddress(), trrp.getPort(), block,
                                 temp, 0, readLength);
-                        transferTftp_.bufferedSend(lastSentData);
+                        sendData(transferTftp_, lastSentData); // send the data
                     }
 
                     answer = null;
@@ -716,7 +716,7 @@ public class TFTPServer implements Runna
                 }
 
                 TFTPAckPacket lastSentAck = new TFTPAckPacket(twrp.getAddress(), twrp.getPort(), 0);
-                transferTftp_.bufferedSend(lastSentAck);
+                sendData(transferTftp_, lastSentAck); // send the data
 
                 while (true)
                 {
@@ -791,7 +791,7 @@ public class TFTPServer implements Runna
                         }
 
                         lastSentAck = new TFTPAckPacket(twrp.getAddress(), twrp.getPort(), block);
-                        transferTftp_.bufferedSend(lastSentAck);
+                        sendData(transferTftp_, lastSentAck); // send the data
                         if (dataLength < TFTPDataPacket.MAX_DATA_LENGTH)
                         {
                             // end of stream signal - The tranfer is complete.
@@ -946,4 +946,18 @@ public class TFTPServer implements Runna
     {
         this.logError_ = logError;
     }
+
+    /*
+     * Allow test code to customise the TFTP instance 
+     */
+    TFTP newTFTP() {
+        return new TFTP();
+    }
+
+    /*
+     * Also allow customisation of sending data/ack so can generate errors if needed
+     */
+    void sendData(TFTP tftp, TFTPPacket data) throws IOException {
+        tftp.bufferedSend(data);
+    }
 }