jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juan Pedro López Sáez <j...@altiria.com>
Subject Strange problem
Date Thu, 22 Jan 2004 10:22:55 GMT
Hello everybody.

I am experiencing a quite strange problem.

I'm testing a servlet using: 

Cactus-13-1.5
Tomcat 4.1.27
J2SE 1.4.2_01
J2EE 1.3.1
Ant 1.5.1

I use the cactus ant tasks and everything seems to be properly
configured. My Cactus Test class extends the ServletTestCase class.

If I run my tests in a windows platform, everything is ok.
If I run my tests in a Linux Debian platform, there are no errors the
very first time at a day, but next executions show me the same error. I
guess it has something to do with the inactivity period at night. The
first test in my test suite (I just have one) throws the following
exception:

[cactus] Testcase:
testMultdestOk(com.altiria.wasp.push.gateway.TestPushWebappGateway):      Caused an ERROR
   [cactus] Failed to get the test results at
[http://localhost:8081/api/ServletRedirector]
   [cactus] org.apache.cactus.util.ChainedRuntimeException: Failed to
get the test results at [http://localhost:8081/api/ServletRedirector]
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:131)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:222)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runWebTest(WebClientTestCaseDelegate.java:333)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runGenericTest(WebClientTestCaseDelegate.java:281)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runTest(WebClientTestCaseDelegate.java:257)
   [cactus]     at
org.apache.cactus.ServletTestCase.runCactusTest(ServletTestCase.java:300)
   [cactus]     at
org.apache.cactus.ServletTestCase.runBare(ServletTestCase.java:263)
   [cactus] org.apache.cactus.client.ParsingException: Not a valid
response [500 Error Interno del Servidor]
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.callGetResult(DefaultHttpClient.java:249)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:126)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:222)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runWebTest(WebClientTestCaseDelegate.java:333)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runGenericTest(WebClientTestCaseDelegate.java:281)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runTest(WebClientTestCaseDelegate.java:257)
   [cactus]     at
org.apache.cactus.ServletTestCase.runCactusTest(ServletTestCase.java:300)
   [cactus]     at
org.apache.cactus.ServletTestCase.runBare(ServletTestCase.java:263)


No matters what the first test is. It is the same situation if I change
the test execution order in the test suite. 

The rest of the test suite is correcly executed.

Every test has the same structure:

  public void beginMyTest(WebRequest theRequest)
    {

log.debug("Enter beginMyTest");

        theRequest.addHeader("Content-type",
"application/x-www-form-urlencoded; charset=UTF-8");
        theRequest.addParameter("cmd",
"sendsms",WebRequest.POST_METHOD);
        
    }

   public void testMyTest() throws Exception{
log.debug("Enter testMyTest");

try{ 
MyServletToTest servlet = new MyServletToTest();
servlet.init(config);

// Call method to test
servlet.doPost(request,response);
}catch(Exception e){
log.fatal("Exception in test",e);
} 
}


    public void endMyTest(WebResponse theResponse)
        throws Exception
    {
log.debug("Enter endMyTest");

        String expected = "expected response";
        
        String result = theResponse.getText();

database = System.getProperty("myDatabasePath");
log.info("database to test results: "+database);

        assertEquals(expected, result);
        // Fetch database data after executing your code
        IDataSet databaseDataSet = getConnection().createDataSet();
        ITable actualTable = databaseDataSet.getTable("TABLE_TO_TEST");
        
        // Load expected data from an XML dataset
        IDataSet expectedDataSet = new FlatXmlDataSet(new
InputStreamReader(getClass().getResourceAsStream("/expectedTablesxml")));

        ITable expectedTable =
expectedDataSet.getTable("TABLE_TO_TEST");
        

        // Assert actual database table match expected table

        Assertion.assertEquals(expectedTable,new
CompositeTable(expectedTable.getTableMetaData(), actualTable));
        
    }

The init method of my servlet just gets a reference to a DataSource
pointing to my database:

public void init(ServletConfig config) throws ServletException {
        super.init(config);
       try {
//Context ctx = new InitialContext();
//dataSource = (DataSource)ctx.lookup("java:comp/env/jdbc/MktsmsDb");

    Context init = new InitialContext();
    Context ctx = (Context) init.lookup("java:comp/env");
      dataSource = (DataSource) ctx.lookup("jdbc/myDb");

    if(dataSource == null ) {
log.fatal("Init: dataSource ERROR");
    }
    else {
log.info("Init: dataSource OK");
    }

}
catch (NamingException ex) {
    throw new ServletException("Cannot retrieve
java:/jdbc/MktsmsDb",ex);
}

    }

Sometimes, there are also some random FAILURES in some tests, but of
course those tests shouldn't fail because they have been previously
checked in the windows platform.

Does anybody know what can be happening?

Thank you,

Juan Pedro López.


Mime
View raw message