Saturday, August 31, 2013

JDBC broken pike error

Error

 [2013-08-31 05:41:15,462] [ERROR] [SimpleAsyncTaskExecutor-2] [TaskletStep] [438]: JobRepository failure forcing exit with unknown status
org.springframework.dao.DataAccessResourceFailureException: PreparedStatementCallback; SQL [UPDATE BATCH_STEP_EXECUTION_CONTEXT SET SHORT_CONTEXT = ?, SERIALIZED_CONTEXT = ? WHERE STEP_EXECUTION_ID = ?]; Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: Broken pipe

STACKTRACE:

java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2689)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2618)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1551)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:930)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1159)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1076)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1061)
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:106)
        at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:824)
        at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:818)

Cause:
MySQL connections are getting terminated by MySQL before they have been released by the connection pool. Then the next time you try to get a connection from the pool, you'll get a dead connection which will give a "broken pipe" error, as in the above stack trace.

Resolution

Evict the idle session before MySQL does. Retrying the connection, will simply create a new connection. The following parameters can be added to the Jira datasource connection URL in Confluence's server.xml for the same:
minEvictableIdleTimeMillis=21600000 (evict after 6 hours of inactivity, given that MySQL has a default timeout of 8 hours for idle database connections after which it closes the connection)
timeBetweenEvictionRunsMillis=1800000 (run the evicter every 30 minutes)
numTestsPerEviction=-1 (check every connection)

Tuesday, February 5, 2013

svn tips

  • Command to view svn change log but stop on copy

svn log --stop-on-copy https://mysvn.net/root/myproject/trunk


  • Command to to merge from a branch

svn merge -r 73526:75424 https://mysvn.net/root/myproject/branches/5.41.x -x --ignore-eol-style --accept postpone

--ignore-eol-style -> Ignores end of line style

--accept postpone -> merges by postponing conflicts, they can be resolved manually once merge is done



  • Summarize changes between revisions
 svn diff -r 70837:HEAD --summarize

  • Get information about a file
 svn info https://mysvn.net/root/myproject/brances/5.41.x/Sample.java

  • Create a new branch using svn copy
svn copy https://mysvn.net/root/myproject/trunk https://mysvn.net/root/myproject/branches/project-branch-q2 -m "sample project branch"





Wednesday, January 16, 2013

Screen Capture using PhantomJS, GhostDriver, Selenium Hub

This document takes notes about setting up PhantomJS headless browser with Ghost Driver and Selenium grid Server. Many thanks to phantomjs and gostdriver team, I am using their tutorial to build this example.

PhantomJS is a headless webkit engine that is capable of executing the test scripts in headless mode. Ghost driver implements remote wire protocol and enhances PhantomJS to be used with selenium and remote web driver. This is an excellent open source product, has good community activity and found it to be robust in my initial tests. I researched extensively on google to find a tools that can take a screen capture of a web page in headless mode and finally narrowed upon this tool.

The setup steps are explained as below:

  • Setup Selenium remote server
    1. Download selenium standalone jar from http://code.google.com/p/selenium/downloads/list
    2. Run selenium grid using the below command
      java -jar selenium-server-standalone-2.28.0.jar -role hub -timeout=20 -browserTimeout=25
  • Setup Phantomjs ghost driver
  1. Download phantomjs for the appropriate platform from the url http://phantomjs.org/download.html
  2. Extract phantomjs zip file in to a specific folder
  3. Cd to the extracted folder/bin directory
  4. Run phantom js using the below command, note multiple instances of phantomjs can be run tied to different ports
sudo ./phantomjs --webdriver=9192 --max-disk-cache-size=10240 --disk-cache=true --webdriver-selenium-grid-hub=http://127.0.0.1:4444
sudo ./phantomjs --webdriver=9191 --max-disk-cache-size=10240 --disk-cache=true --webdriver-selenium-grid-hub=http://127.0.0.1:4444

Sample Client to access the hub and take screen capture

public class SeleniumScreenCapture {
    public static String[] links = {
            "www.google.com"    };



    public static void main(String args[]) throws Exception {
        /**
         * run the server using the below command
         * java -jar selenium-server-standalone-2.28.0.jar -port 9080 -Dwebdriver.chrome.driver=E:/config/chromedriver.exe
         */
        SeleniumScreenCapture scc = new SeleniumScreenCapture();
        scc.testGhostDriver();
    }

    public void testGhostDriver() throws Exception {

        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setJavascriptEnabled(true);
        desiredCapabilities.setCapability("takesScreenshot", true);

//        desiredCapabilities.setCapability(PhantomJSDriverService.P, new String[] {
//                "--web-security=false",
//                "--ssl-protocol=any",
//                "--ignore-ssl-errors=true"
//        });

        String link = "www.google.com";


        int count = 1;
        //for (String link : links) {
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.73.132:4444/wd/hub"), desiredCapabilities);
        long iStart = System.currentTimeMillis();
        driver.get(link);
        //File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        driver = new Augmenter().augment(driver);
        File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        System.out.println("File:" + srcFile);
        FileUtils.copyFile(srcFile, new File("c:\\tmp\\screenshot_" + count++ + ".png"));
        System.out.println("Single Page Time:" + (System.currentTimeMillis() - iStart));
        driver.quit();
        //}


    }

}

References: 

Ghost Driver Home Page
https://github.com/detro/ghostdriver

Additional links:





 Phantom JS options
https://github.com/ariya/phantomjs/wiki/API-Reference

Tips about using selenium Grid
http://code.google.com/p/robotframework-seleniumlibrary/wiki/UseSeleniumGRIDwithRobotFramework

Tip about setting a zoom factor
http://ariya.ofilabs.com/2012/10/web-page-screenshot-with-phantomjs.html