Skip to content

Commit

Permalink
fix: fix the tests and some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
agavra committed Oct 23, 2019
1 parent fd44da4 commit b668bd6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.fasterxml.jackson.databind.node.TextNode;
import com.google.common.collect.ImmutableMap;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -102,11 +103,23 @@ private static boolean compareNumber(final Object actualValue, final JsonNode ex
if (actualValue instanceof Double) {
return expected.doubleValue() == (Double) actualValue;
}
if (actualValue instanceof BigDecimal && !(expectedValue.isBigDecimal())) {
// only allow this to pass if we deserialized a double as a big decimal
// in ValueSpecJsonSerdeSupplier#Deserializer. if we were expecting a big
// decimal than it should be encoded as a string and go to #compareText
return expected.doubleValue() == ((BigDecimal) actualValue).doubleValue();
if (actualValue instanceof BigDecimal) {
if (!expected.isBigDecimal()) {
// we don't want to risk comparing a BigDecimal with something of
// lower precision
return false;
}

expected.isBigDecimal();
try {
return expected.decimalValue()
.setScale(((BigDecimal) actualValue).scale(), RoundingMode.UNNECESSARY)
.equals(actualValue);
} catch (final ArithmeticException e) {
// the scale of the expected value cannot match the scale of the actual value
// without rounding
return false;
}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,12 @@ private static String getActualsForErrorMessage(final List<StubKafkaRecord> actu
}

private static String getProducerRecordInString(final ProducerRecord<?, ?> producerRecord) {
final Object value = producerRecord.value() instanceof String
? "\"" + producerRecord.value() + "\""
: producerRecord.value();

return "<" + producerRecord.key() + ", "
+ producerRecord.value() + "> with timestamp="
+ value + "> with timestamp="
+ producerRecord.timestamp();
}

Expand Down Expand Up @@ -486,7 +490,7 @@ private static void validateCreatedMessage(

final AssertionError error = new AssertionError(
"Topic '" + topicName + "', message " + messageIndex
+ ": Expected <" + expectedKey + ", " + expectedValue.asText() + "> "
+ ": Expected <" + expectedKey + ", " + expectedValue + "> "
+ "with timestamp=" + expectedTimestamp
+ " but was " + getProducerRecordInString(actualProducerRecord));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void shouldFailWithIncorrectTest() throws Exception {

// Then:
assertThat(errContent.toString(UTF_8),
containsString("Test failed: Topic 'S1', message 0: Expected <1001, 101> with timestamp=0 but was <101, 101> with timestamp=0\n"));
containsString("Test failed: Topic 'S1', message 0: Expected <1001, \"101\"> with timestamp=0 but was <101, \"101\"> with timestamp=0\n"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void shouldFailOnTwoLittleOutput() {
expectedException.expect(KsqlException.class);
expectedException.expectMessage("Expected <2> records but it was <1>\n"
+ "Actual records: \n"
+ "<k1, v1> with timestamp=123456719");
+ "<k1, \"v1\"> with timestamp=123456719");

// When:
executor.buildAndExecuteQuery(testCase);
Expand All @@ -222,8 +222,8 @@ public void shouldFailOnTwoMuchOutput() {
expectedException.expect(KsqlException.class);
expectedException.expectMessage("Expected <1> records but it was <2>\n"
+ "Actual records: \n"
+ "<k1, v1> with timestamp=123456719 \n"
+ "<k2, v2> with timestamp=123456789");
+ "<k1, \"v1\"> with timestamp=123456719 \n"
+ "<k2, \"v2\"> with timestamp=123456789");

// When:
executor.buildAndExecuteQuery(testCase);
Expand All @@ -243,7 +243,7 @@ public void shouldFailOnUnexpectedOutput() {
// Expect
expectedException.expect(AssertionError.class);
expectedException.expectMessage(
"Expected <k2, different> with timestamp=123456789 but was <k2, v2> with timestamp=123456789");
"Expected <k2, \"different\"> with timestamp=123456789 but was <k2, \"v2\"> with timestamp=123456789");

// When:
executor.buildAndExecuteQuery(testCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@
"inputs": [
{"topic": "test_topic", "key": 0, "value": {"value":[1.0, 1.0]}},
{"topic": "test_topic", "key": 0, "value": {"value":[2.0, 2.0]}},
{"topic": "test_topic", "key": 0, "value": {"value":[9223372036854775807.0, 1.0]}},
{"topic": "test_topic", "key": 0, "value": {"value":[922337203685.0, 1.0]}},
{"topic": "test_topic", "key": 0, "value": {"value":[1.0, 1.0, null]}}
],
"outputs": [
{"topic": "OUTPUT", "key": 0, "value": {"SUM_VAL":2.0}},
{"topic": "OUTPUT", "key": 0, "value": {"SUM_VAL":6.0}},
{"topic": "OUTPUT", "key": 0, "value": {"SUM_VAL":9223372036854775814.0}},
{"topic": "OUTPUT", "key": 0, "value": {"SUM_VAL":9223372036854775816.0}}
{"topic": "OUTPUT", "key": 0, "value": {"SUM_VAL":922337203692.0}},
{"topic": "OUTPUT", "key": 0, "value": {"SUM_VAL":922337203694.0}}
]
},
{
Expand Down

0 comments on commit b668bd6

Please sign in to comment.