enterLocalPassiveMode() method on the FTPClient instance. This had me confused for a while, which isn't difficult to do and seems to happen often.
enterLocalPassiveMode() method on the FTPClient instance. This had me confused for a while, which isn't difficult to do and seems to happen often.
I spent some time last night watching J.B. Rainsberger's excellent InfoQ presentation entitled "Integration Tests are a Scam". I've been recently contemplating why I favor unit testing (or as J.B. calls it, isolated object testing) over integration testing and I found his presentation particularly relevant. I highly recommend watching it. He also has a series of blog entries that support the presentation (Parts 1, 2, and 3). I also recommend reading those. They're truly gems.
I find many developers using integrated tests as a way to prove the basic correctness of the class or system under test. J.B. writes that "While integration tests offer value in other contexts, too many programmers use them to show basic correctness, and when they do that they waste a tremendous amount of time and effort." Integrated testing can be used within a project (I'm personally fond of acceptance testing), but integrated testing should not be used to prove basic correctness of your code. Focused, isolated object tests (aka unit tests using test doubles) should be used for this endeavor. If you discover behavior that a collaborator demonstrates and you have not accounted for in your isolated object tests, you should mimic this behavior in your test doubled collaborator contracts. You want to cover as much of your code with isolated object tests. We'll talk more about contract tests later.
J.B. mentions using an integrated test to learn about how a collaborator might support its contract, but that this integrated test is not included in the basic correctness test suite. I'm wondering if there isn't some other test suite here that we could use to keep integrated tests that support our learning the runtime and external dependencies. This test suite would be run periodically, but is not part of the whole continuous integration process of building a software system. Need to noodle on this more.
J.B. states in his aforementioned presentation that he does not use the term "unit testing" and instead favors a more focused term of "isolated object testing". He makes a point to call out the isolated word; these tests isolate the class under test by using test doubles to stub or mock the collaborators of the class under test. These tests focus on a single object and a singular behavior. Any collaborations are realized using test doubles.
I tend to agree that the phrase "unit testing" is a weak phrase describing the type of testing that we use to drive design of a single class and a single method. These tests focus on the responsibility of a single method of a single class. These tests also help you focus on understanding the contracts of collaboration between this class under test and its collaborators. This is really where the design part of the equation comes in. Classes that are hard to test are screaming out that the design is wrong. The tests are saying you have too much responsibility in the class under test or there are too many collaborators. Using your fast isolated object tests, you can engage in a reactive design activity, moving responsibilities out of the class under test, create new collaborators, and other design changes to make .
J.B. rightfully makes a big deal about contracts (aka interfaces) to explicitly specify collaboration protocols between objects. He mentions that in Domain-Driven Design, popularized by the Eric Evans book of the same name, three concepts can be used to express a domain-driven model: Values, Entities, and Services. All Services should have contracts and those contracts manifest themselves as interfaces. By specifying interfaces, we explicitly declare the protocol supported by each interface implementation. Constraining ourselves to interface types when specifying collaborations results in looser coupled systems, which is considered a "Good Thing". When engaging in isolated object testing, J.B. details the concept of collaboration tests and the closely associated contract tests. This concept of collaboration tests and contract tests is something new to me and is a big reason the presentation was so valuable in my eyes.
After watching the presentation, I seem to be doing a pretty good job of using collaboration tests, but I'm not making the association to contract tests. Collaboration tests prove that the client interacts with its collaborators correctly; the client sends the correct messages and message arguments to the collaborator and appropriately handles all outputs from the collaborator. This is traditionally what I have used mock objects for and that seems to be what J.B. is arguing one should do for collaboration testing.
Contract testing, on the other hand, deals with testing that an interface implementation accurately respects the interface it is implementing. Does the implementor support the contract it declares to support? I haven't typically written these types of tests, but I'm going to start. Interestingly, I don't see a lot of this sort of testing in the wild. The part I really dig about contract tests as Rainsberger explains them is that they can be reused across interface implementations. He uses the List interface and two of its implementations, ArrayList and LinkedList, and details how to use implementation inheritance in the tests to DRY up your contract tests.
It really gets interesting when he declares that for every collaboration test that implies that a test double behavior, there better be a corresponding contract test that demonstrates that the interface implementation(s) actually does support that behavior. Same goes for values returned: if a test double returns a value in a collaboration test, there should be a contract test that demonstrates that the real implementation(s) does actually return that value. This is where I think selective, integrated learning tests can help you discover how your classes on the edges of a system may act when integrated to real external dependencies. But again, those integrated tests are not providing basic code correctness semantics. They're in your project to help you learn, but are not part of the isolated object tests suite. Don't lump them with your isolated tests and don't run them as part of your code/update repos/run tests/commit cadence. This learning test suite should be run periodically during the day, but not part of the CI build process.
Both Rainsberger's tutorial presentation and his blog postings go into great detail to the fallacy of using integrated testing to prove code correctness. I won't rehash what he has to say about it. My conclusions that I draw from his material are:
J.B.'s series on Integrated Tests are a Scam can be found here.
1 class User {
2
3 transient springSecurityService
4
5 String username
6 String password
7 boolean enabled
8 boolean accountExpired
9 boolean accountLocked
10 boolean passwordExpired
11
12 static constraints = {
13 username blank: false, unique: true
14 password blank: false
15 }
16
17 static mapping = {
18 password column: '`password`'
19 }
20
21 Set<Role> getAuthorities() {
22 UserRole.findAllByUser(this).collect { it.role } as Set
23 }
24
25 def beforeInsert() {
26 encodePassword()
27 }
28
29 def beforeUpdate() {
30 if (isDirty('password')) {
31 encodePassword()
32 }
33 }
34
35 protected void encodePassword() {
36 password = springSecurityService.encodePassword(password)
37 }
38 }
<%= %>) before Underscore ever gets a chance to use it. I assume evaluations would also be consumed by GSP. Took me a while to figure this out, so I thought I'd raise it up as a concern. Underscore.js does give you a way to change the delimiters using regexes.
var MyView = Backbone.View.extend({
initialize: function() {
this.template = _.template($('#my-template').html(), this.model.toJSON());
this.render();
},
render: function() {
this.el.html(this.template);
return this;
},
events: {
"click button#doSomethingButton": "doSomething",
},
doSomething: function(e) {
this.model.set({someValue: $('#someValueTextField').val()});
var promise = this.model.doSomethingOnModel();
promise.done($.proxy(function() {
this.el.fadeOut();
}, this)).fail(function() {
alert('Failed to check sequence uniqueness.');
});
}
});
…
promise.done => @el.fadeOut()
…
I'm working on a Grails application that needs to connect to a Oracle database using a LDAP context. The URL format is something like the following:
jdbc:oracle:thin:@ldap://tns.mycompany.com:389/marketing,cn=OracleContext,dc=com,dc=marketing
I'm also not using the Grails DataSource.groovy configuration for this. I'm managing a separate DataSource in the resources.groovy using Spring DSL. I'm using the org.springframework.jdbc.datasource.DriverManagerDataSource. I have not tried this with the standard DataSource.groovy stuff. When I first tried using this, I would get an exception with the following text: "javax.naming.NotContextException Not an instance of DirContext". There seems to be a bug with the Spring LDAP and the SimpleNamingContextBuilder class. Basically the SimpleNamingContextBuilder returns a Context implementation, not a DirContext implementation. You can work around this in Grails by adding the following to the Config.groovy file:
grails.naming.entries = null
Problem solved. The DataSource now bootstraps correctly and I can go on my merry way. Kudos to Luke Daley for bringing this to my attention.
![]() |
| Big Woods State Park |
I did the first CoffeeScript presentation this past August to the Ruby Users of Minnesota (RUM) group and it looks like I'll be doing a second take on the presentation to the Groovy Users of Minnesota (GUM) here in October. If you're interested in the presentation and the examples, you can find them here.
I spent some time today tracing and profiling SQL in one of the Grails applications that I support. I was looking around for proxy JDBC driver and happened on log4jdbc. It's similar to p6spy, but it seems to be actively developed and supported. Downloaded the driver, dropped it in my lib directory, and changed the logging and datasource configurations a bit in Grails and I was up and running. Very handy. I made copious use of the SQL timings profiling today. There are many other options for tracing and profile with this tool. Here are my changes to Config.groovy for enabling SQL timings to all SQL statements:
Config.groovy change to enable logging of SQL information from log4jdbc:
log4j = {
info 'org.codehaus.groovy.grails.web.servlet',
...
'grails.app',
'jdbc.sqltiming'
}
DataSource.groovy changes to enable log4jdbc:
development {
dataSource {
driverClassName = "net.sf.log4jdbc.DriverSpy"
url = "jdbc:log4jdbc:mysql://localhost/mydb-DEV?useUnicode=true&characterEncoding=UTF-8&useCursorFetch=true&autoReconnect=true"
}
}
Can't say enough good things about this tool. Really helped me zero in on some queries that were performing poorly with large data sets.
I've been working on a data import process the past couple of days, trying to solve some memory issues (OOMEs). Essential we have a reader (the producer) and a writer (the consumer). The writer part of this scenario operates much slower than the reader part. The reader part is implemented as an iterator, so it only produces enough work for the writer to consume. As this design evolved over time, parallel execution of the writer was added, in an effort to speed up the overall writing process. The coordination of the parallelization is an ExecutorService implementation. With this executor service now in place, the iteration of the reader can operate independently of the writer. Thus, the consumer now starts creating lots of tasks that are then submitted to the executor service, where they queue up. The executor service is not bounded, so it just keeps accepting tasks. This wouldn't be a problem if the number of tasks were small and the memory footprint of those tasks was low, but that is not our situation. Thus, we keep blowing out our Java VM process with OOMEs. We're in the process of fixing this issue, using a bounded concurrent collection to handle the buffering of items between the reader and the executor service and ultimately the writer.
Came across a design issue today where we really could have used Groovy's dynamic dispatch and multi-method support to invoke the proper method based on the interrogation of the runtime type of an object instance passed as a parameter to the method. This blog posting by MrHaki gives a great description of how Groovy solves this problem without the need of a double dispatch pattern implementation. We're writing our code in Java, so we don't get the Groovy goodness of dynamic method dispatch and multi-methods. We resorted to a double dispatch implementation to solve our problem. We did not use the instanceof operator and a whole bunch of conditionals.
Clean Coder, The: A Code of Conduct for Professional Programmers by Robert C. Martin
The Great Derangement: A Terrifying True Story of War, Politics, and Religion at the Twilight of the American Empire by Matt TaibbiJust hit this so I thought I would write up a quick entry. I'm trying to get Hibernate and Apache CXF to work together. I have a Gradle build. I ran my test suite and I am seeing issues with CGLib classes. After a little bit of research, it seems there's an issue between the ASM library that Hibernate's CGLib uses and the one that Apache CXF uses. Solution is to exclude cglib-2.1_3.jar and use cglib-nodep-2.1_3.jar instead. To do this in Gradle:
configurations {
all*.exclude group: 'cglib', module: 'cglib'
...
}
dependencies {
compile group: 'cglib', name: 'cglib-nodep', version: '2.1_3'
...
}
Adding these lines to the build.gradle file allow me to remove the cglib-2.1_3.jar dependency and instead specify the nodep version instead. Pretty slick.
Quick blog post here. Hooked up an Atlona AT-MDP21 2x1 Mini DisplayPort KVM switch to my 2009 Mac Pro and my 2010 MacBook Air. Both run the 27" Cinema Display at its highest native resolution, 2560 x 1440. Atlona documentation states highest resolution is 1920 x 1200. Easy to set up and I have the Cinema Display USB in the back working between the two computers. The only downside is the slight 1-2 second pause when switch the KVM from one computer to another. Not a big deal. Highly recommended.
Kingpin: How One Hacker Took Over the Billion-Dollar Cybercrime Underground by Kevin Poulsen
Zero Day by Mark RussinovichQuick post on specifying Grails dependencies in BuildConfig.groovy. The recommended way to suck in JAR dependencies in Grails is to use the dependencies DSL maintained in BuildConfig.groovy. I had a need to bring down a dependency that has a classifier attribute on it. Didn't really find anything definitive on how to do it, but it seemed like following a convention might do the trick. Here's how I solved the issue:
repositories {
grailsPlugins()
grailsHome()
grailsCentral()
mavenCentral()
ebr() // SpringSource Enterprise Bundle Repository
}
dependencies {
runtime group:'net.sf.json-lib', name:'json-lib', version:'2.4', classifier:'jdk15'
}
I recently read this book after seeing Alan Cooper had read it and stated that it was a terrifying book. I wondered what would be so terrifying about "Bubble Machines, Vampire Squids, and the Long Con That is Breaking America". After reading it, I wouldn't characterize it as terrifying as much as I would characterize it as infuriating. The incompetence, greed, self-interest, and gluttony that is repeatedly portrayed in the book is extremely infuriating to me as a hardworking American citizen that pays taxes. The book chronicles some of the most audacious power grabs this nation has ever seen, and in most instances, those power grabs are happening during the past two decades. Taibbi chronicles why the Tea Party is chasing its own tail, lambasts Alan Greenspan as "a one-in-a-billion asshole that has made America the mess it is today", and details the mortgage, commodities, and wealth fund scams that we, American taxpayers, have had to endure the last couple of years. The book is written in a no-holds barred fashion with a fair amount of profanity thrown in to spice up the prose. It's an entertaining read, but also very thought provoking and sheds some interesting light on the current political climate, especially around Obamacare and the health insurance industry. Very highly recommended.

I had some issues getting the Groovy Remote Control plugin to pull down through Maven today. The documentation that is currently in place today is not correct. Here is the fragments of my Maven POM that enabled me to pull the plugin as a dependency: