This is just Groovy, or stubbing chained method calls

This is just a quick note to self because I am prone to forget such things. This blog is my reminder right? I am writing down the things that may be of use later.

So, today I spent a few hours trying to write just one test. For this chained method call:

        FindIterable<Document> ops = oplogCollection.find(filter)
                .sort(new BsonDocument().append("$natural", new BsonInt32(1)))

We are writing tests in both Groovy and Java, but this one was in Groovy. I was trying to stub the invocation so that it would be used in all the chained calls. And I was failing.
First I tried to use this kind of stub:

        FindIterable<Document> stub = Stub(FluentIterable)
        stub.sort(_ as Bson) >> { Bson filter ->
            // do whatever
            return stub
        stub.batchSize(_ as int) >> { int size ->
            // do whatever
            return stub

So, I declared a stub and I returned it all the time. No luck! Only the first chained method was called.
Then I thought, what if we try to return this instead? Unfortunately, in this case this point to the instance of your test class and not your stub, which I promptly learned.

So, I turned to the best authority.
Google and StackOverflow.

In the end, this is how it worked:

        FindIterable<Document> batchResult = [
                batchSize: { int size ->
                    return tmResult
                }] as FindIterable<Document>

        FindIterable<Document> sortResult = [
                sort: { Bson sort ->
                    return batchResult
                }] as FindIterable<Document>

So, the principle is that you have to create another stub for a chained method call, and then they get chained.
I live and I learn.

Posted in java, Programming | Tagged , , | Leave a comment

ElasticSearch for dummies, or why you can’t find what you just indexed

So, let’s say you are starting to use ElasticSearch. You have created a new index and put some data there. Then you go and try to search by one of the fields… and can’t find a thing.

How can this happen?

Well, one of the reasons is that you probably don’t have mappings.

If you just created an index with no specific settings, then mappings are inferred, as well as analyzers. There are three ways of analyzing a field:

  • analyzed. This is the default. It means that field content will be analyzed and available for full-text search.
  • not_analyzed. This means that field content won’t be processed, but it will be searchable. It will be stored “as is” and you will be able to query it by value.
  • no. It means the field won’t be indexed and you can’t use it for search.

So, the default value is analyzed, which means that all the fields are searchable by default. Well then, why aren’t they searched? Continue reading

Posted in ElasticSearch, Programming, Uncategorized | Tagged , | Leave a comment

Organizing your mind: books to Trello

I have a lot of books to read.

Actually, I have read a lot of books, too. I am always reading. When I was a kid, the easiest way to shut me up and give my parents some peace and quiet was to give me a book. At first it was fairy tales, then myths and legends, adventure, science fiction, fantasy etc. And now that I am all grown up and have to take care of my professional education, it’s often programming books. Though I can’t pretend to have given up my love of fiction. How could I not have read Game of Thrones? (Twice. And will probably be going on the third time if Mr. George Martin continues to hold up on the next book.) How could I have not read Harry Potter? (I am not saying how many times.) How could I not read… whatever, I think the point is obvious here. Continue reading

Posted in Learning, tools | Tagged , | 2 Comments

Why selling yourself might be more difficult than you thought, or The art of being humble

We are still hiring.

It is difficult to me to say that and not express my deepest disappointment as to the fact that we still haven’t found a match for our team. But unfortunately, I still don’t think that it is us who are the problem. Rather, I think that the overheated IT jobs market in Ukraine makes the candidates to be unable to estimate their chances and skills objectively.

Continue reading

Posted in interviews, Uncategorized | Tagged | Leave a comment

How to get a list of Tomcat session IDs using JMX and jconsole

Sometimes you want to check if a session is alive or already dead. There’s several ways how you can do it, but I want to tell about the one I found which looks rather simple – it’s by exposing catalina properties and operations via MBeans. It will still need some configuration, though.

First of all, you need to configure your tomcat instance for remote JMX access. If you have a script or a file setting environment variables for your deployment, you can add it to that script. Or, you can do it just by hacking the or like this (see below).
Continue reading

Posted in java, Programming | Tagged , , | Leave a comment

Programming interview: sell your real self


We are looking for a software developer.

We need more hands on deck. And therefore, we are interviewing. As an interviewer, one can see the process from the other side of the table. And there’s one thing that’s become painfully obvious in one recent interview.

When you are selling yourself, don’t oversell.

Continue reading

Posted in interviews, Learning, Success | Tagged , , | Leave a comment

English Vinglish

There’s an Indian movie called English Vinglish, which stars a beautiful actress Sridevi as a mother of two, an owner of a small home-based business and a wife of a white collar worker, struggling to gain respect in her own family. The reason of her not succeeding (in the beginning of the movie) is that she doesn’t speak English. Based on the movie, it looks like it’s quite a big thing in India; if you are an English speaker, you can get a better job, get your kids to a better school, earn more money – and, well, you’ll be more respected.

As a software developer from a non-first-world country, I can relate to that. A software developer, speaking good English, is a kind of elite in Ukraine. He can find a job with the outsourcing company, or outstaffing, or whatever it’s called, the main thing being that an employee is working for a foreign client. And is getting paid the rates which are therefore much higher than he’d get with a domestic client, on average.

Continue reading

Posted in Uncategorized | Tagged , | Leave a comment