View Javadoc

1   /*
2    * $Id: AbstractStreamingDownloadMule1389TestCase.java 22463 2011-07-20 07:58:06Z justin.calleja $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import org.junit.Test;
17  import org.mule.api.MuleMessage;
18  import org.mule.api.endpoint.InboundEndpoint;
19  import org.mule.module.client.MuleClient;
20  import org.mule.tck.AbstractServiceAndFlowTestCase;
21  import org.mule.transport.tcp.integration.AbstractStreamingCapacityTestCase;
22  
23  public abstract class AbstractStreamingDownloadMule1389TestCase extends AbstractServiceAndFlowTestCase
24  {    
25      public AbstractStreamingDownloadMule1389TestCase(ConfigVariant variant, String configResources)
26      {
27          super(variant, configResources);
28      }
29  
30      @Test
31      public void testDownloadSpeed() throws Exception
32      {
33          MuleClient client = new MuleClient(muleContext);
34          long now = System.currentTimeMillis();
35          MuleMessage result = client.send(((InboundEndpoint) client.getMuleContext().getRegistry().lookupObject("inTestComponent")).getAddress(),
36              "request", null);
37          assertNotNull(result);
38          assertNotNull(result.getPayload());
39          assertEquals(InputStreamSource.SIZE, result.getPayloadAsBytes().length);
40          long then = System.currentTimeMillis();
41          double speed = InputStreamSource.SIZE / (double) (then - now) * 1000 / AbstractStreamingCapacityTestCase.ONE_MB;
42          logger.info("Transfer speed " + speed + " MB/s (" + InputStreamSource.SIZE + " B in " + (then - now) + " ms)");
43      }
44  
45  }