diff options
91 files changed, 805 insertions, 993 deletions
diff --git a/api/src/main/java/io/opencensus/common/Duration.java b/api/src/main/java/io/opencensus/common/Duration.java index 77ba3db7..b4b59a57 100644 --- a/api/src/main/java/io/opencensus/common/Duration.java +++ b/api/src/main/java/io/opencensus/common/Duration.java @@ -92,8 +92,8 @@ public abstract class Duration implements Comparable<Duration> { * Compares this {@code Duration} to the specified {@code Duration}. * * @param otherDuration the other {@code Duration} to compare to, not {@code null}. - * @return the comparator value: zero if equal, negative if this duration is smaller - * than otherDuration, positive if larger. + * @return the comparator value: zero if equal, negative if this duration is smaller than + * otherDuration, positive if larger. * @throws NullPointerException if otherDuration is {@code null}. */ @Override diff --git a/api/src/main/java/io/opencensus/common/ExperimentalApi.java b/api/src/main/java/io/opencensus/common/ExperimentalApi.java index 266da4e9..9906cbff 100644 --- a/api/src/main/java/io/opencensus/common/ExperimentalApi.java +++ b/api/src/main/java/io/opencensus/common/ExperimentalApi.java @@ -27,26 +27,26 @@ import java.lang.annotation.Target; * backward-compatibility. * * <p>Usage guidelines: + * * <ol> - * <li>This annotation is used only on public API. Internal interfaces should not use it.</li> - * <li>After OpenCensus has gained API stability, this annotation can only be added to new API. - * Adding it to an existing API is considered API-breaking.</li> - * <li>Removing this annotation from an API gives it stable status.</li> + * <li>This annotation is used only on public API. Internal interfaces should not use it. + * <li>After OpenCensus has gained API stability, this annotation can only be added to new API. + * Adding it to an existing API is considered API-breaking. + * <li>Removing this annotation from an API gives it stable status. * </ol> */ @Internal @Retention(RetentionPolicy.SOURCE) @Target({ - ElementType.ANNOTATION_TYPE, - ElementType.CONSTRUCTOR, - ElementType.FIELD, - ElementType.METHOD, - ElementType.PACKAGE, - ElementType.TYPE}) + ElementType.ANNOTATION_TYPE, + ElementType.CONSTRUCTOR, + ElementType.FIELD, + ElementType.METHOD, + ElementType.PACKAGE, + ElementType.TYPE +}) @Documented public @interface ExperimentalApi { - /** - * Context information such as links to discussion thread, tracking issue etc. - */ + /** Context information such as links to discussion thread, tracking issue etc. */ String value() default ""; -}
\ No newline at end of file +} diff --git a/api/src/main/java/io/opencensus/common/OpenCensusLibraryInformation.java b/api/src/main/java/io/opencensus/common/OpenCensusLibraryInformation.java index 1b1c75e4..aa5d69d5 100644 --- a/api/src/main/java/io/opencensus/common/OpenCensusLibraryInformation.java +++ b/api/src/main/java/io/opencensus/common/OpenCensusLibraryInformation.java @@ -16,14 +16,10 @@ package io.opencensus.common; -/** - * Class holder for all common constants (such as the version) for the OpenCensus Java library. - */ +/** Class holder for all common constants (such as the version) for the OpenCensus Java library. */ @ExperimentalApi public final class OpenCensusLibraryInformation { - /** - * The current version of the OpenCensus Java library. - */ - public static final String VERSION = "0.9.0-SNAPSHOT"; // CURRENT_OPENCENSUS_VERSION + /** The current version of the OpenCensus Java library. */ + public static final String VERSION = "0.9.0-SNAPSHOT"; // CURRENT_OPENCENSUS_VERSION } diff --git a/api/src/main/java/io/opencensus/common/Timestamp.java b/api/src/main/java/io/opencensus/common/Timestamp.java index 0fa7c800..b62a1102 100644 --- a/api/src/main/java/io/opencensus/common/Timestamp.java +++ b/api/src/main/java/io/opencensus/common/Timestamp.java @@ -138,8 +138,8 @@ public abstract class Timestamp implements Comparable<Timestamp> { * Compares this {@code Timestamp} to the specified {@code Timestamp}. * * @param otherTimestamp the other {@code Timestamp} to compare to, not {@code null}. - * @return the comparator value: zero if equal, negative if this timestamp happens - * before otherTimestamp, positive if after. + * @return the comparator value: zero if equal, negative if this timestamp happens before + * otherTimestamp, positive if after. * @throws NullPointerException if otherTimestamp is {@code null}. */ @Override diff --git a/api/src/main/java/io/opencensus/internal/NoopScope.java b/api/src/main/java/io/opencensus/internal/NoopScope.java index 1edac98e..f4a8da07 100644 --- a/api/src/main/java/io/opencensus/internal/NoopScope.java +++ b/api/src/main/java/io/opencensus/internal/NoopScope.java @@ -18,9 +18,7 @@ package io.opencensus.internal; import io.opencensus.common.Scope; -/** - * A {@link Scope} that does nothing when it is created or closed. - */ +/** A {@link Scope} that does nothing when it is created or closed. */ public final class NoopScope implements Scope { private static final Scope INSTANCE = new NoopScope(); diff --git a/api/src/main/java/io/opencensus/stats/Aggregation.java b/api/src/main/java/io/opencensus/stats/Aggregation.java index f12517c8..90341af4 100644 --- a/api/src/main/java/io/opencensus/stats/Aggregation.java +++ b/api/src/main/java/io/opencensus/stats/Aggregation.java @@ -23,10 +23,11 @@ import io.opencensus.common.Function; import javax.annotation.concurrent.Immutable; /** - * {@link Aggregation} is the process of combining a certain set of {@code MeasureValue}s - * for a given {@code Measure} into an {@link AggregationData}. + * {@link Aggregation} is the process of combining a certain set of {@code MeasureValue}s for a + * given {@code Measure} into an {@link AggregationData}. * * <p>{@link Aggregation} currently supports 4 types of basic aggregation: + * * <ul> * <li>Sum * <li>Count @@ -40,12 +41,9 @@ import javax.annotation.concurrent.Immutable; @Immutable public abstract class Aggregation { - private Aggregation() { - } + private Aggregation() {} - /** - * Applies the given match function to the underlying data type. - */ + /** Applies the given match function to the underlying data type. */ public abstract <T> T match( Function<? super Sum, T> p0, Function<? super Count, T> p1, @@ -58,8 +56,7 @@ public abstract class Aggregation { @AutoValue public abstract static class Sum extends Aggregation { - Sum() { - } + Sum() {} private static final Sum INSTANCE = new AutoValue_Aggregation_Sum(); @@ -88,8 +85,7 @@ public abstract class Aggregation { @AutoValue public abstract static class Count extends Aggregation { - Count() { - } + Count() {} private static final Count INSTANCE = new AutoValue_Aggregation_Count(); @@ -118,8 +114,7 @@ public abstract class Aggregation { @AutoValue public abstract static class Mean extends Aggregation { - Mean() { - } + Mean() {} private static final Mean INSTANCE = new AutoValue_Aggregation_Mean(); @@ -144,15 +139,14 @@ public abstract class Aggregation { } /** - * Calculate distribution stats on aggregated {@code MeasureValue}s. Distribution includes - * mean, count, histogram, min, max and sum of squared deviations. + * Calculate distribution stats on aggregated {@code MeasureValue}s. Distribution includes mean, + * count, histogram, min, max and sum of squared deviations. */ @Immutable @AutoValue public abstract static class Distribution extends Aggregation { - Distribution() { - } + Distribution() {} /** * Construct a {@code Distribution}. diff --git a/api/src/main/java/io/opencensus/stats/AggregationData.java b/api/src/main/java/io/opencensus/stats/AggregationData.java index b91d0d19..d5cacfc5 100644 --- a/api/src/main/java/io/opencensus/stats/AggregationData.java +++ b/api/src/main/java/io/opencensus/stats/AggregationData.java @@ -27,10 +27,11 @@ import java.util.List; import javax.annotation.concurrent.Immutable; /** - * {@link AggregationData} is the result of applying a given {@link Aggregation} to a set of - * {@code MeasureValue}s. + * {@link AggregationData} is the result of applying a given {@link Aggregation} to a set of {@code + * MeasureValue}s. * * <p>{@link AggregationData} currently supports 5 types of basic aggregation values: + * * <ul> * <li>SumDataDouble * <li>SumDataLong @@ -39,18 +40,15 @@ import javax.annotation.concurrent.Immutable; * <li>DistributionData * </ul> * - * <p>{@link ViewData} will contain one {@link AggregationData}, corresponding to its - * {@link Aggregation} definition in {@link View}. + * <p>{@link ViewData} will contain one {@link AggregationData}, corresponding to its {@link + * Aggregation} definition in {@link View}. */ @Immutable public abstract class AggregationData { - private AggregationData() { - } + private AggregationData() {} - /** - * Applies the given match function to the underlying data type. - */ + /** Applies the given match function to the underlying data type. */ public abstract <T> T match( Function<? super SumDataDouble, T> p0, Function<? super SumDataLong, T> p1, @@ -64,8 +62,7 @@ public abstract class AggregationData { @AutoValue public abstract static class SumDataDouble extends AggregationData { - SumDataDouble() { - } + SumDataDouble() {} /** * Creates a {@code SumDataDouble}. @@ -101,8 +98,7 @@ public abstract class AggregationData { @AutoValue public abstract static class SumDataLong extends AggregationData { - SumDataLong() { - } + SumDataLong() {} /** * Creates a {@code SumDataLong}. @@ -138,8 +134,7 @@ public abstract class AggregationData { @AutoValue public abstract static class CountData extends AggregationData { - CountData() { - } + CountData() {} /** * Creates a {@code CountData}. @@ -175,8 +170,7 @@ public abstract class AggregationData { @AutoValue public abstract static class MeanData extends AggregationData { - MeanData() { - } + MeanData() {} /** * Creates a {@code MeanData}. @@ -223,8 +217,7 @@ public abstract class AggregationData { @AutoValue public abstract static class DistributionData extends AggregationData { - DistributionData() { - } + DistributionData() {} /** * Creates a {@code DistributionData}. @@ -238,7 +231,11 @@ public abstract class AggregationData { * @return a {@code DistributionData}. */ public static DistributionData create( - double mean, long count, double min, double max, double sumOfSquaredDeviations, + double mean, + long count, + double min, + double max, + double sumOfSquaredDeviations, List<Long> bucketCounts) { if (min != Double.POSITIVE_INFINITY || max != Double.NEGATIVE_INFINITY) { checkArgument(min <= max, "max should be greater or equal to min."); diff --git a/api/src/main/java/io/opencensus/stats/BucketBoundaries.java b/api/src/main/java/io/opencensus/stats/BucketBoundaries.java index b9a808f4..8af83a4e 100644 --- a/api/src/main/java/io/opencensus/stats/BucketBoundaries.java +++ b/api/src/main/java/io/opencensus/stats/BucketBoundaries.java @@ -38,7 +38,7 @@ public abstract class BucketBoundaries { */ public static final BucketBoundaries create(List<Double> bucketBoundaries) { checkNotNull(bucketBoundaries, "bucketBoundaries list should not be null."); - List<Double> bucketBoundariesCopy = new ArrayList<Double>(bucketBoundaries); // Deep copy. + List<Double> bucketBoundariesCopy = new ArrayList<Double>(bucketBoundaries); // Deep copy. // Check if sorted. if (bucketBoundariesCopy.size() > 1) { double lower = bucketBoundariesCopy.get(0); @@ -52,6 +52,8 @@ public abstract class BucketBoundaries { } /** + * Returns a list of histogram bucket boundaries. + * * @return a list of histogram bucket boundaries. */ public abstract List<Double> getBoundaries(); diff --git a/api/src/main/java/io/opencensus/stats/Measure.java b/api/src/main/java/io/opencensus/stats/Measure.java index 062a35bf..52fadfa0 100644 --- a/api/src/main/java/io/opencensus/stats/Measure.java +++ b/api/src/main/java/io/opencensus/stats/Measure.java @@ -30,9 +30,7 @@ public abstract class Measure { @VisibleForTesting static final int NAME_MAX_LENGTH = 255; - /** - * Applies the given match function to the underlying data type. - */ + /** Applies the given match function to the underlying data type. */ public abstract <T> T match( Function<? super MeasureDouble, T> p0, Function<? super MeasureLong, T> p1, @@ -46,35 +44,35 @@ public abstract class Measure { */ public abstract String getName(); - /** - * Detailed description of the measure, used in documentation. - */ + /** Detailed description of the measure, used in documentation. */ public abstract String getDescription(); /** * The units in which {@link Measure} values are measured. * * <p>The suggested grammar for a unit is as follows: - * Expression = Component { "." Component } { "/" Component } ; - * Component = [ PREFIX ] UNIT [ Annotation ] | Annotation | "1" ; - * Annotation = "{" NAME "}" ; - * For example, string “MBy{transmitted}/ms” stands for megabytes per milliseconds, and the + * + * <ul> + * <li>Expression = Component { "." Component } {"/" Component }; + * <li>Component = [ PREFIX ] UNIT [ Annotation ] | Annotation | "1"; + * <li>Annotation = "{" NAME "}" ; + * </ul> + * + * <p>For example, string “MBy{transmitted}/ms” stands for megabytes per milliseconds, and the * annotation transmitted inside {} is just a comment of the unit. */ // TODO(songya): determine whether we want to check the grammar on string unit. public abstract String getUnit(); // Prevents this class from being subclassed anywhere else. - private Measure() { - } + private Measure() {} /** {@link Measure} with {@code Double} typed values. */ @Immutable @AutoValue public abstract static class MeasureDouble extends Measure { - MeasureDouble() { - } + MeasureDouble() {} /** * Constructs a new {@link MeasureDouble}. @@ -85,9 +83,11 @@ public abstract class Measure { * @return a {@code MeasureDouble}. */ public static MeasureDouble create(String name, String description, String unit) { - checkArgument(StringUtil.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH, + checkArgument( + StringUtil.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH, "Name should be a ASCII string with a length no greater than " - + NAME_MAX_LENGTH + " characters."); + + NAME_MAX_LENGTH + + " characters."); return new AutoValue_Measure_MeasureDouble(name, description, unit); } @@ -114,8 +114,7 @@ public abstract class Measure { @AutoValue public abstract static class MeasureLong extends Measure { - MeasureLong() { - } + MeasureLong() {} /** * Constructs a new {@link MeasureLong}. @@ -126,9 +125,11 @@ public abstract class Measure { * @return a {@code MeasureLong}. */ public static MeasureLong create(String name, String description, String unit) { - checkArgument(StringUtil.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH, + checkArgument( + StringUtil.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH, "Name should be a ASCII string with a length no greater than " - + NAME_MAX_LENGTH + " characters."); + + NAME_MAX_LENGTH + + " characters."); return new AutoValue_Measure_MeasureLong(name, description, unit); } diff --git a/api/src/main/java/io/opencensus/stats/Measurement.java b/api/src/main/java/io/opencensus/stats/Measurement.java index 10fc5888..1bb746d8 100644 --- a/api/src/main/java/io/opencensus/stats/Measurement.java +++ b/api/src/main/java/io/opencensus/stats/Measurement.java @@ -26,22 +26,17 @@ import javax.annotation.concurrent.Immutable; @Immutable public abstract class Measurement { - /** - * Applies the given match function to the underlying data type. - */ + /** Applies the given match function to the underlying data type. */ public abstract <T> T match( Function<? super MeasurementDouble, T> p0, Function<? super MeasurementLong, T> p1, Function<? super Measurement, T> defaultFunction); - /** - * Extracts the measured {@link Measure}. - */ + /** Extracts the measured {@link Measure}. */ public abstract Measure getMeasure(); // Prevents this class from being subclassed anywhere else. - private Measurement() { - } + private Measurement() {} /** {@code Double} typed {@link Measurement}. */ @Immutable @@ -49,9 +44,7 @@ public abstract class Measurement { public abstract static class MeasurementDouble extends Measurement { MeasurementDouble() {} - /** - * Constructs a new {@link MeasurementDouble}. - */ + /** Constructs a new {@link MeasurementDouble}. */ public static MeasurementDouble create(MeasureDouble measure, double value) { return new AutoValue_Measurement_MeasurementDouble(measure, value); } @@ -76,9 +69,7 @@ public abstract class Measurement { public abstract static class MeasurementLong extends Measurement { MeasurementLong() {} - /** - * Constructs a new {@link MeasurementLong}. - */ + /** Constructs a new {@link MeasurementLong}. */ public static MeasurementLong create(MeasureLong measure, long value) { return new AutoValue_Measurement_MeasurementLong(measure, value); } diff --git a/api/src/main/java/io/opencensus/stats/View.java b/api/src/main/java/io/opencensus/stats/View.java index 26b1177f..c4b152e0 100644 --- a/api/src/main/java/io/opencensus/stats/View.java +++ b/api/src/main/java/io/opencensus/stats/View.java @@ -31,8 +31,8 @@ import java.util.List; import javax.annotation.concurrent.Immutable; /** - * A View specifies an aggregation and a set of tag keys. The aggregation will be broken - * down by the unique set of matching tag values for each measure. + * A View specifies an aggregation and a set of tag keys. The aggregation will be broken down by the + * unique set of matching tag values for each measure. */ @Immutable @AutoValue @@ -40,27 +40,18 @@ public abstract class View { @VisibleForTesting static final int NAME_MAX_LENGTH = 256; - View() { - } + View() {} - /** - * Name of view. Must be unique. - */ + /** Name of view. Must be unique. */ public abstract Name getName(); - /** - * More detailed description, for documentation purposes. - */ + /** More detailed description, for documentation purposes. */ public abstract String getDescription(); - /** - * Measure type of this view. - */ + /** Measure type of this view. */ public abstract Measure getMeasure(); - /** - * The {@link Aggregation} associated with this {@link View}. - */ + /** The {@link Aggregation} associated with this {@link View}. */ public abstract Aggregation getAggregation(); /** @@ -97,8 +88,7 @@ public abstract class View { Aggregation aggregation, List<TagKey> columns, AggregationWindow window) { - checkArgument(new HashSet<TagKey>(columns).size() == columns.size(), - "Columns have duplicate."); + checkArgument(new HashSet<TagKey>(columns).size() == columns.size(), "Columns have duplicate."); return new AutoValue_View( name, @@ -109,9 +99,7 @@ public abstract class View { window); } - /** - * The name of a {@code View}. - */ + /** The name of a {@code View}. */ // This type should be used as the key when associating data with Views. @Immutable @AutoValue @@ -127,8 +115,8 @@ public abstract class View { public abstract String asString(); /** - * Creates a {@code View.Name} from a {@code String}. Should be a ASCII string with a length - * no greater than 256 characters. + * Creates a {@code View.Name} from a {@code String}. Should be a ASCII string with a length no + * greater than 256 characters. * * <p>Suggested format for name: {@code <web_host>/<path>}. * @@ -136,7 +124,8 @@ public abstract class View { * @return a {@code View.Name} with the given name {@code String}. */ public static Name create(String name) { - checkArgument(StringUtil.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH, + checkArgument( + StringUtil.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH, "Name should be a ASCII string with a length no greater than 256 characters."); return new AutoValue_View_Name(name); } @@ -148,9 +137,7 @@ public abstract class View { private AggregationWindow() {} - /** - * Applies the given match function to the underlying data type. - */ + /** Applies the given match function to the underlying data type. */ public abstract <T> T match( Function<? super Cumulative, T> p0, Function<? super Interval, T> p1, @@ -182,7 +169,7 @@ public abstract class View { Function<? super Cumulative, T> p0, Function<? super Interval, T> p1, Function<? super AggregationWindow, T> defaultFunction) { - return p0.apply(this); + return p0.apply(this); } } @@ -202,7 +189,6 @@ public abstract class View { */ public abstract Duration getDuration(); - /** * Constructs an interval {@code AggregationWindow} that has a finite explicit {@code * Duration}. @@ -222,7 +208,7 @@ public abstract class View { Function<? super Cumulative, T> p0, Function<? super Interval, T> p1, Function<? super AggregationWindow, T> defaultFunction) { - return p1.apply(this); + return p1.apply(this); } } } diff --git a/api/src/main/java/io/opencensus/stats/ViewData.java b/api/src/main/java/io/opencensus/stats/ViewData.java index 007022e7..458b1f1a 100644 --- a/api/src/main/java/io/opencensus/stats/ViewData.java +++ b/api/src/main/java/io/opencensus/stats/ViewData.java @@ -41,8 +41,8 @@ public abstract class ViewData { public abstract View getView(); /** - * The {@link AggregationData} grouped by combination of tag values, associated with this - * {@link ViewData}. + * The {@link AggregationData} grouped by combination of tag values, associated with this {@link + * ViewData}. */ public abstract Map<List<TagValue>, AggregationData> getAggregationMap(); @@ -91,11 +91,9 @@ public abstract class ViewData { Functions.<Void>throwIllegalArgumentException()); Map<List<TagValue>, AggregationData> deepCopy = Maps.newHashMap(); - for (Entry<? extends List<TagValue>, ? extends AggregationData> entry : map - .entrySet()) { + for (Entry<? extends List<TagValue>, ? extends AggregationData> entry : map.entrySet()) { deepCopy.put( - Collections.unmodifiableList(new ArrayList<TagValue>(entry.getKey())), - entry.getValue()); + Collections.unmodifiableList(new ArrayList<TagValue>(entry.getKey())), entry.getValue()); } return new AutoValue_ViewData(view, Collections.unmodifiableMap(deepCopy), windowData); diff --git a/api/src/main/java/io/opencensus/stats/ViewManager.java b/api/src/main/java/io/opencensus/stats/ViewManager.java index 908221c6..f98e8058 100644 --- a/api/src/main/java/io/opencensus/stats/ViewManager.java +++ b/api/src/main/java/io/opencensus/stats/ViewManager.java @@ -19,13 +19,13 @@ package io.opencensus.stats; import javax.annotation.Nullable; /** - * Provides facilities to register {@link View}s for collecting stats and retrieving - * stats data as a {@link ViewData}. + * Provides facilities to register {@link View}s for collecting stats and retrieving stats data as a + * {@link ViewData}. */ public abstract class ViewManager { /** - * Pull model for stats. Registers a {@link View} that will collect data to be accessed - * via {@link #getView(View.Name)}. + * Pull model for stats. Registers a {@link View} that will collect data to be accessed via {@link + * #getView(View.Name)}. * * @param view the {@code View} to be registered. */ diff --git a/api/src/main/java/io/opencensus/tags/InternalUtils.java b/api/src/main/java/io/opencensus/tags/InternalUtils.java index c55ca7d4..734fcf98 100644 --- a/api/src/main/java/io/opencensus/tags/InternalUtils.java +++ b/api/src/main/java/io/opencensus/tags/InternalUtils.java @@ -18,9 +18,7 @@ package io.opencensus.tags; import java.util.Iterator; -/** - * Internal tagging utilities. - */ +/** Internal tagging utilities. */ @io.opencensus.common.Internal public final class InternalUtils { private InternalUtils() {} diff --git a/api/src/main/java/io/opencensus/tags/package-info.java b/api/src/main/java/io/opencensus/tags/package-info.java index e18c68d1..eb19ee77 100644 --- a/api/src/main/java/io/opencensus/tags/package-info.java +++ b/api/src/main/java/io/opencensus/tags/package-info.java @@ -22,8 +22,8 @@ * io.opencensus.stats} package labels all stats with the current tags. * * <p>{@link io.opencensus.tags.Tag Tags} are key-value pairs. The {@link io.opencensus.tags.TagKey - * keys} and {@link io.opencensus.tags.TagValue values} are wrapped {@code String}s. They are - * stored as a map in a {@link io.opencensus.tags.TagContext}. + * keys} and {@link io.opencensus.tags.TagValue values} are wrapped {@code String}s. They are stored + * as a map in a {@link io.opencensus.tags.TagContext}. * * <p>Note that tags are independent of the tracing data that is propagated in the {@code * io.grpc.Context}, such as trace ID. diff --git a/api/src/main/java/io/opencensus/trace/CurrentSpanUtils.java b/api/src/main/java/io/opencensus/trace/CurrentSpanUtils.java index ab8282de..dbbe3a33 100644 --- a/api/src/main/java/io/opencensus/trace/CurrentSpanUtils.java +++ b/api/src/main/java/io/opencensus/trace/CurrentSpanUtils.java @@ -20,9 +20,7 @@ import io.grpc.Context; import io.opencensus.common.Scope; import io.opencensus.trace.unsafe.ContextUtils; -/** - * Util methods/functionality to interact with the {@link Span} in the {@link io.grpc.Context}. - */ +/** Util methods/functionality to interact with the {@link Span} in the {@link io.grpc.Context}. */ final class CurrentSpanUtils { // No instance of this class. private CurrentSpanUtils() {} diff --git a/api/src/main/java/io/opencensus/trace/Sampler.java b/api/src/main/java/io/opencensus/trace/Sampler.java index 429ffe92..e30b5fdd 100644 --- a/api/src/main/java/io/opencensus/trace/Sampler.java +++ b/api/src/main/java/io/opencensus/trace/Sampler.java @@ -44,8 +44,8 @@ public abstract class Sampler { List<Span> parentLinks); /** - * Returns the description of this {@code Sampler}. This may be displayed on debug pages or in - * the logs. + * Returns the description of this {@code Sampler}. This may be displayed on debug pages or in the + * logs. * * <p>Example: "ProbabilitySampler{0.000100}" * diff --git a/api/src/main/java/io/opencensus/trace/Span.java b/api/src/main/java/io/opencensus/trace/Span.java index b58a1fde..3ede6686 100644 --- a/api/src/main/java/io/opencensus/trace/Span.java +++ b/api/src/main/java/io/opencensus/trace/Span.java @@ -77,8 +77,8 @@ public abstract class Span { } /** - * Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping - * for the key, the old value is replaced by the specified value. + * Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for + * the key, the old value is replaced by the specified value. * * @param key the key for this attribute. * @param value the value for this attribute. @@ -103,7 +103,6 @@ public abstract class Span { addAttributes(attributes); } - /** * @deprecated Use {@link #putAttributes(Map)} * @param attributes the attributes that will be added and associated with the {@code Span}. diff --git a/api/src/main/java/io/opencensus/trace/TraceComponent.java b/api/src/main/java/io/opencensus/trace/TraceComponent.java index 4472ba26..e1806490 100644 --- a/api/src/main/java/io/opencensus/trace/TraceComponent.java +++ b/api/src/main/java/io/opencensus/trace/TraceComponent.java @@ -23,8 +23,8 @@ import io.opencensus.trace.export.ExportComponent; import io.opencensus.trace.propagation.PropagationComponent; /** - * Class that holds the implementation instances for {@link Tracer}, {@link - * PropagationComponent}, {@link Clock}, {@link ExportComponent} and {@link TraceConfig}. + * Class that holds the implementation instances for {@link Tracer}, {@link PropagationComponent}, + * {@link Clock}, {@link ExportComponent} and {@link TraceConfig}. * * <p>Unless otherwise noted all methods (on component) results are cacheable. */ @@ -40,8 +40,8 @@ public abstract class TraceComponent { public abstract Tracer getTracer(); /** - * Returns the {@link PropagationComponent} with the provided implementation. If no - * implementation is provided then no-op implementation will be used. + * Returns the {@link PropagationComponent} with the provided implementation. If no implementation + * is provided then no-op implementation will be used. * * @return the {@code PropagationComponent} implementation. */ diff --git a/api/src/main/java/io/opencensus/trace/TraceOptions.java b/api/src/main/java/io/opencensus/trace/TraceOptions.java index 35181e28..fc594853 100644 --- a/api/src/main/java/io/opencensus/trace/TraceOptions.java +++ b/api/src/main/java/io/opencensus/trace/TraceOptions.java @@ -200,7 +200,8 @@ public final class TraceOptions { if (isSampled) { options = (byte) (options | IS_SAMPLED); } else { - options = (byte) (options & ~IS_SAMPLED);; + options = (byte) (options & ~IS_SAMPLED); + ; } return this; } diff --git a/api/src/main/java/io/opencensus/trace/export/ExportComponent.java b/api/src/main/java/io/opencensus/trace/export/ExportComponent.java index abf5c531..9b7e1664 100644 --- a/api/src/main/java/io/opencensus/trace/export/ExportComponent.java +++ b/api/src/main/java/io/opencensus/trace/export/ExportComponent.java @@ -20,8 +20,8 @@ import io.opencensus.trace.TraceOptions; import javax.annotation.Nullable; /** - * Class that holds the implementation instances for {@link SpanExporter}, {@link - * RunningSpanStore} and {@link SampledSpanStore}. + * Class that holds the implementation instances for {@link SpanExporter}, {@link RunningSpanStore} + * and {@link SampledSpanStore}. * * <p>Unless otherwise noted all methods (on component) results are cacheable. */ @@ -48,8 +48,8 @@ public abstract class ExportComponent { public abstract SpanExporter getSpanExporter(); /** - * Returns the {@link RunningSpanStore} that can be used to get useful debugging information - * about all the current active spans. + * Returns the {@link RunningSpanStore} that can be used to get useful debugging information about + * all the current active spans. * * @return the {@code RunningSpanStore} or {@code null} if not supported. */ diff --git a/api/src/main/java/io/opencensus/trace/propagation/PropagationComponent.java b/api/src/main/java/io/opencensus/trace/propagation/PropagationComponent.java index e8abda76..7dfa8202 100644 --- a/api/src/main/java/io/opencensus/trace/propagation/PropagationComponent.java +++ b/api/src/main/java/io/opencensus/trace/propagation/PropagationComponent.java @@ -17,16 +17,16 @@ package io.opencensus.trace.propagation; /** - * Container class for all the supported propagation formats. Currently supports only Binary - * format see {@link BinaryFormat} but more formats will be added. + * Container class for all the supported propagation formats. Currently supports only Binary format + * see {@link BinaryFormat} but more formats will be added. */ public abstract class PropagationComponent { private static final PropagationComponent NOOP_PROPAGATION_COMPONENT = new NoopPropagationComponent(); /** - * Returns the {@link BinaryFormat} with the provided implementations. If no implementation - * is provided then no-op implementation will be used. + * Returns the {@link BinaryFormat} with the provided implementations. If no implementation is + * provided then no-op implementation will be used. * * @return the {@code BinaryFormat} implementation. */ diff --git a/api/src/test/java/io/opencensus/common/DurationTest.java b/api/src/test/java/io/opencensus/common/DurationTest.java index 1aad997b..40682fc4 100644 --- a/api/src/test/java/io/opencensus/common/DurationTest.java +++ b/api/src/test/java/io/opencensus/common/DurationTest.java @@ -74,7 +74,6 @@ public class DurationTest { assertThat(Duration.create(-24, -45).compareTo(Duration.create(-24, -42))).isEqualTo(-1); assertThat(Duration.create(-24, -42).compareTo(Duration.create(-25, -42))).isEqualTo(1); assertThat(Duration.create(24, 42).compareTo(Duration.create(-24, -42))).isEqualTo(1); - } @Test diff --git a/api/src/test/java/io/opencensus/common/TimestampTest.java b/api/src/test/java/io/opencensus/common/TimestampTest.java index 68492cb2..776f5f12 100644 --- a/api/src/test/java/io/opencensus/common/TimestampTest.java +++ b/api/src/test/java/io/opencensus/common/TimestampTest.java @@ -83,7 +83,7 @@ public class TimestampTest { assertThat(timestamp.addNanos(Long.MIN_VALUE)) .isEqualTo(Timestamp.create(1234L - 9223372036L - 1, 223 + 145224192)); } - + @Test public void timestampAddDuration() { Timestamp timestamp = Timestamp.create(1234, 223); diff --git a/api/src/test/java/io/opencensus/stats/AggregationDataTest.java b/api/src/test/java/io/opencensus/stats/AggregationDataTest.java index d4403c93..3431d043 100644 --- a/api/src/test/java/io/opencensus/stats/AggregationDataTest.java +++ b/api/src/test/java/io/opencensus/stats/AggregationDataTest.java @@ -41,13 +41,12 @@ public class AggregationDataTest { private static final double TOLERANCE = 1e-6; - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void testCreateDistributionData() { - DistributionData distributionData = DistributionData.create( - 7.7, 10, 1.1, 9.9, 32.2, Arrays.asList(4L, 1L, 5L)); + DistributionData distributionData = + DistributionData.create(7.7, 10, 1.1, 9.9, 32.2, Arrays.asList(4L, 1L, 5L)); assertThat(distributionData.getMean()).isWithin(TOLERANCE).of(7.7); assertThat(distributionData.getCount()).isEqualTo(10); assertThat(distributionData.getMin()).isWithin(TOLERANCE).of(1.1); @@ -80,53 +79,34 @@ public class AggregationDataTest { @Test public void testEquals() { new EqualsTester() - .addEqualityGroup( - SumDataDouble.create(10.0), - SumDataDouble.create(10.0)) - .addEqualityGroup( - SumDataDouble.create(20.0), - SumDataDouble.create(20.0)) - .addEqualityGroup( - SumDataLong.create(20), - SumDataLong.create(20)) - .addEqualityGroup( - CountData.create(40), - CountData.create(40)) - .addEqualityGroup( - CountData.create(80), - CountData.create(80)) + .addEqualityGroup(SumDataDouble.create(10.0), SumDataDouble.create(10.0)) + .addEqualityGroup(SumDataDouble.create(20.0), SumDataDouble.create(20.0)) + .addEqualityGroup(SumDataLong.create(20), SumDataLong.create(20)) + .addEqualityGroup(CountData.create(40), CountData.create(40)) + .addEqualityGroup(CountData.create(80), CountData.create(80)) .addEqualityGroup( DistributionData.create(10, 10, 1, 1, 0, Arrays.asList(0L, 10L, 0L)), DistributionData.create(10, 10, 1, 1, 0, Arrays.asList(0L, 10L, 0L))) - .addEqualityGroup( - DistributionData.create(10, 10, 1, 1, 0, Arrays.asList(0L, 10L, 100L))) - .addEqualityGroup( - DistributionData.create(110, 10, 1, 1, 0, Arrays.asList(0L, 10L, 0L))) - .addEqualityGroup( - DistributionData.create(10, 110, 1, 1, 0, Arrays.asList(0L, 10L, 0L))) - .addEqualityGroup( - DistributionData.create(10, 10, -1, 1, 0, Arrays.asList(0L, 10L, 0L))) - .addEqualityGroup( - DistributionData.create(10, 10, 1, 5, 0, Arrays.asList(0L, 10L, 0L))) - .addEqualityGroup( - DistributionData.create(10, 10, 1, 1, 55.5, Arrays.asList(0L, 10L, 0L))) - .addEqualityGroup( - MeanData.create(5.0, 1), - MeanData.create(5.0, 1)) - .addEqualityGroup( - MeanData.create(-5.0, 1), - MeanData.create(-5.0, 1)) + .addEqualityGroup(DistributionData.create(10, 10, 1, 1, 0, Arrays.asList(0L, 10L, 100L))) + .addEqualityGroup(DistributionData.create(110, 10, 1, 1, 0, Arrays.asList(0L, 10L, 0L))) + .addEqualityGroup(DistributionData.create(10, 110, 1, 1, 0, Arrays.asList(0L, 10L, 0L))) + .addEqualityGroup(DistributionData.create(10, 10, -1, 1, 0, Arrays.asList(0L, 10L, 0L))) + .addEqualityGroup(DistributionData.create(10, 10, 1, 5, 0, Arrays.asList(0L, 10L, 0L))) + .addEqualityGroup(DistributionData.create(10, 10, 1, 1, 55.5, Arrays.asList(0L, 10L, 0L))) + .addEqualityGroup(MeanData.create(5.0, 1), MeanData.create(5.0, 1)) + .addEqualityGroup(MeanData.create(-5.0, 1), MeanData.create(-5.0, 1)) .testEquals(); } @Test public void testMatchAndGet() { - List<AggregationData> aggregations = Arrays.asList( - SumDataDouble.create(10.0), - SumDataLong.create(100000000), - CountData.create(40), - MeanData.create(5.0, 1), - DistributionData.create(1, 1, 1, 1, 0, Arrays.asList(0L, 10L, 0L))); + List<AggregationData> aggregations = + Arrays.asList( + SumDataDouble.create(10.0), + SumDataLong.create(100000000), + CountData.create(40), + MeanData.create(5.0, 1), + DistributionData.create(1, 1, 1, 1, 0, Arrays.asList(0L, 10L, 0L))); final List<Object> actual = new ArrayList<Object>(); for (AggregationData aggregation : aggregations) { @@ -169,7 +149,7 @@ public class AggregationDataTest { Functions.<Void>throwIllegalArgumentException()); } - assertThat(actual).isEqualTo( - Arrays.asList(10.0, 100000000L, 40L, 5.0, Arrays.asList(0L, 10L, 0L))); + assertThat(actual) + .isEqualTo(Arrays.asList(10.0, 100000000L, 40L, 5.0, Arrays.asList(0L, 10L, 0L))); } } diff --git a/api/src/test/java/io/opencensus/stats/AggregationTest.java b/api/src/test/java/io/opencensus/stats/AggregationTest.java index 66376cbb..3ef131b8 100644 --- a/api/src/test/java/io/opencensus/stats/AggregationTest.java +++ b/api/src/test/java/io/opencensus/stats/AggregationTest.java @@ -38,8 +38,7 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class AggregationTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void testCreateDistribution() { @@ -58,60 +57,56 @@ public class AggregationTest { @Test public void testEquals() { new EqualsTester() - .addEqualityGroup( - Sum.create(), - Sum.create()) - .addEqualityGroup( - Count.create(), - Count.create()) + .addEqualityGroup(Sum.create(), Sum.create()) + .addEqualityGroup(Count.create(), Count.create()) .addEqualityGroup( Distribution.create(BucketBoundaries.create(Arrays.asList(-10.0, 1.0, 5.0))), Distribution.create(BucketBoundaries.create(Arrays.asList(-10.0, 1.0, 5.0)))) .addEqualityGroup( Distribution.create(BucketBoundaries.create(Arrays.asList(0.0, 1.0, 5.0))), Distribution.create(BucketBoundaries.create(Arrays.asList(0.0, 1.0, 5.0)))) - .addEqualityGroup( - Mean.create(), - Mean.create()) + .addEqualityGroup(Mean.create(), Mean.create()) .testEquals(); } @Test public void testMatch() { - List<Aggregation> aggregations = Arrays.asList( - Sum.create(), - Count.create(), - Mean.create(), - Distribution.create(BucketBoundaries.create(Arrays.asList(-10.0, 1.0, 5.0)))); + List<Aggregation> aggregations = + Arrays.asList( + Sum.create(), + Count.create(), + Mean.create(), + Distribution.create(BucketBoundaries.create(Arrays.asList(-10.0, 1.0, 5.0)))); List<String> actual = new ArrayList<String>(); for (Aggregation aggregation : aggregations) { - actual.add(aggregation.match( - new Function<Sum, String>() { - @Override - public String apply(Sum arg) { - return "SUM"; - } - }, - new Function<Count, String>() { - @Override - public String apply(Count arg) { - return "COUNT"; - } - }, - new Function<Mean, String>() { - @Override - public String apply(Mean arg) { - return "MEAN"; - } - }, - new Function<Distribution, String>() { - @Override - public String apply(Distribution arg) { - return "DISTRIBUTION"; - } - }, - Functions.<String>throwIllegalArgumentException())); + actual.add( + aggregation.match( + new Function<Sum, String>() { + @Override + public String apply(Sum arg) { + return "SUM"; + } + }, + new Function<Count, String>() { + @Override + public String apply(Count arg) { + return "COUNT"; + } + }, + new Function<Mean, String>() { + @Override + public String apply(Mean arg) { + return "MEAN"; + } + }, + new Function<Distribution, String>() { + @Override + public String apply(Distribution arg) { + return "DISTRIBUTION"; + } + }, + Functions.<String>throwIllegalArgumentException())); } assertThat(actual).isEqualTo(Arrays.asList("SUM", "COUNT", "MEAN", "DISTRIBUTION")); diff --git a/api/src/test/java/io/opencensus/stats/BucketBoundariesTest.java b/api/src/test/java/io/opencensus/stats/BucketBoundariesTest.java index e3fd3222..36f2edb4 100644 --- a/api/src/test/java/io/opencensus/stats/BucketBoundariesTest.java +++ b/api/src/test/java/io/opencensus/stats/BucketBoundariesTest.java @@ -28,14 +28,11 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** - * Unit tests for {@link io.opencensus.stats.BucketBoundaries}. - */ +/** Unit tests for {@link io.opencensus.stats.BucketBoundaries}. */ @RunWith(JUnit4.class) public class BucketBoundariesTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule public final ExpectedException thrown = ExpectedException.none(); @Test public void testConstructBoundaries() { diff --git a/api/src/test/java/io/opencensus/stats/MeasureTest.java b/api/src/test/java/io/opencensus/stats/MeasureTest.java index 0c1e3867..a9302425 100644 --- a/api/src/test/java/io/opencensus/stats/MeasureTest.java +++ b/api/src/test/java/io/opencensus/stats/MeasureTest.java @@ -36,8 +36,7 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public final class MeasureTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule public final ExpectedException thrown = ExpectedException.none(); @Test public void testConstants() { @@ -61,10 +60,7 @@ public final class MeasureTest { @Test public void testMeasureDoubleComponents() { - Measure measurement = Measure.MeasureDouble.create( - "Foo", - "The description of Foo", - "Mbit/s"); + Measure measurement = Measure.MeasureDouble.create("Foo", "The description of Foo", "Mbit/s"); assertThat(measurement.getName()).isEqualTo("Foo"); assertThat(measurement.getDescription()).isEqualTo("The description of Foo"); assertThat(measurement.getUnit()).isEqualTo("Mbit/s"); @@ -72,10 +68,7 @@ public final class MeasureTest { @Test public void testMeasureLongComponents() { - Measure measurement = Measure.MeasureLong.create( - "Bar", - "The description of Bar", - "1"); + Measure measurement = Measure.MeasureLong.create("Bar", "The description of Bar", "1"); assertThat(measurement.getName()).isEqualTo("Bar"); assertThat(measurement.getDescription()).isEqualTo("The description of Bar"); assertThat(measurement.getUnit()).isEqualTo("1"); @@ -85,19 +78,9 @@ public final class MeasureTest { public void testMeasureDoubleEquals() { new EqualsTester() .addEqualityGroup( - Measure.MeasureDouble.create( - "name", - "description", - "bit/s"), - Measure.MeasureDouble.create( - "name", - "description", - "bit/s")) - .addEqualityGroup( - Measure.MeasureDouble.create( - "name", - "description 2", - "bit/s")) + Measure.MeasureDouble.create("name", "description", "bit/s"), + Measure.MeasureDouble.create("name", "description", "bit/s")) + .addEqualityGroup(Measure.MeasureDouble.create("name", "description 2", "bit/s")) .testEquals(); } @@ -105,27 +88,18 @@ public final class MeasureTest { public void testMeasureLongEquals() { new EqualsTester() .addEqualityGroup( - Measure.MeasureLong.create( - "name", - "description", - "bit/s"), - Measure.MeasureLong.create( - "name", - "description", - "bit/s")) - .addEqualityGroup( - Measure.MeasureLong.create( - "name", - "description 2", - "bit/s")) + Measure.MeasureLong.create("name", "description", "bit/s"), + Measure.MeasureLong.create("name", "description", "bit/s")) + .addEqualityGroup(Measure.MeasureLong.create("name", "description 2", "bit/s")) .testEquals(); } @Test public void testMatch() { - List<Measure> measures = Arrays.asList( - MeasureDouble.create("measure1", "description", "1"), - MeasureLong.create("measure2", "description", "1")); + List<Measure> measures = + Arrays.asList( + MeasureDouble.create("measure1", "description", "1"), + MeasureLong.create("measure2", "description", "1")); List<String> outputs = Lists.newArrayList(); for (Measure measure : measures) { outputs.add( diff --git a/api/src/test/java/io/opencensus/stats/NoopStatsTest.java b/api/src/test/java/io/opencensus/stats/NoopStatsTest.java index 9d686251..9a52b7db 100644 --- a/api/src/test/java/io/opencensus/stats/NoopStatsTest.java +++ b/api/src/test/java/io/opencensus/stats/NoopStatsTest.java @@ -84,10 +84,7 @@ public final class NoopStatsTest { // exception. @Test public void noopStatsRecorder_Record() { - NoopStats.getNoopStatsRecorder() - .newMeasureMap() - .put(MEASURE, 5) - .record(tagContext); + NoopStats.getNoopStatsRecorder().newMeasureMap().put(MEASURE, 5).record(tagContext); } // The NoopStatsRecorder should do nothing, so this test just checks that record doesn't throw an diff --git a/api/src/test/java/io/opencensus/stats/StatsTest.java b/api/src/test/java/io/opencensus/stats/StatsTest.java index cb2f3a23..cc60d6c0 100644 --- a/api/src/test/java/io/opencensus/stats/StatsTest.java +++ b/api/src/test/java/io/opencensus/stats/StatsTest.java @@ -45,16 +45,15 @@ public final class StatsTest { @Test public void loadStatsManager_IgnoresMissingClasses() { - assertThat( - Stats.loadStatsComponent( - new ClassLoader() { - @Override - public Class<?> loadClass(String name) throws ClassNotFoundException { - throw new ClassNotFoundException(); - } - }) - .getClass() - .getName()) + ClassLoader classLoader = + new ClassLoader() { + @Override + public Class<?> loadClass(String name) throws ClassNotFoundException { + throw new ClassNotFoundException(); + } + }; + + assertThat(Stats.loadStatsComponent(classLoader).getClass().getName()) .isEqualTo("io.opencensus.stats.NoopStats$NoopStatsComponent"); } diff --git a/api/src/test/java/io/opencensus/stats/ViewDataTest.java b/api/src/test/java/io/opencensus/stats/ViewDataTest.java index 285921db..028506fb 100644 --- a/api/src/test/java/io/opencensus/stats/ViewDataTest.java +++ b/api/src/test/java/io/opencensus/stats/ViewDataTest.java @@ -48,8 +48,7 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public final class ViewDataTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void testCumulativeViewData() { @@ -86,28 +85,19 @@ public final class ViewDataTest { ViewData.create( cumulativeView, ENTRIES, - CumulativeData.create( - Timestamp.fromMillis(1000), Timestamp.fromMillis(2000))), + CumulativeData.create(Timestamp.fromMillis(1000), Timestamp.fromMillis(2000))), ViewData.create( cumulativeView, ENTRIES, - CumulativeData.create( - Timestamp.fromMillis(1000), Timestamp.fromMillis(2000)))) + CumulativeData.create(Timestamp.fromMillis(1000), Timestamp.fromMillis(2000)))) .addEqualityGroup( ViewData.create( cumulativeView, ENTRIES, - CumulativeData.create( - Timestamp.fromMillis(1000), Timestamp.fromMillis(3000)))) + CumulativeData.create(Timestamp.fromMillis(1000), Timestamp.fromMillis(3000)))) .addEqualityGroup( - ViewData.create( - intervalView, - ENTRIES, - IntervalData.create(Timestamp.fromMillis(2000))), - ViewData.create( - intervalView, - ENTRIES, - IntervalData.create(Timestamp.fromMillis(2000)))) + ViewData.create(intervalView, ENTRIES, IntervalData.create(Timestamp.fromMillis(2000))), + ViewData.create(intervalView, ENTRIES, IntervalData.create(Timestamp.fromMillis(2000)))) .addEqualityGroup( ViewData.create( intervalView, @@ -163,8 +153,7 @@ public final class ViewDataTest { ViewData.create( View.create(NAME, DESCRIPTION, MEASURE, DISTRIBUTION, tagKeys, INTERVAL_HOUR), ENTRIES, - CumulativeData.create( - Timestamp.fromMillis(1000), Timestamp.fromMillis(2000))); + CumulativeData.create(Timestamp.fromMillis(1000), Timestamp.fromMillis(2000))); } @Test @@ -196,11 +185,11 @@ public final class ViewDataTest { private static final AggregationWindow CUMULATIVE = Cumulative.create(); private static final AggregationWindow INTERVAL_HOUR = Interval.create(Duration.create(3600, 0)); - private static final BucketBoundaries BUCKET_BOUNDARIES = BucketBoundaries.create( - Arrays.asList(10.0, 20.0, 30.0, 40.0)); + private static final BucketBoundaries BUCKET_BOUNDARIES = + BucketBoundaries.create(Arrays.asList(10.0, 20.0, 30.0, 40.0)); private static final Aggregation DISTRIBUTION = Distribution.create(BUCKET_BOUNDARIES); - + private static final ImmutableMap<List<TagValue>, DistributionData> ENTRIES = ImmutableMap.of( Arrays.asList(V1, V2), @@ -213,8 +202,6 @@ public final class ViewDataTest { // description private static final String DESCRIPTION = "test-view-descriptor description"; // measure - private static final Measure MEASURE = Measure.MeasureDouble.create( - "measure", - "measure description", - "1"); + private static final Measure MEASURE = + Measure.MeasureDouble.create("measure", "measure description", "1"); } diff --git a/api/src/test/java/io/opencensus/stats/ViewTest.java b/api/src/test/java/io/opencensus/stats/ViewTest.java index 81584ef9..c135713c 100644 --- a/api/src/test/java/io/opencensus/stats/ViewTest.java +++ b/api/src/test/java/io/opencensus/stats/ViewTest.java @@ -46,8 +46,7 @@ public final class ViewTest { @Test public void testDistributionView() { - final View view = View.create( - NAME, DESCRIPTION, MEASURE, MEAN, keys, Cumulative.create()); + final View view = View.create(NAME, DESCRIPTION, MEASURE, MEAN, keys, Cumulative.create()); assertThat(view.getName()).isEqualTo(NAME); assertThat(view.getDescription()).isEqualTo(DESCRIPTION); assertThat(view.getMeasure().getName()).isEqualTo(MEASURE.getName()); @@ -59,12 +58,10 @@ public final class ViewTest { @Test public void testIntervalView() { - final View view = View.create( - NAME, DESCRIPTION, MEASURE, MEAN, keys, Interval.create(MINUTE)); + final View view = View.create(NAME, DESCRIPTION, MEASURE, MEAN, keys, Interval.create(MINUTE)); assertThat(view.getName()).isEqualTo(NAME); assertThat(view.getDescription()).isEqualTo(DESCRIPTION); - assertThat(view.getMeasure().getName()) - .isEqualTo(MEASURE.getName()); + assertThat(view.getMeasure().getName()).isEqualTo(MEASURE.getName()); assertThat(view.getAggregation()).isEqualTo(MEAN); assertThat(view.getColumns()).hasSize(2); assertThat(view.getColumns()).containsExactly(FOO, BAR).inOrder(); @@ -75,21 +72,15 @@ public final class ViewTest { public void testViewEquals() { new EqualsTester() .addEqualityGroup( - View.create( - NAME, DESCRIPTION, MEASURE, MEAN, keys, Cumulative.create()), - View.create( - NAME, DESCRIPTION, MEASURE, MEAN, keys, Cumulative.create())) + View.create(NAME, DESCRIPTION, MEASURE, MEAN, keys, Cumulative.create()), + View.create(NAME, DESCRIPTION, MEASURE, MEAN, keys, Cumulative.create())) .addEqualityGroup( - View.create( - NAME, DESCRIPTION + 2, MEASURE, MEAN, keys, Cumulative.create())) + View.create(NAME, DESCRIPTION + 2, MEASURE, MEAN, keys, Cumulative.create())) .addEqualityGroup( - View.create( - NAME, DESCRIPTION, MEASURE, MEAN, keys, Interval.create(MINUTE)), - View.create( - NAME, DESCRIPTION, MEASURE, MEAN, keys, Interval.create(MINUTE))) + View.create(NAME, DESCRIPTION, MEASURE, MEAN, keys, Interval.create(MINUTE)), + View.create(NAME, DESCRIPTION, MEASURE, MEAN, keys, Interval.create(MINUTE))) .addEqualityGroup( - View.create( - NAME, DESCRIPTION, MEASURE, MEAN, keys, Interval.create(TWO_MINUTES))) + View.create(NAME, DESCRIPTION, MEASURE, MEAN, keys, Interval.create(TWO_MINUTES))) .testEquals(); } @@ -142,16 +133,15 @@ public final class ViewTest { @Test public void testViewNameEquals() { new EqualsTester() - .addEqualityGroup( - View.Name.create("view-1"), View.Name.create("view-1")) + .addEqualityGroup(View.Name.create("view-1"), View.Name.create("view-1")) .addEqualityGroup(View.Name.create("view-2")) .testEquals(); } private static final View.Name NAME = View.Name.create("test-view-name"); private static final String DESCRIPTION = "test-view-name description"; - private static final Measure MEASURE = Measure.MeasureDouble.create( - "measure", "measure description", "1"); + private static final Measure MEASURE = + Measure.MeasureDouble.create("measure", "measure description", "1"); private static final TagKey FOO = TagKey.create("foo"); private static final TagKey BAR = TagKey.create("bar"); private static final List<TagKey> keys = ImmutableList.of(FOO, BAR); diff --git a/api/src/test/java/io/opencensus/tags/InternalUtilsTest.java b/api/src/test/java/io/opencensus/tags/InternalUtilsTest.java index db5a2d9d..65482de1 100644 --- a/api/src/test/java/io/opencensus/tags/InternalUtilsTest.java +++ b/api/src/test/java/io/opencensus/tags/InternalUtilsTest.java @@ -31,9 +31,7 @@ public final class InternalUtilsTest { @Test public void getTags() { final Iterator<Tag> iterator = - Lists.<Tag>newArrayList( - Tag.create(TagKey.create("k"), TagValue.create("v"))) - .iterator(); + Lists.<Tag>newArrayList(Tag.create(TagKey.create("k"), TagValue.create("v"))).iterator(); TagContext ctx = new TagContext() { @Override diff --git a/api/src/test/java/io/opencensus/tags/TagContextTest.java b/api/src/test/java/io/opencensus/tags/TagContextTest.java index 0e229323..813e1a76 100644 --- a/api/src/test/java/io/opencensus/tags/TagContextTest.java +++ b/api/src/test/java/io/opencensus/tags/TagContextTest.java @@ -30,10 +30,8 @@ import org.junit.runners.JUnit4; /** Tests for {@link TagContext}. */ @RunWith(JUnit4.class) public final class TagContextTest { - private static final Tag TAG1 = - Tag.create(TagKey.create("key"), TagValue.create("val")); - private static final Tag TAG2 = - Tag.create(TagKey.create("key2"), TagValue.create("val")); + private static final Tag TAG1 = Tag.create(TagKey.create("key"), TagValue.create("val")); + private static final Tag TAG2 = Tag.create(TagKey.create("key2"), TagValue.create("val")); @Test public void equals_IgnoresTagOrderAndTagContextClass() { diff --git a/api/src/test/java/io/opencensus/tags/TagTest.java b/api/src/test/java/io/opencensus/tags/TagTest.java index f3fe6dc4..3c899e65 100644 --- a/api/src/test/java/io/opencensus/tags/TagTest.java +++ b/api/src/test/java/io/opencensus/tags/TagTest.java @@ -39,10 +39,8 @@ public final class TagTest { .addEqualityGroup( Tag.create(TagKey.create("Key"), TagValue.create("foo")), Tag.create(TagKey.create("Key"), TagValue.create("foo"))) - .addEqualityGroup( - Tag.create(TagKey.create("Key"), TagValue.create("bar"))) - .addEqualityGroup( - Tag.create(TagKey.create("Key2"), TagValue.create("foo"))) + .addEqualityGroup(Tag.create(TagKey.create("Key"), TagValue.create("bar"))) + .addEqualityGroup(Tag.create(TagKey.create("Key2"), TagValue.create("foo"))) .testEquals(); } } diff --git a/api/src/test/java/io/opencensus/trace/AttributeValueTest.java b/api/src/test/java/io/opencensus/trace/AttributeValueTest.java index 01226d1b..b7e0afbd 100644 --- a/api/src/test/java/io/opencensus/trace/AttributeValueTest.java +++ b/api/src/test/java/io/opencensus/trace/AttributeValueTest.java @@ -53,7 +53,8 @@ public class AttributeValueTest { fail("Expected a String"); return null; } - }, Functions.throwIllegalArgumentException()); + }, + Functions.throwIllegalArgumentException()); } @Test @@ -80,7 +81,8 @@ public class AttributeValueTest { fail("Expected a Boolean"); return null; } - }, Functions.throwIllegalArgumentException()); + }, + Functions.throwIllegalArgumentException()); } @Test @@ -107,7 +109,8 @@ public class AttributeValueTest { assertThat(longValue).isEqualTo(123456L); return null; } - }, Functions.throwIllegalArgumentException()); + }, + Functions.throwIllegalArgumentException()); } @Test diff --git a/build.gradle b/build.gradle index 7a0448e1..e32b72be 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,7 @@ buildscript { classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.11' classpath "net.ltgt.gradle:gradle-apt-plugin:0.10" classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0' + classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.6" } } @@ -28,10 +29,11 @@ subprojects { // The plugin only has an effect if a signature is specified apply plugin: 'ru.vyarus.animalsniffer' apply plugin: 'findbugs' - apply plugin: "net.ltgt.apt" + apply plugin: 'net.ltgt.apt' // Plugins that require java8 if (JavaVersion.current().isJava8Compatible()) { apply plugin: "net.ltgt.errorprone" + apply plugin: 'com.github.sherter.google-java-format' } group = "io.opencensus" @@ -182,6 +184,23 @@ subprojects { checkstyleMain.enabled = JavaVersion.current().isJava8Compatible() checkstyleTest.enabled = JavaVersion.current().isJava8Compatible() + // Google formatter works only on java8. + if (JavaVersion.current().isJava8Compatible()) { + googleJavaFormat { + toolVersion '1.5' + } + + tasks.googleJavaFormat { + source = sourceSets*.allJava + include '**/*.java' + } + + tasks.verifyGoogleJavaFormat { + source = sourceSets*.allJava + include '**/*.java' + } + } + signing { required false sign configurations.archives @@ -250,6 +269,7 @@ subprojects { } } } + // Upload the following artifacts only: uploadArchives.onlyIf { name in ['opencensus-api', diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentBuilderListener.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentBuilderListener.java index 548b14fc..54a82442 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentBuilderListener.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentBuilderListener.java @@ -33,44 +33,36 @@ final class AgentBuilderListener implements AgentBuilder.Listener { @Override public void onTransformation( - TypeDescription typeDescription, - ClassLoader classLoader, - JavaModule module, - boolean loaded, - DynamicType dynamicType) { + TypeDescription typeDescription, + ClassLoader classLoader, + JavaModule module, + boolean loaded, + DynamicType dynamicType) { logger.log(Level.FINE, "{0}", typeDescription); } @Override public void onIgnored( - TypeDescription typeDescription, - ClassLoader classLoader, - JavaModule module, - boolean loaded) { - } + TypeDescription typeDescription, + ClassLoader classLoader, + JavaModule module, + boolean loaded) {} @Override public void onError( - String typeName, - ClassLoader classLoader, - JavaModule module, - boolean loaded, - Throwable throwable) { + String typeName, + ClassLoader classLoader, + JavaModule module, + boolean loaded, + Throwable throwable) { logger.log(Level.WARNING, "Failed to handle " + typeName, throwable); } @Override public void onComplete( - String typeName, - ClassLoader classLoader, - JavaModule module, - boolean loaded) { - } + String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {} @Override - public void onDiscovery(String typeName, - ClassLoader classLoader, - JavaModule module, - boolean loaded) { - } + public void onDiscovery( + String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {} } diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentMain.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentMain.java index 5e1e7482..020987b4 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentMain.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/AgentMain.java @@ -30,34 +30,33 @@ import java.util.logging.Logger; import net.bytebuddy.agent.builder.AgentBuilder; /** - * The <b>OpenCensus Agent for Java</b> collects and sends latency data about your Java - * process to OpenCensus backends such as Stackdriver Trace for analysis and visualization. + * The <b>OpenCensus Agent for Java</b> collects and sends latency data about your Java process to + * OpenCensus backends such as Stackdriver Trace for analysis and visualization. * - * <p>To enable the *OpenCensus Agent for Java* for your application, add the option - * <code>-javaagent:path/to/opencensus-contrib-agent.jar</code> to the invocation of the - * <code>java</code> executable as shown in the following example: + * <p>To enable the *OpenCensus Agent for Java* for your application, add the option <code> + * -javaagent:path/to/opencensus-contrib-agent.jar</code> to the invocation of the <code>java</code> + * executable as shown in the following example: * * <pre> * java -javaagent:path/to/opencensus-contrib-agent.jar ... * </pre> * - * @see <a href="https://github.com/census-instrumentation/instrumentation-java/tree/master/agent">https://github.com/census-instrumentation/instrumentation-java/tree/master/agent</a> + * @see <a + * href="https://github.com/census-instrumentation/instrumentation-java/tree/master/agent">https://github.com/census-instrumentation/instrumentation-java/tree/master/agent</a> */ public final class AgentMain { private static final Logger logger = Logger.getLogger(AgentMain.class.getName()); - private AgentMain() { - } + private AgentMain() {} /** * Initializes the OpenCensus Agent for Java. * * @param agentArgs agent options, passed as a single string by the JVM - * @param instrumentation the {@link Instrumentation} object provided by the JVM for - * instrumenting Java programming language code + * @param instrumentation the {@link Instrumentation} object provided by the JVM for instrumenting + * Java programming language code * @throws Exception if initialization of the agent fails - * * @see java.lang.instrument */ public static void premain(String agentArgs, Instrumentation instrumentation) throws Exception { @@ -69,12 +68,13 @@ public final class AgentMain { // from classes loaded by the bootstrap classloader. Thus, these classes have to be loaded by // the bootstrap classloader, too. instrumentation.appendToBootstrapClassLoaderSearch( - new JarFile(Resources.getResourceAsTempFile("bootstrap.jar"))); + new JarFile(Resources.getResourceAsTempFile("bootstrap.jar"))); checkLoadedByBootstrapClassloader(ContextTrampoline.class); checkLoadedByBootstrapClassloader(ContextStrategy.class); - AgentBuilder agentBuilder = new AgentBuilder.Default() + AgentBuilder agentBuilder = + new AgentBuilder.Default() .disableClassFormatChanges() .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION) .with(new AgentBuilderListener()) @@ -88,8 +88,7 @@ public final class AgentMain { } private static void checkLoadedByBootstrapClassloader(Class<?> clazz) { - checkState(clazz.getClassLoader() == null, - "%s must be loaded by the bootstrap classloader", - clazz); + checkState( + clazz.getClassLoader() == null, "%s must be loaded by the bootstrap classloader", clazz); } } diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/Resources.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/Resources.java index 31170923..33b71feb 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/Resources.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/Resources.java @@ -28,9 +28,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -/** - * Helper methods for working with resources. - */ +/** Helper methods for working with resources. */ final class Resources { /** @@ -53,7 +51,7 @@ final class Resources { @VisibleForTesting static void getResourceAsTempFile(String resourceName, File file, OutputStream outputStream) - throws IOException { + throws IOException { file.deleteOnExit(); InputStream is = getResourceAsStream(resourceName); @@ -68,7 +66,7 @@ final class Resources { InputStream is = Resources.class.getResourceAsStream(resourceName); if (is == null) { throw new FileNotFoundException( - "Cannot find resource '" + resourceName + "' on the class path."); + "Cannot find resource '" + resourceName + "' on the class path."); } return is; } diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextStrategy.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextStrategy.java index 6f3b97aa..a51a9bfd 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextStrategy.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextStrategy.java @@ -16,9 +16,7 @@ package io.opencensus.contrib.agent.bootstrap; -/** - * Strategy interface for accessing and manipulating the context. - */ +/** Strategy interface for accessing and manipulating the context. */ public interface ContextStrategy { /** diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextTrampoline.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextTrampoline.java index f1efad35..dd250790 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextTrampoline.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/bootstrap/ContextTrampoline.java @@ -24,9 +24,9 @@ package io.opencensus.contrib.agent.bootstrap; * context by accessing and manipulating the context through the {@link ContextStrategy} interface. * * <p>Both {@link ContextTrampoline} and {@link ContextStrategy} are loaded by the bootstrap - * classloader so that they can be used from classes loaded by the bootstrap classloader. - * A concrete implementation of {@link ContextStrategy} will be loaded by the system classloader. - * This allows for using the same context implementation as the instrumented application. + * classloader so that they can be used from classes loaded by the bootstrap classloader. A concrete + * implementation of {@link ContextStrategy} will be loaded by the system classloader. This allows + * for using the same context implementation as the instrumented application. * * <p>{@code ContextTrampoline} is implemented as a static class to allow for easy and fast use from * instrumented bytecode. We cannot use dependency injection for the instrumented bytecode. @@ -38,8 +38,7 @@ public final class ContextTrampoline { // other method of this class is called. private static ContextStrategy contextStrategy; - private ContextTrampoline() { - } + private ContextTrampoline() {} /** * Sets the concrete strategy for accessing and manipulating the context. @@ -67,7 +66,6 @@ public final class ContextTrampoline { * * @param runnable a {@link Runnable} object * @return the wrapped {@link Runnable} object - * * @see ContextStrategy#wrapInCurrentContext */ public static Runnable wrapInCurrentContext(Runnable runnable) { diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/deps/package-info.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/deps/package-info.java index 25de9eb0..71e81270 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/deps/package-info.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/deps/package-info.java @@ -18,6 +18,6 @@ package io.opencensus.contrib.agent.deps; /** * Contains third party packages, such as Byte Buddy, Guava, etc., relocated here by the build - * process to avoid any conflicts of the agent's classes with the app's classes, which are loaded - * by the same classloader (the system classloader). + * process to avoid any conflicts of the agent's classes with the app's classes, which are loaded by + * the same classloader (the system classloader). */ diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextStrategyImpl.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextStrategyImpl.java index 37fb9e0f..e99fbd3b 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextStrategyImpl.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextStrategyImpl.java @@ -23,8 +23,8 @@ import io.opencensus.contrib.agent.bootstrap.ContextStrategy; import java.lang.ref.WeakReference; /** - * Implementation of {@link ContextStrategy} for accessing and manipulating the - * {@link io.grpc.Context}. + * Implementation of {@link ContextStrategy} for accessing and manipulating the {@link + * io.grpc.Context}. */ final class ContextStrategyImpl implements ContextStrategy { @@ -49,8 +49,7 @@ final class ContextStrategyImpl implements ContextStrategy { * <p>NB: Using thread IDs as keys was considered: It's unclear how to safely detect and cleanup * otherwise unreferenced threads IDs from the map. */ - private final Cache<Thread, Context> savedContexts - = CacheBuilder.newBuilder().weakKeys().build(); + private final Cache<Thread, Context> savedContexts = CacheBuilder.newBuilder().weakKeys().build(); @Override public Runnable wrapInCurrentContext(Runnable runnable) { diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextTrampolineInitializer.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextTrampolineInitializer.java index 964ef053..1ed18857 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextTrampolineInitializer.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ContextTrampolineInitializer.java @@ -21,9 +21,7 @@ import io.opencensus.contrib.agent.bootstrap.ContextStrategy; import io.opencensus.contrib.agent.bootstrap.ContextTrampoline; import net.bytebuddy.agent.builder.AgentBuilder; -/** - * Initializes the {@link ContextTrampoline} with a concrete {@link ContextStrategy}. - */ +/** Initializes the {@link ContextTrampoline} with a concrete {@link ContextStrategy}. */ @AutoService(Instrumenter.class) public final class ContextTrampolineInitializer implements Instrumenter { diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ExecutorInstrumentation.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ExecutorInstrumentation.java index 3859744f..669c0627 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ExecutorInstrumentation.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ExecutorInstrumentation.java @@ -36,8 +36,8 @@ import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.utility.JavaModule; /** - * Propagates the context of the caller of {@link Executor#execute} to the submitted - * {@link Runnable}, just like the Microsoft .Net Framework propagates the <a + * Propagates the context of the caller of {@link Executor#execute} to the submitted {@link + * Runnable}, just like the Microsoft .Net Framework propagates the <a * href="https://msdn.microsoft.com/en-us/library/system.threading.executioncontext(v=vs.110).aspx">System.Threading.ExecutionContext</a>. */ @AutoService(Instrumenter.class) @@ -47,16 +47,17 @@ public final class ExecutorInstrumentation implements Instrumenter { public AgentBuilder instrument(AgentBuilder agentBuilder) { checkNotNull(agentBuilder, "agentBuilder"); - return agentBuilder - .type(createMatcher()) - .transform(new Transformer()); + return agentBuilder.type(createMatcher()).transform(new Transformer()); } private static class Transformer implements AgentBuilder.Transformer { @Override - public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, - TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) { + public DynamicType.Builder<?> transform( + DynamicType.Builder<?> builder, + TypeDescription typeDescription, + ClassLoader classLoader, + JavaModule module) { return builder.visit(Advice.to(Execute.class).on(named("execute"))); } } @@ -69,9 +70,12 @@ public final class ExecutorInstrumentation implements Instrumenter { // turned into a no-op to avoid another unneeded context propagation. Likewise, when using // FixedContextExecutor, the automatic context propagation added by the agent is unneeded. return isSubTypeOf(Executor.class) - .and(not(isAbstract())) - .and(not(nameStartsWith("io.grpc.Context$") - .and(nameEndsWith("CurrentContextExecutor") + .and(not(isAbstract())) + .and( + not( + nameStartsWith("io.grpc.Context$") + .and( + nameEndsWith("CurrentContextExecutor") .or(nameEndsWith("FixedContextExecutor"))))); } @@ -88,7 +92,7 @@ public final class ExecutorInstrumentation implements Instrumenter { */ @Advice.OnMethodEnter @SuppressWarnings(value = "UnusedAssignment") - @SuppressFBWarnings(value = {"DLS_DEAD_LOCAL_STORE", "UPM_UNCALLED_PRIVATE_METHOD",}) + @SuppressFBWarnings(value = {"DLS_DEAD_LOCAL_STORE", "UPM_UNCALLED_PRIVATE_METHOD"}) private static void enter(@Advice.Argument(value = 0, readOnly = false) Runnable runnable) { runnable = ContextTrampoline.wrapInCurrentContext(runnable); } diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/Instrumenter.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/Instrumenter.java index a485177d..9168eef6 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/Instrumenter.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/Instrumenter.java @@ -18,16 +18,14 @@ package io.opencensus.contrib.agent.instrumentation; import net.bytebuddy.agent.builder.AgentBuilder; -/** - * Interface for plug-ins that add bytecode instrumentation. - */ +/** Interface for plug-ins that add bytecode instrumentation. */ public interface Instrumenter { /** * Adds bytecode instrumentation to the given {@link AgentBuilder}. * * @param agentBuilder an {@link AgentBuilder} object to which the additional instrumentation is - * added + * added * @return an {@link AgentBuilder} object having the additional instrumentation */ AgentBuilder instrument(AgentBuilder agentBuilder); diff --git a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ThreadInstrumentation.java b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ThreadInstrumentation.java index cb185445..a1b6e17e 100644 --- a/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ThreadInstrumentation.java +++ b/contrib/agent/src/main/java/io/opencensus/contrib/agent/instrumentation/ThreadInstrumentation.java @@ -45,19 +45,20 @@ public final class ThreadInstrumentation implements Instrumenter { public AgentBuilder instrument(AgentBuilder agentBuilder) { checkNotNull(agentBuilder, "agentBuilder"); - return agentBuilder - .type(isSubTypeOf(Thread.class)) - .transform(new Transformer()); + return agentBuilder.type(isSubTypeOf(Thread.class)).transform(new Transformer()); } private static class Transformer implements AgentBuilder.Transformer { @Override - public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, - TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) { + public DynamicType.Builder<?> transform( + DynamicType.Builder<?> builder, + TypeDescription typeDescription, + ClassLoader classLoader, + JavaModule module) { return builder - .visit(Advice.to(Start.class).on(named("start"))) - .visit(Advice.to(Run.class).on(named("run"))); + .visit(Advice.to(Start.class).on(named("start"))) + .visit(Advice.to(Run.class).on(named("run"))); } } diff --git a/contrib/agent/src/test/java/io/opencensus/contrib/agent/ResourcesTest.java b/contrib/agent/src/test/java/io/opencensus/contrib/agent/ResourcesTest.java index 8a765556..4de58884 100644 --- a/contrib/agent/src/test/java/io/opencensus/contrib/agent/ResourcesTest.java +++ b/contrib/agent/src/test/java/io/opencensus/contrib/agent/ResourcesTest.java @@ -32,17 +32,13 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -/** - * Unit tests for {@link Resources}. - */ +/** Unit tests for {@link Resources}. */ @RunWith(MockitoJUnitRunner.class) public class ResourcesTest { - @Rule - public final ExpectedException exception = ExpectedException.none(); - - @Mock - private File mockFile; + @Rule public final ExpectedException exception = ExpectedException.none(); + + @Mock private File mockFile; @Test public void getResourceAsTempFile_deleteOnExit() throws IOException { @@ -56,7 +52,7 @@ public class ResourcesTest { File file = Resources.getResourceAsTempFile("some_resource.txt"); assertThat(new String(java.nio.file.Files.readAllBytes(file.toPath()), Charsets.UTF_8)) - .isEqualTo("A resource!"); + .isEqualTo("A resource!"); } @Test @@ -75,12 +71,13 @@ public class ResourcesTest { @Test public void getResourceAsTempFile_WriteFailure() throws IOException { - OutputStream badOutputStream = new OutputStream() { - @Override - public void write(int b) throws IOException { - throw new IOException("denied"); - } - }; + OutputStream badOutputStream = + new OutputStream() { + @Override + public void write(int b) throws IOException { + throw new IOException("denied"); + } + }; exception.expect(IOException.class); exception.expectMessage("denied"); diff --git a/contrib/agent/src/test/java/io/opencensus/contrib/agent/bootstrap/ContextTrampolineTest.java b/contrib/agent/src/test/java/io/opencensus/contrib/agent/bootstrap/ContextTrampolineTest.java index bccdec92..f693dc3b 100644 --- a/contrib/agent/src/test/java/io/opencensus/contrib/agent/bootstrap/ContextTrampolineTest.java +++ b/contrib/agent/src/test/java/io/opencensus/contrib/agent/bootstrap/ContextTrampolineTest.java @@ -26,9 +26,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -/** - * Unit tests for {@link ContextTrampoline}. - */ +/** Unit tests for {@link ContextTrampoline}. */ @RunWith(MockitoJUnitRunner.class) public class ContextTrampolineTest { @@ -39,14 +37,11 @@ public class ContextTrampolineTest { ContextTrampoline.setContextStrategy(mockContextStrategy); } - @Rule - public final ExpectedException exception = ExpectedException.none(); + @Rule public final ExpectedException exception = ExpectedException.none(); - @Mock - private Runnable runnable; + @Mock private Runnable runnable; - @Mock - private Thread thread; + @Mock private Thread thread; @Test public void setContextStrategy_already_initialized() { diff --git a/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java b/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java index 36e981e0..531b6e11 100644 --- a/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java +++ b/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java @@ -21,9 +21,7 @@ import io.opencensus.stats.Measure.MeasureDouble; import io.opencensus.stats.Measure.MeasureLong; import io.opencensus.tags.TagKey; -/** - * Constants for collecting rpc stats. - */ +/** Constants for collecting rpc stats. */ public final class RpcMeasureConstants { // Rpc tag keys. @@ -37,118 +35,67 @@ public final class RpcMeasureConstants { // RPC client Measures. public static final MeasureLong RPC_CLIENT_ERROR_COUNT = - Measure.MeasureLong.create( - "grpc.io/client/error_count", - "RPC Errors", - COUNT); + Measure.MeasureLong.create("grpc.io/client/error_count", "RPC Errors", COUNT); public static final MeasureDouble RPC_CLIENT_REQUEST_BYTES = - Measure.MeasureDouble.create( - "grpc.io/client/request_bytes", - "Request bytes", - BYTE); + Measure.MeasureDouble.create("grpc.io/client/request_bytes", "Request bytes", BYTE); public static final MeasureDouble RPC_CLIENT_RESPONSE_BYTES = - Measure.MeasureDouble.create( - "grpc.io/client/response_bytes", - "Response bytes", - BYTE); + Measure.MeasureDouble.create("grpc.io/client/response_bytes", "Response bytes", BYTE); public static final MeasureDouble RPC_CLIENT_ROUNDTRIP_LATENCY = Measure.MeasureDouble.create( - "grpc.io/client/roundtrip_latency", - "RPC roundtrip latency msec", - MILLISECOND); + "grpc.io/client/roundtrip_latency", "RPC roundtrip latency msec", MILLISECOND); public static final MeasureDouble RPC_CLIENT_SERVER_ELAPSED_TIME = Measure.MeasureDouble.create( - "grpc.io/client/server_elapsed_time", - "Server elapsed time in msecs", - MILLISECOND); + "grpc.io/client/server_elapsed_time", "Server elapsed time in msecs", MILLISECOND); public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES = Measure.MeasureDouble.create( - "grpc.io/client/uncompressed_request_bytes", - "Uncompressed Request bytes", - BYTE); + "grpc.io/client/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE); public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES = Measure.MeasureDouble.create( - "grpc.io/client/uncompressed_response_bytes", - "Uncompressed Response bytes", - BYTE); + "grpc.io/client/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE); public static final MeasureLong RPC_CLIENT_STARTED_COUNT = Measure.MeasureLong.create( - "grpc.io/client/started_count", - "Number of client RPCs (streams) started", - COUNT); + "grpc.io/client/started_count", "Number of client RPCs (streams) started", COUNT); public static final MeasureLong RPC_CLIENT_FINISHED_COUNT = Measure.MeasureLong.create( - "grpc.io/client/finished_count", - "Number of client RPCs (streams) finished", - COUNT); + "grpc.io/client/finished_count", "Number of client RPCs (streams) finished", COUNT); public static final MeasureLong RPC_CLIENT_REQUEST_COUNT = Measure.MeasureLong.create( - "grpc.io/client/request_count", - "Number of client RPC request messages", - COUNT); + "grpc.io/client/request_count", "Number of client RPC request messages", COUNT); public static final MeasureLong RPC_CLIENT_RESPONSE_COUNT = Measure.MeasureLong.create( - "grpc.io/client/response_count", - "Number of client RPC response messages", - COUNT); - + "grpc.io/client/response_count", "Number of client RPC response messages", COUNT); // RPC server Measures. public static final MeasureLong RPC_SERVER_ERROR_COUNT = - Measure.MeasureLong.create( - "grpc.io/server/error_count", - "RPC Errors", - COUNT); + Measure.MeasureLong.create("grpc.io/server/error_count", "RPC Errors", COUNT); public static final MeasureDouble RPC_SERVER_REQUEST_BYTES = - Measure.MeasureDouble.create( - "grpc.io/server/request_bytes", - "Request bytes", - BYTE); + Measure.MeasureDouble.create("grpc.io/server/request_bytes", "Request bytes", BYTE); public static final MeasureDouble RPC_SERVER_RESPONSE_BYTES = - Measure.MeasureDouble.create( - "grpc.io/server/response_bytes", - "Response bytes", - BYTE); + Measure.MeasureDouble.create("grpc.io/server/response_bytes", "Response bytes", BYTE); public static final MeasureDouble RPC_SERVER_SERVER_ELAPSED_TIME = Measure.MeasureDouble.create( - "grpc.io/server/server_elapsed_time", - "Server elapsed time in msecs", - MILLISECOND); + "grpc.io/server/server_elapsed_time", "Server elapsed time in msecs", MILLISECOND); public static final MeasureDouble RPC_SERVER_SERVER_LATENCY = Measure.MeasureDouble.create( - "grpc.io/server/server_latency", - "Latency in msecs", - MILLISECOND); + "grpc.io/server/server_latency", "Latency in msecs", MILLISECOND); public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES = Measure.MeasureDouble.create( - "grpc.io/server/uncompressed_request_bytes", - "Uncompressed Request bytes", - BYTE); + "grpc.io/server/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE); public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES = Measure.MeasureDouble.create( - "grpc.io/server/uncompressed_response_bytes", - "Uncompressed Response bytes", - BYTE); + "grpc.io/server/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE); public static final MeasureLong RPC_SERVER_STARTED_COUNT = Measure.MeasureLong.create( - "grpc.io/server/started_count", - "Number of server RPCs (streams) started", - COUNT); + "grpc.io/server/started_count", "Number of server RPCs (streams) started", COUNT); public static final MeasureLong RPC_SERVER_FINISHED_COUNT = Measure.MeasureLong.create( - "grpc.io/server/finished_count", - "Number of server RPCs (streams) finished", - COUNT); + "grpc.io/server/finished_count", "Number of server RPCs (streams) finished", COUNT); public static final MeasureLong RPC_SERVER_REQUEST_COUNT = Measure.MeasureLong.create( - "grpc.io/server/request_count", - "Number of server RPC request messages", - COUNT); + "grpc.io/server/request_count", "Number of server RPC request messages", COUNT); public static final MeasureLong RPC_SERVER_RESPONSE_COUNT = Measure.MeasureLong.create( - "grpc.io/server/response_count", - "Number of server RPC response messages", - COUNT); + "grpc.io/server/response_count", "Number of server RPC response messages", COUNT); // Visible for testing. RpcMeasureConstants() { diff --git a/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcViewConstants.java b/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcViewConstants.java index da3f3e5f..83ced6ba 100644 --- a/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcViewConstants.java +++ b/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcViewConstants.java @@ -58,25 +58,43 @@ import java.util.List; public final class RpcViewConstants { // Common histogram bucket boundaries for bytes received/sets Views. - static final List<Double> RPC_BYTES_BUCKET_BOUNDARIES = Collections.unmodifiableList( - Arrays.asList(0.0, 1024.0, 2048.0, 4096.0, 16384.0, 65536.0, 262144.0, 1048576.0, 4194304.0, - 16777216.0, 67108864.0, 268435456.0, 1073741824.0, 4294967296.0)); + static final List<Double> RPC_BYTES_BUCKET_BOUNDARIES = + Collections.unmodifiableList( + Arrays.asList( + 0.0, + 1024.0, + 2048.0, + 4096.0, + 16384.0, + 65536.0, + 262144.0, + 1048576.0, + 4194304.0, + 16777216.0, + 67108864.0, + 268435456.0, + 1073741824.0, + 4294967296.0)); // Common histogram bucket boundaries for latency and elapsed-time Views. - static final List<Double> RPC_MILLIS_BUCKET_BOUNDARIES = Collections.unmodifiableList( - Arrays.asList(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0, - 40.0, 50.0, 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, - 800.0, 1000.0, 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0)); + static final List<Double> RPC_MILLIS_BUCKET_BOUNDARIES = + Collections.unmodifiableList( + Arrays.asList( + 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0, 40.0, + 50.0, 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, + 800.0, 1000.0, 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0)); // Common histogram bucket boundaries for request/response count Views. - static final List<Double> RPC_COUNT_BUCKET_BOUNDARIES = Collections.unmodifiableList( - Arrays.asList(0.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, - 4096.0, 8192.0, 16384.0, 32768.0, 65536.0)); + static final List<Double> RPC_COUNT_BUCKET_BOUNDARIES = + Collections.unmodifiableList( + Arrays.asList( + 0.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, + 4096.0, 8192.0, 16384.0, 32768.0, 65536.0)); // Use Aggregation.Mean to record sum and count stats at the same time. static final Aggregation MEAN = Mean.create(); - static final Aggregation AGGREGATION_WITH_BYTES_HISTOGRAM = + static final Aggregation AGGREGATION_WITH_BYTES_HISTOGRAM = Distribution.create(BucketBoundaries.create(RPC_BYTES_BUCKET_BOUNDARIES)); static final Aggregation AGGREGATION_WITH_MILLIS_HISTOGRAM = @@ -165,7 +183,6 @@ public final class RpcViewConstants { Arrays.asList(RPC_METHOD), CUMULATIVE); - // Rpc server cumulative views. public static final View RPC_SERVER_ERROR_COUNT_VIEW = View.create( diff --git a/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstantsTest.java b/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstantsTest.java index ee5114be..d945ee93 100644 --- a/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstantsTest.java +++ b/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstantsTest.java @@ -22,9 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** - * Test for {@link RpcMeasureConstants}. - */ +/** Test for {@link RpcMeasureConstants}. */ @RunWith(JUnit4.class) public class RpcMeasureConstantsTest { diff --git a/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcViewConstantsTest.java b/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcViewConstantsTest.java index 99cf80b3..b226d326 100644 --- a/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcViewConstantsTest.java +++ b/contrib/grpc_metrics/src/test/java/io/opencensus/contrib/grpc/metrics/RpcViewConstantsTest.java @@ -36,36 +36,57 @@ public final class RpcViewConstantsTest { public void testConstants() { // Test bucket boundaries. - assertThat(RpcViewConstants.RPC_BYTES_BUCKET_BOUNDARIES).containsExactly( - 0.0, 1024.0, 2048.0, 4096.0, 16384.0, 65536.0, 262144.0, 1048576.0, 4194304.0, - 16777216.0, 67108864.0, 268435456.0, 1073741824.0, 4294967296.0).inOrder(); - assertThat(RpcViewConstants.RPC_MILLIS_BUCKET_BOUNDARIES).containsExactly( - 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0, - 40.0, 50.0, 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, - 800.0, 1000.0, 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0).inOrder(); - assertThat(RpcViewConstants.RPC_COUNT_BUCKET_BOUNDARIES).containsExactly( - 0.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, - 4096.0, 8192.0, 16384.0, 32768.0, 65536.0).inOrder(); + assertThat(RpcViewConstants.RPC_BYTES_BUCKET_BOUNDARIES) + .containsExactly( + 0.0, + 1024.0, + 2048.0, + 4096.0, + 16384.0, + 65536.0, + 262144.0, + 1048576.0, + 4194304.0, + 16777216.0, + 67108864.0, + 268435456.0, + 1073741824.0, + 4294967296.0) + .inOrder(); + assertThat(RpcViewConstants.RPC_MILLIS_BUCKET_BOUNDARIES) + .containsExactly( + 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0, 40.0, 50.0, + 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, 800.0, + 1000.0, 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0) + .inOrder(); + assertThat(RpcViewConstants.RPC_COUNT_BUCKET_BOUNDARIES) + .containsExactly( + 0.0, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 2048.0, 4096.0, + 8192.0, 16384.0, 32768.0, 65536.0) + .inOrder(); // Test Aggregations assertThat(RpcViewConstants.MEAN).isEqualTo(Mean.create()); - assertThat(RpcViewConstants.AGGREGATION_WITH_BYTES_HISTOGRAM).isEqualTo( - Distribution.create(BucketBoundaries.create(RpcViewConstants.RPC_BYTES_BUCKET_BOUNDARIES))); - assertThat(RpcViewConstants.AGGREGATION_WITH_MILLIS_HISTOGRAM).isEqualTo( - Distribution.create( - BucketBoundaries.create(RpcViewConstants.RPC_MILLIS_BUCKET_BOUNDARIES))); - assertThat(RpcViewConstants.AGGREGATION_WITH_COUNT_HISTOGRAM).isEqualTo( - Distribution.create(BucketBoundaries.create(RpcViewConstants.RPC_COUNT_BUCKET_BOUNDARIES))); + assertThat(RpcViewConstants.AGGREGATION_WITH_BYTES_HISTOGRAM) + .isEqualTo( + Distribution.create( + BucketBoundaries.create(RpcViewConstants.RPC_BYTES_BUCKET_BOUNDARIES))); + assertThat(RpcViewConstants.AGGREGATION_WITH_MILLIS_HISTOGRAM) + .isEqualTo( + Distribution.create( + BucketBoundaries.create(RpcViewConstants.RPC_MILLIS_BUCKET_BOUNDARIES))); + assertThat(RpcViewConstants.AGGREGATION_WITH_COUNT_HISTOGRAM) + .isEqualTo( + Distribution.create( + BucketBoundaries.create(RpcViewConstants.RPC_COUNT_BUCKET_BOUNDARIES))); // Test Duration and Window assertThat(RpcViewConstants.MINUTE).isEqualTo(Duration.create(60, 0)); assertThat(RpcViewConstants.HOUR).isEqualTo(Duration.create(60 * 60, 0)); assertThat(RpcViewConstants.CUMULATIVE).isEqualTo(Cumulative.create()); - assertThat(RpcViewConstants.INTERVAL_MINUTE).isEqualTo( - Interval.create(RpcViewConstants.MINUTE)); - assertThat(RpcViewConstants.INTERVAL_HOUR).isEqualTo( - Interval.create(RpcViewConstants.HOUR)); - + assertThat(RpcViewConstants.INTERVAL_MINUTE) + .isEqualTo(Interval.create(RpcViewConstants.MINUTE)); + assertThat(RpcViewConstants.INTERVAL_HOUR).isEqualTo(Interval.create(RpcViewConstants.HOUR)); // Test client distribution view descriptors. assertThat(RpcViewConstants.RPC_CLIENT_ERROR_COUNT_VIEW).isNotNull(); diff --git a/contrib/grpc_util/src/main/java/io/opencensus/contrib/grpc/util/StatusConverter.java b/contrib/grpc_util/src/main/java/io/opencensus/contrib/grpc/util/StatusConverter.java index 3bf91e3f..a5732327 100644 --- a/contrib/grpc_util/src/main/java/io/opencensus/contrib/grpc/util/StatusConverter.java +++ b/contrib/grpc_util/src/main/java/io/opencensus/contrib/grpc/util/StatusConverter.java @@ -52,8 +52,8 @@ public final class StatusConverter { * @param opencensusCanonicalCode the given {@code io.opencensus.trace.Status.CanonicalCode}. * @return a {@code io.grpc.Status.Code} from a {@code io.opencensus.trace.Status.CanonicalCode}. */ - public static io.grpc.Status.Code toGrpcCode(io.opencensus.trace.Status.CanonicalCode - opencensusCanonicalCode) { + public static io.grpc.Status.Code toGrpcCode( + io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode) { return grpcStatusFromOpencensusCanonicalCode(opencensusCanonicalCode).getCode(); } @@ -64,16 +64,16 @@ public final class StatusConverter { * @return a {@code io.grpc.Status} from a {@code io.opencensus.trace.Status}. */ public static io.grpc.Status toGrpcStatus(io.opencensus.trace.Status opencensusStatus) { - io.grpc.Status status = grpcStatusFromOpencensusCanonicalCode(opencensusStatus - .getCanonicalCode()); + io.grpc.Status status = + grpcStatusFromOpencensusCanonicalCode(opencensusStatus.getCanonicalCode()); if (opencensusStatus.getDescription() != null) { status = status.withDescription(opencensusStatus.getDescription()); } return status; } - private static io.opencensus.trace.Status opencensusStatusFromGrpcCode(io.grpc.Status.Code - grpcCanonicaleCode) { + private static io.opencensus.trace.Status opencensusStatusFromGrpcCode( + io.grpc.Status.Code grpcCanonicaleCode) { switch (grpcCanonicaleCode) { case OK: return io.opencensus.trace.Status.OK; @@ -113,8 +113,8 @@ public final class StatusConverter { throw new AssertionError("Unhandled status code " + grpcCanonicaleCode); } - private static io.grpc.Status grpcStatusFromOpencensusCanonicalCode(io.opencensus.trace.Status - .CanonicalCode opencensusCanonicalCode) { + private static io.grpc.Status grpcStatusFromOpencensusCanonicalCode( + io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode) { switch (opencensusCanonicalCode) { case OK: return io.grpc.Status.OK; @@ -154,6 +154,5 @@ public final class StatusConverter { throw new AssertionError("Unhandled status code " + opencensusCanonicalCode); } - private StatusConverter() { - } + private StatusConverter() {} } diff --git a/contrib/grpc_util/src/test/java/io/opencensus/contrib/grpc/util/StatusConverterTest.java b/contrib/grpc_util/src/test/java/io/opencensus/contrib/grpc/util/StatusConverterTest.java index c62c5fa7..a6b5e87c 100644 --- a/contrib/grpc_util/src/test/java/io/opencensus/contrib/grpc/util/StatusConverterTest.java +++ b/contrib/grpc_util/src/test/java/io/opencensus/contrib/grpc/util/StatusConverterTest.java @@ -22,17 +22,15 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** - * Unit tests for {@link StatusConverter}. - */ +/** Unit tests for {@link StatusConverter}. */ @RunWith(JUnit4.class) public class StatusConverterTest { @Test public void convertFromGrpcCode() { for (io.grpc.Status.Code grpcCanonicalCode : io.grpc.Status.Code.values()) { - io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode = StatusConverter - .fromGrpcCode(grpcCanonicalCode); + io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode = + StatusConverter.fromGrpcCode(grpcCanonicalCode); assertThat(opencensusCanonicalCode.toString()).isEqualTo(grpcCanonicalCode.toString()); } } @@ -63,8 +61,7 @@ public class StatusConverterTest { public void convertToGrpcCode() { for (io.opencensus.trace.Status.CanonicalCode opencensusCanonicalCode : io.opencensus.trace.Status.CanonicalCode.values()) { - io.grpc.Status.Code grpcCanonicalCode = StatusConverter - .toGrpcCode(opencensusCanonicalCode); + io.grpc.Status.Code grpcCanonicalCode = StatusConverter.toGrpcCode(opencensusCanonicalCode); assertThat(grpcCanonicalCode.toString()).isEqualTo(opencensusCanonicalCode.toString()); } } diff --git a/contrib/zpages/src/main/java/io/opencensus/contrib/zpages/TracezZPageHandler.java b/contrib/zpages/src/main/java/io/opencensus/contrib/zpages/TracezZPageHandler.java index e8ed9b9f..9b86179d 100644 --- a/contrib/zpages/src/main/java/io/opencensus/contrib/zpages/TracezZPageHandler.java +++ b/contrib/zpages/src/main/java/io/opencensus/contrib/zpages/TracezZPageHandler.java @@ -523,10 +523,10 @@ final class TracezZPageHandler extends ZPageHandler { private static void emitLegend(PrintWriter out) { out.write("<br>\n"); - out.printf("<p><b style=\"color:%s;\">TraceId</b> means sampled request. " + out.printf( + "<p><b style=\"color:%s;\">TraceId</b> means sampled request. " + "<b style=\"color:%s;\">TraceId</b> means not sampled request.</p>%n", - SAMPLED_TRACE_ID_COLOR, - NOT_SAMPLED_TRACE_ID_COLOR); + SAMPLED_TRACE_ID_COLOR, NOT_SAMPLED_TRACE_ID_COLOR); } private static Map<LatencyBucketBoundaries, String> buildLatencyBucketBoundariesStringMap() { diff --git a/core_impl/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java b/core_impl/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java index ac966089..deb755f3 100644 --- a/core_impl/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java +++ b/core_impl/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java @@ -36,8 +36,7 @@ final class IntervalBucket { private final Timestamp start; private final Duration duration; private final Aggregation aggregation; - private final Map<List<TagValue>, MutableAggregation> tagValueAggregationMap = - Maps.newHashMap(); + private final Map<List<TagValue>, MutableAggregation> tagValueAggregationMap = Maps.newHashMap(); IntervalBucket(Timestamp start, Duration duration, Aggregation aggregation) { checkNotNull(start, "Start"); @@ -60,12 +59,11 @@ final class IntervalBucket { // Puts a new value into the internal MutableAggregations, based on the TagValues. void record(List<TagValue> tagValues, double value) { if (!tagValueAggregationMap.containsKey(tagValues)) { - tagValueAggregationMap.put( - tagValues, MutableViewData.createMutableAggregation(aggregation)); + tagValueAggregationMap.put(tagValues, MutableViewData.createMutableAggregation(aggregation)); } tagValueAggregationMap.get(tagValues).add(value); } - + /* * Returns how much fraction of duration has passed in this IntervalBucket. For example, if this * bucket starts at 10s and has a duration of 20s, and now is 15s, then getFraction() should @@ -76,7 +74,8 @@ final class IntervalBucket { */ double getFraction(Timestamp now) { Duration elapsedTime = now.subtractTimestamp(start); - checkArgument(elapsedTime.compareTo(ZERO) >= 0 && elapsedTime.compareTo(duration) < 0, + checkArgument( + elapsedTime.compareTo(ZERO) >= 0 && elapsedTime.compareTo(duration) < 0, "This bucket must be current."); return ((double) toMillis(elapsedTime)) / toMillis(duration); } diff --git a/core_impl/src/main/java/io/opencensus/implcore/stats/MeasureMapInternal.java b/core_impl/src/main/java/io/opencensus/implcore/stats/MeasureMapInternal.java index a99b9062..c68b4aff 100644 --- a/core_impl/src/main/java/io/opencensus/implcore/stats/MeasureMapInternal.java +++ b/core_impl/src/main/java/io/opencensus/implcore/stats/MeasureMapInternal.java @@ -25,14 +25,10 @@ import java.util.Iterator; import java.util.NoSuchElementException; // TODO(songya): consider combining MeasureMapImpl and this class. -/** - * A map from {@link Measure}'s to measured values. - */ +/** A map from {@link Measure}'s to measured values. */ final class MeasureMapInternal { - /** - * Returns a {@link Builder} for the {@link MeasureMapInternal} class. - */ + /** Returns a {@link Builder} for the {@link MeasureMapInternal} class. */ static Builder builder() { return new Builder(); } @@ -51,13 +47,11 @@ final class MeasureMapInternal { this.measurements = measurements; } - /** - * Builder for the {@link MeasureMapInternal} class. - */ + /** Builder for the {@link MeasureMapInternal} class. */ static class Builder { /** - * Associates the {@link MeasureDouble} with the given value. Subsequent updates to the - * same {@link MeasureDouble} will overwrite the previous value. + * Associates the {@link MeasureDouble} with the given value. Subsequent updates to the same + * {@link MeasureDouble} will overwrite the previous value. * * @param measure the {@link MeasureDouble} * @param value the value to be associated with {@code measure} @@ -69,8 +63,8 @@ final class MeasureMapInternal { } /** - * Associates the {@link MeasureLong} with the given value. Subsequent updates to the - * same {@link MeasureLong} will overwrite the previous value. + * Associates the {@link MeasureLong} with the given value. Subsequent updates to the same + * {@link MeasureLong} will overwrite the previous value. * * @param measure the {@link MeasureLong} * @param value the value to be associated with {@code measure} @@ -81,9 +75,7 @@ final class MeasureMapInternal { return this; } - /** - * Constructs a {@link MeasureMapInternal} from the current measurements. - */ + /** Constructs a {@link MeasureMapInternal} from the current measurements. */ MeasureMapInternal build() { // Note: this makes adding measurements quadratic but is fastest for the sizes of // MeasureMapInternals that we should see. We may want to go to a strategy of sort/eliminate @@ -101,8 +93,7 @@ final class MeasureMapInternal { private final ArrayList<Measurement> measurements = new ArrayList<Measurement>(); - private Builder() { - } + private Builder() {} } // Provides an unmodifiable Iterator over this instance's measurements. diff --git a/core_impl/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java b/core_impl/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java index c2e251db..db08d4fb 100644 --- a/core_impl/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java +++ b/core_impl/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java @@ -37,10 +37,7 @@ import java.util.Map; import javax.annotation.Nullable; import javax.annotation.concurrent.GuardedBy; -/** - * A class that stores a singleton map from {@code MeasureName}s to {@link - * MutableViewData}s. - */ +/** A class that stores a singleton map from {@code MeasureName}s to {@link MutableViewData}s. */ final class MeasureToViewMap { /* @@ -52,8 +49,7 @@ final class MeasureToViewMap { HashMultimap.<String, MutableViewData>create(); @GuardedBy("this") - private final Map<View.Name, View> registeredViews = - new HashMap<View.Name, View>(); + private final Map<View.Name, View> registeredViews = new HashMap<View.Name, View>(); // TODO(songya): consider adding a Measure.Name class @GuardedBy("this") @@ -71,15 +67,19 @@ final class MeasureToViewMap { if (view == null) { return null; } - Collection<MutableViewData> views = - mutableMap.get(view.getMeasure().getName()); + Collection<MutableViewData> views = mutableMap.get(view.getMeasure().getName()); for (MutableViewData viewData : views) { if (viewData.getView().getName().equals(viewName)) { return viewData; } } - throw new AssertionError("Internal error: Not recording stats for view: \"" + viewName - + "\" registeredViews=" + registeredViews + ", mutableMap=" + mutableMap); + throw new AssertionError( + "Internal error: Not recording stats for view: \"" + + viewName + + "\" registeredViews=" + + registeredViews + + ", mutableMap=" + + mutableMap); } /** Enable stats collection for the given {@link View}. */ @@ -162,4 +162,4 @@ final class MeasureToViewMap { this.timestamp = timestamp; } } -}
\ No newline at end of file +} diff --git a/core_impl/src/main/java/io/opencensus/implcore/stats/MutableAggregation.java b/core_impl/src/main/java/io/opencensus/implcore/stats/MutableAggregation.java index b4fa08e8..deabdce7 100644 --- a/core_impl/src/main/java/io/opencensus/implcore/stats/MutableAggregation.java +++ b/core_impl/src/main/java/io/opencensus/implcore/stats/MutableAggregation.java @@ -26,8 +26,7 @@ import io.opencensus.stats.BucketBoundaries; /** Mutable version of {@link Aggregation} that supports adding values. */ abstract class MutableAggregation { - private MutableAggregation() { - } + private MutableAggregation() {} // Tolerance for double comparison. private static final double TOLERANCE = 1e-6; @@ -43,7 +42,7 @@ abstract class MutableAggregation { * Combine the internal values of this MutableAggregation and value of the given * MutableAggregation, with the given fraction. Then set the internal value of this * MutableAggregation to the combined value. - * + * * @param other the other {@code MutableAggregation}. The type of this and other {@code * MutableAggregation} must match. * @param fraction the fraction that the value in other {@code MutableAggregation} should @@ -51,9 +50,7 @@ abstract class MutableAggregation { */ abstract void combine(MutableAggregation other, double fraction); - /** - * Applies the given match function to the underlying data type. - */ + /** Applies the given match function to the underlying data type. */ abstract <T> T match( Function<? super MutableSum, T> p0, Function<? super MutableCount, T> p1, @@ -65,8 +62,7 @@ abstract class MutableAggregation { private double sum = 0.0; - private MutableSum() { - } + private MutableSum() {} /** * Construct a {@code MutableSum}. @@ -112,8 +108,7 @@ abstract class MutableAggregation { private long count = 0; - private MutableCount() { - } + private MutableCount() {} /** * Construct a {@code MutableCount}. @@ -160,8 +155,7 @@ abstract class MutableAggregation { private double sum = 0.0; private long count = 0; - private MutableMean() { - } + private MutableMean() {} /** * Construct a {@code MutableMean}. @@ -296,17 +290,21 @@ abstract class MutableAggregation { } MutableDistribution mutableDistribution = (MutableDistribution) other; - checkArgument(this.bucketBoundaries.equals(mutableDistribution.bucketBoundaries), + checkArgument( + this.bucketBoundaries.equals(mutableDistribution.bucketBoundaries), "Bucket boundaries should match."); // Algorithm for calculating the combination of sum of squared deviations: // https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm. if (this.count + mutableDistribution.count > 0) { double delta = mutableDistribution.mean - this.mean; - this.sumOfSquaredDeviations = this.sumOfSquaredDeviations - + mutableDistribution.sumOfSquaredDeviations - + Math.pow(delta, 2) * this.count * mutableDistribution.count - / (this.count + mutableDistribution.count); + this.sumOfSquaredDeviations = + this.sumOfSquaredDeviations + + mutableDistribution.sumOfSquaredDeviations + + Math.pow(delta, 2) + * this.count + * mutableDistribution.count + / (this.count + mutableDistribution.count); } this.count += mutableDistribution.count; diff --git a/core_impl/src/main/java/io/opencensus/implcore/stats/MutableViewData.java b/core_impl/src/main/java/io/opencensus/implcore/stats/MutableViewData.java index 9b342a12..335d3cbc 100644 --- a/core_impl/src/main/java/io/opencensus/implcore/stats/MutableViewData.java +++ b/core_impl/src/main/java/io/opencensus/implcore/stats/MutableViewData.java @@ -67,8 +67,7 @@ abstract class MutableViewData { private static final long MILLIS_PER_SECOND = 1000L; private static final long NANOS_PER_MILLI = 1000 * 1000; - @VisibleForTesting - static final TagValue UNKNOWN_TAG_VALUE = null; + @VisibleForTesting static final TagValue UNKNOWN_TAG_VALUE = null; private final View view; @@ -84,35 +83,28 @@ abstract class MutableViewData { * @return a {@code MutableViewData}. */ static MutableViewData create(final View view, final Timestamp start) { - return view.getWindow().match( - new CreateCumulative(view, start), - new CreateInterval(view, start), - Functions.<MutableViewData>throwAssertionError()); + return view.getWindow() + .match( + new CreateCumulative(view, start), + new CreateInterval(view, start), + Functions.<MutableViewData>throwAssertionError()); } - /** - * The {@link View} associated with this {@link ViewData}. - */ + /** The {@link View} associated with this {@link ViewData}. */ View getView() { return view; } - /** - * Record double stats with the given tags. - */ + /** Record double stats with the given tags. */ abstract void record(TagContext context, double value, Timestamp timestamp); - /** - * Record long stats with the given tags. - */ + /** Record long stats with the given tags. */ void record(TagContext tags, long value, Timestamp timestamp) { // TODO(songya): shall we check for precision loss here? record(tags, (double) value, timestamp); } - /** - * Convert this {@link MutableViewData} to {@link ViewData}. - */ + /** Convert this {@link MutableViewData} to {@link ViewData}. */ abstract ViewData toViewData(Timestamp now); private static Map<TagKey, TagValue> getTagMap(TagContext ctx) { @@ -188,8 +180,7 @@ abstract class MutableViewData { private static <T> Map<T, AggregationData> createAggregationMap( Map<T, MutableAggregation> tagValueAggregationMap, Measure measure) { Map<T, AggregationData> map = Maps.newHashMap(); - for (Entry<T, MutableAggregation> entry : - tagValueAggregationMap.entrySet()) { + for (Entry<T, MutableAggregation> entry : tagValueAggregationMap.entrySet()) { map.put(entry.getKey(), createAggregationData(entry.getValue(), measure)); } return map; @@ -219,7 +210,8 @@ abstract class MutableViewData { @Override ViewData toViewData(Timestamp now) { return ViewData.create( - super.view, createAggregationMap(tagValueAggregationMap, super.view.getMeasure()), + super.view, + createAggregationMap(tagValueAggregationMap, super.view.getMeasure()), CumulativeData.create(start, now)); } } @@ -263,7 +255,7 @@ abstract class MutableViewData { private static final int N = 4; // IntervalView has N + 1 buckets private final LinkedList<IntervalBucket> buckets = new LinkedList<IntervalBucket>(); - private final Duration totalDuration; // Duration of the whole interval. + private final Duration totalDuration; // Duration of the whole interval. private final Duration bucketDuration; // Duration of a single bucket (totalDuration / N) private IntervalMutableViewData(View view, Timestamp start) { @@ -300,7 +292,8 @@ abstract class MutableViewData { } Timestamp startOfLastBucket = buckets.peekLast().getStart(); // TODO(songya): decide what to do when time goes backwards - checkArgument(now.compareTo(startOfLastBucket) >= 0, + checkArgument( + now.compareTo(startOfLastBucket) >= 0, "Current time must be within or after the last bucket."); long elapsedTimeMillis = toMillis(now.subtractTimestamp(startOfLastBucket)); long numOfPadBuckets = elapsedTimeMillis / toMillis(bucketDuration); @@ -340,8 +333,7 @@ abstract class MutableViewData { // Combine stats within each bucket, aggregate stats by tag values, and return the mapping from // tag values to aggregation data. - private Map<List<TagValue>, AggregationData> combineBucketsAndGetAggregationMap( - Timestamp now) { + private Map<List<TagValue>, AggregationData> combineBucketsAndGetAggregationMap(Timestamp now) { Multimap<List<TagValue>, MutableAggregation> multimap = HashMultimap.create(); LinkedList<IntervalBucket> shallowCopy = new LinkedList<IntervalBucket>(buckets); Aggregation aggregation = super.view.getAggregation(); @@ -363,7 +355,8 @@ abstract class MutableViewData { IntervalBucket tail = buckets.peekLast(); double fractionTail = tail.getFraction(now); // TODO(songya): decide what to do when time goes backwards - checkArgument(0.0 <= fractionTail && fractionTail <= 1.0, + checkArgument( + 0.0 <= fractionTail && fractionTail <= 1.0, "Fraction " + fractionTail + " should be within [0.0, 1.0]."); double fractionHead = 1.0 - fractionTail; putFractionalMutableAggregationsToMultiMap( @@ -400,8 +393,7 @@ abstract class MutableViewData { // For each tag value list (key of AggregationMap), combine mutable aggregations into one // mutable aggregation, thus convert the multimap into a single map. private static <T> Map<T, MutableAggregation> aggregateOnEachTagValueList( - Multimap<T, MutableAggregation> multimap, - Aggregation aggregation) { + Multimap<T, MutableAggregation> multimap, Aggregation aggregation) { Map<T, MutableAggregation> map = Maps.newHashMap(); for (T tagValues : multimap.keySet()) { // Initially empty MutableAggregations. @@ -502,8 +494,13 @@ abstract class MutableViewData { for (long bucketCount : arg.getBucketCounts()) { boxedBucketCounts.add(bucketCount); } - return DistributionData.create(arg.getMean(), arg.getCount(), arg.getMin(), arg.getMax(), - arg.getSumOfSquaredDeviations(), boxedBucketCounts); + return DistributionData.create( + arg.getMean(), + arg.getCount(), + arg.getMin(), + arg.getMax(), + arg.getSumOfSquaredDeviations(), + boxedBucketCounts); } private static final CreateDistributionData INSTANCE = new CreateDistributionData(); diff --git a/core_impl/src/main/java/io/opencensus/implcore/stats/StatsManager.java b/core_impl/src/main/java/io/opencensus/implcore/stats/StatsManager.java index 05b99fda..284781f1 100644 --- a/core_impl/src/main/java/io/opencensus/implcore/stats/StatsManager.java +++ b/core_impl/src/main/java/io/opencensus/implcore/stats/StatsManager.java @@ -71,4 +71,4 @@ final class StatsManager { statsManager.measureToViewMap.record(tags, stats, statsManager.clock.now()); } } -}
\ No newline at end of file +} diff --git a/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java b/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java index a7982852..177ce639 100644 --- a/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java +++ b/core_impl/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java @@ -80,6 +80,5 @@ public final class TagContextImpl extends TagContext { public void remove() { throw new UnsupportedOperationException("TagIterator.remove()"); } - } } diff --git a/core_impl/src/main/java/io/opencensus/implcore/tags/propagation/SerializationUtils.java b/core_impl/src/main/java/io/opencensus/implcore/tags/propagation/SerializationUtils.java index 018eeda3..d889a4b8 100644 --- a/core_impl/src/main/java/io/opencensus/implcore/tags/propagation/SerializationUtils.java +++ b/core_impl/src/main/java/io/opencensus/implcore/tags/propagation/SerializationUtils.java @@ -143,8 +143,7 @@ final class SerializationUtils { } } - private static final void encodeTag( - Tag tag, ByteArrayDataOutput byteArrayDataOutput) { + private static final void encodeTag(Tag tag, ByteArrayDataOutput byteArrayDataOutput) { byteArrayDataOutput.write(TAG_FIELD_ID); encodeString(tag.getKey().getName(), byteArrayDataOutput); encodeString(tag.getValue().asString(), byteArrayDataOutput); diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/IntervalBucketTest.java b/core_impl/src/test/java/io/opencensus/implcore/stats/IntervalBucketTest.java index 663673f5..10bce262 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/stats/IntervalBucketTest.java +++ b/core_impl/src/test/java/io/opencensus/implcore/stats/IntervalBucketTest.java @@ -66,11 +66,10 @@ public class IntervalBucketTest { thrown.expect(NullPointerException.class); new IntervalBucket(START, MINUTE, null); } - + @Test public void testGetTagValueAggregationMap_empty() { - assertThat(new IntervalBucket(START, MINUTE, MEAN).getTagValueAggregationMap()) - .isEmpty(); + assertThat(new IntervalBucket(START, MINUTE, MEAN).getTagValueAggregationMap()).isEmpty(); } @Test @@ -98,9 +97,9 @@ public class IntervalBucketTest { @Test public void testGetFraction() { Timestamp thirtySecondsAfterStart = Timestamp.create(90, 0); - assertThat( - new IntervalBucket(START, MINUTE, MEAN).getFraction(thirtySecondsAfterStart)) - .isWithin(TOLERANCE).of(0.5); + assertThat(new IntervalBucket(START, MINUTE, MEAN).getFraction(thirtySecondsAfterStart)) + .isWithin(TOLERANCE) + .of(0.5); } @Test diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/MeasureMapInternalTest.java b/core_impl/src/test/java/io/opencensus/implcore/stats/MeasureMapInternalTest.java index 06f25d2e..c57baa0b 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/stats/MeasureMapInternalTest.java +++ b/core_impl/src/test/java/io/opencensus/implcore/stats/MeasureMapInternalTest.java @@ -43,17 +43,20 @@ public class MeasureMapInternalTest { @Test public void testPutLong() { MeasureMapInternal metrics = MeasureMapInternal.builder().put(M3, 9999L).put(M4, 8888L).build(); - assertContains(metrics, - MeasurementLong.create(M3, 9999L), - MeasurementLong.create(M4, 8888L)); + assertContains(metrics, MeasurementLong.create(M3, 9999L), MeasurementLong.create(M4, 8888L)); } @Test public void testCombination() { MeasureMapInternal metrics = - MeasureMapInternal.builder().put(M1, 44.4).put(M2, 66.6).put(M3, 9999L).put(M4, 8888L) + MeasureMapInternal.builder() + .put(M1, 44.4) + .put(M2, 66.6) + .put(M3, 9999L) + .put(M4, 8888L) .build(); - assertContains(metrics, + assertContains( + metrics, MeasurementDouble.create(M1, 44.4), MeasurementDouble.create(M2, 66.6), MeasurementLong.create(M3, 9999L), @@ -71,8 +74,7 @@ public class MeasureMapInternalTest { ArrayList<Measurement> expected = new ArrayList<Measurement>(10); MeasureMapInternal.Builder builder = MeasureMapInternal.builder(); for (int i = 1; i <= 10; i++) { - expected - .add(MeasurementDouble.create(makeSimpleMeasureDouble("m" + i), i * 11.1)); + expected.add(MeasurementDouble.create(makeSimpleMeasureDouble("m" + i), i * 11.1)); builder.put(makeSimpleMeasureDouble("m" + i), i * 11.1); assertContains(builder.build(), expected.toArray(new Measurement[i])); } @@ -80,38 +82,48 @@ public class MeasureMapInternalTest { @Test public void testDuplicateMeasureDoubles() { - assertContains(MeasureMapInternal.builder().put(M1, 1.0).put(M1, 2.0).build(), + assertContains( + MeasureMapInternal.builder().put(M1, 1.0).put(M1, 2.0).build(), MeasurementDouble.create(M1, 2.0)); - assertContains(MeasureMapInternal.builder().put(M1, 1.0).put(M1, 2.0).put(M1, 3.0).build(), + assertContains( + MeasureMapInternal.builder().put(M1, 1.0).put(M1, 2.0).put(M1, 3.0).build(), MeasurementDouble.create(M1, 3.0)); - assertContains(MeasureMapInternal.builder().put(M1, 1.0).put(M2, 2.0).put(M1, 3.0).build(), + assertContains( + MeasureMapInternal.builder().put(M1, 1.0).put(M2, 2.0).put(M1, 3.0).build(), MeasurementDouble.create(M1, 3.0), MeasurementDouble.create(M2, 2.0)); - assertContains(MeasureMapInternal.builder().put(M1, 1.0).put(M1, 2.0).put(M2, 2.0).build(), + assertContains( + MeasureMapInternal.builder().put(M1, 1.0).put(M1, 2.0).put(M2, 2.0).build(), MeasurementDouble.create(M1, 2.0), MeasurementDouble.create(M2, 2.0)); } @Test public void testDuplicateMeasureLongs() { - assertContains(MeasureMapInternal.builder().put(M3, 100L).put(M3, 100L).build(), + assertContains( + MeasureMapInternal.builder().put(M3, 100L).put(M3, 100L).build(), MeasurementLong.create(M3, 100L)); - assertContains(MeasureMapInternal.builder().put(M3, 100L).put(M3, 200L).put(M3, 300L).build(), + assertContains( + MeasureMapInternal.builder().put(M3, 100L).put(M3, 200L).put(M3, 300L).build(), MeasurementLong.create(M3, 300L)); - assertContains(MeasureMapInternal.builder().put(M3, 100L).put(M4, 200L).put(M3, 300L).build(), + assertContains( + MeasureMapInternal.builder().put(M3, 100L).put(M4, 200L).put(M3, 300L).build(), MeasurementLong.create(M3, 300L), MeasurementLong.create(M4, 200L)); - assertContains(MeasureMapInternal.builder().put(M3, 100L).put(M3, 200L).put(M4, 200L).build(), + assertContains( + MeasureMapInternal.builder().put(M3, 100L).put(M3, 200L).put(M4, 200L).build(), MeasurementLong.create(M3, 200L), MeasurementLong.create(M4, 200L)); } @Test public void testDuplicateMeasures() { - assertContains(MeasureMapInternal.builder().put(M3, 100L).put(M1, 1.0).put(M3, 300L).build(), + assertContains( + MeasureMapInternal.builder().put(M3, 100L).put(M1, 1.0).put(M3, 300L).build(), MeasurementLong.create(M3, 300L), MeasurementDouble.create(M1, 1.0)); - assertContains(MeasureMapInternal.builder().put(M2, 2.0).put(M3, 100L).put(M2, 3.0).build(), + assertContains( + MeasureMapInternal.builder().put(M2, 2.0).put(M3, 100L).put(M2, 3.0).build(), MeasurementDouble.create(M2, 3.0), MeasurementLong.create(M3, 100L)); } diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/MeasureToViewMapTest.java b/core_impl/src/test/java/io/opencensus/implcore/stats/MeasureToViewMapTest.java index 9901e7b9..4358eba1 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/stats/MeasureToViewMapTest.java +++ b/core_impl/src/test/java/io/opencensus/implcore/stats/MeasureToViewMapTest.java @@ -38,18 +38,20 @@ import org.junit.runners.JUnit4; public class MeasureToViewMapTest { private static final Measure MEASURE = - Measure.MeasureDouble.create( - "my measurement", - "measurement description", - "By"); + Measure.MeasureDouble.create("my measurement", "measurement description", "By"); private static final Name VIEW_NAME = View.Name.create("my view"); private static final Cumulative CUMULATIVE = Cumulative.create(); private static final View VIEW = - View.create(VIEW_NAME, "view description", MEASURE, Mean.create(), - Arrays.asList(TagKey.create("my key")), CUMULATIVE); + View.create( + VIEW_NAME, + "view description", + MEASURE, + Mean.create(), + Arrays.asList(TagKey.create("my key")), + CUMULATIVE); @Test public void testRegisterAndGetView() { @@ -59,8 +61,8 @@ public class MeasureToViewMapTest { clock.setTime(Timestamp.create(30, 40)); ViewData viewData = measureToViewMap.getView(VIEW_NAME, clock); assertThat(viewData.getView()).isEqualTo(VIEW); - assertThat(viewData.getWindowData()).isEqualTo( - CumulativeData.create(Timestamp.create(10, 20), Timestamp.create(30, 40))); + assertThat(viewData.getWindowData()) + .isEqualTo(CumulativeData.create(Timestamp.create(10, 20), Timestamp.create(30, 40))); assertThat(viewData.getAggregationMap()).isEmpty(); } } diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/MutableAggregationTest.java b/core_impl/src/test/java/io/opencensus/implcore/stats/MutableAggregationTest.java index 15248b19..054a5b44 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/stats/MutableAggregationTest.java +++ b/core_impl/src/test/java/io/opencensus/implcore/stats/MutableAggregationTest.java @@ -37,8 +37,7 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class MutableAggregationTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); + @Rule public ExpectedException thrown = ExpectedException.none(); private static final double TOLERANCE = 1e-6; private static final BucketBoundaries BUCKET_BOUNDARIES = @@ -70,19 +69,19 @@ public class MutableAggregationTest { @Test public void testNoBoundaries() { List<Double> buckets = Arrays.asList(); - MutableDistribution noBoundaries = - MutableDistribution.create(BucketBoundaries.create(buckets)); + MutableDistribution noBoundaries = MutableDistribution.create(BucketBoundaries.create(buckets)); assertThat(noBoundaries.getBucketCounts().length).isEqualTo(1); assertThat(noBoundaries.getBucketCounts()[0]).isEqualTo(0); } @Test public void testAdd() { - List<MutableAggregation> aggregations = Arrays.asList( - MutableSum.create(), - MutableCount.create(), - MutableMean.create(), - MutableDistribution.create(BUCKET_BOUNDARIES)); + List<MutableAggregation> aggregations = + Arrays.asList( + MutableSum.create(), + MutableCount.create(), + MutableMean.create(), + MutableDistribution.create(BUCKET_BOUNDARIES)); List<Double> values = Arrays.asList(-1.0, 1.0, -5.0, 20.0, 5.0); @@ -118,7 +117,7 @@ public class MutableAggregationTest { new Function<MutableDistribution, Void>() { @Override public Void apply(MutableDistribution arg) { - assertThat(arg.getBucketCounts()).isEqualTo(new long[]{0, 2, 2, 1}); + assertThat(arg.getBucketCounts()).isEqualTo(new long[] {0, 2, 2, 1}); return null; } }); @@ -127,56 +126,53 @@ public class MutableAggregationTest { @Test public void testMatch() { - List<MutableAggregation> aggregations = Arrays.asList( - MutableSum.create(), - MutableCount.create(), - MutableMean.create(), - MutableDistribution.create(BUCKET_BOUNDARIES)); + List<MutableAggregation> aggregations = + Arrays.asList( + MutableSum.create(), + MutableCount.create(), + MutableMean.create(), + MutableDistribution.create(BUCKET_BOUNDARIES)); List<String> actual = new ArrayList<String>(); for (MutableAggregation aggregation : aggregations) { - actual.add(aggregation.match( - new Function<MutableSum, String>() { - @Override - public String apply(MutableSum arg) { - return "SUM"; - } - }, - new Function<MutableCount, String>() { - @Override - public String apply(MutableCount arg) { - return "COUNT"; - } - }, - new Function<MutableMean, String>() { - @Override - public String apply(MutableMean arg) { - return "MEAN"; - } - }, - new Function<MutableDistribution, String>() { - @Override - public String apply(MutableDistribution arg) { - return "DISTRIBUTION"; - } - })); + actual.add( + aggregation.match( + new Function<MutableSum, String>() { + @Override + public String apply(MutableSum arg) { + return "SUM"; + } + }, + new Function<MutableCount, String>() { + @Override + public String apply(MutableCount arg) { + return "COUNT"; + } + }, + new Function<MutableMean, String>() { + @Override + public String apply(MutableMean arg) { + return "MEAN"; + } + }, + new Function<MutableDistribution, String>() { + @Override + public String apply(MutableDistribution arg) { + return "DISTRIBUTION"; + } + })); } - assertThat(actual) - .isEqualTo(Arrays.asList("SUM", "COUNT", "MEAN", "DISTRIBUTION")); + assertThat(actual).isEqualTo(Arrays.asList("SUM", "COUNT", "MEAN", "DISTRIBUTION")); } @Test public void testCombine_SumCountMean() { // combine() for Mutable Sum, Count and Mean will pick up fractional stats - List<MutableAggregation> aggregations1 = Arrays.asList( - MutableSum.create(), - MutableCount.create(), - MutableMean.create()); - List<MutableAggregation> aggregations2 = Arrays.asList( - MutableSum.create(), - MutableCount.create(), - MutableMean.create()); + List<MutableAggregation> aggregations1 = + Arrays.asList(MutableSum.create(), MutableCount.create(), MutableMean.create()); + List<MutableAggregation> aggregations2 = + Arrays.asList(MutableSum.create(), MutableCount.create(), MutableMean.create()); for (double val : Arrays.asList(-1.0, -5.0)) { for (MutableAggregation aggregation : aggregations1) { @@ -189,10 +185,8 @@ public class MutableAggregationTest { } } - List<MutableAggregation> combined = Arrays.asList( - MutableSum.create(), - MutableCount.create(), - MutableMean.create()); + List<MutableAggregation> combined = + Arrays.asList(MutableSum.create(), MutableCount.create(), MutableMean.create()); double fraction1 = 1.0; double fraction2 = 0.6; for (int i = 0; i < combined.size(); i++) { @@ -225,24 +219,31 @@ public class MutableAggregationTest { MutableDistribution combined = MutableDistribution.create(BUCKET_BOUNDARIES); combined.combine(distribution1, 1.0); // distribution1 will be combined combined.combine(distribution2, 0.6); // distribution2 will be ignored - verifyMutableDistribution(combined, 0, 2, -5, 5, 50.0, new long[]{0, 1, 1, 0}, TOLERANCE); + verifyMutableDistribution(combined, 0, 2, -5, 5, 50.0, new long[] {0, 1, 1, 0}, TOLERANCE); combined.combine(distribution2, 1.0); // distribution2 will be combined - verifyMutableDistribution(combined, 7.5, 4, -5, 20, 325.0, new long[]{0, 1, 1, 2}, TOLERANCE); + verifyMutableDistribution(combined, 7.5, 4, -5, 20, 325.0, new long[] {0, 1, 1, 2}, TOLERANCE); combined.combine(distribution3, 1.0); // distribution3 will be combined - verifyMutableDistribution(combined, 0, 8, -20, 20, 1500.0, new long[]{2, 2, 1, 3}, TOLERANCE); + verifyMutableDistribution(combined, 0, 8, -20, 20, 1500.0, new long[] {2, 2, 1, 3}, TOLERANCE); } - private static void verifyMutableDistribution(MutableDistribution mutableDistribution, - double mean, long count, double min, double max, double sumOfSquaredDeviations, - long[] bucketCounts, double tolerance) { + private static void verifyMutableDistribution( + MutableDistribution mutableDistribution, + double mean, + long count, + double min, + double max, + double sumOfSquaredDeviations, + long[] bucketCounts, + double tolerance) { assertThat(mutableDistribution.getMean()).isWithin(tolerance).of(mean); assertThat(mutableDistribution.getCount()).isEqualTo(count); assertThat(mutableDistribution.getMin()).isWithin(tolerance).of(min); assertThat(mutableDistribution.getMax()).isWithin(tolerance).of(max); - assertThat(mutableDistribution.getSumOfSquaredDeviations()).isWithin(tolerance).of( - sumOfSquaredDeviations); + assertThat(mutableDistribution.getSumOfSquaredDeviations()) + .isWithin(tolerance) + .of(sumOfSquaredDeviations); assertThat(mutableDistribution.getBucketCounts()).isEqualTo(bucketCounts); } } diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/MutableViewDataTest.java b/core_impl/src/test/java/io/opencensus/implcore/stats/MutableViewDataTest.java index 6d253922..9f6c3c6a 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/stats/MutableViewDataTest.java +++ b/core_impl/src/test/java/io/opencensus/implcore/stats/MutableViewDataTest.java @@ -83,19 +83,18 @@ public class MutableViewDataTest { public void createMutableAggregation() { BucketBoundaries bucketBoundaries = BucketBoundaries.create(Arrays.asList(-1.0, 0.0, 1.0)); - assertThat( - ((MutableSum) MutableViewData.createMutableAggregation(Sum.create())).getSum()) - .isWithin(EPSILON).of(0.0); - assertThat( - ((MutableCount) MutableViewData.createMutableAggregation(Count.create())).getCount()) + assertThat(((MutableSum) MutableViewData.createMutableAggregation(Sum.create())).getSum()) + .isWithin(EPSILON) + .of(0.0); + assertThat(((MutableCount) MutableViewData.createMutableAggregation(Count.create())).getCount()) .isEqualTo(0L); - assertThat( - ((MutableMean) MutableViewData.createMutableAggregation(Mean.create())) - .getMean()) - .isWithin(EPSILON).of(0D); + assertThat(((MutableMean) MutableViewData.createMutableAggregation(Mean.create())).getMean()) + .isWithin(EPSILON) + .of(0D); - MutableDistribution mutableDistribution = (MutableDistribution) MutableViewData - .createMutableAggregation(Distribution.create(bucketBoundaries)); + MutableDistribution mutableDistribution = + (MutableDistribution) + MutableViewData.createMutableAggregation(Distribution.create(bucketBoundaries)); assertThat(mutableDistribution.getMin()).isPositiveInfinity(); assertThat(mutableDistribution.getMax()).isNegativeInfinity(); assertThat(mutableDistribution.getSumOfSquaredDeviations()).isWithin(EPSILON).of(0); @@ -105,10 +104,11 @@ public class MutableViewDataTest { @Test public void createAggregationData() { BucketBoundaries bucketBoundaries = BucketBoundaries.create(Arrays.asList(-1.0, 0.0, 1.0)); - List<MutableAggregation> mutableAggregations = Arrays.asList( - MutableCount.create(), - MutableMean.create(), - MutableDistribution.create(bucketBoundaries)); + List<MutableAggregation> mutableAggregations = + Arrays.asList( + MutableCount.create(), + MutableMean.create(), + MutableDistribution.create(bucketBoundaries)); List<AggregationData> aggregates = new ArrayList<AggregationData>(); aggregates.add(MutableViewData.createAggregationData(MutableSum.create(), MEASURE_DOUBLE)); diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/StatsRecorderImplTest.java b/core_impl/src/test/java/io/opencensus/implcore/stats/StatsRecorderImplTest.java index ca192568..5c547c64 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/stats/StatsRecorderImplTest.java +++ b/core_impl/src/test/java/io/opencensus/implcore/stats/StatsRecorderImplTest.java @@ -93,8 +93,7 @@ public final class StatsRecorderImplTest { viewManager.registerView(view); Context orig = Context.current() - .withValue( - ContextUtils.TAG_CONTEXT_KEY, new SimpleTagContext(Tag.create(KEY, VALUE))) + .withValue(ContextUtils.TAG_CONTEXT_KEY, new SimpleTagContext(Tag.create(KEY, VALUE))) .attach(); try { statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record(); diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java b/core_impl/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java index 363f58f6..c81cfb11 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java +++ b/core_impl/src/test/java/io/opencensus/implcore/stats/StatsTestUtil.java @@ -60,8 +60,7 @@ final class StatsTestUtil { * Compare the actual and expected AggregationMap within the given tolerance. * * @param expected the expected map. - * @param actual the actual mapping from {@code List<TagValue>} to - * {@code AggregationData}. + * @param actual the actual mapping from {@code List<TagValue>} to {@code AggregationData}. * @param tolerance the tolerance used for {@code double} comparison. */ static void assertAggregationMapEquals( @@ -133,8 +132,9 @@ final class StatsTestUtil { assertThat(actual.getMean()).isWithin(tolerance).of(expected.getMean()); assertThat(actual.getCount()).isEqualTo(expected.getCount()); assertThat(actual.getMean()).isWithin(tolerance).of(expected.getMean()); - assertThat(actual.getSumOfSquaredDeviations()).isWithin(tolerance).of( - expected.getSumOfSquaredDeviations()); + assertThat(actual.getSumOfSquaredDeviations()) + .isWithin(tolerance) + .of(expected.getSumOfSquaredDeviations()); if (expected.getMax() == Double.NEGATIVE_INFINITY && expected.getMin() == Double.POSITIVE_INFINITY) { diff --git a/core_impl/src/test/java/io/opencensus/implcore/stats/ViewManagerImplTest.java b/core_impl/src/test/java/io/opencensus/implcore/stats/ViewManagerImplTest.java index 387c59fb..a5b26c6c 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/stats/ViewManagerImplTest.java +++ b/core_impl/src/test/java/io/opencensus/implcore/stats/ViewManagerImplTest.java @@ -100,7 +100,7 @@ public class ViewManagerImplTest { BucketBoundaries.create( Arrays.asList( 0.0, 0.2, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 7.0, 10.0, 15.0, 20.0, 30.0, 40.0, 50.0)); - + private static final Sum SUM = Sum.create(); private static final Mean MEAN = Mean.create(); private static final Distribution DISTRIBUTION = Distribution.create(BUCKET_BOUNDARIES); @@ -161,7 +161,11 @@ public class ViewManagerImplTest { public void preventRegisteringDifferentViewWithSameName() { View view1 = View.create( - VIEW_NAME, "View description.", MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), + VIEW_NAME, + "View description.", + MEASURE_DOUBLE, + DISTRIBUTION, + Arrays.asList(KEY), CUMULATIVE); View view2 = View.create( @@ -171,20 +175,22 @@ public class ViewManagerImplTest { DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE); - testFailedToRegisterView(view1, view2, - "A different view with the same name is already registered"); + testFailedToRegisterView( + view1, view2, "A different view with the same name is already registered"); } @Test public void preventRegisteringDifferentMeasureWithSameName() { MeasureDouble measure1 = MeasureDouble.create("measure", "description", "1"); MeasureLong measure2 = MeasureLong.create("measure", "description", "1"); - View view1 = View.create( - VIEW_NAME, VIEW_DESCRIPTION, measure1, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE); - View view2 = View.create( - VIEW_NAME_2, VIEW_DESCRIPTION, measure2, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE); - testFailedToRegisterView(view1, view2, - "A different measure with the same name is already registered"); + View view1 = + View.create( + VIEW_NAME, VIEW_DESCRIPTION, measure1, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE); + View view2 = + View.create( + VIEW_NAME_2, VIEW_DESCRIPTION, measure2, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE); + testFailedToRegisterView( + view1, view2, "A different measure with the same name is already registered"); } private void testFailedToRegisterView(View view1, View view2, String message) { @@ -229,8 +235,7 @@ public class ViewManagerImplTest { viewManager.registerView(view); TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build(); for (double val : values) { - putToMeasureMap(statsRecorder.newMeasureMap(), measure, val) - .record(tags); + putToMeasureMap(statsRecorder.newMeasureMap(), measure, val).record(tags); } clock.setTime(Timestamp.create(3, 4)); ViewData viewData = viewManager.getView(VIEW_NAME); @@ -250,7 +255,7 @@ public class ViewManagerImplTest { testRecordInterval( MEASURE_DOUBLE, MEAN, - new double[]{20.0, -1.0, 1.0, -5.0, 5.0}, + new double[] {20.0, -1.0, 1.0, -5.0, 5.0}, 9.0, 30.0, MeanData.create((19 * 0.6 + 1) / 4, 4), @@ -263,7 +268,7 @@ public class ViewManagerImplTest { testRecordInterval( MEASURE_LONG, MEAN, - new double[]{1000, 2000, 3000, 4000, 5000}, + new double[] {1000, 2000, 3000, 4000, 5000}, -5000, 30, MeanData.create((3000 * 0.6 + 12000) / 4, 4), @@ -276,7 +281,7 @@ public class ViewManagerImplTest { testRecordInterval( MEASURE_DOUBLE, SUM, - new double[]{20.0, -1.0, 1.0, -5.0, 5.0}, + new double[] {20.0, -1.0, 1.0, -5.0, 5.0}, 9.0, 30.0, SumDataDouble.create(19 * 0.6 + 1), @@ -289,7 +294,7 @@ public class ViewManagerImplTest { testRecordInterval( MEASURE_LONG, SUM, - new double[]{1000, 2000, 3000, 4000, 5000}, + new double[] {1000, 2000, 3000, 4000, 5000}, -5000, 30, SumDataLong.create(Math.round(3000 * 0.6 + 12000)), @@ -308,9 +313,14 @@ public class ViewManagerImplTest { AggregationData expectedValues3) { // The interval is 10 seconds, i.e. values should expire after 10 seconds. // Each bucket has a duration of 2.5 seconds. - View view = View.create( - VIEW_NAME, VIEW_DESCRIPTION, measure, aggregation, Arrays.asList(KEY), - Interval.create(TEN_SECONDS)); + View view = + View.create( + VIEW_NAME, + VIEW_DESCRIPTION, + measure, + aggregation, + Arrays.asList(KEY), + Interval.create(TEN_SECONDS)); long startTimeMillis = 30 * MILLIS_PER_SECOND; // start at 30s clock.setTime(Timestamp.fromMillis(startTimeMillis)); viewManager.registerView(view); @@ -325,8 +335,7 @@ public class ViewManagerImplTest { * 5th value should fall into the third bucket [35.0, 37.5). */ clock.setTime(Timestamp.fromMillis(startTimeMillis + i * MILLIS_PER_SECOND)); - putToMeasureMap(statsRecorder.newMeasureMap(), measure, initialValues[i - 1]) - .record(tags); + putToMeasureMap(statsRecorder.newMeasureMap(), measure, initialValues[i - 1]).record(tags); } clock.setTime(Timestamp.fromMillis(startTimeMillis + 8 * MILLIS_PER_SECOND)); @@ -347,8 +356,7 @@ public class ViewManagerImplTest { clock.setTime(Timestamp.fromMillis(startTimeMillis + 12 * MILLIS_PER_SECOND)); // 42s, add a new value value1, should fall into bucket [40.0, 42.5) - putToMeasureMap(statsRecorder.newMeasureMap(), measure, value6) - .record(tags); + putToMeasureMap(statsRecorder.newMeasureMap(), measure, value6).record(tags); clock.setTime(Timestamp.fromMillis(startTimeMillis + 17 * MILLIS_PER_SECOND)); // 47s, values in the first and second bucket should have expired, and 80% of values in the @@ -360,8 +368,7 @@ public class ViewManagerImplTest { clock.setTime(Timestamp.fromMillis(60 * MILLIS_PER_SECOND)); // 60s, all previous values should have expired, add another value value2 - putToMeasureMap(statsRecorder.newMeasureMap(), measure, value7) - .record(tags); + putToMeasureMap(statsRecorder.newMeasureMap(), measure, value7).record(tags); StatsTestUtil.assertAggregationMapEquals( viewManager.getView(VIEW_NAME).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), expectedValues3), @@ -436,9 +443,14 @@ public class ViewManagerImplTest { @Test public void testRecordIntervalMultipleTagValues() { // The interval is 10 seconds, i.e. values should expire after 10 seconds. - View view = View.create( - VIEW_NAME, VIEW_DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), - Interval.create(TEN_SECONDS)); + View view = + View.create( + VIEW_NAME, + VIEW_DESCRIPTION, + MEASURE_DOUBLE, + DISTRIBUTION, + Arrays.asList(KEY), + Interval.create(TEN_SECONDS)); clock.setTime(Timestamp.create(10, 0)); // Start at 10s viewManager.registerView(view); @@ -520,10 +532,7 @@ public class ViewManagerImplTest { viewManager.registerView( createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY))); // DEFAULT doesn't have tags, but the view has tag key "KEY". - statsRecorder - .newMeasureMap() - .put(MEASURE_DOUBLE, 10.0) - .record(tagger.empty()); + statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 10.0).record(tagger.empty()); ViewData viewData = viewManager.getView(VIEW_NAME); assertAggregationMapEquals( viewData.getAggregationMap(), @@ -553,15 +562,9 @@ public class ViewManagerImplTest { } private void testRecord_MeasureNotMatch(Measure measure1, Measure measure2, double value) { - viewManager.registerView( - createCumulativeView( - VIEW_NAME, - measure1, - MEAN, - Arrays.asList(KEY))); + viewManager.registerView(createCumulativeView(VIEW_NAME, measure1, MEAN, Arrays.asList(KEY))); TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build(); - putToMeasureMap(statsRecorder.newMeasureMap(), measure2, value) - .record(tags); + putToMeasureMap(statsRecorder.newMeasureMap(), measure2, value).record(tags); ViewData view = viewManager.getView(VIEW_NAME); assertThat(view.getAggregationMap()).isEmpty(); } @@ -573,13 +576,11 @@ public class ViewManagerImplTest { statsRecorder .newMeasureMap() .put(MEASURE_DOUBLE, 10.0) - .record( - tagger.emptyBuilder().put(TagKey.create("wrong key"), VALUE).build()); + .record(tagger.emptyBuilder().put(TagKey.create("wrong key"), VALUE).build()); statsRecorder .newMeasureMap() .put(MEASURE_DOUBLE, 50.0) - .record( - tagger.emptyBuilder().put(TagKey.create("another wrong key"), VALUE).build()); + .record(tagger.emptyBuilder().put(TagKey.create("another wrong key"), VALUE).build()); ViewData viewData = viewManager.getView(VIEW_NAME); assertAggregationMapEquals( viewData.getAggregationMap(), @@ -703,8 +704,7 @@ public class ViewManagerImplTest { private void testMultipleViews_DifferentMeasures( Measure measure1, Measure measure2, double value1, double value2) { - final View view1 = - createCumulativeView(VIEW_NAME, measure1, DISTRIBUTION, Arrays.asList(KEY)); + final View view1 = createCumulativeView(VIEW_NAME, measure1, DISTRIBUTION, Arrays.asList(KEY)); final View view2 = createCumulativeView(VIEW_NAME_2, measure2, DISTRIBUTION, Arrays.asList(KEY)); clock.setTime(Timestamp.create(1, 0)); @@ -740,10 +740,9 @@ public class ViewManagerImplTest { @Test public void testGetCumulativeViewDataWithEmptyBucketBoundaries() { - Aggregation noHistogram = Distribution.create( - BucketBoundaries.create(Collections.<Double>emptyList())); - View view = - createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, noHistogram, Arrays.asList(KEY)); + Aggregation noHistogram = + Distribution.create(BucketBoundaries.create(Collections.<Double>emptyList())); + View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, noHistogram, Arrays.asList(KEY)); clock.setTime(Timestamp.create(1, 0)); viewManager.registerView(view); statsRecorder @@ -764,8 +763,7 @@ public class ViewManagerImplTest { @Test public void testGetCumulativeViewDataWithoutBucketBoundaries() { - View view = - createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY)); + View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY)); clock.setTime(Timestamp.create(1, 0)); viewManager.registerView(view); statsRecorder @@ -779,13 +777,11 @@ public class ViewManagerImplTest { StatsTestUtil.assertAggregationMapEquals( viewData.getAggregationMap(), ImmutableMap.of( - Arrays.asList(VALUE), - StatsTestUtil.createAggregationData(MEAN, MEASURE_DOUBLE, 1.1)), + Arrays.asList(VALUE), StatsTestUtil.createAggregationData(MEAN, MEASURE_DOUBLE, 1.1)), EPSILON); } - private static MeasureMap putToMeasureMap( - MeasureMap measureMap, Measure measure, double value) { + private static MeasureMap putToMeasureMap(MeasureMap measureMap, Measure measure, double value) { if (measure instanceof MeasureDouble) { return measureMap.put((MeasureDouble) measure, value); } else if (measure instanceof MeasureLong) { diff --git a/core_impl/src/test/java/io/opencensus/implcore/tags/TaggerImplTest.java b/core_impl/src/test/java/io/opencensus/implcore/tags/TaggerImplTest.java index 89fc9e09..4ca2ae76 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/tags/TaggerImplTest.java +++ b/core_impl/src/test/java/io/opencensus/implcore/tags/TaggerImplTest.java @@ -90,8 +90,7 @@ public class TaggerImplTest { tagsComponent.setState(TaggingState.ENABLED); TagContextBuilder builder = tagger.emptyBuilder(); assertThat(builder).isInstanceOf(TagContextBuilderImpl.class); - assertThat(tagContextToList(builder.put(K1, V1).build())) - .containsExactly(Tag.create(K1, V1)); + assertThat(tagContextToList(builder.put(K1, V1).build())).containsExactly(Tag.create(K1, V1)); } @Test diff --git a/core_impl/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java b/core_impl/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java index 4ce34966..14118be0 100644 --- a/core_impl/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java +++ b/core_impl/src/test/java/io/opencensus/implcore/tags/propagation/TagContextDeserializationTest.java @@ -108,10 +108,7 @@ public class TagContextDeserializationTest { output.write(SerializationUtils.VERSION_ID); encodeTagToOutput("Key", "Value", output); TagContext expected = - tagger - .emptyBuilder() - .put(TagKey.create("Key"), TagValue.create("Value")) - .build(); + tagger.emptyBuilder().put(TagKey.create("Key"), TagValue.create("Value")).build(); assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected); } @@ -186,8 +183,7 @@ public class TagContextDeserializationTest { // <tag_key> == tag_key_len bytes comprising tag key name // <tag_val_len> == varint encoded integer // <tag_val> == tag_val_len bytes comprising UTF-8 string - private static void encodeTagToOutput( - String key, String value, ByteArrayDataOutput output) { + private static void encodeTagToOutput(String key, String value, ByteArrayDataOutput output) { output.write(SerializationUtils.TAG_FIELD_ID); encodeString(key, output); encodeString(value, output); diff --git a/core_impl_android/src/main/java/io/opencensus/impllite/stats/StatsComponentImplLite.java b/core_impl_android/src/main/java/io/opencensus/impllite/stats/StatsComponentImplLite.java index e8143031..a58a9d3e 100644 --- a/core_impl_android/src/main/java/io/opencensus/impllite/stats/StatsComponentImplLite.java +++ b/core_impl_android/src/main/java/io/opencensus/impllite/stats/StatsComponentImplLite.java @@ -21,9 +21,7 @@ import io.opencensus.implcore.internal.SimpleEventQueue; import io.opencensus.implcore.stats.StatsComponentImplBase; import io.opencensus.stats.StatsComponent; -/** - * Android-compatible implementation of {@link StatsComponent}. - */ +/** Android-compatible implementation of {@link StatsComponent}. */ public final class StatsComponentImplLite extends StatsComponentImplBase { public StatsComponentImplLite() { diff --git a/core_impl_android/src/test/java/io/opencensus/impllite/stats/StatsTest.java b/core_impl_android/src/test/java/io/opencensus/impllite/stats/StatsTest.java index 0142fa51..313f8916 100644 --- a/core_impl_android/src/test/java/io/opencensus/impllite/stats/StatsTest.java +++ b/core_impl_android/src/test/java/io/opencensus/impllite/stats/StatsTest.java @@ -26,9 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** - * Test for accessing the {@link StatsComponent} through the {@link Stats} class. - */ +/** Test for accessing the {@link StatsComponent} through the {@link Stats} class. */ @RunWith(JUnit4.class) public final class StatsTest { @Test diff --git a/core_impl_android/src/test/java/io/opencensus/impllite/tags/TagsTest.java b/core_impl_android/src/test/java/io/opencensus/impllite/tags/TagsTest.java index 2932bd16..890cdb15 100644 --- a/core_impl_android/src/test/java/io/opencensus/impllite/tags/TagsTest.java +++ b/core_impl_android/src/test/java/io/opencensus/impllite/tags/TagsTest.java @@ -36,7 +36,6 @@ public final class TagsTest { @Test public void getTagContextSerializer() { - assertThat(Tags.getTagPropagationComponent()) - .isInstanceOf(TagPropagationComponentImpl.class); + assertThat(Tags.getTagPropagationComponent()).isInstanceOf(TagPropagationComponentImpl.class); } } diff --git a/core_impl_java/src/test/java/io/opencensus/impl/tags/TagsTest.java b/core_impl_java/src/test/java/io/opencensus/impl/tags/TagsTest.java index c1399c64..e94cf254 100644 --- a/core_impl_java/src/test/java/io/opencensus/impl/tags/TagsTest.java +++ b/core_impl_java/src/test/java/io/opencensus/impl/tags/TagsTest.java @@ -36,7 +36,6 @@ public final class TagsTest { @Test public void getTagContextSerializer() { - assertThat(Tags.getTagPropagationComponent()) - .isInstanceOf(TagPropagationComponentImpl.class); + assertThat(Tags.getTagPropagationComponent()).isInstanceOf(TagPropagationComponentImpl.class); } } diff --git a/examples/src/main/java/io/opencensus/examples/zpages/ZPagesTester.java b/examples/src/main/java/io/opencensus/examples/zpages/ZPagesTester.java index 24dd7841..61e135dd 100644 --- a/examples/src/main/java/io/opencensus/examples/zpages/ZPagesTester.java +++ b/examples/src/main/java/io/opencensus/examples/zpages/ZPagesTester.java @@ -18,9 +18,7 @@ package io.opencensus.examples.zpages; import io.opencensus.contrib.zpages.ZPageHandlers; -/** - * Testing only class for the UI. - */ +/** Testing only class for the UI. */ public class ZPagesTester { /** Main method. */ public static void main(String[] args) throws Exception { diff --git a/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverExporter.java b/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverExporter.java index 7592b062..534b16a8 100644 --- a/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverExporter.java +++ b/exporters/trace/stackdriver/src/main/java/io/opencensus/exporter/trace/stackdriver/StackdriverExporter.java @@ -57,9 +57,8 @@ public final class StackdriverExporter { * @param projectId the cloud project id. * @throws IllegalStateException if a Stackdriver exporter is already registered. */ - public static void createAndRegisterWithCredentialsAndProjectId(Credentials credentials, - String projectId) - throws IOException { + public static void createAndRegisterWithCredentialsAndProjectId( + Credentials credentials, String projectId) throws IOException { synchronized (monitor) { checkState(handler == null, "Stackdriver exporter is already registered."); handler = StackdriverV1ExporterHandler.createWithCredentials(credentials, projectId); diff --git a/exporters/trace/zipkin/src/main/java/io/opencensus/exporter/trace/zipkin/ZipkinExporter.java b/exporters/trace/zipkin/src/main/java/io/opencensus/exporter/trace/zipkin/ZipkinExporter.java index b90abfd4..743ee639 100644 --- a/exporters/trace/zipkin/src/main/java/io/opencensus/exporter/trace/zipkin/ZipkinExporter.java +++ b/exporters/trace/zipkin/src/main/java/io/opencensus/exporter/trace/zipkin/ZipkinExporter.java @@ -67,12 +67,12 @@ public final class ZipkinExporter { * exporter can be registered at any point. * * @param encoder Usually {@link SpanBytesEncoder#JSON_V2} - * @param sender Often, but not necessarily an http sender. This could be Kafka or SQS. + * @param sender Often, but not necessarily an http sender. This could be Kafka or SQS. * @param serviceName the {@link Span#localServiceName() local service name} of the process. * @throws IllegalStateException if a Zipkin exporter is already registered. */ - public static void createAndRegister(SpanBytesEncoder encoder, Sender sender, - String serviceName) { + public static void createAndRegister( + SpanBytesEncoder encoder, Sender sender, String serviceName) { synchronized (monitor) { checkState(handler == null, "Zipkin exporter is already registered."); handler = new ZipkinExporterHandler(encoder, sender, serviceName); @@ -107,7 +107,7 @@ public final class ZipkinExporter { * Unregisters the {@code ZipkinExporter}. * * @param spanExporter the instance of the {@code SpanExporter} from where this service is - * unregistered. + * unregistered. */ @VisibleForTesting static void unregister(SpanExporter spanExporter) { diff --git a/exporters/trace/zipkin/src/main/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterHandler.java b/exporters/trace/zipkin/src/main/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterHandler.java index 96d8352a..2885db14 100644 --- a/exporters/trace/zipkin/src/main/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterHandler.java +++ b/exporters/trace/zipkin/src/main/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterHandler.java @@ -70,9 +70,7 @@ final class ZipkinExporterHandler extends SpanExporter.Handler { this.localEndpoint = produceLocalEndpoint(serviceName); } - /** - * Logic borrowed from brave.internal.Platform.produceLocalEndpoint - */ + /** Logic borrowed from brave.internal.Platform.produceLocalEndpoint */ static Endpoint produceLocalEndpoint(String serviceName) { Endpoint.Builder builder = Endpoint.newBuilder().serviceName(serviceName); try { @@ -104,14 +102,15 @@ final class ZipkinExporterHandler extends SpanExporter.Handler { SpanContext context = spanData.getContext(); long startTimestamp = toEpochMicros(spanData.getStartTimestamp()); long endTimestamp = toEpochMicros(spanData.getEndTimestamp()); - Span.Builder spanBuilder = Span.newBuilder() - .traceId(encodeTraceId(context.getTraceId())) - .id(encodeSpanId(context.getSpanId())) - .kind(toSpanKind(spanData)) - .name(spanData.getName()) - .timestamp(toEpochMicros(spanData.getStartTimestamp())) - .duration(endTimestamp - startTimestamp) - .localEndpoint(localEndpoint); + Span.Builder spanBuilder = + Span.newBuilder() + .traceId(encodeTraceId(context.getTraceId())) + .id(encodeSpanId(context.getSpanId())) + .kind(toSpanKind(spanData)) + .name(spanData.getName()) + .timestamp(toEpochMicros(spanData.getStartTimestamp())) + .duration(endTimestamp - startTimestamp) + .localEndpoint(localEndpoint); if (spanData.getParentSpanId() != null && spanData.getParentSpanId().isValid()) { spanBuilder.parentId(encodeSpanId(spanData.getParentSpanId())); @@ -128,16 +127,12 @@ final class ZipkinExporterHandler extends SpanExporter.Handler { for (TimedEvent<Annotation> annotation : spanData.getAnnotations().getEvents()) { spanBuilder.addAnnotation( - toEpochMicros(annotation.getTimestamp()), - annotation.getEvent().getDescription() - ); + toEpochMicros(annotation.getTimestamp()), annotation.getEvent().getDescription()); } for (TimedEvent<NetworkEvent> networkEvent : spanData.getNetworkEvents().getEvents()) { spanBuilder.addAnnotation( - toEpochMicros(networkEvent.getTimestamp()), - networkEvent.getEvent().getType().name() - ); + toEpochMicros(networkEvent.getTimestamp()), networkEvent.getEvent().getType().name()); } return spanBuilder.build(); diff --git a/exporters/trace/zipkin/src/test/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterHandlerTest.java b/exporters/trace/zipkin/src/test/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterHandlerTest.java index 3d95a795..6476aadb 100644 --- a/exporters/trace/zipkin/src/test/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterHandlerTest.java +++ b/exporters/trace/zipkin/src/test/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterHandlerTest.java @@ -46,9 +46,7 @@ import zipkin2.Endpoint; import zipkin2.Span; import zipkin2.Span.Kind; -/** - * Unit tests for {@link ZipkinExporterHandler}. - */ +/** Unit tests for {@link ZipkinExporterHandler}. */ @RunWith(JUnit4.class) public class ZipkinExporterHandlerTest { @@ -60,51 +58,51 @@ public class ZipkinExporterHandlerTest { String parentId = "8b03ab423da481c5"; Map<String, AttributeValue> attributes = Collections.emptyMap(); List<TimedEvent<Annotation>> annotations = Collections.emptyList(); - List<TimedEvent<NetworkEvent>> networkEvents = ImmutableList.of( - TimedEvent.create( - Timestamp.create(1505855799, 433901068), - NetworkEvent.builder(Type.RECV, 0).setCompressedMessageSize(7).build() - ), - TimedEvent.create( - Timestamp.create(1505855799, 459486280), - NetworkEvent.builder(Type.SENT, 0).setCompressedMessageSize(13).build() - ) - ); - SpanData data = SpanData.create( - SpanContext.create( - // TODO SpanId.fromLowerBase16 - TraceId.fromBytes(BaseEncoding.base16().lowerCase().decode(traceId)), + List<TimedEvent<NetworkEvent>> networkEvents = + ImmutableList.of( + TimedEvent.create( + Timestamp.create(1505855799, 433901068), + NetworkEvent.builder(Type.RECV, 0).setCompressedMessageSize(7).build()), + TimedEvent.create( + Timestamp.create(1505855799, 459486280), + NetworkEvent.builder(Type.SENT, 0).setCompressedMessageSize(13).build())); + SpanData data = + SpanData.create( + SpanContext.create( + // TODO SpanId.fromLowerBase16 + TraceId.fromBytes(BaseEncoding.base16().lowerCase().decode(traceId)), + // TODO SpanId.fromLowerBase16 + SpanId.fromBytes(BaseEncoding.base16().lowerCase().decode(spanId)), + TraceOptions.fromBytes(new byte[] {1} /* sampled */)), // TODO SpanId.fromLowerBase16 - SpanId.fromBytes(BaseEncoding.base16().lowerCase().decode(spanId)), - TraceOptions.fromBytes(new byte[]{1} /* sampled */) - ), - // TODO SpanId.fromLowerBase16 - SpanId.fromBytes(BaseEncoding.base16().lowerCase().decode(parentId)), - true, /* hasRemoteParent */ - "Recv.helloworld.Greeter.SayHello", /* name */ - Timestamp.create(1505855794, 194009601) /* startTimestamp */, - Attributes.create(attributes, 0 /* droppedAttributesCount */), - TimedEvents.create(annotations, 0 /* droppedEventsCount */), - TimedEvents.create(networkEvents, 0 /* droppedEventsCount */), - Links.create(Collections.<Link>emptyList(), 0 /* droppedLinksCount */), - null, /* childSpanCount */ - Status.OK, - Timestamp.create(1505855799, 465726528) /* endTimestamp */ - ); + SpanId.fromBytes(BaseEncoding.base16().lowerCase().decode(parentId)), + true, /* hasRemoteParent */ + "Recv.helloworld.Greeter.SayHello", /* name */ + Timestamp.create(1505855794, 194009601) /* startTimestamp */, + Attributes.create(attributes, 0 /* droppedAttributesCount */), + TimedEvents.create(annotations, 0 /* droppedEventsCount */), + TimedEvents.create(networkEvents, 0 /* droppedEventsCount */), + Links.create(Collections.<Link>emptyList(), 0 /* droppedLinksCount */), + null, /* childSpanCount */ + Status.OK, + Timestamp.create(1505855799, 465726528) /* endTimestamp */); - assertThat(ZipkinExporterHandler.generateSpan(data, localEndpoint)).isEqualTo(Span.newBuilder() - .traceId(traceId) - .parentId(parentId) - .id(spanId) - .kind(Kind.SERVER) - .name(data.getName()) - .timestamp(1505855794000000L + 194009601L / 1000) - .duration((1505855799000000L + 465726528L / 1000) - (1505855794000000L + 194009601L / 1000)) - .localEndpoint(localEndpoint) - .addAnnotation(1505855799000000L + 433901068L / 1000, "RECV") - .addAnnotation(1505855799000000L + 459486280L / 1000, "SENT") - .putTag("census.status_code", "OK") - .build() - ); + assertThat(ZipkinExporterHandler.generateSpan(data, localEndpoint)) + .isEqualTo( + Span.newBuilder() + .traceId(traceId) + .parentId(parentId) + .id(spanId) + .kind(Kind.SERVER) + .name(data.getName()) + .timestamp(1505855794000000L + 194009601L / 1000) + .duration( + (1505855799000000L + 465726528L / 1000) + - (1505855794000000L + 194009601L / 1000)) + .localEndpoint(localEndpoint) + .addAnnotation(1505855799000000L + 433901068L / 1000, "RECV") + .addAnnotation(1505855799000000L + 459486280L / 1000, "SENT") + .putTag("census.status_code", "OK") + .build()); } } diff --git a/exporters/trace/zipkin/src/test/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterTest.java b/exporters/trace/zipkin/src/test/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterTest.java index 11d39ad8..e88b5ff7 100644 --- a/exporters/trace/zipkin/src/test/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterTest.java +++ b/exporters/trace/zipkin/src/test/java/io/opencensus/exporter/trace/zipkin/ZipkinExporterTest.java @@ -29,15 +29,11 @@ import org.junit.runners.JUnit4; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -/** - * Unit tests for {@link ZipkinExporter}. - */ +/** Unit tests for {@link ZipkinExporter}. */ @RunWith(JUnit4.class) public class ZipkinExporterTest { - @Mock - private SpanExporter spanExporter; - @Mock - private Handler handler; + @Mock private SpanExporter spanExporter; + @Mock private Handler handler; @Before public void setUp() { @@ -48,8 +44,7 @@ public class ZipkinExporterTest { public void registerUnregisterZipkinExporter() { ZipkinExporter.register(spanExporter, handler); verify(spanExporter) - .registerHandler( - eq("io.opencensus.exporter.trace.zipkin.ZipkinExporter"), same(handler)); + .registerHandler(eq("io.opencensus.exporter.trace.zipkin.ZipkinExporter"), same(handler)); ZipkinExporter.unregister(spanExporter); verify(spanExporter) .unregisterHandler(eq("io.opencensus.exporter.trace.zipkin.ZipkinExporter")); diff --git a/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java b/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java index f825d526..e11d6107 100644 --- a/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java +++ b/impl/src/main/java/io/opencensus/impl/internal/DisruptorEventQueue.java @@ -121,14 +121,15 @@ public final class DisruptorEventQueue implements EventQueue { } private static final AtomicInteger threadIdGen = new AtomicInteger(); - private static final ThreadFactory threadFactory = new ThreadFactory() { - @Override - public Thread newThread(Runnable r) { - Thread thread = new Thread(r, "CensusDisruptor-" + threadIdGen.getAndIncrement()); - thread.setDaemon(true); - return thread; - } - }; + private static final ThreadFactory threadFactory = + new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread thread = new Thread(r, "CensusDisruptor-" + threadIdGen.getAndIncrement()); + thread.setDaemon(true); + return thread; + } + }; // The single instance of the class. private static final DisruptorEventQueue eventQueue = new DisruptorEventQueue(); diff --git a/impl/src/main/java/io/opencensus/impl/trace/internal/ThreadLocalRandomHandler.java b/impl/src/main/java/io/opencensus/impl/trace/internal/ThreadLocalRandomHandler.java index 1c6d6112..d13e3982 100644 --- a/impl/src/main/java/io/opencensus/impl/trace/internal/ThreadLocalRandomHandler.java +++ b/impl/src/main/java/io/opencensus/impl/trace/internal/ThreadLocalRandomHandler.java @@ -25,9 +25,7 @@ import javax.annotation.concurrent.ThreadSafe; @ThreadSafe public final class ThreadLocalRandomHandler extends RandomHandler { - /** - * Constructs a new {@code ThreadLocalRandomHandler}. - */ + /** Constructs a new {@code ThreadLocalRandomHandler}. */ public ThreadLocalRandomHandler() {} @Override diff --git a/impl/src/test/java/io/opencensus/impl/trace/TracingTest.java b/impl/src/test/java/io/opencensus/impl/trace/TracingTest.java index 5eef2c0d..e58ce1cb 100644 --- a/impl/src/test/java/io/opencensus/impl/trace/TracingTest.java +++ b/impl/src/test/java/io/opencensus/impl/trace/TracingTest.java @@ -38,8 +38,7 @@ public class TracingTest { @Test public void implementationOfBinaryPropagationHandler() { - assertThat(Tracing.getPropagationComponent()) - .isInstanceOf(PropagationComponent.class); + assertThat(Tracing.getPropagationComponent()).isInstanceOf(PropagationComponent.class); } @Test diff --git a/impl_core/src/main/java/io/opencensus/implcore/internal/NoopScope.java b/impl_core/src/main/java/io/opencensus/implcore/internal/NoopScope.java index 5d9be5b6..51efe894 100644 --- a/impl_core/src/main/java/io/opencensus/implcore/internal/NoopScope.java +++ b/impl_core/src/main/java/io/opencensus/implcore/internal/NoopScope.java @@ -18,9 +18,7 @@ package io.opencensus.implcore.internal; import io.opencensus.common.Scope; -/** - * A {@link Scope} that does nothing when it is created or closed. - */ +/** A {@link Scope} that does nothing when it is created or closed. */ public final class NoopScope implements Scope { private static final Scope INSTANCE = new NoopScope(); diff --git a/impl_lite/src/test/java/io/opencensus/impllite/trace/TraceComponentImplLiteTest.java b/impl_lite/src/test/java/io/opencensus/impllite/trace/TraceComponentImplLiteTest.java index 0cc953ae..c4a609a4 100644 --- a/impl_lite/src/test/java/io/opencensus/impllite/trace/TraceComponentImplLiteTest.java +++ b/impl_lite/src/test/java/io/opencensus/impllite/trace/TraceComponentImplLiteTest.java @@ -37,8 +37,7 @@ public class TraceComponentImplLiteTest { @Test public void implementationOfBinaryPropagationHandler() { - assertThat(Tracing.getPropagationComponent()) - .isInstanceOf(PropagationComponentImpl.class); + assertThat(Tracing.getPropagationComponent()).isInstanceOf(PropagationComponentImpl.class); } @Test diff --git a/scripts/travis_script b/scripts/travis_script index 74b50bf0..f39b7ee0 100755 --- a/scripts/travis_script +++ b/scripts/travis_script @@ -20,6 +20,7 @@ case "$TASK" in export JAVA_HOMES="$(jdk_switcher home openjdk6)/jre:$(jdk_switcher home openjdk7)/jre:$(jdk_switcher home oraclejdk8)/jre:$(jdk_switcher home oraclejdk9)" ./gradlew clean assemble --stacktrace ./gradlew check :opencensus-all:jacocoTestReport + ./gradlew verGJF ;; "openjdk7") # "./gradlew classes testClasses" is a workaround for |