Sunday
Jan252009

Regular vs Underground Party

I was invited to go to a party in Oakland last Saturday. It is called "People's party" and my friends were raving about the great vibe you find at this place. So we went. Brad driving, me giving directions (thanks to my Google phone).

We got there at 11pm (which is fairly early for clubbin) and the place was packed. It definitely exceeded the maximum allowed occupancy as it took us about 10 minutes to squeeze through people to get to the back room and to the patio. People were friendly, dancing to African music, eating African food and drinking tea (which I loved) in addition to the standard bar drinks. You could smell some weed in the air, and everyone was taking it easy. So my friends were right, it does feel like a best friend's house party, but with 10 times more people than is healthy.
There were only two things wrong with this party:

  • there was a line outside (Why do American clubs try to keep a visible line of people freezing their tails outside on the street? Is this a marketing strategy? Can someone explain why you do not see any lines in clubs outside of the US?)
  • everybody knew about it and everybody went there => there was absolutely no space to dance
Second Chance
It was 12:30 and we bailed out. Our Google phone came to the rescue again... we looked up another party that night... at the underground venue (you need to call a hotline to get the address). Q Burns (our favorite DJ) was playing and it was only few blocks from our loft in San Francisco! So we headed back through the Bay Bridge into the industrial neighborhood at the very south of SOMA.

Finding underground parties requires a bit of patience. First drive to the place Google Maps arrow points to. Then get out of the car and start walking around carefully listening to warehouses. You will get to a door on the side of a dark warehouse. There is no line, no bouncers, no lights, no visible signs of anything happening. You know that you are at the right place because there is definitely a loud house music playing behind that door. You go in, and there is a handful of people who check your ID, take the cover, and let you in. The dancefloor is mostly dark. Few lights point at the bare walls of the warehouse, cars and machinery is moved to one side of the hall, and makeshift bar serves a limited selection of drinks. There is plenty of space for dancing and few dozen people are practicing their house dance routines. There is not stage, no go-go dancers, no posers, no skimpy dressed girls. Just you, them, great music, and great vibe.

Saturday
Jan242009

Testing RPC in GWT

There is very little information about sticking with GWTTestCase (instead of TestCase) and using fake server-side service implementation.

Problem:

You do not want to make any database-calls when your client-side tests run (when client-side tests make RPC calls to the service impl). You already have to live with crappy test speeds due to GWT test framework starting up an invisible hosted-mode browser to be able to execute JavaScript (that many widgets natively use) and you am too lazy to refactor your code to follow the GWT using MVC model example (to be able to stop using GWTTestCase).

Solution:

Define a separate fake service implementation (TestServiceImpl) and a module for testing (TestModule.gwt.xml). Simply make a copy of the production module, and change the contents of the servlet path tag to point to your TestSeviceImpl. Then make sure your GWTTestCase specifies this module in its getModuleName().

Voila! Tests run, they return expected values (either baked into TestServiceImpl or if you get fancy, your TestServiceImpl can implement a nice in-memory data store).
You can now be confident that your asynchronous RPC mechanism works as intended and you can test the production ServiceImpl separately (using JUnit).

Friday
Jan232009

Are you scared yet?

Gerald Celente predicts a major economic depression, tax rebellions, food riots, and by 2012 people will worry about food for Christmas rather than gifts. He predicts that local governments will keep raising taxes to get as much money from public as possible.
Soon, people will have food-producing gardens, and the only thing that can save us must be comparable to an invention of the wheel. He predicts revolutionary advances in renewable energy technologies, medical science, and a shift towards holistic healing practices and a crash of the overpriced college education system.

So buy some gold and then dust off your gardening gear and plant some food!

Friday
Jan232009

Guice 1.0 vs 2.0

The Guice 2.0 contains lots of neat improvements. It removes lots of unnecessary boilerplate and allows to write more compact Guice modules. Here is an example of how a confusing binding can be refactored into a simple provider method.

Example using Guice 1.0:
@Override
protected void configure() {
bind(new TypeLiteral<List<string>>(){})
  .annotatedWith(TagsToProcess.class)
  .toProvider(TagsProvider.class);
}

The same example using Guice 2.0:
@Provides @TagsToProcess
public List<string> provideTags(@Named("tags") String tags) {
  return ImmutableList.of(StringUtil.splitAndTrim(tags, ","));
}

Thursday
Jan222009

JMock vs EasyMock Smackdown

Lets see which of the two popular Java test object mocking tools is more straightforward. Cast your vote! (in comments)

with jMock
with EasyMock
you need to import

import org.jmock.Expectations;import static org.easymock.classextension.
EasyMock.createMock;
import static org.easymock.classextension.
EasyMock.expect;
import static org.easymock.classextension.
EasyMock.expectLastCall;
import static org.easymock.classextension.
EasyMock.replay;
import static org.easymock.classextension.
EasyMock.verify;
your test class needs to extend

MockObjectTestCaseTestCase
in setUp() method

mockedThing = mock(SomeInterface.class)mockedThing = createMock(SomeInterface.class)
to set expectations
checking(
new Expectations() {{
// this run does not throw
one(mockedThing).run();

// expect an exception
one(mockedThing).run();
will(throwException(new RuntimeException());

// expect multiple runs
exactly(4).of(mockedThing).getBlah();
}});

// since run() returns void
expect(mockedThing.run());

// or if the method returns non-void
expect(mockedThing.execute(SOMETHING))
.andReturns(SOMETHING_ELSE);

// expect an exception
mockedThing.run();expectLastCall().times(1).

andThrow(new RuntimeException());

// expect multiple runs
mockedThing.run();expectLastCall().times(1);

to put into replay mode

N/A
replay(mockedThing);
// only after this call the mock is usable
to use the mock in tests

RealThing realThing = new RealThing(mockedThing);

// this will call the mocked thing at some point
realThing.doSomething();

RealThing realThing = new RealThing(mockedThing);

// this will call the mocked thing at some point
realThing.doSomething();

to verify mock

N/A
verify(mockedThing);
// if you forget this, you will not know if the
// expectations were fulfilled
thread safe

???
mockedThing is not thread-safe.... use this
to make it so:
makeThreadSafe(mockedThing, true);