Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archiving of existing events #9

Merged
merged 4 commits into from
May 31, 2018

Conversation

dineshkadm
Copy link

No description provided.

@coveralls
Copy link

coveralls commented May 29, 2018

Coverage Status

Coverage increased (+0.2%) to 83.264% when pulling 6f29d7f on dineshkadm:archive-events into 2d18d1f on CJSCommonPlatform:archive-events.

@purple52 purple52 changed the base branch from master to archive-events May 30, 2018 11:02
when(event.metadata()).thenReturn(metadata);
when(event.metadata().name()).thenReturn("sample.archive.events.name");

assertTrue(sampleTransformation.action(event)==ARCHIVE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting around the == and in the other test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted and done

@@ -98,6 +107,12 @@ private boolean eventStoreTransformedEventPresent() throws SQLException {

private void insertEventLogData() throws SQLException, InvalidSequenceIdException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it would be cleaner if we had a method to insert event for stream, at version with name. But this is ok.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, refactored method to have parameters and removed added method.

return false;
}

default TransformAction action(final JsonEnvelope event) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java doc comments. Also update the deprecated comment to point to #action()

Is actionFor a better name than action ? (just asking the question, can discuss)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated java doc and renamed action method to actionFor

@@ -17,15 +21,25 @@
* @param event - the event to check
* @return TRUE if the event is eligible to have the transformation applied to it.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably update javadoc to mention default implementation is false also

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
* Transforms an events into zero to many events.
*
* @param event - the event to be transformed
* @return a stream of transformed events.
*/
Stream<JsonEnvelope> apply(final JsonEnvelope event);
default Stream<JsonEnvelope> apply(final JsonEnvelope event){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update javadoc

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

final UUID clonedStreamId = eventSource.cloneStream(streamId);
switch (requiresTransformation(eventStream, streamId)) {
case TRANSFORM_EVENT:
return transformEvent(streamId, eventStream);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be transformStream not events?

This language is a little bit confusing because the way the requresTransformation returns a result for a stream but has an action based on an Event.

Maybe if we just name the action TRANSFORM ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -104,15 +129,39 @@ private JsonEnvelope clearEventVersion(final JsonEnvelope event) {
).flatMap(identity());
}

private boolean requiresTransformation(final Stream<JsonEnvelope> eventStream) {
return eventStream.filter(this::checkTransformations).count() > 0;
private TransformAction requiresTransformation(final Stream<JsonEnvelope> eventStream, UUID streamId) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final params

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

private UUID archiveStream(final UUID streamId, final Stream<JsonEnvelope> eventStream) throws EventStreamException {
eventStreamJdbcRepository.markActive(streamId,false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting. space after comma

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

stream.append(transformedEventStream.map(this::clearEventVersion));
events.close();
} catch (Exception e) {
logger.error("Failed to clone stream", e);
Copy link
Collaborator

@matt-rich matt-rich May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to say which stream id failed to clone

Is the only failure that can occur a clone? isn't the clone action just a small part of this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the logger statement to accept the stream Id parameter.
Not quite sure about the exception as this is an existing implementation and not changed as part of this work.

.distinct()
.collect(Collectors.toList());

if (eventTransformationList.size() == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use isEmpty?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return noAction(eventStream, streamId, "Stream {} did not require transformation stream ");
}
if (eventTransformationList.size() > 1) {
return noAction(eventStream, streamId, "Stream {} can not have multiple actions ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be useful to log/return what the multiple actions were?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. added in logger the multiple action names


}

private TransformAction noAction(Stream<JsonEnvelope> eventStream, UUID streamId, String errorMessage) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final params

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@matt-rich matt-rich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the general structure looks ok, just a few minor comments.

Not 100% sure if there is a better way to do the switch statement to make it open for extension, but is not to fix now.

@purple52 purple52 merged commit 5e52a22 into CJSCommonPlatform:archive-events May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants