01: /*
02: * Copyright 2006-2007 The Scriptella Project Team.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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(
42: new ConnectionParameters(new MockConnectionEl(),
43: MockDriverContext.INSTANCE));
44: ParametersCallback pc = MockParametersCallbacks.NAME;
45:
46: Resource scriptContent = new StringResource(
47: "int i=1;get(\"1\");");
48: for (int i = 0; i < 1000000; i++) {
49: c.executeScript(scriptContent, pc);
50: }
51: c.close();
52: }
53:
54: /**
55: * History:
56: * 06.09.2006 - Duron 1.7Mhz - 844 ms
57: */
58: public void testQuery() {
59: JaninoConnection c = new JaninoConnection(
60: new ConnectionParameters(new MockConnectionEl(),
61: MockDriverContext.INSTANCE));
62: final int[] r = new int[] { 0 };
63:
64: Resource queryContent = new StringResource(
65: "for (int i=0;i<1000000;i++) {"
66: + "set(\"p\", \"value\"+i );"
67: + "set(\"extra\", \"value\" );" + "next();"
68: + "}");
69: c.executeQuery(queryContent, MockParametersCallbacks.SIMPLE,
70: new QueryCallback() {
71: public final void processRow(
72: final ParametersCallback parameters) {
73: r[0]++;
74: parameters.getParameter("p");
75: }
76: });
77: c.close();
78: assertEquals(1000000, r[0]);
79:
80: }
81:
82: }
|