UpdateManager implements IUpdateManager { @Override public boolean setProcessingState(final IMessageUnitEntity msgUnit, final ProcessingState currentProcState, final ProcessingState newProcState) throws PersistenceException { return this.setProcessingState(msgUnit, currentProcState, newProcState, null); }  @Override V storeMessageUnit(final T messageUnit); @Override boolean setProcessingState(final IMessageUnitEntity msgUnit, final ProcessingState currentProcState,
                                      final ProcessingState newProcState); @Override boolean setProcessingState(final IMessageUnitEntity msgUnit, final ProcessingState currentProcState,
                                      final ProcessingState newProcState, final String description); @Override void deleteMessageUnit(final IMessageUnitEntity messageUnit); @Override void setPModeId(final IMessageUnitEntity msgUnit, final String pmodeId); @Override void setMultiHop(final IMessageUnitEntity msgUnit, final boolean isMultihop); @Override void setPayloadInformation(final IUserMessageEntity userMessage, final Collection<IPayload> payloadInfo); @Override void setAddSOAPFault(final IErrorMessageEntity errorMessage, final boolean addSOAPFault);  }
@Test public void setProcessingState() throws PersistenceException, InterruptedException { em.getTransaction().begin(); UserMessage userMsgJPA = new UserMessage(TestData.userMsg1); em.persist(userMsgJPA); final UserMessageEntity userMsg = new UserMessageEntity(userMsgJPA); em.getTransaction().commit(); assertNotEquals(T_NEW_PROC_STATE_1, userMsg.getCurrentProcessingState().getState()); ProcUpdater updater1 = new ProcUpdater(userMsg, userMsg.getCurrentProcessingState().getState(), T_NEW_PROC_STATE_1); new Thread(updater1).start(); synchronized(updater1) { updater1.wait(); } assertTrue(updater1.s); assertEquals(T_NEW_PROC_STATE_1, userMsg.getCurrentProcessingState().getState()); assertEquals(2, userMsg.getProcessingStates().size()); em.refresh(userMsgJPA); assertEquals(T_NEW_PROC_STATE_1, userMsgJPA.getCurrentProcessingState().getState()); assertEquals(2, userMsgJPA.getProcessingStates().size()); new Thread(updater1).start(); synchronized(updater1) { updater1.wait(); } assertFalse(updater1.s); assertEquals(T_NEW_PROC_STATE_1, userMsg.getCurrentProcessingState().getState()); assertEquals(2, userMsg.getProcessingStates().size()); em.refresh(userMsgJPA); assertEquals(T_NEW_PROC_STATE_1, userMsgJPA.getCurrentProcessingState().getState()); assertEquals(2, userMsgJPA.getProcessingStates().size()); updater1 = new ProcUpdater(userMsg, userMsg.getCurrentProcessingState().getState(), T_NEW_PROC_STATE_2); ProcUpdater updater2 = new ProcUpdater(userMsg, userMsg.getCurrentProcessingState().getState(), T_NEW_PROC_STATE_2); new Thread(updater1).start(); new Thread(updater2).start(); synchronized(updater1) { updater1.wait(); } if (updater2.s == null) synchronized(updater2) { updater2.wait(); } assertFalse(updater1.s && updater2.s); assertEquals(T_NEW_PROC_STATE_2, userMsg.getCurrentProcessingState().getState()); assertEquals(3, userMsg.getProcessingStates().size()); em.refresh(userMsgJPA); assertEquals(T_NEW_PROC_STATE_2, userMsgJPA.getCurrentProcessingState().getState()); assertEquals(3, userMsgJPA.getProcessingStates().size()); }