xds: fix lint (#7210)

This commit is contained in:
Chengyuan Zhang 2020-07-14 22:25:34 +00:00 committed by GitHub
parent 47c6bfefe5
commit 631e07f090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 21 deletions

View File

@ -20,6 +20,7 @@ import com.google.common.annotations.VisibleForTesting;
import io.grpc.xds.internal.certprovider.CertificateProvider.Watcher; import io.grpc.xds.internal.certprovider.CertificateProvider.Watcher;
import io.grpc.xds.internal.sds.ReferenceCountingMap; import io.grpc.xds.internal.sds.ReferenceCountingMap;
import java.io.Closeable;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -41,7 +42,7 @@ public final class CertificateProviderStore {
/** Opaque Handle returned by {@link #createOrGetProvider}. */ /** Opaque Handle returned by {@link #createOrGetProvider}. */
@VisibleForTesting @VisibleForTesting
final class Handle implements java.io.Closeable { final class Handle implements Closeable {
private final CertProviderKey key; private final CertProviderKey key;
private final Watcher watcher; private final Watcher watcher;
@VisibleForTesting @VisibleForTesting

View File

@ -19,6 +19,7 @@ package io.grpc.xds.internal.certprovider;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyListOf; import static org.mockito.ArgumentMatchers.anyListOf;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -127,23 +128,22 @@ public class CertificateProviderStoreTest {
@Test @Test
public void notifyCertUpdatesNotSupported_expectExceptionOnSecondCall() { public void notifyCertUpdatesNotSupported_expectExceptionOnSecondCall() {
CertificateProviderProvider unused = registerPlugin("plugin1"); registerPlugin("plugin1");
throwExceptionForCertUpdates = true; throwExceptionForCertUpdates = true;
CertificateProvider.Watcher mockWatcher = mock(CertificateProvider.Watcher.class); CertificateProvider.Watcher mockWatcher = mock(CertificateProvider.Watcher.class);
CertificateProviderStore.Handle handle1 = try (CertificateProviderStore.Handle unused =
certificateProviderStore.createOrGetProvider( certificateProviderStore
"cert-name1", "plugin1", "config", mockWatcher, false); .createOrGetProvider("cert-name1", "plugin1", "config", mockWatcher, false)) {
try { try {
CertificateProviderStore.Handle unused1 = certificateProviderStore.createOrGetProvider(
certificateProviderStore.createOrGetProvider( "cert-name1", "plugin1", "config", mockWatcher, true);
"cert-name1", "plugin1", "config", mockWatcher, true); fail("exception expected");
fail("exception expected"); } catch (UnsupportedOperationException expected) {
} catch (UnsupportedOperationException expected) { assertThat(expected)
assertThat(expected) .hasMessageThat()
.hasMessageThat() .isEqualTo("Provider does not support Certificate Updates.");
.isEqualTo("Provider does not support Certificate Updates."); }
} }
handle1.close();
} }
@Test @Test
@ -162,7 +162,7 @@ public class CertificateProviderStoreTest {
TestCertificateProvider testCertificateProvider = TestCertificateProvider testCertificateProvider =
(TestCertificateProvider) handle1.certProvider; (TestCertificateProvider) handle1.certProvider;
CertificateProvider.DistributorWatcher distWatcher = testCertificateProvider.getWatcher(); CertificateProvider.DistributorWatcher distWatcher = testCertificateProvider.getWatcher();
assertThat(distWatcher.downsstreamWatchers.size()).isEqualTo(2); assertThat(distWatcher.downsstreamWatchers).hasSize(2);
PrivateKey testKey = mock(PrivateKey.class); PrivateKey testKey = mock(PrivateKey.class);
X509Certificate cert = mock(X509Certificate.class); X509Certificate cert = mock(X509Certificate.class);
List<X509Certificate> testList = ImmutableList.of(cert); List<X509Certificate> testList = ImmutableList.of(cert);
@ -178,7 +178,7 @@ public class CertificateProviderStoreTest {
reset(mockWatcher2); reset(mockWatcher2);
handle1.close(); handle1.close();
assertThat(testCertificateProvider.closeCalled).isEqualTo(0); assertThat(testCertificateProvider.closeCalled).isEqualTo(0);
assertThat(distWatcher.downsstreamWatchers.size()).isEqualTo(1); assertThat(distWatcher.downsstreamWatchers).hasSize(1);
testCertificateProvider.getWatcher().updateCertificate(testKey, testList); testCertificateProvider.getWatcher().updateCertificate(testKey, testList);
verify(mockWatcher1, never()) verify(mockWatcher1, never())
.updateCertificate(any(PrivateKey.class), anyListOf(X509Certificate.class)); .updateCertificate(any(PrivateKey.class), anyListOf(X509Certificate.class));
@ -261,7 +261,7 @@ public class CertificateProviderStoreTest {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void checkDifferentInstances( private static void checkDifferentInstances(
CertificateProvider.Watcher mockWatcher1, CertificateProvider.Watcher mockWatcher1,
CertificateProviderStore.Handle handle1, CertificateProviderStore.Handle handle1,
CertificateProviderProvider certProviderProvider1, CertificateProviderProvider certProviderProvider1,
@ -278,9 +278,9 @@ public class CertificateProviderStoreTest {
assertThat(testCertificateProvider2.certProviderProvider) assertThat(testCertificateProvider2.certProviderProvider)
.isSameInstanceAs(certProviderProvider2); .isSameInstanceAs(certProviderProvider2);
CertificateProvider.DistributorWatcher distWatcher1 = testCertificateProvider1.getWatcher(); CertificateProvider.DistributorWatcher distWatcher1 = testCertificateProvider1.getWatcher();
assertThat(distWatcher1.downsstreamWatchers.size()).isEqualTo(1); assertThat(distWatcher1.downsstreamWatchers).hasSize(1);
CertificateProvider.DistributorWatcher distWatcher2 = testCertificateProvider2.getWatcher(); CertificateProvider.DistributorWatcher distWatcher2 = testCertificateProvider2.getWatcher();
assertThat(distWatcher2.downsstreamWatchers.size()).isEqualTo(1); assertThat(distWatcher2.downsstreamWatchers).hasSize(1);
PrivateKey testKey1 = mock(PrivateKey.class); PrivateKey testKey1 = mock(PrivateKey.class);
X509Certificate cert1 = mock(X509Certificate.class); X509Certificate cert1 = mock(X509Certificate.class);
List<X509Certificate> testList1 = ImmutableList.of(cert1); List<X509Certificate> testList1 = ImmutableList.of(cert1);
@ -310,7 +310,7 @@ public class CertificateProviderStoreTest {
when(certProviderProvider.createCertificateProvider( when(certProviderProvider.createCertificateProvider(
any(Object.class), any(Object.class),
any(CertificateProvider.DistributorWatcher.class), any(CertificateProvider.DistributorWatcher.class),
any(Boolean.TYPE))) anyBoolean()))
.then( .then(
new Answer<CertificateProvider>() { new Answer<CertificateProvider>() {