Wednesday, February 16, 2011

TDD Kata: Batchrunner

(Do one task at a time, and try not to read ahead.)

Purpose: Practice on using fake objects for sensing.

Goal: Implement a transactional command batchrunner that ensures that a series of commands either all runs successfully, or the whole chain is rolled back.

Interface


public class TransactionalCommandRunner {
  public void addCommand(ICommand c);
  public void execute();
}

public interface ICommand {
  public void execute();
  public void undo();
}


  1. Start simple:


    1. TransactionalCommandRunner can execute zero commands.

    2. TransactionalCommandRunner can execute one command.

    3. TransactionalCommandRunner can execute many commands.


  2. Implement rollback


    1. If the first command fails (throws an Exception), the rest of the commands are not executed.

    2. If the first command fails, it is not rolled back (undone).

    3. If the second command fails, the first command is rolled back.

    4. If a subsequent command fails, all preceding commands are rolled back.

    5. The exception thrown by the failing command is rethrown from TransactionalCommandRunner.execute().



No comments:

Post a Comment