@Test public void testOrdinaryInteger() throws Exception { final JsonParser parser = new JsonParser(); final Value msgpackValue = parser.parse("12345"); assertTrue(msgpackValue.getValueType().isNumberType()); assertTrue(msgpackValue.getValueType().isIntegerType()); assertFalse(msgpackValue.getValueType().isFloatType()); assertFalse(msgpackValue.getValueType().isStringType()); assertEquals(12345, msgpackValue.asIntegerValue().asInt()); }
@Override public Long deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize ) { return value.asIntegerValue().asLong(); } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof Value)) { return false; } Value v = (Value) o; if (!v.isIntegerValue()) { return false; } IntegerValue iv = v.asIntegerValue(); if (!iv.isInLongRange()) { return false; } return value == iv.toLong(); }
public static MessageFormat mostSuccinctMessageFormat(IntegerValue v) { if (v.isInByteRange()) { return MessageFormat.INT8; } else if (v.isInShortRange()) { return MessageFormat.INT16; } else if (v.isInIntRange()) { return MessageFormat.INT32; } else if (v.isInLongRange()) { return MessageFormat.INT64; } else { return MessageFormat.UINT64; } }
private Object value(Value value) { switch (value.getValueType()) { case NIL: return null; case BOOLEAN: return value.asBooleanValue().getBoolean(); case INTEGER: return value.asIntegerValue().toLong(); case FLOAT: return value.asFloatValue().toFloat(); case STRING: return value.asStringValue().toString(); case BINARY: case ARRAY: case MAP: case EXTENSION: default: throw new UnsupportedOperationException("Unsupported column type: " + value.getValueType()); } } }
@Override public Short deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize ) { return value.asIntegerValue().asShort(); } }
@Override public Byte deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize ) { return value.asIntegerValue().asByte(); } }
private boolean fetchJobResult(int rows, TDJobOperator job) { Optional<ArrayValue> firstRow = pollingRetryExecutor(state, RESULT) .retryUnless(TDOperator::isDeterministicClientException) .withErrorMessage("Failed to download result of job '%s'", job.getJobId()) .withRetryInterval(retryInterval) .run(s -> job.getResult( ite -> ite.hasNext() ? Optional.of(ite.next()) : Optional.absent())); if (!firstRow.isPresent()) { throw new TaskExecutionException("Got unexpected empty result for count job: " + job.getJobId()); } ArrayValue row = firstRow.get(); if (row.size() != 1) { throw new TaskExecutionException("Got unexpected result row size for count job: " + row.size()); } Value count = row.get(0); IntegerValue actualRows; try { actualRows = count.asIntegerValue(); } catch (MessageTypeCastException e) { throw new TaskExecutionException("Got unexpected value type count job: " + count.getValueType()); } return BigInteger.valueOf(rows).compareTo(actualRows.asBigInteger()) <= 0; }
@Override public Integer deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize ) { return value.asIntegerValue().asInt(); } }
private boolean isTruthy(Value firstCol) { // Anything that is not NULL and not FALSE or 0 is considered truthy. switch (firstCol.getValueType()) { case NIL: return false; case BOOLEAN: return firstCol.asBooleanValue().getBoolean(); case INTEGER: return firstCol.asIntegerValue().asLong() != 0; default: return true; } } }
ageEventsSum.addAndGet(val.asIntegerValue().asInt());
@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))); }
@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()); }
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());
@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); }
Map<Value, Value> map = unpacker.unpackValue().asMapValue().map(); assertEquals(2, map.size()); assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt()); String ackResponseToken = map.get(KEY_OPTION_CHUNK).asRawValue().asString(); assertNotNull(ackResponseToken);