View Javadoc

1   /*
2    * $Id: AbstractStreamingDownloadMule1389TestCase.java 19817 2010-10-04 18:10:39Z dzapata $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.tcp.issues;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.endpoint.InboundEndpoint;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.DynamicPortTestCase;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.transport.tcp.integration.AbstractStreamingCapacityTestCase;
19  
20  public abstract class AbstractStreamingDownloadMule1389TestCase extends DynamicPortTestCase
21  {
22      public void testDownloadSpeed() throws Exception
23      {
24          MuleClient client = new MuleClient(muleContext);
25          long now = System.currentTimeMillis();
26          MuleMessage result = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("inTestComponent")).getAddress(),
27              "request", null);
28          assertNotNull(result);
29          assertNotNull(result.getPayload());
30          assertEquals(InputStreamSource.SIZE, result.getPayloadAsBytes().length);
31          long then = System.currentTimeMillis();
32          double speed = InputStreamSource.SIZE / (double) (then - now) * 1000 / AbstractStreamingCapacityTestCase.ONE_MB;
33          logger.info("Transfer speed " + speed + " MB/s (" + InputStreamSource.SIZE + " B in " + (then - now) + " ms)");
34      }
35  
36  }