@Test
  public void testDomainEventEntry_WrapEventsCorrectly() {
    Serializer serializer = new XStreamSerializer();

    String payload = "Payload";
    MetaData metaData = new MetaData(Collections.singletonMap("Key", "Value"));
    DomainEventMessage<String> event =
        new GenericDomainEventMessage<>(
            "type",
            randomUUID().toString(),
            2L,
            payload,
            metaData,
            randomUUID().toString(),
            Instant.now());

    DomainEventEntry eventEntry = new DomainEventEntry(event, serializer);

    assertEquals(event.getAggregateIdentifier(), eventEntry.getAggregateIdentifier());
    assertEquals(event.getSequenceNumber(), eventEntry.getSequenceNumber());
    assertEquals(event.getTimestamp(), eventEntry.getTimestamp());
    assertEquals(payload, serializer.deserialize(eventEntry.getPayload()));
    assertEquals(metaData, serializer.deserialize(eventEntry.getMetaData()));
    assertEquals(byte[].class, eventEntry.getPayload().getContentType());
  }
示例#2
0
  @Override
  public <S> Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier) {
    EntityManager entityManager = entityManagerProvider.getEntityManager();
    List<SerializedSaga> serializedSagaList =
        entityManager
            .createNamedQuery(LOAD_SAGA_NAMED_QUERY, SerializedSaga.class)
            .setParameter("sagaId", sagaIdentifier)
            .setParameter("sagaType", getSagaTypeName(sagaType))
            .setMaxResults(1)
            .getResultList();
    if (serializedSagaList == null || serializedSagaList.isEmpty()) {
      return null;
    }

    SerializedSaga serializedSaga = serializedSagaList.get(0);
    S loadedSaga = serializer.deserialize(serializedSaga);
    if (injector != null) {
      injector.injectResources(loadedSaga);
    }
    Set<AssociationValue> associationValues =
        loadAssociationValues(entityManager, sagaType, sagaIdentifier);
    if (logger.isDebugEnabled()) {
      logger.debug(
          "Loaded saga id [{}] of type [{}]", sagaIdentifier, loadedSaga.getClass().getName());
    }
    return new EntryImpl<>(associationValues, loadedSaga);
  }
示例#3
0
 /**
  * Constructs a new SagaEntry for the given {@code saga}. The given saga must be serializable. The
  * provided saga is not modified by this operation.
  *
  * @param saga The saga to store
  * @param serializer The serialization mechanism to convert the Saga to a byte stream
  */
 public SagaEntry(T saga, String sagaIdentifier, Serializer serializer) {
   this.sagaId = sagaIdentifier;
   SerializedObject<byte[]> serialized = serializer.serialize(saga, byte[].class);
   this.serializedSaga = serialized.getData();
   this.sagaType = serialized.getType().getName();
   this.revision = serialized.getType().getRevision();
 }
示例#4
0
 private String getSagaTypeName(Class<?> sagaType) {
   return serializer.typeForClass(sagaType).getName();
 }