Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: SftpPoolingFunctionalTestCase.java 23812 2012-02-03 13:17:37Z asequeira $
   * --------------------------------------------------------------------------------------
   * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
   *
   * The software in this package is published under the terms of the CPAL v1.0
   * license, a copy of which has been included with this distribution in the
   * LICENSE.txt file.
   */
 
 package org.mule.transport.sftp;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 
 import java.util.List;
 
 import org.junit.Test;
SftpPoolingFunctionalTestCase tests sending an receiving multiple small text files.
 
 {
 
     private static final long TIMEOUT = 30000;
 
     private List<StringsendFiles;
     private List<StringreceiveFiles;
 
     private int nrOfFiles = 100;
 
     public SftpPoolingFunctionalTestCase(ConfigVariant variantString configResources)
     {
         super(variantconfigResources);
     }
 
     @Parameters
     public static Collection<Object[]> parameters()
     {
         return Arrays.asList(new Object[][]{
             {."mule-pooling-test-config-service.xml"},
             {."mule-pooling-test-config-flow.xml"}
         });
     }
 
     @Test
     public void testSftpConfig() throws Exception
     {
         SftpConnector c = (SftpConnector.getRegistry().lookupConnector("sftp-pool");
         assertEquals(3, c.getMaxConnectionPoolSize());
         assertEquals(truec.useConnectionPool());
 
         SftpConnector c2 = (SftpConnector.getRegistry().lookupConnector("sftp-no-pool");
         assertEquals(falsec2.useConnectionPool());
     }
 
     @Test
     public void testSendAndReceiveMultipleFiles() throws Exception
     {
          = new ArrayList<String>();
 
         for (int i = 1; i <= i++)
         {
             .add("file" + i);
         }
         sendAndReceiveFiles();
     }
 
     protected void sendAndReceiveFiles() throws Exception
     {
         final CountDownLatch latch = new CountDownLatch(.size());
         final AtomicInteger loopCount = new AtomicInteger(0);
 
         MuleClient client = new MuleClient();
 
          = new ArrayList<String>();
 
         EventCallback callback = new EventCallback()
         {
             @Override
             public void eventReceived(MuleEventContext contextObject componentthrows Exception
             {
                String filename = context.getMessage().getProperty(.,
                    null);
                SftpInputStream inputStream = null;
                try
                {
                    .info("called " + loopCount.incrementAndGet() + " times. Filename = " + filename);
                    // This is not thread safe! (it should be safe if
                    // synchronous="true" is used)
                    // FunctionalTestComponent ftc = (FunctionalTestComponent)
                    // component;
                    // inputStream = (SftpInputStream) ftc.getLastReceivedMessage();
                    // Use this instead!
                    inputStream = (SftpInputStreamcontext.getMessage().getPayload();
                    String o = IOUtils.toString(inputStream);
                    if (.contains(o))
                    {
                        .info("The received file was added. Received: '" + o + "'");
                        .add(o);
                    }
                    else
                    {
                        fail("The received file was not sent. Received: '" + o + "'");
                    }
                    latch.countDown();
                }
                catch (IOException e)
                {
                    .error("Error occured while processing callback for file=" + filenamee);
                    throw e;
                }
                finally
                {
                    if (inputStream != null)
                    {
                        inputStream.close();
                    }
                }
            }
        };
        getFunctionalTestComponent("receiving").setEventCallback(callback);
        for (String sendFile : )
        {
            HashMap<StringStringprops = new HashMap<StringString>(1);
            props.put(.sendFile + ".txt");
            client.dispatch("vm://test.upload"sendFileprops);
        }
        latch.await(.);
        .debug("Number of files sent: " + .size());
        .debug("Number of files received: " + .size());
        // This makes sure we received the same number of files we sent, and that
        // the content was a match (since only matched content gets on the
        // receiveFiles ArrayList)
        assertTrue("expected : " + .size() + " but got " + .size(),
            .size() == .size());
    }
New to GrepCode? Check out our FAQ X