Skip to content

Commit

Permalink
xds: fix lint (#7210)
Browse files Browse the repository at this point in the history
  • Loading branch information
voidzcy authored Jul 14, 2020
1 parent 47c6bfe commit 631e07f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.grpc.xds.internal.certprovider.CertificateProvider.Watcher;
import io.grpc.xds.internal.sds.ReferenceCountingMap;

import java.io.Closeable;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -41,7 +42,7 @@ public final class CertificateProviderStore {

/** Opaque Handle returned by {@link #createOrGetProvider}. */
@VisibleForTesting
final class Handle implements java.io.Closeable {
final class Handle implements Closeable {
private final CertProviderKey key;
private final Watcher watcher;
@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyListOf;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -127,23 +128,22 @@ public void notifyCertUpdatesNotSupported_expectException() {

@Test
public void notifyCertUpdatesNotSupported_expectExceptionOnSecondCall() {
CertificateProviderProvider unused = registerPlugin("plugin1");
registerPlugin("plugin1");
throwExceptionForCertUpdates = true;
CertificateProvider.Watcher mockWatcher = mock(CertificateProvider.Watcher.class);
CertificateProviderStore.Handle handle1 =
certificateProviderStore.createOrGetProvider(
"cert-name1", "plugin1", "config", mockWatcher, false);
try {
CertificateProviderStore.Handle unused1 =
certificateProviderStore.createOrGetProvider(
"cert-name1", "plugin1", "config", mockWatcher, true);
fail("exception expected");
} catch (UnsupportedOperationException expected) {
assertThat(expected)
.hasMessageThat()
.isEqualTo("Provider does not support Certificate Updates.");
try (CertificateProviderStore.Handle unused =
certificateProviderStore
.createOrGetProvider("cert-name1", "plugin1", "config", mockWatcher, false)) {
try {
certificateProviderStore.createOrGetProvider(
"cert-name1", "plugin1", "config", mockWatcher, true);
fail("exception expected");
} catch (UnsupportedOperationException expected) {
assertThat(expected)
.hasMessageThat()
.isEqualTo("Provider does not support Certificate Updates.");
}
}
handle1.close();
}

@Test
Expand All @@ -162,7 +162,7 @@ public void onePluginSameConfig_sameInstance() {
TestCertificateProvider testCertificateProvider =
(TestCertificateProvider) handle1.certProvider;
CertificateProvider.DistributorWatcher distWatcher = testCertificateProvider.getWatcher();
assertThat(distWatcher.downsstreamWatchers.size()).isEqualTo(2);
assertThat(distWatcher.downsstreamWatchers).hasSize(2);
PrivateKey testKey = mock(PrivateKey.class);
X509Certificate cert = mock(X509Certificate.class);
List<X509Certificate> testList = ImmutableList.of(cert);
Expand All @@ -178,7 +178,7 @@ public void onePluginSameConfig_sameInstance() {
reset(mockWatcher2);
handle1.close();
assertThat(testCertificateProvider.closeCalled).isEqualTo(0);
assertThat(distWatcher.downsstreamWatchers.size()).isEqualTo(1);
assertThat(distWatcher.downsstreamWatchers).hasSize(1);
testCertificateProvider.getWatcher().updateCertificate(testKey, testList);
verify(mockWatcher1, never())
.updateCertificate(any(PrivateKey.class), anyListOf(X509Certificate.class));
Expand Down Expand Up @@ -261,7 +261,7 @@ public void twoPlugins_differentInstance() {
}

@SuppressWarnings("deprecation")
private void checkDifferentInstances(
private static void checkDifferentInstances(
CertificateProvider.Watcher mockWatcher1,
CertificateProviderStore.Handle handle1,
CertificateProviderProvider certProviderProvider1,
Expand All @@ -278,9 +278,9 @@ private void checkDifferentInstances(
assertThat(testCertificateProvider2.certProviderProvider)
.isSameInstanceAs(certProviderProvider2);
CertificateProvider.DistributorWatcher distWatcher1 = testCertificateProvider1.getWatcher();
assertThat(distWatcher1.downsstreamWatchers.size()).isEqualTo(1);
assertThat(distWatcher1.downsstreamWatchers).hasSize(1);
CertificateProvider.DistributorWatcher distWatcher2 = testCertificateProvider2.getWatcher();
assertThat(distWatcher2.downsstreamWatchers.size()).isEqualTo(1);
assertThat(distWatcher2.downsstreamWatchers).hasSize(1);
PrivateKey testKey1 = mock(PrivateKey.class);
X509Certificate cert1 = mock(X509Certificate.class);
List<X509Certificate> testList1 = ImmutableList.of(cert1);
Expand Down Expand Up @@ -310,7 +310,7 @@ private CertificateProviderProvider registerPlugin(String pluginName) {
when(certProviderProvider.createCertificateProvider(
any(Object.class),
any(CertificateProvider.DistributorWatcher.class),
any(Boolean.TYPE)))
anyBoolean()))
.then(
new Answer<CertificateProvider>() {

Expand Down

0 comments on commit 631e07f

Please sign in to comment.