Coverage Report - org.mule.examples.loanbroker.tests.AbstractAsynchronousLoanBrokerTestCase
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractAsynchronousLoanBrokerTestCase
0%
0/40
0%
0/6
1.5
 
 1  
 /*
 2  
  * $Id: AbstractAsynchronousLoanBrokerTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.examples.loanbroker.tests;
 12  
 
 13  
 import org.mule.examples.loanbroker.messages.Customer;
 14  
 import org.mule.examples.loanbroker.messages.CustomerQuoteRequest;
 15  
 import org.mule.examples.loanbroker.messages.LoanQuote;
 16  
 import org.mule.extras.client.MuleClient;
 17  
 import org.mule.providers.NullPayload;
 18  
 import org.mule.umo.UMOMessage;
 19  
 
 20  
 /**
 21  
  * Tests the Loan Broker application asynchronously.  Note that a simple thread delay is used to wait for the 
 22  
  * incoming responses to arrive.  This may or may not be sufficient depending on external factors (processor 
 23  
  * speed, logging detail, etc.).  To make the tests reliable, a more accurate mechanism should be employed 
 24  
  * (notifications, thread-safe counter, etc.)
 25  
  */
 26  0
 public abstract class AbstractAsynchronousLoanBrokerTestCase extends AbstractLoanBrokerTestCase
 27  
 {
 28  
     // @Override
 29  
     protected int getNumberOfRequests()
 30  
     {
 31  0
         return 100;
 32  
     }
 33  
     
 34  
     /**
 35  
      * Milliseconds to wait after sending each message in order for the thread to "catch up" with the test.
 36  
      */
 37  
     protected int getDelay()
 38  
     {
 39  0
         return 3000;
 40  
     }
 41  
     
 42  
     public void testSingleLoanRequest() throws Exception
 43  
     {
 44  0
         MuleClient client = new MuleClient();
 45  0
         Customer c = new Customer("Ross Mason", 1234);
 46  0
         CustomerQuoteRequest request = new CustomerQuoteRequest(c, 100000, 48);
 47  
         // Send asynchronous request
 48  0
         client.dispatch("CustomerRequests", request, null);
 49  
         
 50  
         // Wait for asynchronous response
 51  0
         UMOMessage result = client.receive("CustomerResponses", getDelay());
 52  0
         assertNotNull("Result is null", result);
 53  0
         assertFalse("Result is null", result.getPayload() instanceof NullPayload);
 54  0
         assertTrue("Result should be LoanQuote but is " + result.getPayload().getClass().getName(), 
 55  
                     result.getPayload() instanceof LoanQuote);
 56  0
         LoanQuote quote = (LoanQuote)result.getPayload();
 57  0
         assertTrue(quote.getInterestRate() > 0);
 58  0
     }
 59  
 
 60  
     public void testLotsOfLoanRequests() throws Exception
 61  
     {
 62  0
         MuleClient client = new MuleClient();
 63  0
         Customer c = new Customer("Ross Mason", 1234);
 64  0
         CustomerQuoteRequest[] requests = new CustomerQuoteRequest[3];
 65  0
         requests[0] = new CustomerQuoteRequest(c, 100000, 48);
 66  0
         requests[1] = new CustomerQuoteRequest(c, 1000, 12);
 67  0
         requests[2] = new CustomerQuoteRequest(c, 10, 24);
 68  
 
 69  0
         long start = System.currentTimeMillis();
 70  
 
 71  0
         int numRequests = getNumberOfRequests();
 72  0
         int i = 0;
 73  
         UMOMessage result;
 74  
         try
 75  
         {
 76  0
             for (i = 0; i < numRequests; i++)
 77  
             {
 78  0
                 client.dispatch("CustomerRequests", requests[i % 3], null);
 79  
             }
 80  0
             for (i = 0; i < numRequests; i++)
 81  
             {
 82  0
                 result = client.receive("CustomerResponses", getDelay() * numRequests);
 83  0
                 assertNotNull("Result is null", result);
 84  0
                 assertFalse("Result is null", result.getPayload() instanceof NullPayload);
 85  0
                 assertTrue("Result should be LoanQuote but is " + result.getPayload().getClass().getName(), 
 86  
                             result.getPayload() instanceof LoanQuote);
 87  0
                 LoanQuote quote = (LoanQuote)result.getPayload();
 88  0
                 assertTrue(quote.getInterestRate() > 0);
 89  
             }
 90  0
         }
 91  
         finally
 92  
         {
 93  0
             long el = System.currentTimeMillis() - start;
 94  0
             System.out.println("Total running time was: " + el + "ms");
 95  0
             System.out.println("Requests processed was: " + i);
 96  0
             int mps = (int)(numRequests/((double)el/(double)1000));
 97  0
             System.out.println("Msg/sec: " + mps + " (no warm up)");
 98  0
         }
 99  0
     }
 100  
 }