use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.
the class RestSwaggerReaderModelTest method testReaderRead.
@Test
public void testReaderRead() throws Exception {
BeanConfig config = new BeanConfig();
config.setHost("localhost:8080");
config.setSchemes(new String[] { "http" });
config.setBasePath("/api");
config.setTitle("Camel User store");
config.setLicense("Apache 2.0");
config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
RestSwaggerReader reader = new RestSwaggerReader();
Swagger swagger = reader.read(context.getRestDefinitions(), null, config, context.getName(), new DefaultClassResolver());
assertNotNull(swagger);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String json = mapper.writeValueAsString(swagger);
log.info(json);
assertTrue(json.contains("\"host\" : \"localhost:8080\""));
assertTrue(json.contains("\"description\" : \"The user returned\""));
assertTrue(json.contains("\"$ref\" : \"#/definitions/User\""));
assertTrue(json.contains("\"x-className\""));
assertTrue(json.contains("\"format\" : \"org.apache.camel.swagger.User\""));
assertFalse(json.contains("\"enum\""));
context.stop();
}
use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.
the class RestSwaggerReaderTest method testReaderRead.
@Test
public void testReaderRead() throws Exception {
BeanConfig config = new BeanConfig();
config.setHost("localhost:8080");
config.setSchemes(new String[] { "http" });
config.setBasePath("/api");
RestSwaggerReader reader = new RestSwaggerReader();
Swagger swagger = reader.read(context.getRestDefinitions(), null, config, context.getName(), new DefaultClassResolver());
assertNotNull(swagger);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
String json = mapper.writeValueAsString(swagger);
log.info(json);
assertTrue(json.contains("\"host\" : \"localhost:8080\""));
assertTrue(json.contains("\"basePath\" : \"/api\""));
assertTrue(json.contains("\"/hello/bye\""));
assertTrue(json.contains("\"summary\" : \"To update the greeting message\""));
assertTrue(json.contains("\"/hello/bye/{name}\""));
assertTrue(json.contains("\"/hello/hi/{name}\""));
context.stop();
}
use of com.fasterxml.jackson.databind.ObjectMapper in project pulsar by yahoo.
the class ConsumerStats method init.
private void init(ConsumerConfiguration conf) {
ObjectMapper m = new ObjectMapper();
m.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
ObjectWriter w = m.writerWithDefaultPrettyPrinter();
try {
log.info("Starting Pulsar consumer perf with config: {}", w.writeValueAsString(conf));
log.info("Pulsar client config: {}", w.writeValueAsString(pulsarClient.getConfiguration()));
} catch (IOException e) {
log.error("Failed to dump config info: {}", e);
}
stat = (timeout) -> {
if (timeout.isCancelled()) {
return;
}
try {
long now = System.nanoTime();
double elapsed = (now - oldTime) / 1e9;
oldTime = now;
long currentNumMsgsReceived = numMsgsReceived.sumThenReset();
long currentNumBytesReceived = numBytesReceived.sumThenReset();
long currentNumReceiveFailed = numReceiveFailed.sumThenReset();
long currentNumAcksSent = numAcksSent.sumThenReset();
long currentNumAcksFailed = numAcksFailed.sumThenReset();
totalMsgsReceived.add(currentNumMsgsReceived);
totalBytesReceived.add(currentNumBytesReceived);
totalReceiveFailed.add(currentNumReceiveFailed);
totalAcksSent.add(currentNumAcksSent);
totalAcksFailed.add(currentNumAcksFailed);
if ((currentNumMsgsReceived | currentNumBytesReceived | currentNumReceiveFailed | currentNumAcksSent | currentNumAcksFailed) != 0) {
log.info("[{}] [{}] [{}] Prefetched messages: {} --- Consume throughput: {} msgs/s --- " + "Throughput received: {} msg/s --- {} Mbit/s --- " + "Ack sent rate: {} ack/s --- " + "Failed messages: {} --- " + "Failed acks: {}", consumer.getTopic(), consumer.getSubscription(), consumer.consumerName, consumer.incomingMessages.size(), throughputFormat.format(currentNumMsgsReceived / elapsed), throughputFormat.format(currentNumBytesReceived / elapsed * 8 / 1024 / 1024), throughputFormat.format(currentNumAcksSent / elapsed), currentNumReceiveFailed, currentNumAcksFailed);
}
} catch (Exception e) {
log.error("[{}] [{}] [{}]: {}", consumer.getTopic(), consumer.subscription, consumer.consumerName, e.getMessage());
} finally {
// schedule the next stat info
statTimeout = pulsarClient.timer().newTimeout(stat, statsIntervalSeconds, TimeUnit.SECONDS);
}
};
oldTime = System.nanoTime();
statTimeout = pulsarClient.timer().newTimeout(stat, statsIntervalSeconds, TimeUnit.SECONDS);
}
use of com.fasterxml.jackson.databind.ObjectMapper in project pulsar by yahoo.
the class ProducerStats method init.
private void init(ProducerConfiguration conf) {
ObjectMapper m = new ObjectMapper();
m.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
ObjectWriter w = m.writerWithDefaultPrettyPrinter();
try {
log.info("Starting Pulsar producer perf with config: {}", w.writeValueAsString(conf));
log.info("Pulsar client config: {}", w.writeValueAsString(pulsarClient.getConfiguration()));
} catch (IOException e) {
log.error("Failed to dump config info: {}", e);
}
stat = (timeout) -> {
if (timeout.isCancelled()) {
return;
}
try {
long now = System.nanoTime();
double elapsed = (now - oldTime) / 1e9;
oldTime = now;
long currentNumMsgsSent = numMsgsSent.sumThenReset();
long currentNumBytesSent = numBytesSent.sumThenReset();
long currentNumSendFailedMsgs = numSendFailed.sumThenReset();
long currentNumAcksReceived = numAcksReceived.sumThenReset();
totalMsgsSent.add(currentNumMsgsSent);
totalBytesSent.add(currentNumBytesSent);
totalSendFailed.add(currentNumSendFailedMsgs);
totalAcksReceived.add(currentNumAcksReceived);
double[] percentileValues;
synchronized (ds) {
percentileValues = ds.getQuantiles(percentiles);
ds.reset();
}
if ((currentNumMsgsSent | currentNumSendFailedMsgs | currentNumAcksReceived | currentNumMsgsSent) != 0) {
for (int i = 0; i < percentileValues.length; i++) {
if (percentileValues[i] == Double.NaN) {
percentileValues[i] = 0;
}
}
log.info("[{}] [{}] Pending messages: {} --- Publish throughput: {} msg/s --- {} Mbit/s --- " + "Latency: med: {} ms - 95pct: {} ms - 99pct: {} ms - 99.9pct: {} ms - 99.99pct: {} ms --- " + "Ack received rate: {} ack/s --- Failed messages: {}", producer.getTopic(), producer.getProducerName(), producer.getPendingQueueSize(), throughputFormat.format(currentNumMsgsSent / elapsed), throughputFormat.format(currentNumBytesSent / elapsed / 1024 / 1024 * 8), dec.format(percentileValues[0] / 1000.0), dec.format(percentileValues[1] / 1000.0), dec.format(percentileValues[2] / 1000.0), dec.format(percentileValues[3] / 1000.0), dec.format(percentileValues[4] / 1000.0), throughputFormat.format(currentNumAcksReceived / elapsed), currentNumSendFailedMsgs);
}
} catch (Exception e) {
log.error("[{}] [{}]: {}", producer.getTopic(), producer.getProducerName(), e.getMessage());
} finally {
// schedule the next stat info
statTimeout = pulsarClient.timer().newTimeout(stat, statsIntervalSeconds, TimeUnit.SECONDS);
}
};
oldTime = System.nanoTime();
statTimeout = pulsarClient.timer().newTimeout(stat, statsIntervalSeconds, TimeUnit.SECONDS);
}
use of com.fasterxml.jackson.databind.ObjectMapper in project pulsar by yahoo.
the class ObjectMapperFactory method create.
public static ObjectMapper create() {
ObjectMapper mapper = new ObjectMapper();
// forward compatibility for the properties may go away in the future
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
return mapper;
}
Aggregations