@Test public void newGlobalTxIdInSagaStart() throws Throwable { aspect.advise(joinPoint, sagaStart); TxEvent startedEvent = messages.get(0); assertThat(startedEvent.globalTxId(), is(globalTxId)); assertThat(startedEvent.localTxId(), is(globalTxId)); assertThat(startedEvent.parentTxId(), is(nullValue())); assertThat(startedEvent.type(), is(EventType.SagaStartedEvent)); TxEvent endedEvent = messages.get(1); assertThat(endedEvent.globalTxId(), is(globalTxId)); assertThat(endedEvent.localTxId(), is(globalTxId)); assertThat(endedEvent.parentTxId(), is(nullValue())); assertThat(endedEvent.type(), is(EventType.SagaEndedEvent)); assertThat(omegaContext.globalTxId(), is(nullValue())); assertThat(omegaContext.localTxId(), is(nullValue())); }
@Around("execution(@org.apache.servicecomb.saga.omega.context.annotations.SagaStart * *(..)) && @annotation(sagaStart)") Object advise(ProceedingJoinPoint joinPoint, SagaStart sagaStart) throws Throwable { long a = System.nanoTime(); Method method = null; boolean isProceed = false; try { initializeOmegaContext(sagaStart); method = ((MethodSignature) joinPoint.getSignature()).getMethod(); AlphaResponse alphaResponse = sagaStartAnnotationProcessor.preIntercept(context.globalTxId(), method.toString(), sagaStart.timeout(), "", 0); if (!alphaResponse.enabledTx()) { CompensableSqlMetrics.setIsMonitorSql(ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.SqlMonitor.toInteger(), context.category()).getStatus()); } isProceed = true; Object result = joinPoint.proceed(); if (alphaResponse.enabledTx()) { sagaStartAnnotationProcessor.postIntercept(context.globalTxId(), method.toString()); } return result; } catch (Throwable throwable) { boolean isFaultTolerant = ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.GlobalTxFaultTolerant.toInteger(), context.category()).getStatus(); if (!(throwable instanceof OmegaException) && !isFaultTolerant) { try { sagaStartAnnotationProcessor.onError(context.globalTxId(), method == null ? null : method.toString(), throwable); LOG.error("Transaction {} failed.", context.globalTxId()); } catch (Throwable e) { throw e; } } if (!isProceed && isFaultTolerant) { return joinPoint.proceed(); } throw throwable; } finally { context.clear(); } }
SagaStartAspect { @Around("execution(@org.apache.servicecomb.saga.omega.context.annotations.SagaStart * *(..)) && @annotation(sagaStart)") Object advise(ProceedingJoinPoint joinPoint, SagaStart sagaStart) throws Throwable { long a = System.nanoTime(); Method method = null; boolean isProceed = false; try { initializeOmegaContext(sagaStart); method = ((MethodSignature) joinPoint.getSignature()).getMethod(); AlphaResponse alphaResponse = sagaStartAnnotationProcessor.preIntercept(context.globalTxId(), method.toString(), sagaStart.timeout(), "", 0); if (!alphaResponse.enabledTx()) { CompensableSqlMetrics.setIsMonitorSql(ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.SqlMonitor.toInteger(), context.category()).getStatus()); } isProceed = true; Object result = joinPoint.proceed(); if (alphaResponse.enabledTx()) { sagaStartAnnotationProcessor.postIntercept(context.globalTxId(), method.toString()); } return result; } catch (Throwable throwable) { boolean isFaultTolerant = ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.GlobalTxFaultTolerant.toInteger(), context.category()).getStatus(); if (!(throwable instanceof OmegaException) && !isFaultTolerant) { try { sagaStartAnnotationProcessor.onError(context.globalTxId(), method == null ? null : method.toString(), throwable); LOG.error("Transaction {} failed.", context.globalTxId()); } catch (Throwable e) { throw e; } } if (!isProceed && isFaultTolerant) { return joinPoint.proceed(); } throw throwable; } finally { context.clear(); } } }
SagaStartAspect { @Around("execution(@org.apache.servicecomb.saga.omega.context.annotations.SagaStart * *(..)) && @annotation(sagaStart)") Object advise(ProceedingJoinPoint joinPoint, SagaStart sagaStart) throws Throwable { long a = System.nanoTime(); Method method = null; boolean isProceed = false; try { initializeOmegaContext(sagaStart); method = ((MethodSignature) joinPoint.getSignature()).getMethod(); AlphaResponse alphaResponse = sagaStartAnnotationProcessor.preIntercept(context.globalTxId(), method.toString(), sagaStart.timeout(), "", 0); if (!alphaResponse.enabledTx()) { CompensableSqlMetrics.setIsMonitorSql(ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.SqlMonitor.toInteger(), context.category()).getStatus()); } isProceed = true; Object result = joinPoint.proceed(); if (alphaResponse.enabledTx()) { sagaStartAnnotationProcessor.postIntercept(context.globalTxId(), method.toString()); } return result; } catch (Throwable throwable) { boolean isFaultTolerant = ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.GlobalTxFaultTolerant.toInteger(), context.category()).getStatus(); if (!(throwable instanceof OmegaException) && !isFaultTolerant) { try { sagaStartAnnotationProcessor.onError(context.globalTxId(), method == null ? null : method.toString(), throwable); LOG.error("Transaction {} failed.", context.globalTxId()); } catch (Throwable e) { throw e; } } if (!isProceed && isFaultTolerant) { return joinPoint.proceed(); } throw throwable; } finally { context.clear(); } } SagaStartAspect(MessageSender sender, OmegaContext context); }
SagaStartAspect { @Around("execution(@org.apache.servicecomb.saga.omega.context.annotations.SagaStart * *(..)) && @annotation(sagaStart)") Object advise(ProceedingJoinPoint joinPoint, SagaStart sagaStart) throws Throwable { long a = System.nanoTime(); Method method = null; boolean isProceed = false; try { initializeOmegaContext(sagaStart); method = ((MethodSignature) joinPoint.getSignature()).getMethod(); AlphaResponse alphaResponse = sagaStartAnnotationProcessor.preIntercept(context.globalTxId(), method.toString(), sagaStart.timeout(), "", 0); if (!alphaResponse.enabledTx()) { CompensableSqlMetrics.setIsMonitorSql(ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.SqlMonitor.toInteger(), context.category()).getStatus()); } isProceed = true; Object result = joinPoint.proceed(); if (alphaResponse.enabledTx()) { sagaStartAnnotationProcessor.postIntercept(context.globalTxId(), method.toString()); } return result; } catch (Throwable throwable) { boolean isFaultTolerant = ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.GlobalTxFaultTolerant.toInteger(), context.category()).getStatus(); if (!(throwable instanceof OmegaException) && !isFaultTolerant) { try { sagaStartAnnotationProcessor.onError(context.globalTxId(), method == null ? null : method.toString(), throwable); LOG.error("Transaction {} failed.", context.globalTxId()); } catch (Throwable e) { throw e; } } if (!isProceed && isFaultTolerant) { return joinPoint.proceed(); } throw throwable; } finally { context.clear(); } } SagaStartAspect(MessageSender sender, OmegaContext context);  }
SagaStartAspect { @Around("execution(@org.apache.servicecomb.saga.omega.context.annotations.SagaStart * *(..)) && @annotation(sagaStart)") Object advise(ProceedingJoinPoint joinPoint, SagaStart sagaStart) throws Throwable { long a = System.nanoTime(); Method method = null; boolean isProceed = false; try { initializeOmegaContext(sagaStart); method = ((MethodSignature) joinPoint.getSignature()).getMethod(); AlphaResponse alphaResponse = sagaStartAnnotationProcessor.preIntercept(context.globalTxId(), method.toString(), sagaStart.timeout(), "", 0); if (!alphaResponse.enabledTx()) { CompensableSqlMetrics.setIsMonitorSql(ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.SqlMonitor.toInteger(), context.category()).getStatus()); } isProceed = true; Object result = joinPoint.proceed(); if (alphaResponse.enabledTx()) { sagaStartAnnotationProcessor.postIntercept(context.globalTxId(), method.toString()); } return result; } catch (Throwable throwable) { boolean isFaultTolerant = ApplicationContextUtil.getApplicationContext().getBean(MessageSender.class).readConfigFromServer(ConfigCenterType.GlobalTxFaultTolerant.toInteger(), context.category()).getStatus(); if (!(throwable instanceof OmegaException) && !isFaultTolerant) { try { sagaStartAnnotationProcessor.onError(context.globalTxId(), method == null ? null : method.toString(), throwable); LOG.error("Transaction {} failed.", context.globalTxId()); } catch (Throwable e) { throw e; } } if (!isProceed && isFaultTolerant) { return joinPoint.proceed(); } throw throwable; } finally { context.clear(); } } SagaStartAspect(MessageSender sender, OmegaContext context);   }