java.lang.Object
br.com.objectos.testing.concurrent.TestableCpuWorker
All Implemented Interfaces:
CpuWorker

public final class TestableCpuWorker extends Object implements CpuWorker
A CpuWorker implementation that can be inspected for correct task submission but that does not execute any of the submitted tasks.
Since:
2
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Removes all tasks in this worker.
    final boolean
    offer(CpuTask task)
    Adds the specified task to this worker but does not execute it.
    final CpuTask
    Retrieves, but does not remove, the head of this worker or returns null if this worker is empty.
    final CpuTask
    Retrieves and removes the head of this worker, or returns null if this worker is empty.
    final int
    Returns the number of tasks in this worker.
    Returns a new list containing all tasks currently in this worker.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TestableCpuWorker

      public TestableCpuWorker()
      Creates a new instance.
  • Method Details

    • clear

      public final void clear()
      Removes all tasks in this worker.
    • offer

      public final boolean offer(CpuTask task)
      Adds the specified task to this worker but does not execute it.
      Specified by:
      offer in interface CpuWorker
      Parameters:
      task - a task to be added
      Returns:
      true if the task was successfully added to this worker
    • peek

      public final CpuTask peek()
      Retrieves, but does not remove, the head of this worker or returns null if this worker is empty.

      The head is the task which has been the longest in this worker.

      Returns:
      the head of this worker, or null if this worker is empty
    • poll

      public final CpuTask poll()
      Retrieves and removes the head of this worker, or returns null if this worker is empty.

      The head is the task which has been the longest in this worker.

      Returns:
      the head of this worker, or null if this worker is empty
    • size

      public final int size()
      Returns the number of tasks in this worker.
      Returns:
      the number of tasks in this worker
    • toImmutableList

      public final ImmutableList<CpuTask> toImmutableList()
      Returns a new list containing all tasks currently in this worker.
      Returns:
      a new list containing all tasks currently in this worker