Hi!
I thought you may be interested: here's a recollection of problems I
have encountered while trying to use Harmony for a small project at
work.
First, jmock-based unit tests fail when run under Harmony's JVM.
Compiler doesn't seem to matter: both sun's and harmony's work. I have
attached a sample program which reproduces the following error:
unexpected invocation: foo.frob()
expectations:
expected exactly 1 time, already invoked 0 times: foo.frob();
returns a default value
at
org.jmock.internal.InvocationDispatcher.dispatch(InvocationDispatcher.java:54)
at org.jmock.Mockery.dispatch(Mockery.java:194)
at org.jmock.Mockery.access$000(Mockery.java:34)
at org.jmock.Mockery$MockObject.invoke(Mockery.java:221)
at
org.jmock.internal.InvocationDiverter.invoke(InvocationDiverter.java:27)
at
org.jmock.internal.ProxiedObjectIdentity.invoke(ProxiedObjectIdentity.java:33)
at
org.jmock.lib.JavaReflectionImposteriser$1.invoke(JavaReflectionImposteriser.java:34)
at $Proxy0.frob(Unknown Source)
at SimpleMock.main(SimpleMock.java:21)
Second, our java.nio-based network code which works on Sun's JVM
throws a SockectExcepion on innocent-looking code:
java.net.SocketException
at
org.apache.harmony.luni.platform.OSNetworkSystem.select(OSNetworkSystem.java:312)
at
org.apache.harmony.nio.internal.SelectorImpl.selectInternal(SelectorImpl.java)
at
org.apache.harmony.nio.internal.SelectorImpl.select(SelectorImpl.java:167)
at
com.shamrock.smf.niosmpp.net.SelectorHandler.run(SelectorHandler.java:156)
These exceptions don't seem to affect the application though. They
seem to happen after setting OP_WRITE on each interesting selection
key. Relevant portion of source code looks like this (unfortunately I
cannot provide a short runnable example):
while (true) {
try {
/* register new channels etc. */
synchronized(this.writableKeys) {
/* for each key in writableKeys */
if (key.isValid()) {
key.interestOps(key.interestOps() |
SelectionKey.OP_WRITE);
}
}
selector.select(selectTimeout);
Set set = selector.selectedKeys();
/* process selected keys */
set.clear();
}
}
However, the problem might as well be in buggy application code. Any
ideas on how to debug this?
Third, VM hard-codes default character set to iso-8859-1 instead of
using process' locale settings. Every UTF-8 user then has to manually
set file.encoding system property, or otherwise get garbage on console
when output does not fit in ASCII.
Lastly, is there a native javac adapter for ant? One can use
build.compiler=extJavac or write a custom CompilerAdapter, but a
drop-in replacement for Sun's javac would be nice. Google even finds
an implementation of com.sun.tools.javac.Main in harmony's subversion
repo, but it seems to have been removed later (for trademark
reasons?).
Harmony & OS details:
$ java -version
Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software
Foundation or its licensors, as applicable.
java version "1.5.0"
pre-alpha : not complete or compatible
svn = r533500, (Apr 30 2007), Linux/ia32/gcc 4.1.0, release build
http://incubator.apache.org/harmony
OS: Debian linux 4.0, kernel: 2.6.18-4-686 #1 SMP, libc-2.3.6
Thank you.
--
Alexey Grigorovich
import org.jmock.Mockery;
import org.jmock.Expectations;
/*
* Run with:
*
* CLASSPATH=hamcrest-api-1.0.jar:hamcrest-library-1.0.jar:jmock-2.0.0.jar:.
* javac -source 1.5 -target 1.5 -classpath $CLASSPATH SimpleMock.java
* java -classpath $CLASSPATH SimpleMock
*/
public class SimpleMock {
public static void main(String[] args) {
try {
Mockery context = new Mockery();
final Foo foo = context.mock(Foo.class);
context.checking(new Expectations() {{
one(foo).frob();
}});
foo.frob();
context.assertIsSatisfied();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
public interface Foo {
void frob();
}