1   /*
2    * $Id: JdbcConnectionTestCase.java 10961 2008-02-22 19:01:02Z dfeist $
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.test.integration.transport.jdbc;
12  
13  
14  import org.mule.api.endpoint.EndpointBuilder;
15  import org.mule.api.endpoint.InboundEndpoint;
16  import org.mule.api.service.Service;
17  import org.mule.api.transport.Connector;
18  import org.mule.endpoint.EndpointURIEndpointBuilder;
19  import org.mule.tck.testmodels.fruit.Orange;
20  import org.mule.transport.SimpleRetryConnectionStrategy;
21  import org.mule.transport.jdbc.JdbcConnector;
22  
23  import javax.sql.DataSource;
24  
25  /**
26   * This test must be run manually. See the comments inline in testReconnection
27   */
28  public class JdbcConnectionTestCase extends AbstractJdbcFunctionalTestCase
29  {
30  
31      protected JdbcConnector connector;
32  
33      protected void emptyTable() throws Exception
34      {
35          // TODO this overrides super.emptyTable() - is this correct?
36          // the entire test seems to be incomplete, see the comments below..
37      }
38  
39      public Connector createConnector() throws Exception
40      {
41          connector = (JdbcConnector)super.createConnector();
42          SimpleRetryConnectionStrategy strategy = new SimpleRetryConnectionStrategy();
43          strategy.setRetryCount(10);
44          strategy.setRetryFrequency(1000);
45          strategy.setDoThreading(true);
46          connector.setConnectionStrategy(strategy);
47          return connector;
48      }
49  
50      public void testReconnection() throws Exception
51      {
52  
53          Service service = getTestService("anOrange", Orange.class);
54          service.setModel(model);
55          muleContext.getRegistry().registerService(service);
56          EndpointBuilder endpointBuilder = new EndpointURIEndpointBuilder("jdbc://test?sql=SELECT * FROM TABLE", muleContext);
57          endpointBuilder.setName("test");
58          endpointBuilder.setConnector(connector);
59          InboundEndpoint endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint(
60              endpointBuilder);
61          muleContext.start();
62          connector.registerListener(service, endpoint);
63  
64          // The derbydb instance should be put offline before starting test
65          // The receiver should try to connect to the database
66          //
67          // Then put derbydb online.
68          // Check that the receiver reconnect and polls the database
69          //
70          // Put derbydb offline.
71          // The receiver should try to connect to the database.
72          Thread.sleep(1000);
73      }
74      
75      protected DataSource createDataSource() throws Exception
76      {
77          return createClientDataSource();
78      }
79  
80  }