.comment-link {margin-left:.6em;} <$BlogRSDURL$>

Monday, February 27, 2006

SQL - Compute duration between two TIMESTAMPs 

Do you want to compute the time between two SQL TIMESTAMP objects? Try the following, replacing TS1 and TS2 with column containing the TIMESTAMP value.

(
EXTRACT (DAY FROM TS2-TS1) * 24 * 60 * 60
+ EXTRACT (HOUR FROM TS2-TS1) * 60 * 60
+ EXTRACT (MINUTE FROM TS2-TS1) * 60
+ EXTRACT (SECOND FROM TS2-TS1)
) AS SEC_DURATION

I'm not 100% sure that it's not specific to Oracle, but I think it should work with most databases.

JUnit and Maven - LinkageError: loader constraints violated when linking 

Today I ran into an error trying to run my JUnit (3.8.1) test for my spring (1.2.6) application from within Maven (1.0.2). It looked like the following:

Testsuite: com.carrieriq.sqp.collector.AppTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.762 sec

Testcase: testApp(com.carrieriq.sqp.collector.AppTest): Caused an ERROR
loader constraints violated when linking org/w3c/dom/Node class
java.lang.LinkageError: loader constraints violated when linking org/w3c/dom/Node class
at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java :294)
at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:191)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:295)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:223)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions (XmlBeanDefinitionReader.java:148)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java :126)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
This error can happen when using earlier versions of JUnit (I believe anything before 3.8 or so) or when using later version of JUnit within maven. A google search on the subject found a dated answer in the JUnit FAQ:

The JUnit FAQ says:

Why do I get a LinkageError when using XML interfaces in my test?

(Submitted by: Scott Stirling)

The workaround as of JUnit 3.7 is to add org.w3c.dom.* and org.xml.sax.* to your excluded.properties.

It's just a matter of time before this fix becomes incorporated into the released version of JUnit's excluded.properties, since JAXP is a standard part of JDK 1.4. It will be just like excluding org.omg.*. By the way, if you download the JUnit source from its Sourceforge CVS, you will find that these patterns have already been added to the default excluded.properties and so has a pattern for JINI. In fact, here is the current version in CVS, which demonstrates how to add exclusions to the list too:

#
# The list of excluded package paths for the TestCaseClassLoader
#
excluded.0=sun.*
excluded.1=com.sun.*
excluded.2=org.omg.*
excluded.3=javax.*
excluded.4=sunw.*
excluded.5=java.*
excluded.6=org.w3c.dom.*
excluded.7=org.xml.sax.*
excluded.8=net.jini.*

What isn't clear from the FAQ is that this problem was fixed by JUnit 3.8, and yet it can still happen when using JUnit from within Maven.

To solve the problem within maven, make sure you fork a new JVM to run your junit tests:

in project.properties, add :
------------------------------
maven.junit.fork=true
maven.compile.fork=true
------------------------------
to fork to distinct JVM.


Reference


This page is powered by Blogger. Isn't yours?