Removed scheduling.timer and scheduling.backportconcurrent packages

This commit is contained in:
Juergen Hoeller
2013-03-19 15:01:11 +01:00
parent f1258a6a02
commit 3f35bdc79a
14 changed files with 1 additions and 1704 deletions

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.scheduling.backportconcurrent;
import junit.framework.TestCase;
import org.springframework.core.task.NoOpRunnable;
/**
* @author Rick Evans
* @author Juergen Hoeller
*/
@Deprecated
public class ConcurrentTaskExecutorTests extends TestCase {
public void testZeroArgCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor();
// must not throw a NullPointerException
executor.execute(new NoOpRunnable());
}
public void testPassingNullExecutorToCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(null);
// must not throw a NullPointerException
executor.execute(new NoOpRunnable());
}
public void testPassingNullExecutorToSetterResultsInDefaultTaskExecutorBeingUsed() throws Exception {
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor();
executor.setConcurrentExecutor(null);
// must not throw a NullPointerException
executor.execute(new NoOpRunnable());
}
}

View File

@@ -1,133 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.scheduling.timer;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import junit.framework.TestCase;
import org.springframework.tests.context.TestMethodInvokingTask;
/**
* @author Juergen Hoeller
* @since 20.02.2004
*/
@Deprecated
public class TimerSupportTests extends TestCase {
public void testTimerFactoryBean() throws Exception {
final TestTimerTask timerTask0 = new TestTimerTask();
TestMethodInvokingTask task1 = new TestMethodInvokingTask();
MethodInvokingTimerTaskFactoryBean mittfb = new MethodInvokingTimerTaskFactoryBean();
mittfb.setTargetObject(task1);
mittfb.setTargetMethod("doSomething");
mittfb.afterPropertiesSet();
final TimerTask timerTask1 = mittfb.getObject();
final TestRunnable timerTask2 = new TestRunnable();
ScheduledTimerTask[] tasks = new ScheduledTimerTask[3];
tasks[0] = new ScheduledTimerTask(timerTask0, 0, 10, false);
tasks[1] = new ScheduledTimerTask(timerTask1, 10, 20, true);
tasks[2] = new ScheduledTimerTask(timerTask2, 20);
final List<Boolean> success = new ArrayList<Boolean>(3);
final Timer timer = new Timer(true) {
@Override
public void schedule(TimerTask task, long delay, long period) {
if (task == timerTask0 && delay == 0 && period == 10) {
success.add(Boolean.TRUE);
}
}
@Override
public void scheduleAtFixedRate(TimerTask task, long delay, long period) {
if (task == timerTask1 && delay == 10 && period == 20) {
success.add(Boolean.TRUE);
}
}
@Override
public void schedule(TimerTask task, long delay) {
if (task instanceof DelegatingTimerTask && delay == 20) {
success.add(Boolean.TRUE);
}
}
@Override
public void cancel() {
success.add(Boolean.TRUE);
}
};
TimerFactoryBean timerFactoryBean = new TimerFactoryBean() {
@Override
protected Timer createTimer(String name, boolean daemon) {
return timer;
}
};
try {
timerFactoryBean.setScheduledTimerTasks(tasks);
timerFactoryBean.afterPropertiesSet();
assertThat(timerFactoryBean.getObject(), instanceOf(Timer.class));
timerTask0.run();
timerTask1.run();
timerTask2.run();
}
finally {
timerFactoryBean.destroy();
}
assertTrue("Correct Timer invocations", success.size() == 4);
assertTrue("TimerTask0 works", timerTask0.counter == 1);
assertTrue("TimerTask1 works", task1.counter == 1);
assertTrue("TimerTask2 works", timerTask2.counter == 1);
}
public void testPlainTimerFactoryBean() {
TimerFactoryBean tfb = new TimerFactoryBean();
tfb.afterPropertiesSet();
tfb.destroy();
}
private static class TestTimerTask extends TimerTask {
private int counter = 0;
@Override
public void run() {
counter++;
}
}
private static class TestRunnable implements Runnable {
private int counter = 0;
@Override
public void run() {
counter++;
}
}
}

View File

@@ -1,190 +0,0 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.scheduling.timer;
import static org.junit.Assert.*;
import java.util.Timer;
import org.junit.Test;
/**
* Unit tests for the {@link TimerTaskExecutor} class.
*
* @author Rick Evans
* @author Chris Beams
*/
@Deprecated
public final class TimerTaskExecutorTests {
@Test(expected=IllegalArgumentException.class)
public void testExecuteChokesWithNullTimer() throws Exception {
TimerTaskExecutor executor = new TimerTaskExecutor();
executor.execute(new NoOpRunnable());
}
@Test(expected=IllegalArgumentException.class)
public void testExecuteChokesWithNullTask() throws Exception {
TimerTaskExecutor executor = new TimerTaskExecutor(new Timer());
executor.execute(null);
}
@Test(expected=IllegalArgumentException.class)
public void testExecuteChokesWithNegativeDelay() throws Exception {
TimerTaskExecutor executor = new TimerTaskExecutor(new Timer());
executor.setDelay(-10);
executor.execute(new NoOpRunnable());
}
@Test
public void testExecuteReallyDoesScheduleTheSuppliedTask() throws Exception {
final Object monitor = new Object();
RunAwareRunnable task = new RunAwareRunnable(monitor);
TimerTaskExecutor executor = new TimerTaskExecutor(new Timer());
executor.execute(task);
synchronized (monitor) {
monitor.wait(5000);
}
assertTrue("Supplied task (a Runnable) is not being invoked.", task.isRunWasCalled());
}
@Test(expected=IllegalArgumentException.class)
public void testCtorWithNullTimer() throws Exception {
new TimerTaskExecutor(null);
}
@Test
public void testCreateTimerMethodIsCalledIfNoTimerIsExplicitlySupplied() throws Exception {
CreationAwareTimerTaskExecutor executor = new CreationAwareTimerTaskExecutor();
executor.afterPropertiesSet();
assertTrue("If no Timer is set explicitly, then the protected createTimer() " +
"method must be called to create the Timer (it obviously isn't being called).",
executor.isCreateTimerWasCalled());
}
@Test
public void testCreateTimerMethodIsNotCalledIfTimerIsExplicitlySupplied() throws Exception {
CreationAwareTimerTaskExecutor executor = new CreationAwareTimerTaskExecutor();
executor.setTimer(new Timer());
executor.afterPropertiesSet();
assertFalse("If a Timer is set explicitly, then the protected createTimer() " +
"method must not be called to create the Timer (it obviously is being called, in error).",
executor.isCreateTimerWasCalled());
}
@Test
public void testThatTheDestroyCallbackCancelsTheTimerIfNoTimerIsExplicitlySupplied() throws Exception {
final CancelAwareTimer timer = new CancelAwareTimer();
TimerTaskExecutor executor = new TimerTaskExecutor() {
@Override
protected Timer createTimer() {
return timer;
}
};
executor.afterPropertiesSet();
executor.destroy();
assertTrue("When the Timer used is created by the TimerTaskExecutor because " +
"no Timer was set explicitly, then the destroy() callback must cancel() said Timer (it obviously isn't doing this).",
timer.isCancelWasCalled());
}
@Test
public void testThatTheDestroyCallbackDoesNotCancelTheTimerIfTheTimerWasSuppliedExplictly() throws Exception {
TimerTaskExecutor executor = new TimerTaskExecutor();
CancelAwareTimer timer = new CancelAwareTimer();
executor.setTimer(timer);
executor.afterPropertiesSet();
executor.destroy();
assertFalse("When the Timer used is not created by the TimerTaskExecutor because " +
"it Timer was set explicitly, then the destroy() callback must NOT cancel() said Timer (it obviously is, in error).",
timer.isCancelWasCalled());
}
private final static class CreationAwareTimerTaskExecutor extends TimerTaskExecutor {
private boolean createTimerWasCalled = false;
public boolean isCreateTimerWasCalled() {
return this.createTimerWasCalled;
}
@Override
protected Timer createTimer() {
this.createTimerWasCalled = true;
return super.createTimer();
}
}
private static class CancelAwareTimer extends Timer {
private boolean cancelWasCalled;
public boolean isCancelWasCalled() {
return this.cancelWasCalled;
}
@Override
public void cancel() {
this.cancelWasCalled = true;
super.cancel();
}
}
private static class RunAwareRunnable implements Runnable {
private boolean runWasCalled;
private final Object monitor;
public RunAwareRunnable(Object monitor) {
this.monitor = monitor;
}
public boolean isRunWasCalled() {
return this.runWasCalled;
}
@Override
public void run() {
this.runWasCalled = true;
synchronized (monitor) {
monitor.notifyAll();
}
}
}
private static final class NoOpRunnable implements Runnable {
@Override
public void run() {
// explicit no-op
}
}
}