void wrap(LoggedEvent rawEvent) { final RecordMetadataImpl metadata = new RecordMetadataImpl( objectMapper, partitionId, rawMetadata.getIntent(), rawMetadata.getRecordType(), rawMetadata.getRejectionType(), BufferUtil.bufferAsString(rawMetadata.getRejectionReason()), rawMetadata.getValueType()); record = recordMapper.map(rawEvent, metadata); exporterIndex = 0; shouldExecuteSideEffects = record != null; }
void wrap(LoggedEvent rawEvent) { final RecordMetadataImpl metadata = new RecordMetadataImpl( objectMapper, partitionId, rawMetadata.getIntent(), rawMetadata.getRecordType(), rawMetadata.getRejectionType(), BufferUtil.bufferAsString(rawMetadata.getRejectionReason()), rawMetadata.getValueType()); record = recordMapper.map(rawEvent, metadata); exporterIndex = 0; shouldExecuteSideEffects = record != null; }
@Override public void writeRejection(TypedRecord<?> rejection) { final RecordMetadata metadata = rejection.getMetadata(); stage( RecordType.COMMAND_REJECTION, metadata.getIntent(), rejection.getKey(), rejection.getMetadata().getRejectionType(), rejection.getMetadata().getRejectionReason(), rejection.getMetadata(), rejection.getValue()); }
@Override public void writeRejection(TypedRecord<?> rejection) { final RecordMetadata metadata = rejection.getMetadata(); stage( RecordType.COMMAND_REJECTION, metadata.getIntent(), rejection.getKey(), rejection.getMetadata().getRejectionType(), rejection.getMetadata().getRejectionReason(), rejection.getMetadata(), rejection.getValue()); }
@Test public void shouldRejectCancelCommand() { // when final TypedRecord<TimerRecord> timerRecord = timerRecordForActivity("timer"); envRule.writeCommand(timerRecord.getKey(), TimerIntent.TRIGGER, timerRecord.getValue()); envRule.writeCommand(timerRecord.getKey(), TimerIntent.CANCEL, timerRecord.getValue()); streamProcessor.unblock(); // then final TypedRecord<TimerRecord> rejection = findTimerCommandRejection(); assertThat(rejection.getMetadata().getIntent()).isEqualTo(TimerIntent.CANCEL); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectTriggerCommand() { // when final TypedRecord<TimerRecord> timerRecord = timerRecordForActivity("timer"); envRule.writeCommand(timerRecord.getKey(), TimerIntent.CANCEL, timerRecord.getValue()); envRule.writeCommand(timerRecord.getKey(), TimerIntent.TRIGGER, timerRecord.getValue()); streamProcessor.unblock(); // then final TypedRecord<TimerRecord> rejection = findTimerCommandRejection(); assertThat(rejection.getMetadata().getIntent()).isEqualTo(TimerIntent.TRIGGER); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectCancelCommand() { // when final TypedRecord<TimerRecord> timerRecord = timerRecordForActivity("timer"); envRule.writeCommand(timerRecord.getKey(), TimerIntent.TRIGGER, timerRecord.getValue()); envRule.writeCommand(timerRecord.getKey(), TimerIntent.CANCEL, timerRecord.getValue()); streamProcessor.unblock(); // then final TypedRecord<TimerRecord> rejection = findTimerCommandRejection(); assertThat(rejection.getMetadata().getIntent()).isEqualTo(TimerIntent.CANCEL); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectDuplicatedTriggerCommand() { // when final TypedRecord<TimerRecord> timerRecord = timerRecordForActivity("timer"); envRule.writeCommand(timerRecord.getKey(), TimerIntent.TRIGGER, timerRecord.getValue()); envRule.writeCommand(timerRecord.getKey(), TimerIntent.TRIGGER, timerRecord.getValue()); streamProcessor.unblock(); // then final TypedRecord<TimerRecord> rejection = findTimerCommandRejection(); assertThat(rejection.getMetadata().getIntent()).isEqualTo(TimerIntent.TRIGGER); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectDuplicatedTriggerCommand() { // when final TypedRecord<TimerRecord> timerRecord = timerRecordForActivity("timer"); envRule.writeCommand(timerRecord.getKey(), TimerIntent.TRIGGER, timerRecord.getValue()); envRule.writeCommand(timerRecord.getKey(), TimerIntent.TRIGGER, timerRecord.getValue()); streamProcessor.unblock(); // then final TypedRecord<TimerRecord> rejection = findTimerCommandRejection(); assertThat(rejection.getMetadata().getIntent()).isEqualTo(TimerIntent.TRIGGER); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectTriggerCommand() { // when final TypedRecord<TimerRecord> timerRecord = timerRecordForActivity("timer"); envRule.writeCommand(timerRecord.getKey(), TimerIntent.CANCEL, timerRecord.getValue()); envRule.writeCommand(timerRecord.getKey(), TimerIntent.TRIGGER, timerRecord.getValue()); streamProcessor.unblock(); // then final TypedRecord<TimerRecord> rejection = findTimerCommandRejection(); assertThat(rejection.getMetadata().getIntent()).isEqualTo(TimerIntent.TRIGGER); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectCorrelateIfMessageSubscriptionClosed() { // given final MessageSubscriptionRecord subscription = messageSubscription(); final MessageRecord message = message(); rule.writeCommand(MessageIntent.PUBLISH, message); streamProcessor.blockAfterMessageSubscriptionEvent( m -> m.getMetadata().getIntent() == MessageSubscriptionIntent.OPENED); rule.writeCommand(MessageSubscriptionIntent.OPEN, subscription); waitUntil(() -> streamProcessor.isBlocked()); // when rule.writeCommand(MessageSubscriptionIntent.CLOSE, subscription); rule.writeCommand(MessageSubscriptionIntent.CORRELATE, subscription); streamProcessor.unblock(); // then final TypedRecord<MessageSubscriptionRecord> rejection = awaitAndGetFirstSubscriptionRejection(); assertThat(rejection.getMetadata().getIntent()).isEqualTo(MessageSubscriptionIntent.CORRELATE); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectCorrelateIfMessageSubscriptionClosed() { // given final MessageSubscriptionRecord subscription = messageSubscription(); final MessageRecord message = message(); rule.writeCommand(MessageIntent.PUBLISH, message); streamProcessor.blockAfterMessageSubscriptionEvent( m -> m.getMetadata().getIntent() == MessageSubscriptionIntent.OPENED); rule.writeCommand(MessageSubscriptionIntent.OPEN, subscription); waitUntil(() -> streamProcessor.isBlocked()); // when rule.writeCommand(MessageSubscriptionIntent.CLOSE, subscription); rule.writeCommand(MessageSubscriptionIntent.CORRELATE, subscription); streamProcessor.unblock(); // then final TypedRecord<MessageSubscriptionRecord> rejection = awaitAndGetFirstSubscriptionRejection(); assertThat(rejection.getMetadata().getIntent()).isEqualTo(MessageSubscriptionIntent.CORRELATE); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectDuplicatedOpenWorkflowInstanceSubscription() { // given streamProcessorRule.deploy(MESSAGE_CATCH_EVENT_WORKFLOW); streamProcessor.blockAfterWorkflowInstanceRecord( isForElement("catch-event", WorkflowInstanceIntent.EVENT_ACTIVATED)); streamProcessorRule.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); waitUntil(() -> streamProcessor.isBlocked()); final TypedRecord<WorkflowInstanceRecord> catchEvent = streamProcessorRule.awaitElementInState( "catch-event", WorkflowInstanceIntent.EVENT_ACTIVATED); // when final WorkflowInstanceSubscriptionRecord subscription = subscriptionRecordForEvent(catchEvent); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.OPEN, subscription); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.OPEN, subscription); streamProcessor.unblock(); // then final TypedRecord<WorkflowInstanceSubscriptionRecord> rejection = streamProcessorRule.awaitAndGetFirstSubscriptionRejection(); assertThat(rejection.getMetadata().getIntent()) .isEqualTo(WorkflowInstanceSubscriptionIntent.OPEN); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.INVALID_STATE); }
@Test public void shouldRejectDuplicatedOpenWorkflowInstanceSubscription() { // given streamProcessorRule.deploy(MESSAGE_CATCH_EVENT_WORKFLOW); streamProcessor.blockAfterWorkflowInstanceRecord( isForElement("catch-event", WorkflowInstanceIntent.ELEMENT_ACTIVATED)); streamProcessorRule.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); waitUntil(() -> streamProcessor.isBlocked()); final TypedRecord<WorkflowInstanceRecord> catchEvent = streamProcessorRule.awaitElementInState( "catch-event", WorkflowInstanceIntent.ELEMENT_ACTIVATED); // when final WorkflowInstanceSubscriptionRecord subscription = subscriptionRecordForEvent(catchEvent); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.OPEN, subscription); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.OPEN, subscription); streamProcessor.unblock(); // then final TypedRecord<WorkflowInstanceSubscriptionRecord> rejection = streamProcessorRule.awaitAndGetFirstSubscriptionRejection(); assertThat(rejection.getMetadata().getIntent()) .isEqualTo(WorkflowInstanceSubscriptionIntent.OPEN); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.INVALID_STATE); }
@Test public void shouldRejectDuplicatedCloseWorkflowInstanceSubscription() { // given streamProcessorRule.deploy(MESSAGE_CATCH_EVENT_WORKFLOW); streamProcessorRule.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final TypedRecord<WorkflowInstanceRecord> catchEvent = streamProcessorRule.awaitElementInState( "catch-event", WorkflowInstanceIntent.EVENT_ACTIVATED); final WorkflowInstanceSubscriptionRecord subscription = subscriptionRecordForEvent(catchEvent); streamProcessor.blockAfterWorkflowInstanceSubscriptionEvent( e -> e.getMetadata().getIntent() == WorkflowInstanceSubscriptionIntent.OPENED); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.OPEN, subscription); waitUntil(() -> streamProcessor.isBlocked()); // when envRule.writeCommand(WorkflowInstanceSubscriptionIntent.CLOSE, subscription); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.CLOSE, subscription); streamProcessor.unblock(); // then final TypedRecord<WorkflowInstanceSubscriptionRecord> rejection = streamProcessorRule.awaitAndGetFirstSubscriptionRejection(); assertThat(rejection.getMetadata().getIntent()) .isEqualTo(WorkflowInstanceSubscriptionIntent.CLOSE); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectDuplicatedCloseWorkflowInstanceSubscription() { // given streamProcessorRule.deploy(MESSAGE_CATCH_EVENT_WORKFLOW); streamProcessorRule.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final TypedRecord<WorkflowInstanceRecord> catchEvent = streamProcessorRule.awaitElementInState( "catch-event", WorkflowInstanceIntent.ELEMENT_ACTIVATED); final WorkflowInstanceSubscriptionRecord subscription = subscriptionRecordForEvent(catchEvent); streamProcessor.blockAfterWorkflowInstanceSubscriptionEvent( e -> e.getMetadata().getIntent() == WorkflowInstanceSubscriptionIntent.OPENED); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.OPEN, subscription); waitUntil(() -> streamProcessor.isBlocked()); // when envRule.writeCommand(WorkflowInstanceSubscriptionIntent.CLOSE, subscription); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.CLOSE, subscription); streamProcessor.unblock(); // then final TypedRecord<WorkflowInstanceSubscriptionRecord> rejection = streamProcessorRule.awaitAndGetFirstSubscriptionRejection(); assertThat(rejection.getMetadata().getIntent()) .isEqualTo(WorkflowInstanceSubscriptionIntent.CLOSE); assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.NOT_FOUND); }
@Test public void shouldRejectCorrelateWorkflowInstanceSubscription() { // given streamProcessorRule.deploy(MESSAGE_CATCH_EVENT_WORKFLOW); final TypedRecord<WorkflowInstanceRecord> createdEvent = streamProcessorRule.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final TypedRecord<WorkflowInstanceRecord> catchEvent = streamProcessorRule.awaitElementInState( "catch-event", WorkflowInstanceIntent.EVENT_ACTIVATED); final WorkflowInstanceSubscriptionRecord subscription = subscriptionRecordForEvent(catchEvent); streamProcessor.blockAfterWorkflowInstanceSubscriptionEvent( e -> e.getMetadata().getIntent() == WorkflowInstanceSubscriptionIntent.OPENED); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.OPEN, subscription); waitUntil(() -> streamProcessor.isBlocked()); envRule.writeCommand( createdEvent.getKey(), WorkflowInstanceIntent.CANCEL, catchEvent.getValue()); streamProcessor.unblock(); streamProcessorRule.awaitElementInState(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_TERMINATED); // when envRule.writeCommand(WorkflowInstanceSubscriptionIntent.CORRELATE, subscription); // then final TypedRecord<WorkflowInstanceSubscriptionRecord> rejection = streamProcessorRule.awaitAndGetFirstSubscriptionRejection(); assertThat(rejection.getMetadata().getIntent()) .isEqualTo(WorkflowInstanceSubscriptionIntent.CORRELATE); // since we mock the message partition, we never get the acknowledged CLOSE command, so our // subscription remains in closing state assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.INVALID_STATE); }
@Test public void shouldRejectCorrelateWorkflowInstanceSubscription() { // given streamProcessorRule.deploy(MESSAGE_CATCH_EVENT_WORKFLOW); final TypedRecord<WorkflowInstanceRecord> createdEvent = streamProcessorRule.createWorkflowInstance(PROCESS_ID, asMsgPack("orderId", "order-123")); final TypedRecord<WorkflowInstanceRecord> catchEvent = streamProcessorRule.awaitElementInState( "catch-event", WorkflowInstanceIntent.ELEMENT_ACTIVATED); final WorkflowInstanceSubscriptionRecord subscription = subscriptionRecordForEvent(catchEvent); streamProcessor.blockAfterWorkflowInstanceSubscriptionEvent( e -> e.getMetadata().getIntent() == WorkflowInstanceSubscriptionIntent.OPENED); envRule.writeCommand(WorkflowInstanceSubscriptionIntent.OPEN, subscription); waitUntil(() -> streamProcessor.isBlocked()); envRule.writeCommand( createdEvent.getKey(), WorkflowInstanceIntent.CANCEL, catchEvent.getValue()); streamProcessor.unblock(); streamProcessorRule.awaitElementInState(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_TERMINATED); // when envRule.writeCommand(WorkflowInstanceSubscriptionIntent.CORRELATE, subscription); // then final TypedRecord<WorkflowInstanceSubscriptionRecord> rejection = streamProcessorRule.awaitAndGetFirstSubscriptionRejection(); assertThat(rejection.getMetadata().getIntent()) .isEqualTo(WorkflowInstanceSubscriptionIntent.CORRELATE); // since we mock the message partition, we never get the acknowledged CLOSE command, so our // subscription remains in closing state assertThat(rejection.getMetadata().getRejectionType()).isEqualTo(RejectionType.INVALID_STATE); }
.hasPartitionId(PARTITION_ID) .hasRecordType(metadata.getRecordType()) .hasRejectionType(metadata.getRejectionType()) .hasRejectionReason(bufferAsString(metadata.getRejectionReason())) .hasValueType(metadata.getValueType());
.hasPartitionId(PARTITION_ID) .hasRecordType(metadata.getRecordType()) .hasRejectionType(metadata.getRejectionType()) .hasRejectionReason(bufferAsString(metadata.getRejectionReason())) .hasValueType(metadata.getValueType());