state.put(user, sum + value);
}
- public synchronized Long calculate(String user)
+ public synchronized AdderResult calculate(String user)
{
if (!state.containsKey(user))
throw new IllegalStateException("No sumation for " + user + " in progress");
- return state.remove(user);
+ return new AdderResult(66, state.remove(user));
}
protected Map<String, Long> getState()
--- /dev/null
+package de.juplo.kafka;
+
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+
+@RequiredArgsConstructor
+@Getter
+@EqualsAndHashCode
+public class AdderResult
+{
+ final int number;
+ final long sum;
+
+ @Override
+ public String toString()
+ {
+ return "sum(" + number + ") = " + sum;
+ }
+}
if (message.equals("CALCULATE"))
{
- Long result = state.get(partition).calculate(user);
+ AdderResult result = state.get(partition).calculate(user);
log.info("New result for {}: {}", user, result);
return;
}
long expectedResult = Arrays.stream(numbers).sum();
AdderBusinessLogic adder = new AdderBusinessLogic();
Arrays.stream(numbers).forEach(number -> adder.addToSum("foo", number));
- assertThat(adder.calculate("foo")).isEqualTo(expectedResult);
+ AdderResult result = adder.calculate("foo");
+ assertThat(result.number).isEqualTo(numbers[numbers.length-1]);
+ assertThat(result.sum).isEqualTo(expectedResult);
}
static Stream<Arguments> numbersProvider() {