First Time User of AWS Lambda

Following the announcement that AWS Lambda now supports running Java code, I took the chance to try it out. It was pretty straightforward to follow the documentation and see it running.

According to AWS Lambda’s document, there are essentially two ways of creating lambda function handler. One is to implement one of the pre-defined interface classes which requires you to implement “handleRequest” method, the other is to designate your own custom method as the handler.

For the sake of simplicity or my own laziness, I chose implementing AWS Lambda’s interface.

com.amazonaws.services.lambda.runtime.RequestHandler

All it takes is just

public class CurrentTime implements RequestHandler<Request, Response> {

    public Response handleRequest(Request request, Context context) {
        LambdaLogger logger = context.getLogger();

        logger.log(String.format("name:%s, requestId:%s, function:%s, groupName:%s, logStreamName:%s",
            request.getName(), context.getAwsRequestId(), context.getFunctionName(),
            context.getLogGroupName(), context.getLogStreamName()));

        Response response = new Response();
        response.setMessage((new Date()).toString());

        return response;
    }
}

Request and Response classes are custom classes for the input and output. This function simply logs the request (with information from request object as well as context provided by AWS) and return the current timestamp in the response.

The entire project can be found on github.

The instruction to prepare the deployable jar file is also easy to follow. Once you have that, the instruction for deploying the jar file through AWS Lambda console can be found at here.

To create a new Lambda Function

simple-lambda-java-create

Invoke the function

simple-lambda-java-console

Log in the AWS Cloud Watch

simple-lambda-java-cloud-watch

Function List

simple-lambda-java-function-list

What is next?

Maybe try out invoking the function for the AWS Events.

First Time User of AWS Lambda

Heartbeat Hotel – a Spring Boot application with WebSocket and STOMP

As an attempt to understand WebSocket and STOMP, I have come across several blog posts which have illustrated with code sample of how it works. Here I learnt shamelessly copied, pasted and modified their code and created a somehow contrived sample application with functionality remotely related to my current day job.

Continue reading “Heartbeat Hotel – a Spring Boot application with WebSocket and STOMP”

Heartbeat Hotel – a Spring Boot application with WebSocket and STOMP

Developing a REST application using Jersey with JPA and Running it on AWS EC2

Based on what we have built before (see previous post), we are now ready to move further to extend the application to support HTTP GET, POST, PUT and DELETE.

This time we also include JPA for data persistence and use AWS EC2 to deploy the application on Glassfish server.

You can check out the code from Bitbucket.

Continue reading “Developing a REST application using Jersey with JPA and Running it on AWS EC2”

Developing a REST application using Jersey with JPA and Running it on AWS EC2

Developing a REST application using Jersey and running it on AWS Beanstalk

I have had the chance to develop some REST applications at work using Spring in the past and now I would like to try out Jersey to develop a simple REST application which only supports GET operation.

This is not a step-by-step tutorial but rather a place to share what I have.

You can check out the code from Bitbucket.

Continue reading “Developing a REST application using Jersey and running it on AWS Beanstalk”

Developing a REST application using Jersey and running it on AWS Beanstalk

Configure Ant Task for Running SoapUI as JUnit Test

There have been some blog posts regarding running SoapUI using either testrunner.bat or testrunner.sh scripts coming with SoapUI installation. You can choose either bat or sh script based on your OS. But what if I need a solution that works on both Windows and Linux? There  are also posts mentioning reading the SoapUI project file and creating custom JUnit test class to run each test case inside test suite. Is there another way ?

What “testrunner” does is simply to run a Java program (with com.eviware.soapui.tools.SoapUITestCaseRunner as Main class) and generates JUnit reports.  What we can do is to configure an Ant task running the very same Java class with the same configurations.



Ant Task Configuration

Ant target configuration

After running this target, JUnit reports will be generated in the pre-defined directory. If you are using CI server (such as Bamboo), since build plan is configured to look for JUnit results, in the email sent out by Bamboo after each build you can see which test case failed if any.    Voilà

Configure Ant Task for Running SoapUI as JUnit Test

Configure Clover and Sonar Ant Tasks for Code Coverage

Using Cobertura or Clover to generate code coverage reports is a relatively straightforward task as there have been some examples out there to begin with. On the other hand, being able to see coverage number generated by Clover in Sonar console takes a little bit extra configuration as Sonar by default is using Cobertura as code coverage plugin.

Ant Tasks Configuration

Sonar Ant target configuration(with dynamic analysis)

Sonar Ant target configuration(with reuseReports)

Clover Ant target configuration

Ant Command

ant   with.clover   test   clover.report   sonar

(test target is the one to compile source code and run JUnit test, replace it with your own one)

Sonar Server Configuration

There was something I have been missing and kept me from seeing the code coverage number showing up in Sonar console after running the above mentioned Ant command. Despite already setting “sonar.core.codeCoveragePlugin” property to “clover”, I was still not able to see the coverage number. It turned out that the answer is right there in the Sonar Clover Plugin instruction.

What I was missing is adding Sonar Clover Plugin jar file into Sonar core-plugins directory.

sonar-2.12/lib/core-plugins/sonar-clover-plugin-2.8.jar

It is also important to configure Sonar’s Global or Project settings to specify using “clover” as code coverage plugin.

Configure Clover and Sonar Ant Tasks for Code Coverage

Integration Test with Maven

A collection of posts found on the internet focusing on how to tweak/enhance Maven to perform integration tests.

  1. Integration testing with maven 2.0 – by Julien Dechmann
  2. Getting Coverage For Integration Tests – by Ulrik Sandberg
  3. Integration tests with Maven (Part 1): Failsafe Plugin – by velo
  4. Unit tests are not integration tests – by John Ferguson Smart
  5. Maven Integration Testing – by Rod Coffin
  6. Maven and Integration Testing – from codehaus



Continue reading “Integration Test with Maven”

Integration Test with Maven