📄 asyncexectest.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// Copyright (C) 2004 Leo Mekenkamp. All rights reserved.//// $Id$package test.ozoneDB.core.storage.gammaStore;import junit.framework.Test;import junit.framework.TestResult;import junit.framework.TestSuite;import junit.textui.TestRunner;import org.ozoneDB.core.storage.gammaStore.AsyncExec;import test.OzoneTestCase;import test.OzoneTestRunner;/** * @author leo */public class AsyncExecTest extends OzoneTestCase { private AsyncExec asyncExec = new AsyncExec("test", Thread.MAX_PRIORITY, true); private Object lock = new Object(); private volatile int taskCount = 0; public AsyncExecTest() { super("testAsyncExec"); } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new LocTest()); return suite; } public void testAsyncExec() { Object key1 = new Integer(0); Object key2 = new Integer(1); synchronized (lock){ asyncExec.put(key1, new Task()); asyncExec.put(key2, new Task()); try { lock.wait(); } catch (InterruptedException ignore) { } assertNotNull(asyncExec.get(key2)); assertEquals(taskCount, 0); assertNull(asyncExec.get(key1)); assertEquals(taskCount, 1); try { lock.wait(); } catch (InterruptedException ignore) { } assertNull(asyncExec.get(key2)); assertEquals(taskCount, 2); asyncExec.stopWhenReady(); } } public static void main(String[] args) { TestRunner testRunner = new TestRunner(); testRunner.run(AsyncExecTest.class); } private class Task implements Runnable { public void run() { synchronized (lock) { lock.notifyAll(); } try { Thread.sleep(1000); } catch (InterruptedException ignore) { } taskCount++; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -