Thursday, 12 June 2014

add hint to a criteria in hibernate

http://stackoverflow.com/questions/1327503/how-to-insert-an-optimizer-hint-to-hibernate-criteria-api-query

---

ProjectionList proList = Projections.projectionList();
proList.add(Projections.sqlProjection("/*+ index(this_ OUTGOING_ADAPTOR_MSG_IDX_6) */ 1 as MYHINT",    new String[]{},    new Type  []{}));

for (javax.persistence.metamodel.Attribute<. super OutgoingAdaptorMessageEntity, .> o : getManager().getMetamodel().managedType(OutgoingAdaptorMessageEntity.class).getAttributes()) {
    proList.add(Projections.property(o.getName()),o.getName());
}

criteria.setProjection(proList);

criteria.setResultTransformer(new AliasToBeanResultTransformer(OutgoingAdaptorMessageEntity.class));

Thursday, 29 December 2011

disable alps touchpad ubuntu 11.10

If you have an Alps touchpad and cannot use the "normal" settings for synaptics and the setup believes that your touchpad is a mouse. Install touchfreeze and replace synclient with

#!/bin/sh

if [ $# != 1 ]
then
echo nothing
else

if [ $1 = "TouchpadOff=0" ]
then
xinput --set-prop "ImPS/2 ALPS GlidePoint" "Device Enabled" 1
fi

if [ $1 = "TouchpadOff=2" ]
then
xinput --set-prop "ImPS/2 ALPS GlidePoint" "Device Enabled" 0
fi

fi

Change depening on what your xlist says

This works by touchfreeze calls synclient to disable touchpad. Synclient isn't working because you don't have a synaptics touchpad...

Friday, 28 January 2011

wget http://imgsrc.hubblesite.org/hu/db/images/hs-2010-13-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2003-28-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2005-37-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-41-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2004-27-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2006-23-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2006-01-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-19-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1999-12-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2005-12-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2005-12-b-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2006-10-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2003-22-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-16-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2003-24-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2003-11-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2006-14-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2003-01-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-15-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2001-15-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1996-01-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-11-b-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2009-14-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-17-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-09-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2000-10-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1995-01-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2000-15-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2008-22-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2009-25-f-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-11-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-36-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1998-35-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-16-h-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2009-25-i-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-16-f-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1995-45-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2001-10-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2005-15-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2009-25-x-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1999-20-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2001-12-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2003-09-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-35-b-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-16-e-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2008-37-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2006-07-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1999-14-b-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2000-14-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2008-34-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-34-b-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2005-30-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-05-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2009-25-q-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1998-39-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1998-12-b-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-11-c-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-37-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2006-13-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2009-10-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2005-25-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-30-d-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1998-21-b-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-11-d-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-1999-04-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2001-34-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-42-c-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-29-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2003-06-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2001-11-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-01-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2001-21-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-25-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-30-b-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-26-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2006-34-b-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2001-25-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2002-12-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-30-c-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2007-18-a-2560x1024_wallpaper.jpg;
wget http://imgsrc.hubblesite.org/hu/db/images/hs-2006-34-c-2560x1024_wallpaper.jpg;

Monday, 23 August 2010

query strings in LOBs

select * from TABLE where dbms_lob.instr(COLUMN, utl_raw.cast_to_raw('TEXT'),1,1) > 0

Thursday, 19 August 2010

iconify & pop windows for long running batch jobs

When I start long running jobs, I lose context and working with something else and start. Then I forget whatever I was doing.

sudo apt-get install xwit

in /usr/bin create 2 files

iconifyw
-------------------
tmpwinid=`env|grep WINDOWID | sed 's/WINDOWID=\([0-9]*\)/\1/'`
xwit -iconify -id $tmpwinid
-------------------

popbw
-------------------
tmpwinid=`env | grep WINDOWID | sed 's/WINDOWID=\([0-9]*\)/\1/'`
xwit -pop -id $tmpwinid
aplay -q /usr/share/sounds/beep-1.wav
-------------------

the wav file has to be found somewhere

chmod a+x popbw
chmod a+x iconifyw


test with

> iconifyw ;sleep 5 ;popbw

Tuesday, 27 July 2010

oracle audit

http://www.dba-oracle.com/security/application_users.html
from: http://miguelmoreno.net/post/Increase-your-VMWare-disk-size.aspx

Increase your VMWare disk size… Over the years I have used both Microsoft's Virtual PC and VMWare. As to which one I prefer and is better, that is a whole other post. In this post I wanted to write about increasing the size of a virtual hard drive of a VMWare machine.

When creating a new machine you are asked to define the size of your drive and when you choose 16Gb, you think you'll never use that much anyways, until, after a while, you realize you do need more. In that case, there are no options to increase the size of your C: drive. Ofcourse, you could always add a new drive (D or E), but that is just more files lingering around, as if VMware didn't create enough already....

With regards to your OS drive size, you are stuck with the size you chose. No menu options, dialogs, or wizards can increase it…

...unless you do this trick. Thanks to Paul Marshall for outlining these steps.

I have done this a couple of times and have found these steps work almost without fail. One observation, is that apparently the hard drive needs to be assigned a drive letter, or otherwise you cannot extend it. Here are the complete steps:

1: Create a new full clone of your VM machine you want to increase in size, ensuring it has no snapshots.
2: Open the folder containing your VM files and you should have only one vmdk file.
3: Open a Command Prompt and issue the following command, choosing your own size in Gigabytes, followed by the path to the vmdk file: vmware-vdiskmanager -x 20Gb vmdiskfile.vmdk
4: After several minutes, the process completes, however, the disk is not ready yet. 5: You have expanded it, but the newly added space has not been allocated yet and is thus unusable at this point. If the disk is the system volume you will need to mount the disk in a second VM and expand it from there. If its not a system volume do it within the virtual machine it belongs to.
6: Once you've mounted the disk in a different VM or booted up the VM it belongs to if its not the system volume, do the following: click on Start and then right-click on My Computer and select Manage
7: Click on Disk Management
8: Your second hard drive should show as available and the difference in space shows as unpartitioned.
9: Ensure this second hard drive has a drive letter, if not, assign it one.
10: Open a Command Prompt and type: diskpart
11: Then type list disk and ensure the disk you want to expand is indeed in the list.
12: Now type list volume
13: This will show you the drives, their volume number, capacity etc. You now need to select the volume you are about to expand, using the following command. Where n is equal to the number of the volume. select volume=n
14: Once selected, you can now expand it using the extend command. Type extend, and your hard drive is ready. Close your machine (without saving) and start up the VM that this drive is the system volume on and check the size.
by Miguel Moreno

Friday, 23 July 2010

install grc

add match in /etc/grc.conf

add corresponding conf file in /usr/share/grc

for example log4j


#Colours are one of:
# none, default, bold, underline, blink, reverse, concealed,
# black, green, yellow, blue, magenta, cyan, white,
# on_black, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white
# beep
#
#count is one of words: once, more, stop, previous, block or unblock
#
# * once means that if the regexp is matched, its first occurrence is coloured
# and the program will continue with other regexp's.
#
# * more means that if there are multiple matches of the regexp in one line,
# all of them will be coloured.
#
# * stop means that the regexp will be coloured and program will move to the
# next line (i.e. ignoring other regexp's)
#
# * previous means the count will be the same as for the previous line
#
# * block marks a start of a multiline block of text, coloured with
# the same colour
#
# * unblock, obviously, marks the end of such a block

regexp=\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\W\d{3}
colours="\033[1;38;5;16m"
count=more
=====
regexp=INFO\s+\[.+\]
colours=blue
count=once
=====
regexp=\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\W\d{3}\s+INFO
colours=on_blue
count=once
=====
regexp=DEBUG\s+\[.+\]
colours=green
count=once
=====
regexp=\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\W\d{3}\s+DEBUG
colours=on_green
count=once
=====
regexp=WARN\s+\[.+\]
colours=yellow
count=once
=====
regexp=\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\W\d{3}\s+WARN
colours=on_yellow
count=once
=====
regexp=ERROR\s+\[.+\]
colours=red
count=once
=====
regexp=\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\W\d{3}\s+ERROR
colours=on_red
count=once


Then use grc:

grc tail -300f x.log

this will trigger the log.conf file and colourize the tail output

Monday, 5 July 2010

Use marathon ant and maven

Running marathon from an ant task is easy. To setup the classpath however is a pain. Marathon can either run in test or gui mode. Gui is used when you develop a test.

Start with installing the actual marathon application.

Create a pom with the artifact that contains the gui application. This is just so that the pom version is updated by a release.

Finally use this ant file to run marathon:
-------------------------------------------------------
<?xml version="1.0"?>

<project name="main" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">


<property name="m2_loc_repo" value="${user.home}/.m2/repository"/>

<!-- has its own pom so that we the version will change with the maven releases -->
<artifact:dependencies pathId="aqva_client.classpathId">
<pom file="pom.xml"/>
<localRepository path="${m2_loc_repo}"/>
</artifact:dependencies>

<taskdef resource="net/sf/antcontrib/antlib.xml"/>

<property file="aqva_marathon.properties"/>
<fail unless="marathon.home">
You need to add a file called aqva_marathon.properties with the following properties:

marathon.home (required): path to marathon downloaded from here http://www.marathontesting.com
aqva_url (optional): url to aqva server, default: http://localhost:8080/Aqva/
aqva_user (optional): user aqva server, default: roger
aqva_pwd (optional): password aqva server, default: helly
</fail>


<path id='marathon_classpath'>
<fileset dir="${marathon.home}">
<include name="marathon.jar"/>
<include name="marathon-python.jar"/>
<include name="marathon-ruby.jar"/>
<include name="marathon-runtime.jar"/>
</fileset>
<fileset dir="${marathon.home}/Support">
<include name="forms-1.2.1/forms-1.2.1.jar"/>
<include name="jaccess-1.3/jaccess.jar"/>
<include name="jedit-textArea.jar"/>
<include name="jline-0.9.93.jar"/>
<include name="junit3.8.2/junit.jar"/>
<include name="looks-2.2.0/looks-2.2.0.jar"/>
<include name="vldocking_2.1.5C.jar"/>
</fileset>
</path>


<property name='marathon.project.dir' value='.'/>

<!-- the default test i.e. all tests -->
<property name="test" value=""/>
<property name="aqva_url" value="xxx"/>
<property name="aqva_user" value="yyy"/>
<property name="aqva_pwd" value="zzz"/>

<!-- has a value that is used for all tests in run, use this to create unique data that is used
between tests in one run -->
<tstamp>
<format property="timestamp_val" pattern="yyyyMMdd_HHmmss_SSS" />
</tstamp>


<target name="test" description="runs test(s) in batch mode (wo gui) -Dtest= to run a specific test">
<property name="app_classpath" refid="aqva_client.classpathId"/>

<java classname="net.sourceforge.marathon.Main" fork="yes">
<classpath refid="marathon_classpath"/>
<jvmarg value="-Dmarathon.application.classpath=${app_classpath}"/>
<jvmarg value="-Dpython.cachedir=${env.HOME}/.jycache"/>
<jvmarg value="-Dmarathon.project.file=marathon_test.project"/>
<!-- send in java exe -->
<jvmarg value="-Dmarathon.application.vm.command=${java.home}/bin/java"/>
<!-- send startup args -->
<jvmarg value="-Dmarathon.application.vm.arguments=-Daqva_url=${aqva_url} -Daqva_user=${aqva_user} -Daqva_pwd=${aqva_pwd} -Dtimestamp_val=${timestamp_val}"/>

<arg value="-batch"/>
<arg value="-reportdir"/>
<arg value="${marathon.project.dir}/reports"/>
<arg line="${marathon.project.dir}"/>
<arg line="${test}"/>
</java>
</target>

<target name="gui" description="run marathon gui for developing tests">
<!-- need to set the classpath in the project file-->
<property name="app_classpath" refid="aqva_client.classpathId"/>

<propertyregex property="app_classpath_fixed"
input="${app_classpath}"
regexp="\\"
replace="/"
global="true"
defaultValue="${app_classpath}"/>
<propertyregex property="JAVA_EXE_PATH_fixed"
input="${java.home}/bin/java"
regexp="\\"
replace="/"
global="true"
defaultValue="${java.home}/bin/java"/>
<copy file="resources/marathon_gui.project_TEMPLATE" tofile="temp/marathon_gui.project" overwrite="true">
<filterset>
<filter token="APP_CLASSPATH" value="${app_classpath_fixed}"/>
<filter token="JAVA_EXE_PATH" value="${JAVA_EXE_PATH_fixed}"/>
<filter token="APP_ARGS"
value="-Daqva_url=${aqva_url} -Daqva_user=${aqva_user} -Daqva_pwd=${aqva_pwd} -Dtimestamp_val=${timestamp_val}"/>
</filterset>
</copy>

<!--echo message="${app_classpath}"/-->
<java classname="net.sourceforge.marathon.Main" fork="yes">
<classpath refid="marathon_classpath"/>
<jvmarg value="-Xmx256m"/>
<jvmarg value="-Dmarathon.home=${marathon.home}"/>
<jvmarg value="-Dpython.cachedir=${env.HOME}/.jycache"/>
<jvmarg value="-Dmarathon.project.file=temp/marathon_gui.project"/>

<arg line="${marathon.project.dir}"/>
</java>
</target>

</project>

------

Monday, 28 June 2010

exclude transitive dependencies in maven built ear

set: <defaultlibbundledir>..</defaultlibbundledir>
as in

<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-ear-plugin</artifactid>
<version>2.4.2</version>
<configuration>
<version>5</version>
<defaultlibbundledir>..</defaultlibbundledir>
<modules>
<jarmodule>
<groupid>antlr</groupid>
<artifactid>antlr</artifactid>
<includeinapplicationxml>true</includeinapplicationxml>
<bundledir>APP-INF/lib</bundledir>
</jarmodule>
</modules>
...
</configuration>
</plugin>

Friday, 26 March 2010

android:
adb logcat - trace log
telnet localhost
gsm call 12345678

Friday, 22 January 2010

FileInputStream input = new FileInputStream("/tmp/1.xml");
FileChannel channel = input.getChannel();

// Create a read-only CharBuffer on the file
ByteBuffer bbuf = channel.map(FileChannel.MapMode.READ_ONLY, 0, (int) channel.size());
CharBuffer cbuf = Charset.forName("UTF-8").newDecoder().decode(bbuf);

Tuesday, 5 January 2010

vmware tools, ubuntu 9.10 minimal virtual machine

First:
sudo apt-get install build-essential linux-headers-`uname -r` gcc make

Follow: http://langui.sh/2009/10/05/ubuntu-9-10-in-vmware/

We use the virtual kernel package
cd /usr/src/
sudo dpkg -i --force-depends open-vm-modules-2.6.31-14-generic-pae_2009.07.22-179896-2+2.6.31-14.48_i386.deb

The steps above upgraded the kernel but the vmware tools is compiled for the older kernel. Follow
http://www.kunthar.com/blogs/kunthar.php/grub2-switching-boot-order

to do a default boot from the older

Monday, 7 December 2009

Using grinder and junit.

It may be convenient to use junit tests for stress tests sometimes.

junit.py

from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from java.lang import Class
from java.lang import System
from java.lang import Integer
from java.lang import Runnable
from java.lang import Thread
from java.lang import Exception
from java.lang import Throwable
from org.junit.runner import JUnitCore
from org.junit.runner import Request
from org.junit.runner import Result
from org.junit.runner.notification import RunListener

class MyRunListener(RunListener):

def testFailure(self,failure):
print "jUniTFailure: " + failure.toString() + failure.trace
grinder.logger.error("jUniTFailure: " + failure.toString() + failure.trace)

def testFinished(self,description):
print "jUniTFinished: " + description.displayName
grinder.logger.output("jUniTFinished: " + description.displayName)

def testRunFinished(self,result):
grinder.logger.output("jUniTRunFinished: ")

def testRunStarted(self,description):
print "jUniTRunStarted: "
grinder.logger.output("jUniTRunStarted: ")

def testStarted(self,description):
print "jUniTestStarted: " + description.displayName
grinder.logger.output("jUniTestStarted: " + description.displayName)

# recursive method to get all tests regardless of what test description is used
# The description has a tree structure that has to be traversed. The actual tests are
# the leaves with no children
def getTests(description):
if (description.children == None or description.getChildren().size() == 0):
return [description]

childDescs = description.children
idx=0

children=[]
while idx < childDescs.size():
if (childDescs.get(idx).children == None or childDescs.get(idx).getChildren().size() == 0):
children.append(childDescs.get(idx))
else:
children.extend(getTests(childDescs.get(idx)))

idx=idx+1
return children

class TestRunner:
def __call__(self):

#wait with writing the reports
grinder.statistics.delayReports = 1

# get settings from the start script
testClassName = System.getProperty("grinder.test")
offsetStr = System.getProperty("grinder.offset")
offset=0
if offsetStr != None:
offset=int(offsetStr)


jUnitCore=JUnitCore()
#jUnitCore.addListener(MyRunListener())

mainRequest=Request.aClass(Class.forName(testClassName));

description= mainRequest.getRunner().getDescription()

testDecs=getTests(description)
idx=0
for testDec in testDecs:
#print "running test "+childDescs.get(idx).toString()

# we only have the display name for each test. The syntax is method_name(test_class_name)
displayName=testDec.displayName
method=displayName[:displayName.index('(')]
testClass=displayName[displayName.index('(')+1:displayName.index(')')]

#print "method: "+displayName[:displayName.index('(')]
# lookup the junit test
childReq=Request.method(Class.forName(testClass), displayName[:displayName.index('(')])
print "running test "+testClass+"."+method
print "#tests "+str(childReq.getRunner().testCount())
print "runner description "+childReq.getRunner().getDescription().displayName

# wrap the junit test with the grinder test. This basically triggers the statitics in
# grinder when we call any method on the wrapped object
wrappedJunitCore = Test(offset+idx, testDec.displayName).wrap(jUnitCore)

# start junit test and collect statistics for grinder
result=wrappedJunitCore.run(childReq)
idx=idx+1
if result.failureCount > 0:
grinder.statistics.forLastTest.setSuccess(0)
failures=result.failures
failure=failures.get(0)
print "failure: "+failure.toString()
print "failure trace: "+failure.getTrace()
grinder.logger.error("jUniTFailure: " + failure.toString() + failure.trace)



starting grinder using classpath from maven and ant
<?xml version="1.0"?>
<project name="main" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">


<property name="script_folder" value="."/>
<property name="project_dir" value="."/>


<property name="repo_server" value="x.y.z"/>
<property name="repo_url" value="http://${repo_server}:8081"/>

<property name="m2_repo_path" value="${user.home}/.m2/repository"/>

<!-- handle artifacts -->
<!--artifact:remoteRepository id="public.repository" url="http://10.71.64.68:8081/nexus/content/repositories/central-m1/"/-->
<artifact:remoteRepository id="central" url="${repo_url}/nexus/content/groups/public"/>
<artifact:remoteRepository id="snapshot.repository" url="${repo_url}/nexus/content/groups/public-snapshots/"/>
<artifact:localRepository id="local.repository" path="${m2_repo_path}"/>

<artifact:dependencies pathId="deps.classpath" filesetId="deps.fileset" useScope="test">
<pom file="${project_dir}/pom.xml">
</pom>
<localRepository refid="local.repository"/>
<remoteRepository refid="central"/>
<remoteRepository refid="snapshot.repository"/>
</artifact:dependencies>


<artifact:dependencies pathId="grinder.classpath">
<dependency groupId="junit" artifactId="junit" version="4.7"/>
<dependency groupId="grinder" artifactId="grinder-j2se5" version="3.1"/>
<dependency groupId="grinder" artifactId="grinder" version="3.1"/>
<dependency groupId="grinder" artifactId="grinder-xmlbeans" version="3.1"/>
<dependency groupId="grinder" artifactId="picocontainer" version="1.3"/>
<dependency groupId="javax.xml.bind" artifactId="jsr173_api" version="1.0"/>
<dependency groupId="grinder" artifactId="jython" version="2.2.1"/>
<dependency groupId="grinder" artifactId="xmlbeans-xbean" version="2.3.0"/>
<dependency groupId="grinder" artifactId="picocontainer" version="1.3"/>


<localRepository refid="local.repository"/>
<remoteRepository refid="central"/>
<remoteRepository refid="snapshot.repository"/>
</artifact:dependencies>


<artifact:dependencies pathId="antcontrib.classpath">
<dependency groupId="ant-contrib"
artifactId="ant-contrib"
version="1.0b3"/>
<localRepository refid="local.repository"/>
<remoteRepository refid="central"/>
<remoteRepository refid="snapshot.repository"/>
</artifact:dependencies>


<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<path refid="antcontrib.classpath"/>
</classpath>
</taskdef>


<property name="testClassPattern" value="**/JUnit*IntegrationTest.class"/>
<property name="noTestsInParallell" value="1"/>
<target name="run-tests">
<var name="idx" value="0"/>
<for param="integrationtestfull" parallel="true" threadCount="${noTestsInParallell}">
<path>
<fileset dir="${project_dir}/target/test-classes" includes="${testClassPattern}"/>
</path>
<sequential>

<propertyregex property="integrationtesttmp"
input="@{integrationtestfull}"
override="true"
regexp=".+[\/\\]target[\/\\]test-classes[\/\\](.+)\.class"
select="\1"/>
<propertyregex property="integrationtest"
input="${integrationtesttmp}"
override="true"
regexp="[\/\\]"
replace="\."/>
<!--var name="offset" unset="true"/-->
<math result="offset" operand1="${idx}" operation="*" operand2="100" datatype="int"/>
<math result="idx" operand1="${idx}" operation="+" operand2="1" datatype="int"/>
<antcall target="run-agent">
<param name="grinder.test" value="${integrationtest}"/>
<param name="grinder.offset" value="${offset}"/>
</antcall>
</sequential>
</for>
</target>

<!-- Default values sent to the agent process -->
<property name="grinder.processes" value="1"/>
<property name="grinder.threads" value="1"/>
<property name="grinder.runs" value="1"/>
<property name="grinder.consoleHost" value="localhost"/>
<property name="grinder.consolePort" value="6372"/>

<target name="run-agent">
<echo message="grinder.test ${grinder.test} offset ${grinder.offset}"/>
<echo message="args to gridner agent -Dgrinder.runs=${grinder.runs} -Dgrinder.processes=${grinder.processes} -Dgrinder.threads=${grinder.threads} -Dgrinder.test=${grinder.test} -Dmts.integrationtest.enabled=true -Dmts.integrationtest.jnp.url=${mts.integrationtest.jnp.url} -Dgrinder.offset=${grinder.offset}"/>
<echo message="property file ${script_folder}/grinder.properties"/>
<java classname="net.grinder.Grinder"
fork="true"
failonerror="true"
maxmemory="64m">
<classpath>
<path refid="grinder.classpath"/>
<path refid="deps.classpath"/>
</classpath>
<arg value="${script_folder}/grinder.properties"/>
<!-- Args sent to the agent worker processes -->
<sysproperty key="grinder.jvm.arguments" value=" -Dgrinder.runs=${grinder.runs} -Dgrinder.processes=${grinder.processes} -Dgrinder.threads=${grinder.threads} -Dgrinder.test=${grinder.test} -Dmts.integrationtest.enabled=true -Dmts.integrationtest.jnp.url=${mts.integrationtest.jnp.url} -Dgrinder.offset=${grinder.offset}"/>
<!-- Args sent to the agent process -->
<sysproperty key="grinder.runs" value="${grinder.runs}"/>
<sysproperty key="grinder.processes" value="${grinder.processes}"/>
<sysproperty key="grinder.threads" value="${grinder.threads}"/>
<sysproperty key="grinder.consoleHost" value="${grinder.consoleHost}"/>
<sysproperty key="grinder.consolePort" value="${grinder.consolePort}"/>
</java>
</target>

<target name="run-console">
<java classname="net.grinder.Console"
fork="true"
failonerror="true"
maxmemory="64m">
<classpath>
<path refid="grinder.classpath"/>
</classpath>
</java>
</target>
<path id="jython.classpath">
<path refid="grinder.classpath"/>
<!--path refid="deps.classpath"/-->
<pathelement location="target/classes/"/>
<pathelement location="target/test-classes/"/>
</path>

</project>

Friday, 13 February 2009

How to add a svnlog to artifact

<!-- this puts a xml file with svn log info in the ear -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
<configuration>
<executable>svn</executable>
<commandlineArgs>log --xml -r{`date %Y-%m-%d -d '2 months ago'`}:HEAD</commandlineArgs>
<skip>${skipSvnLog}</skip>
<workingDirectory>${basedir}/../..</workingDirectory>
<outputFile>${project.build.directory}/${project.build.finalName}/svnlog.xml</outputFile>
</configuration>
</plugin>

Thursday, 22 May 2008

Monitor long running task

When I run a long running command and can't be bothered to check up on it.

I start it with nohup so I can log out. It returns a which pid it was started with

bash-2.05$ nohup [command] > log.log &
Sending output to nohup.out
[1] 1247

Then I start a monitor script that mails me when the process is finished

bash-2.05$ nohup ./mail_when_finished.sh 1247 &


Script (works on solaris):
--------------------------------
#!/usr/bin/sh
trap '' 1
pid=$1

bail_out () {
mail name@domain.com <Subject: My_Job has finished
Importance: high
X-Priority: 1


My_Job has finished running.
.
!done
exit 0
}

check_it () {

while :
do
ps -p $pid > /dev/null 2>&1
case $? in
0) sleep 120 ;;
*) bail_out; exit 1 ;;
esac
done
}

check_it

---------------------
I took and modified the script from http://www.unix.com/shell-programming-scripting/3205-lightwight-process-monitor.html

Monday, 14 January 2008

Installing Ubuntu on MacBookPro (SantaRosa)

I bought a MacBook in a weak moment but realized that OS X is overhyped.

Therefore I decided to install ubuntu 7.10. This are the steps I took (after a lot of googling).

There are a lot of information but none worked 100% for me.

The whole problem was that when I installed it, the screen was just empty or it stopped at "running local boot scripts".
  1. Made a backup... with time machine.
  2. used boot camp to make a new partition.
  3. installed refit
  4. Downloaded ubuntu (after a lot of trying I used the "alt"-version 64 bit)
  5. When the install selection window is shown. Press F6. You will get boot command that you can edit. Remove "splash" and "quiet"
  6. Start in safe graphics mode
  7. After some time it will stop on "running local boot scripts"
  8. do a control-c and on the prompt write "startx"
  9. wait for a few minutes and you will get the "normal" install window.
  10. Install as normal, remember to choose the correct keyboard
  11. Important. Do not allocate 100% of your partition. It seems like Ubuntu needs to save some on the harddisk.
Then after the reboot, you will need to remove the splash boot commando again.

Now I hope that I can follow the documentation on the web. I'll get back on that.

Monday, 26 November 2007

Nohup and sqlplus for long oracle batch jobs

To run a batch job in oracle. You want to use nohup, redirect the nohup.log etc.

nohup sqlplus [user]/[pwd] @[script] / -print > [logfile] &

note that the "-print >" is not to be changed

The spooling doesn't work due to the fact that the spool buffer seems to be flushed at the end of the script

Wednesday, 29 August 2007

Using headers in GWT FlexTable

I'm a moron. I've been dicking around with headers in GWT FlexTable for a while. I simply added rows and used a different styleset for the headers. Then I had to subtract and add for each table operation....

The solution is (of course) to insert table headers with the DOM-class in GWT.


/**
* Initializes the table with header rows. The headers are defined by the headerModel
* This adds the header rows directly to the table, using the DOM-class. The current FlexTable implemenetation
* doesn't have headers. This uses the normal html ... syntax
*/
private void initTable() {

Element thead = DOM.createTHead();

DOM.insertChild(table.getElement(), thead, 0);

for (int row = 0; row <>

Element tr = DOM.createTR();
DOM.appendChild(thead, tr);
for (int col = 0; col <>

Element th = DOM.createTH();
DOM.appendChild(tr, th);

// NB!!!! camelback on attributes for IE or despair
DOM.setElementAttribute(th, "colSpan", String.valueOf(headerModel.getHeaderSpan(row, col)));
DOM.setElementAttribute(th, "align", "left");
DOM.setElementAttribute(th, "border", "1");

//set header text
DOM.setInnerText(th, headerModel.getHeaderText(row, col));
}
}

}

Now the number of rows, clear etc works fine. FlexTable uses "correct". The camel back IE "feature" took me a while though.

Saturday, 11 August 2007

Printing protected PDF files

Once every year, I need to print a protected PDF-file. Of course I forget what I did in between. The main problem is that you can't print a protected file from the Adobe Reader even if you have the password. They want you to buy the full Adobe product
  1. Download pdfbox from sourceforge. The latest version does not work but version 0.7.0 works fine.
  2. Unzip it and go to the bin directory. Run: Decrypt.exe . And the file is printable!!
While Googling, I found the PDFCrack utility (also on sourceforge), which is used to crack pdf files. It's now running in the background. This may also work