+++ /dev/null
-/*--------------------------------------------------------------------------\r
- * Copyright 2007 Taro L. Saito\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *--------------------------------------------------------------------------*/\r
-//--------------------------------------\r
-// Phenome Commons Project\r
-//\r
-// ThreadManagerTest.java\r
-// Since: 2005/01/04\r
-//\r
-// $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/test/java/org/xerial/util/thread/ThreadManagerTest.java $ \r
-// $Author: leo $\r
-//--------------------------------------\r
-package org.xerial.util.thread;\r
-\r
-import junit.framework.TestCase;\r
-\r
-/**\r
- * @author leo\r
- *\r
- */\r
-public class ThreadManagerTest extends TestCase\r
-{\r
- ThreadManager _manager;\r
- Counter _counter;\r
- \r
- protected void setUp() throws Exception\r
- {\r
- _manager = new ThreadManager();\r
- _counter = new Counter();\r
- }\r
- \r
- class Counter\r
- {\r
- synchronized void increment()\r
- {\r
- count++;\r
- }\r
- int count = 0;\r
- }\r
- \r
- class SimpleTask implements Runnable\r
- { \r
- SimpleTask(Counter c)\r
- {\r
- _c = c;\r
- }\r
- public void run()\r
- { \r
- for(int i=0; i<1000; i++) {}\r
- _c.increment();\r
- } \r
- Counter _c;\r
- }\r
- \r
- public void testWork() throws InterruptedException\r
- {\r
- _manager.addTask(new SimpleTask(_counter));\r
- _manager.joinAll();\r
- assertEquals(1, _counter.count);\r
- }\r
- \r
- public void testManyTasks() throws InterruptedException\r
- {\r
- for(int i=0; i<500; i++)\r
- {\r
- _manager.addTask(new SimpleTask(_counter));\r
- }\r
- _manager.joinAll();\r
- assertEquals(500, _counter.count);\r
- }\r
-}\r
-\r
-\r
-\r
-\r