Skip to content

Commit

Permalink
SI-8116 Signifcantly reduce the dependency on Guava. Only data-avro a…
Browse files Browse the repository at this point in the history
…nd restli-int-test subproject now depend on Guava.

RB=1396146
BUG=SI-8116
R=kbalasub,ajing,aponniah,xma,mlamure,mapatel
A=kbalasub,aponniah,xma
  • Loading branch information
Baron Roberts committed Aug 20, 2018
1 parent 0ac6da1 commit 5404831
Show file tree
Hide file tree
Showing 23 changed files with 76 additions and 80 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
@@ -1,7 +1,12 @@
23.0.16
-------

23.0.15
-------
(RB=1394375)
Populate internal DataMap for gathered batch response.
(RB=1396146)
Remove Guava dependency from compile in all modules except data-avro and restli-int-test

(RB=1396585)
Updated gradle wrapper to version 4.6.
Expand Down
20 changes: 15 additions & 5 deletions build.gradle
Expand Up @@ -147,8 +147,7 @@ subprojects {
apply plugin: 'eclipse'

afterEvaluate {
if (project.plugins.hasPlugin('pegasus'))
{
if (project.plugins.hasPlugin('pegasus')) {
configurations {
pluginsRuntime {
visible = false
Expand All @@ -165,9 +164,7 @@ subprojects {
pegasusPlugin project(':generator')
pegasusPlugin project(':restli-tools')
}
}
else
{
} else {
apply from: "${buildScriptDirPath}/cleanGenerated.gradle", to: it
}
}
Expand All @@ -191,6 +188,19 @@ subprojects {
configurations.testArtifacts.visible = true
}

if (!(it.name in ['data-avro', 'restli-int-test'])) {
configurations {
// Prevent Guava from creeping in to avoid incompatibilities in multiple classloader environments.
compile.resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.google.guava' && details.requested.name == 'guava') {
throw new GradleException('Cannot directly or transitively depend on Guava.')
}
}
}
}
}

// Default dependencies for all subprojects
dependencies {
compile externalDependency.slf4jApi
Expand Down
Expand Up @@ -16,7 +16,6 @@

package com.linkedin.d2.balancer.clients;

import com.google.common.annotations.VisibleForTesting;
import com.linkedin.common.callback.Callback;
import com.linkedin.common.util.None;
import com.linkedin.d2.balancer.util.URIRewriter;
Expand Down Expand Up @@ -90,7 +89,6 @@ public void shutdown(Callback<None> callback)
_transportClient.shutdown(callback);
}

@VisibleForTesting
public TransportClient getDecoratedClient()
{
return _transportClient;
Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.linkedin.d2.balancer.clients;


import com.google.common.annotations.VisibleForTesting;
import com.linkedin.common.callback.Callback;
import com.linkedin.common.util.None;
import com.linkedin.d2.balancer.LoadBalancerClient;
Expand Down Expand Up @@ -87,7 +86,6 @@ public TransportClient getWrappedClient()
return _client;
}

@VisibleForTesting
public TransportClient getDecoratedClient()
{
return _client;
Expand Down
Expand Up @@ -16,7 +16,6 @@

package com.linkedin.d2.balancer.simple;

import com.google.common.annotations.VisibleForTesting;
import com.linkedin.common.callback.Callback;
import com.linkedin.common.callback.Callbacks;
import com.linkedin.common.callback.FutureCallback;
Expand Down Expand Up @@ -94,7 +93,6 @@ public class SimpleLoadBalancer implements LoadBalancer, HashRingProvider, Clien
private final ScheduledExecutorService _executor;
private final Random _random = new Random();

@VisibleForTesting
public SimpleLoadBalancer(LoadBalancerState state, ScheduledExecutorService executorService)
{
this(state, new Stats(1000), new Stats(1000), 0, TimeUnit.SECONDS, executorService);
Expand Down
1 change: 1 addition & 0 deletions data-avro/build.gradle
Expand Up @@ -5,6 +5,7 @@

dependencies {
compile project(':data')
compile externalDependency.guava
compile externalDependency.jacksonCoreAsl_1_4
compile externalDependency.avro
testCompile externalDependency.testng
Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.linkedin.data.avro;


import com.google.common.collect.Maps;
import com.linkedin.data.Data;
import com.linkedin.data.DataMap;
import com.linkedin.data.schema.DataSchema;
Expand Down Expand Up @@ -384,7 +383,10 @@ protected void encodeFieldOptional(RecordDataSchema.Field field) throws IOExcept
@Override
protected void encodeFieldProperties(RecordDataSchema.Field field) throws IOException
{
_builder.writeProperties(Maps.filterKeys(field.getProperties(), property -> !RESERVED_DATA_PROPERTIES.contains(property)));
final Map<String, ?> filteredMap = field.getProperties().entrySet().stream()
.filter(entry -> !RESERVED_DATA_PROPERTIES.contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
_builder.writeProperties(filteredMap);
}

/**
Expand Down
Expand Up @@ -16,7 +16,6 @@

package com.linkedin.data.avro;

import com.google.common.collect.ImmutableList;
import com.linkedin.data.DataMap;
import com.linkedin.data.TestUtil;
import com.linkedin.data.avro.util.AvroUtil;
Expand All @@ -31,6 +30,8 @@
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -1223,24 +1224,16 @@ public Object[][] arrayFieldProvider() {
null
},
{
ImmutableList.of()
Collections.emptyList()
},
{
ImmutableList.of("foo", "bar", "baz")
Collections.unmodifiableList(Arrays.asList("foo", "bar", "baz"))
},
{
getList(() -> {
ArrayList<String> list = new ArrayList<>();
list.addAll(ImmutableList.of("foo", "bar"));
return list;
})
getList(() -> new ArrayList<>(Arrays.asList("foo", "bar")))
},
{
getList(() -> {
LinkedList<String> list = new LinkedList<>();
list.addAll(ImmutableList.of("foo", "bar"));
return list;
})
getList(() -> new LinkedList<>(Arrays.asList("foo", "bar")))
},
{
getList(() -> {
Expand Down
1 change: 0 additions & 1 deletion data/build.gradle
Expand Up @@ -4,7 +4,6 @@ dependencies {
compile project(':entity-stream')
compile externalDependency.antlrRuntime
compile externalDependency.commonsLang3
compile externalDependency.guava
compile externalDependency.jacksonCore

testCompile project(':data-testutils')
Expand Down
Expand Up @@ -16,20 +16,6 @@

package com.linkedin.data.schema.validator;


import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import com.linkedin.data.DataMap;
import com.linkedin.data.element.DataElement;
import com.linkedin.data.message.Message;
Expand All @@ -40,6 +26,17 @@
import com.linkedin.data.schema.NamedDataSchema;
import com.linkedin.data.schema.RecordDataSchema;
import com.linkedin.data.schema.TyperefDataSchema;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentHashMap;


/**
Expand Down Expand Up @@ -197,8 +194,7 @@ public int compare(ValidatorInfo v1, ValidatorInfo v2)
}
};

private static final Cache<String, Class<? extends Validator>> VALIDATOR_CLASS_CACHE =
CacheBuilder.newBuilder().maximumSize(500).build();
private static final Map<String, Class<? extends Validator>> VALIDATOR_CLASS_CACHE = new ConcurrentHashMap<>();

// No-op {@link Validator} implementation to denote a negative cache value in {@link #VALIDATOR_CLASS_CACHE}
private static final Validator NULL_VALIDATOR = (context) -> {};
Expand Down Expand Up @@ -474,7 +470,7 @@ protected Class<? extends Validator> locateValidatorClass(String key, List<Strin
}

// If we have already seen this key before, use the cached Validator class
clazz = VALIDATOR_CLASS_CACHE.getIfPresent(key);
clazz = VALIDATOR_CLASS_CACHE.get(key);
if (clazz != null)
{
return (NULL_VALIDATOR.getClass().equals(clazz) ? null : clazz);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,4 +1,4 @@
version=23.0.14
version=23.0.15
sonatypeUsername=please_set_in_home_dir_if_uploading_to_maven_central
sonatypePassword=please_set_in_home_dir_if_uploading_to_maven_central
org.gradle.configureondemand=true
Expand Down
1 change: 0 additions & 1 deletion multipart-mime/build.gradle
Expand Up @@ -7,5 +7,4 @@ dependencies {
testCompile externalDependency.mail
testCompile externalDependency.easymock
testCompile externalDependency.mockito
testCompile externalDependency.guava
}
Expand Up @@ -23,15 +23,14 @@
import com.linkedin.r2.message.stream.StreamRequest;
import com.linkedin.r2.message.stream.entitystream.FullEntityReader;

import com.google.common.collect.ImmutableList;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
Expand Down Expand Up @@ -259,7 +258,8 @@ public Object[][] prependDataSources() throws Exception
Collections.<String, String>emptyMap()).build();

final List<MultiPartMIMEDataSourceWriter> withPreambleDataSourceWriterList =
ImmutableList.of(purelyEmptyBodyWriterPreamble, headerLessBodyWriterPreamble, normalWriterPreamble);
Collections.unmodifiableList(Arrays.asList(purelyEmptyBodyWriterPreamble, headerLessBodyWriterPreamble,
normalWriterPreamble));

final MultiPartMIMEWriter.Builder multiPartMIMEWriterWithPreamble = new MultiPartMIMEWriter.Builder("preamble", "epilogue");

Expand All @@ -277,7 +277,8 @@ public Object[][] prependDataSources() throws Exception
Collections.<String, String>emptyMap()).build();

final List<MultiPartMIMEDataSourceWriter> withoutPreambleDataSourceWriterList =
ImmutableList.of(purelyEmptyBodyWriterNoPreamble, headerLessBodyWriterNoPreamble, normalWriterNoPreamble);
Collections.unmodifiableList(Arrays.asList(purelyEmptyBodyWriterNoPreamble, headerLessBodyWriterNoPreamble,
normalWriterNoPreamble));

final MultiPartMIMEWriter.Builder multiPartMIMEWriterWithoutPreamble = new MultiPartMIMEWriter.Builder("", "epilogue");

Expand Down
Expand Up @@ -42,13 +42,12 @@
import com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder;
import com.linkedin.r2.transport.http.client.HttpClientFactory;

import com.google.common.collect.ImmutableList;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -170,7 +169,7 @@ public void testEachSingleBodyDataSource(final int chunkSize, final MIMEDataPart

final MultiPartMIMEWriter writer = new MultiPartMIMEWriter.Builder("some preamble", "").appendDataSource(inputStreamDataSource).build();

executeRequestAndAssert(writer, ImmutableList.of(bodyPart));
executeRequestAndAssert(writer, Collections.unmodifiableList(Collections.singletonList(bodyPart)));
}

@Test(dataProvider = "eachSingleBodyDataSource", enabled = false)
Expand All @@ -188,7 +187,7 @@ public void testEachSingleBodyDataSourceMultipleTimes(final int chunkSize, final

final MultiPartMIMEWriter writer = new MultiPartMIMEWriter.Builder("some preamble", "").appendDataSources(dataSources).build();

executeRequestAndAssert(writer, ImmutableList.of(bodyPart, bodyPart, bodyPart, bodyPart));
executeRequestAndAssert(writer, Collections.unmodifiableList(Arrays.asList(bodyPart, bodyPart, bodyPart, bodyPart)));
}

///////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -227,7 +226,8 @@ public void testMultipleBodies(final int chunkSize) throws Exception
.appendDataSource(headerLessBodyInputStream).appendDataSource(bodyLessBodyInputStream)
.appendDataSource(purelyEmptyBodyInputStream).build();

executeRequestAndAssert(writer, ImmutableList.of(_normalBody, _headerLessBody, _bodyLessBody, _purelyEmptyBody));
executeRequestAndAssert(writer, Collections.unmodifiableList(Arrays.asList(_normalBody, _headerLessBody,
_bodyLessBody, _purelyEmptyBody)));
}

@Test
Expand Down
Expand Up @@ -24,8 +24,6 @@
import com.linkedin.multipart.MultiPartMIMEReaderCallback;
import com.linkedin.multipart.SinglePartMIMEReaderCallback;

import com.google.common.collect.ImmutableMap;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -156,38 +154,38 @@ public static List<Integer> generatePrimeNumbers(final int limit)
{
//Non javax mail sources:
final byte[] bodyAbytes = "BODY_A".getBytes();
final Map<String, String> bodyAHeaders = ImmutableMap.of("headerA", "valueA");
final Map<String, String> bodyAHeaders = Collections.unmodifiableMap(Collections.singletonMap("headerA", "valueA"));
BODY_A = new MIMEDataPart(ByteString.copy(bodyAbytes), bodyAHeaders);

final byte[] bodyBbytes = "BODY_B".getBytes();
final Map<String, String> bodyBHeaders = ImmutableMap.of("headerB", "valueB");
final Map<String, String> bodyBHeaders = Collections.unmodifiableMap(Collections.singletonMap("headerB", "valueB"));
BODY_B = new MIMEDataPart(ByteString.copy(bodyBbytes), bodyBHeaders);

//body c has no headers
final byte[] bodyCbytes = "BODY_C".getBytes();
BODY_C = new MIMEDataPart(ByteString.copy(bodyCbytes), Collections.<String, String>emptyMap());

final byte[] bodyDbytes = "BODY_D".getBytes();
final Map<String, String> bodyDHeaders = ImmutableMap.of("headerD", "valueD");
final Map<String, String> bodyDHeaders = Collections.unmodifiableMap(Collections.singletonMap("headerD", "valueD"));
BODY_D = new MIMEDataPart(ByteString.copy(bodyDbytes), bodyDHeaders);

final byte[] body1bytes = "BODY_1".getBytes();
final Map<String, String> body1Headers = ImmutableMap.of("header1", "value1");
final Map<String, String> body1Headers = Collections.unmodifiableMap(Collections.singletonMap("header1", "value1"));
BODY_1 = new MIMEDataPart(ByteString.copy(body1bytes), body1Headers);

final byte[] body2bytes = "BODY_2".getBytes();
final Map<String, String> body2Headers = ImmutableMap.of("header2", "value2");
final Map<String, String> body2Headers = Collections.unmodifiableMap(Collections.singletonMap("header2", "value2"));
BODY_2 = new MIMEDataPart(ByteString.copy(body2bytes), body2Headers);

//body 3 is completely empty
BODY_3 = new MIMEDataPart(ByteString.empty(), Collections.<String, String>emptyMap());

final byte[] body4bytes = "BODY_4".getBytes();
final Map<String, String> body4Headers = ImmutableMap.of("header4", "value4");
final Map<String, String> body4Headers = Collections.unmodifiableMap(Collections.singletonMap("header4", "value4"));
BODY_4 = new MIMEDataPart(ByteString.copy(body4bytes), body4Headers);

final byte[] localInputStreamBytes = "local input stream".getBytes();
final Map<String, String> localInputStreamHeaders = ImmutableMap.of("local1", "local2");
final Map<String, String> localInputStreamHeaders = Collections.unmodifiableMap(Collections.singletonMap("local1", "local2"));
BODY_5 = new MIMEDataPart(ByteString.copy(localInputStreamBytes), localInputStreamHeaders);
}

Expand Down

0 comments on commit 5404831

Please sign in to comment.