mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
05.51.2007 77dcb75fb0bf9c03a591297519a97f2f3b69dbf0
opends/tests/unit-tests-testng/src/server/org/opends/server/tasks/DummyTask.java
@@ -28,9 +28,15 @@
import java.util.List;
import org.opends.messages.Message;
import org.opends.server.backends.task.Task;
import org.opends.server.backends.task.TaskState;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
@@ -41,6 +47,15 @@
public class DummyTask
       extends Task
{
  // The length of time that the task should sleep before completing.
  private long sleepTime;
  // The task state to use when interrupting the task.  This will be null unless
  // the task gets interrupted.
  private volatile TaskState interruptedState;
  /**
   * {@inheritDoc}
   */
@@ -48,7 +63,25 @@
  public void initializeTask()
         throws DirectoryException
  {
    // No implementation is required.
    sleepTime = 0;
    interruptedState = null;
    Entry taskEntry = getTaskEntry();
    if (taskEntry != null)
    {
      List<Attribute> attrList =
           taskEntry.getAttribute("ds-task-dummy-sleep-time");
      if (attrList != null)
      {
        for (Attribute a : attrList)
        {
          for (AttributeValue v : a.getValues())
          {
            sleepTime = Long.parseLong(v.getStringValue());
          }
        }
      }
    }
  }
@@ -58,7 +91,34 @@
   */
  protected TaskState runTask()
  {
    return TaskState.COMPLETED_SUCCESSFULLY;
    long stopTime = System.currentTimeMillis() + sleepTime;
    while ((interruptedState == null) &&
           (System.currentTimeMillis() < stopTime))
    {
      try
      {
        Thread.sleep(10);
      } catch (Exception e) {}
    }
    if (interruptedState == null)
    {
      return TaskState.COMPLETED_SUCCESSFULLY;
    }
    else
    {
      return interruptedState;
    }
  }
  /**
   * {@inheritDoc}
   */
  public void interruptTask(TaskState taskState, Message interruptMessage)
  {
    interruptedState = taskState;
  }
}