Skip to content

Commit

Permalink
JAV-374 more proper compensation event name
Browse files Browse the repository at this point in the history
  • Loading branch information
seanyinx committed Sep 13, 2017
1 parent 21bed12 commit 0e0ae94
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
Expand Up @@ -53,7 +53,7 @@ public void compensate(SagaRequest request) {
Compensation compensation = request.compensation();
SagaResponse response = fallbackPolicy.apply(request.serviceName(), compensation, request.fallback());

sagaLog.offer(new CompensationEndedEvent(sagaId, request, response));
sagaLog.offer(new TransactionCompensatedEvent(sagaId, request, response));
}

@Override
Expand Down
Expand Up @@ -19,15 +19,15 @@
import java.util.Map;
import java.util.Set;

public class CompensationEndedEvent extends SagaEvent {
public class TransactionCompensatedEvent extends SagaEvent {

private final SagaResponse response;

CompensationEndedEvent(String sagaId, SagaRequest request) {
TransactionCompensatedEvent(String sagaId, SagaRequest request) {
this(sagaId, request, SagaResponse.EMPTY_RESPONSE);
}

public CompensationEndedEvent(String sagaId, SagaRequest request, SagaResponse response) {
public TransactionCompensatedEvent(String sagaId, SagaRequest request, SagaResponse response) {
super(sagaId, request);
this.response = response;
}
Expand All @@ -49,7 +49,7 @@ public String json(ToJsonFormat toJsonFormat) {

@Override
public String toString() {
return "CompensationEndedEvent{id="
return "TransactionCompensatedEvent{id="
+ payload().id()
+ ", sagaId=" + sagaId
+ ", operation="
Expand Down
Expand Up @@ -156,8 +156,8 @@ public void compensateCommittedTransactionsOnFailure() {
anyOf(eventWith(sagaId, transaction2, TransactionStartedEvent.class), eventWith(sagaId, transaction3, TransactionStartedEvent.class)),
eventWith(sagaId, transaction3, TransactionEndedEvent.class),
eventWith(sagaId, transaction2, TransactionAbortedEvent.class),
eventWith(sagaId, compensation3, CompensationEndedEvent.class),
eventWith(sagaId, compensation1, CompensationEndedEvent.class),
eventWith(sagaId, compensation3, TransactionCompensatedEvent.class),
eventWith(sagaId, compensation1, TransactionCompensatedEvent.class),
eventWith(sagaId, SAGA_START_COMPENSATION, SagaEndedEvent.class)));

verify(transaction1).send(request1.serviceName());
Expand Down Expand Up @@ -208,8 +208,8 @@ public void redoHangingTransactionsOnFailure() throws InterruptedException {
eventWith(sagaId, transaction3, TransactionAbortedEvent.class),
eventWith(sagaId, transaction2, TransactionStartedEvent.class),
eventWith(sagaId, transaction2, TransactionEndedEvent.class),
eventWith(sagaId, compensation2, CompensationEndedEvent.class),
eventWith(sagaId, compensation1, CompensationEndedEvent.class),
eventWith(sagaId, compensation2, TransactionCompensatedEvent.class),
eventWith(sagaId, compensation1, TransactionCompensatedEvent.class),
eventWith(sagaId, SAGA_START_COMPENSATION, SagaEndedEvent.class)));

verify(transaction1).send(request1.serviceName());
Expand Down Expand Up @@ -369,8 +369,8 @@ public void restoresToCompensationFromAbortedTransactionByPlayingAllEvents() {
eventWith(sagaId, transaction2, TransactionEndedEvent.class),
eventWith(sagaId, transaction3, TransactionStartedEvent.class),
eventWith(sagaId, transaction3, TransactionAbortedEvent.class),
eventWith(sagaId, compensation2, CompensationEndedEvent.class),
eventWith(sagaId, compensation1, CompensationEndedEvent.class),
eventWith(sagaId, compensation2, TransactionCompensatedEvent.class),
eventWith(sagaId, compensation1, TransactionCompensatedEvent.class),
eventWith(sagaId, SAGA_START_COMPENSATION, SagaEndedEvent.class)
));

Expand All @@ -395,7 +395,7 @@ public void restoresSagaToCompensationStateByPlayingAllEvents() {
envelope(new TransactionEndedEvent(sagaId, request2)),
envelope(new TransactionStartedEvent(sagaId, request3)),
envelope(new TransactionEndedEvent(sagaId, request3)),
envelope(new CompensationEndedEvent(sagaId, request2))
envelope(new TransactionCompensatedEvent(sagaId, request2))
);

eventStore.populate(events);
Expand All @@ -410,9 +410,9 @@ public void restoresSagaToCompensationStateByPlayingAllEvents() {
eventWith(sagaId, transaction2, TransactionEndedEvent.class),
eventWith(sagaId, transaction3, TransactionStartedEvent.class),
eventWith(sagaId, transaction3, TransactionEndedEvent.class),
eventWith(sagaId, compensation2, CompensationEndedEvent.class),
eventWith(sagaId, compensation3, CompensationEndedEvent.class),
eventWith(sagaId, compensation1, CompensationEndedEvent.class),
eventWith(sagaId, compensation2, TransactionCompensatedEvent.class),
eventWith(sagaId, compensation3, TransactionCompensatedEvent.class),
eventWith(sagaId, compensation1, TransactionCompensatedEvent.class),
eventWith(sagaId, SAGA_START_COMPENSATION, SagaEndedEvent.class)
));

Expand All @@ -437,7 +437,7 @@ public void restoresPartialCompensationByPlayingAllEvents() {
envelope(new TransactionEndedEvent(sagaId, request2)),
envelope(new TransactionStartedEvent(sagaId, request3)),
envelope(new TransactionEndedEvent(sagaId, request3)),
envelope(new CompensationEndedEvent(sagaId, request2))
envelope(new TransactionCompensatedEvent(sagaId, request2))
);

eventStore.populate(events);
Expand All @@ -452,9 +452,9 @@ public void restoresPartialCompensationByPlayingAllEvents() {
eventWith(sagaId, transaction2, TransactionEndedEvent.class),
eventWith(sagaId, transaction3, TransactionStartedEvent.class),
eventWith(sagaId, transaction3, TransactionEndedEvent.class),
eventWith(sagaId, compensation2, CompensationEndedEvent.class),
eventWith(sagaId, compensation3, CompensationEndedEvent.class),
eventWith(sagaId, compensation1, CompensationEndedEvent.class),
eventWith(sagaId, compensation2, TransactionCompensatedEvent.class),
eventWith(sagaId, compensation3, TransactionCompensatedEvent.class),
eventWith(sagaId, compensation1, TransactionCompensatedEvent.class),
eventWith(sagaId, SAGA_START_COMPENSATION, SagaEndedEvent.class)
));

Expand Down
Expand Up @@ -20,7 +20,7 @@
import static io.servicecomb.saga.core.NoOpSagaRequest.SAGA_START_REQUEST;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.servicecomb.saga.core.CompensationEndedEvent;
import io.servicecomb.saga.core.TransactionCompensatedEvent;
import io.servicecomb.saga.core.FailedSagaRequestContext;
import io.servicecomb.saga.core.SagaEndedEvent;
import io.servicecomb.saga.core.SagaEvent;
Expand All @@ -42,7 +42,7 @@ public class JacksonSagaEventFormat implements SagaEventFormat {
put(TransactionStartedEvent.class.getSimpleName(), (sagaId, json) -> transactionStartedEvent(sagaId, json));
put(TransactionEndedEvent.class.getSimpleName(), (sagaId, json) -> transactionEndedEvent(sagaId, json));
put(TransactionAbortedEvent.class.getSimpleName(), (sagaId, json) -> transactionAbortedEvent(sagaId, json));
put(CompensationEndedEvent.class.getSimpleName(), (sagaId, json) -> compensationEndedEvent(sagaId, json));
put(TransactionCompensatedEvent.class.getSimpleName(), (sagaId, json) -> compensationEndedEvent(sagaId, json));
put(SagaEndedEvent.class.getSimpleName(), (sagaId, json) -> sagaEndedEvent(sagaId));
}};

Expand Down Expand Up @@ -94,7 +94,7 @@ private SagaEvent transactionAbortedEvent(String sagaId, String json) {
private SagaEvent compensationEndedEvent(String sagaId, String json) {
try {
SuccessfulSagaRequestContext context = objectMapper.readValue(json, SuccessfulSagaRequestContext.class);
return new CompensationEndedEvent(sagaId, context.request().with(transportFactory), context.response());
return new TransactionCompensatedEvent(sagaId, context.request().with(transportFactory), context.response());
} catch (IOException e) {
throw new SagaException(cause(sagaId, json), e);
}
Expand Down
Expand Up @@ -29,7 +29,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.seanyinx.github.unit.scaffolding.Randomness;
import io.servicecomb.saga.core.CompensationEndedEvent;
import io.servicecomb.saga.core.TransactionCompensatedEvent;
import io.servicecomb.saga.core.FailedSagaResponse;
import io.servicecomb.saga.core.JacksonToJsonFormat;
import io.servicecomb.saga.core.RestOperation;
Expand Down Expand Up @@ -125,16 +125,16 @@ public void TransactionAbortedEventCanBeSerializedAndDeserialized() throws JsonP

@Test
public void compensationEndedEventCanBeSerializedAndDeserialized() throws JsonProcessingException {
CompensationEndedEvent event = new CompensationEndedEvent(sagaId, request, response);
TransactionCompensatedEvent event = new TransactionCompensatedEvent(sagaId, request, response);
String json = event.json(toJsonFormat);

SagaEvent sagaEvent = toEventFormat
.toSagaEvent(sagaId, event.getClass().getSimpleName(), json);

assertThat(sagaEvent, instanceOf(CompensationEndedEvent.class));
assertThat(sagaEvent, instanceOf(TransactionCompensatedEvent.class));
assertThat(sagaEvent.sagaId, is(sagaId));
assertThat(sagaEvent.payload(), eqToRequest(request));
assertThat(((CompensationEndedEvent) sagaEvent).response(), eqToResponse(response));
assertThat(((TransactionCompensatedEvent) sagaEvent).response(), eqToResponse(response));
}

private static Matcher<SagaRequest> eqToRequest(SagaRequest expected) {
Expand Down
Expand Up @@ -29,7 +29,7 @@
import static java.util.Collections.singletonMap;

import com.github.tomakehurst.wiremock.junit.WireMockRule;
import io.servicecomb.saga.core.CompensationEndedEvent;
import io.servicecomb.saga.core.TransactionCompensatedEvent;
import io.servicecomb.saga.core.PersistentStore;
import io.servicecomb.saga.core.SagaEndedEvent;
import io.servicecomb.saga.core.SagaRequest;
Expand Down Expand Up @@ -161,7 +161,7 @@ PersistentStore persistentStore(SagaEventRepo repo, ToJsonFormat toJsonFormat, S
store.offer(new TransactionStartedEvent("yyy", request3));
store.offer(new TransactionAbortedEvent("yyy", request3, new TransactionFailedException("oops")));

store.offer(new CompensationEndedEvent("yyy", request2, response2));
store.offer(new TransactionCompensatedEvent("yyy", request2, response2));

return store;
}
Expand Down

0 comments on commit 0e0ae94

Please sign in to comment.