Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename newBuilder() to builder() #4407

Merged
merged 2 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public interface Cache<K, V> {

/** Returns a new {@link CacheBuilder} to configure a {@link Cache}. */
static CacheBuilder newBuilder() {
static CacheBuilder builder() {
return new CacheBuilder();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class Config {
@Nullable private static volatile Config instance = null;

/** Start building a new {@link Config} instance. */
public static ConfigBuilder newBuilder() {
public static ConfigBuilder builder() {
return new ConfigBuilder();
}

Expand Down Expand Up @@ -68,7 +68,7 @@ public static Config get() {
// this should only happen in library instrumentation
//
// no need to synchronize because worst case is creating instance more than once
instance = newBuilder().readEnvironmentVariables().readSystemProperties().build();
instance = builder().readEnvironmentVariables().readSystemProperties().build();
}
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class SqlStatementSanitizer {
private static final SupportabilityMetrics supportability = SupportabilityMetrics.instance();

private static final Cache<String, SqlStatementInfo> sqlToStatementInfoCache =
Cache.newBuilder().setMaximumSize(1000).build();
Cache.builder().setMaximumSize(1000).build();

public static SqlStatementInfo sanitize(@Nullable String statement) {
if (!isStatementSanitizationEnabled() || statement == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
final class HttpHeaderAttributes {

private static final Cache<String, AttributeKey<List<String>>> requestKeysCache =
Cache.newBuilder().setMaximumSize(32).build();
Cache.builder().setMaximumSize(32).build();
private static final Cache<String, AttributeKey<List<String>>> responseKeysCache =
Cache.newBuilder().setMaximumSize(32).build();
Cache.builder().setMaximumSize(32).build();

static AttributeKey<List<String>> requestAttributeKey(String headerName) {
return requestKeysCache.computeIfAbsent(headerName, n -> createKey("request", n));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public <U extends T, T, F> VirtualField<U, F> find(Class<T> type, Class<F> field
}

private static final class CacheBasedVirtualField<T, F> extends VirtualField<T, F> {
private final Cache<T, F> cache = Cache.newBuilder().setWeakKeys().build();
private final Cache<T, F> cache = Cache.builder().setWeakKeys().build();

@Override
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CacheTest {
class StrongKeys {
@Test
void unbounded() {
Cache<String, String> cache = Cache.newBuilder().build();
Cache<String, String> cache = Cache.builder().build();

assertThat(cache.computeIfAbsent("bear", unused -> "roar")).isEqualTo("roar");
cache.remove("bear");
Expand All @@ -40,7 +40,7 @@ void unbounded() {

@Test
void bounded() {
Cache<String, String> cache = Cache.newBuilder().setMaximumSize(1).build();
Cache<String, String> cache = Cache.builder().setMaximumSize(1).build();

assertThat(cache.computeIfAbsent("bear", unused -> "roar")).isEqualTo("roar");
cache.remove("bear");
Expand All @@ -65,7 +65,7 @@ void bounded() {
class WeakKeys {
@Test
void unbounded() {
Cache<String, String> cache = Cache.newBuilder().setWeakKeys().build();
Cache<String, String> cache = Cache.builder().setWeakKeys().build();

assertThat(cache.computeIfAbsent("bear", unused -> "roar")).isEqualTo("roar");
cache.remove("bear");
Expand Down Expand Up @@ -99,7 +99,7 @@ void unbounded() {

@Test
void bounded() {
Cache<String, String> cache = Cache.newBuilder().setWeakKeys().setMaximumSize(1).build();
Cache<String, String> cache = Cache.builder().setWeakKeys().setMaximumSize(1).build();

assertThat(cache.computeIfAbsent("bear", unused -> "roar")).isEqualTo("roar");
cache.remove("bear");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PatchCaffeineTest {
void cleanupNotForkJoinTask() {
AtomicReference<AssertionError> errorRef = new AtomicReference<>();
Cache<String, String> cache =
Cache.newBuilder()
Cache.builder()
.setExecutor(
task -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class ConfigTest {
@Test
void shouldGetString() {
Config config = Config.newBuilder().addProperty("prop.string", "some text").build();
Config config = Config.builder().addProperty("prop.string", "some text").build();

assertEquals("some text", config.getString("prop.string"));
assertEquals("some text", config.getString("prop.string", "default"));
Expand All @@ -43,7 +43,7 @@ void shouldGetString() {

@Test
void shouldGetBoolean() {
Config config = Config.newBuilder().addProperty("prop.boolean", "true").build();
Config config = Config.builder().addProperty("prop.boolean", "true").build();

assertTrue(config.getBoolean("prop.boolean"));
assertTrue(config.getBoolean("prop.boolean", false));
Expand All @@ -54,10 +54,7 @@ void shouldGetBoolean() {
@Test
void shouldGetInt() {
Config config =
Config.newBuilder()
.addProperty("prop.int", "12")
.addProperty("prop.wrong", "twelve")
.build();
Config.builder().addProperty("prop.int", "12").addProperty("prop.wrong", "twelve").build();

assertEquals(12, config.getInt("prop.int"));
assertEquals(12, config.getInt("prop.int", 1000));
Expand All @@ -68,18 +65,15 @@ void shouldGetInt() {

@Test
void shouldFailOnInvalidInt() {
Config config = Config.newBuilder().addProperty("prop.wrong", "twelve").build();
Config config = Config.builder().addProperty("prop.wrong", "twelve").build();

assertThrows(ConfigParsingException.class, () -> config.getInt("prop.wrong"));
}

@Test
void shouldGetLong() {
Config config =
Config.newBuilder()
.addProperty("prop.long", "12")
.addProperty("prop.wrong", "twelve")
.build();
Config.builder().addProperty("prop.long", "12").addProperty("prop.wrong", "twelve").build();

assertEquals(12, config.getLong("prop.long"));
assertEquals(12, config.getLong("prop.long", 1000));
Expand All @@ -90,15 +84,15 @@ void shouldGetLong() {

@Test
void shouldFailOnInvalidLong() {
Config config = Config.newBuilder().addProperty("prop.wrong", "twelve").build();
Config config = Config.builder().addProperty("prop.wrong", "twelve").build();

assertThrows(ConfigParsingException.class, () -> config.getLong("prop.wrong"));
}

@Test
void shouldGetDouble() {
Config config =
Config.newBuilder()
Config.builder()
.addProperty("prop.double", "12.345")
.addProperty("prop.wrong", "twelve point something")
.build();
Expand All @@ -112,15 +106,15 @@ void shouldGetDouble() {

@Test
void shouldFailOnInvalidDouble() {
Config config = Config.newBuilder().addProperty("prop.wrong", "twelve point something").build();
Config config = Config.builder().addProperty("prop.wrong", "twelve point something").build();

assertThrows(ConfigParsingException.class, () -> config.getDouble("prop.wrong"));
}

@Test
void shouldGetDuration_defaultUnit() {
Config config =
Config.newBuilder()
Config.builder()
.addProperty("prop.duration", "5000")
.addProperty("prop.wrong", "hundred days")
.build();
Expand All @@ -134,32 +128,32 @@ void shouldGetDuration_defaultUnit() {

@Test
void shouldFailOnInvalidDuration() {
Config config = Config.newBuilder().addProperty("prop.wrong", "hundred days").build();
Config config = Config.builder().addProperty("prop.wrong", "hundred days").build();

assertThrows(ConfigParsingException.class, () -> config.getDuration("prop.wrong"));
}

@Test
void shouldGetDuration_variousUnits() {
Config config = Config.newBuilder().addProperty("prop.duration", "100ms").build();
Config config = Config.builder().addProperty("prop.duration", "100ms").build();
assertEquals(Duration.ofMillis(100), config.getDuration("prop.duration"));

config = Config.newBuilder().addProperty("prop.duration", "100s").build();
config = Config.builder().addProperty("prop.duration", "100s").build();
assertEquals(Duration.ofSeconds(100), config.getDuration("prop.duration"));

config = Config.newBuilder().addProperty("prop.duration", "100m").build();
config = Config.builder().addProperty("prop.duration", "100m").build();
assertEquals(Duration.ofMinutes(100), config.getDuration("prop.duration"));

config = Config.newBuilder().addProperty("prop.duration", "100h").build();
config = Config.builder().addProperty("prop.duration", "100h").build();
assertEquals(Duration.ofHours(100), config.getDuration("prop.duration"));

config = Config.newBuilder().addProperty("prop.duration", "100d").build();
config = Config.builder().addProperty("prop.duration", "100d").build();
assertEquals(Duration.ofDays(100), config.getDuration("prop.duration"));
}

@Test
void shouldGetList() {
Config config = Config.newBuilder().addProperty("prop.list", "one, two ,three").build();
Config config = Config.builder().addProperty("prop.list", "one, two ,three").build();

assertEquals(asList("one", "two", "three"), config.getList("prop.list"));
assertEquals(
Expand All @@ -172,7 +166,7 @@ void shouldGetList() {
@Test
void shouldGetMap() {
Config config =
Config.newBuilder()
Config.builder()
.addProperty("prop.map", "one=1, two=2")
.addProperty("prop.wrong", "one=1, but not two!")
.addProperty("prop.trailing", "one=1,")
Expand All @@ -191,15 +185,15 @@ void shouldGetMap() {

@Test
void shouldFailOnInvalidMap() {
Config config = Config.newBuilder().addProperty("prop.wrong", "one=1, but not two!").build();
Config config = Config.builder().addProperty("prop.wrong", "one=1, but not two!").build();

assertThrows(ConfigParsingException.class, () -> config.getMap("prop.wrong"));
}

@ParameterizedTest
@ArgumentsSource(AgentDebugParams.class)
void shouldCheckIfAgentDebugModeIsEnabled(String propertyValue, boolean expected) {
Config config = Config.newBuilder().addProperty("otel.javaagent.debug", propertyValue).build();
Config config = Config.builder().addProperty("otel.javaagent.debug", propertyValue).build();

assertEquals(expected, config.isAgentDebugEnabled());
}
Expand All @@ -217,7 +211,7 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
void shouldCheckIfInstrumentationIsEnabled(
List<String> names, boolean defaultEnabled, boolean expected) {
Config config =
Config.newBuilder()
Config.builder()
.addProperty("otel.instrumentation.order.enabled", "true")
.addProperty("otel.instrumentation.test-prop.enabled", "true")
.addProperty("otel.instrumentation.disabled-prop.enabled", "false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void resetsCountsEachReport() {
}

private static Config configWithJavaagentDebug(boolean enabled) {
return Config.newBuilder()
return Config.builder()
.readProperties(Collections.singletonMap("otel.javaagent.debug", Boolean.toString(enabled)))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public final class InstrumentationHelper {
static {
asyncOperationEndStrategy =
GuavaAsyncOperationEndStrategy.newBuilder()
GuavaAsyncOperationEndStrategy.builder()
.setCaptureExperimentalSpanAttributes(
Config.get()
.getBoolean("otel.instrumentation.guava.experimental-span-attributes", false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public final class GuavaAsyncOperationEndStrategy implements AsyncOperationEndSt
AttributeKey.booleanKey("guava.canceled");

public static GuavaAsyncOperationEndStrategy create() {
return newBuilder().build();
return builder().build();
}

public static GuavaAsyncOperationEndStrategyBuilder newBuilder() {
public static GuavaAsyncOperationEndStrategyBuilder builder() {
return new GuavaAsyncOperationEndStrategyBuilder();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GuavaAsyncOperationEndStrategyTest extends Specification {

def underTest = GuavaAsyncOperationEndStrategy.create()

def underTestWithExperimentalAttributes = GuavaAsyncOperationEndStrategy.newBuilder()
def underTestWithExperimentalAttributes = GuavaAsyncOperationEndStrategy.builder()
.setCaptureExperimentalSpanAttributes(true)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class FutureListenerWrappers {
// to the key, that means it's no longer used (referenced) by the netty future anyways.
private static final Cache<
GenericFutureListener<? extends Future<?>>, GenericFutureListener<? extends Future<?>>>
wrappers = Cache.newBuilder().setWeakKeys().setWeakValues().build();
wrappers = Cache.builder().setWeakKeys().setWeakValues().build();

private static final ClassValue<Boolean> shouldWrap =
new ClassValue<Boolean>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class ResetOnEachOperatorAdvice {

@Advice.OnMethodExit(suppress = Throwable.class)
public static void postStaticInitializer() {
ContextPropagationOperator.newBuilder()
ContextPropagationOperator.builder()
.setCaptureExperimentalSpanAttributes(
Config.get()
.getBoolean("otel.instrumentation.reactor.experimental-span-attributes", false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
public final class ContextPropagationOperator {

public static ContextPropagationOperator create() {
return newBuilder().build();
return builder().build();
}

public static ContextPropagationOperatorBuilder newBuilder() {
public static ContextPropagationOperatorBuilder builder() {
return new ContextPropagationOperatorBuilder();
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public static Context getOpenTelemetryContext(

ContextPropagationOperator(boolean captureExperimentalSpanAttributes) {
this.asyncOperationEndStrategy =
ReactorAsyncOperationEndStrategy.newBuilder()
ReactorAsyncOperationEndStrategy.builder()
.setCaptureExperimentalSpanAttributes(captureExperimentalSpanAttributes)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public final class ReactorAsyncOperationEndStrategy implements AsyncOperationEnd
AttributeKey.booleanKey("reactor.canceled");

public static ReactorAsyncOperationEndStrategy create() {
return newBuilder().build();
return builder().build();
}

public static ReactorAsyncOperationEndStrategyBuilder newBuilder() {
public static ReactorAsyncOperationEndStrategyBuilder builder() {
return new ReactorAsyncOperationEndStrategyBuilder();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ReactorAsyncOperationEndStrategyTest extends Specification {

def underTest = ReactorAsyncOperationEndStrategy.create()

def underTestWithExperimentalAttributes = ReactorAsyncOperationEndStrategy.newBuilder()
def underTestWithExperimentalAttributes = ReactorAsyncOperationEndStrategy.builder()
.setCaptureExperimentalSpanAttributes(true)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected AtomicBoolean computeValue(Class<?> type) {

public static void activate(Class<?> clz) {
if (activated.get(clz).compareAndSet(false, true)) {
TracingAssembly.newBuilder()
TracingAssembly.builder()
.setCaptureExperimentalSpanAttributes(
Config.get()
.getBoolean("otel.instrumentation.rxjava.experimental-span-attributes", false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public final class RxJava2AsyncOperationEndStrategy implements AsyncOperationEnd
AttributeKey.booleanKey("rxjava.canceled");

public static RxJava2AsyncOperationEndStrategy create() {
return newBuilder().build();
return builder().build();
}

public static RxJava2AsyncOperationEndStrategyBuilder newBuilder() {
public static RxJava2AsyncOperationEndStrategyBuilder builder() {
return new RxJava2AsyncOperationEndStrategyBuilder();
}

Expand Down
Loading