From 5fb353191daf293fb90edc84b7257e3981cd0661 Mon Sep 17 00:00:00 2001 From: Josh Gordineer Date: Tue, 14 Nov 2023 12:31:18 -0800 Subject: [PATCH] update guava version, eliminate usages of guava except for loadbalancer --- gradle.properties | 1 - ribbon-archaius/build.gradle | 1 - ribbon-core/build.gradle | 1 - .../DefaultLoadBalancerRetryHandler.java | 9 +++--- .../client/RequestSpecificRetryHandler.java | 13 ++++----- .../client/config/CommonClientConfigKey.java | 16 ++++------ .../client/config/ReloadableClientConfig.java | 10 +++---- .../client/ssl/URLSslContextFactory.java | 20 ++++++++----- .../config/CommonClientConfigKeyTest.java | 6 ++-- ribbon-examples/build.gradle | 1 - .../examples/server/ServerResources.java | 6 ++-- ribbon-httpclient/build.gradle | 1 - .../client/http/CaseInsensitiveMultiMap.java | 3 +- .../niws/client/http/HttpClientResponse.java | 10 ++----- ribbon-loadbalancer/build.gradle | 2 +- .../loadbalancer/AbstractServerPredicate.java | 14 ++++----- .../loadbalancer/CompositePredicate.java | 4 +-- .../ConfigurationBasedServerList.java | 4 +-- .../loadbalancer/PredicateBasedRule.java | 2 +- .../loadbalancer/ServerListSubsetFilter.java | 22 +++++--------- .../loadbalancer/BestAvailableRuleTest.java | 5 ++-- .../netflix/loadbalancer/MockServerList.java | 4 +-- .../netflix/loadbalancer/PredicatesTest.java | 29 ++++++++----------- .../loadbalancer/SubsetFilterTest.java | 7 +++-- ribbon-test/build.gradle | 3 +- .../test/resources/EmbeddedResources.java | 7 ++--- .../netflix/serialization/JacksonCodec.java | 4 +-- .../serialization/StringDeserializer.java | 4 +-- ribbon-transport/build.gradle | 1 - .../transport/netty/http/NettyClientTest.java | 5 ++-- .../netty/http/ServerListRefreshTest.java | 7 +++-- ribbon/build.gradle | 1 - 32 files changed, 101 insertions(+), 122 deletions(-) diff --git a/gradle.properties b/gradle.properties index c4acbb672..44dcf7660 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,6 @@ rx_java_version=1.0.9 rx_netty_version=0.4.9 servo_version=0.10.1 hystrix_version=1.4.3 -guava_version=19.0 archaius_version=0.7.6 eureka_version=1.7.2 jersey_version=1.19.1 diff --git a/ribbon-archaius/build.gradle b/ribbon-archaius/build.gradle index 519148905..f161e8699 100644 --- a/ribbon-archaius/build.gradle +++ b/ribbon-archaius/build.gradle @@ -1,7 +1,6 @@ dependencies { api "org.slf4j:slf4j-api:${slf4j_version}" api 'com.google.code.findbugs:annotations:2.0.0' - api "com.google.guava:guava:${guava_version}" api 'commons-configuration:commons-configuration:1.8' api 'commons-lang:commons-lang:2.6' api "com.netflix.archaius:archaius-core:${archaius_version}" diff --git a/ribbon-core/build.gradle b/ribbon-core/build.gradle index ab5b7c1af..a79c770c4 100644 --- a/ribbon-core/build.gradle +++ b/ribbon-core/build.gradle @@ -1,7 +1,6 @@ dependencies { api "org.slf4j:slf4j-api:${slf4j_version}" api 'com.google.code.findbugs:annotations:2.0.0' - api "com.google.guava:guava:${guava_version}" api 'commons-lang:commons-lang:2.6' testImplementation 'junit:junit:4.11' diff --git a/ribbon-core/src/main/java/com/netflix/client/DefaultLoadBalancerRetryHandler.java b/ribbon-core/src/main/java/com/netflix/client/DefaultLoadBalancerRetryHandler.java index 3b902e3b0..ef0d1d60c 100644 --- a/ribbon-core/src/main/java/com/netflix/client/DefaultLoadBalancerRetryHandler.java +++ b/ribbon-core/src/main/java/com/netflix/client/DefaultLoadBalancerRetryHandler.java @@ -17,13 +17,14 @@ */ package com.netflix.client; -import com.google.common.collect.Lists; import com.netflix.client.config.CommonClientConfigKey; import com.netflix.client.config.IClientConfig; import java.net.ConnectException; import java.net.SocketException; import java.net.SocketTimeoutException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -36,12 +37,12 @@ public class DefaultLoadBalancerRetryHandler implements RetryHandler { @SuppressWarnings("unchecked") - private List> retriable = - Lists.>newArrayList(ConnectException.class, SocketTimeoutException.class); + private List> retriable = + new ArrayList<>(Arrays.asList(ConnectException.class, SocketTimeoutException.class)); @SuppressWarnings("unchecked") private List> circuitRelated = - Lists.>newArrayList(SocketException.class, SocketTimeoutException.class); + new ArrayList<>(Arrays.asList(SocketException.class, SocketTimeoutException.class)); protected final int retrySameServer; protected final int retryNextServer; diff --git a/ribbon-core/src/main/java/com/netflix/client/RequestSpecificRetryHandler.java b/ribbon-core/src/main/java/com/netflix/client/RequestSpecificRetryHandler.java index 8d3fab65e..e1957e937 100644 --- a/ribbon-core/src/main/java/com/netflix/client/RequestSpecificRetryHandler.java +++ b/ribbon-core/src/main/java/com/netflix/client/RequestSpecificRetryHandler.java @@ -1,14 +1,13 @@ package com.netflix.client; -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; import com.netflix.client.config.CommonClientConfigKey; import com.netflix.client.config.IClientConfig; -import javax.annotation.Nullable; +import java.util.Collections; +import java.util.Objects; import java.net.SocketException; import java.util.List; -import java.util.Optional; +import javax.annotation.Nullable; /** * Implementation of RetryHandler created for each request which allows for request @@ -22,15 +21,15 @@ public class RequestSpecificRetryHandler implements RetryHandler { private final boolean okToRetryOnConnectErrors; private final boolean okToRetryOnAllErrors; - protected List> connectionRelated = - Lists.>newArrayList(SocketException.class); + protected List> connectionRelated = + Collections.singletonList(SocketException.class); public RequestSpecificRetryHandler(boolean okToRetryOnConnectErrors, boolean okToRetryOnAllErrors) { this(okToRetryOnConnectErrors, okToRetryOnAllErrors, RetryHandler.DEFAULT, null); } public RequestSpecificRetryHandler(boolean okToRetryOnConnectErrors, boolean okToRetryOnAllErrors, RetryHandler baseRetryHandler, @Nullable IClientConfig requestConfig) { - Preconditions.checkNotNull(baseRetryHandler); + Objects.requireNonNull(baseRetryHandler); this.okToRetryOnConnectErrors = okToRetryOnConnectErrors; this.okToRetryOnAllErrors = okToRetryOnAllErrors; this.fallback = baseRetryHandler; diff --git a/ribbon-core/src/main/java/com/netflix/client/config/CommonClientConfigKey.java b/ribbon-core/src/main/java/com/netflix/client/config/CommonClientConfigKey.java index 6c7bc18fb..c8edf054c 100644 --- a/ribbon-core/src/main/java/com/netflix/client/config/CommonClientConfigKey.java +++ b/ribbon-core/src/main/java/com/netflix/client/config/CommonClientConfigKey.java @@ -17,8 +17,6 @@ */ package com.netflix.client.config; -import com.google.common.reflect.TypeToken; - import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; @@ -28,8 +26,6 @@ import java.util.Set; import java.util.concurrent.TimeUnit; -import static com.google.common.base.Preconditions.checkArgument; - public abstract class CommonClientConfigKey implements IClientConfigKey { public static final String DEFAULT_NAME_SPACE = "ribbon"; @@ -248,20 +244,20 @@ public Class type() { private final String configKey; private final Class type; - private T defaultValue; + private final T defaultValue; - @SuppressWarnings("unchecked") protected CommonClientConfigKey(String configKey) { this(configKey, null); } + @SuppressWarnings("unchecked") protected CommonClientConfigKey(String configKey, T defaultValue) { this.configKey = configKey; Type superclass = getClass().getGenericSuperclass(); - checkArgument(superclass instanceof ParameterizedType, - "%s isn't parameterized", superclass); - Type runtimeType = ((ParameterizedType) superclass).getActualTypeArguments()[0]; - type = (Class) TypeToken.of(runtimeType).getRawType(); + if (!(superclass instanceof ParameterizedType)) { + throw new IllegalArgumentException(superclass + " isn't parameterized"); + } + this.type = (Class) ((ParameterizedType) superclass).getActualTypeArguments()[0]; this.defaultValue = defaultValue; } diff --git a/ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java b/ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java index c712ad85e..278e7def3 100644 --- a/ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java +++ b/ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java @@ -1,6 +1,6 @@ package com.netflix.client.config; -import com.google.common.base.Preconditions; +import java.util.Objects; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -159,7 +159,7 @@ interface ReloadableProperty extends Property { } private synchronized Property getOrCreateProperty(final IClientConfigKey key, final Supplier> valueSupplier, final Supplier defaultSupplier) { - Preconditions.checkNotNull(valueSupplier, "defaultValueSupplier cannot be null"); + Objects.requireNonNull(valueSupplier, "defaultValueSupplier cannot be null"); return (Property)dynamicProperties.computeIfAbsent(key, ignore -> new ReloadableProperty() { private volatile Optional current = Optional.empty(); @@ -355,7 +355,7 @@ protected final void setDefault(IClientConfigKey key) { * Store the default value for key while giving precedence to default values in the property resolver */ protected final void setDefault(IClientConfigKey key, T value) { - Preconditions.checkArgument(key != null, "key cannot be null"); + Objects.requireNonNull(key, "key cannot be null"); value = resolveFromPropertyResolver(key).orElse(value); internalProperties.put(key, Optional.ofNullable(value)); @@ -367,7 +367,7 @@ protected final void setDefault(IClientConfigKey key, T value) { @Override public IClientConfig set(IClientConfigKey key, T value) { - Preconditions.checkArgument(key != null, "key cannot be null"); + Objects.requireNonNull(key, "key cannot be null"); value = resolveValueToType(key, value); if (isDynamic) { @@ -384,7 +384,7 @@ public IClientConfig set(IClientConfigKey key, T value) { @Override @Deprecated public void setProperty(IClientConfigKey key, Object value) { - Preconditions.checkArgument(value != null, "Value may not be null"); + Objects.requireNonNull(value, "Value may not be null"); set(key, value); } diff --git a/ribbon-core/src/main/java/com/netflix/client/ssl/URLSslContextFactory.java b/ribbon-core/src/main/java/com/netflix/client/ssl/URLSslContextFactory.java index f9ead162b..a314da53d 100644 --- a/ribbon-core/src/main/java/com/netflix/client/ssl/URLSslContextFactory.java +++ b/ribbon-core/src/main/java/com/netflix/client/ssl/URLSslContextFactory.java @@ -29,9 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; - /** * Secure socket factory that is used the NIWS code if a non-standard key store or trust store * is specified. @@ -100,8 +97,11 @@ private static KeyStore createKeyStore(final URL storeFile, final String passwor if(storeFile == null){ return null; } - - Preconditions.checkArgument(StringUtils.isNotEmpty(password), "Null keystore should have empty password, defined keystore must have password"); + + if (StringUtils.isEmpty(password)) { + throw new IllegalArgumentException( + "Null keystore should have empty password, defined keystore must have password"); + } KeyStore keyStore = null; @@ -139,13 +139,17 @@ public String toString() { builder.append("ClientSslSocketFactory [trustStoreUrl=").append(trustStoreUrl); if (trustStoreUrl != null) { - builder.append(", trustStorePassword="); - builder.append(Strings.repeat("*", this.getTrustStorePasswordLength())); + builder.append(", trustStorePassword="); + for (int i = 0; i < this.getTrustStorePasswordLength(); i++) { + builder.append("*"); + } } builder.append(", keyStoreUrl=").append(keyStoreUrl); if (keyStoreUrl != null) { builder.append(", keystorePassword = "); - builder.append(Strings.repeat("*", this.getKeyStorePasswordLength())); + for (int i = 0; i < this.getKeyStorePasswordLength(); i++) { + builder.append("*"); + } } builder.append(']'); diff --git a/ribbon-core/src/test/java/com/netflix/client/config/CommonClientConfigKeyTest.java b/ribbon-core/src/test/java/com/netflix/client/config/CommonClientConfigKeyTest.java index 335d0e597..426972d5f 100644 --- a/ribbon-core/src/test/java/com/netflix/client/config/CommonClientConfigKeyTest.java +++ b/ribbon-core/src/test/java/com/netflix/client/config/CommonClientConfigKeyTest.java @@ -2,9 +2,11 @@ import static org.junit.Assert.*; + import org.junit.Test; -import com.google.common.collect.Sets; +import java.util.Arrays; +import java.util.HashSet; public class CommonClientConfigKeyTest { @@ -12,7 +14,7 @@ public class CommonClientConfigKeyTest { public void testCommonKeys() { IClientConfigKey[] keys = CommonClientConfigKey.values(); assertTrue(keys.length > 30); - assertEquals(Sets.newHashSet(keys), CommonClientConfigKey.keys()); + assertEquals(new HashSet<>(Arrays.asList(keys)), CommonClientConfigKey.keys()); assertTrue(CommonClientConfigKey.keys().contains(CommonClientConfigKey.ConnectTimeout)); } } diff --git a/ribbon-examples/build.gradle b/ribbon-examples/build.gradle index e885de9ed..202074c1f 100644 --- a/ribbon-examples/build.gradle +++ b/ribbon-examples/build.gradle @@ -12,7 +12,6 @@ dependencies { api 'org.codehaus.jackson:jackson-mapper-asl:1.9.11' api 'com.thoughtworks.xstream:xstream:1.4.5' api "com.sun.jersey:jersey-server:${jersey_version}" - api "com.google.guava:guava:${guava_version}" api "com.netflix.archaius:archaius-core:${archaius_version}" testImplementation 'junit:junit:4.11' } diff --git a/ribbon-examples/src/main/java/com/netflix/ribbon/examples/server/ServerResources.java b/ribbon-examples/src/main/java/com/netflix/ribbon/examples/server/ServerResources.java index 2ca21c406..bb18a71b2 100644 --- a/ribbon-examples/src/main/java/com/netflix/ribbon/examples/server/ServerResources.java +++ b/ribbon-examples/src/main/java/com/netflix/ribbon/examples/server/ServerResources.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; import java.util.List; import javax.ws.rs.Consumes; @@ -34,7 +35,6 @@ import org.codehaus.jackson.map.ObjectMapper; -import com.google.common.collect.Lists; import com.thoughtworks.xstream.XStream; @Path("/testAsync") @@ -89,9 +89,9 @@ public boolean equals(Object obj) { private static ObjectMapper mapper = new ObjectMapper(); public static final Person defaultPerson = new Person("ribbon", 1); - public static final List persons = Lists.newArrayList(); + public static final List persons = new ArrayList<>(); - public static final List streamContent = Lists.newArrayList(); + public static final List streamContent = new ArrayList<>(); static { for (int i = 0; i < 1000; i++) { diff --git a/ribbon-httpclient/build.gradle b/ribbon-httpclient/build.gradle index f595022e5..046aaa646 100644 --- a/ribbon-httpclient/build.gradle +++ b/ribbon-httpclient/build.gradle @@ -8,7 +8,6 @@ dependencies { api "com.sun.jersey.contribs:jersey-apache-client4:${jersey_version}" api "org.slf4j:slf4j-api:${slf4j_version}" api "com.netflix.servo:servo-core:${servo_version}" - api "com.google.guava:guava:${guava_version}" api 'com.netflix.netflix-commons:netflix-commons-util:0.1.1' testImplementation 'junit:junit:4.11' testImplementation "org.slf4j:slf4j-log4j12:${slf4j_version}" diff --git a/ribbon-httpclient/src/main/java/com/netflix/client/http/CaseInsensitiveMultiMap.java b/ribbon-httpclient/src/main/java/com/netflix/client/http/CaseInsensitiveMultiMap.java index 4d933504e..7be86e2a1 100644 --- a/ribbon-httpclient/src/main/java/com/netflix/client/http/CaseInsensitiveMultiMap.java +++ b/ribbon-httpclient/src/main/java/com/netflix/client/http/CaseInsensitiveMultiMap.java @@ -8,7 +8,6 @@ import java.util.AbstractMap.SimpleEntry; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; public class CaseInsensitiveMultiMap implements HttpHeaders { @@ -26,7 +25,7 @@ public String getFirstValue(String headerName) { @Override public List getAllValues(String headerName) { Collection> entries = map.get(headerName.toLowerCase()); - List values = Lists.newArrayList(); + List values = new ArrayList<>(); if (entries != null) { for (Entry entry: entries) { values.add(entry.getValue()); diff --git a/ribbon-httpclient/src/main/java/com/netflix/niws/client/http/HttpClientResponse.java b/ribbon-httpclient/src/main/java/com/netflix/niws/client/http/HttpClientResponse.java index f0c8cd228..3aef839ff 100644 --- a/ribbon-httpclient/src/main/java/com/netflix/niws/client/http/HttpClientResponse.java +++ b/ribbon-httpclient/src/main/java/com/netflix/niws/client/http/HttpClientResponse.java @@ -18,7 +18,6 @@ package com.netflix.niws.client.http; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.reflect.TypeToken; import com.netflix.client.ClientException; @@ -28,15 +27,12 @@ import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.GenericType; +import java.util.Map.Entry; import javax.ws.rs.core.MultivaluedMap; import java.io.InputStream; import java.lang.reflect.Type; import java.net.URI; -import java.util.AbstractMap; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; +import java.util.*; /** * A NIWS Client Response @@ -74,7 +70,7 @@ public List getAllValues(String headerName) { @Override public List> getAllHeaders() { MultivaluedMap map = bcr.getHeaders(); - List> result = Lists.newArrayList(); + List> result = new ArrayList<>(); for (Map.Entry> header: map.entrySet()) { String name = header.getKey(); for (String value: header.getValue()) { diff --git a/ribbon-loadbalancer/build.gradle b/ribbon-loadbalancer/build.gradle index ad7cbd275..4da381ef1 100644 --- a/ribbon-loadbalancer/build.gradle +++ b/ribbon-loadbalancer/build.gradle @@ -4,8 +4,8 @@ dependencies { api "io.reactivex:rxjava:${rx_java_version}" api "org.slf4j:slf4j-api:${slf4j_version}" api "com.netflix.servo:servo-core:${servo_version}" - api "com.google.guava:guava:${guava_version}" api 'com.netflix.netflix-commons:netflix-commons-util:0.1.1' + api "com.google.guava:guava:32.1.3-jre" testImplementation project(":ribbon-archaius") testImplementation 'junit:junit:4.11' diff --git a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java index 03dde8b05..4ea21553c 100644 --- a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java +++ b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java @@ -17,17 +17,17 @@ */ package com.netflix.loadbalancer; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nullable; -import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.netflix.client.config.IClientConfig; /** @@ -133,7 +133,7 @@ public List getEligibleServers(List servers, Object loadBalancer if (loadBalancerKey == null) { return ImmutableList.copyOf(Iterables.filter(servers, this.getServerOnlyPredicate())); } else { - List results = Lists.newArrayList(); + List results = new ArrayList<>(); for (Server server: servers) { if (this.apply(new PredicateKey(loadBalancerKey, server))) { results.add(server); @@ -167,7 +167,7 @@ private int incrementAndGetModulo(int modulo) { public Optional chooseRandomlyAfterFiltering(List servers) { List eligible = getEligibleServers(servers); if (eligible.size() == 0) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(eligible.get(random.nextInt(eligible.size()))); } @@ -179,7 +179,7 @@ public Optional chooseRandomlyAfterFiltering(List servers) { public Optional chooseRoundRobinAfterFiltering(List servers) { List eligible = getEligibleServers(servers); if (eligible.size() == 0) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(eligible.get(incrementAndGetModulo(eligible.size()))); } @@ -192,7 +192,7 @@ public Optional chooseRoundRobinAfterFiltering(List servers) { public Optional chooseRandomlyAfterFiltering(List servers, Object loadBalancerKey) { List eligible = getEligibleServers(servers, loadBalancerKey); if (eligible.size() == 0) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(eligible.get(random.nextInt(eligible.size()))); } @@ -203,7 +203,7 @@ public Optional chooseRandomlyAfterFiltering(List servers, Objec public Optional chooseRoundRobinAfterFiltering(List servers, Object loadBalancerKey) { List eligible = getEligibleServers(servers, loadBalancerKey); if (eligible.size() == 0) { - return Optional.absent(); + return Optional.empty(); } return Optional.of(eligible.get(incrementAndGetModulo(eligible.size()))); } diff --git a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/CompositePredicate.java b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/CompositePredicate.java index 1fc527b41..5af33e4f7 100644 --- a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/CompositePredicate.java +++ b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/CompositePredicate.java @@ -18,6 +18,7 @@ */ package com.netflix.loadbalancer; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -25,7 +26,6 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import com.google.common.collect.Lists; /** * A predicate that is composed from one or more predicates in "AND" relationship. @@ -41,7 +41,7 @@ public class CompositePredicate extends AbstractServerPredicate { private AbstractServerPredicate delegate; - private List fallbacks = Lists.newArrayList(); + private List fallbacks = new ArrayList<>(); private int minimalFilteredServers = 1; diff --git a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/ConfigurationBasedServerList.java b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/ConfigurationBasedServerList.java index 770269e8a..fc7f97379 100644 --- a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/ConfigurationBasedServerList.java +++ b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/ConfigurationBasedServerList.java @@ -17,10 +17,10 @@ */ package com.netflix.loadbalancer; +import java.util.ArrayList; import java.util.List; import com.google.common.base.Strings; -import com.google.common.collect.Lists; import com.netflix.client.config.CommonClientConfigKey; import com.netflix.client.config.IClientConfig; @@ -56,7 +56,7 @@ public void initWithNiwsConfig(IClientConfig clientConfig) { } protected List derive(String value) { - List list = Lists.newArrayList(); + List list = new ArrayList<>(); if (!Strings.isNullOrEmpty(value)) { for (String s: value.split(",")) { list.add(new Server(s.trim())); diff --git a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/PredicateBasedRule.java b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/PredicateBasedRule.java index feaddacb4..dfd70d5f1 100644 --- a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/PredicateBasedRule.java +++ b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/PredicateBasedRule.java @@ -17,7 +17,7 @@ */ package com.netflix.loadbalancer; -import com.google.common.base.Optional; +import java.util.Optional; /** * A rule which delegates the server filtering logic to an instance of {@link AbstractServerPredicate}. diff --git a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/ServerListSubsetFilter.java b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/ServerListSubsetFilter.java index 56c4d1a74..de501348b 100644 --- a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/ServerListSubsetFilter.java +++ b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/ServerListSubsetFilter.java @@ -15,19 +15,13 @@ */ package com.netflix.loadbalancer; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.netflix.client.IClientConfigAware; import com.netflix.client.config.CommonClientConfigKey; import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfigKey; import com.netflix.client.config.Property; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Random; -import java.util.Set; +import java.util.*; /** * A server list filter that limits the number of the servers used by the load balancer to be the subset of all servers. @@ -42,7 +36,7 @@ public class ServerListSubsetFilter extends ZoneAffinityServerListFilter implements IClientConfigAware, Comparator{ private Random random = new Random(); - private volatile Set currentSubset = Sets.newHashSet(); + private volatile Set currentSubset = new HashSet<>(); private Property sizeProp; private Property eliminationPercent; private Property eliminationFailureCountThreshold; @@ -101,8 +95,8 @@ public void initWithNiwsConfig(IClientConfig clientConfig) { @Override public List getFilteredListOfServers(List servers) { List zoneAffinityFiltered = super.getFilteredListOfServers(servers); - Set candidates = Sets.newHashSet(zoneAffinityFiltered); - Set newSubSet = Sets.newHashSet(currentSubset); + Set candidates = new HashSet<>(zoneAffinityFiltered); + Set newSubSet = new HashSet<>(currentSubset); LoadBalancerStats lbStats = getLoadBalancerStats(); for (T server: currentSubset) { // this server is either down or out of service @@ -135,7 +129,7 @@ public List getFilteredListOfServers(List servers) { } if (numToForceEliminate > 0) { - List sortedSubSet = Lists.newArrayList(newSubSet); + List sortedSubSet = new ArrayList<>(newSubSet); Collections.sort(sortedSubSet, this); List forceEliminated = sortedSubSet.subList(0, numToForceEliminate); newSubSet.removeAll(forceEliminated); @@ -151,16 +145,16 @@ public List getFilteredListOfServers(List servers) { if (numToChoose > candidates.size()) { // Not enough healthy instances to choose, fallback to use the // total server pool - candidates = Sets.newHashSet(zoneAffinityFiltered); + candidates = new HashSet<>(zoneAffinityFiltered); candidates.removeAll(newSubSet); } - List chosen = randomChoose(Lists.newArrayList(candidates), numToChoose); + List chosen = randomChoose(new ArrayList<>(candidates), numToChoose); for (T server: chosen) { newSubSet.add(server); } } currentSubset = newSubSet; - return Lists.newArrayList(newSubSet); + return new ArrayList<>(newSubSet); } /** diff --git a/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/BestAvailableRuleTest.java b/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/BestAvailableRuleTest.java index 0599fcca8..58860053b 100644 --- a/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/BestAvailableRuleTest.java +++ b/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/BestAvailableRuleTest.java @@ -20,17 +20,16 @@ import static org.junit.Assert.*; +import java.util.ArrayList; import java.util.List; import org.junit.Test; -import com.google.common.collect.Lists; - public class BestAvailableRuleTest { @Test public void testRule() { - List servers = Lists.newArrayList(); + List servers = new ArrayList<>(); for (int i = 0; i < 10; i++) { servers.add(new Server(String.valueOf(i), 80)); } diff --git a/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/MockServerList.java b/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/MockServerList.java index 8f76b5ff9..7e3f2e9da 100644 --- a/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/MockServerList.java +++ b/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/MockServerList.java @@ -1,13 +1,13 @@ package com.netflix.loadbalancer; +import java.util.ArrayList; import java.util.List; -import com.google.common.collect.Lists; import com.netflix.client.config.IClientConfig; public class MockServerList extends AbstractServerList { - private List serverList = Lists.newArrayList(); + private List serverList = new ArrayList<>(); public void setServerList(List serverList) { this.serverList = serverList; diff --git a/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/PredicatesTest.java b/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/PredicatesTest.java index 027e9e00d..87f6ae65f 100644 --- a/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/PredicatesTest.java +++ b/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/PredicatesTest.java @@ -19,17 +19,12 @@ import static org.junit.Assert.*; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import org.junit.AfterClass; import org.junit.Test; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.netflix.config.ConfigurationManager; import com.netflix.config.DeploymentContext.ContextKey; @@ -66,7 +61,7 @@ public void setServerStats(LoadBalancerStats lbStats, Object[][] stats) { @Test public void testAvalabilityPredicate() { Object[][] stats = new Object[10][3]; - List expectedFiltered = Lists.newArrayList(); + List expectedFiltered = new ArrayList<>(); for (int i = 0; i < 7; i++) { stats[i] = new Object[3]; stats[i][0] = new Server("good:" + i); @@ -85,13 +80,13 @@ public void testAvalabilityPredicate() { AvailabilityPredicate predicate = new AvailabilityPredicate(lbStats, null); assertFalse(predicate.apply(new PredicateKey((Server) stats[8][0]))); assertTrue(predicate.apply(new PredicateKey((Server) stats[0][0]))); - List servers = Lists.newArrayList(); + List servers = new ArrayList<>(); for (int i = 0; i < 10; i++) { servers.add((Server) stats[i][0]); } List filtered = predicate.getEligibleServers(servers); assertEquals(expectedFiltered, filtered); - Set chosen = Sets.newHashSet(); + Set chosen = new HashSet<>(); for (int i = 0; i < 20; i++) { Server s = predicate.chooseRoundRobinAfterFiltering(servers).get(); assertEquals("good:" + (i % 7), s.getId()); @@ -128,8 +123,8 @@ public void testAvalabilityPredicateAfterFailure() { public void testZoneAvoidancePredicate() { Object[][] stats = new Object[10][3]; Map> zoneMap = Maps.newHashMap(); - List expectedFiltered = Lists.newArrayList(); - List list0 = Lists.newArrayList(); + List expectedFiltered = new ArrayList<>(); + List list0 = new ArrayList<>(); for (int i = 0; i < 3; i++) { stats[i] = new Object[3]; stats[i][0] = new Server("good:" + i); @@ -140,7 +135,7 @@ public void testZoneAvoidancePredicate() { expectedFiltered.add((Server) stats[i][0]); } zoneMap.put("0", list0); - List list1 = Lists.newArrayList(); + List list1 = new ArrayList<>(); for (int i = 3; i < 7; i++) { stats[i] = new Object[3]; stats[i][0] = new Server("bad:" + i); @@ -150,7 +145,7 @@ public void testZoneAvoidancePredicate() { stats[i][2] = 2; } zoneMap.put("1", list1); - List list2 = Lists.newArrayList(); + List list2 = new ArrayList<>(); for (int i = 7; i < 10; i++) { stats[i] = new Object[3]; stats[i][0] = new Server("good:" + i); @@ -175,7 +170,7 @@ public void testCompositePredicate() { Object[][] stats = new Object[10][3]; Map> zoneMap = Maps.newHashMap(); - List expectedFiltered = Lists.newArrayList(); + List expectedFiltered = new ArrayList<>(); for (int i = 0; i < 3; i++) { stats[i] = new Object[3]; stats[i][0] = new Server("good:" + i); @@ -184,7 +179,7 @@ public void testCompositePredicate() { stats[i][2] = 0; expectedFiltered.add((Server) stats[i][0]); } - List list1 = Lists.newArrayList(); + List list1 = new ArrayList<>(); for (int i = 3; i < 7; i++) { stats[i] = new Object[3]; stats[i][0] = new Server("bad:" + i); @@ -194,7 +189,7 @@ public void testCompositePredicate() { stats[i][2] = 0; } zoneMap.put("1", list1); - List list2 = Lists.newArrayList(); + List list2 = new ArrayList<>(); for (int i = 7; i < 10; i++) { stats[i] = new Object[3]; stats[i][0] = new Server("good:" + i); @@ -214,7 +209,7 @@ public void testCompositePredicate() { assertFalse(c.apply(new PredicateKey((Server) stats[5][0]))); assertTrue(c.apply(new PredicateKey((Server) stats[0][0]))); assertFalse(c.apply(new PredicateKey((Server) stats[9][0]))); - List servers = Lists.newArrayList(); + List servers = new ArrayList<>(); for (int i = 0; i < 10; i++) { servers.add((Server) stats[i][0]); } diff --git a/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/SubsetFilterTest.java b/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/SubsetFilterTest.java index 9524e513c..250937989 100644 --- a/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/SubsetFilterTest.java +++ b/ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/SubsetFilterTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -50,7 +51,7 @@ public static void init() { } List getServersAndStats(LoadBalancerStats lbStats, Object[][] stats) { - List list = Lists.newArrayList(); + List list = new ArrayList<>(); for (Object[] serverStats: stats) { Server server = new Server((String) serverStats[0]); list.add(server); @@ -140,7 +141,7 @@ public void testFiltering() { assertTrue(filtered.contains(s5)); // Not enough healthy servers, just get whatever is available - List lastFiltered = filter.getFilteredListOfServers(Lists.newArrayList(filtered)); + List lastFiltered = filter.getFilteredListOfServers(new ArrayList<>(filtered)); assertEquals(5, lastFiltered.size()); } @@ -207,7 +208,7 @@ public void testWithLoadBalancer() { assertTrue(filtered.contains(s5)); // Not enough healthy servers, just get whatever is available - serverList.setServerList(Lists.newArrayList(filtered)); + serverList.setServerList(new ArrayList<>(filtered)); lb.updateListOfServers(); List lastFiltered = lb.getAllServers(); assertEquals(5, lastFiltered.size()); diff --git a/ribbon-test/build.gradle b/ribbon-test/build.gradle index 12a8405ce..3f8bb5682 100644 --- a/ribbon-test/build.gradle +++ b/ribbon-test/build.gradle @@ -5,8 +5,7 @@ dependencies { api 'org.codehaus.jackson:jackson-mapper-asl:1.9.11' api "com.netflix.eureka:eureka-client:${eureka_version}" api "io.reactivex:rxjava:${rx_java_version}" - api 'javax.ws.rs:jsr311-api:1.1.1' - api "com.google.guava:guava:${guava_version}" + api 'javax.ws.rs:jsr311-api:1.1.1' api "junit:junit:${junit_version}" api "org.powermock:powermock-easymock-release-full:${powermock_version}" api "org.easymock:easymock:${easymock_version}" diff --git a/ribbon-test/src/main/java/com/netflix/ribbon/test/resources/EmbeddedResources.java b/ribbon-test/src/main/java/com/netflix/ribbon/test/resources/EmbeddedResources.java index df2517ee4..bea568016 100644 --- a/ribbon-test/src/main/java/com/netflix/ribbon/test/resources/EmbeddedResources.java +++ b/ribbon-test/src/main/java/com/netflix/ribbon/test/resources/EmbeddedResources.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; import java.util.List; import javax.ws.rs.Consumes; @@ -37,8 +38,6 @@ import org.codehaus.jackson.map.ObjectMapper; import org.junit.Ignore; -import com.google.common.collect.Lists; - @Ignore @Path("/testAsync") @Consumes(MediaType.APPLICATION_JSON) @@ -89,8 +88,8 @@ public boolean equals(Object obj) { private static ObjectMapper mapper = new ObjectMapper(); public static final Person defaultPerson = new Person("ribbon", 1); - public static final List streamContent = Lists.newArrayList(); - public static final List entityStream = Lists.newArrayList(); + public static final List streamContent = new ArrayList<>(); + public static final List entityStream = new ArrayList<>(); static { for (int i = 0; i < 1000; i++) { diff --git a/ribbon-test/src/main/java/com/netflix/serialization/JacksonCodec.java b/ribbon-test/src/main/java/com/netflix/serialization/JacksonCodec.java index 947beee59..2af7b2ac4 100644 --- a/ribbon-test/src/main/java/com/netflix/serialization/JacksonCodec.java +++ b/ribbon-test/src/main/java/com/netflix/serialization/JacksonCodec.java @@ -5,12 +5,12 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectWriter; import org.codehaus.jackson.type.TypeReference; -import com.google.common.base.Charsets; import com.google.common.io.CharStreams; public class JacksonCodec implements Serializer, Deserializer { @@ -23,7 +23,7 @@ public class JacksonCodec implements Serializer, Deserializ public T deserialize(InputStream in, TypeDef type) throws IOException { if (String.class.equals(type.getRawType())) { - return (T) CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8)); + return (T) CharStreams.toString(new InputStreamReader(in, StandardCharsets.UTF_8)); } return mapper.readValue(in, new TypeTokenBasedReference(type)); } diff --git a/ribbon-test/src/main/java/com/netflix/serialization/StringDeserializer.java b/ribbon-test/src/main/java/com/netflix/serialization/StringDeserializer.java index 47c63ce05..6a7c9c23d 100644 --- a/ribbon-test/src/main/java/com/netflix/serialization/StringDeserializer.java +++ b/ribbon-test/src/main/java/com/netflix/serialization/StringDeserializer.java @@ -3,8 +3,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; -import com.google.common.base.Charsets; import com.google.common.io.CharStreams; import com.google.common.io.Closeables; @@ -23,7 +23,7 @@ public static final StringDeserializer getInstance() { public String deserialize(InputStream in, TypeDef type) throws IOException { try { - String content = CharStreams.toString(new InputStreamReader(in, Charsets.UTF_8)); + String content = CharStreams.toString(new InputStreamReader(in, StandardCharsets.UTF_8)); return content; } finally { Closeables.close(in, true); diff --git a/ribbon-transport/build.gradle b/ribbon-transport/build.gradle index 934ca609e..5e1cd2f0f 100644 --- a/ribbon-transport/build.gradle +++ b/ribbon-transport/build.gradle @@ -9,7 +9,6 @@ dependencies { api "io.netty:netty-codec-http:4.0.27.Final" api 'javax.inject:javax.inject:1' api "org.slf4j:slf4j-api:${slf4j_version}" - api "com.google.guava:guava:${guava_version}" testImplementation 'junit:junit:4.11' testImplementation "org.slf4j:slf4j-log4j12:${slf4j_version}" testImplementation "com.sun.jersey:jersey-server:${jersey_version}" diff --git a/ribbon-transport/src/test/java/com/netflix/ribbon/transport/netty/http/NettyClientTest.java b/ribbon-transport/src/test/java/com/netflix/ribbon/transport/netty/http/NettyClientTest.java index b1d1dbbca..7630825be 100644 --- a/ribbon-transport/src/test/java/com/netflix/ribbon/transport/netty/http/NettyClientTest.java +++ b/ribbon-transport/src/test/java/com/netflix/ribbon/transport/netty/http/NettyClientTest.java @@ -38,6 +38,7 @@ import java.io.IOException; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Random; @@ -631,7 +632,7 @@ private static List getPersonListFromResponse(Observable getPersonList(Observable events) { - List result = Lists.newArrayList(); + List result = new ArrayList<>(); Iterator iterator = events.map(new Func1() { @Override public Person call(ServerSentEvent t1) { @@ -671,7 +672,7 @@ public void testStreamWithLoadBalancer() throws Exception { BaseLoadBalancer lb = new BaseLoadBalancer(new DummyPing(), new AvailabilityFilteringRule()); LoadBalancingHttpClient lbObservables = (LoadBalancingHttpClient) RibbonTransport.newSSEClient(lb, config); HttpClientRequest request = HttpClientRequest.createGet("/testAsync/personStream"); - List result = Lists.newArrayList(); + List result = new ArrayList<>(); Server goodServer = new Server("localhost:" + port); Server badServer = new Server("localhost:12245"); List servers = Lists.newArrayList(badServer, badServer, badServer, goodServer); diff --git a/ribbon-transport/src/test/java/com/netflix/ribbon/transport/netty/http/ServerListRefreshTest.java b/ribbon-transport/src/test/java/com/netflix/ribbon/transport/netty/http/ServerListRefreshTest.java index 422a2dbd9..3560db363 100644 --- a/ribbon-transport/src/test/java/com/netflix/ribbon/transport/netty/http/ServerListRefreshTest.java +++ b/ribbon-transport/src/test/java/com/netflix/ribbon/transport/netty/http/ServerListRefreshTest.java @@ -18,7 +18,6 @@ package com.netflix.ribbon.transport.netty.http; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.google.mockwebserver.MockResponse; import com.google.mockwebserver.MockWebServer; import com.netflix.ribbon.transport.netty.RibbonTransport; @@ -29,6 +28,8 @@ import org.junit.Test; import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -71,11 +72,11 @@ public void testServerListRefresh() throws IOException { HttpClientRequest request2 = HttpClientRequest.createGet("http://localhost:" + server3.getPort()); client.submit(request2).toBlocking().last(); Set cachedServers = client.getRxClients().keySet(); - assertEquals(Sets.newHashSet(new Server("localhost", server1.getPort()), new Server("localhost", server2.getPort()), new Server("localhost", server3.getPort())), cachedServers); + assertEquals(new HashSet<>(Arrays.asList(new Server("localhost", server1.getPort()), new Server("localhost", server2.getPort()), new Server("localhost", server3.getPort()))), cachedServers); List newList = Lists.newArrayList(new Server("localhost", server1.getPort()), new Server("localhost", 99999)); lb.setServersList(newList); cachedServers = client.getRxClients().keySet(); - assertEquals(Sets.newHashSet(new Server("localhost", server1.getPort()), new Server("localhost", server3.getPort())), cachedServers); + assertEquals(new HashSet<>(Arrays.asList(new Server("localhost", server1.getPort()), new Server("localhost", server3.getPort()))), cachedServers); } finally { server1.shutdown(); server2.shutdown(); diff --git a/ribbon/build.gradle b/ribbon/build.gradle index ab0673633..cea7368dc 100644 --- a/ribbon/build.gradle +++ b/ribbon/build.gradle @@ -16,7 +16,6 @@ dependencies { api "io.reactivex:rxjava:${rx_java_version}" api "io.reactivex:rxnetty:${rx_netty_version}" api 'commons-configuration:commons-configuration:1.8' - api "com.google.guava:guava:${guava_version}" api "com.netflix.archaius:archaius-core:${archaius_version}" testImplementation "junit:junit:${junit_version}" testImplementation "org.powermock:powermock-easymock-release-full:${powermock_version}"