📄 marshallingperftest.java
字号:
// Test using a map with the specified number of entries
System.out.println("\nTest using a map with " + entries +
" entries\n");
Map myMap = new HashMap();
for (int i = 0; i < entries; i++)
{
myMap.put("key" + i, "value" + i);
}
new STAFMarshallingContext();
mc.setRootObject(myMap);
formatter = new SimpleDateFormat("yyyy-MM-dd 'at' hh:mm:ss a");
System.out.println("FormatObject started: " + formatter.format(new Date()));
STAFMarshallingContext.formatObject(mc);
System.out.println("FormatObject ended : " + formatter.format(new Date()));
startTime = formatter.format(new Date());
System.out.println("Marshalling started : " + startTime);
result = mc.marshall();
endTime = formatter.format(new Date());
System.out.println("Marshalling ended : " + endTime);
System.out.println("Length of marshalled data: " + result.length());
startTime = formatter.format(new Date());
System.out.println("Unmarshalling started : " + startTime);
mc = STAFMarshallingContext.unmarshall(result);
endTime = formatter.format(new Date());
System.out.println("Unmarshalling ended : " + endTime);
myMap = new HashMap();
// Test using a list (with the specified number of entries / 10) of map
// class objects each with 10 keys
int numEntries = entries / 10;
System.out.println("\nTest using a list with " + numEntries +
" entries of map class objects with 10 keys\n");
// Define a map class with 10 keys
STAFMapClassDefinition myMapClass = new STAFMapClassDefinition(
"STAF/Test/MyMapClassDefinition");
int numKeys = 10;
for (int k = 1; k <= numKeys; k++)
{
myMapClass.addKey("key" + k, "Key #" + k);
}
// Create a marshalling context and assign a map class definition to it
mc = new STAFMarshallingContext();
mc.setMapClassDefinition(myMapClass);
List resultList = new ArrayList();
for (int i = 1; i <= numEntries; i++)
{
// Create an instance of this map class definition and assign
// data to the map class instance
Map theMap = myMapClass.createInstance();
for (int j = 1; j <= numKeys; j++)
{
theMap.put("key" + j, "Value " + j + " " + i);
}
resultList.add(theMap);
}
mc.setRootObject(resultList);
formatter = new SimpleDateFormat("yyyy-MM-dd 'at' hh:mm:ss a");
System.out.println("FormatObject started: " + formatter.format(new Date()));
STAFMarshallingContext.formatObject(mc);
System.out.println("FormatObject ended : " + formatter.format(new Date()));
startTime = formatter.format(new Date());
System.out.println("Marshalling started : " + startTime);
result = mc.marshall();
endTime = formatter.format(new Date());
System.out.println("Marshalling ended : " + endTime);
System.out.println("Length of marshalled data: " + result.length());
startTime = formatter.format(new Date());
System.out.println("Unmarshalling started : " + startTime);
mc = STAFMarshallingContext.unmarshall(result);
endTime = formatter.format(new Date());
System.out.println("Unmarshalling ended : " + endTime);
resultList = new ArrayList();
}
public static void testErrors(int entries)
{
System.out.println(
"\n************************************************************\n" +
"Test for Errors in Marshalling, FormatObject, and Unmarshall\n" +
"************************************************************\n");
int numKeys = 2;
System.out.println(
"Test for errors using a list with " + entries +
" entries of map class objects with " + numKeys + " keys");
// Define a map class with 2 keys
STAFMapClassDefinition myMapClass = new STAFMapClassDefinition(
"STAF/Test/MyMapClassDefinition");
for (int k = 1; k <= numKeys; k++)
{
myMapClass.addKey("key" + k, "Key #" + k);
}
// Create a marshalling context and assign a map class definition to it
STAFMarshallingContext mc = new STAFMarshallingContext();
//mc.setMapClassDefinition(myMapClass);
List resultList = new ArrayList();
for (int i = 1; i <= entries; i++)
{
// Create an instance of this map class definition and assign
// data to the map class instance
Map theMap = myMapClass.createInstance();
for (int j = 1; j <= numKeys; j++)
{
theMap.put("key" + j, "Value " + j + " " + i);
}
resultList.add(theMap);
}
mc.setRootObject(resultList);
// Verify that you can format, marshall, and unmarshall an object that
// references a map class but does not define the map class in the
// marshalling context.
System.out.println(
"\nVerify you can format, marshall, and unmarshall an object" +
" that references a map class but does not define the map" +
" class in the context:\n");
System.out.println(
"FormatObject result without map class definition in context:");
System.out.println(STAFMarshallingContext.formatObject(mc));
String result = mc.marshall();
System.out.println("\nMarshalled string:\n" + result);
System.out.println("\nLength of marshalled data: " + result.length());
STAFMarshallingContext mc2 = STAFMarshallingContext.unmarshall(result);
System.out.println(
"\nUnmarshall and call FormatObject on the context:\n" + mc2);
// Verify that calling formatObject on an object that references a
// map class but does not provide a marshalling context does not
// cause an error.
List outputList = (List)mc2.getRootObject();
System.out.println(
"\nPrint root list object as a formatted string:\n" +
STAFMarshallingContext.formatObject(outputList));
// Now create another map class definition with no keys and add it to
// the context but don't reference it.
STAFMapClassDefinition myMapClass2 = new STAFMapClassDefinition(
"STAF/Test/MyMapClassDefinition2");
mc.setMapClassDefinition(myMapClass2);
System.out.println(
"\nFormatObject result with wrong map class definition " +
"in context:\n" + mc);
System.out.println(
"\nMarshalling string with wrong map class definition " +
"in context:");
result = mc.marshall();
System.out.println(result);
System.out.println("\nLength of marshalled data: " + result.length());
mc2 = STAFMarshallingContext.unmarshall(result);
System.out.println(
"\nUnmarshall and call FormatObject on the context:\n" + mc);
// Now add the right map class definition to the context
mc.setMapClassDefinition(myMapClass);
System.out.println(
"\nFormatObject result with map class definition in context:\n" +
mc);
// Now create an instance for the map class with no keys
System.out.println(
"\nAdd a map object created for the map class definition " +
"with no keys");
Map theMap2 = myMapClass2.createInstance();
theMap2.put("KeyXXX", "ValueXXX");
theMap2.put("KeyZZZ", "ValueZZZ");
resultList.add(theMap2);
mc.setRootObject(resultList);
// Verify that you can format, marshall, and unmarshall an object that
// references a map class that doesn't have any keys defined.
System.out.println(
"\nVerify you can format, marshall, and unmarshall an object " +
"that references a map class without any keys defined:\n");
System.out.println("FormatObject Result: ");
System.out.println(mc);
result = mc.marshall();
System.out.println("\nMarshalled String: \n" + result);
System.out.println("\nLength of marshalled data: " + result.length());
System.out.println("\nUnmarshall and call FormatObject on the context:");
mc2 = STAFMarshallingContext.unmarshall(result);
System.out.println(mc2);
// Add keys to the second map class definition. One that doesn't match
// the entry and one that does
myMapClass2.addKey("KeyYYY", "Key YYY");
myMapClass2.addKey("KeyXXX", "Key XXX");
// Verify that you can format, marshall, and unmarshall an object that
// references a map class that has a key that it doesn't provide an
// entry for.
System.out.println(
"\nVerify you can format, marshall, and unmarshall an object" +
" that references a map class without a key that it doesn't " +
"provide an entry for:");
System.out.println("FormatObject Result: ");
System.out.println(mc);
result = mc.marshall();
System.out.println("\nMarshalled String: \n" + result);
System.out.println("\nLength of marshalled data: " + result.length());
System.out.println("\nUnmarshall and call FormatObject on the context:");
mc2 = STAFMarshallingContext.unmarshall(result);
System.out.println(mc2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -