Skip to content

Commit

Permalink
Merge pull request #5 from btison/incidents
Browse files Browse the repository at this point in the history
incident priority also returns total number of incidents in session
  • Loading branch information
btison authored May 4, 2019
2 parents b454af5 + a724c15 commit 9ffe938
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void handleMessage(KafkaConsumerRecord<String, String> msg) {
log.warn("Message of type '" + "' has unexpected structure: " + message.toString());
}
String incidentId = message.getJsonObject("body").getString("incidentId");
log.info("Consumed '" + messageType + "' message for incident '" + incidentId + "'. Topic: " + msg.topic()
log.debug("Consumed '" + messageType + "' message for incident '" + incidentId + "'. Topic: " + msg.topic()
+ " , partition: " + msg.partition() + ", offset: " + msg.offset());

vertx.eventBus().send("incident-assignment-event", body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ private void incidentPriority(Message<JsonObject> message) {
} else {
average = ((AveragePriority)row.get("averagePriority")).getAveragePriority();
}

results = ksession.getQueryResults("incidents");
JsonObject jsonObject = new JsonObject().put("incidentId", incidentId).put("priority", priority)
.put("average", average);
.put("average", average).put("incidents", results.size());
message.reply(jsonObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ end

query "averagePriority"
averagePriority : AveragePriority( )
end

query "incidents"
incidentPriority: IncidentPriority()
end
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public void testIncreaseIncidentPriority() {
assertThat(row.get("incidentPriority"), notNullValue());
assertThat(row.get("incidentPriority"), is(instanceOf(IncidentPriority.class)));
assertThat(((IncidentPriority)row.get("incidentPriority")).getPriority(), equalTo(1));
QueryResults incidents = session.getQueryResults("incidents");
assertThat(incidents.size(), equalTo(1));
}

@Test
Expand All @@ -86,6 +88,8 @@ public void testRetractIncidentPriority() {
session.fireAllRules();
QueryResults results = session.getQueryResults("incidentPriority", "incident123");
assertThat(results.size(), equalTo(0));
QueryResults incidents = session.getQueryResults("incidents");
assertThat(incidents.size(), equalTo(0));
}

@Test
Expand All @@ -99,6 +103,8 @@ public void testAveragePriority1() {
assertThat(row.get("averagePriority"), notNullValue());
assertThat(row.get("averagePriority"), is(instanceOf(AveragePriority.class)));
assertThat(((AveragePriority)row.get("averagePriority")).getAveragePriority(), equalTo(1.0));
QueryResults incidents = session.getQueryResults("incidents");
assertThat(incidents.size(), equalTo(1));
}

@Test
Expand All @@ -112,6 +118,8 @@ public void testAveragePriority2() {
assertThat(row.get("averagePriority"), notNullValue());
assertThat(row.get("averagePriority"), is(instanceOf(AveragePriority.class)));
assertThat(((AveragePriority)row.get("averagePriority")).getAveragePriority(), equalTo(1.0));
QueryResults incidents = session.getQueryResults("incidents");
assertThat(incidents.size(), equalTo(1));
}

@Test
Expand All @@ -127,6 +135,8 @@ public void testAveragePriority3() {
assertThat(row.get("averagePriority"), notNullValue());
assertThat(row.get("averagePriority"), is(instanceOf(AveragePriority.class)));
assertThat(((AveragePriority)row.get("averagePriority")).getAveragePriority(), equalTo(0.0));
QueryResults incidents = session.getQueryResults("incidents");
assertThat(incidents.size(), equalTo(0));
}

@Test
Expand All @@ -142,6 +152,8 @@ public void testAveragePriority4() {
assertThat(row.get("averagePriority"), notNullValue());
assertThat(row.get("averagePriority"), is(instanceOf(AveragePriority.class)));
assertThat(((AveragePriority)row.get("averagePriority")).getAveragePriority(), equalTo(1.0));
QueryResults incidents = session.getQueryResults("incidents");
assertThat(incidents.size(), equalTo(2));
}

@Test
Expand All @@ -159,6 +171,8 @@ public void testAveragePriority5() {
assertThat(row.get("averagePriority"), notNullValue());
assertThat(row.get("averagePriority"), is(instanceOf(AveragePriority.class)));
assertThat(((AveragePriority)row.get("averagePriority")).getAveragePriority(), equalTo(1.5));
QueryResults incidents = session.getQueryResults("incidents");
assertThat(incidents.size(), equalTo(2));
}

@Test
Expand All @@ -178,6 +192,8 @@ public void testAveragePriority6() {
assertThat(row.get("averagePriority"), notNullValue());
assertThat(row.get("averagePriority"), is(instanceOf(AveragePriority.class)));
assertThat(((AveragePriority)row.get("averagePriority")).getAveragePriority(), equalTo(2.0));
QueryResults incidents = session.getQueryResults("incidents");
assertThat(incidents.size(), equalTo(1));
}

private static KieBase setupKieBase(String... resources) {
Expand Down

0 comments on commit 9ffe938

Please sign in to comment.