### Question:
TccStartAspect { @Around("execution(@org.apache.servicecomb.pack.omega.context.annotations.TccStart * *(..)) && @annotation(tccStart)") Object advise(ProceedingJoinPoint joinPoint, TccStart tccStart) throws Throwable { initializeOmegaContext(); Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); tccStartAnnotationProcessor.preIntercept(context.globalTxId(), method.toString(), tccStart.timeout()); LOG.debug("Initialized context {} before execution of method {}", context, method.toString()); try { Object result = joinPoint.proceed(); tccStartAnnotationProcessor.postIntercept(context.globalTxId(), method.toString()); LOG.debug("Transaction with context {} has finished.", context); return result; } catch (Throwable throwable) { if (!(throwable instanceof OmegaException)) { tccStartAnnotationProcessor.onError(context.globalTxId(), method.toString(), throwable); LOG.error("Transaction {} failed.", context.globalTxId()); } throw throwable; } finally { context.clear(); } } TccStartAspect(TccMessageSender tccMessageSender, OmegaContext context);   }### Answer:
@Test public void newGlobalTxIdInTccStart() throws Throwable { aspect.advise(joinPoint, tccStart); assertThat(startedEvents.size(), is(1)); TccStartedEvent startedEvent = startedEvents.get(0); assertThat(startedEvent.getGlobalTxId(), is(globalTxId)); assertThat(startedEvent.getLocalTxId(), is(globalTxId)); assertThat(endedEvents.size(), is(1)); TccEndedEvent endedEvent = endedEvents.get(0); assertThat(endedEvent.getGlobalTxId(), is(globalTxId)); assertThat(endedEvent.getLocalTxId(), is(globalTxId)); assertThat(endedEvent.getStatus(), is(TransactionStatus.Succeed)); assertThat(omegaContext.globalTxId(), is(nullValue())); assertThat(omegaContext.localTxId(), is(nullValue())); }
@Test public void clearContextOnTccStartError() throws Throwable { RuntimeException oops = new RuntimeException("oops"); when(joinPoint.proceed()).thenThrow(oops); try { aspect.advise(joinPoint, tccStart); expectFailing(RuntimeException.class); } catch (RuntimeException e) { assertThat(e, is(oops)); } assertThat(startedEvents.size(), is(1)); TccStartedEvent event = startedEvents.get(0); assertThat(event.getGlobalTxId(), is(globalTxId)); assertThat(event.getLocalTxId(), is(globalTxId)); TccEndedEvent endedEvent = endedEvents.get(0); assertThat(endedEvent.getGlobalTxId(), is(globalTxId)); assertThat(endedEvent.getLocalTxId(), is(globalTxId)); assertThat(endedEvent.getStatus(), is(TransactionStatus.Failed)); assertThat(omegaContext.globalTxId(), is(nullValue())); assertThat(omegaContext.localTxId(), is(nullValue())); }