View Javadoc

1   /*
2    * $Id: AbstractStreamingDownloadMule1389TestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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.transport.tcp.integration.AbstractStreamingCapacityTestCase;
18  
19  public abstract class AbstractStreamingDownloadMule1389TestCase extends DynamicPortTestCase
20  {
21      public void testDownloadSpeed() throws Exception
22      {
23          MuleClient client = new MuleClient(muleContext);
24          long now = System.currentTimeMillis();
25          MuleMessage result = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("inTestComponent")).getAddress(),
26              "request", null);
27          assertNotNull(result);
28          assertNotNull(result.getPayload());
29          assertEquals(InputStreamSource.SIZE, result.getPayloadAsBytes().length);
30          long then = System.currentTimeMillis();
31          double speed = InputStreamSource.SIZE / (double) (then - now) * 1000 / AbstractStreamingCapacityTestCase.ONE_MB;
32          logger.info("Transfer speed " + speed + " MB/s (" + InputStreamSource.SIZE + " B in " + (then - now) + " ms)");
33      }
34  
35  }