Skip to content

Commit

Permalink
use Number instead of long for response context (#8342)
Browse files Browse the repository at this point in the history
* use Number instead of long for response context to be forgiving of json serde to int or long

* test that encounters issue without fix

* now with more test

* is ints
  • Loading branch information
clintropolis authored and gianm committed Aug 21, 2019
1 parent d5a1967 commit c87b68d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public enum Key implements BaseKey
*/
NUM_SCANNED_ROWS(
"count",
(oldValue, newValue) -> (long) oldValue + (long) newValue
(oldValue, newValue) -> ((Number) oldValue).longValue() + ((Number) newValue).longValue()
),
/**
* The total CPU time for threads related to Sequence processing of the query.
Expand All @@ -159,7 +159,7 @@ public enum Key implements BaseKey
*/
CPU_CONSUMED_NANOS(
"cpuConsumed",
(oldValue, newValue) -> (long) oldValue + (long) newValue
(oldValue, newValue) -> ((Number) oldValue).longValue() + ((Number) newValue).longValue()
),
/**
* Indicates if a {@link ResponseContext} was truncated during serialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,22 @@ public void deserializeTest() throws IOException
{
final DefaultObjectMapper mapper = new DefaultObjectMapper();
final ResponseContext ctx = ResponseContext.deserialize(
mapper.writeValueAsString(ImmutableMap.of("ETag", "string-value", "count", 100)),
mapper.writeValueAsString(
ImmutableMap.of(
"ETag", "string-value",
"count", 100L,
"cpuConsumed", 100000L
)
),
mapper
);
Assert.assertEquals("string-value", ctx.get(ResponseContext.Key.ETAG));
Assert.assertEquals(100, ctx.get(ResponseContext.Key.NUM_SCANNED_ROWS));
Assert.assertEquals(100000, ctx.get(ResponseContext.Key.CPU_CONSUMED_NANOS));
ctx.add(ResponseContext.Key.NUM_SCANNED_ROWS, 10L);
Assert.assertEquals(110L, ctx.get(ResponseContext.Key.NUM_SCANNED_ROWS));
ctx.add(ResponseContext.Key.CPU_CONSUMED_NANOS, 100);
Assert.assertEquals(100100L, ctx.get(ResponseContext.Key.CPU_CONSUMED_NANOS));
}

@Test(expected = IllegalStateException.class)
Expand Down

0 comments on commit c87b68d

Please sign in to comment.