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);
Friday, 22 January 2010
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
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
starting grinder using classpath from maven and ant
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>
<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
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".
Now I hope that I can follow the documentation on the web. I'll get back on that.
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".
- Made a backup... with time machine.
- used boot camp to make a new partition.
- installed refit
- Downloaded ubuntu (after a lot of trying I used the "alt"-version 64 bit)
- When the install selection window is shown. Press F6. You will get boot command that you can edit. Remove "splash" and "quiet"
- Start in safe graphics mode
- After some time it will stop on "running local boot scripts"
- do a control-c and on the prompt write "startx"
- wait for a few minutes and you will get the "normal" install window.
- Install as normal, remember to choose the correct keyboard
- Important. Do not allocate 100% of your partition. It seems like Ubuntu needs to save some on the harddisk.
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
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
Subscribe to:
Posts (Atom)