From fb6eaac66eb4cbbc5ce9da54d3f5b9ce41d07afd Mon Sep 17 00:00:00 2001 From: Zac Blanco Date: Fri, 8 Nov 2024 12:05:43 -0800 Subject: [PATCH 1/3] Copy units source --- units/README.md | 5 + units/pom.xml | 88 ++++ .../main/java/io/airlift/units/DataSize.java | 208 +++++++++ .../main/java/io/airlift/units/Duration.java | 256 +++++++++++ .../java/io/airlift/units/MaxDataSize.java | 44 ++ .../airlift/units/MaxDataSizeValidator.java | 41 ++ .../java/io/airlift/units/MaxDuration.java | 46 ++ .../airlift/units/MaxDurationValidator.java | 43 ++ .../java/io/airlift/units/MinDataSize.java | 44 ++ .../airlift/units/MinDataSizeValidator.java | 41 ++ .../java/io/airlift/units/MinDuration.java | 46 ++ .../airlift/units/MinDurationValidator.java | 43 ++ .../java/io/airlift/units/Preconditions.java | 83 ++++ .../resources/ValidationMessages.properties | 4 + .../units/ConstraintValidatorAssert.java | 86 ++++ .../io/airlift/units/MockMaxDataSize.java | 62 +++ .../io/airlift/units/MockMaxDuration.java | 62 +++ .../io/airlift/units/MockMinDataSize.java | 62 +++ .../io/airlift/units/MockMinDuration.java | 62 +++ .../java/io/airlift/units/TestDataSize.java | 364 ++++++++++++++++ .../airlift/units/TestDataSizeValidator.java | 317 ++++++++++++++ .../java/io/airlift/units/TestDuration.java | 403 ++++++++++++++++++ .../airlift/units/TestDurationValidator.java | 309 ++++++++++++++ 23 files changed, 2719 insertions(+) create mode 100644 units/README.md create mode 100644 units/pom.xml create mode 100644 units/src/main/java/io/airlift/units/DataSize.java create mode 100644 units/src/main/java/io/airlift/units/Duration.java create mode 100644 units/src/main/java/io/airlift/units/MaxDataSize.java create mode 100644 units/src/main/java/io/airlift/units/MaxDataSizeValidator.java create mode 100644 units/src/main/java/io/airlift/units/MaxDuration.java create mode 100644 units/src/main/java/io/airlift/units/MaxDurationValidator.java create mode 100644 units/src/main/java/io/airlift/units/MinDataSize.java create mode 100644 units/src/main/java/io/airlift/units/MinDataSizeValidator.java create mode 100644 units/src/main/java/io/airlift/units/MinDuration.java create mode 100644 units/src/main/java/io/airlift/units/MinDurationValidator.java create mode 100644 units/src/main/java/io/airlift/units/Preconditions.java create mode 100644 units/src/main/resources/ValidationMessages.properties create mode 100644 units/src/test/java/io/airlift/units/ConstraintValidatorAssert.java create mode 100644 units/src/test/java/io/airlift/units/MockMaxDataSize.java create mode 100644 units/src/test/java/io/airlift/units/MockMaxDuration.java create mode 100644 units/src/test/java/io/airlift/units/MockMinDataSize.java create mode 100644 units/src/test/java/io/airlift/units/MockMinDuration.java create mode 100644 units/src/test/java/io/airlift/units/TestDataSize.java create mode 100644 units/src/test/java/io/airlift/units/TestDataSizeValidator.java create mode 100644 units/src/test/java/io/airlift/units/TestDuration.java create mode 100644 units/src/test/java/io/airlift/units/TestDurationValidator.java diff --git a/units/README.md b/units/README.md new file mode 100644 index 0000000000..2eb03017ce --- /dev/null +++ b/units/README.md @@ -0,0 +1,5 @@ +# Units +[![Maven Central](https://img.shields.io/maven-central/v/io.airlift/units.svg?label=Maven%20Central)](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.airlift%22%20AND%20a%3A%22units%22) +[![Build Status](https://travis-ci.org/airlift/units.svg?branch=master)](https://travis-ci.org/airlift/units) + +Units is a Java library for immutable, human-friendly units. diff --git a/units/pom.xml b/units/pom.xml new file mode 100644 index 0000000000..fa4537b28a --- /dev/null +++ b/units/pom.xml @@ -0,0 +1,88 @@ + + + 4.0.0 + units + 1.4-SNAPSHOT + jar + + units + Library for immutable human-friendly units + https://github.com/airlift/units + + + io.airlift + airbase + 91 + + + 2016 + + + true + + + + Airlift + + + + + Apache License 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + repo + + + + + + javax.validation + validation-api + true + + + + com.fasterxml.jackson.core + jackson-annotations + true + + + + + org.testng + testng + test + + + + org.assertj + assertj-core + test + + + + com.google.guava + guava + test + + + + io.airlift + testing + 0.134 + test + + + + io.airlift + json + 0.134 + test + + + + org.apache.bval + bval-jsr + test + + + diff --git a/units/src/main/java/io/airlift/units/DataSize.java b/units/src/main/java/io/airlift/units/DataSize.java new file mode 100644 index 0000000000..e34476af8e --- /dev/null +++ b/units/src/main/java/io/airlift/units/DataSize.java @@ -0,0 +1,208 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static io.airlift.units.Preconditions.checkArgument; +import static io.airlift.units.Preconditions.checkState; +import static java.lang.Math.floor; +import static java.util.Objects.requireNonNull; + +public class DataSize + implements Comparable +{ + private static final Pattern PATTERN = Pattern.compile("^\\s*(\\d+(?:\\.\\d+)?)\\s*([a-zA-Z]+)\\s*$"); + + // We iterate over the DATASIZE_UNITS constant in convertToMostSuccinctDataSize() + // instead of Unit.values() as the latter results in non-trivial amount of memory + // allocation when that method is called in a tight loop. The reason is that the values() + // call allocates a new array at each call. + private static final Unit[] DATASIZE_UNITS = Unit.values(); + + public static DataSize succinctBytes(long bytes) + { + return succinctDataSize(bytes, Unit.BYTE); + } + + public static DataSize succinctDataSize(double size, Unit unit) + { + return new DataSize(size, unit).convertToMostSuccinctDataSize(); + } + + private final double value; + private final Unit unit; + + public DataSize(double size, Unit unit) + { + checkArgument(!Double.isInfinite(size), "size is infinite"); + checkArgument(!Double.isNaN(size), "size is not a number"); + checkArgument(size >= 0, "size is negative"); + requireNonNull(unit, "unit is null"); + + this.value = size; + this.unit = unit; + } + + public long toBytes() + { + double bytes = getValue(Unit.BYTE); + checkState(bytes <= Long.MAX_VALUE, "size is too large to be represented in bytes as a long"); + return (long) bytes; + } + + public double getValue() + { + return value; + } + + public Unit getUnit() + { + return unit; + } + + public double getValue(Unit unit) + { + return value * (this.unit.getFactor() * 1.0 / unit.getFactor()); + } + + public long roundTo(Unit unit) + { + double rounded = Math.floor(getValue(unit) + 0.5d); + checkArgument(rounded <= Long.MAX_VALUE, + "size is too large to be represented in requested unit as a long"); + return (long) rounded; + } + + public DataSize convertTo(Unit unit) + { + requireNonNull(unit, "unit is null"); + return new DataSize(getValue(unit), unit); + } + + public DataSize convertToMostSuccinctDataSize() + { + Unit unitToUse = Unit.BYTE; + for (Unit unitToTest : DATASIZE_UNITS) { + if (getValue(unitToTest) >= 1.0) { + unitToUse = unitToTest; + } + else { + break; + } + } + return convertTo(unitToUse); + } + + @JsonValue + @Override + public String toString() + { + //noinspection FloatingPointEquality + if (floor(value) == value) { + return (long) (floor(value)) + unit.getUnitString(); + } + + return String.format(Locale.ENGLISH, "%.2f%s", value, unit.getUnitString()); + } + + @JsonCreator + public static DataSize valueOf(String size) + throws IllegalArgumentException + { + requireNonNull(size, "size is null"); + checkArgument(!size.isEmpty(), "size is empty"); + + Matcher matcher = PATTERN.matcher(size); + if (!matcher.matches()) { + throw new IllegalArgumentException("size is not a valid data size string: " + size); + } + + double value = Double.parseDouble(matcher.group(1)); + String unitString = matcher.group(2); + + for (Unit unit : Unit.values()) { + if (unit.getUnitString().equals(unitString)) { + return new DataSize(value, unit); + } + } + + throw new IllegalArgumentException("Unknown unit: " + unitString); + } + + @Override + public int compareTo(DataSize o) + { + return Double.compare(getValue(Unit.BYTE), o.getValue(Unit.BYTE)); + } + + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + DataSize dataSize = (DataSize) o; + + return compareTo(dataSize) == 0; + } + + @Override + public int hashCode() + { + double value = getValue(Unit.BYTE); + return Double.hashCode(value); + } + + public enum Unit + { + //This order is important, it should be in increasing magnitude. + BYTE(1L, "B"), + KILOBYTE(1L << 10, "kB"), + MEGABYTE(1L << 20, "MB"), + GIGABYTE(1L << 30, "GB"), + TERABYTE(1L << 40, "TB"), + PETABYTE(1L << 50, "PB"); + + private final long factor; + private final String unitString; + + Unit(long factor, String unitString) + { + this.factor = factor; + this.unitString = unitString; + } + + long getFactor() + { + return factor; + } + + public String getUnitString() + { + return unitString; + } + } +} diff --git a/units/src/main/java/io/airlift/units/Duration.java b/units/src/main/java/io/airlift/units/Duration.java new file mode 100644 index 0000000000..8d1f61719c --- /dev/null +++ b/units/src/main/java/io/airlift/units/Duration.java @@ -0,0 +1,256 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import java.util.Locale; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static io.airlift.units.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; +import static java.util.concurrent.TimeUnit.DAYS; +import static java.util.concurrent.TimeUnit.HOURS; +import static java.util.concurrent.TimeUnit.MICROSECONDS; +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.MINUTES; +import static java.util.concurrent.TimeUnit.NANOSECONDS; +import static java.util.concurrent.TimeUnit.SECONDS; + +public final class Duration + implements Comparable +{ + private static final Pattern PATTERN = Pattern.compile("^\\s*(\\d+(?:\\.\\d+)?)\\s*([a-zA-Z]+)\\s*$"); + + // We iterate over the TIME_UNITS constant in convertToMostSuccinctTimeUnit() + // instead of TimeUnit.values() as the latter results in non-trivial amount of memory + // allocation when that method is called in a tight loop. The reason is that the values() + // call allocates a new array at each call. + private static final TimeUnit[] TIME_UNITS = TimeUnit.values(); + + public static Duration nanosSince(long start) + { + return succinctNanos(System.nanoTime() - start); + } + + public static Duration succinctNanos(long nanos) + { + return succinctDuration(nanos, NANOSECONDS); + } + + public static Duration succinctDuration(double value, TimeUnit unit) + { + return new Duration(value, unit).convertToMostSuccinctTimeUnit(); + } + + private final double value; + private final TimeUnit unit; + + public Duration(double value, TimeUnit unit) + { + checkArgument(!Double.isInfinite(value), "value is infinite"); + checkArgument(!Double.isNaN(value), "value is not a number"); + checkArgument(value >= 0, "value is negative"); + requireNonNull(unit, "unit is null"); + + this.value = value; + this.unit = unit; + } + + public long toMillis() + { + return roundTo(MILLISECONDS); + } + + public double getValue() + { + return value; + } + + public TimeUnit getUnit() + { + return unit; + } + + public double getValue(TimeUnit timeUnit) + { + requireNonNull(timeUnit, "timeUnit is null"); + return value * (millisPerTimeUnit(this.unit) * 1.0 / millisPerTimeUnit(timeUnit)); + } + + public long roundTo(TimeUnit timeUnit) + { + requireNonNull(timeUnit, "timeUnit is null"); + double rounded = Math.floor(getValue(timeUnit) + 0.5d); + checkArgument(rounded <= Long.MAX_VALUE, + "size is too large to be represented in requested unit as a long"); + return (long) rounded; + } + + public Duration convertTo(TimeUnit timeUnit) + { + requireNonNull(timeUnit, "timeUnit is null"); + return new Duration(getValue(timeUnit), timeUnit); + } + + public Duration convertToMostSuccinctTimeUnit() + { + TimeUnit unitToUse = NANOSECONDS; + for (TimeUnit unitToTest : TIME_UNITS) { + // since time units are powers of ten, we can get rounding errors here, so fuzzy match + if (getValue(unitToTest) > 0.9999) { + unitToUse = unitToTest; + } + else { + break; + } + } + return convertTo(unitToUse); + } + + @JsonValue + @Override + public String toString() + { + return toString(unit); + } + + public String toString(TimeUnit timeUnit) + { + requireNonNull(timeUnit, "timeUnit is null"); + double magnitude = getValue(timeUnit); + String timeUnitAbbreviation = timeUnitToString(timeUnit); + return String.format(Locale.ENGLISH, "%.2f%s", magnitude, timeUnitAbbreviation); + } + + @JsonCreator + public static Duration valueOf(String duration) + throws IllegalArgumentException + { + requireNonNull(duration, "duration is null"); + checkArgument(!duration.isEmpty(), "duration is empty"); + + Matcher matcher = PATTERN.matcher(duration); + if (!matcher.matches()) { + throw new IllegalArgumentException("duration is not a valid data duration string: " + duration); + } + + double value = Double.parseDouble(matcher.group(1)); + String unitString = matcher.group(2); + + TimeUnit timeUnit = valueOfTimeUnit(unitString); + return new Duration(value, timeUnit); + } + + @Override + public int compareTo(Duration o) + { + return Double.compare(getValue(MILLISECONDS), o.getValue(MILLISECONDS)); + } + + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + Duration duration = (Duration) o; + + return compareTo(duration) == 0; + } + + @Override + public int hashCode() + { + double value = getValue(MILLISECONDS); + return Double.hashCode(value); + } + + public static TimeUnit valueOfTimeUnit(String timeUnitString) + { + requireNonNull(timeUnitString, "timeUnitString is null"); + switch (timeUnitString) { + case "ns": + return NANOSECONDS; + case "us": + return MICROSECONDS; + case "ms": + return MILLISECONDS; + case "s": + return SECONDS; + case "m": + return MINUTES; + case "h": + return HOURS; + case "d": + return DAYS; + default: + throw new IllegalArgumentException("Unknown time unit: " + timeUnitString); + } + } + + public static String timeUnitToString(TimeUnit timeUnit) + { + requireNonNull(timeUnit, "timeUnit is null"); + switch (timeUnit) { + case NANOSECONDS: + return "ns"; + case MICROSECONDS: + return "us"; + case MILLISECONDS: + return "ms"; + case SECONDS: + return "s"; + case MINUTES: + return "m"; + case HOURS: + return "h"; + case DAYS: + return "d"; + default: + throw new IllegalArgumentException("Unsupported time unit " + timeUnit); + } + } + + private static double millisPerTimeUnit(TimeUnit timeUnit) + { + switch (timeUnit) { + case NANOSECONDS: + return 1.0 / 1000000.0; + case MICROSECONDS: + return 1.0 / 1000.0; + case MILLISECONDS: + return 1; + case SECONDS: + return 1000; + case MINUTES: + return 1000 * 60; + case HOURS: + return 1000 * 60 * 60; + case DAYS: + return 1000 * 60 * 60 * 24; + default: + throw new IllegalArgumentException("Unsupported time unit " + timeUnit); + } + } +} diff --git a/units/src/main/java/io/airlift/units/MaxDataSize.java b/units/src/main/java/io/airlift/units/MaxDataSize.java new file mode 100644 index 0000000000..a39745aba6 --- /dev/null +++ b/units/src/main/java/io/airlift/units/MaxDataSize.java @@ -0,0 +1,44 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.Constraint; +import javax.validation.Payload; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Retention(RUNTIME) +@Documented +@Constraint(validatedBy = MaxDataSizeValidator.class) +public @interface MaxDataSize +{ + String value(); + + String message() default "{io.airlift.units.MaxDataSize.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/units/src/main/java/io/airlift/units/MaxDataSizeValidator.java b/units/src/main/java/io/airlift/units/MaxDataSizeValidator.java new file mode 100644 index 0000000000..e71b9a7b14 --- /dev/null +++ b/units/src/main/java/io/airlift/units/MaxDataSizeValidator.java @@ -0,0 +1,41 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxDataSizeValidator + implements ConstraintValidator +{ + private DataSize max; + + @Override + public void initialize(MaxDataSize dataSize) + { + this.max = DataSize.valueOf(dataSize.value()); + } + + @Override + public boolean isValid(DataSize dataSize, ConstraintValidatorContext context) + { + return (dataSize == null) || (dataSize.compareTo(max) <= 0); + } + + @Override + public String toString() + { + return "max:" + max; + } +} diff --git a/units/src/main/java/io/airlift/units/MaxDuration.java b/units/src/main/java/io/airlift/units/MaxDuration.java new file mode 100644 index 0000000000..223aa3d169 --- /dev/null +++ b/units/src/main/java/io/airlift/units/MaxDuration.java @@ -0,0 +1,46 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.Constraint; +import javax.validation.Payload; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Retention(RUNTIME) +@Documented +@Constraint(validatedBy = MaxDurationValidator.class) +public @interface MaxDuration +{ + String value(); + + String message() default "{io.airlift.units.MaxDuration.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/units/src/main/java/io/airlift/units/MaxDurationValidator.java b/units/src/main/java/io/airlift/units/MaxDurationValidator.java new file mode 100644 index 0000000000..f27b9641b7 --- /dev/null +++ b/units/src/main/java/io/airlift/units/MaxDurationValidator.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MaxDurationValidator + implements ConstraintValidator +{ + private Duration max; + + @Override + public void initialize(MaxDuration duration) + { + this.max = Duration.valueOf(duration.value()); + } + + @Override + public boolean isValid(Duration duration, ConstraintValidatorContext context) + { + return duration == null || duration.compareTo(max) <= 0; + } + + @Override + public String toString() + { + return "max:" + max; + } +} diff --git a/units/src/main/java/io/airlift/units/MinDataSize.java b/units/src/main/java/io/airlift/units/MinDataSize.java new file mode 100644 index 0000000000..6f9c5cad66 --- /dev/null +++ b/units/src/main/java/io/airlift/units/MinDataSize.java @@ -0,0 +1,44 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.Constraint; +import javax.validation.Payload; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Retention(RUNTIME) +@Documented +@Constraint(validatedBy = MinDataSizeValidator.class) +public @interface MinDataSize +{ + String value(); + + String message() default "{io.airlift.units.MinDataSize.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/units/src/main/java/io/airlift/units/MinDataSizeValidator.java b/units/src/main/java/io/airlift/units/MinDataSizeValidator.java new file mode 100644 index 0000000000..7251939d10 --- /dev/null +++ b/units/src/main/java/io/airlift/units/MinDataSizeValidator.java @@ -0,0 +1,41 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinDataSizeValidator + implements ConstraintValidator +{ + private DataSize min; + + @Override + public void initialize(MinDataSize dataSize) + { + this.min = DataSize.valueOf(dataSize.value()); + } + + @Override + public boolean isValid(DataSize dataSize, ConstraintValidatorContext context) + { + return (dataSize == null) || (dataSize.compareTo(min) >= 0); + } + + @Override + public String toString() + { + return "min:" + min; + } +} diff --git a/units/src/main/java/io/airlift/units/MinDuration.java b/units/src/main/java/io/airlift/units/MinDuration.java new file mode 100644 index 0000000000..a080d08a71 --- /dev/null +++ b/units/src/main/java/io/airlift/units/MinDuration.java @@ -0,0 +1,46 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.Constraint; +import javax.validation.Payload; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Retention(RUNTIME) +@Documented +@Constraint(validatedBy = MinDurationValidator.class) +public @interface MinDuration +{ + String value(); + + String message() default "{io.airlift.units.MinDuration.message}"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/units/src/main/java/io/airlift/units/MinDurationValidator.java b/units/src/main/java/io/airlift/units/MinDurationValidator.java new file mode 100644 index 0000000000..28cb3dd109 --- /dev/null +++ b/units/src/main/java/io/airlift/units/MinDurationValidator.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class MinDurationValidator + implements ConstraintValidator +{ + private Duration min; + + @Override + public void initialize(MinDuration duration) + { + this.min = Duration.valueOf(duration.value()); + } + + @Override + public boolean isValid(Duration duration, ConstraintValidatorContext context) + { + return duration == null || duration.compareTo(min) >= 0; + } + + @Override + public String toString() + { + return "min:" + min; + } +} diff --git a/units/src/main/java/io/airlift/units/Preconditions.java b/units/src/main/java/io/airlift/units/Preconditions.java new file mode 100644 index 0000000000..9f111c7b03 --- /dev/null +++ b/units/src/main/java/io/airlift/units/Preconditions.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2007 The Guava Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +// forked from com.google.common.base.Preconditions +final class Preconditions +{ + private Preconditions() { } + + static void checkArgument(boolean expression, String errorMessage) + { + if (!expression) { + throw new IllegalArgumentException(errorMessage); + } + } + + static void checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) + { + if (!expression) { + throw new IllegalArgumentException(format(errorMessageTemplate, errorMessageArgs)); + } + } + + static void checkState(boolean expression, String errorMessage) + { + if (!expression) { + throw new IllegalStateException(errorMessage); + } + } + + static void checkState(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) + { + if (!expression) { + throw new IllegalStateException(format(errorMessageTemplate, errorMessageArgs)); + } + } + + private static String format(String template, Object... args) + { + template = String.valueOf(template); // null -> "null" + + // start substituting the arguments into the '%s' placeholders + StringBuilder builder = new StringBuilder(template.length() + 16 * args.length); + int templateStart = 0; + int i = 0; + while (i < args.length) { + int placeholderStart = template.indexOf("%s", templateStart); + if (placeholderStart == -1) { + break; + } + builder.append(template.substring(templateStart, placeholderStart)); + builder.append(args[i++]); + templateStart = placeholderStart + 2; + } + builder.append(template.substring(templateStart)); + + // if we run out of placeholders, append the extra args in square braces + if (i < args.length) { + builder.append(" ["); + builder.append(args[i++]); + while (i < args.length) { + builder.append(", "); + builder.append(args[i++]); + } + builder.append(']'); + } + + return builder.toString(); + } +} diff --git a/units/src/main/resources/ValidationMessages.properties b/units/src/main/resources/ValidationMessages.properties new file mode 100644 index 0000000000..00195c64c8 --- /dev/null +++ b/units/src/main/resources/ValidationMessages.properties @@ -0,0 +1,4 @@ +io.airlift.units.MinDuration.message=must be greater than or equal to {value} +io.airlift.units.MaxDuration.message=must be less than or equal to {value} +io.airlift.units.MinDataSize.message=must be greater than or equal to {value} +io.airlift.units.MaxDataSize.message=must be less than or equal to {value} diff --git a/units/src/test/java/io/airlift/units/ConstraintValidatorAssert.java b/units/src/test/java/io/airlift/units/ConstraintValidatorAssert.java new file mode 100644 index 0000000000..9625a89129 --- /dev/null +++ b/units/src/test/java/io/airlift/units/ConstraintValidatorAssert.java @@ -0,0 +1,86 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import org.assertj.core.api.AbstractAssert; + +import javax.validation.ClockProvider; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import java.lang.annotation.Annotation; + +final class ConstraintValidatorAssert + extends AbstractAssert, ConstraintValidator> +{ + public ConstraintValidatorAssert(ConstraintValidator actual) + { + super(actual, ConstraintValidatorAssert.class); + } + + public static ConstraintValidatorAssert assertThat(ConstraintValidator actual) + { + return new ConstraintValidatorAssert<>(actual); + } + + public void isValidFor(T value) + { + isNotNull(); + if (!actual.isValid(value, new MockContext())) { + failWithMessage("Expected <%s> to be valid for <%s>", actual, value); + } + } + + public void isInvalidFor(T value) + { + isNotNull(); + if (actual.isValid(value, new MockContext())) { + failWithMessage("Expected <%s> to be invalid for <%s>", actual, value); + } + } + + private static class MockContext + implements ConstraintValidatorContext + { + @Override + public void disableDefaultConstraintViolation() + { + throw new UnsupportedOperationException(); + } + + @Override + public String getDefaultConstraintMessageTemplate() + { + throw new UnsupportedOperationException(); + } + + @Override + public ClockProvider getClockProvider() + { + throw new UnsupportedOperationException(); + } + + @Override + public ConstraintViolationBuilder buildConstraintViolationWithTemplate(String s) + { + throw new UnsupportedOperationException(); + } + + @Override + public T unwrap(Class type) + { + throw new UnsupportedOperationException(); + } + } +} diff --git a/units/src/test/java/io/airlift/units/MockMaxDataSize.java b/units/src/test/java/io/airlift/units/MockMaxDataSize.java new file mode 100644 index 0000000000..07c565161f --- /dev/null +++ b/units/src/test/java/io/airlift/units/MockMaxDataSize.java @@ -0,0 +1,62 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.Payload; + +import java.lang.annotation.Annotation; + +import static java.util.Objects.requireNonNull; + +@SuppressWarnings("ClassExplicitlyAnnotation") +class MockMaxDataSize + implements MaxDataSize +{ + private final DataSize dataSize; + + public MockMaxDataSize(DataSize dataSize) + { + this.dataSize = requireNonNull(dataSize, "dataSize is null"); + } + + @Override + public String value() + { + return dataSize.toString(); + } + + @Override + public String message() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class[] groups() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class[] payload() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class annotationType() + { + return MaxDuration.class; + } +} diff --git a/units/src/test/java/io/airlift/units/MockMaxDuration.java b/units/src/test/java/io/airlift/units/MockMaxDuration.java new file mode 100644 index 0000000000..bba5dc2aa2 --- /dev/null +++ b/units/src/test/java/io/airlift/units/MockMaxDuration.java @@ -0,0 +1,62 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.Payload; + +import java.lang.annotation.Annotation; + +@SuppressWarnings("ClassExplicitlyAnnotation") +class MockMaxDuration + implements MaxDuration +{ + private final Duration duration; + + public MockMaxDuration(Duration duration) + { + this.duration = duration; + } + + @Override + public String value() + { + return duration.toString(); + } + + @Override + public String message() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class[] groups() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class[] payload() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class annotationType() + { + return MaxDuration.class; + } +} diff --git a/units/src/test/java/io/airlift/units/MockMinDataSize.java b/units/src/test/java/io/airlift/units/MockMinDataSize.java new file mode 100644 index 0000000000..591a6c903f --- /dev/null +++ b/units/src/test/java/io/airlift/units/MockMinDataSize.java @@ -0,0 +1,62 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.Payload; + +import java.lang.annotation.Annotation; + +import static java.util.Objects.requireNonNull; + +@SuppressWarnings("ClassExplicitlyAnnotation") +class MockMinDataSize + implements MinDataSize +{ + private final DataSize dataSize; + + public MockMinDataSize(DataSize dataSize) + { + this.dataSize = requireNonNull(dataSize, "dataSize is null"); + } + + @Override + public String value() + { + return dataSize.toString(); + } + + @Override + public String message() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class[] groups() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class[] payload() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class annotationType() + { + return MinDataSize.class; + } +} diff --git a/units/src/test/java/io/airlift/units/MockMinDuration.java b/units/src/test/java/io/airlift/units/MockMinDuration.java new file mode 100644 index 0000000000..a20e682238 --- /dev/null +++ b/units/src/test/java/io/airlift/units/MockMinDuration.java @@ -0,0 +1,62 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import javax.validation.Payload; + +import java.lang.annotation.Annotation; + +@SuppressWarnings("ClassExplicitlyAnnotation") +class MockMinDuration + implements MinDuration +{ + private final Duration duration; + + public MockMinDuration(Duration duration) + { + this.duration = duration; + } + + @Override + public String value() + { + return duration.toString(); + } + + @Override + public String message() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class[] groups() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class[] payload() + { + throw new UnsupportedOperationException(); + } + + @Override + public Class annotationType() + { + return MinDuration.class; + } +} diff --git a/units/src/test/java/io/airlift/units/TestDataSize.java b/units/src/test/java/io/airlift/units/TestDataSize.java new file mode 100644 index 0000000000..53b994a158 --- /dev/null +++ b/units/src/test/java/io/airlift/units/TestDataSize.java @@ -0,0 +1,364 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import com.google.common.collect.ImmutableList; +import io.airlift.json.JsonCodec; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.Locale; + +import static io.airlift.testing.EquivalenceTester.comparisonTester; +import static io.airlift.units.DataSize.Unit.BYTE; +import static io.airlift.units.DataSize.Unit.GIGABYTE; +import static io.airlift.units.DataSize.Unit.KILOBYTE; +import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static io.airlift.units.DataSize.Unit.PETABYTE; +import static io.airlift.units.DataSize.Unit.TERABYTE; +import static io.airlift.units.DataSize.succinctBytes; +import static io.airlift.units.DataSize.succinctDataSize; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; +import static org.assertj.core.data.Percentage.withPercentage; +import static org.testng.Assert.assertEquals; + +public class TestDataSize +{ + @Test + public void testSuccinctFactories() + { + assertEquals(succinctBytes(123), new DataSize(123, BYTE)); + assertEquals(succinctBytes((long) (5.5 * 1024)), new DataSize(5.5, KILOBYTE)); + assertEquals(succinctBytes(5 * 1024 * 1024), new DataSize(5, MEGABYTE)); + + assertEquals(succinctDataSize(123, BYTE), new DataSize(123, BYTE)); + assertEquals(succinctDataSize((long) (5.5 * 1024), BYTE), new DataSize(5.5, KILOBYTE)); + assertEquals(succinctDataSize(5 * 1024, KILOBYTE), new DataSize(5, MEGABYTE)); + } + + @Test(dataProvider = "conversions") + public void testConversions(DataSize.Unit unit, DataSize.Unit toUnit, double factor) + { + DataSize size = new DataSize(1, unit).convertTo(toUnit); + assertEquals(size.getUnit(), toUnit); + assertEquals(size.getValue(), factor); + + assertEquals(size.getValue(toUnit), factor); + } + + @Test(dataProvider = "conversions") + public void testConvertToMostSuccinctDataSize(DataSize.Unit unit, DataSize.Unit toUnit, double factor) + { + DataSize size = new DataSize(factor, toUnit); + DataSize actual = size.convertToMostSuccinctDataSize(); + assertThat(actual).isEqualTo(new DataSize(1, unit)); + assertThat(actual.getValue(unit)).isCloseTo(1.0, offset(0.001)); + assertThat(actual.getUnit()).isEqualTo(unit); + } + + @Test + public void testEquivalence() + { + comparisonTester() + .addLesserGroup(group(0)) + .addGreaterGroup(group(1)) + .addGreaterGroup(group(123352)) + .addGreaterGroup(group(Long.MAX_VALUE)) + .check(); + } + + private static Iterable group(double bytes) + { + return ImmutableList.of( + new DataSize(bytes, BYTE), + new DataSize(bytes / 1024, KILOBYTE), + new DataSize(bytes / 1024 / 1024, MEGABYTE), + new DataSize(bytes / 1024 / 1024 / 1024, GIGABYTE), + new DataSize(bytes / 1024 / 1024 / 1024 / 1024, TERABYTE), + new DataSize(bytes / 1024 / 1024 / 1024 / 1024 / 1024, PETABYTE) + ); + } + + @Test(dataProvider = "printedValues") + public void testToString(String expectedString, double value, DataSize.Unit unit) + { + assertEquals(new DataSize(value, unit).toString(), expectedString); + } + + @Test(dataProvider = "printedValues") + public void testNonEnglishLocale(String expectedString, double value, DataSize.Unit unit) + { + synchronized (Locale.class) { + Locale previous = Locale.getDefault(); + Locale.setDefault(Locale.GERMAN); + try { + assertEquals(new DataSize(value, unit).toString(), expectedString); + } + finally { + Locale.setDefault(previous); + } + } + } + + @Test(dataProvider = "parseableValues") + public void testValueOf(String string, double expectedValue, DataSize.Unit expectedUnit) + { + DataSize size = DataSize.valueOf(string); + + assertEquals(size.getUnit(), expectedUnit); + assertEquals(size.getValue(), expectedValue); + } + + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "size is null") + public void testValueOfRejectsNull() + { + DataSize.valueOf(null); + } + + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is empty") + public void testValueOfRejectsEmptyString() + { + DataSize.valueOf(""); + } + + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Unknown unit: kg") + public void testValueOfRejectsInvalidUnit() + { + DataSize.valueOf("1.234 kg"); + } + + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is not a valid.*") + public void testValueOfRejectsInvalidNumber() + { + DataSize.valueOf("1.2x4 B"); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is negative") + public void testConstructorRejectsNegativeSize() + { + new DataSize(-1, BYTE); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is infinite") + public void testConstructorRejectsInfiniteSize() + { + new DataSize(Double.POSITIVE_INFINITY, BYTE); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is infinite") + public void testConstructorRejectsInfiniteSize2() + { + new DataSize(Double.NEGATIVE_INFINITY, BYTE); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is not a number") + public void testConstructorRejectsNaN() + { + new DataSize(Double.NaN, BYTE); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "unit is null") + public void testConstructorRejectsNullUnit() + { + new DataSize(1, null); + } + + @Test + public void testToBytes() + { + assertEquals(new DataSize(0, BYTE).toBytes(), 0); + assertEquals(new DataSize(0, MEGABYTE).toBytes(), 0); + assertEquals(new DataSize(1, BYTE).toBytes(), 1); + assertEquals(new DataSize(1, KILOBYTE).toBytes(), 1024); + assertEquals(new DataSize(42, MEGABYTE).toBytes(), 42L * 1024 * 1024); + assertEquals(new DataSize(0.037, KILOBYTE).toBytes(), 37); + assertEquals(new DataSize(1, TERABYTE).toBytes(), 1024L * 1024 * 1024 * 1024); + assertEquals(new DataSize(1, PETABYTE).toBytes(), 1024L * 1024 * 1024 * 1024 * 1024); + assertEquals(new DataSize(1024, PETABYTE).toBytes(), 1024L * 1024 * 1024 * 1024 * 1024 * 1024); + assertEquals(new DataSize(8191, PETABYTE).toBytes(), 8191L * 1024 * 1024 * 1024 * 1024 * 1024); + assertEquals(new DataSize(Long.MAX_VALUE, BYTE).toBytes(), Long.MAX_VALUE); + assertEquals(new DataSize(Long.MAX_VALUE / 1024.0, KILOBYTE).toBytes(), Long.MAX_VALUE); + } + + @Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "size is too large .*") + public void testToBytesTooLarge() + { + new DataSize(Long.MAX_VALUE + 1024.0001, BYTE).toBytes(); // smallest value that overflows + } + + @Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "size is too large .*") + public void testToBytesTooLarge2() + { + new DataSize(9000, PETABYTE).toBytes(); + } + + @Test + public void testRoundTo() + { + assertEquals(new DataSize(0, BYTE).roundTo(BYTE), 0); + assertEquals(new DataSize(0.5, BYTE).roundTo(BYTE), 1); + assertEquals(new DataSize((42 * 1024) + 511, BYTE).roundTo(KILOBYTE), 42); + assertEquals(new DataSize((42 * 1024) + 512, BYTE).roundTo(KILOBYTE), 43); + assertEquals(new DataSize(513, TERABYTE).roundTo(PETABYTE), 1); + assertEquals(new DataSize(9000L * 1024 * 1024 * 1024 * 1024, KILOBYTE).roundTo(PETABYTE), 9000); + } + + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is too large .*") + public void testRoundToTooLarge() + { + new DataSize(Long.MAX_VALUE + 1024.0001, BYTE).roundTo(BYTE); + } + + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is too large .*") + public void testRoundToTooLarge2() + { + new DataSize(9000, PETABYTE).roundTo(BYTE); + } + + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "size is too large .*") + public void testRoundToTooLarge3() + { + new DataSize(9000 * 1024, PETABYTE).roundTo(KILOBYTE); + } + + @Test + public void testJsonRoundTrip() + throws Exception + { + assertJsonRoundTrip(new DataSize(1.234, BYTE)); + assertJsonRoundTrip(new DataSize(1.234, KILOBYTE)); + assertJsonRoundTrip(new DataSize(1.234, MEGABYTE)); + assertJsonRoundTrip(new DataSize(1.234, GIGABYTE)); + assertJsonRoundTrip(new DataSize(1.234, TERABYTE)); + assertJsonRoundTrip(new DataSize(1.234, PETABYTE)); + } + + private static void assertJsonRoundTrip(DataSize dataSize) + { + JsonCodec dataSizeCodec = JsonCodec.jsonCodec(DataSize.class); + String json = dataSizeCodec.toJson(dataSize); + DataSize dataSizeCopy = dataSizeCodec.fromJson(json); + + assertThat(dataSizeCopy.getValue(BYTE)) + .isCloseTo(dataSize.getValue(BYTE), withPercentage(1)); + } + + @DataProvider(name = "parseableValues", parallel = true) + private Object[][] parseableValues() + { + return new Object[][] { + // spaces + new Object[] {"1234 B", 1234, BYTE}, + new Object[] {"1234 kB", 1234, KILOBYTE}, + new Object[] {"1234 MB", 1234, MEGABYTE}, + new Object[] {"1234 GB", 1234, GIGABYTE}, + new Object[] {"1234 TB", 1234, TERABYTE}, + new Object[] {"1234 PB", 1234, PETABYTE}, + new Object[] {"1234.567 B", 1234.567, BYTE}, + new Object[] {"1234.567 kB", 1234.567, KILOBYTE}, + new Object[] {"1234.567 MB", 1234.567, MEGABYTE}, + new Object[] {"1234.567 GB", 1234.567, GIGABYTE}, + new Object[] {"1234.567 TB", 1234.567, TERABYTE}, + new Object[] {"1234.567 PB", 1234.567, PETABYTE}, + // no spaces + new Object[] {"1234B", 1234, BYTE}, + new Object[] {"1234kB", 1234, KILOBYTE}, + new Object[] {"1234MB", 1234, MEGABYTE}, + new Object[] {"1234GB", 1234, GIGABYTE}, + new Object[] {"1234TB", 1234, TERABYTE}, + new Object[] {"1234PB", 1234, PETABYTE}, + new Object[] {"1234.567B", 1234.567, BYTE}, + new Object[] {"1234.567kB", 1234.567, KILOBYTE}, + new Object[] {"1234.567MB", 1234.567, MEGABYTE}, + new Object[] {"1234.567GB", 1234.567, GIGABYTE}, + new Object[] {"1234.567TB", 1234.567, TERABYTE}, + new Object[] {"1234.567PB", 1234.567, PETABYTE} + }; + } + + @DataProvider(name = "printedValues", parallel = true) + private Object[][] printedValues() + { + return new Object[][] { + new Object[] {"1234B", 1234, BYTE}, + new Object[] {"1234kB", 1234, KILOBYTE}, + new Object[] {"1234MB", 1234, MEGABYTE}, + new Object[] {"1234GB", 1234, GIGABYTE}, + new Object[] {"1234TB", 1234, TERABYTE}, + new Object[] {"1234PB", 1234, PETABYTE}, + new Object[] {"1234.57B", 1234.567, BYTE}, + new Object[] {"1234.57kB", 1234.567, KILOBYTE}, + new Object[] {"1234.57MB", 1234.567, MEGABYTE}, + new Object[] {"1234.57GB", 1234.567, GIGABYTE}, + new Object[] {"1234.57TB", 1234.567, TERABYTE}, + new Object[] {"1234.57PB", 1234.567, PETABYTE} + }; + } + + @DataProvider(name = "conversions", parallel = true) + private Object[][] conversions() + { + return new Object[][] { + new Object[] {BYTE, BYTE, 1}, + new Object[] {BYTE, KILOBYTE, 1.0 / 1024}, + new Object[] {BYTE, MEGABYTE, 1.0 / 1024 / 1024}, + new Object[] {BYTE, GIGABYTE, 1.0 / 1024 / 1024 / 1024}, + new Object[] {BYTE, TERABYTE, 1.0 / 1024 / 1024 / 1024 / 1024}, + new Object[] {BYTE, PETABYTE, 1.0 / 1024 / 1024 / 1024 / 1024 / 1024}, + + new Object[] {KILOBYTE, BYTE, 1024}, + new Object[] {KILOBYTE, KILOBYTE, 1}, + new Object[] {KILOBYTE, MEGABYTE, 1.0 / 1024}, + new Object[] {KILOBYTE, GIGABYTE, 1.0 / 1024 / 1024}, + new Object[] {KILOBYTE, TERABYTE, 1.0 / 1024 / 1024 / 1024}, + new Object[] {KILOBYTE, PETABYTE, 1.0 / 1024 / 1024 / 1024 / 1024}, + + new Object[] {MEGABYTE, BYTE, 1024 * 1024}, + new Object[] {MEGABYTE, KILOBYTE, 1024}, + new Object[] {MEGABYTE, MEGABYTE, 1}, + new Object[] {MEGABYTE, GIGABYTE, 1.0 / 1024}, + new Object[] {MEGABYTE, TERABYTE, 1.0 / 1024 / 1024}, + new Object[] {MEGABYTE, PETABYTE, 1.0 / 1024 / 1024 / 1024}, + + new Object[] {GIGABYTE, BYTE, 1024 * 1024 * 1024}, + new Object[] {GIGABYTE, KILOBYTE, 1024 * 1024}, + new Object[] {GIGABYTE, MEGABYTE, 1024}, + new Object[] {GIGABYTE, GIGABYTE, 1}, + new Object[] {GIGABYTE, TERABYTE, 1.0 / 1024}, + new Object[] {GIGABYTE, PETABYTE, 1.0 / 1024 / 1024}, + + new Object[] {TERABYTE, BYTE, 1024L * 1024 * 1024 * 1024}, + new Object[] {TERABYTE, KILOBYTE, 1024 * 1024 * 1024}, + new Object[] {TERABYTE, MEGABYTE, 1024 * 1024}, + new Object[] {TERABYTE, GIGABYTE, 1024}, + new Object[] {TERABYTE, TERABYTE, 1}, + new Object[] {TERABYTE, PETABYTE, 1.0 / 1024}, + + new Object[] {PETABYTE, BYTE, 1024L * 1024 * 1024 * 1024 * 1024}, + new Object[] {PETABYTE, KILOBYTE, 1024L * 1024 * 1024 * 1024}, + new Object[] {PETABYTE, MEGABYTE, 1024 * 1024 * 1024}, + new Object[] {PETABYTE, GIGABYTE, 1024 * 1024}, + new Object[] {PETABYTE, TERABYTE, 1024}, + new Object[] {PETABYTE, PETABYTE, 1}, + }; + } +} diff --git a/units/src/test/java/io/airlift/units/TestDataSizeValidator.java b/units/src/test/java/io/airlift/units/TestDataSizeValidator.java new file mode 100644 index 0000000000..240a06a9c3 --- /dev/null +++ b/units/src/test/java/io/airlift/units/TestDataSizeValidator.java @@ -0,0 +1,317 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import org.apache.bval.jsr.ApacheValidationProvider; +import org.testng.annotations.Test; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.ValidationException; +import javax.validation.Validator; + +import java.util.Optional; +import java.util.Set; + +import static io.airlift.units.ConstraintValidatorAssert.assertThat; +import static io.airlift.units.DataSize.Unit.GIGABYTE; +import static io.airlift.units.DataSize.Unit.KILOBYTE; +import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.testng.Assert.assertTrue; + +public class TestDataSizeValidator +{ + private static final Validator VALIDATOR = Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory().getValidator(); + + @Test + public void testMaxDataSizeValidator() + { + MaxDataSizeValidator maxValidator = new MaxDataSizeValidator(); + maxValidator.initialize(new MockMaxDataSize(new DataSize(8, MEGABYTE))); + + assertThat(maxValidator).isValidFor(new DataSize(0, KILOBYTE)); + assertThat(maxValidator).isValidFor(new DataSize(5, KILOBYTE)); + assertThat(maxValidator).isValidFor(new DataSize(5005, KILOBYTE)); + assertThat(maxValidator).isValidFor(new DataSize(5, MEGABYTE)); + assertThat(maxValidator).isValidFor(new DataSize(8, MEGABYTE)); + assertThat(maxValidator).isValidFor(new DataSize(8192, KILOBYTE)); + assertThat(maxValidator).isInvalidFor(new DataSize(9, MEGABYTE)); + assertThat(maxValidator).isInvalidFor(new DataSize(1, GIGABYTE)); + } + + @Test + public void testMinDataSizeValidator() + { + MinDataSizeValidator minValidator = new MinDataSizeValidator(); + minValidator.initialize(new MockMinDataSize(new DataSize(4, MEGABYTE))); + + assertThat(minValidator).isValidFor(new DataSize(4, MEGABYTE)); + assertThat(minValidator).isValidFor(new DataSize(4096, KILOBYTE)); + assertThat(minValidator).isValidFor(new DataSize(5, MEGABYTE)); + assertThat(minValidator).isInvalidFor(new DataSize(0, GIGABYTE)); + assertThat(minValidator).isInvalidFor(new DataSize(1, MEGABYTE)); + } + + @Test + public void testAllowsNullMinAnnotation() + { + VALIDATOR.validate(new NullMinAnnotation()); + } + + @Test + public void testAllowsNullMaxAnnotation() + { + VALIDATOR.validate(new NullMaxAnnotation()); + } + + @Test + public void testDetectsBrokenMinAnnotation() + { + assertThatThrownBy(() -> VALIDATOR.validate(new BrokenMinAnnotation())) + .isInstanceOf(ValidationException.class) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasMessage("java.lang.IllegalArgumentException: size is not a valid data size string: broken"); + + assertThatThrownBy(() -> VALIDATOR.validate(new MinAnnotationOnOptional())) + .isInstanceOf(ValidationException.class) + .hasMessage("No compliant io.airlift.units.MinDataSize ConstraintValidator found for annotated element of type java.util.Optional"); + + assertThatThrownBy(() -> VALIDATOR.validate(new BrokenOptionalMinAnnotation())) + .isInstanceOf(ValidationException.class) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasMessage("java.lang.IllegalArgumentException: size is not a valid data size string: broken"); + } + + @Test + public void testDetectsBrokenMaxAnnotation() + { + assertThatThrownBy(() -> VALIDATOR.validate(new BrokenMaxAnnotation())) + .isInstanceOf(ValidationException.class) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasMessage("java.lang.IllegalArgumentException: size is not a valid data size string: broken"); + + assertThatThrownBy(() -> VALIDATOR.validate(new MaxAnnotationOnOptional())) + .isInstanceOf(ValidationException.class) + .hasMessage("No compliant io.airlift.units.MaxDataSize ConstraintValidator found for annotated element of type java.util.Optional"); + + assertThatThrownBy(() -> VALIDATOR.validate(new BrokenOptionalMaxAnnotation())) + .isInstanceOf(ValidationException.class) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasMessage("java.lang.IllegalArgumentException: size is not a valid data size string: broken"); + } + + @Test + public void testPassesValidation() + { + assertTrue(VALIDATOR.validate(new ConstrainedDataSize(new DataSize(7, MEGABYTE))).isEmpty()); + + assertThat(VALIDATOR.validate(new ConstrainedOptionalDataSize(Optional.of(new DataSize(7, MEGABYTE))))).isEmpty(); + + assertThat(VALIDATOR.validate(new ConstrainedOptionalDataSize(Optional.empty()))).isEmpty(); + + assertThat(VALIDATOR.validate(new ConstrainedOptionalDataSize(null))).isEmpty(); + } + + @Test + public void testFailsMaxDataSizeConstraint() + { + Set> violations = VALIDATOR.validate(new ConstrainedDataSize(new DataSize(11, MEGABYTE))); + assertThat(violations).hasSize(2); + assertThat(violations) + .extracting(violation -> violation.getConstraintDescriptor().getAnnotation()) + .allMatch(MaxDataSize.class::isInstance); + assertThat(violations) + .extracting(violation -> violation.getPropertyPath().toString()) + .containsOnly("constrainedByMax", "constrainedByMinAndMax"); + assertThat(violations) + .extracting(ConstraintViolation::getMessage) + .containsOnly("must be less than or equal to 10000kB", "must be less than or equal to 10MB"); + + violations = VALIDATOR.validate(new ConstrainedOptionalDataSize(Optional.of(new DataSize(11, MEGABYTE)))); + assertThat(violations).hasSize(2); + assertThat(violations) + .extracting(violation -> violation.getConstraintDescriptor().getAnnotation()) + .allMatch(MaxDataSize.class::isInstance); + assertThat(violations) + .extracting(violation -> violation.getPropertyPath().toString()) + .containsOnly("constrainedByMax", "constrainedByMinAndMax"); + assertThat(violations) + .extracting(ConstraintViolation::getMessage) + .containsOnly("must be less than or equal to 10000kB", "must be less than or equal to 10MB"); + } + + @Test + public void testFailsMinDataSizeConstraint() + { + Set> violations = VALIDATOR.validate(new ConstrainedDataSize(new DataSize(1, MEGABYTE))); + assertThat(violations).hasSize(2); + assertThat(violations) + .extracting(violation -> violation.getConstraintDescriptor().getAnnotation()) + .allMatch(MinDataSize.class::isInstance); + assertThat(violations) + .extracting(violation -> violation.getPropertyPath().toString()) + .containsOnly("constrainedByMin", "constrainedByMinAndMax"); + assertThat(violations) + .extracting(ConstraintViolation::getMessage) + .containsOnly("must be greater than or equal to 5MB", "must be greater than or equal to 5000kB"); + + violations = VALIDATOR.validate(new ConstrainedOptionalDataSize(Optional.of(new DataSize(1, MEGABYTE)))); + assertThat(violations).hasSize(2); + assertThat(violations) + .extracting(violation -> violation.getConstraintDescriptor().getAnnotation()) + .allMatch(MinDataSize.class::isInstance); + assertThat(violations) + .extracting(violation -> violation.getPropertyPath().toString()) + .containsOnly("constrainedByMin", "constrainedByMinAndMax"); + assertThat(violations) + .extracting(ConstraintViolation::getMessage) + .containsOnly("must be greater than or equal to 5MB", "must be greater than or equal to 5000kB"); + } + + @SuppressWarnings("UnusedDeclaration") + public static class ConstrainedDataSize + { + private final DataSize dataSize; + + public ConstrainedDataSize(DataSize dataSize) + { + this.dataSize = dataSize; + } + + @MinDataSize("5MB") + public DataSize getConstrainedByMin() + { + return dataSize; + } + + @MaxDataSize("10MB") + public DataSize getConstrainedByMax() + { + return dataSize; + } + + @MinDataSize("5000kB") + @MaxDataSize("10000kB") + public DataSize getConstrainedByMinAndMax() + { + return dataSize; + } + } + + @SuppressWarnings("UnusedDeclaration") + public static class ConstrainedOptionalDataSize + { + private final Optional dataSize; + + public ConstrainedOptionalDataSize(Optional dataSize) + { + this.dataSize = dataSize; + } + + public Optional<@MinDataSize("5MB") DataSize> getConstrainedByMin() + { + return dataSize; + } + + public Optional<@MaxDataSize("10MB") DataSize> getConstrainedByMax() + { + return dataSize; + } + + public Optional<@MinDataSize("5000kB") @MaxDataSize("10000kB") DataSize> getConstrainedByMinAndMax() + { + return dataSize; + } + } + + public static class NullMinAnnotation + { + @SuppressWarnings("UnusedDeclaration") + @MinDataSize("1MB") + public DataSize getConstrainedByMin() + { + return null; + } + } + + public static class NullMaxAnnotation + { + @SuppressWarnings("UnusedDeclaration") + @MaxDataSize("1MB") + public DataSize getConstrainedByMin() + { + return null; + } + } + + public static class BrokenMinAnnotation + { + @SuppressWarnings("UnusedDeclaration") + @MinDataSize("broken") + public DataSize getConstrainedByMin() + { + return new DataSize(32, KILOBYTE); + } + } + + public static class BrokenMaxAnnotation + { + @SuppressWarnings("UnusedDeclaration") + @MinDataSize("broken") + public DataSize getConstrainedByMin() + { + return new DataSize(32, KILOBYTE); + } + } + + public static class MinAnnotationOnOptional + { + @SuppressWarnings("UnusedDeclaration") + @MinDataSize("1MB") + public Optional getConstrainedByMin() + { + return Optional.empty(); + } + } + + public static class MaxAnnotationOnOptional + { + @SuppressWarnings("UnusedDeclaration") + @MaxDataSize("1MB") + public Optional getConstrainedByMin() + { + return Optional.empty(); + } + } + + public static class BrokenOptionalMinAnnotation + { + @SuppressWarnings("UnusedDeclaration") + public Optional<@MinDataSize("broken") DataSize> getConstrainedByMin() + { + return Optional.empty(); + } + } + + public static class BrokenOptionalMaxAnnotation + { + @SuppressWarnings("UnusedDeclaration") + public Optional<@MaxDataSize("broken") DataSize> getConstrainedByMax() + { + return Optional.empty(); + } + } +} diff --git a/units/src/test/java/io/airlift/units/TestDuration.java b/units/src/test/java/io/airlift/units/TestDuration.java new file mode 100644 index 0000000000..b3e4ec7d2b --- /dev/null +++ b/units/src/test/java/io/airlift/units/TestDuration.java @@ -0,0 +1,403 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import io.airlift.json.JsonCodec; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.TimeUnit; + +import static io.airlift.testing.EquivalenceTester.comparisonTester; +import static io.airlift.units.Duration.succinctDuration; +import static io.airlift.units.Duration.succinctNanos; +import static java.util.concurrent.TimeUnit.DAYS; +import static java.util.concurrent.TimeUnit.HOURS; +import static java.util.concurrent.TimeUnit.MICROSECONDS; +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.concurrent.TimeUnit.MINUTES; +import static java.util.concurrent.TimeUnit.NANOSECONDS; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.offset; +import static org.assertj.core.data.Percentage.withPercentage; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.fail; + +public class TestDuration +{ + @Test + public void testSuccinctFactories() + { + assertEquals(succinctNanos(123), new Duration(123, NANOSECONDS)); + assertEquals(succinctNanos(123456), new Duration(123.456, MICROSECONDS)); + assertEquals(succinctNanos(SECONDS.toNanos(300)), new Duration(5, MINUTES)); + + assertEquals(succinctDuration(123, NANOSECONDS), new Duration(123, NANOSECONDS)); + assertEquals(succinctDuration(123456, NANOSECONDS), new Duration(123.456, MICROSECONDS)); + assertEquals(succinctDuration(300, SECONDS), new Duration(5, MINUTES)); + } + + @Test + public void testGetValue() + { + double millis = 12346789.0d; + Duration duration = new Duration(millis, MILLISECONDS); + assertThat(duration.getValue(MILLISECONDS)).isEqualTo(millis); + assertThat(duration.getValue(SECONDS)).isCloseTo(millis / 1000, offset(0.001)); + assertThat(duration.getValue(MINUTES)).isCloseTo(millis / 1000 / 60, offset(0.001)); + assertThat(duration.getValue(HOURS)).isCloseTo(millis / 1000 / 60 / 60, offset(0.001)); + assertThat(duration.getValue(DAYS)).isCloseTo(millis / 1000 / 60 / 60 / 24, offset(0.001)); + + double days = 3.0; + duration = new Duration(days, DAYS); + assertThat(duration.getValue(DAYS)).isEqualTo(days); + assertThat(duration.getValue(HOURS)).isCloseTo(days * 24, offset(0.001)); + assertThat(duration.getValue(MINUTES)).isCloseTo(days * 24 * 60, offset(0.001)); + assertThat(duration.getValue(SECONDS)).isCloseTo(days * 24 * 60 * 60, offset(0.001)); + assertThat(duration.getValue(MILLISECONDS)).isCloseTo(days * 24 * 60 * 60 * 1000, offset(0.001)); + } + + @Test(dataProvider = "conversions") + public void testConversions(TimeUnit unit, TimeUnit toTimeUnit, double factor) + { + Duration duration = new Duration(1, unit).convertTo(toTimeUnit); + assertThat(duration.getUnit()).isEqualTo(toTimeUnit); + assertThat(duration.getValue()).isCloseTo(factor, withPercentage(0.1)); + assertThat(duration.getValue(toTimeUnit)).isCloseTo(factor, withPercentage(0.1)); + } + + @Test(dataProvider = "conversions") + public void testConvertToMostSuccinctDuration(TimeUnit unit, TimeUnit toTimeUnit, double factor) + { + Duration duration = new Duration(factor, toTimeUnit); + Duration actual = duration.convertToMostSuccinctTimeUnit(); + assertThat(actual.getValue(toTimeUnit)).isCloseTo(factor, withPercentage(0.1)); + assertThat(actual.getValue(unit)).isCloseTo(1.0, offset(0.001)); + assertThat(actual.getUnit()).isEqualTo(unit); + } + + @Test + public void testEquivalence() + { + comparisonTester() + .addLesserGroup(generateTimeBucket(0)) + .addGreaterGroup(generateTimeBucket(1)) + .addGreaterGroup(generateTimeBucket(123352)) + .addGreaterGroup(generateTimeBucket(Long.MAX_VALUE)) + .check(); + } + + private static List generateTimeBucket(double seconds) + { + List bucket = new ArrayList<>(); + bucket.add(new Duration(seconds * 1000 * 1000 * 1000, NANOSECONDS)); + bucket.add(new Duration(seconds * 1000 * 1000, MICROSECONDS)); + bucket.add(new Duration(seconds * 1000, MILLISECONDS)); + bucket.add(new Duration(seconds, SECONDS)); + bucket.add(new Duration(seconds / 60, MINUTES)); + bucket.add(new Duration(seconds / 60 / 60, HOURS)); + // skip days for larger values as this results in rounding errors + if (seconds <= 1.0) { + bucket.add(new Duration(seconds / 60 / 60 / 24, DAYS)); + } + return bucket; + } + + @Test(dataProvider = "printedValues") + public void testToString(String expectedString, double value, TimeUnit unit) + { + assertEquals(new Duration(value, unit).toString(), expectedString); + } + + @Test(dataProvider = "printedValues") + public void testNonEnglishLocale(String expectedString, double value, TimeUnit unit) + throws Exception + { + synchronized (Locale.class) { + Locale previous = Locale.getDefault(); + Locale.setDefault(Locale.GERMAN); + try { + assertEquals(new Duration(value, unit).toString(), expectedString); + } + finally { + Locale.setDefault(previous); + } + } + } + + @Test(dataProvider = "parseableValues") + public void testValueOf(String string, double expectedValue, TimeUnit expectedUnit) + { + Duration duration = Duration.valueOf(string); + + assertEquals(duration.getUnit(), expectedUnit); + assertEquals(duration.getValue(), expectedValue); + } + + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "duration is null") + public void testValueOfRejectsNull() + { + Duration.valueOf(null); + } + + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "duration is empty") + public void testValueOfRejectsEmptyString() + { + Duration.valueOf(""); + } + + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Unknown time unit: kg") + public void testValueOfRejectsInvalidUnit() + { + Duration.valueOf("1.234 kg"); + } + + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "duration is not a valid.*") + public void testValueOfRejectsInvalidNumber() + { + Duration.valueOf("1.2x4 s"); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "value is negative") + public void testConstructorRejectsNegativeValue() + { + new Duration(-1, SECONDS); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "value is infinite") + public void testConstructorRejectsInfiniteValue() + { + new Duration(Double.POSITIVE_INFINITY, SECONDS); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "value is infinite") + public void testConstructorRejectsInfiniteValue2() + { + new Duration(Double.NEGATIVE_INFINITY, SECONDS); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "value is not a number") + public void testConstructorRejectsNaN() + { + new Duration(Double.NaN, SECONDS); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "unit is null") + public void testConstructorRejectsNullUnit() + { + new Duration(1, null); + } + + @Test + public void testEquals() + { + assertEquals(new Duration(12359.0d, MILLISECONDS), new Duration(12359.0d, MILLISECONDS)); + assertFalse(new Duration(12359.0d, MILLISECONDS).equals(new Duration(4444.0d, MILLISECONDS))); + } + + @Test + public void testHashCode() + { + assertEquals(new Duration(12359.0d, MILLISECONDS).hashCode(), new Duration(12359.0d, MILLISECONDS).hashCode()); + assertFalse(new Duration(12359.0d, MILLISECONDS).hashCode() == new Duration(4444.0d, MILLISECONDS).hashCode()); + } + + @Test + public void testNanoConversions() + { + double nanos = 1.0d; + Duration duration = new Duration(nanos, NANOSECONDS); + assertThat(duration.getValue()).isEqualTo(nanos); + assertThat(duration.getValue(NANOSECONDS)).isEqualTo(nanos); + assertThat(duration.getValue(MILLISECONDS)).isEqualTo(nanos / 1000000); + assertThat(duration.getValue(SECONDS)).isEqualTo(nanos / 1000000 / 1000); + assertThat(duration.getValue(MINUTES)).isCloseTo(nanos / 1000000 / 1000 / 60, offset(1.0E10)); + assertThat(duration.getValue(HOURS)).isCloseTo(nanos / 1000000 / 1000 / 60 / 60, offset(1.0E10)); + assertThat(duration.getValue(DAYS)).isCloseTo(nanos / 1000000 / 1000 / 60 / 60 / 24, offset(1.0E10)); + } + + @SuppressWarnings("ResultOfMethodCallIgnored") + @Test + public void invalidParameters() + { + failDurationConstruction(Double.NEGATIVE_INFINITY, MILLISECONDS); + failDurationConstruction(Double.POSITIVE_INFINITY, MILLISECONDS); + failDurationConstruction(Double.NaN, MILLISECONDS); + failDurationConstruction(42, null); + failDurationConstruction(-42, MILLISECONDS); + + Duration duration = new Duration(42, MILLISECONDS); + try { + duration.convertTo(null); + fail("Expected NullPointerException"); + } + catch (NullPointerException e) { + // ok + } + try { + duration.toString(null); + fail("Expected NullPointerException"); + } + catch (NullPointerException e) { + // ok + } + } + + @Test + public void testJsonRoundTrip() + throws Exception + { + assertJsonRoundTrip(new Duration(1.234, MILLISECONDS)); + assertJsonRoundTrip(new Duration(1.234, SECONDS)); + assertJsonRoundTrip(new Duration(1.234, MINUTES)); + assertJsonRoundTrip(new Duration(1.234, HOURS)); + assertJsonRoundTrip(new Duration(1.234, DAYS)); + } + + private static void assertJsonRoundTrip(Duration duration) + { + JsonCodec durationCodec = JsonCodec.jsonCodec(Duration.class); + String json = durationCodec.toJson(duration); + Duration durationCopy = durationCodec.fromJson(json); + + assertThat(durationCopy.getValue(MILLISECONDS)) + .isCloseTo(duration.getValue(MILLISECONDS), withPercentage(1)); + } + + @SuppressWarnings("ResultOfObjectAllocationIgnored") + private static void failDurationConstruction(double value, TimeUnit timeUnit) + { + try { + new Duration(value, timeUnit); + fail("Expected NullPointerException or IllegalArgumentException"); + } + catch (NullPointerException | IllegalArgumentException e) { + // ok + } + } + + @DataProvider(name = "parseableValues", parallel = true) + private Object[][] parseableValues() + { + return new Object[][] { + // spaces + new Object[] {"1234 ns", 1234, NANOSECONDS}, + new Object[] {"1234 ms", 1234, MILLISECONDS}, + new Object[] {"1234 s", 1234, SECONDS}, + new Object[] {"1234 m", 1234, MINUTES}, + new Object[] {"1234 h", 1234, HOURS}, + new Object[] {"1234 d", 1234, DAYS}, + new Object[] {"1234.567 ns", 1234.567, NANOSECONDS}, + new Object[] {"1234.567 ms", 1234.567, MILLISECONDS}, + new Object[] {"1234.567 s", 1234.567, SECONDS}, + new Object[] {"1234.567 m", 1234.567, MINUTES}, + new Object[] {"1234.567 h", 1234.567, HOURS}, + new Object[] {"1234.567 d", 1234.567, DAYS}, + // no spaces + new Object[] {"1234ns", 1234, NANOSECONDS}, + new Object[] {"1234ms", 1234, MILLISECONDS}, + new Object[] {"1234s", 1234, SECONDS}, + new Object[] {"1234m", 1234, MINUTES}, + new Object[] {"1234h", 1234, HOURS}, + new Object[] {"1234d", 1234, DAYS}, + new Object[] {"1234.567ns", 1234.567, NANOSECONDS}, + new Object[] {"1234.567ms", 1234.567, MILLISECONDS}, + new Object[] {"1234.567s", 1234.567, SECONDS}, + new Object[] {"1234.567m", 1234.567, MINUTES}, + new Object[] {"1234.567h", 1234.567, HOURS}, + new Object[] {"1234.567d", 1234.567, DAYS} + }; + } + + @DataProvider(name = "printedValues", parallel = true) + private Object[][] printedValues() + { + return new Object[][] { + new Object[] {"1234.00ns", 1234, NANOSECONDS}, + new Object[] {"1234.00us", 1234, MICROSECONDS}, + new Object[] {"1234.00ms", 1234, MILLISECONDS}, + new Object[] {"1234.00s", 1234, SECONDS}, + new Object[] {"1234.00m", 1234, MINUTES}, + new Object[] {"1234.00h", 1234, HOURS}, + new Object[] {"1234.00d", 1234, DAYS}, + new Object[] {"1234.57ns", 1234.567, NANOSECONDS}, + new Object[] {"1234.57us", 1234.567, MICROSECONDS}, + new Object[] {"1234.57ms", 1234.567, MILLISECONDS}, + new Object[] {"1234.57s", 1234.567, SECONDS}, + new Object[] {"1234.57m", 1234.567, MINUTES}, + new Object[] {"1234.57h", 1234.567, HOURS}, + new Object[] {"1234.57d", 1234.567, DAYS} + }; + } + + @DataProvider(name = "conversions", parallel = true) + private Object[][] conversions() + { + return new Object[][] { + new Object[] {NANOSECONDS, NANOSECONDS, 1.0}, + new Object[] {NANOSECONDS, MILLISECONDS, 1.0 / 1000_000}, + new Object[] {NANOSECONDS, SECONDS, 1.0 / 1000_000 / 1000}, + new Object[] {NANOSECONDS, MINUTES, 1.0 / 1000_000 / 1000 / 60}, + new Object[] {NANOSECONDS, HOURS, 1.0 / 1000_000 / 1000 / 60 / 60}, + new Object[] {NANOSECONDS, DAYS, 1.0 / 1000_000 / 1000 / 60 / 60 / 24}, + + new Object[] {MILLISECONDS, NANOSECONDS, 1000000.0}, + new Object[] {MILLISECONDS, MILLISECONDS, 1.0}, + new Object[] {MILLISECONDS, SECONDS, 1.0 / 1000}, + new Object[] {MILLISECONDS, MINUTES, 1.0 / 1000 / 60}, + new Object[] {MILLISECONDS, HOURS, 1.0 / 1000 / 60 / 60}, + new Object[] {MILLISECONDS, DAYS, 1.0 / 1000 / 60 / 60 / 24}, + + new Object[] {SECONDS, NANOSECONDS, 1000000.0 * 1000}, + new Object[] {SECONDS, MILLISECONDS, 1000}, + new Object[] {SECONDS, SECONDS, 1}, + new Object[] {SECONDS, MINUTES, 1.0 / 60}, + new Object[] {SECONDS, HOURS, 1.0 / 60 / 60}, + new Object[] {SECONDS, DAYS, 1.0 / 60 / 60 / 24}, + + new Object[] {MINUTES, NANOSECONDS, 1000000.0 * 1000 * 60}, + new Object[] {MINUTES, MILLISECONDS, 1000 * 60}, + new Object[] {MINUTES, SECONDS, 60}, + new Object[] {MINUTES, MINUTES, 1}, + new Object[] {MINUTES, HOURS, 1.0 / 60}, + new Object[] {MINUTES, DAYS, 1.0 / 60 / 24}, + + new Object[] {HOURS, NANOSECONDS, 1000000.0 * 1000 * 60 * 60}, + new Object[] {HOURS, MILLISECONDS, 1000 * 60 * 60}, + new Object[] {HOURS, SECONDS, 60 * 60}, + new Object[] {HOURS, MINUTES, 60}, + new Object[] {HOURS, HOURS, 1}, + new Object[] {HOURS, DAYS, 1.0 / 24}, + + new Object[] {DAYS, NANOSECONDS, 1000000.0 * 1000 * 60 * 60 * 24}, + new Object[] {DAYS, MILLISECONDS, 1000 * 60 * 60 * 24}, + new Object[] {DAYS, SECONDS, 60 * 60 * 24}, + new Object[] {DAYS, MINUTES, 60 * 24}, + new Object[] {DAYS, HOURS, 24}, + new Object[] {DAYS, DAYS, 1}, + }; + } +} diff --git a/units/src/test/java/io/airlift/units/TestDurationValidator.java b/units/src/test/java/io/airlift/units/TestDurationValidator.java new file mode 100644 index 0000000000..e7acd82440 --- /dev/null +++ b/units/src/test/java/io/airlift/units/TestDurationValidator.java @@ -0,0 +1,309 @@ +/* + * Copyright 2010 Proofpoint, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.airlift.units; + +import org.apache.bval.jsr.ApacheValidationProvider; +import org.testng.annotations.Test; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.ValidationException; +import javax.validation.Validator; + +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import static io.airlift.units.ConstraintValidatorAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class TestDurationValidator +{ + private static final Validator VALIDATOR = Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory().getValidator(); + + @Test + public void testMaxDurationValidator() + { + MaxDurationValidator maxValidator = new MaxDurationValidator(); + maxValidator.initialize(new MockMaxDuration(new Duration(5, TimeUnit.SECONDS))); + + assertThat(maxValidator).isValidFor(new Duration(0, TimeUnit.SECONDS)); + assertThat(maxValidator).isValidFor(new Duration(5, TimeUnit.SECONDS)); + assertThat(maxValidator).isInvalidFor(new Duration(6, TimeUnit.SECONDS)); + } + + @Test + public void testMinDurationValidator() + { + MinDurationValidator minValidator = new MinDurationValidator(); + minValidator.initialize(new MockMinDuration(new Duration(5, TimeUnit.SECONDS))); + + assertThat(minValidator).isValidFor(new Duration(5, TimeUnit.SECONDS)); + assertThat(minValidator).isValidFor(new Duration(6, TimeUnit.SECONDS)); + assertThat(minValidator).isInvalidFor(new Duration(0, TimeUnit.SECONDS)); + } + + @Test + public void testAllowsNullMinAnnotation() + { + VALIDATOR.validate(new NullMinAnnotation()); + } + + @Test + public void testAllowsNullMaxAnnotation() + { + VALIDATOR.validate(new NullMaxAnnotation()); + } + + @Test + public void testDetectsBrokenMinAnnotation() + { + assertThatThrownBy(() -> VALIDATOR.validate(new BrokenMinAnnotation())) + .isInstanceOf(ValidationException.class) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasMessage("java.lang.IllegalArgumentException: duration is not a valid data duration string: broken"); + + assertThatThrownBy(() -> VALIDATOR.validate(new MinAnnotationOnOptional())) + .isInstanceOf(ValidationException.class) + .hasMessage("No compliant io.airlift.units.MinDuration ConstraintValidator found for annotated element of type java.util.Optional"); + + assertThatThrownBy(() -> VALIDATOR.validate(new BrokenOptionalMinAnnotation())) + .isInstanceOf(ValidationException.class) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasMessage("java.lang.IllegalArgumentException: duration is not a valid data duration string: broken"); + } + + @Test + public void testDetectsBrokenMaxAnnotation() + { + assertThatThrownBy(() -> VALIDATOR.validate(new BrokenMaxAnnotation())) + .isInstanceOf(ValidationException.class) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasMessage("java.lang.IllegalArgumentException: duration is not a valid data duration string: broken"); + + assertThatThrownBy(() -> VALIDATOR.validate(new MaxAnnotationOnOptional())) + .isInstanceOf(ValidationException.class) + .hasMessage("No compliant io.airlift.units.MaxDuration ConstraintValidator found for annotated element of type java.util.Optional"); + + assertThatThrownBy(() -> VALIDATOR.validate(new BrokenOptionalMaxAnnotation())) + .isInstanceOf(ValidationException.class) + .hasRootCauseInstanceOf(IllegalArgumentException.class) + .hasMessage("java.lang.IllegalArgumentException: duration is not a valid data duration string: broken"); + } + + @Test + public void testPassesValidation() + { + assertThat(VALIDATOR.validate(new ConstrainedDuration(new Duration(7, TimeUnit.SECONDS)))).isEmpty(); + + assertThat(VALIDATOR.validate(new ConstrainedOptionalDuration(Optional.of(new Duration(7, TimeUnit.SECONDS))))).isEmpty(); + + assertThat(VALIDATOR.validate(new ConstrainedOptionalDuration(Optional.empty()))).isEmpty(); + + assertThat(VALIDATOR.validate(new ConstrainedOptionalDuration(null))).isEmpty(); + } + + @Test + public void testFailsMaxDurationConstraint() + { + Set> violations = VALIDATOR.validate(new ConstrainedDuration(new Duration(11, TimeUnit.SECONDS))); + assertThat(violations).hasSize(2); + assertThat(violations) + .extracting(violation -> violation.getConstraintDescriptor().getAnnotation()) + .allMatch(MaxDuration.class::isInstance); + assertThat(violations) + .extracting(violation -> violation.getPropertyPath().toString()) + .containsOnly("constrainedByMax", "constrainedByMinAndMax"); + assertThat(violations) + .extracting(ConstraintViolation::getMessage) + .containsOnly("must be less than or equal to 10s", "must be less than or equal to 10000ms"); + + violations = VALIDATOR.validate(new ConstrainedOptionalDuration(Optional.of(new Duration(11, TimeUnit.SECONDS)))); + assertThat(violations).hasSize(2); + assertThat(violations) + .extracting(violation -> violation.getConstraintDescriptor().getAnnotation()) + .allMatch(MaxDuration.class::isInstance); + assertThat(violations) + .extracting(violation -> violation.getPropertyPath().toString()) + .containsOnly("constrainedByMax", "constrainedByMinAndMax"); + assertThat(violations) + .extracting(ConstraintViolation::getMessage) + .containsOnly("must be less than or equal to 10s", "must be less than or equal to 10000ms"); + } + + @Test + public void testFailsMinDurationConstraint() + { + Set> violations = VALIDATOR.validate(new ConstrainedDuration(new Duration(1, TimeUnit.SECONDS))); + assertThat(violations).hasSize(2); + assertThat(violations) + .extracting(violation -> violation.getConstraintDescriptor().getAnnotation()) + .allMatch(MinDuration.class::isInstance); + assertThat(violations) + .extracting(violation -> violation.getPropertyPath().toString()) + .containsOnly("constrainedByMin", "constrainedByMinAndMax"); + assertThat(violations) + .extracting(ConstraintViolation::getMessage) + .containsOnly("must be greater than or equal to 5000ms", "must be greater than or equal to 5s"); + + violations = VALIDATOR.validate(new ConstrainedOptionalDuration(Optional.of(new Duration(1, TimeUnit.SECONDS)))); + assertThat(violations).hasSize(2); + assertThat(violations) + .extracting(violation -> violation.getConstraintDescriptor().getAnnotation()) + .allMatch(MinDuration.class::isInstance); + assertThat(violations) + .extracting(violation -> violation.getPropertyPath().toString()) + .containsOnly("constrainedByMin", "constrainedByMinAndMax"); + assertThat(violations) + .extracting(ConstraintViolation::getMessage) + .containsOnly("must be greater than or equal to 5000ms", "must be greater than or equal to 5s"); + } + + @SuppressWarnings("UnusedDeclaration") + public static class ConstrainedDuration + { + private final Duration duration; + + public ConstrainedDuration(Duration duration) + { + this.duration = duration; + } + + @MinDuration("5s") + public Duration getConstrainedByMin() + { + return duration; + } + + @MaxDuration("10s") + public Duration getConstrainedByMax() + { + return duration; + } + + @MinDuration("5000ms") + @MaxDuration("10000ms") + public Duration getConstrainedByMinAndMax() + { + return duration; + } + } + + @SuppressWarnings("UnusedDeclaration") + public static class ConstrainedOptionalDuration + { + private final Optional duration; + + public ConstrainedOptionalDuration(Optional duration) + { + this.duration = duration; + } + + public Optional<@MinDuration("5s") Duration> getConstrainedByMin() + { + return duration; + } + + public Optional<@MaxDuration("10s") Duration> getConstrainedByMax() + { + return duration; + } + + public Optional<@MinDuration("5000ms") @MaxDuration("10000ms") Duration> getConstrainedByMinAndMax() + { + return duration; + } + } + + public static class NullMinAnnotation + { + @SuppressWarnings("UnusedDeclaration") + @MinDuration("1s") + public Duration getConstrainedByMin() + { + return null; + } + } + + public static class NullMaxAnnotation + { + @SuppressWarnings("UnusedDeclaration") + @MaxDuration("1s") + public Duration getConstrainedByMin() + { + return null; + } + } + + public static class BrokenMinAnnotation + { + @SuppressWarnings("UnusedDeclaration") + @MinDuration("broken") + public Duration getConstrainedByMin() + { + return new Duration(10, TimeUnit.SECONDS); + } + } + + public static class BrokenMaxAnnotation + { + @SuppressWarnings("UnusedDeclaration") + @MinDuration("broken") + public Duration getConstrainedByMin() + { + return new Duration(10, TimeUnit.SECONDS); + } + } + + public static class MinAnnotationOnOptional + { + @SuppressWarnings("UnusedDeclaration") + @MinDuration("1s") + public Optional getConstrainedByMin() + { + return Optional.empty(); + } + } + + public static class MaxAnnotationOnOptional + { + @SuppressWarnings("UnusedDeclaration") + @MaxDuration("1s") + public Optional getConstrainedByMin() + { + return Optional.empty(); + } + } + + public static class BrokenOptionalMinAnnotation + { + @SuppressWarnings("UnusedDeclaration") + public Optional<@MinDuration("broken") Duration> getConstrainedByMin() + { + return Optional.empty(); + } + } + + public static class BrokenOptionalMaxAnnotation + { + @SuppressWarnings("UnusedDeclaration") + public Optional<@MaxDuration("broken") Duration> getConstrainedByMax() + { + return Optional.empty(); + } + } +} From d25252b5031727ce48f43167732f89e644585714 Mon Sep 17 00:00:00 2001 From: Zac Blanco Date: Fri, 8 Nov 2024 12:14:33 -0800 Subject: [PATCH 2/3] migrate from io.airlift:units to com.facebook.airlift:units --- concurrent/pom.xml | 2 +- dbpool/pom.xml | 2 +- discovery/pom.xml | 2 +- event/pom.xml | 2 +- http-client/pom.xml | 2 +- http-server/pom.xml | 2 +- log-manager/pom.xml | 2 +- pom.xml | 13 +++++++------ sample-server/pom.xml | 2 +- security/pom.xml | 2 +- stats/pom.xml | 2 +- units/pom.xml | 8 ++++---- 12 files changed, 21 insertions(+), 20 deletions(-) diff --git a/concurrent/pom.xml b/concurrent/pom.xml index 74753b1749..b6f6f4aa01 100644 --- a/concurrent/pom.xml +++ b/concurrent/pom.xml @@ -17,7 +17,7 @@ - io.airlift + com.facebook.airlift units diff --git a/dbpool/pom.xml b/dbpool/pom.xml index e3df6ef595..5256c3aaa5 100644 --- a/dbpool/pom.xml +++ b/dbpool/pom.xml @@ -32,7 +32,7 @@ - io.airlift + com.facebook.airlift units diff --git a/discovery/pom.xml b/discovery/pom.xml index 0be459fcac..cd2dfcca85 100644 --- a/discovery/pom.xml +++ b/discovery/pom.xml @@ -31,7 +31,7 @@ - io.airlift + com.facebook.airlift units diff --git a/event/pom.xml b/event/pom.xml index 0d67014dd1..59b54b79d8 100644 --- a/event/pom.xml +++ b/event/pom.xml @@ -36,7 +36,7 @@ - io.airlift + com.facebook.airlift units diff --git a/http-client/pom.xml b/http-client/pom.xml index 448ed7f885..b375c1c614 100644 --- a/http-client/pom.xml +++ b/http-client/pom.xml @@ -71,7 +71,7 @@ - io.airlift + com.facebook.airlift units diff --git a/http-server/pom.xml b/http-server/pom.xml index d2a2eb4ae8..df699e7f92 100644 --- a/http-server/pom.xml +++ b/http-server/pom.xml @@ -27,7 +27,7 @@ - io.airlift + com.facebook.airlift units diff --git a/log-manager/pom.xml b/log-manager/pom.xml index adc32c6fc9..aa012acbca 100644 --- a/log-manager/pom.xml +++ b/log-manager/pom.xml @@ -27,7 +27,7 @@ - io.airlift + com.facebook.airlift units diff --git a/pom.xml b/pom.xml index ae4347903d..f923a8850f 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,7 @@ stats testing trace-token + units skeleton-server @@ -167,6 +168,12 @@ ${dep.airlift.version} + + com.facebook.airlift + units + ${dep.airlift.version} + + com.facebook.airlift json @@ -297,12 +304,6 @@ ${dep.airlift.version} - - io.airlift - units - 1.0 - - mysql mysql-connector-java diff --git a/sample-server/pom.xml b/sample-server/pom.xml index f9d1c1847a..6c43d4c50a 100644 --- a/sample-server/pom.xml +++ b/sample-server/pom.xml @@ -118,7 +118,7 @@ - io.airlift + com.facebook.airlift units diff --git a/security/pom.xml b/security/pom.xml index a0e8e83a2d..54b0294766 100644 --- a/security/pom.xml +++ b/security/pom.xml @@ -22,7 +22,7 @@ - io.airlift + com.facebook.airlift units diff --git a/stats/pom.xml b/stats/pom.xml index 5714ff4744..392540f885 100644 --- a/stats/pom.xml +++ b/stats/pom.xml @@ -33,7 +33,7 @@ - io.airlift + com.facebook.airlift units diff --git a/units/pom.xml b/units/pom.xml index fa4537b28a..3de9d2266f 100644 --- a/units/pom.xml +++ b/units/pom.xml @@ -2,7 +2,7 @@ 4.0.0 units - 1.4-SNAPSHOT + 0.216-SNAPSHOT jar units @@ -10,9 +10,9 @@ https://github.com/airlift/units - io.airlift - airbase - 91 + com.facebook.airlift + airlift + 0.216-SNAPSHOT 2016 From af9ce64b5ca4462abc935b9519c39cf0adce8463 Mon Sep 17 00:00:00 2001 From: Zac Blanco Date: Fri, 8 Nov 2024 12:24:52 -0800 Subject: [PATCH 3/3] move package io.airlift.units to com.facebook.airlift.units --- .../airlift/concurrent/MoreFutures.java | 2 +- .../concurrent/ThreadPoolExecutorMBean.java | 2 +- .../airlift/concurrent/TestMoreFutures.java | 2 +- .../airlift/dbpool/ManagedDataSource.java | 4 ++-- .../dbpool/ManagedDataSourceConfig.java | 2 +- .../airlift/dbpool/ManagedDataSourceStats.java | 2 +- .../airlift/dbpool/PooledDataSource.java | 2 +- .../airlift/dbpool/ManagedDataSourceTest.java | 4 ++-- .../airlift/dbpool/MockManagedDataSource.java | 2 +- .../dbpool/TestH2EmbeddedDataSourceConfig.java | 2 +- .../dbpool/TestMySqlDataSourceConfig.java | 2 +- .../dbpool/TestPostgreSqlDataSourceConfig.java | 2 +- .../airlift/discovery/client/Announcer.java | 2 +- .../client/CachingServiceSelector.java | 2 +- .../client/DiscoveryAnnouncementClient.java | 2 +- .../discovery/client/ExponentialBackOff.java | 2 +- .../HttpDiscoveryAnnouncementClient.java | 2 +- .../client/HttpDiscoveryLookupClient.java | 2 +- .../discovery/client/ServiceDescriptors.java | 2 +- .../discovery/client/ServiceInventory.java | 2 +- .../client/ServiceInventoryConfig.java | 2 +- .../testing/InMemoryDiscoveryClient.java | 2 +- .../discovery/client/TestAnnouncer.java | 2 +- .../client/TestServiceInventoryConfig.java | 2 +- .../event/client/TestHttpEventClient.java | 2 +- .../airlift/http/client/HttpClientConfig.java | 16 ++++++++-------- .../airlift/http/client/RequestStats.java | 2 +- .../jetty/BufferingResponseListener.java | 6 +++--- .../client/jetty/DefaultHttpClientLogger.java | 4 ++-- .../http/client/jetty/JettyHttpClient.java | 2 +- .../client/spnego/SpnegoAuthentication.java | 2 +- .../spnego/SpnegoAuthenticationStore.java | 2 +- .../http/client/testing/TestingHttpClient.java | 2 +- .../http/client/AbstractHttpClientTest.java | 4 ++-- .../http/client/TestHttpClientBinder.java | 2 +- .../http/client/TestHttpClientConfig.java | 10 +++++----- .../client/jetty/TestHttpClientLogger.java | 6 +++--- .../http/server/AsyncResponseHandler.java | 2 +- .../http/server/DelimitedRequestLog.java | 4 ++-- .../airlift/http/server/HttpServerConfig.java | 14 +++++++------- .../airlift/http/server/RequestStats.java | 2 +- .../http/server/StatsRecordingHandler.java | 2 +- .../http/server/TestHttpServerConfig.java | 10 +++++----- .../server/testing/TestTestingHttpServer.java | 2 +- .../airlift/log/LoggingConfiguration.java | 6 +++--- .../airlift/log/RollingFileHandler.java | 4 ++-- .../airlift/log/TestLoggingConfiguration.java | 4 ++-- .../facebook/airlift/sample/StoreConfig.java | 2 +- .../airlift/sample/TestPersonStore.java | 2 +- .../airlift/sample/TestStoreConfig.java | 2 +- .../airlift/security/ReloadableSslContext.java | 2 +- .../com/facebook/airlift/stats/CpuTimer.java | 2 +- .../com/facebook/airlift/stats/GcMonitor.java | 2 +- .../facebook/airlift/stats/JmxGcMonitor.java | 2 +- .../com/facebook/airlift/stats/PauseMeter.java | 2 +- .../airlift/stats/TestingGcMonitor.java | 2 +- .../com/facebook/airlift/stats/TimeStat.java | 2 +- .../com/facebook/airlift/stats/TimedStat.java | 2 +- .../GarbageCollectionNotificationInfo.java | 4 ++-- .../airlift/stats/TestJmxGcMonitor.java | 2 +- .../airlift/stats/TestTestingGcMonitor.java | 2 +- .../facebook}/airlift/units/DataSize.java | 6 +++--- .../facebook}/airlift/units/Duration.java | 4 ++-- .../facebook}/airlift/units/MaxDataSize.java | 4 ++-- .../airlift/units/MaxDataSizeValidator.java | 2 +- .../facebook}/airlift/units/MaxDuration.java | 4 ++-- .../airlift/units/MaxDurationValidator.java | 2 +- .../facebook}/airlift/units/MinDataSize.java | 4 ++-- .../airlift/units/MinDataSizeValidator.java | 2 +- .../facebook}/airlift/units/MinDuration.java | 4 ++-- .../airlift/units/MinDurationValidator.java | 2 +- .../facebook}/airlift/units/Preconditions.java | 2 +- .../resources/ValidationMessages.properties | 8 ++++---- .../units/ConstraintValidatorAssert.java | 2 +- .../airlift/units/MockMaxDataSize.java | 2 +- .../airlift/units/MockMaxDuration.java | 2 +- .../airlift/units/MockMinDataSize.java | 2 +- .../airlift/units/MockMinDuration.java | 2 +- .../facebook}/airlift/units/TestDataSize.java | 18 +++++++++--------- .../airlift/units/TestDataSizeValidator.java | 14 +++++++------- .../facebook}/airlift/units/TestDuration.java | 6 +++--- .../airlift/units/TestDurationValidator.java | 8 ++++---- 82 files changed, 146 insertions(+), 146 deletions(-) rename units/src/main/java/{io => com/facebook}/airlift/units/DataSize.java (97%) rename units/src/main/java/{io => com/facebook}/airlift/units/Duration.java (98%) rename units/src/main/java/{io => com/facebook}/airlift/units/MaxDataSize.java (92%) rename units/src/main/java/{io => com/facebook}/airlift/units/MaxDataSizeValidator.java (97%) rename units/src/main/java/{io => com/facebook}/airlift/units/MaxDuration.java (92%) rename units/src/main/java/{io => com/facebook}/airlift/units/MaxDurationValidator.java (97%) rename units/src/main/java/{io => com/facebook}/airlift/units/MinDataSize.java (92%) rename units/src/main/java/{io => com/facebook}/airlift/units/MinDataSizeValidator.java (97%) rename units/src/main/java/{io => com/facebook}/airlift/units/MinDuration.java (92%) rename units/src/main/java/{io => com/facebook}/airlift/units/MinDurationValidator.java (97%) rename units/src/main/java/{io => com/facebook}/airlift/units/Preconditions.java (98%) rename units/src/test/java/{io => com/facebook}/airlift/units/ConstraintValidatorAssert.java (98%) rename units/src/test/java/{io => com/facebook}/airlift/units/MockMaxDataSize.java (97%) rename units/src/test/java/{io => com/facebook}/airlift/units/MockMaxDuration.java (97%) rename units/src/test/java/{io => com/facebook}/airlift/units/MockMinDataSize.java (97%) rename units/src/test/java/{io => com/facebook}/airlift/units/MockMinDuration.java (97%) rename units/src/test/java/{io => com/facebook}/airlift/units/TestDataSize.java (96%) rename units/src/test/java/{io => com/facebook}/airlift/units/TestDataSizeValidator.java (94%) rename units/src/test/java/{io => com/facebook}/airlift/units/TestDuration.java (99%) rename units/src/test/java/{io => com/facebook}/airlift/units/TestDurationValidator.java (96%) diff --git a/concurrent/src/main/java/com/facebook/airlift/concurrent/MoreFutures.java b/concurrent/src/main/java/com/facebook/airlift/concurrent/MoreFutures.java index 0a6f23a56c..92e4d7def0 100644 --- a/concurrent/src/main/java/com/facebook/airlift/concurrent/MoreFutures.java +++ b/concurrent/src/main/java/com/facebook/airlift/concurrent/MoreFutures.java @@ -1,12 +1,12 @@ package com.facebook.airlift.concurrent; +import com.facebook.airlift.units.Duration; import com.google.common.util.concurrent.AsyncFunction; import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; -import io.airlift.units.Duration; import javax.annotation.Nullable; diff --git a/concurrent/src/main/java/com/facebook/airlift/concurrent/ThreadPoolExecutorMBean.java b/concurrent/src/main/java/com/facebook/airlift/concurrent/ThreadPoolExecutorMBean.java index 15e852e58e..e5de1e3aec 100644 --- a/concurrent/src/main/java/com/facebook/airlift/concurrent/ThreadPoolExecutorMBean.java +++ b/concurrent/src/main/java/com/facebook/airlift/concurrent/ThreadPoolExecutorMBean.java @@ -1,7 +1,7 @@ package com.facebook.airlift.concurrent; +import com.facebook.airlift.units.Duration; import com.google.common.annotations.Beta; -import io.airlift.units.Duration; import org.weakref.jmx.Managed; import java.util.concurrent.ThreadPoolExecutor; diff --git a/concurrent/src/test/java/com/facebook/airlift/concurrent/TestMoreFutures.java b/concurrent/src/test/java/com/facebook/airlift/concurrent/TestMoreFutures.java index 27cba2e41a..0d344c1760 100644 --- a/concurrent/src/test/java/com/facebook/airlift/concurrent/TestMoreFutures.java +++ b/concurrent/src/test/java/com/facebook/airlift/concurrent/TestMoreFutures.java @@ -1,9 +1,9 @@ package com.facebook.airlift.concurrent; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; -import io.airlift.units.Duration; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; diff --git a/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSource.java b/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSource.java index 734fe05d84..c56cb4aada 100644 --- a/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSource.java +++ b/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSource.java @@ -15,8 +15,8 @@ */ package com.facebook.airlift.dbpool; +import com.facebook.airlift.units.Duration; import com.google.common.primitives.Ints; -import io.airlift.units.Duration; import org.weakref.jmx.Flatten; import org.weakref.jmx.Managed; @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; -import static io.airlift.units.Duration.nanosSince; +import static com.facebook.airlift.units.Duration.nanosSince; import static java.lang.Math.ceil; public abstract class ManagedDataSource diff --git a/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSourceConfig.java b/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSourceConfig.java index 09b90e3102..5ef1a99832 100644 --- a/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSourceConfig.java +++ b/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSourceConfig.java @@ -17,7 +17,7 @@ import com.facebook.airlift.configuration.Config; import com.facebook.airlift.configuration.DefunctConfig; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import java.util.concurrent.TimeUnit; diff --git a/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSourceStats.java b/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSourceStats.java index 03437152fc..0845a91782 100644 --- a/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSourceStats.java +++ b/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSourceStats.java @@ -16,7 +16,7 @@ package com.facebook.airlift.dbpool; import com.facebook.airlift.stats.TimeStat; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import org.weakref.jmx.Managed; import org.weakref.jmx.Nested; diff --git a/dbpool/src/main/java/com/facebook/airlift/dbpool/PooledDataSource.java b/dbpool/src/main/java/com/facebook/airlift/dbpool/PooledDataSource.java index 7e333a045a..f07c1cb9c5 100644 --- a/dbpool/src/main/java/com/facebook/airlift/dbpool/PooledDataSource.java +++ b/dbpool/src/main/java/com/facebook/airlift/dbpool/PooledDataSource.java @@ -15,7 +15,7 @@ */ package com.facebook.airlift.dbpool; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import javax.sql.ConnectionPoolDataSource; import javax.sql.PooledConnection; diff --git a/dbpool/src/test/java/com/facebook/airlift/dbpool/ManagedDataSourceTest.java b/dbpool/src/test/java/com/facebook/airlift/dbpool/ManagedDataSourceTest.java index 18c595cd34..de81973fe8 100644 --- a/dbpool/src/test/java/com/facebook/airlift/dbpool/ManagedDataSourceTest.java +++ b/dbpool/src/test/java/com/facebook/airlift/dbpool/ManagedDataSourceTest.java @@ -16,7 +16,7 @@ package com.facebook.airlift.dbpool; import com.facebook.airlift.dbpool.MockConnectionPoolDataSource.MockConnection; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import org.testng.annotations.Test; import javax.sql.ConnectionPoolDataSource; @@ -37,7 +37,7 @@ import static com.facebook.airlift.testing.Assertions.assertGreaterThan; import static com.facebook.airlift.testing.Assertions.assertInstanceOf; -import static io.airlift.units.Duration.nanosSince; +import static com.facebook.airlift.units.Duration.nanosSince; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.SECONDS; import static org.testng.Assert.assertEquals; diff --git a/dbpool/src/test/java/com/facebook/airlift/dbpool/MockManagedDataSource.java b/dbpool/src/test/java/com/facebook/airlift/dbpool/MockManagedDataSource.java index 7bdd55198b..99d43859ed 100644 --- a/dbpool/src/test/java/com/facebook/airlift/dbpool/MockManagedDataSource.java +++ b/dbpool/src/test/java/com/facebook/airlift/dbpool/MockManagedDataSource.java @@ -15,7 +15,7 @@ */ package com.facebook.airlift.dbpool; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import javax.sql.PooledConnection; diff --git a/dbpool/src/test/java/com/facebook/airlift/dbpool/TestH2EmbeddedDataSourceConfig.java b/dbpool/src/test/java/com/facebook/airlift/dbpool/TestH2EmbeddedDataSourceConfig.java index 0a831b9e69..4a6d33b966 100644 --- a/dbpool/src/test/java/com/facebook/airlift/dbpool/TestH2EmbeddedDataSourceConfig.java +++ b/dbpool/src/test/java/com/facebook/airlift/dbpool/TestH2EmbeddedDataSourceConfig.java @@ -1,8 +1,8 @@ package com.facebook.airlift.dbpool; import com.facebook.airlift.configuration.testing.ConfigAssertions; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableMap; -import io.airlift.units.Duration; import org.testng.annotations.Test; import javax.validation.constraints.NotNull; diff --git a/dbpool/src/test/java/com/facebook/airlift/dbpool/TestMySqlDataSourceConfig.java b/dbpool/src/test/java/com/facebook/airlift/dbpool/TestMySqlDataSourceConfig.java index e78a83ca15..24581204f5 100644 --- a/dbpool/src/test/java/com/facebook/airlift/dbpool/TestMySqlDataSourceConfig.java +++ b/dbpool/src/test/java/com/facebook/airlift/dbpool/TestMySqlDataSourceConfig.java @@ -1,8 +1,8 @@ package com.facebook.airlift.dbpool; import com.facebook.airlift.configuration.testing.ConfigAssertions; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableMap; -import io.airlift.units.Duration; import org.testng.annotations.Test; import java.util.Map; diff --git a/dbpool/src/test/java/com/facebook/airlift/dbpool/TestPostgreSqlDataSourceConfig.java b/dbpool/src/test/java/com/facebook/airlift/dbpool/TestPostgreSqlDataSourceConfig.java index 97f367f8ec..ed9c2fef4a 100644 --- a/dbpool/src/test/java/com/facebook/airlift/dbpool/TestPostgreSqlDataSourceConfig.java +++ b/dbpool/src/test/java/com/facebook/airlift/dbpool/TestPostgreSqlDataSourceConfig.java @@ -1,8 +1,8 @@ package com.facebook.airlift.dbpool; import com.facebook.airlift.configuration.testing.ConfigAssertions; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableMap; -import io.airlift.units.Duration; import org.testng.annotations.Test; import java.util.Map; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/Announcer.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/Announcer.java index 2524537ce1..1403cce4b2 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/Announcer.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/Announcer.java @@ -17,13 +17,13 @@ import com.facebook.airlift.concurrent.ThreadPoolExecutorMBean; import com.facebook.airlift.log.Logger; +import com.facebook.airlift.units.Duration; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.MapMaker; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import io.airlift.units.Duration; import org.weakref.jmx.Managed; import org.weakref.jmx.Nested; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/CachingServiceSelector.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/CachingServiceSelector.java index 977a717b63..84d188d45f 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/CachingServiceSelector.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/CachingServiceSelector.java @@ -16,13 +16,13 @@ package com.facebook.airlift.discovery.client; import com.facebook.airlift.log.Logger; +import com.facebook.airlift.units.Duration; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; -import io.airlift.units.Duration; import javax.annotation.PostConstruct; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/DiscoveryAnnouncementClient.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/DiscoveryAnnouncementClient.java index d5fd77063c..91fef3f1ed 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/DiscoveryAnnouncementClient.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/DiscoveryAnnouncementClient.java @@ -15,8 +15,8 @@ */ package com.facebook.airlift.discovery.client; +import com.facebook.airlift.units.Duration; import com.google.common.util.concurrent.ListenableFuture; -import io.airlift.units.Duration; import java.util.Set; import java.util.concurrent.TimeUnit; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/ExponentialBackOff.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/ExponentialBackOff.java index a3d7f60ee7..0cf6e23593 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/ExponentialBackOff.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/ExponentialBackOff.java @@ -1,7 +1,7 @@ package com.facebook.airlift.discovery.client; import com.facebook.airlift.log.Logger; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import javax.annotation.concurrent.GuardedBy; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/HttpDiscoveryAnnouncementClient.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/HttpDiscoveryAnnouncementClient.java index 461e149de0..102e40224e 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/HttpDiscoveryAnnouncementClient.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/HttpDiscoveryAnnouncementClient.java @@ -22,11 +22,11 @@ import com.facebook.airlift.http.client.ResponseHandler; import com.facebook.airlift.json.JsonCodec; import com.facebook.airlift.node.NodeInfo; +import com.facebook.airlift.units.Duration; import com.google.common.io.CharStreams; import com.google.common.net.HttpHeaders; import com.google.common.net.MediaType; import com.google.common.util.concurrent.ListenableFuture; -import io.airlift.units.Duration; import javax.inject.Inject; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/HttpDiscoveryLookupClient.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/HttpDiscoveryLookupClient.java index 923d3483d0..2ffada639e 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/HttpDiscoveryLookupClient.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/HttpDiscoveryLookupClient.java @@ -24,10 +24,10 @@ import com.facebook.airlift.http.client.ResponseHandler; import com.facebook.airlift.json.JsonCodec; import com.facebook.airlift.node.NodeInfo; +import com.facebook.airlift.units.Duration; import com.google.common.io.ByteStreams; import com.google.common.net.HttpHeaders; import com.google.common.util.concurrent.ListenableFuture; -import io.airlift.units.Duration; import org.weakref.jmx.Flatten; import org.weakref.jmx.Managed; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceDescriptors.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceDescriptors.java index 593a79aefd..252e4fee9c 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceDescriptors.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceDescriptors.java @@ -15,8 +15,8 @@ */ package com.facebook.airlift.discovery.client; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableList; -import io.airlift.units.Duration; import java.util.List; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceInventory.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceInventory.java index c1bb3d9807..2a5823e26c 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceInventory.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceInventory.java @@ -20,9 +20,9 @@ import com.facebook.airlift.json.JsonCodec; import com.facebook.airlift.log.Logger; import com.facebook.airlift.node.NodeInfo; +import com.facebook.airlift.units.Duration; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import io.airlift.units.Duration; import org.weakref.jmx.Managed; import javax.annotation.PostConstruct; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceInventoryConfig.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceInventoryConfig.java index 435c4b306d..cd9c819fe4 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceInventoryConfig.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceInventoryConfig.java @@ -17,7 +17,7 @@ import com.facebook.airlift.configuration.Config; import com.facebook.airlift.configuration.ConfigDescription; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import javax.validation.constraints.NotNull; diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/testing/InMemoryDiscoveryClient.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/testing/InMemoryDiscoveryClient.java index 0f87ba0e7c..29742fc2a5 100644 --- a/discovery/src/main/java/com/facebook/airlift/discovery/client/testing/InMemoryDiscoveryClient.java +++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/testing/InMemoryDiscoveryClient.java @@ -21,11 +21,11 @@ import com.facebook.airlift.discovery.client.ServiceDescriptor; import com.facebook.airlift.discovery.client.ServiceDescriptors; import com.facebook.airlift.node.NodeInfo; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.MapMaker; import com.google.common.util.concurrent.ListenableFuture; -import io.airlift.units.Duration; import javax.inject.Inject; diff --git a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestAnnouncer.java b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestAnnouncer.java index 19e57764fc..49cd0d92c6 100644 --- a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestAnnouncer.java +++ b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestAnnouncer.java @@ -18,9 +18,9 @@ import com.facebook.airlift.discovery.client.testing.InMemoryDiscoveryClient; import com.facebook.airlift.node.NodeConfig; import com.facebook.airlift.node.NodeInfo; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import io.airlift.units.Duration; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestServiceInventoryConfig.java b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestServiceInventoryConfig.java index 3db2038efc..c0aa62a519 100644 --- a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestServiceInventoryConfig.java +++ b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestServiceInventoryConfig.java @@ -16,8 +16,8 @@ package com.facebook.airlift.discovery.client; import com.facebook.airlift.configuration.testing.ConfigAssertions; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableMap; -import io.airlift.units.Duration; import org.testng.annotations.Test; import java.net.URI; diff --git a/event/src/test/java/com/facebook/airlift/event/client/TestHttpEventClient.java b/event/src/test/java/com/facebook/airlift/event/client/TestHttpEventClient.java index 8b1af04f00..1287f77610 100644 --- a/event/src/test/java/com/facebook/airlift/event/client/TestHttpEventClient.java +++ b/event/src/test/java/com/facebook/airlift/event/client/TestHttpEventClient.java @@ -21,8 +21,8 @@ import com.facebook.airlift.http.client.HttpClientConfig; import com.facebook.airlift.http.client.jetty.JettyHttpClient; import com.facebook.airlift.node.NodeInfo; +import com.facebook.airlift.units.Duration; import com.google.common.io.CharStreams; -import io.airlift.units.Duration; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/HttpClientConfig.java b/http-client/src/main/java/com/facebook/airlift/http/client/HttpClientConfig.java index 7a23325836..d146a68a6c 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/HttpClientConfig.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/HttpClientConfig.java @@ -19,15 +19,15 @@ import com.facebook.airlift.configuration.ConfigDescription; import com.facebook.airlift.configuration.ConfigSecuritySensitive; import com.facebook.airlift.configuration.LegacyConfig; +import com.facebook.airlift.units.DataSize; +import com.facebook.airlift.units.Duration; +import com.facebook.airlift.units.MaxDataSize; +import com.facebook.airlift.units.MinDataSize; +import com.facebook.airlift.units.MinDuration; import com.google.common.annotations.Beta; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.net.HostAndPort; -import io.airlift.units.DataSize; -import io.airlift.units.Duration; -import io.airlift.units.MaxDataSize; -import io.airlift.units.MinDataSize; -import io.airlift.units.MinDuration; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; @@ -35,9 +35,9 @@ import java.util.List; import static com.facebook.airlift.http.client.KerberosNameType.HOSTBASED_SERVICE; -import static io.airlift.units.DataSize.Unit.GIGABYTE; -import static io.airlift.units.DataSize.Unit.KILOBYTE; -import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.GIGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.KILOBYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/RequestStats.java b/http-client/src/main/java/com/facebook/airlift/http/client/RequestStats.java index dd59c0f34c..55e43479f3 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/RequestStats.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/RequestStats.java @@ -18,8 +18,8 @@ import com.facebook.airlift.stats.CounterStat; import com.facebook.airlift.stats.DistributionStat; import com.facebook.airlift.stats.TimeStat; +import com.facebook.airlift.units.Duration; import com.google.common.annotations.Beta; -import io.airlift.units.Duration; import org.weakref.jmx.Managed; import org.weakref.jmx.Nested; diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/BufferingResponseListener.java b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/BufferingResponseListener.java index f9da9cbdbf..e60bbb90e8 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/BufferingResponseListener.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/BufferingResponseListener.java @@ -2,7 +2,7 @@ import com.facebook.airlift.http.client.GatheringByteArrayInputStream; import com.facebook.airlift.http.client.ResponseTooLargeException; -import io.airlift.units.DataSize; +import com.facebook.airlift.units.DataSize; import org.eclipse.jetty.client.api.Response; import org.eclipse.jetty.client.api.Result; import org.eclipse.jetty.http.HttpHeader; @@ -14,10 +14,10 @@ import java.util.ArrayList; import java.util.List; +import static com.facebook.airlift.units.DataSize.Unit.KILOBYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; -import static io.airlift.units.DataSize.Unit.KILOBYTE; -import static io.airlift.units.DataSize.Unit.MEGABYTE; import static java.lang.Math.max; import static java.lang.Math.min; import static java.util.Objects.requireNonNull; diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/DefaultHttpClientLogger.java b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/DefaultHttpClientLogger.java index 5fd806ffc1..0917b57497 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/DefaultHttpClientLogger.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/DefaultHttpClientLogger.java @@ -21,8 +21,8 @@ import ch.qos.logback.core.status.ErrorStatus; import ch.qos.logback.core.util.FileSize; import com.facebook.airlift.log.Logger; -import io.airlift.units.DataSize; -import io.airlift.units.Duration; +import com.facebook.airlift.units.DataSize; +import com.facebook.airlift.units.Duration; import java.io.File; import java.io.IOException; diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyHttpClient.java b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyHttpClient.java index 2cabdab0e1..d48ba9a7b3 100755 --- a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyHttpClient.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyHttpClient.java @@ -15,10 +15,10 @@ import com.facebook.airlift.http.client.spnego.SpnegoAuthenticationProtocolHandler; import com.facebook.airlift.http.client.spnego.SpnegoAuthenticationStore; import com.facebook.airlift.security.pem.PemReader; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableList; import com.google.common.net.HostAndPort; import com.google.common.primitives.Ints; -import io.airlift.units.Duration; import org.eclipse.jetty.client.DuplexConnectionPool; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClientTransport; diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/spnego/SpnegoAuthentication.java b/http-client/src/main/java/com/facebook/airlift/http/client/spnego/SpnegoAuthentication.java index 7a46cf6784..92cb10529e 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/spnego/SpnegoAuthentication.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/spnego/SpnegoAuthentication.java @@ -2,10 +2,10 @@ import com.facebook.airlift.http.client.KerberosNameType; import com.facebook.airlift.log.Logger; +import com.facebook.airlift.units.Duration; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.sun.security.auth.module.Krb5LoginModule; -import io.airlift.units.Duration; import net.jodah.failsafe.Failsafe; import net.jodah.failsafe.RetryPolicy; import org.eclipse.jetty.client.api.Authentication; diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/spnego/SpnegoAuthenticationStore.java b/http-client/src/main/java/com/facebook/airlift/http/client/spnego/SpnegoAuthenticationStore.java index 5198ae26f9..9ec1120db0 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/spnego/SpnegoAuthenticationStore.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/spnego/SpnegoAuthenticationStore.java @@ -1,8 +1,8 @@ package com.facebook.airlift.http.client.spnego; +import com.facebook.airlift.units.Duration; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import io.airlift.units.Duration; import org.eclipse.jetty.client.api.Authentication; import org.eclipse.jetty.client.api.AuthenticationStore; diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/testing/TestingHttpClient.java b/http-client/src/main/java/com/facebook/airlift/http/client/testing/TestingHttpClient.java index 250821cd5a..6a4ea19edc 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/testing/TestingHttpClient.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/testing/TestingHttpClient.java @@ -6,10 +6,10 @@ import com.facebook.airlift.http.client.RequestStats; import com.facebook.airlift.http.client.Response; import com.facebook.airlift.http.client.ResponseHandler; +import com.facebook.airlift.units.Duration; import com.google.common.util.concurrent.ForwardingListenableFuture; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; -import io.airlift.units.Duration; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/http-client/src/test/java/com/facebook/airlift/http/client/AbstractHttpClientTest.java b/http-client/src/test/java/com/facebook/airlift/http/client/AbstractHttpClientTest.java index f2dce9afe8..2c222f8cd8 100755 --- a/http-client/src/test/java/com/facebook/airlift/http/client/AbstractHttpClientTest.java +++ b/http-client/src/test/java/com/facebook/airlift/http/client/AbstractHttpClientTest.java @@ -6,8 +6,8 @@ import com.facebook.airlift.http.client.jetty.JettyHttpClient; import com.facebook.airlift.log.Logging; import com.facebook.airlift.testing.Closeables; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableList; -import io.airlift.units.Duration; import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -66,6 +66,7 @@ import static com.facebook.airlift.testing.Assertions.assertGreaterThanOrEqual; import static com.facebook.airlift.testing.Assertions.assertLessThan; import static com.facebook.airlift.testing.Closeables.closeQuietly; +import static com.facebook.airlift.units.Duration.nanosSince; import static com.google.common.base.Throwables.getStackTraceAsString; import static com.google.common.base.Throwables.propagateIfPossible; import static com.google.common.base.Throwables.throwIfUnchecked; @@ -75,7 +76,6 @@ import static com.google.common.net.HttpHeaders.CONTENT_TYPE; import static com.google.common.net.HttpHeaders.LOCATION; import static com.google.common.net.HttpHeaders.USER_AGENT; -import static io.airlift.units.Duration.nanosSince; import static java.lang.String.format; import static java.lang.Thread.currentThread; import static java.nio.charset.StandardCharsets.UTF_8; diff --git a/http-client/src/test/java/com/facebook/airlift/http/client/TestHttpClientBinder.java b/http-client/src/test/java/com/facebook/airlift/http/client/TestHttpClientBinder.java index bd786dbbc5..39832374ff 100644 --- a/http-client/src/test/java/com/facebook/airlift/http/client/TestHttpClientBinder.java +++ b/http-client/src/test/java/com/facebook/airlift/http/client/TestHttpClientBinder.java @@ -19,10 +19,10 @@ import com.facebook.airlift.bootstrap.LifeCycleManager; import com.facebook.airlift.http.client.jetty.JettyHttpClient; import com.facebook.airlift.tracetoken.TraceTokenModule; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableList; import com.google.inject.Injector; import com.google.inject.Key; -import io.airlift.units.Duration; import org.testng.annotations.Test; import javax.inject.Qualifier; diff --git a/http-client/src/test/java/com/facebook/airlift/http/client/TestHttpClientConfig.java b/http-client/src/test/java/com/facebook/airlift/http/client/TestHttpClientConfig.java index 7217d8bfd7..807af07d12 100644 --- a/http-client/src/test/java/com/facebook/airlift/http/client/TestHttpClientConfig.java +++ b/http-client/src/test/java/com/facebook/airlift/http/client/TestHttpClientConfig.java @@ -16,10 +16,10 @@ package com.facebook.airlift.http.client; import com.facebook.airlift.configuration.testing.ConfigAssertions; +import com.facebook.airlift.units.DataSize; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableMap; import com.google.common.net.HostAndPort; -import io.airlift.units.DataSize; -import io.airlift.units.Duration; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.testng.annotations.Test; @@ -36,9 +36,9 @@ import static com.facebook.airlift.http.client.KerberosNameType.HOSTBASED_SERVICE; import static com.facebook.airlift.http.client.KerberosNameType.USER_NAME; import static com.facebook.airlift.testing.ValidationAssertions.assertFailsValidation; -import static io.airlift.units.DataSize.Unit.GIGABYTE; -import static io.airlift.units.DataSize.Unit.KILOBYTE; -import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.GIGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.KILOBYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; diff --git a/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestHttpClientLogger.java b/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestHttpClientLogger.java index 0baf6716ed..71a6ad4d51 100644 --- a/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestHttpClientLogger.java +++ b/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestHttpClientLogger.java @@ -15,9 +15,9 @@ import com.facebook.airlift.http.client.jetty.HttpClientLogger.RequestInfo; import com.facebook.airlift.http.client.jetty.HttpClientLogger.ResponseInfo; +import com.facebook.airlift.units.DataSize; +import com.facebook.airlift.units.Duration; import com.google.common.io.Files; -import io.airlift.units.DataSize; -import io.airlift.units.Duration; import org.eclipse.jetty.client.api.ContentProvider; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; @@ -50,7 +50,7 @@ import static com.facebook.airlift.http.client.TraceTokenRequestFilter.TRACETOKEN_HEADER; import static com.facebook.airlift.http.client.jetty.HttpRequestEvent.NO_RESPONSE; import static com.facebook.airlift.http.client.jetty.HttpRequestEvent.getFailureReason; -import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.file.Files.readAllLines; import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME; diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/AsyncResponseHandler.java b/http-server/src/main/java/com/facebook/airlift/http/server/AsyncResponseHandler.java index 3fc78db045..1a832196b5 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/AsyncResponseHandler.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/AsyncResponseHandler.java @@ -13,11 +13,11 @@ */ package com.facebook.airlift.http.server; +import com.facebook.airlift.units.Duration; import com.google.common.annotations.Beta; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import io.airlift.units.Duration; import javax.ws.rs.container.AsyncResponse; import javax.ws.rs.core.Response; diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/DelimitedRequestLog.java b/http-server/src/main/java/com/facebook/airlift/http/server/DelimitedRequestLog.java index 2c94487b1f..9b81ba85c8 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/DelimitedRequestLog.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/DelimitedRequestLog.java @@ -25,7 +25,7 @@ import com.facebook.airlift.event.client.EventClient; import com.facebook.airlift.log.Logger; import com.facebook.airlift.tracetoken.TraceTokenManager; -import io.airlift.units.DataSize; +import com.facebook.airlift.units.DataSize; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Response; @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicLong; import static com.facebook.airlift.http.server.HttpRequestEvent.createHttpRequestEvent; -import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; import static java.util.concurrent.TimeUnit.SECONDS; class DelimitedRequestLog diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/HttpServerConfig.java b/http-server/src/main/java/com/facebook/airlift/http/server/HttpServerConfig.java index 2e3927ccbd..1d5c3077ec 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/HttpServerConfig.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/HttpServerConfig.java @@ -19,14 +19,14 @@ import com.facebook.airlift.configuration.ConfigDescription; import com.facebook.airlift.configuration.ConfigSecuritySensitive; import com.facebook.airlift.configuration.DefunctConfig; +import com.facebook.airlift.units.DataSize; +import com.facebook.airlift.units.Duration; +import com.facebook.airlift.units.MaxDataSize; +import com.facebook.airlift.units.MinDataSize; +import com.facebook.airlift.units.MinDuration; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import io.airlift.units.DataSize; -import io.airlift.units.Duration; -import io.airlift.units.MaxDataSize; -import io.airlift.units.MinDataSize; -import io.airlift.units.MinDuration; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; @@ -34,9 +34,9 @@ import java.util.List; import java.util.Set; +import static com.facebook.airlift.units.DataSize.Unit.KILOBYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; import static com.google.common.collect.ImmutableSet.toImmutableSet; -import static io.airlift.units.DataSize.Unit.KILOBYTE; -import static io.airlift.units.DataSize.Unit.MEGABYTE; import static java.util.Locale.ENGLISH; import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.HOURS; diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/RequestStats.java b/http-server/src/main/java/com/facebook/airlift/http/server/RequestStats.java index bf4bb2f074..1b034b689d 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/RequestStats.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/RequestStats.java @@ -18,7 +18,7 @@ import com.facebook.airlift.stats.CounterStat; import com.facebook.airlift.stats.DistributionStat; import com.facebook.airlift.stats.TimeStat; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import org.weakref.jmx.Flatten; import org.weakref.jmx.Managed; import org.weakref.jmx.Nested; diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/StatsRecordingHandler.java b/http-server/src/main/java/com/facebook/airlift/http/server/StatsRecordingHandler.java index 8c74f758e9..9d506fcea7 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/StatsRecordingHandler.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/StatsRecordingHandler.java @@ -15,7 +15,7 @@ */ package com.facebook.airlift.http.server; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.RequestLog; import org.eclipse.jetty.server.Response; diff --git a/http-server/src/test/java/com/facebook/airlift/http/server/TestHttpServerConfig.java b/http-server/src/test/java/com/facebook/airlift/http/server/TestHttpServerConfig.java index 066bdb71e0..354fdd0822 100644 --- a/http-server/src/test/java/com/facebook/airlift/http/server/TestHttpServerConfig.java +++ b/http-server/src/test/java/com/facebook/airlift/http/server/TestHttpServerConfig.java @@ -16,9 +16,9 @@ package com.facebook.airlift.http.server; import com.facebook.airlift.configuration.testing.ConfigAssertions; +import com.facebook.airlift.units.DataSize; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableMap; -import io.airlift.units.DataSize; -import io.airlift.units.Duration; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.testng.annotations.Test; @@ -26,9 +26,9 @@ import java.util.List; import java.util.Map; -import static io.airlift.units.DataSize.Unit.GIGABYTE; -import static io.airlift.units.DataSize.Unit.KILOBYTE; -import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.GIGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.KILOBYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; diff --git a/http-server/src/test/java/com/facebook/airlift/http/server/testing/TestTestingHttpServer.java b/http-server/src/test/java/com/facebook/airlift/http/server/testing/TestTestingHttpServer.java index bfc4aecda3..0ee065801a 100644 --- a/http-server/src/test/java/com/facebook/airlift/http/server/testing/TestTestingHttpServer.java +++ b/http-server/src/test/java/com/facebook/airlift/http/server/testing/TestTestingHttpServer.java @@ -30,13 +30,13 @@ import com.facebook.airlift.log.Logging; import com.facebook.airlift.node.NodeInfo; import com.facebook.airlift.node.testing.TestingNodeModule; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.net.HttpHeaders; import com.google.common.net.MediaType; import com.google.inject.Injector; import com.google.inject.TypeLiteral; -import io.airlift.units.Duration; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; diff --git a/log-manager/src/main/java/com/facebook/airlift/log/LoggingConfiguration.java b/log-manager/src/main/java/com/facebook/airlift/log/LoggingConfiguration.java index 77458f3ebb..a4c576d6b4 100644 --- a/log-manager/src/main/java/com/facebook/airlift/log/LoggingConfiguration.java +++ b/log-manager/src/main/java/com/facebook/airlift/log/LoggingConfiguration.java @@ -17,10 +17,10 @@ import com.facebook.airlift.configuration.Config; import com.facebook.airlift.configuration.LegacyConfig; -import io.airlift.units.DataSize; +import com.facebook.airlift.units.DataSize; -import static io.airlift.units.DataSize.Unit.BYTE; -import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.BYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; public class LoggingConfiguration { diff --git a/log-manager/src/main/java/com/facebook/airlift/log/RollingFileHandler.java b/log-manager/src/main/java/com/facebook/airlift/log/RollingFileHandler.java index 5297a8e9a9..2efb6bdb92 100644 --- a/log-manager/src/main/java/com/facebook/airlift/log/RollingFileHandler.java +++ b/log-manager/src/main/java/com/facebook/airlift/log/RollingFileHandler.java @@ -7,14 +7,14 @@ import ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP; import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; import ch.qos.logback.core.util.FileSize; -import io.airlift.units.DataSize; +import com.facebook.airlift.units.DataSize; import java.io.File; import java.util.logging.ErrorManager; import java.util.logging.Handler; import java.util.logging.LogRecord; -import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.logging.ErrorManager.CLOSE_FAILURE; diff --git a/log-manager/src/test/java/com/facebook/airlift/log/TestLoggingConfiguration.java b/log-manager/src/test/java/com/facebook/airlift/log/TestLoggingConfiguration.java index 2581f74dfc..7ac8a6169d 100644 --- a/log-manager/src/test/java/com/facebook/airlift/log/TestLoggingConfiguration.java +++ b/log-manager/src/test/java/com/facebook/airlift/log/TestLoggingConfiguration.java @@ -14,13 +14,13 @@ package com.facebook.airlift.log; import com.facebook.airlift.configuration.testing.ConfigAssertions; +import com.facebook.airlift.units.DataSize; import com.google.common.collect.ImmutableMap; -import io.airlift.units.DataSize; import org.testng.annotations.Test; import java.util.Map; -import static io.airlift.units.DataSize.Unit.KILOBYTE; +import static com.facebook.airlift.units.DataSize.Unit.KILOBYTE; @SuppressWarnings("deprecation") public class TestLoggingConfiguration diff --git a/sample-server/src/main/java/com/facebook/airlift/sample/StoreConfig.java b/sample-server/src/main/java/com/facebook/airlift/sample/StoreConfig.java index 227973714f..cac2f9051a 100644 --- a/sample-server/src/main/java/com/facebook/airlift/sample/StoreConfig.java +++ b/sample-server/src/main/java/com/facebook/airlift/sample/StoreConfig.java @@ -17,8 +17,8 @@ import com.facebook.airlift.configuration.Config; import com.facebook.airlift.configuration.LegacyConfig; +import com.facebook.airlift.units.Duration; import com.google.common.base.Preconditions; -import io.airlift.units.Duration; import javax.validation.constraints.NotNull; diff --git a/sample-server/src/test/java/com/facebook/airlift/sample/TestPersonStore.java b/sample-server/src/test/java/com/facebook/airlift/sample/TestPersonStore.java index 39ca516f30..65bb38e076 100644 --- a/sample-server/src/test/java/com/facebook/airlift/sample/TestPersonStore.java +++ b/sample-server/src/test/java/com/facebook/airlift/sample/TestPersonStore.java @@ -16,8 +16,8 @@ package com.facebook.airlift.sample; import com.facebook.airlift.event.client.InMemoryEventClient; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableList; -import io.airlift.units.Duration; import org.testng.annotations.Test; import java.util.concurrent.TimeUnit; diff --git a/sample-server/src/test/java/com/facebook/airlift/sample/TestStoreConfig.java b/sample-server/src/test/java/com/facebook/airlift/sample/TestStoreConfig.java index 939f81ae84..afa4d81a50 100644 --- a/sample-server/src/test/java/com/facebook/airlift/sample/TestStoreConfig.java +++ b/sample-server/src/test/java/com/facebook/airlift/sample/TestStoreConfig.java @@ -16,8 +16,8 @@ package com.facebook.airlift.sample; import com.facebook.airlift.configuration.testing.ConfigAssertions; +import com.facebook.airlift.units.Duration; import com.google.common.collect.ImmutableMap; -import io.airlift.units.Duration; import org.testng.annotations.Test; import java.util.Map; diff --git a/security/src/main/java/com/facebook/airlift/security/ReloadableSslContext.java b/security/src/main/java/com/facebook/airlift/security/ReloadableSslContext.java index c1ba7e1373..5da331d587 100644 --- a/security/src/main/java/com/facebook/airlift/security/ReloadableSslContext.java +++ b/security/src/main/java/com/facebook/airlift/security/ReloadableSslContext.java @@ -15,9 +15,9 @@ import com.facebook.airlift.log.Logger; import com.facebook.airlift.security.pem.PemReader; +import com.facebook.airlift.units.Duration; import com.google.common.hash.HashCode; import com.google.common.io.Files; -import io.airlift.units.Duration; import javax.annotation.concurrent.GuardedBy; import javax.net.ssl.KeyManager; diff --git a/stats/src/main/java/com/facebook/airlift/stats/CpuTimer.java b/stats/src/main/java/com/facebook/airlift/stats/CpuTimer.java index 68985e7a9d..b7c44b9fdd 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/CpuTimer.java +++ b/stats/src/main/java/com/facebook/airlift/stats/CpuTimer.java @@ -13,8 +13,8 @@ */ package com.facebook.airlift.stats; +import com.facebook.airlift.units.Duration; import com.google.common.annotations.Beta; -import io.airlift.units.Duration; import java.lang.management.ManagementFactory; import java.lang.management.ThreadMXBean; diff --git a/stats/src/main/java/com/facebook/airlift/stats/GcMonitor.java b/stats/src/main/java/com/facebook/airlift/stats/GcMonitor.java index b49da1186d..c4ebd279ff 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/GcMonitor.java +++ b/stats/src/main/java/com/facebook/airlift/stats/GcMonitor.java @@ -13,7 +13,7 @@ */ package com.facebook.airlift.stats; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; public interface GcMonitor { diff --git a/stats/src/main/java/com/facebook/airlift/stats/JmxGcMonitor.java b/stats/src/main/java/com/facebook/airlift/stats/JmxGcMonitor.java index 3abc59eddf..971d7471ab 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/JmxGcMonitor.java +++ b/stats/src/main/java/com/facebook/airlift/stats/JmxGcMonitor.java @@ -14,7 +14,7 @@ package com.facebook.airlift.stats; import com.facebook.airlift.log.Logger; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import org.weakref.jmx.Managed; import org.weakref.jmx.Nested; diff --git a/stats/src/main/java/com/facebook/airlift/stats/PauseMeter.java b/stats/src/main/java/com/facebook/airlift/stats/PauseMeter.java index 68e178c9ac..c5a06d003f 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/PauseMeter.java +++ b/stats/src/main/java/com/facebook/airlift/stats/PauseMeter.java @@ -14,9 +14,9 @@ package com.facebook.airlift.stats; import com.facebook.airlift.log.Logger; +import com.facebook.airlift.units.Duration; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import io.airlift.units.Duration; import org.HdrHistogram.Histogram; import org.HdrHistogram.HistogramIterationValue; import org.weakref.jmx.Managed; diff --git a/stats/src/main/java/com/facebook/airlift/stats/TestingGcMonitor.java b/stats/src/main/java/com/facebook/airlift/stats/TestingGcMonitor.java index 04b93655f3..b8fbe2a883 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/TestingGcMonitor.java +++ b/stats/src/main/java/com/facebook/airlift/stats/TestingGcMonitor.java @@ -13,7 +13,7 @@ */ package com.facebook.airlift.stats; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import javax.annotation.concurrent.GuardedBy; diff --git a/stats/src/main/java/com/facebook/airlift/stats/TimeStat.java b/stats/src/main/java/com/facebook/airlift/stats/TimeStat.java index 909c05cdc3..f2a800ad8e 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/TimeStat.java +++ b/stats/src/main/java/com/facebook/airlift/stats/TimeStat.java @@ -16,10 +16,10 @@ package com.facebook.airlift.stats; import com.facebook.airlift.stats.TimeDistribution.TimeDistributionSnapshot; +import com.facebook.airlift.units.Duration; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Ticker; -import io.airlift.units.Duration; import org.weakref.jmx.Managed; import org.weakref.jmx.Nested; diff --git a/stats/src/main/java/com/facebook/airlift/stats/TimedStat.java b/stats/src/main/java/com/facebook/airlift/stats/TimedStat.java index 9ebc1d3776..9aafef2a83 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/TimedStat.java +++ b/stats/src/main/java/com/facebook/airlift/stats/TimedStat.java @@ -15,7 +15,7 @@ */ package com.facebook.airlift.stats; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import org.weakref.jmx.Managed; import java.util.Collections; diff --git a/stats/src/main/java/io/airlift/stats/GarbageCollectionNotificationInfo.java b/stats/src/main/java/io/airlift/stats/GarbageCollectionNotificationInfo.java index deb9a62a59..1e9864cdcb 100644 --- a/stats/src/main/java/io/airlift/stats/GarbageCollectionNotificationInfo.java +++ b/stats/src/main/java/io/airlift/stats/GarbageCollectionNotificationInfo.java @@ -1,7 +1,7 @@ package com.facebook.airlift.stats; +import com.facebook.airlift.units.DataSize; import com.google.common.collect.ImmutableMap; -import io.airlift.units.DataSize; import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularData; @@ -10,8 +10,8 @@ import java.util.Collection; import java.util.Map; +import static com.facebook.airlift.units.DataSize.succinctBytes; import static com.google.common.base.MoreObjects.toStringHelper; -import static io.airlift.units.DataSize.succinctBytes; import static java.lang.Math.max; import static java.util.Objects.requireNonNull; diff --git a/stats/src/test/java/com/facebook/airlift/stats/TestJmxGcMonitor.java b/stats/src/test/java/com/facebook/airlift/stats/TestJmxGcMonitor.java index 9d9851cfb2..b12a56681d 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/TestJmxGcMonitor.java +++ b/stats/src/test/java/com/facebook/airlift/stats/TestJmxGcMonitor.java @@ -1,6 +1,6 @@ package com.facebook.airlift.stats; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import org.testng.annotations.Test; import static com.facebook.airlift.testing.Assertions.assertGreaterThanOrEqual; diff --git a/stats/src/test/java/com/facebook/airlift/stats/TestTestingGcMonitor.java b/stats/src/test/java/com/facebook/airlift/stats/TestTestingGcMonitor.java index ccccc3d035..ec2a864bfe 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/TestTestingGcMonitor.java +++ b/stats/src/test/java/com/facebook/airlift/stats/TestTestingGcMonitor.java @@ -1,7 +1,7 @@ package com.facebook.airlift.stats; -import io.airlift.units.Duration; +import com.facebook.airlift.units.Duration; import org.testng.annotations.Test; import static java.util.concurrent.TimeUnit.SECONDS; diff --git a/units/src/main/java/io/airlift/units/DataSize.java b/units/src/main/java/com/facebook/airlift/units/DataSize.java similarity index 97% rename from units/src/main/java/io/airlift/units/DataSize.java rename to units/src/main/java/com/facebook/airlift/units/DataSize.java index e34476af8e..e992712cb1 100644 --- a/units/src/main/java/io/airlift/units/DataSize.java +++ b/units/src/main/java/com/facebook/airlift/units/DataSize.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; @@ -22,8 +22,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static io.airlift.units.Preconditions.checkArgument; -import static io.airlift.units.Preconditions.checkState; +import static com.facebook.airlift.units.Preconditions.checkArgument; +import static com.facebook.airlift.units.Preconditions.checkState; import static java.lang.Math.floor; import static java.util.Objects.requireNonNull; diff --git a/units/src/main/java/io/airlift/units/Duration.java b/units/src/main/java/com/facebook/airlift/units/Duration.java similarity index 98% rename from units/src/main/java/io/airlift/units/Duration.java rename to units/src/main/java/com/facebook/airlift/units/Duration.java index 8d1f61719c..0cb93fafa2 100644 --- a/units/src/main/java/io/airlift/units/Duration.java +++ b/units/src/main/java/com/facebook/airlift/units/Duration.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; @@ -23,7 +23,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static io.airlift.units.Preconditions.checkArgument; +import static com.facebook.airlift.units.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.HOURS; diff --git a/units/src/main/java/io/airlift/units/MaxDataSize.java b/units/src/main/java/com/facebook/airlift/units/MaxDataSize.java similarity index 92% rename from units/src/main/java/io/airlift/units/MaxDataSize.java rename to units/src/main/java/com/facebook/airlift/units/MaxDataSize.java index a39745aba6..b464ec6cc2 100644 --- a/units/src/main/java/io/airlift/units/MaxDataSize.java +++ b/units/src/main/java/com/facebook/airlift/units/MaxDataSize.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.Constraint; import javax.validation.Payload; @@ -36,7 +36,7 @@ { String value(); - String message() default "{io.airlift.units.MaxDataSize.message}"; + String message() default "{com.facebook.airlift.units.MaxDataSize.message}"; Class[] groups() default {}; diff --git a/units/src/main/java/io/airlift/units/MaxDataSizeValidator.java b/units/src/main/java/com/facebook/airlift/units/MaxDataSizeValidator.java similarity index 97% rename from units/src/main/java/io/airlift/units/MaxDataSizeValidator.java rename to units/src/main/java/com/facebook/airlift/units/MaxDataSizeValidator.java index e71b9a7b14..6cc98ae10f 100644 --- a/units/src/main/java/io/airlift/units/MaxDataSizeValidator.java +++ b/units/src/main/java/com/facebook/airlift/units/MaxDataSizeValidator.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; diff --git a/units/src/main/java/io/airlift/units/MaxDuration.java b/units/src/main/java/com/facebook/airlift/units/MaxDuration.java similarity index 92% rename from units/src/main/java/io/airlift/units/MaxDuration.java rename to units/src/main/java/com/facebook/airlift/units/MaxDuration.java index 223aa3d169..6727c0937f 100644 --- a/units/src/main/java/io/airlift/units/MaxDuration.java +++ b/units/src/main/java/com/facebook/airlift/units/MaxDuration.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.Constraint; import javax.validation.Payload; @@ -38,7 +38,7 @@ { String value(); - String message() default "{io.airlift.units.MaxDuration.message}"; + String message() default "{com.facebook.airlift.units.MaxDuration.message}"; Class[] groups() default {}; diff --git a/units/src/main/java/io/airlift/units/MaxDurationValidator.java b/units/src/main/java/com/facebook/airlift/units/MaxDurationValidator.java similarity index 97% rename from units/src/main/java/io/airlift/units/MaxDurationValidator.java rename to units/src/main/java/com/facebook/airlift/units/MaxDurationValidator.java index f27b9641b7..c06c3b1bf1 100644 --- a/units/src/main/java/io/airlift/units/MaxDurationValidator.java +++ b/units/src/main/java/com/facebook/airlift/units/MaxDurationValidator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; diff --git a/units/src/main/java/io/airlift/units/MinDataSize.java b/units/src/main/java/com/facebook/airlift/units/MinDataSize.java similarity index 92% rename from units/src/main/java/io/airlift/units/MinDataSize.java rename to units/src/main/java/com/facebook/airlift/units/MinDataSize.java index 6f9c5cad66..ac09354229 100644 --- a/units/src/main/java/io/airlift/units/MinDataSize.java +++ b/units/src/main/java/com/facebook/airlift/units/MinDataSize.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.Constraint; import javax.validation.Payload; @@ -36,7 +36,7 @@ { String value(); - String message() default "{io.airlift.units.MinDataSize.message}"; + String message() default "{com.facebook.airlift.units.MinDataSize.message}"; Class[] groups() default {}; diff --git a/units/src/main/java/io/airlift/units/MinDataSizeValidator.java b/units/src/main/java/com/facebook/airlift/units/MinDataSizeValidator.java similarity index 97% rename from units/src/main/java/io/airlift/units/MinDataSizeValidator.java rename to units/src/main/java/com/facebook/airlift/units/MinDataSizeValidator.java index 7251939d10..6a53a99261 100644 --- a/units/src/main/java/io/airlift/units/MinDataSizeValidator.java +++ b/units/src/main/java/com/facebook/airlift/units/MinDataSizeValidator.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; diff --git a/units/src/main/java/io/airlift/units/MinDuration.java b/units/src/main/java/com/facebook/airlift/units/MinDuration.java similarity index 92% rename from units/src/main/java/io/airlift/units/MinDuration.java rename to units/src/main/java/com/facebook/airlift/units/MinDuration.java index a080d08a71..2e49d0b834 100644 --- a/units/src/main/java/io/airlift/units/MinDuration.java +++ b/units/src/main/java/com/facebook/airlift/units/MinDuration.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.Constraint; import javax.validation.Payload; @@ -38,7 +38,7 @@ { String value(); - String message() default "{io.airlift.units.MinDuration.message}"; + String message() default "{com.facebook.airlift.units.MinDuration.message}"; Class[] groups() default {}; diff --git a/units/src/main/java/io/airlift/units/MinDurationValidator.java b/units/src/main/java/com/facebook/airlift/units/MinDurationValidator.java similarity index 97% rename from units/src/main/java/io/airlift/units/MinDurationValidator.java rename to units/src/main/java/com/facebook/airlift/units/MinDurationValidator.java index 28cb3dd109..d9bd4b2279 100644 --- a/units/src/main/java/io/airlift/units/MinDurationValidator.java +++ b/units/src/main/java/com/facebook/airlift/units/MinDurationValidator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; diff --git a/units/src/main/java/io/airlift/units/Preconditions.java b/units/src/main/java/com/facebook/airlift/units/Preconditions.java similarity index 98% rename from units/src/main/java/io/airlift/units/Preconditions.java rename to units/src/main/java/com/facebook/airlift/units/Preconditions.java index 9f111c7b03..b4597eab84 100644 --- a/units/src/main/java/io/airlift/units/Preconditions.java +++ b/units/src/main/java/com/facebook/airlift/units/Preconditions.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; // forked from com.google.common.base.Preconditions final class Preconditions diff --git a/units/src/main/resources/ValidationMessages.properties b/units/src/main/resources/ValidationMessages.properties index 00195c64c8..b1b015cc4c 100644 --- a/units/src/main/resources/ValidationMessages.properties +++ b/units/src/main/resources/ValidationMessages.properties @@ -1,4 +1,4 @@ -io.airlift.units.MinDuration.message=must be greater than or equal to {value} -io.airlift.units.MaxDuration.message=must be less than or equal to {value} -io.airlift.units.MinDataSize.message=must be greater than or equal to {value} -io.airlift.units.MaxDataSize.message=must be less than or equal to {value} +com.facebook.airlift.units.MinDuration.message=must be greater than or equal to {value} +com.facebook.airlift.units.MaxDuration.message=must be less than or equal to {value} +com.facebook.airlift.units.MinDataSize.message=must be greater than or equal to {value} +com.facebook.airlift.units.MaxDataSize.message=must be less than or equal to {value} diff --git a/units/src/test/java/io/airlift/units/ConstraintValidatorAssert.java b/units/src/test/java/com/facebook/airlift/units/ConstraintValidatorAssert.java similarity index 98% rename from units/src/test/java/io/airlift/units/ConstraintValidatorAssert.java rename to units/src/test/java/com/facebook/airlift/units/ConstraintValidatorAssert.java index 9625a89129..d9f46ab433 100644 --- a/units/src/test/java/io/airlift/units/ConstraintValidatorAssert.java +++ b/units/src/test/java/com/facebook/airlift/units/ConstraintValidatorAssert.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import org.assertj.core.api.AbstractAssert; diff --git a/units/src/test/java/io/airlift/units/MockMaxDataSize.java b/units/src/test/java/com/facebook/airlift/units/MockMaxDataSize.java similarity index 97% rename from units/src/test/java/io/airlift/units/MockMaxDataSize.java rename to units/src/test/java/com/facebook/airlift/units/MockMaxDataSize.java index 07c565161f..6cc81c40b1 100644 --- a/units/src/test/java/io/airlift/units/MockMaxDataSize.java +++ b/units/src/test/java/com/facebook/airlift/units/MockMaxDataSize.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.Payload; diff --git a/units/src/test/java/io/airlift/units/MockMaxDuration.java b/units/src/test/java/com/facebook/airlift/units/MockMaxDuration.java similarity index 97% rename from units/src/test/java/io/airlift/units/MockMaxDuration.java rename to units/src/test/java/com/facebook/airlift/units/MockMaxDuration.java index bba5dc2aa2..6c550f35dd 100644 --- a/units/src/test/java/io/airlift/units/MockMaxDuration.java +++ b/units/src/test/java/com/facebook/airlift/units/MockMaxDuration.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.Payload; diff --git a/units/src/test/java/io/airlift/units/MockMinDataSize.java b/units/src/test/java/com/facebook/airlift/units/MockMinDataSize.java similarity index 97% rename from units/src/test/java/io/airlift/units/MockMinDataSize.java rename to units/src/test/java/com/facebook/airlift/units/MockMinDataSize.java index 591a6c903f..41fede310c 100644 --- a/units/src/test/java/io/airlift/units/MockMinDataSize.java +++ b/units/src/test/java/com/facebook/airlift/units/MockMinDataSize.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.Payload; diff --git a/units/src/test/java/io/airlift/units/MockMinDuration.java b/units/src/test/java/com/facebook/airlift/units/MockMinDuration.java similarity index 97% rename from units/src/test/java/io/airlift/units/MockMinDuration.java rename to units/src/test/java/com/facebook/airlift/units/MockMinDuration.java index a20e682238..cbe1771a8b 100644 --- a/units/src/test/java/io/airlift/units/MockMinDuration.java +++ b/units/src/test/java/com/facebook/airlift/units/MockMinDuration.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import javax.validation.Payload; diff --git a/units/src/test/java/io/airlift/units/TestDataSize.java b/units/src/test/java/com/facebook/airlift/units/TestDataSize.java similarity index 96% rename from units/src/test/java/io/airlift/units/TestDataSize.java rename to units/src/test/java/com/facebook/airlift/units/TestDataSize.java index 53b994a158..b176c9cb35 100644 --- a/units/src/test/java/io/airlift/units/TestDataSize.java +++ b/units/src/test/java/com/facebook/airlift/units/TestDataSize.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import com.google.common.collect.ImmutableList; import io.airlift.json.JsonCodec; @@ -23,14 +23,14 @@ import java.util.Locale; import static io.airlift.testing.EquivalenceTester.comparisonTester; -import static io.airlift.units.DataSize.Unit.BYTE; -import static io.airlift.units.DataSize.Unit.GIGABYTE; -import static io.airlift.units.DataSize.Unit.KILOBYTE; -import static io.airlift.units.DataSize.Unit.MEGABYTE; -import static io.airlift.units.DataSize.Unit.PETABYTE; -import static io.airlift.units.DataSize.Unit.TERABYTE; -import static io.airlift.units.DataSize.succinctBytes; -import static io.airlift.units.DataSize.succinctDataSize; +import static com.facebook.airlift.units.DataSize.Unit.BYTE; +import static com.facebook.airlift.units.DataSize.Unit.GIGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.KILOBYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.PETABYTE; +import static com.facebook.airlift.units.DataSize.Unit.TERABYTE; +import static com.facebook.airlift.units.DataSize.succinctBytes; +import static com.facebook.airlift.units.DataSize.succinctDataSize; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.offset; import static org.assertj.core.data.Percentage.withPercentage; diff --git a/units/src/test/java/io/airlift/units/TestDataSizeValidator.java b/units/src/test/java/com/facebook/airlift/units/TestDataSizeValidator.java similarity index 94% rename from units/src/test/java/io/airlift/units/TestDataSizeValidator.java rename to units/src/test/java/com/facebook/airlift/units/TestDataSizeValidator.java index 240a06a9c3..4ac5b43e1b 100644 --- a/units/src/test/java/io/airlift/units/TestDataSizeValidator.java +++ b/units/src/test/java/com/facebook/airlift/units/TestDataSizeValidator.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import org.apache.bval.jsr.ApacheValidationProvider; import org.testng.annotations.Test; @@ -24,10 +24,10 @@ import java.util.Optional; import java.util.Set; -import static io.airlift.units.ConstraintValidatorAssert.assertThat; -import static io.airlift.units.DataSize.Unit.GIGABYTE; -import static io.airlift.units.DataSize.Unit.KILOBYTE; -import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static com.facebook.airlift.units.ConstraintValidatorAssert.assertThat; +import static com.facebook.airlift.units.DataSize.Unit.GIGABYTE; +import static com.facebook.airlift.units.DataSize.Unit.KILOBYTE; +import static com.facebook.airlift.units.DataSize.Unit.MEGABYTE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertTrue; @@ -87,7 +87,7 @@ public void testDetectsBrokenMinAnnotation() assertThatThrownBy(() -> VALIDATOR.validate(new MinAnnotationOnOptional())) .isInstanceOf(ValidationException.class) - .hasMessage("No compliant io.airlift.units.MinDataSize ConstraintValidator found for annotated element of type java.util.Optional"); + .hasMessage("No compliant com.facebook.airlift.units.MinDataSize ConstraintValidator found for annotated element of type java.util.Optional"); assertThatThrownBy(() -> VALIDATOR.validate(new BrokenOptionalMinAnnotation())) .isInstanceOf(ValidationException.class) @@ -105,7 +105,7 @@ public void testDetectsBrokenMaxAnnotation() assertThatThrownBy(() -> VALIDATOR.validate(new MaxAnnotationOnOptional())) .isInstanceOf(ValidationException.class) - .hasMessage("No compliant io.airlift.units.MaxDataSize ConstraintValidator found for annotated element of type java.util.Optional"); + .hasMessage("No compliant com.facebook.airlift.units.MaxDataSize ConstraintValidator found for annotated element of type java.util.Optional"); assertThatThrownBy(() -> VALIDATOR.validate(new BrokenOptionalMaxAnnotation())) .isInstanceOf(ValidationException.class) diff --git a/units/src/test/java/io/airlift/units/TestDuration.java b/units/src/test/java/com/facebook/airlift/units/TestDuration.java similarity index 99% rename from units/src/test/java/io/airlift/units/TestDuration.java rename to units/src/test/java/com/facebook/airlift/units/TestDuration.java index b3e4ec7d2b..ce82cd3ed5 100644 --- a/units/src/test/java/io/airlift/units/TestDuration.java +++ b/units/src/test/java/com/facebook/airlift/units/TestDuration.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import io.airlift.json.JsonCodec; import org.testng.annotations.DataProvider; @@ -25,8 +25,8 @@ import java.util.concurrent.TimeUnit; import static io.airlift.testing.EquivalenceTester.comparisonTester; -import static io.airlift.units.Duration.succinctDuration; -import static io.airlift.units.Duration.succinctNanos; +import static com.facebook.airlift.units.Duration.succinctDuration; +import static com.facebook.airlift.units.Duration.succinctNanos; import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.MICROSECONDS; diff --git a/units/src/test/java/io/airlift/units/TestDurationValidator.java b/units/src/test/java/com/facebook/airlift/units/TestDurationValidator.java similarity index 96% rename from units/src/test/java/io/airlift/units/TestDurationValidator.java rename to units/src/test/java/com/facebook/airlift/units/TestDurationValidator.java index e7acd82440..b318e2e103 100644 --- a/units/src/test/java/io/airlift/units/TestDurationValidator.java +++ b/units/src/test/java/com/facebook/airlift/units/TestDurationValidator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.airlift.units; +package com.facebook.airlift.units; import org.apache.bval.jsr.ApacheValidationProvider; import org.testng.annotations.Test; @@ -27,7 +27,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; -import static io.airlift.units.ConstraintValidatorAssert.assertThat; +import static com.facebook.airlift.units.ConstraintValidatorAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -79,7 +79,7 @@ public void testDetectsBrokenMinAnnotation() assertThatThrownBy(() -> VALIDATOR.validate(new MinAnnotationOnOptional())) .isInstanceOf(ValidationException.class) - .hasMessage("No compliant io.airlift.units.MinDuration ConstraintValidator found for annotated element of type java.util.Optional"); + .hasMessage("No compliant com.facebook.airlift.units.MinDuration ConstraintValidator found for annotated element of type java.util.Optional"); assertThatThrownBy(() -> VALIDATOR.validate(new BrokenOptionalMinAnnotation())) .isInstanceOf(ValidationException.class) @@ -97,7 +97,7 @@ public void testDetectsBrokenMaxAnnotation() assertThatThrownBy(() -> VALIDATOR.validate(new MaxAnnotationOnOptional())) .isInstanceOf(ValidationException.class) - .hasMessage("No compliant io.airlift.units.MaxDuration ConstraintValidator found for annotated element of type java.util.Optional"); + .hasMessage("No compliant com.facebook.airlift.units.MaxDuration ConstraintValidator found for annotated element of type java.util.Optional"); assertThatThrownBy(() -> VALIDATOR.validate(new BrokenOptionalMaxAnnotation())) .isInstanceOf(ValidationException.class)