01: /* ****************************************************************************
02: * PerfTest.java
03: * ****************************************************************************/
04:
05: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
06: * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
07: * Use is subject to license terms. *
08: * J_LZ_COPYRIGHT_END *********************************************************/
09:
10: package org.openlaszlo.test.xmlrpc;
11:
12: import java.util.*;
13: import java.io.*;
14: import javax.xml.rpc.*;
15: import javax.xml.parsers.*;
16: import javax.xml.namespace.*;
17: import org.w3c.dom.*;
18: import org.xml.sax.*;
19: import org.apache.axis.Constants;
20: import org.apache.axis.utils.*;
21: import org.apache.log4j.Logger;
22:
23: class PerfDataParser {
24: DocumentBuilder mBuilder;
25:
26: public PerfDataParser() throws ParserConfigurationException {
27: DocumentBuilderFactory factory = DocumentBuilderFactory
28: .newInstance();
29: mBuilder = factory.newDocumentBuilder();
30: }
31:
32: public Map parse(String file) throws IOException, SAXException {
33:
34: Map map = new HashMap();
35:
36: Element root = mBuilder.parse(
37: new InputSource(new FileReader(file)))
38: .getDocumentElement();
39: NodeList children = root.getChildNodes();
40: for (int i = 0; i < children.getLength(); i++) {
41: Node node = children.item(i);
42: if (node.getNodeType() != Node.ELEMENT_NODE)
43: continue;
44: Map item = new HashMap();
45: NamedNodeMap attributes = ((Element) node).getAttributes();
46: for (int j = 0; j < attributes.getLength(); j++) {
47: Attr attr = (Attr) attributes.item(j);
48: item.put(attr.getName(), attr.getValue());
49: }
50: map.put(item.get("id"), item);
51: }
52:
53: return map;
54: }
55: }
56:
57: public class PerfTest {
58: static String PERF_DATA_DIR = "/home/pkang/perforce/qa/testharness/docroot/perf-data";
59:
60: static Map addrMap = new HashMap();
61:
62: static {
63: try {
64: PerfDataParser p = new PerfDataParser();
65: addrMap.put(new Integer(0), p.parse(PERF_DATA_DIR
66: + "/0k.xml"));
67: addrMap.put(new Integer(1), p.parse(PERF_DATA_DIR
68: + "/1k.xml"));
69: addrMap.put(new Integer(10), p.parse(PERF_DATA_DIR
70: + "/10k.xml"));
71: addrMap.put(new Integer(25), p.parse(PERF_DATA_DIR
72: + "/25k.xml"));
73: } catch (Exception e) {
74: e.printStackTrace();
75: }
76: }
77:
78: public static Map getAddresses(int k) {
79: return (Map) addrMap.get(new Integer(k));
80: }
81: }
|