KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > driver > velocity > VelocityPerfTest


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.velocity;
17
18 import scriptella.AbstractTestCase;
19
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.util.concurrent.CountDownLatch JavaDoc;
22
23 /**
24  * Performance test for velocity connection provider.
25  *
26  * @author Fyodor Kupolov
27  * @version 1.0
28  */

29 public class VelocityPerfTest extends AbstractTestCase {
30     /**
31      * This method tests velocity driver under load (5 threads * 5000 iterations).
32      */

33     public void test() throws InterruptedException JavaDoc {
34         final CountDownLatch JavaDoc cdl = new CountDownLatch JavaDoc(5);
35         for (int t=0;t<5;t++) {
36             new Thread JavaDoc(new Runnable JavaDoc() {
37                 public void run() {
38                     try {
39                         ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
40                         VelocityConnection con = VelocityConnectionTest.createConnection(out);
41                         for (int i=0;i<5000;i++) {
42                             VelocityConnectionTest.run(con);
43                             out.reset();
44                         }
45                         con.close();
46                     } finally {
47                         cdl.countDown();
48                     }
49                 }
50             }).start();
51         }
52         cdl.await();
53     }
54 }
55
Popular Tags