@Test public void toOptionalLong() { Collector<Long, ?, OptionalLong> collector = OptionalCollectors.toOptionalLong(); assertThat(Stream.<Long>empty().collect(collector)).isEmpty(); assertThat(Stream.of((Long) null).collect(collector)).isEmpty(); assertThat(Stream.of(1L).collect(collector)).hasValue(1L); assertThatThrownBy( () -> Stream.of(1L, 2L).collect(collector)) .isInstanceOf(IllegalStateException.class) .hasMessage("Multiple values for optional: ['1', '2', ...]"); assertThatThrownBy( () -> Stream.of(1L, null).collect(collector)) .isInstanceOf(IllegalStateException.class) .hasMessage("Multiple values for optional: ['1', null, ...]"); assertThatThrownBy( () -> Stream.of(null, 2L).collect(collector)) .isInstanceOf(IllegalStateException.class) .hasMessage("Multiple values for optional: [null, '2', ...]"); }
private static void assertThatStatisticsAreNotPresent(BasicStatistics statistics) { assertThat(statistics.getNumRows()).isNotPresent(); assertThat(statistics.getNumFiles()).isNotPresent(); assertThat(statistics.getRawDataSize()).isNotPresent(); assertThat(statistics.getTotalSize()).isNotPresent(); }
@Test public void canGetTimestampsFromRangeInTheMiddle() { assertThat(TimestampRanges.getTimestampMatchingModulus(SEVENTY_THREE_TO_EIGHTY_TWO, 7, 10)) .isPresent() .hasValue(77L); assertThat(TimestampRanges.getTimestampMatchingModulus(SEVENTY_THREE_TO_EIGHTY_TWO, 8, 10)) .isPresent() .hasValue(78L); }
@Test public void shouldNotReturnEmptyOptionalWhenBlockNumberNotSpecified() { final GenesisConfigOptions config = fromConfigOptions(emptyMap()); assertThat(config.getHomesteadBlockNumber()).isEmpty(); assertThat(config.getDaoForkBlock()).isEmpty(); assertThat(config.getTangerineWhistleBlockNumber()).isEmpty(); assertThat(config.getSpuriousDragonBlockNumber()).isEmpty(); assertThat(config.getByzantiumBlockNumber()).isEmpty(); assertThat(config.getConstantinopleBlockNumber()).isEmpty(); assertThat(config.getConstantinopleFixBlockNumber()).isEmpty(); }
@Test public void shouldGetConstantinopleBlockNumber() { final GenesisConfigOptions config = fromConfigOptions(singletonMap("constantinopleBlock", 1000)); assertThat(config.getConstantinopleBlockNumber()).hasValue(1000); }
@Test public void canHandleMultipleValidMatches() { assertThat(TimestampRanges.getTimestampMatchingModulus(SEVENTY_THREE_TO_EIGHTY_TWO, 1, 2)) .isPresent() .satisfies(optionalLong -> { long value = optionalLong.getAsLong(); assertThat(value).isIn(73L, 75L, 77L, 79L, 81L); }); assertThat(TimestampRanges.getTimestampMatchingModulus(SEVENTY_THREE_TO_EIGHTY_TWO, 0, 2)) .isPresent() .satisfies(optionalLong -> { long value = optionalLong.getAsLong(); assertThat(value).isIn(74L, 76L, 78L, 80L, 82L); }); }
private void assertMaximumNonceForSender(final Address sender1, final int i) { assertThat(transactions.getNextNonceForSender(sender1)).isEqualTo(OptionalLong.of(i)); }
/** * Create assertion for {@link java.util.OptionalInt}. * * @param actual the actual value. * * @return the created assertion object. */ public static OptionalLongAssert assertThat(OptionalLong actual) { return new OptionalLongAssert(actual); }
@Test public void canHandleNegativeResidues() { assertThat(TimestampRanges.getTimestampMatchingModulus(SEVENTY_THREE_TO_EIGHTY_TWO, -7, 10)) .isPresent() .hasValue(SEVENTY_THREE); assertThat(TimestampRanges.getTimestampMatchingModulus(SEVENTY_THREE_TO_EIGHTY_TWO, -5, 10)) .isPresent() .hasValue(75); }
@Test public void shouldReturnEmptyOptionalAsMaximumNonceWhenNoTransactionsPresent() { assertThat(transactions.getNextNonceForSender(SENDER1)).isEmpty(); }
@Test public void shouldGetDaoForkBlockNumber() { final GenesisConfigOptions config = fromConfigOptions(singletonMap("daoForkBlock", 1000)); assertThat(config.getDaoForkBlock()).hasValue(1000); }
@Test public void capture_jackson_optional_handling_behaviour() throws IOException { assertThat(mapper.readValue("null", com.google.common.base.Optional.class)) .isEqualTo(com.google.common.base.Optional.absent()); assertThat(mapper.readValue("null", OptionalInt.class)).isEqualTo(OptionalInt.empty()); assertThat(mapper.readValue("null", OptionalDouble.class)).isEqualTo(OptionalDouble.empty()); assertThat(mapper.readValue("null", OptionalLong.class)).isEqualTo(OptionalLong.empty()); }
/** * Create assertion for {@link java.util.OptionalInt}. * * @param actual the actual value. * * @return the created assertion object. */ @CheckReturnValue public static OptionalLongAssert assertThat(OptionalLong actual) { return new OptionalLongAssert(actual); }
@Test public void testBindOptionalLong() { assertThat(handle.createQuery("SELECT :value") .bind("value", OptionalLong.empty()) .collectInto(OptionalLong.class)) .isEmpty(); assertThat(handle.createQuery("SELECT :value") .bind("value", OptionalLong.of(123)) .collectInto(OptionalLong.class)) .hasValue(123); }
private void doInsertIntoExistingPartitionEmptyStatistics(HiveStorageFormat storageFormat, SchemaTableName tableName) throws Exception { doCreateEmptyTable(tableName, storageFormat, CREATE_TABLE_COLUMNS_PARTITIONED); insertData(tableName, CREATE_TABLE_PARTITIONED_DATA); eraseStatistics(tableName); insertData(tableName, CREATE_TABLE_PARTITIONED_DATA); try (Transaction transaction = newTransaction()) { List<String> partitionNames = transaction.getMetastore(tableName.getSchemaName()).getPartitionNames(tableName.getSchemaName(), tableName.getTableName()) .orElseThrow(() -> new AssertionError("Table does not exist: " + tableName)); for (String partitionName : partitionNames) { HiveBasicStatistics statistics = getBasicStatisticsForPartition(transaction, tableName, partitionName); assertThat(statistics.getRowCount()).isNotPresent(); assertThat(statistics.getInMemoryDataSizeInBytes()).isNotPresent(); // fileCount and rawSize statistics are computed on the fly by the metastore, thus cannot be erased } } }
@Test public void shouldSupportEmptyGenesisConfig() { final GenesisConfigOptions config = GenesisConfigFile.fromConfig("{}").getConfigOptions(); assertThat(config.isEthHash()).isFalse(); assertThat(config.isIbft()).isFalse(); assertThat(config.isClique()).isFalse(); assertThat(config.getHomesteadBlockNumber()).isEmpty(); }
@Test public void shouldGetByzantiumBlockNumber() { final GenesisConfigOptions config = fromConfigOptions(singletonMap("byzantiumBlock", 1000)); assertThat(config.getByzantiumBlockNumber()).hasValue(1000); }
@Test public void testMapToOptionalLong() { assertThat(handle.select("select id from something where name = 'ford'") .collectInto(OptionalLong.class)) .isEmpty(); assertThat(handle.select("select null from something where name = 'eric'") .collectInto(OptionalLong.class)) .isEmpty(); assertThat(handle.select("select id from something where name = 'eric'") .collectInto(OptionalLong.class)) .hasValue(1L); assertThatThrownBy(() -> handle.select("select id from something") .collectInto(OptionalLong.class)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Multiple values for optional"); }