Saturday, January 27, 2018

Installing Erlang version 20.1 and RabbitMQ 3.7 on AWS EC2 Amazon Linux instance

Today we are going to install Erlang version 20.1 and RabbitMQ 3.7 on an Amazon EC2 instance which is having an Amazon Linux version installed in it. In a nutshell we can say that, Amazon Linux can be considered equivalent to CentOS 6.

I am not going to eat your time and jumping directly towards the commands that you have to execute on your new instance. Before we start, please ensure:


  1. you have the administrative privileges. 
  2. Java 8 installed.
Just a brief, to install RabbitMQ, we would need Erlang and Socat to install first.

OK.. So, you have to execute the following commands as mentioned below.

Installing Erlang version 20.1

# cd /opt


# rpm -ivh erlang-20.1.7-1.el6.x86_64.rpm

Installing Socat


# yum install socat

 Installing RabbitMQ



# rpm -ivhrabbitmq-server-3.7.0-1.el6.noarch.rpm

# service rabbitmq-server start

Now we have to make sure that RabbitMQ is up as a service as soon as the server start up. To do this, execute the following command: 

# chkconfigrabbitmq-server on

To access the RabbitMQ Management Console on web, we need to enable the plugin. To do so execute the following command:

#  cd /usr/lib/rabbitmq/bin/

# rabbitmq-plugins enable rabbitmq_management

# cd /etc/rabbitmq/

# vim rabbitmq.config

[{rabbit, [{tcp_listeners, [{"", 5672}]},{loopback_users, []}]}].


Esc+:wq!

Now you can access the RabbitMQ on browser using:

http://<IP_Of_Your_AWS_Machine>:15672/

To login, use guest/guest as default password which you can change later.


Congratulations!! You did it.. :)

Do share your thoughts if you have any query, suggestion. 

Thanks!!

Installing Java 8 on AWS EC2 Amazon Linux instance

Today we are going to install Java 8 (JDK 8, I must say from the developer's perspective) in an Amazon EC2 instance which is having an Amazon Linux version installed in it. In a nutshell we can say that, Amazon Linux can be considered equivalent to CentOS 6.

I am not going to eat your time and jumping directly towards the commands that you have to execute to install JDK 8 on your new instance. Before we start, please ensure you have the administrative privileges. OK.. So, you have to execute the following commands as mentioned below.

Installing Java 8

$ cd /opt

$ sudo wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz


$ sudo tar xzf jdk-8u151-linux-x64.tar.gz

$ cd jdk1.8.0_151/

$ sudo alternatives --install /usr/bin/java java /opt/jdk1.8.0_151/bin/java 2

$ sudo alternatives --config java
There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /opt/jdk1.8.0_151/bin/java

Enter to keep the current selection[+], or type selection number: 2 

(If you are getting some other options as well, choose the one with "/opt/jdk1.8.0_151/bin/java")


$ sudo alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_151/bin/jar 2

$ sudoalternatives --set jar /opt/jdk1.8.0_151/bin/jar

$ sudo alternatives --set javac /opt/jdk1.8.0_151/bin/javac

Check Java version 


$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

Setting environment variables.


# vim /etc/profile
export JAVA_HOME=/opt/jdk1.8.0_151
export JRE_HOME=/opt/jdk1.8.0_151/jre
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin


Congratulations!! You did it.. :)

Do share your thoughts if you have any query, suggestion. 

Thanks!!

Tuesday, June 5, 2012

Writing JUnit Test Case

Dear Folks,

In this blog I'll tell how to write the JUnit Test Cases to test your application's methods.

Suppose we have a class which manipulates with the date and time. See the sample class:

package com.test.util;

import java.util.Calendar;

public class DateManipulation {
    public static String getDate() {
        Calendar c = new 
Calendar ();
        return c.getTime().toString();
    }
}

Now, we will write a test case of this method.

* Create a directory src_test parallel to src directory in your project.
* Now create the same package in it as your original src file.
* Create a class file TestDateManipulation in it.


package com.test.util;

import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertTrue;

@RunWith(JMock.class)
public class TestDateManipulation {
    
    private Mockery context = new JUnit4Mockery() {    
        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };

    @Test
    public void getDate(){
        String returnValue =  DateManipulation.getDate();
        assert returnValue != null;
        assertTrue(!returnValue.equals(""));
    }
}



* Use @Test annotation to show this is a JUnit Test method which is called to test the existing method.
* Mockery is mandatory to create otherwise it will give "no Mockery found in test class" error.
* assertTrue will validate the output of the program by evaluating the condition written in it. You can learn more about them in http://www.junit.org/apidocs/junit/framework/TestCase.html link.

Hope this will help you in writing test cases for your application. :)

--
Best regards,


Monday, August 9, 2010

Spring Tutorial for Web Application Development

Hi Folks,

This is the must read Spring Framework Tutorial that the interested developers should read. It clarifies the basic concepts of spring and tells the approach to develop web application using springs.

This tutorial is helping me.. Hope this will help you too.. :)

Best regards,