lauantai 18. syyskuuta 2010

Use normal class as message receiver in Scala

I constantly encounter the following problem when writing Scala.

If you want to use normal class as receiver for messages, you have to remember to import Actor._. Otherwise compiler will complain:


error: not found: value self

Following should print "Success"

import actors.Actor
import actors.Actor._
class Example {
case class Message(sender: Actor)
val receiver = actor {
  react {
    case Message(s: Actor) => sender ! true; exit();
  }
}

receiver ! Message(self)

self.receiveWithin(100) {
  case true => println("Success")
  case false => println("Failure")
}
}


I've been using this kind of "pattern" when testing message based communication between objects. It seems to be working pretty well, but tweaking of that timeout is important.

tiistai 14. syyskuuta 2010

MySQL changes foreign key names

Just spent few hours debugging database conversion scripts, and bumped into a "little" bug in MySQL.


CREATE TABLE `test1`(
`id` integer NOT NULL,
PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


CREATE TABLE `test2` (
`id` integer NOT NULL,
`id2` integer DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IX_test_1` (`id`),
CONSTRAINT `FK_1` FOREIGN KEY (`id2`) REFERENCES `test1` (`id`) ) ENGINE=INNODB DEFAULT CHARSET=latin1;


INSERT INTO test2 (id, id2) VALUES (1, 44);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test`.`test2`, CONSTRAINT `FK_1` FOREIGN KEY (`id2`) REFERENCES `test1` (`id`))


ALTER TABLE test2 DROP FOREIGN KEY `FK_1`;
ALTER TABLE test2 ADD FOREIGN KEY `FK_1` (`id2`) REFERENCES `test1` (`id`);


INSERT INTO test2 (id, id2) VALUES (1, 44);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test`.`test2`, CONSTRAINT `test2_ibfk_1` FOREIGN KEY (`id2`) REFERENCES `test1` (`id`))

Somehow foreign key named FK_1 changed into test2_ibfk_1..

torstai 15. huhtikuuta 2010

Rollback with Hudson and Maven?

I've been thinking about implementing rollback with Hudson and Maven. Our projects consists of multiple subprojects which are packaged into .war -files. If these were deployed into Maven repository, it would be possible to use Hudson's "redeploy" artifacts to deploy older versions. After this, you could have a job in Hudson which does the actual deployment to application server.

If that deployment job had dependencies to the .war -files, Hudson might actually spot these changes and do the deployment job automatically after redeploy. I definitely have to check this out.

keskiviikko 7. huhtikuuta 2010

(Almost) Continuous deployment with Gerrit and Hudson

Here's a somewhat simplified workflow for continuous deployment when working with Gerrit and Hudson.


As you can see, features are deployed into Beta server instead of production server. This is mandatory when working with corporate clients, they don't want to have real continuous deployment.

keskiviikko 31. maaliskuuta 2010

Integrating Gerrit with Hudson, part 2

After long time of useless pondering, I finally managed to write and publish Gerrit plugin for Hudson. You can find more information about if from http://wiki.hudson-ci.org/display/HUDSON/Gerrit+Plugin .

To use it, you still need to wait for next version of Hudson's Git plugin to be released, because current version might take something like an hour to resolve what to build. Reason for this is that Gerrit uses branches for change sets. As a result, there's a lot of branches and Git plugin tries to find merge bases for every one of them.

keskiviikko 25. marraskuuta 2009

Hudson and Python

Using Hudson with Python is pretty easy, at least when using Buildout. I currently use following buildout script with Hudson (only relevant parts are shown):

parts = python hudson_test
develop = .
eggs =
   project_name

[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}

[hudson_test]
recipe = pbp.recipe.noserunner
defaults = --with-doctest --with-xunit
eggs = ${buildout:eggs}

[hudson_test] -part uses nosetest to find all tests from project, including doctests (--with-doctest). When using --with-xunit -parameter, nosetest will output test results to nosetests.xml, which is "standard" xUnit result file. Hudson can then track and display test statistics.

Running tests in Hudson is done by calling bin/hudson_test as shell build step. Because nosetest outputs test results as a XML-file, it's pretty trivial to show results in Hudson.

maanantai 9. marraskuuta 2009

The game of software

I'm currently reading "Dynamics of Software Development" by Jim McCarthy. What a great book. I was astonished after reading first few chapters, most stuff is straight from lean and agile. Only thing is that the book was published on 1995.

There's a lot of interesting views to software development in the book, and here's probably one of the bests:
"The game of software rewards and punishes those who play it well and foolishly according to its own nature and principles of. Don't worry about dispensing justice and arbitration. The game itself sorts things out many times more efficiently and intensely than you can." p. 91.

Even though I kind of agree with this, it requires a lot of responsibility from developers, they have to care about the product. If they don't care, "losing" in the game doesn't matter. But when they care, play the game!