KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > driver > janino > JaninoPerfTest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.driver.janino;
17
18 import scriptella.AbstractTestCase;
19 import scriptella.configuration.MockConnectionEl;
20 import scriptella.configuration.StringResource;
21 import scriptella.spi.ConnectionParameters;
22 import scriptella.spi.MockDriverContext;
23 import scriptella.spi.MockParametersCallbacks;
24 import scriptella.spi.ParametersCallback;
25 import scriptella.spi.QueryCallback;
26 import scriptella.spi.Resource;
27
28 /**
29  * Tests Janino connection class.
30  *
31  * @author Fyodor Kupolov
32  * @version 1.0
33  */

34 public class JaninoPerfTest extends AbstractTestCase {
35     /**
36      * This test creates a Janino connection that executes simple valid and invalid scripts.
37      * History:
38      * 06.09.2006 - Duron 1.7Mhz - 656 ms
39      */

40     public void testScript() {
41         JaninoConnection c = new JaninoConnection(new ConnectionParameters(new MockConnectionEl(), MockDriverContext.INSTANCE));
42         ParametersCallback pc = MockParametersCallbacks.NAME;
43
44
45         Resource scriptContent = new StringResource("int i=1;get(\"1\");");
46         for (int i = 0; i < 1000000; i++) {
47             c.executeScript(scriptContent, pc);
48         }
49         c.close();
50     }
51
52     /**
53      * History:
54      * 06.09.2006 - Duron 1.7Mhz - 844 ms
55      */

56     public void testQuery() {
57         JaninoConnection c = new JaninoConnection(new ConnectionParameters(new MockConnectionEl(), MockDriverContext.INSTANCE));
58         final int[] r = new int[]{0};
59
60         Resource queryContent = new StringResource(
61                 "for (int i=0;i<1000000;i++) {" +
62                         "set(\"p\", \"value\"+i );" +
63                         "set(\"extra\", \"value\" );" +
64                         "next();" +
65                         "}");
66         c.executeQuery(queryContent,
67                 MockParametersCallbacks.SIMPLE, new QueryCallback() {
68             public final void processRow(final ParametersCallback parameters) {
69                 r[0]++;
70                 parameters.getParameter("p");
71             }
72         });
73         c.close();
74         assertEquals(1000000, r[0]);
75
76     }
77
78
79 }
80
Popular Tags