@Test public void convertSingleNumericToString() throws Exception { ImmutableMap<String, String> tags = ImmutableMap.of("myTagKey1", "myTagValue1"); ResultSerializer resultSerializer = new DefaultResultSerializer(ImmutableList.<String>of(), false, "rootPrefix", tags, asList("typeName.type", "className")); long now = System.currentTimeMillis(); String message = resultSerializer.serialize(dummyServer(), dummyQuery(), numericResultAt(now)); assertThat(message).endsWith("}}"); JsonNode jsonNode = objectMapper.readValue(message, JsonNode.class); assertThat(jsonNode.get("keyspace").asText()).isEqualTo("rootPrefix.host_example_net_4321.MemoryAlias.ObjectPendingFinalizationCount"); assertThat(jsonNode.get("value").asLong()).isEqualTo(10L); assertThat(jsonNode.get("timestamp").asLong()).isEqualTo(now / 1000); assertThat(jsonNode.get("tags").get("myTagKey1").asText()).isEqualTo("myTagValue1"); assertThat(jsonNode.get("tags").get("typeName.type").asText()).isEqualTo("Memory"); assertThat(jsonNode.get("tags").get("className").asText()).endsWith("MemoryImpl"); }
@Override public String serialize(Server server, Query query, Result result) throws IOException { log.debug("Query result: [{}]", result); Object value = result.getValue(); if (!isNumeric(value)) { log.warn("Unable to submit non-numeric value to Kafka: [{}] from result [{}]", value, result); return null; } return createJsonMessage(server, query, result, result.getValuePath(), value); }
DefaultResultSerializer implements ResultSerializer { @Override public String serialize(Server server, Query query, Result result) throws IOException { log.debug("Query result: [{}]", result); Object value = result.getValue(); if (!isNumeric(value)) { log.warn("Unable to submit non-numeric value to Kafka: [{}] from result [{}]", value, result); return null; } return createJsonMessage(server, query, result, result.getValuePath(), value); } }
DefaultResultSerializer implements ResultSerializer { @Override public String serialize(Server server, Query query, Result result) throws IOException { log.debug("Query result: [{}]", result); Object value = result.getValue(); if (!isNumeric(value)) { log.warn("Unable to submit non-numeric value to Kafka: [{}] from result [{}]", value, result); return null; } return createJsonMessage(server, query, result, result.getValuePath(), value); } @JsonCreator  DefaultResultSerializer(@JsonProperty("typeNames") List<String> typeNames,
									@JsonProperty("booleanAsNumber") boolean booleanAsNumber,
									@JsonProperty("rootPrefix") String rootPrefix,
									@JsonProperty("tags") Map<String, String> tags,
									@JsonProperty("resultTags") List<String> resultTags
									); }
DefaultResultSerializer implements ResultSerializer { @Override public String serialize(Server server, Query query, Result result) throws IOException { log.debug("Query result: [{}]", result); Object value = result.getValue(); if (!isNumeric(value)) { log.warn("Unable to submit non-numeric value to Kafka: [{}] from result [{}]", value, result); return null; } return createJsonMessage(server, query, result, result.getValuePath(), value); } @JsonCreator  DefaultResultSerializer(@JsonProperty("typeNames") List<String> typeNames,
									@JsonProperty("booleanAsNumber") boolean booleanAsNumber,
									@JsonProperty("rootPrefix") String rootPrefix,
									@JsonProperty("tags") Map<String, String> tags,
									@JsonProperty("resultTags") List<String> resultTags
									); @Override String serialize(Server server, Query query, Result result); }
DefaultResultSerializer implements ResultSerializer { @Override public String serialize(Server server, Query query, Result result) throws IOException { log.debug("Query result: [{}]", result); Object value = result.getValue(); if (!isNumeric(value)) { log.warn("Unable to submit non-numeric value to Kafka: [{}] from result [{}]", value, result); return null; } return createJsonMessage(server, query, result, result.getValuePath(), value); } @JsonCreator  DefaultResultSerializer(@JsonProperty("typeNames") List<String> typeNames,
									@JsonProperty("booleanAsNumber") boolean booleanAsNumber,
									@JsonProperty("rootPrefix") String rootPrefix,
									@JsonProperty("tags") Map<String, String> tags,
									@JsonProperty("resultTags") List<String> resultTags
									); @Override String serialize(Server server, Query query, Result result);  }