use Number instead of long for response context (#8342)

* 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
This commit is contained in:
Clint Wylie 2019-08-20 19:05:49 -07:00 committed by Gian Merlino
parent d5a19675dd
commit c87b68d2a4
2 changed files with 14 additions and 3 deletions

View File

@ -150,7 +150,7 @@ public abstract class ResponseContext
*/
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.
@ -159,7 +159,7 @@ public abstract class ResponseContext
*/
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.

View File

@ -280,11 +280,22 @@ public class ResponseContextTest
{
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)