001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.business;
020:
021: import java.util.Date;
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.roller.TestUtils;
028: import org.apache.roller.business.runnable.RollerTask;
029: import org.apache.roller.business.RollerFactory;
030: import org.apache.roller.business.runnable.ThreadManager;
031:
032: /**
033: * Test TaskLock related business operations.
034: */
035: public class TaskLockTest extends TestCase {
036:
037: public static Log log = LogFactory.getLog(TaskLockTest.class);
038:
039: public TaskLockTest(String name) {
040: super (name);
041: }
042:
043: public static Test suite() {
044: return new TestSuite(TaskLockTest.class);
045: }
046:
047: public void setUp() throws Exception {
048: }
049:
050: public void tearDown() throws Exception {
051: }
052:
053: /**
054: * Test basic persistence operations ... Create, Update, Delete.
055: */
056: public void testTaskLockCRUD() throws Exception {
057:
058: ThreadManager mgr = RollerFactory.getRoller()
059: .getThreadManager();
060:
061: // need a test task to play with
062: RollerTask task = new TestTask();
063:
064: // try to acquire a lock
065: boolean lockAcquired = mgr.acquireLock(task);
066: assertTrue(lockAcquired);
067: TestUtils.endSession(true);
068:
069: // make sure task is locked
070: boolean stillLocked = mgr.isLocked(task);
071: assertTrue(stillLocked);
072: TestUtils.endSession(true);
073:
074: // try to release a lock
075: boolean lockReleased = mgr.releaseLock(task);
076: assertTrue(lockReleased);
077: TestUtils.endSession(true);
078:
079: // make sure task is not locked
080: stillLocked = mgr.isLocked(task);
081: assertFalse(stillLocked);
082: TestUtils.endSession(true);
083: }
084:
085: class TestTask extends RollerTask {
086:
087: public String getName() {
088: return "TestTask";
089: }
090:
091: public Date getStartTime(Date current) {
092: return current;
093: }
094:
095: public int getLeaseTime() {
096: return 300;
097: }
098:
099: public int getInterval() {
100: return 1800;
101: }
102:
103: public void runTask() {
104: }
105:
106: }
107:
108: }
|