servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lh...@apache.org
Subject svn commit: r723492 - in /servicemix/components/bindings/servicemix-file/trunk/src: main/java/org/apache/servicemix/file/ test/java/org/apache/servicemix/file/ test/resources/
Date Thu, 04 Dec 2008 23:26:24 GMT
Author: lhein
Date: Thu Dec  4 15:26:23 2008
New Revision: 723492

URL: http://svn.apache.org/viewvc?rev=723492&view=rev
Log:
fixed issue SM-1715
The problem was that in archive only one file with a given src name can exist. I modified
the logic, the if the file already exists, a timestamp is put it front of the file name with
a underscore divider:  <System.currentTimeMillis>_<Filename>

Modified:
    servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java
    servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java
    servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java
    servicemix/components/bindings/servicemix-file/trunk/src/test/resources/spring-polling.xml

Modified: servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java?rev=723492&r1=723491&r2=723492&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java
(original)
+++ servicemix/components/bindings/servicemix-file/trunk/src/main/java/org/apache/servicemix/file/FilePollerEndpoint.java
Thu Dec  4 15:26:23 2008
@@ -22,7 +22,6 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Date;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.locks.Lock;
@@ -415,8 +414,14 @@
      * @throws IOException 
      */
     public static void moveFile(File src, File targetDirectory) throws IOException {
-        if (!src.renameTo(new File(targetDirectory, src.getName()))) {
-            throw new IOException("Failed to move " + src + " to " + targetDirectory);
+    	String targetName = src.getName();
+    	File target = new File(targetDirectory, targetName);
+    	if (target.exists() && target.isFile()) {
+    		// the file is already inside archive...we need a new file name
+    		targetName = String.format("%d_%s", System.currentTimeMillis(), src.getName()); //
that should be unique
+    	}
+        if (!src.renameTo(new File(targetDirectory, targetName))) {
+            throw new IOException("Failed to move " + src + " to " + targetDirectory + "
with new name " + targetName);
         }
     }
 }

Modified: servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java?rev=723492&r1=723491&r2=723492&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java
(original)
+++ servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/FilePollerEndpointTest.java
Thu Dec  4 15:26:23 2008
@@ -37,8 +37,8 @@
 
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.executors.Executor;
-import org.apache.servicemix.jbi.util.FileUtil;
 import org.apache.servicemix.tck.mock.MockExchangeFactory;
+import org.apache.servicemix.util.FileUtil;
 
 public class FilePollerEndpointTest extends TestCase {
     

Modified: servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java?rev=723492&r1=723491&r2=723492&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java
(original)
+++ servicemix/components/bindings/servicemix-file/trunk/src/test/java/org/apache/servicemix/file/PollDirectoryTest.java
Thu Dec  4 15:26:23 2008
@@ -28,9 +28,9 @@
 import org.apache.servicemix.components.util.DefaultFileMarshaler;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
-import org.apache.servicemix.jbi.util.FileUtil;
 import org.apache.servicemix.tck.Receiver;
 import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.servicemix.util.FileUtil;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 
@@ -58,7 +58,42 @@
         Receiver receiver = (Receiver) getBean("receiver");
         receiver.getMessageList().assertMessagesReceived(NUMBER);
     }
+    
+    public void testArchive() throws Exception {
+        FileUtil.deleteFile(new File("./target/pollerFiles2/"));
+        
+        // now lets make a request on this endpoint
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
 
+        // lets send a request to be written to a file
+        // which should then be polled
+        for (int i = 0; i < NUMBER; i++) {
+            InOnly me = client.createInOnlyExchange();
+            me.setService(new QName("urn:test", "service2"));
+            NormalizedMessage message = me.getInMessage();
+            message.setProperty(DefaultFileMarshaler.FILE_NAME_PROPERTY, "test.xml");
+            message.setContent(new StringSource("<hello>world</hello>"));
+            client.sendSync(me);
+            try {
+            	Thread.sleep(2000); // wait for file move / delete
+            } catch (InterruptedException e) {
+            	// ignore it
+            }
+        }
+
+        Receiver receiver = (Receiver) getBean("receiver2");
+        receiver.getMessageList().assertMessagesReceived(NUMBER);
+        
+        File dir = new File("./target/archive");
+        assertEquals("The archive is not created...", true, dir.exists() && dir.isDirectory());
+        int numFiles = dir.listFiles().length;
+        assertEquals("There should be " + NUMBER + " files in archive but only " + numFiles
+ " files are found..." , NUMBER, numFiles);
+        dir = new File("target/pollerFiles2");
+        assertEquals("The archive is not created...", true, dir.exists() && dir.isDirectory());
+        numFiles = dir.listFiles().length;
+        assertEquals("There shouldn't be any files in the poll folder...but I found " + numFiles
+ " files there..." , 0, numFiles);
+    }
+   
     protected void assertExchangeWorked(MessageExchange me) throws Exception {
         if (me.getStatus() == ExchangeStatus.ERROR) {
             if (me.getError() != null) {

Modified: servicemix/components/bindings/servicemix-file/trunk/src/test/resources/spring-polling.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-file/trunk/src/test/resources/spring-polling.xml?rev=723492&r1=723491&r2=723492&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-file/trunk/src/test/resources/spring-polling.xml
(original)
+++ servicemix/components/bindings/servicemix-file/trunk/src/test/resources/spring-polling.xml
Thu Dec  4 15:26:23 2008
@@ -29,15 +29,27 @@
       	<sm:component>
             <file:component>
             	<file:endpoints>
-                <file:sender service="test:service"
-                             endpoint="endpoint"
-                             directory="file:target/pollerFiles" />
-              
-                <file:poller service="test:poller"
-                             endpoint="poller"
-                             targetService="test:receiver"
-                             file="file:target/pollerFiles"
-                             period="500" />
+	                <file:sender service="test:service"
+	                             endpoint="endpoint"
+	                             directory="file:target/pollerFiles" />
+	              
+	                <file:poller service="test:poller"
+	                             endpoint="poller"
+	                             targetService="test:receiver"
+	                             file="file:target/pollerFiles"
+	                             period="500" />
+	                             
+                    <file:sender service="test:service2"
+                                 endpoint="endpoint"
+                                 directory="file:target/pollerFiles2/" />
+                  
+                    <file:poller service="test:poller2"
+                                 endpoint="poller"
+                                 targetService="test:receiver2"
+                                 file="file:target/pollerFiles2/"
+                                 deleteFile="true"
+                                 archive="file:target/archive"
+                                 period="500" />
             	</file:endpoints>
             </file:component>
         </sm:component>
@@ -49,6 +61,12 @@
         </sm:component>
       </sm:activationSpec>
       
+      <sm:activationSpec id="receiver2" service="test:receiver2">
+        <sm:component>
+          <bean class="org.apache.servicemix.tck.ReceiverComponent" />
+        </sm:component>
+      </sm:activationSpec>
+      
     </sm:activationSpecs>
   </sm:container>
 



Mime
View raw message