Getting the network to work in a VirtualBox VM with CentOS6

For some reason the network card for eth0 is not automagically detected by VirtualBox VM when installing a CentOS6. ( On VirtualBox running in Ubuntu 12.10 )

After some googling I found many different solutions of which none worked.
First things first: set the network interface in VirtualBox to be the PCnet-FAST III (Am79C973) networkcard. Usually I set this attached to NAT, but this does not seem to work. Attaching the adapter to one of my Ubuntu’s network interface cards by setting it to Bridged Adapter.

Restart the network service in the VM. Still no network. Only after some manual configuration in ‘/etc/sysconfig/network-scripts/ifcfg-eth0’ I got it to work. (it the ifcfg-eth0 file does not exist, create it.)

After trying out different configurations found on the net, I shuffled a bit with the possible config options and this got it to work:

DEVICE="eth0"
HWADDR=08:00:27:D0:F7:95
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="dhcp"
TYPE=Ethernet
IPV6INIT=no
PEERDNS=yes

Restart network service and go do some fun magic in your VM.

Note: don’t forget to change the HWADDR with the address of the network card from the virtualbox configuration!

What to do after Fortinet VPNClient Crash in Ubuntu

At work they are using ForitGate VPN. To be able to work from home I have to use the FortiNetSSLVpnClient. It seems FortiGate is not compatible with any existing other VPN Clients. The forticlient some times crashes and this seem to result in routes not being cleaned up as it should be.

When I am in the office my Ubuntu 12.10 thinks I’m still using VPN and tries to tunnel the connections through the forticlient, which is not running of course. The result is that I get failures for connecting to certain internal domains and servers.

Ping to the servers doens’t work. That gives DNS Lookup failures but performing dnslookup works.

The fix! Flush the dns’s using

sudo /etc/init.d/dns-clean

Update:
Also check that the DNS entries in /etc/resolve.conf are correct. It is possible that the fortinet client did not clean it up as it should be.

Unit testing the database layer

Testing the database layer. Usually an important part of many applications and thus everyone should test it.

But how do you do that?
(if you know how it’s done, this post is not for you, go read something more interesting then!)

You don’t want to setup an Oracle, MySQL, PostgreSQL and such just for running unit tests. Your option? Use an in memory database!

There are a couple of tools available on the opensource market to test your dao layer. I’ve put together an example for a database layer that is using Spring 3.1.2 with JPA2/Hibernate 4.x. For testing I choose the combination of Unitils, H2 in memory database and JUnit.

Unitils is the thing that creates the database using your entities or if you want it can also create your database using an sql script. I usually let hibernate create the database. And add some <dataset> xmls with data.

You can find the example code at github.

Take a look at the tests in src/test/java to see how it is done. There is one test that uses an xml file to populate the database and another test without an xml file. I’ve added Javadoc to the tests to explain what is happening.

This way of testing also allows you to test your service layer with a predefined dataset. Personally I prefer to mock stuff in the service layers. But for doing integration tests it can be useful to have an in memory database.

Happy Testing!