public void writeTo(MessagePacker packer) throws IOException { toValue().writeTo(packer); }
/** * Create corresponding InfluxDBException from the message pack error body. * @param messagePackErrorBody * @return */ public static InfluxDBException buildExceptionForErrorState(final InputStream messagePackErrorBody) { try { MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(messagePackErrorBody); ImmutableMapValue mapVal = (ImmutableMapValue) unpacker.unpackValue(); return InfluxDBException.buildExceptionFromErrorMessage( mapVal.map().get(new ImmutableStringValueImpl("error")).toString()); } catch (Exception e) { return new InfluxDBException(e); } } }
int mapSize = mapValue.size(); Value[] keyValueArray = mapValue.getKeyValueArray();
/** * Create corresponding InfluxDBException from the message pack error body. * @param messagePackErrorBody * @return */ public static InfluxDBException buildExceptionForErrorState(final InputStream messagePackErrorBody) { try { MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(messagePackErrorBody); ImmutableMapValue mapVal = (ImmutableMapValue) unpacker.unpackValue(); return InfluxDBException.buildExceptionFromErrorMessage( mapVal.map().get(new ImmutableStringValueImpl("error")).toString()); } catch (Exception e) { return new InfluxDBException(e); } } }
@Override protected String getStringFromValueState( String state, String key ) throws Exception { return MessagePack.newDefaultUnpacker( Base64.getDecoder().decode( state ) ) .unpackValue().asMapValue() .map().get( ValueFactory.newString( key ) ) .asStringValue().asString(); } }
private void assertRecord0(byte[] formatted, long expectedTime) throws IOException { try (MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(formatted)) { Map<Value, Value> map = unpacker.unpackValue().asMapValue().map(); assertEquals(4, map.size()); assertEquals(expectedTime, map.get(KEY_TIME).asNumberValue().toLong()); assertEquals("first", map.get(KEY_NAME).asStringValue().asString()); assertEquals(42, map.get(KEY_AGE).asNumberValue().toInt()); assertEquals("hello@world.com", map.get(KEY_EMAIL).asStringValue().asString()); } }
private void assertRecord1(byte[] formatted, long expectedTime) throws IOException { try (MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(formatted)) { Map<Value, Value> map = unpacker.unpackValue().asMapValue().map(); assertEquals(4, map.size()); assertEquals(expectedTime, map.get(KEY_TIME).asNumberValue().toLong()); assertEquals("second", map.get(KEY_NAME).asStringValue().asString()); assertEquals(55, map.get(KEY_AGE).asNumberValue().toInt()); assertEquals("zzzzzz", map.get(KEY_COMMENT).asStringValue().asString()); } }
private void assertRecord2(byte[] formatted, long expectedTime) throws IOException { try (MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(formatted)) { Map<Value, Value> map = unpacker.unpackValue().asMapValue().map(); assertEquals(4, map.size()); assertEquals(expectedTime, map.get(KEY_TIME).asNumberValue().toLong()); assertEquals("third", map.get(KEY_NAME).asStringValue().asString()); assertEquals(99, map.get(KEY_AGE).asNumberValue().toInt()); assertEquals("knight", map.get(KEY_JOB).asStringValue().asString()); } }
assertEquals("foo.bar", unpacker.unpackString()); ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue(); Map<Value, Value> map = unpacker.unpackValue().asMapValue().map(); assertEquals(2, map.size()); assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());
@Theory public void testWithAckResponseButNotReceiveToken(final boolean sslEnabled) throws Throwable { Exception exception = new ConfigurableTestServer(sslEnabled).run( clientSocket -> { MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocket.getInputStream()); assertEquals(3, unpacker.unpackArrayHeader()); assertEquals("foo.bar", unpacker.unpackString()); ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue(); Map<Value, Value> map = unpacker.unpackValue().asMapValue().map(); assertEquals(2, map.size()); assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt()); assertNotNull(map.get(KEY_OPTION_CHUNK).asRawValue().asString()); unpacker.close(); }, serverPort -> { FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd(); builder.setSslEnabled(sslEnabled); builder.setAckResponseMode(true); try (Fluency fluency = builder.build(serverPort)) { fluency.emit("foo.bar", new HashMap<>()); } }, 5000); assertEquals(exception.getClass(), TimeoutException.class); }
@Theory public void testWithoutAckResponse(final boolean sslEnabled) throws Throwable { Exception exception = new ConfigurableTestServer(sslEnabled).run( clientSocket -> { MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocket.getInputStream()); assertEquals(3, unpacker.unpackArrayHeader()); assertEquals("foo.bar", unpacker.unpackString()); ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue(); Map<Value, Value> map = unpacker.unpackValue().asMapValue().map(); assertEquals(1, map.size()); assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt()); unpacker.close(); }, serverPort -> { FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd(); builder.setSslEnabled(sslEnabled); try (Fluency fluency = builder.build(serverPort)) { fluency.emit("foo.bar", new HashMap<>()); } }, 5000); assertNull(exception); }
assertEquals("foo.bar", unpacker.unpackString()); ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue(); Map<Value, Value> map = unpacker.unpackValue().asMapValue().map(); assertEquals(2, map.size()); assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());