Behaviour is different when program is exectued from windowsNT and solaris
from /usr/local/java/jdk1.4
java.util.prefs.Preferences getFloat()
While testing on Ultra60/SunOs5.7
Following line is output at the end of the program:
Couldn't flush system prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
Please see Observation case4:
Observation:
-----------------------------------------------------------------------------
windowsNT Case 1 :
d:/jdk1.4/bin/java GetFloatTest
passes
windows NT Case 2:
/usr/local/java/jdk1.4/win/bin/java GetFloatTest
passes
SunOS 5.7 case 3:
/home/pande/jdk1.4/bin/java GetFloatTest
passes
SunOS 5.7 case 4:
/usr/local/java/jdk1.4/solsparc/bin/java GetFloatTest
passes
with following message:
Couldn't flush system prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
---------------------------------------------------------
Test Program:
import java.util.prefs.*;
import java.util.*;
/**
*
*GetFloatTest01: Single JVM and Thread case:
*
*GetFloatTest01: java.util.prefs.Preferences long getFloat(java.lang.String key, float def)
*Create userRoot preferences
*Create "N1" node in userRoot
*In "N1" put key "k1" and value 1l
*verify 1l is put by calling getFloat() method, if ok then pass.
*
*GetFloatTest02: check for default
*
*GetFloatTest03: remove node and see that IllegalStateException is thrown when getFloat() is called.
*
*GetFloatTest04: key = null and see that NullPointerException is thrown when getFloat() is called.
*
*/
public class GetFloatTest {
public static void main(String[] args) throws Exception {
boolean status[];
int passcount = 0, failcount = 0;
int numTests = 4;
int i, j = 0;
status = new boolean[numTests];
System.out.println("Total tests for Exec : "+numTests);
for(i = 0; i < numTests; ++i) {
// GetFloat all tests in try... catch block
try {
++j;
switch (j) {
case 1:
status[i] = GetFloatTest01();
break;
case 2:
status[i] = GetFloatTest02();
break;
case 3:
status[i] = GetFloatTest03();
break;
case 4:
status[i] = GetFloatTest04();
break;
}
} catch (Exception e) {
status[i] = false;
System.out.println ("Exception in test "+j+": "+e.getMessage());
e.printStackTrace();
}
} // end for
// Get pass and fail totals
for(i = 0; i < numTests; ++i) {
if (status[i] == true)
passcount++;
else
failcount++;
}
System.out.println("Pass count: " + passcount);
System.out.println("Fail count: " + failcount);
// check if tests passed
if ( failcount < 1 ) {
System.out.println("Test for GetFloat.java Passed");
System.exit(0);
} else {
System.out.println("Test for GetFloat.java Failed");
System.exit(1);
}
} // end main
/**
*
*GetFloatTest01: java.util.prefs.Preferences long getFloat(java.lang.String key, float def)
*Create userRoot preferences
*Create "N1" node in userRoot
*In "N1" put key "k1" and value 1.0f
*verify 1.0f is put by calling getFloat() method, if ok then pass.
*
*/
public static boolean GetFloatTest01() {
boolean bReturn = false;
try {
Preferences userRoot = Preferences.userRoot();
Preferences N1 = userRoot.node("N1");
N1.clear();
float float01 = 1.0f;
N1.putFloat("k1",float01);
N1.flush();
float gotFloat = N1.getFloat("k1",0.0f);
if (gotFloat != 1.0f) {
throw new Exception("gotFloat != 1.0f not ok in GetFloatTest01()");
}
bReturn = true;
System.out.println("GetFloatTest01() Pass");
} catch(Exception e) {
bReturn = false;
System.out.println("Exception thrown = " + e);
System.out.println("GetFloatTest01() Fail");
e.printStackTrace();
}
return bReturn;
}
/**
*
*GetFloatTest02: check for default
*/
public static boolean GetFloatTest02() {
boolean bReturn = false;
try {
Preferences userRoot = Preferences.userRoot();
Preferences N1 = userRoot.node("N1");
N1.clear();
float float01 = 1.0f;
N1.putFloat("k1",float01);
N1.flush();
float gotFloat = N1.getFloat("k2",0.0f);
if (gotFloat != 0.0f) {
throw new Exception("gotFloat != 0.0f not ok in GetFloatTest02()");
}
bReturn = true;
System.out.println("GetFloatTest02() Pass");
} catch(Exception e) {
bReturn = false;
System.out.println("Exception thrown = " + e);
System.out.println("GetFloatTest02() Fail");
e.printStackTrace();
}
return bReturn;
}
/**
*
*GetFloatTest03: remove node and see that IllegalStateException is thrown when getFloat() is called.
*
*/
public static boolean GetFloatTest03() {
boolean bReturn = false;
try {
Preferences userRoot = Preferences.userRoot();
Preferences N1 = userRoot.node("N1");
float float01 = 1.0f;
N1.putFloat("k1",float01);
N1.flush();
N1.removeNode();
N1.getFloat("k1",0.0f);
bReturn = false;
System.out.println("GetFloatTest03() Fail");
} catch(IllegalStateException ise) {
bReturn = true;
System.out.println("Expected IllegalStateException thrown GetFloatTest03()Pass");
} catch(Exception e) {
bReturn = false;
System.out.println("Exception thrown = " + e);
System.out.println("GetFloatTest03() Fail");
e.printStackTrace();
}
return bReturn;
}
/**
*
*GetFloatTest04: key = null and see that NullPointerException is thrown when getFloat() is called.
*
*/
public static boolean GetFloatTest04() {
boolean bReturn = false;
try {
Preferences userRoot = Preferences.userRoot();
Preferences N1 = userRoot.node("N1");
float float01 = 1.0f;
N1.putFloat("k1",float01);
N1.flush();
N1.removeNode();
N1.getFloat(null,0.0f);
bReturn = false;
System.out.println("GetFloatTest04() Fail");
} catch(NullPointerException ise) {
bReturn = true;
System.out.println("Expected NullPointerException thrown GetFloatTest04()Pass");
} catch(Exception e) {
bReturn = false;
System.out.println("Exception thrown = " + e);
System.out.println("GetFloatTest04() Fail");
e.printStackTrace();
}
return bReturn;
}
}
-----------------------------------------outputresult case 3----
javasupport2:/home/pande/merlin/dev/testbase/src/libs_api_tests/common/java_util/prefs/Preferences/SJvmSThread/userRoot/GetFloat 32 % /home/pande/merlin/jdk14/bin/java GetFloatTest
Total tests for Exec : 4
GetFloatTest01() Pass
GetFloatTest02() Pass
Expected IllegalStateException thrown GetFloatTest03()Pass
Expected NullPointerException thrown GetFloatTest04()Pass
Pass count: 4
Fail count: 0
Test for GetFloat.java Passed
------------------------------------------case4 output-----------------
/usr/local/java/jdk1.4/solsparc/bin/java GetFloatTest
Total tests for Exec : 4
GetFloatTest01() Pass
GetFloatTest02() Pass
Expected IllegalStateException thrown GetFloatTest03()Pass
Expected NullPointerException thrown GetFloatTest04()Pass
Pass count: 4
Fail count: 0
Test for GetFloat.java Passed
Couldn't flush system prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.