### Question:
PersistMachine extends Machine { public String getBizId() { return bizId; } protected  PersistMachine(String bizId, String processName, int processVersion, ProcessDO processDO,
                             ProcessDOMapper processDOMapper
        , StateDOMapper stateDOMapper
        , PersistHelper persistHelper
        , TaskDOMapper taskDOMapper
        , ParticipationDOMapper participationDOMapper
        , JobDOMapper jobDOMapper); List<StateDOWithBLOBs> getStateDOList(); String getStatePathString(); void rollback(); String getBizId(); boolean isExist(); boolean isCompleted(); ProcessDO getProcessDO();  }### Answer:
@Test public void testMachineRunPerf() throws InterruptedException { final int count = 500; int threadCount = 5; long startTime = System.currentTimeMillis(); Thread[] threadList = new Thread[threadCount]; for (int i = 0; i < threadCount; i++) { threadList[i] = new Thread("perf-thread-" + i) { @Override public void run() { for (int i = 0; i < count; i++) { String bizId = getBizId(); PersistMachine m = persistMachineFactory.newInstance(bizId, "process"); m.addContext("goto", 2); m.addContext("_i", 3); m.run(); System.out.println("thread:" + this.getName() + " count:" + i + " bizId:" + bizId); } } }; } for (Thread t : threadList) { t.start(); } for (Thread t : threadList) { t.join(); } long duration = System.currentTimeMillis() - startTime; System.out.println("total time:" + duration + "ms"); System.out.println("average time:" + (duration / (count * threadCount)) + "ms"); }
@Test public void PersistMachineTest_run_not_DB() { String bizId = getBizId(); PersistMachine p = persistMachineFactory.newInstance(bizId, "process"); p.addContext("goto", 2); p.addContext("i", 3); p.run(); }
@Test public void testMachineRunWithException() { PersistMachine p = persistMachineFactory.newInstance(getBizId(), "process_with_biz_exception"); p.addContext("goto", 2); p.addContext("_i", 1); try { p.run(); Assert.fail("Should get exception here!"); } catch (Exception e) { System.out.println("get a exception:" + e.getMessage() + "\n"); e.printStackTrace(); } PersistMachine p2 = persistMachineFactory.newInstance(p.getBizId()); Assert.assertEquals("state2", p2.getCurrentStateName()); p2.addContext("_i", 0); p2.run(); Assert.assertEquals("end", p2.getCurrentStateName()); }
@Test public void testMachineRunWithEvent() { PersistMachine p = persistMachineFactory.newInstance(getBizId(), "process_with_event_p"); p.run(); System.out.println(p.getCurrentStateName()); Assert.assertEquals("some info", p.getContext("_info")); PersistMachine p2 = persistMachineFactory.newInstance(p.getBizId()); p2.addContext("goto", 2); p2.addContext("_i", 3); p2.addContext("info", "some info1"); p2.run(); Assert.assertEquals("wok", p2.getContext("_errorInfo")); System.out.println(p2.getContext()); Assert.assertEquals(6, p2.getContext("_a")); }