Blog

17 Feb, 2009

The OCZ SSD syndrome

Posted by: admin In: Hardware

It’s a shame that all the OCZ disks are haunted by what I like to call the “OCZ SSD syndrome” which is a ridiculous low number of write operations per second. The first disk to be plagued by this problem was the OCZ Core disk. Today I read a review of their Apex model and it seems to suffer from the same problem.

I can’t believe that they’re still releasing disks with this problem! It has to affect their reputation in a very negative way!? I’m curious to read reviews of their new Vertex series. They’re supposed to have 32-64MB on board cache that should remove some of the iops problems.

Guess it’s just left to hope that we’ll see cheap SSDs without iops problems soon!

Tags: , , ,

29 Jan, 2009

A w3.org standard for smileys?!

Posted by: admin In: Programming

23 Jan, 2009

Unit testing private methods in Java

Posted by: admin In: Programming

Want to unit test a private method in Java?

You could obviously change your methods access modifier from private. By making it public you’re breaking encapsulation and by making it protected you’re making your API less intuitive. Don’t do that.

Another way to go about this is to create a new class that’s extending the one with your private method

I find the easiest and most convenient way achieve unit testing of private methods is reflection. Some of the features the Java reflection API offers is access to private fields and invocation of private methods. This sounds like something useful for our problem, by using reflection we’re able to test our private methods without making any changes to our classes.

class TestSubject {
 
	/**
	 * For some reason we want to unit-test this method
	 */
	private int adder(int numberOne, int numberTwo) {
		int answer = numberOne + numberTwo;
		return answer;
	}
}

This is the method we want to test, here is how we go around to actually do it:

TestSubject subjectInstance = new TestSubject();
Class testClass = subjectInstance.getClass();
 
// Find the method. getDeclaredMethod will give you any methods from that
// class whether it's public or not where getMethod only will give you
// methods with public access. The first argument is obviously our method's name,
// where the next arguments are the formal types of the adder methods parameters.
Method adderMethod = testClass.getDeclaredMethod("adder", int.class, int.class);
 
// Method is a sub class of AccessibleObject if we don't call it's
// setAccessible method we'll get an IllegalAccessException when we
// try to invoke it on our object.
adderMethod.setAccessible(true); 
 
// Invoke the method on our instance of TestSubject
int answer = (Integer) adderMethod.invoke(subjectInstance, 2, 2); 
 
// assert answer = 4

It’s more or less just to plug it into your testing framework of choice and you’ll have unit testing of your private methods.

But hey! Do you really want to unit test your private methods? Doesn’t it give you that bad feeling in your stomach. You know the feeling you get when you’re code smells a little? I mean, a part of the reason for those methods being private is that they’re subject to change.

It’s the oldest oo rule in the book, hide the inner working of you’re classes so you later can change the inner workings of the class without exposing any change to your clients. What you really want to do is to unit test the public methods using those private once. If you find that difficult it might be a little hint that you should consider changing your design a little in order to improve it’s testability.

Why did I bother showing you how to unit test private methods if I consider it bad practice? Well, sometimes when I’m working on complicated things I like to unit-test private methods while working on the class. And there might be situations where unit testing of private methods is the right way to go. Just be careful so you’re not writing a lot of tests you’ll waste a lot of time maintaining later!

Relevant Java API: Class, Method and reflect.

Happy coding!

I alle år, iallfall siden jeg smakte mine første Grandiosa ferdig pizza har jeg gått rundt i den tro at jeg ikke er spesielt glad i paprika.

Fersk og fin paprika har i ettertid vist seg å være kjempegodt! Jeg klandrer de dvaske blaute paprikabitene på Grandiosaen for alle mine år med et dårlig inntryk av paprika!

08 Jan, 2009

Pøbler, ikke demonstranter

Posted by: admin In: Nyheter

Media må se å slutte å bruke ordet “demonstranter” om de som går amok i hovedstaden nå. Dette er i beste fall pøbler. Det de holder på med nå har overhodet ingen ting med krigen i Gaza å gjøre, jeg kan ikke skjønne annet enn at dette er pøbler som ser på dette som en fin anledning til å rasere ting. Jeg håper virkelig at de som blir arrestert nå får en skikkelig smekk.

Dersom det er slik som jeg leser mange steder at det er innvandrere som er med på dette er det veldig trist og ødelegger saken til de innvandrerne som faktisk trenger beskyttelse. Det er jo nettopp slik oppførsel som gjør at folk flykter til fredelige land som Norge. Dersom de samme menneskene tar med seg dette må jeg faktisk støtte FRP i at de like godt kan sendes tilbake. På en måte håper jeg nesten at det er snakk om norske pøbler.

Er det noen som har fått med seg hvilke folkegrupper som har vært mest voldelige i kveld?

Har samlet opp en liste saker:

Steinkasting, gassgranater og søppelkasser i brann, knusing av politibil, eldre mann slått og sparket, bryr seg ikke filla om Gaza, her knuses Karl Johan, fakkeltog, politimann skadet, badet i tåregass

Saker dagen derpå:

Seks personer skadet, skjerp dere

Disse overskriftene sier det meste! Håper vi for en gang skyld klarer å gi de verste en skikkelig smekk. For som vanlig er det vel noen få som drar det i gang og ødelegger for noe som kunne vært en fredelig markering.

Tags:

07 Jan, 2009

Enda en luretittel på VG

Posted by: admin In: Nyheter

“Hellstrøm-restaurant gikk konkurs”

http://www.vg.no/rampelys/artikkel.php?artid=539571

Åhh så lei jeg er sånne lureoverskrifter! Jeg tenkte at det var den snobbete Bagatell restauranten som hadde gått konkurs også er det selvfølgelig bare ukeblad-vg’s tabloide overskrifer. At han snobben har vært innom restauranten med et tv kamera gjør den da ikke til en “Hellstrøm” restaurant!

Oppdatert: Da har jammen Dagbladet / kjendis.no skrevet om saken også. Fortsatt en tabloid sak, men litt bedre overskrift enn VG :-)

07 Jan, 2009

Hva vil han gjøre? Obama og Gaza krisen

Posted by: admin In: Nyheter

Skal si den gode mann Obama skal få henda fulle når han blir president. Økonomisk krise, meget kostbar og omdiskutert krigføring i Afghanistan og Irak og nå denne Gaza krisen.

Som Dagbladet er inne på i artikkelen sin har han mange Isrealvenner i partiet sitt og landet generelt. Etter at USA nå opp til flere ganger har hevded retten til å forsvare seg selv mot terrorisme med krigshandlinger i andre land vil det være hypokratisk å nekte Israel denne retten etter alle rakettene Hamas har skutt inn i Isreal. At diskusjonen rundt hvem som har retten til dette området er omstridt gjør heller ikke saken enklere.

Det skal bli spennende å se hva han finner på. Noe som er sikkert er iallfall at han skal være bra flink for å ikke tråkke noen på tærne!

Tags: , ,

07 Jan, 2009

Tips! Cheap Gillette razor blades

Posted by: admin In: Uncategorized

I don’t know about other countries, but in Norway you get ripped of when buying razor blades. Imagine my thrill when I found out that Dealextreme.com are selling the same blades (with Chinese packing, but who cares?!) for 1/3 of the price!

Enjoy cheap shaving! :-)

For some time I’ve been looking for a way to auto generate UML diagrams inside JavaDoc files. The perfect solution would integrate into Maven 2, which is my build system of choice. A few days ago I stumbled across Apiviz, which turned out to be exactly what I’ve been looking for! It provides simple integration with Maven, Ant and Eclipse.

By default it draws implementation of interfaces and inheritance and if you add some tags / annotations to your JavaDoc it will draw composition, aggregation, dependencies and navigable relationships as well. There are some undocumented options as well. I’ve used the Netty source code as a reference as it seems to be the project maintainer of Netty that’s behind ApiWiz (shoot me if I’m wrong).

I’m in progress of uncovering some of the undocumented features. If someone knows something I appreciate a comment below.

Example from the Netty project

Example from the Netty project

Update: After digging through the source code (gotta love open source!) I found the documentation missing from the web page! This documentation shows how to add labels to the edges.

apiviz.uses
<FQCN> [<sourceLabel> <targetLabel> [<edgeLabel>]]
 
apiviz.has
<FQCN> [oneway] [<sourceLabel> <targetLabel> [<edgeLabel>]]
 
apiviz.owns
<FQCN> [<sourceLabel> <targetLabel> [<edgeLabel>]]
 
apiviz.composedOf
<FQCN> [<sourceLabel> <targetLabel> [<edgeLabel>]]

FQCN is short for “Fully Qualified Class Name”.

04 Jan, 2009

CakePHP 1.2 Final!

Posted by: admin In: Webdevelopment

CakePHP1.2  has finally been marked as stable! I’ve been using this framework in a couple of projects now and I’m impressed by how fast it allows me to develop web applications. That being said, it’s often that way that if something makes development fast, it also makes execution slow. CakePHP comes with a rather serious overhead so I hope further versions of the 1.2 branch will be dedicated to performance improvements.

Anyway, I want to thank the CakePHP team for all the time and effort they’re investing in the project!

Release announcement can be found here