|
|
|
|||||
|
ICE_CONFIG not honored under Java in 3.3
I may be misunderstanding under what conditions ICE_CONFIG is used in Java, but the attached tests shows that what I think is a straight-forward usage does not work, while it does so in Python.
|
|
|||||
|
|||||
|
Sorry about the attachment. For whatever reason, they don't seem to be working for me. Instead, here's a script file to run the whole test:
Code:
#!/bin/bash
test -e "$CLASSPATH" || {
echo "$CLASSPATH unfound. Set CLASSPATH to Ice-3.3.0.jar"; exit 1
}
echo `uname -a`
echo `java -version`
echo =========================
rm -rf test
mkdir test
cat > test/iceconfigtest.cfg<<EOF
omero.user=me
EOF
cat > test/iceconfigtest.java<<EOF
public class iceconfigtest
{
public static void main(String[] args)
{
System.out.println("ENV:" + System.getenv("ICE_CONFIG"));
Ice.InitializationData id = new Ice.InitializationData();
id.properties = Ice.Util.createProperties();
if ( args.length > 0 )
{
for ( String arg : args )
{
System.out.println("Loading: " + arg);
id.properties.load( arg );
}
}
Ice.Communicator ic = Ice.Util.initialize( id );
try
{
String value = ic.getProperties().getProperty("omero.user");
System.out.println("ICE:" + value);
assert "me".equals(value);
}
finally
{
ic.destroy();
}
}
}
EOF
cat > test/iceconfigtest.py<<EOF
import Ice, os
print "ENV: " + os.environ["ICE_CONFIG"]
id = Ice.InitializationData()
ic = Ice.initialize(id)
value = ic.getProperties().getProperty("omero.user")
print value
assert value == "me"
EOF
cd test
echo Compiling
javac -cp $CLASSPATH iceconfigtest.java
echo Passes with value on command line
env ICE_CONFIG=iceconfigtest.cfg java -ea -cp $CLASSPATH:. iceconfigtest iceconfigtest.cfg
echo Fails without.
env ICE_CONFIG=iceconfigtest.cfg java -ea -cp $CLASSPATH:. iceconfigtest
echo Also ok in Python
env ICE_CONFIG=iceconfigtest.cfg python iceconfigtest.py
Code:
CLASSPATH=xxx/ice-3.3.0.jar ./ice_config.sh
Linux gxxx 2.6.18-53.1.14.el5 #1 SMP Wed Mar 5 11:37:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) 64-Bit Server VM (build 10.0-b22, mixed mode)
=========================
Compiling
Passes with value on command line
ENV:iceconfigtest.cfg
Loading: iceconfigtest.cfg
ICE:me
Fails without.
ENV:iceconfigtest.cfg
ICE:
Exception in thread "main" java.lang.AssertionError
at iceconfigtest.main(iceconfigtest.java:24)
Also ok in Python
ENV: iceconfigtest.cfg
Code:
CLASSPATH=xxx/ice-3.3.0.jar ./ice_config.sh
Linux nxxx 2.6.23-gentoo-r8 #2 SMP Tue Feb 19 19:27:38 GMT 2008 x86_64 Intel(R) Xeon(R) CPU X5355 @ 2.66GHz GenuineIntel GNU/Linux
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode)
=========================
Compiling
Passes with value on command line
ENV:iceconfigtest.cfg
Loading: iceconfigtest.cfg
ICE:me
Fails without.
ENV:iceconfigtest.cfg
ICE:
Exception in thread "main" java.lang.AssertionError
at iceconfigtest.main(iceconfigtest.java:24)
...(missing Python)...
Code:
CLASSPATH=xxx/ice-3.3.0.jar ./ice_config.sh
Darwin jxxx 8.11.1 Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386 i386 i386
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-275)
Java HotSpot(TM) Client VM (build 1.5.0_16-132, mixed mode, sharing)
=========================
Compiling
Passes with value on command line
ENV:iceconfigtest.cfg
Loading: iceconfigtest.cfg
ICE:me
Fails without.
ENV:iceconfigtest.cfg
ICE:
Exception in thread "main" java.lang.AssertionError
at iceconfigtest.main(iceconfigtest.java:24)
Also ok in Python
ENV: iceconfigtest.cfg
me
|
|
||||||
|
This is not a bug in Ice. The issue is that you are using Ice.Util.createProperties() (ie with no args) to create the properties in your test. If you take a look at section 38.8.2 of the manual you will see the following:
"The parameter-less version of createProperties simply creates an empty property set. It does not check ICE_CONFIG for a configuration file to parse." Change your test to use Ice.Util.createProperties(args) and you should get the behavior you expect. |
|
|||||
|
Thanks for looking into this, Dwayne.
It's also possible to comment out the call to createProperties completely and still have the test case fail. It's there for doing the manual loading, but I did test without it. Is the expected behavior that ICE_CONFIG will only be checked when command-line-like arguments are explicitly passed into either Ice.Util.createProperties or an initialize method, i.e. not when using something like "Ice.Util.initialize()" If so, would you mind explaining the logic behind this for me? The behavior in Python where: Code:
import Ice ic = Ice.initialize() Thanks again, ~Josh. |
|
||||||
|
The behavior between python and java is indeed inconsistent. We are discussing internally how this should be fixed. That is, which language should be changed to act like the other. Thanks for bringing this to our attention.
|
|
|||||
|
Hi Dwayne,
just another data point for your discussions. I was surprised that the two print methods returned different values: Code:
import Ice
f = open("cfg","w")
f.write("omero.host=hi\n")
f.close()
args1 = ["--Ice.Config=cfg"]
args2 = list(args1)
id = Ice.InitializationData()
ic = Ice.initialize(args1,id)
print "1:",ic.getProperties().getProperty("omero.host")
id = Ice.InitializationData()
id.properties = Ice.createProperties()
id.properties.parseIceCommandLineOptions(args2)
id.properties.parseCommandLineOptions("omero", args2)
print id.properties
ic = Ice.initialize(id)
print "2:",ic.getProperties().getProperty("omero.host")
Not a complaint, just pointing out where even Ice regular's can go afoul. ~J. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Patch #3 for Ice 3.3.0 (C++): compression setting not always honored | benoit | Patches | 0 | 08-18-2008 04:11 AM |
| Is the ICE for Java based on Java NIO? | Jiangyubao | Comments | 1 | 03-30-2008 06:04 PM |
| Unset ICE_CONFIG when running tests | Edward Bishop | Comments | 1 | 10-23-2007 09:22 PM |
| IceV3.11 java client and vc7.0Server : java.lang.NullPointerException? | zhoubin | Help Center | 2 | 11-24-2006 03:03 AM |
| Question about ICE_CONFIG environment variable in Ice for java ? | rc_hz | Comments | 2 | 09-18-2006 05:54 AM |