for (int t = 0; t < 110; t++) {
domainEvents.add(new GenericDomainEventMessage<String>(aggregateIdentifier, (long) t,
"Mock contents", MetaData.emptyInstance()));
}
testSubject.appendEvents("test", new SimpleDomainEventStream(domainEvents));
final Serializer serializer = new Serializer() {
private ConverterFactory converterFactory = new ChainingConverterFactory();
@SuppressWarnings("unchecked")
@Override
public <T> SerializedObject<T> serialize(Object object, Class<T> expectedType) {
// this will cause InstantiationError, since it is an interface
Assert.assertEquals(byte[].class, expectedType);
return new SimpleSerializedObject("<org.axonframework.eventhandling.EventListener />".getBytes(),
byte[].class,
"failingType",
"0");
}
@Override
public <T> boolean canSerializeTo(Class<T> expectedRepresentation) {
return byte[].class.equals(expectedRepresentation);
}
@Override
public <S, T> T deserialize(SerializedObject<S> serializedObject) {
throw new UnsupportedOperationException("Not implemented yet");
}
@Override
public Class classForType(SerializedType type) {
try {
return Class.forName(type.getName());
} catch (ClassNotFoundException e) {
return null;
}
}
@Override
public SerializedType typeForClass(Class type) {
return new SimpleSerializedType(type.getName(), "");
}
@Override
public ConverterFactory getConverterFactory() {
return converterFactory;
}
};
final DomainEventMessage<String> stubDomainEvent = new GenericDomainEventMessage<String>(
aggregateIdentifier,
(long) 30,
"Mock contents", MetaData.emptyInstance()
);
SnapshotEventEntry entry = new SnapshotEventEntry(
"test", stubDomainEvent,
serializer.serialize(stubDomainEvent.getPayload(), byte[].class),
serializer.serialize(stubDomainEvent.getMetaData(), byte[].class));
entityManager.persist(entry);
entityManager.flush();
entityManager.clear();
DomainEventStream stream = testSubject.readEvents("test", aggregateIdentifier);