/** * 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); } } }
HttpEntity messageEntity = httpResponse.getEntity(); if (messageEntity != null) { MessagePack msgpack = new MessagePack(); MessageUnpacker u = msgpack.newUnpacker(messageEntity.getContent()); MapValue mv = (MapValue) u.unpackValue(); Map<Value, Value> map = mv.map();
/** * 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 public <T> T deserialize( ModuleDescriptor module, ValueType valueType, InputStream state ) { try( MessageUnpacker unpacker = MessagePack.newDefaultUnpacker( state ) ) { if( !unpacker.hasNext() ) { return null; } ImmutableValue value = unpacker.unpackValue(); return doDeserialize( module, valueType, value ); } catch( IOException ex ) { throw new SerializationException( "Unable to deserialize " + valueType, ex ); } }
@Override protected String getSingleStringRawState( String state ) throws Exception { return MessagePack.newDefaultUnpacker( Base64.getDecoder().decode( state ) ) .unpackValue().asStringValue().asString(); } }
ImmutableValue message = unpacker.unpackValue(); deserialisedMessages += message; deserialisedMessages += "\n";
@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 byte[] addTimeColumnToMsgpackRecord(MessageUnpacker unpacker, long timestamp, int mapValueLen) throws IOException ImmutableMapValue mapValue = unpacker.unpackValue().asMapValue(); int mapSize = mapValue.size(); Value[] keyValueArray = mapValue.getKeyValueArray();
List<Value> list = new ArrayList<Value>(size); for (int i = 0; i < size; i++) { list.add(unpackValue()); Map<Value, Value> map = new HashMap<Value, Value>(); for (int i = 0; i < size; i++) { Value k = unpackValue(); Value v = unpackValue(); map.put(k, v);
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()); } }
@Test public void ingestWithAck() throws IOException { FluentdIngester.Config config = new FluentdIngester.Config(); config.setAckResponseMode(true); Ingester ingester = new FluentdIngester(config, fluentdSender); ingester.ingest(TAG, ByteBuffer.wrap(DATA)); ArgumentCaptor<byte[]> ackTokenArgumentCaptor = ArgumentCaptor.forClass(byte[].class); verify(fluentdSender, times(1)) .sendWithAck(byteBuffersArgumentCaptor.capture(), ackTokenArgumentCaptor.capture()); List<ByteBuffer> byteBuffers = byteBuffersArgumentCaptor.getAllValues().get(0); byte[] ingested = getIngestedData(byteBuffers); MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(ingested); ImmutableArrayValue arrayValue = unpacker.unpackValue().asArrayValue(); assertEquals(3, arrayValue.size()); assertEquals(TAG, arrayValue.get(0).asStringValue().asString()); assertArrayEquals(DATA, arrayValue.get(1).asRawValue().asByteArray()); Map<Value, Value> options = arrayValue.get(2).asMapValue().map(); assertEquals(2, options.size()); assertEquals(DATA.length, options.get(ValueFactory.newString("size")).asIntegerValue().asInt()); String ackToken = options.get(ValueFactory.newString("chunk")).asRawValue().asString(); UUID uuidFromAckToken = UUID.fromString(ackToken); List<byte[]> ackTokenArgumentCaptorAllValues = ackTokenArgumentCaptor.getAllValues(); assertEquals(1, ackTokenArgumentCaptorAllValues.size()); assertEquals(uuidFromAckToken, UUID.fromString(new String(ackTokenArgumentCaptorAllValues.get(0), CHARSET))); }
break; value = unpacker.unpackValue(); LOG.trace("Received a value: local.port={}, remote.port={}", acceptSocket.getLocalPort(), acceptSocket.getPort()); MessageUnpacker eventsUnpacker = MessagePack.newDefaultUnpacker(packedBytes); while (eventsUnpacker.hasNext()) { ImmutableArrayValue arrayValue = eventsUnpacker.unpackValue().asArrayValue(); assertEquals(2, arrayValue.size()); Value timestampValue = arrayValue.get(0);
Value[] array = new Value[size]; for (int i = 0; i < size; i++) { array[i] = unpackValue(); Value[] kvs = new Value[size * 2]; for (int i = 0; i < size * 2; ) { kvs[i] = unpackValue(); i++; kvs[i] = unpackValue(); i++;
@Test public void ingestWithoutAck() throws IOException { Ingester ingester = new FluentdIngester(new FluentdIngester.Config(), fluentdSender); ingester.ingest(TAG, ByteBuffer.wrap(DATA)); verify(fluentdSender, times(1)).send(byteBuffersArgumentCaptor.capture()); List<ByteBuffer> byteBuffers = byteBuffersArgumentCaptor.getAllValues().get(0); byte[] ingested = getIngestedData(byteBuffers); MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(ingested); ImmutableArrayValue arrayValue = unpacker.unpackValue().asArrayValue(); assertEquals(3, arrayValue.size()); assertEquals(TAG, arrayValue.get(0).asStringValue().asString()); assertArrayEquals(DATA, arrayValue.get(1).asRawValue().asByteArray()); Map<Value, Value> options = arrayValue.get(2).asMapValue().map(); assertEquals(1, options.size()); assertEquals(DATA.length, options.get(ValueFactory.newString("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(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());
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());