Here is an interesting video of a talk given by Ari Zilka (CTO and founder of Terracotta Technologies) to employees of Google. Terracotta was recently open sourced and is receiving good reviews and attention. I am excited to experiment with it.
Entries in 'java'
Terracotta talk: Cluster your JVM to Simplify Application Architecture
EasyMock for JUnit tests
In the Virtual Workspace Service TP1.2.2 (just released) we used EasyMock for unit tests:
“EasyMock provides Mock Objects for interfaces in JUnit tests by generating them on the fly using Java’s proxy mechanism. Due to EasyMock’s unique style of recording expectations, most refactorings will not affect the Mock Objects.”
I am pretty happy with this package. For testing our internal state transition logic I could pre-record the exact methods on the task object that were expected to be called (including argument matching) for a certain transition, test that the expectations were met, and simultaneously test that the wrong tasks were not called.
We have around 30 internal states, around 15 types of tasks, and the tasks are launched out of band via work queue threads, so it was helpful to abstract out as much as possible and just concentrate on testing the transitions and the resulting tasks that were launched.
Having internal subsystem plugins that are instantiated via JNDI helped. Using a test JNDI config to override a factory implementation with a new one that returns mock objects, it was straightforward to isolate the code under test.
This will be good for testing a lot of things: it’s designed expressly to let you mock up the “collaborators” of a subsystem and make sure the interactions are correct without running code in the subsystems that are not being tested.
Debugging Globus Java services with an IDE
These are some notes previously hosted on the old gridvm.org website.
This shows how to run GT4 Java core and/or services in a Java debugger, using IntelliJ IDEA as an example.
The technique (remote debugging) can be used with most Java IDE/debugger combinations. This is a bootstrapping walkthrough, good especially for developers who primarily use editors like emacs and vi and want to quickly learn to use a debugger for their Java GT4 services.
Note that setting this up for GT4 is not much different from remote debugging a normal server application.
Assumptions: working GT4 Java core installation with either the installer or the core tgz downloaded. Any platform supported by both GT4 and IntelliJ (Windows, Mac, Unix and Linux variants). This walkthrough depicts a Linux host.
Java 7 get/set syntax shortcuts
Now that Java 6 has been released, people are starting to talk more about the future of the language. I noticed Kirk Pepperdine’s comments in Java 7.0 language feature considered harmful:
“I’ve just watched the Danny Corward presentation at the Prague JUG on what could be coming in the JSE 7.0. In that presentation he demonstrated the “->” operator. The purpose of the operator is to provide a short hand notatino for properties. The syntax that we would normally use is;
a.setFoo( b->getFoo());
With the “->” operator we would see;
a->foo = b->foo;
How we’d currrently coding this is;
a.foo = b.foo where foo would have to be more visiable than private.”
He goes on to comment on how this violates OO data encapsulation principles and I agree with his arguments about these principles themselves, but I don’t see what the problem with syntactic sugar for very standard method calls is (I am assuming this proposed syntax is, as he suggests, just syntactic sugar for getFoo() and setFoo(x) and that the resulting bytecode is the same). This is just a compiler facilitating something already possible, like using:
String[] x = {"one", "two"};
instead of:
String[] x = new String[2]; x[0] = "one"; x[1] = "two";
As someone who likes Python a lot, it’s a natural thing for me to see “a.foo = x” and understand that a set method could have been executed. You can use “__getattr__” and “__setattr__” to override member access/mutation via instance.property syntax. This can be employed to do useful things behind the scenes while maintaining simple, legible code (such as in SQLObject).
If only it weren’t far too late for Java to eliminate the ability to do direct instance.property access altogether and have that mean get/set instead :-).
