@Override
    public void recordStateMachineStarted(StateMachineInstance machineInstance, ProcessContext context) {
        if (machineInstance != null) {
            //if parentId is not null, machineInstance is a SubStateMachine, do not start a new global transaction,
            //use parent transaction instead.
            String parentId = machineInstance.getParentId();
            if (StringUtils.isEmpty(parentId)) {
                beginTransaction(machineInstance, context);
            }

            try {
                if (StringUtils.isEmpty(machineInstance.getId()) && seqGenerator != null) {
                    machineInstance.setId(seqGenerator.generate(DomainConstants.SEQ_ENTITY_STATE_MACHINE_INST));
                }

                // bind SAGA branch type
                RootContext.bindBranchType(BranchType.SAGA);

                // save to db
                machineInstance.setSerializedStartParams(paramsSerializer.serialize(machineInstance.getStartParams()));
                int effect = executeUpdate(stateLogStoreSqls.getRecordStateMachineStartedSql(dbType),
                    STATE_MACHINE_INSTANCE_TO_STATEMENT_FOR_INSERT, machineInstance);
                if (effect < 1) {
                    throw new StoreException("StateMachineInstance record start error, Xid: " + machineInstance.getId(),
                        FrameworkErrorCode.OperationDenied);
                }
            } catch (StoreException e) {
                LOGGER.error("Record statemachine start error: {}, StateMachine: {}, XID: {}, Reason: {}",
                    e.getErrcode(), machineInstance.getStateMachine().getName(), machineInstance.getId(), e.getMessage(), e);
                this.clearUp(context);
                throw e;
            }
        }
    }
@Test
    public void testRecordStateMachineStarted() {
        DbAndReportTcStateLogStore dbAndReportTcStateLogStore = new DbAndReportTcStateLogStore();
        StateMachineInstanceImpl stateMachineInstance = new StateMachineInstanceImpl();
        ProcessContextImpl context = new ProcessContextImpl();
        context.setVariable(DomainConstants.VAR_NAME_STATEMACHINE_CONFIG,  new DbStateMachineConfig());
        Assertions.assertThrows(NullPointerException.class,
                () -> dbAndReportTcStateLogStore.recordStateMachineStarted(stateMachineInstance, context));
    }