Shanmuganathan(Shan) Srinivasan

Thursday, September 18, 2014

Grails Intellij common fixes for spurious, crazy build behaviours and other issues.

GRAILS:

Try deleting the work folder and rerun the build

<Project path>\target\work folder.

Above should solve most of the issues if it didnt

Try also deleting the cache folder or the whole contents
<homedirectory>/.grails /version

INTELLIJ:

For all crazy intellij issues,

Click on File --> Invalidate Caches/Restart

Thursday, May 15, 2014

MD5 checksum comparison of two files looking for changes

Environment:
  Java et. al.

Issue:
  We are in process of migrating from one framework to another, so we had to keep two copies of same file conforming two different frameworks until we complete the whole migration. but there is active development going on in the same code base. We need to make sure if the change made in one file belonging to one framework is also made in similar file when applicable.

Solution:
Write a testcase that checks if any one of the files is changed, indicate user to make sure both are synced and update the latest checksum in the Enum file for the testcase to pass.

Below is the Enum for the list of dependent files and Test case 


//Enum that has master list of dependent files and corresponding checksums
 public enum Fmwk1Fmwk2FilesEnum {

    /**
     * This has to be manually updated after making sure the Fmwk1 and Fmwk2 files are synced if changed.
     */
    HEADER_TILE("src\\main\\webapp\\common\\tiles\\header_tile_fmwk1.jsp",
"src\\main\\webapp\\common\\tiles\\header_tile.jsp",
"375b53df14a8c0170ee2baa51408338a","dc31d9355a5a74333a146ee1541e53c1"),
    LAYOUT_SIMPLE("src\\main\\webapp\\common\\layouts\\layout_simple_fmwk1.jsp",
"src\\main\\webapp\\common\\layouts\\layout_simple.jsp",
"8cc127cf58db6ecfc57c275eef4fc76e","cd6396dca9abbb9243402f222f8c98b8"),


/***
* TEST CASE to check if the files have been changed
***/
/**
 *
 * The purpose of this test to keep the new Fmwk1 files to be in sync with Older Fmwk2 files.
 * This test need to be deleted once we move to 100% Fmwk1 and we should not have any older
 * Fmwk2 files until then every time any of the associated file is modified it is expected that both
 * the files are synced in other words if any change is done in one file it should be done in other as well and
 * corresponding checksum needs to be updated.
* Respective enums also need to be updated once we delete the files while we migrate to new framework
 *
 */
                final String fmwk1MD5 = DigestUtils.md5Hex(new FileInputStream(fmwk1File));

                assertFalse("Fmwk1 File " + fmwk1Fmwk2FilesEnum.getFmwk1File() + " has been changed, make sure the changes are synced in " + fmwk1Fmwk2FilesEnum.getFmwk2File() +
                                ". If synced fine, update the checksum in the Enum Fmwk1Fmwk2FilesEnum. Updated MD5 " + fmwk1MD5,
                        !fmwk1MD5.equals(fmwk1Fmwk2FilesEnum.getFmwk1CheckSum())
                );

Monday, May 12, 2014

Grails grailsApplication null in Service , Controller

Environment:
  Grails on tomcat deployed as war

Reported Issue:
  grailsApplication is null

Error Messages:
Cannot get property 'config' on null object

Cause:
    The service is created in resources.groovy(BeanBuilder) rather than the default behavior of grails. This was done to inject a custom resource to the service.

Solution:
  Inject the grailsApplication in resources.groovy along with other dependencies.

Grails Datasource connection issue

Environment:
  Grails on tomcat deployed as war

Reported Issue:
   Application looses database connections every 3-5 days

Error Messages:
com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)

ERROR Could not toggle autocommit (JDBCTransaction.toggleAutoCommit)
com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed

Cause:
     Once a Database Connection Reset or Network disconnection happens, application does not recover DB connections automatically. Throws either Connection Reset or Connection is closed error  The DB connections are not pooled by default.

Solution:
dataSource {
    driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    dialect = "org.hibernate.dialect.SQLServer2008Dialect"
     pooled = true
}

Also use other configurations related connection pooling as specified in Grails documentation