KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > querying > impl > xtas > XtasStressTest


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5 package org.exoplatform.services.xml.querying.impl.xtas;
6
7 import junit.framework.TestCase;
8 import org.exoplatform.container.PortalContainer;
9 import org.exoplatform.services.xml.querying.Statement;
10 import org.exoplatform.services.xml.querying.XMLQueryingService;
11 import org.exoplatform.services.xml.querying.impl.xtas.Query;
12 import org.exoplatform.services.xml.querying.impl.xtas.WellFormedUniFormTree;
13 import org.xml.sax.InputSource JavaDoc;
14
15 import java.io.ByteArrayInputStream JavaDoc;
16
17 //import xtas.*;
18
//import xtas.test.*;
19

20 /**
21  * Created by the Exo Development team.
22  */

23 public class XtasStressTest extends TestCase {
24
25    public void setUp() throws Exception JavaDoc
26    {
27    }
28
29    public void testLoading() throws Exception JavaDoc
30    {
31        long t;
32        int numT = 100;
33        try {
34
35           PortalContainer manager = PortalContainer.getInstance();
36           XMLQueryingService service = (XMLQueryingService) manager.
37               getComponentInstanceOfType(XMLQueryingService.class);
38           Query query = (Query)service.createQuery();
39
40           Statement qc = service.createStatementHelper().select("/", "tmp/employees.xml");
41           query.prepare(qc);
42           query.execute();
43
44           t = System.currentTimeMillis();
45           for(int i=0;i<numT;i++)
46           {
47              WellFormedUniFormTree tree = new WellFormedUniFormTree();
48              tree.init(new InputSource JavaDoc(new ByteArrayInputStream JavaDoc(("<employee id=\"N"+i+"\"><firstname>Firstname"+i+"</firstname><lastname>Lastname"+i+"</lastname></employee>").getBytes())));
49              qc = service.createStatementHelper().append("employees/*[last()]",tree);
50
51              query.prepareNext(qc);
52              query.execute();
53           }
54           System.out.println("Avg INSERT time: "+(System.currentTimeMillis() - t)/numT+" ms.");
55           t = System.currentTimeMillis();
56
57           for(int i=0;i<numT;i++)
58           {
59              WellFormedUniFormTree tree = new WellFormedUniFormTree();
60              tree.init(new InputSource JavaDoc(new ByteArrayInputStream JavaDoc(("<firstname>Firstname"+(i*10)+"</firstname>").getBytes())));
61              qc = service.createStatementHelper().update("employees/employee/firstname[text()='Firstname"+i+"']", "tmp/employees.xml", "tmp/employees1.xml",tree);
62                                                                
63              query.prepareNext(qc);
64              query.execute();
65           }
66          System.out.println("Avg UPDATE time: "+(System.currentTimeMillis() - t)/numT+" ms.");
67
68          query.serialize();
69          t = System.currentTimeMillis();
70
71           for(int i=0;i<numT;i++)
72           {
73
74              qc = service.createStatementHelper().delete("employees/employee/firstname[text()='Firstname"+i+"']");
75
76              query.prepareNext(qc);
77              query.execute();
78           }
79          System.out.println("Avg DELETE time: "+(System.currentTimeMillis() - t)/numT+" ms.");
80          System.out.println(""+numT+" times on 30 to "+(3*numT)+" (entity) nodes tree ");
81
82 // query.serialize();
83

84        } catch ( Exception JavaDoc e) {
85
86             fail( "testSelect() ERROR: "+e.toString());
87        }
88
89    }
90
91 }
92
Popular Tags