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