VCR - Match Body

We had to have make external API calls and we used vcr to record and replay in our integration tests. All was going on well.

Despite this coverage, we saw our code breaking in production due to small chages in request xml body. We wanted our integration spec to cover these too. By default, vcr matches request method and url. We wanted it to match the post body too. Simple match by body does not solve as it does plain string match. It would give false negatives.

So, we decided to match our xml request body. This is what we did.

Apache Camel With Scala: Extending DSL

Let’s take a very simple use case of integrating with a http endpoint which has an authentication mechanism.

      //Do some processing
      .setHeader("Authorization", _ => "OAuth anObfuscatedTokenString")
      .setHeader(Exchange.HTTP_METHOD, "GET")
      .process(//Do something with response)

      //Do some processing
      .setHeader("Authorization", _ => "OAuth anObfuscatedTokenString")
      .setHeader(Exchange.HTTP_METHOD, "POST")
      .process(//Do something with response)

You can clearly see if have many routes like this, there will be a lot of duplication.

Apache Camel With Scala: Testing Styles

Scala with Camel is a very powerful combination for integration. Camel has fantastic support for testing. It’s very easy and useful to test-drive the integration. Following are few styles when it comes to testing camel with scala.

Integer.parseInt(‘God’) = ???

Migrated from: My old post

Today people visit temple for so many reasons. Fundamentally, those reasons come out of fear or greed depending on the situation. During recession people ask god to save job (out of fear) or otherwise, they ask for promotion or better job (out of greed).

How We Debugged Memory Leak in a Rails App.

We run our app on heroku and kept on getting R14s. Our google and stackoverflow skills did provide few suggestions and but din’t help much. We used few tools (rack_bug, oink) see the memory usage. They provided who use how much
but we could make further progress with that. So here’s what we did to find out.

Onclick Link Disabling With jQuery

Days back I have come across a common requirement to disable link on clicking it once. Typically, it’s because on click of those links some AJAX thins happen and some fragments of the page gets updated.

If Else or Switch Case to Polymorphism

If you try to express your logic in if-else way like this,

  private static String getSoundIfElseWay(String animal) {
       if (animal.equalsIgnoreCase("Dog"))
            return "Bark";
       else if (animal.equalsIgnoreCase("Cat"))
            return "Mew";
       else if (animal.equalsIgnoreCase("Lion"))
            return "Roar";
       return "";

then polymorphic way would be,