@Override
    public void recordStateStarted(StateInstance stateInstance, ProcessContext context) {
        if (stateInstance != null) {

            boolean isUpdateMode = isUpdateMode(stateInstance, context);

            // if this state is for retry, do not register branch
            if (StringUtils.hasLength(stateInstance.getStateIdRetriedFor())) {
                if (isUpdateMode) {
                    stateInstance.setId(stateInstance.getStateIdRetriedFor());
                } else {
                    // generate id by default
                    stateInstance.setId(generateRetryStateInstanceId(stateInstance));
                }
            }
            // if this state is for compensation, do not register branch
            else if (StringUtils.hasLength(stateInstance.getStateIdCompensatedFor())) {
                stateInstance.setId(generateCompensateStateInstanceId(stateInstance, isUpdateMode));
            } else {
                branchRegister(stateInstance, context);
            }

            if (StringUtils.isEmpty(stateInstance.getId()) && seqGenerator != null) {
                stateInstance.setId(seqGenerator.generate(DomainConstants.SEQ_ENTITY_STATE_INST));
            }

            stateInstance.setSerializedInputParams(paramsSerializer.serialize(stateInstance.getInputParams()));
            if (!isUpdateMode) {
                executeUpdate(stateLogStoreSqls.getRecordStateStartedSql(dbType),
                    STATE_INSTANCE_TO_STATEMENT_FOR_INSERT, stateInstance);
            } else {
                // if this retry/compensate state do not need persist, just update last inst
                executeUpdate(stateLogStoreSqls.getUpdateStateExecutionStatusSql(dbType),
                    stateInstance.getStatus().name(), new Timestamp(System.currentTimeMillis()),
                    stateInstance.getMachineInstanceId(), stateInstance.getId());
            }
        }
    }
@Test
    public void testRecordStateStarted() {
        DbAndReportTcStateLogStore dbAndReportTcStateLogStore = new DbAndReportTcStateLogStore();
        StateInstanceImpl stateMachineInstance = new StateInstanceImpl();
        ProcessContextImpl context = new ProcessContextImpl();
        context.setVariable(DomainConstants.VAR_NAME_STATEMACHINE_CONFIG,  new DbStateMachineConfig());
        Assertions.assertThrows(NullPointerException.class,
                () -> dbAndReportTcStateLogStore.recordStateStarted(stateMachineInstance, context));
    }