@@ -0,0 +1,2140 @@
+/*%0A * Copyright 2015 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage net.kuujo.copycat.raft;%0A%0Aimport net.kuujo.copycat.cluster.MemberInfo;%0Aimport net.kuujo.copycat.cluster.Session;%0Aimport org.testng.annotations.Test;%0A%0Aimport static org.testng.Assert.assertEquals;%0A%0A/**%0A * State machine test.%0A *%0A * @author %3Ca href=%22http://github.com/kuujo%22%3EJordan Halterman%3C/a%3E%0A */%0A@Test%0Apublic class StateMachineTest %7B%0A%0A  /**%0A   * Tests a state machine.%0A   */%0A  public void testStateMachine() %7B%0A    StateMachine stateMachine = new TestStateMachine();%0A    assertEquals(stateMachine.apply(new Commit%3C%3E(1, new Session(2, new MemberInfo(3) %7B%7D), System.currentTimeMillis(), new TestCommand())), %22write%22);%0A    assertEquals(stateMachine.apply(new Commit%3C%3E(1, new Session(2, new MemberInfo(3) %7B%7D), System.currentTimeMillis(), new TestQuery())), %22read%22);%0A  %7D%0A%0A  /**%0A   * Test command.%0A   */%0A  public static class TestCommand implements Command%3CString%3E %7B%0A  %7D%0A%0A  /**%0A   * Test query.%0A   */%0A  public static class TestQuery implements Query%3CString%3E %7B%0A    @Override%0A    public Consistency consistency() %7B%0A      return Consistency.LINEARIZABLE_STRICT;%0A    %7D%0A  %7D%0A%0A  /**%0A   * Test state machine.%0A   */%0A  public static class TestStateMachine extends StateMachine %7B%0A    @Apply(TestCommand.class)%0A    public String applyCommand(Commit%3CTestCommand%3E commit) %7B%0A      return %22write%22;%0A    %7D%0A%0A    @Filter(TestCommand.class)%0A    public boolean filterCommand(Commit%3CTestCommand%3E commit) %7B%0A      return true;%0A    %7D%0A%0A    @Apply(TestQuery.class)%0A    public String applyQuery(Commit%3CTestQuery%3E commit) %7B%0A      return %22read%22;%0A    %7D%0A  %7D%0A%0A%7D%0A

Add simple state machine test.