Skip to content

Instantly share code, notes, and snippets.

View swapnonil's full-sized avatar

Swapnonil Mukherjee swapnonil

  • London
View GitHub Profile
@swapnonil
swapnonil / AppTest.java
Last active December 14, 2015 03:59
Rabbit MQ Test with Publisher Acknowledgements.
package rabbitmqclient;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.*;
import org.springframework.amqp.rabbit.support.*;
import org.springframework.context.support.*;
@swapnonil
swapnonil / applicationConfig.xml
Created February 24, 2013 19:57
General Spring Publisher Config for Rabbit MQ. The rabbit:queue-arguments are not being used, as they did not work with Rabbit MQ 3.0.2 The HA /Mirror Queue Settings were set using the Rabbit MQ Management Console. Refer to http://www.rabbitmq.com/ha.html.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
<rabbit:connection-factory id="connectionFactory" addresses="localhost:5672,localhost:5673" publisher-confirms="true"/>
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/>
@swapnonil
swapnonil / rabbitmq.config
Created February 24, 2013 20:00
Generic Rabbit MQ Config. This one makes the rabbit mq work on 5673 instead of 5672 and the Management Plugin work on 15673 instead of 15672.
[
{mnesia, [{dump_log_write_threshold, 1000}]},
{rabbit, [{tcp_listeners, [5673]}]},
{rabbitmq_management,
[{listener, [{port, 15673},
{ip, "127.0.0.1"}
]}
]}
].
@swapnonil
swapnonil / rabbitmq-env.conf
Created February 24, 2013 20:03
Generic rabbitmq-env.conf. This names the node and changes the default port to 5673
# I am a complete /etc/rabbitmq/rabbitmq-env.conf file.
# Comment lines start with a hash character.
# This is a /bin/sh script file - use ordinary envt var syntax
NODENAME=mir_node_2@localhost
NODE_PORT=5673
@swapnonil
swapnonil / apt.conf
Created February 26, 2013 10:53
Ubuntu Proxy configuration for Apt.
Go to /etc/apt. Create the file apt.conf if you don't have it there. Write the following lines there.
Acquire::http::proxy "http://username:password@proxyserver:port/";
Acquire::https::proxy "https://username:password@proxyserver:port/";
Acquire::socks::proxy "socks://username:password@proxyserver:port/";
@swapnonil
swapnonil / build.xml
Last active August 29, 2015 13:56
Ant build script with Sonar, Jacoco Integration
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="SomeLegacyCode" xmlns:sonar="antlib:org.sonar.ant" xmlns:jacoco="antlib:org.jacoco.ant">
<property environment="env" />
<property name="ECLIPSE_HOME" value="../../" />
<property name="debuglevel" value="source,lines,vars" />
package functions
object BasicFunctions {
def main(args: Array[String]) = {
val person = personInfo(100)
println(person._1, person._2, person._3, person._4)
// Another way of creating a simple Tuple. This creates a key, value pair
val data = "red" -> 1900
println(data._1, data._2)
@swapnonil
swapnonil / ShoppingCart.java
Last active August 29, 2015 14:21
How I Test Business Logic
public class ShoppingCart {
private AuditGateway auditGateway;
private User user;
public void applyDiscount(int productId) {
// find the product which has been already been added to the cart
Product product = getProduct(productId);
if (product == null || user == null) {
throw new IllegalArgumentException("Either product or user is invalid");
public class ShoppingCartUTest {
ShoppingCart shoppingCart;
private MockProduct mockProduct;
private MockUser mockUser;
@Before
public void setUp() throws Exception {
shoppingCart = new ShoppingCart();
}
public class ShoppingCartITest {
ShoppingCart shoppingCart;
private Product product;
private User user;
@Before
public void setUp() throws Exception {
shoppingCart = new ShoppingCart();
}