Wednesday, March 23, 2011

Hibernate JDBC batching

Just made the Hibernate JDBC batching work properly.

Here are essential parts:

1. Make sure "hibernate.temp.use_jdbc_metadata_defaults" setting is not used.
2. Make sure JDBC driver supports JDBC caching.
3. Set "hibernate.jdbc.batch_size" to something reasonable like 50.

Nothing else should be needed.

Monday, February 21, 2011

udev SYMLINK does not work

It took me years until I finally forced myself to look into udev source code and find out why RUN attribute always work perfectly, but NAME, SYMLINK and MODE often fail to work properly.

The symptoms are also well described here:
http://ubuntuforums.org/showthread.php?t=1329255

I found out that if "uevent" file in sysfs directory of appropriate directory does not contain a version number, udev silently ignores the whole rule and never says anything in logs.

So, there are two possible solutions for the problem. One is to use RUN attribute only that would perform all the actions needed and the other is to fix the kernel module which creates such non-nonsensical entries.

Monday, August 23, 2010

Resizing encrypted LVM

Recently I have found myself in the situation that my root partition does not have any free space left for a new software. That is why I installed LVM I thought. Reading several FAQs and tutorials in Internet made me miserable though. It seemed that no tool support encrypted LVM properly and so on. According to numerous tutorials you had to decrypt the whole partition somewhere before working with it and so on. So, I risked to just use the tools ignoring the fact that my LVM is indeed encrypted. It worked like a charm in several minutes. It could be that the tools I used (e2fsck, e2resize, lvreduce, lvextend) already support encrypted LVMs...

You can use the following guide to try it yourself. Do not look that the blog has Feodora in the name. I used Debian and everything went fine.

http://allaboutfedora.blogspot.com/2007/01/how-to-resize-or-expand-lvm-partitions.html

Thursday, June 3, 2010

Making JUnit tests run parallely

If you use Selenium tests or other JUnit based tests with long execution time and low CPU usage you will eventually try to make them run concurrently. The good thing is that this is extremely easy thing to do with Apache Ant.

That why I am extremely surprised nobody still does it. Most people try to invent the wheel and try to use other frameworks like TestNG, write new experimental parallel computer classes for JUnit, or even configurable versions of the same classes. This all is a time waste for the people who just want to run some concurrent tests.

Here is how you do that:

1. Make sure that you have "ant-contrib" package installed. Usually it is enough if the appropriate JAR file is in the ant class path.

2. Turn the tasks of "ant-contrib" library. You can do this by adding the following lines to your "build.xml" file.
<taskdef
  resource="net/sf/antcontrib/antcontrib.properties"
/>
3. Add the new target that will execute exactly one test. You will have something like following.
<target name="execute.test">

  <!-- we need to have relative path -->
  <pathconvert property="test.source.relative">
    <fileset file="${test.source.absolute}" />
    <map from="${test.sources}/" to="" />
  </pathconvert>

  <!-- run one particular test -->
  <junit fork="true" printsummary="true">

    <classpath>
      <path refid="${test.classes}" />
    </classpath>

    <formatter type="xml" />

    <batchtest todir="${test.reports}">
      <fileset dir="${test.sources}">
        <filename name="${test.source.relative}" />
      </fileset>
    </batchtest>
  </junit>

</target>
4. Now use built-in "foreach" concurrent execution capabilities to execute this target. You would have to add something like following to your other target.
<foreach
target="execute.test"
maxthreads="5"
inheritall="true"
inheritrefs="true"
parallel="true"
param="test.source.absolute">
  <path>
    <fileset dir="${test.sources}">
      <include name="**/*.java"/>
    </fileset>
  </path>
</foreach>
5. That's all. Easy and nice. You will have all your tests executing in 5 nice threads. You can use any number of threads you want. No additional configuration, classes, code is needed.