diff --git a/api/src/test/java/io/grpc/NameResolverRegistryTest.java b/api/src/test/java/io/grpc/NameResolverRegistryTest.java index 32067e976d..19ae09520d 100644 --- a/api/src/test/java/io/grpc/NameResolverRegistryTest.java +++ b/api/src/test/java/io/grpc/NameResolverRegistryTest.java @@ -203,14 +203,12 @@ public class NameResolverRegistryTest { public void baseProviders() { Map providers = NameResolverRegistry.getDefaultRegistry().providers(); - assertThat(providers).hasSize(2); + assertThat(providers).hasSize(1); // 2 name resolvers from grpclb and core, higher priority one is returned. assertThat(providers.get("dns").getClass().getName()) .isEqualTo("io.grpc.grpclb.SecretGrpclbNameResolverProvider$Provider"); assertThat(NameResolverRegistry.getDefaultRegistry().asFactory().getDefaultScheme()) .isEqualTo("dns"); - assertThat(providers.get("inprocess").getClass().getName()) - .isEqualTo("io.grpc.inprocess.InProcessNameResolverProvider"); } @Test diff --git a/inprocess/src/main/java/io/grpc/inprocess/InProcessNameResolver.java b/inprocess/src/main/java/io/grpc/inprocess/InProcessNameResolver.java deleted file mode 100644 index f2e50eade4..0000000000 --- a/inprocess/src/main/java/io/grpc/inprocess/InProcessNameResolver.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2023 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.inprocess; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.base.Preconditions; -import io.grpc.EquivalentAddressGroup; -import io.grpc.NameResolver; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -final class InProcessNameResolver extends NameResolver { - private Listener2 listener; - private final String authority; - - InProcessNameResolver(String authority, String targetPath) { - checkArgument(authority == null, "non-null authority not supported"); - this.authority = targetPath; - } - - @Override - public String getServiceAuthority() { - return this.authority; - } - - @Override - public void start(Listener2 listener) { - Preconditions.checkState(this.listener == null, "already started"); - this.listener = checkNotNull(listener, "listener"); - resolve(); - } - - @Override - public void refresh() { - resolve(); - } - - private void resolve() { - ResolutionResult.Builder resolutionResultBuilder = ResolutionResult.newBuilder(); - List servers = new ArrayList<>(1); - servers.add(new EquivalentAddressGroup(new InProcessSocketAddress(authority))); - resolutionResultBuilder.setAddresses(Collections.unmodifiableList(servers)); - listener.onResult(resolutionResultBuilder.build()); - } - - @Override - public void shutdown() {} -} diff --git a/inprocess/src/main/java/io/grpc/inprocess/InProcessNameResolverProvider.java b/inprocess/src/main/java/io/grpc/inprocess/InProcessNameResolverProvider.java deleted file mode 100644 index 98a37fc409..0000000000 --- a/inprocess/src/main/java/io/grpc/inprocess/InProcessNameResolverProvider.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2023 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.inprocess; - -import com.google.common.base.Preconditions; -import io.grpc.Internal; -import io.grpc.NameResolver; -import io.grpc.NameResolverProvider; -import java.net.SocketAddress; -import java.net.URI; -import java.util.Collection; -import java.util.Collections; - -@Internal -public final class InProcessNameResolverProvider extends NameResolverProvider { - - private static final String SCHEME = "inprocess"; - - @Override - public InProcessNameResolver newNameResolver(URI targetUri, NameResolver.Args args) { - if (SCHEME.equals(targetUri.getScheme())) { - return new InProcessNameResolver(targetUri.getAuthority(), getTargetPathFromUri(targetUri)); - } else { - return null; - } - } - - static String getTargetPathFromUri(URI targetUri) { - Preconditions.checkArgument(SCHEME.equals(targetUri.getScheme()), "scheme must be " + SCHEME); - String targetPath = targetUri.getPath(); - if (targetPath == null) { - targetPath = Preconditions.checkNotNull(targetUri.getSchemeSpecificPart(), "targetPath"); - } - return targetPath; - } - - @Override - public String getDefaultScheme() { - return SCHEME; - } - - @Override - protected boolean isAvailable() { - return true; - } - - @Override - protected int priority() { - return 3; - } - - @Override - public Collection> getProducedSocketAddressTypes() { - return Collections.singleton(InProcessSocketAddress.class); - } -} diff --git a/inprocess/src/main/resources/META-INF/services/io.grpc.NameResolverProvider b/inprocess/src/main/resources/META-INF/services/io.grpc.NameResolverProvider deleted file mode 100644 index a054250839..0000000000 --- a/inprocess/src/main/resources/META-INF/services/io.grpc.NameResolverProvider +++ /dev/null @@ -1 +0,0 @@ -io.grpc.inprocess.InProcessNameResolverProvider diff --git a/inprocess/src/test/java/io/grpc/inprocess/InProcessNameResolverProviderTest.java b/inprocess/src/test/java/io/grpc/inprocess/InProcessNameResolverProviderTest.java deleted file mode 100644 index 0a2e85dcf2..0000000000 --- a/inprocess/src/test/java/io/grpc/inprocess/InProcessNameResolverProviderTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2023 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.inprocess; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.verify; - -import io.grpc.EquivalentAddressGroup; -import io.grpc.NameResolver; -import java.net.SocketAddress; -import java.net.URI; -import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -/** Unit tests for {@link InProcessNameResolverProvider}. */ -@RunWith(JUnit4.class) -public class InProcessNameResolverProviderTest { - - @Rule - public final MockitoRule mocks = MockitoJUnit.rule(); - - @Mock - private NameResolver.Listener2 mockListener; - - @Captor - private ArgumentCaptor resultCaptor; - - InProcessNameResolverProvider inProcessNameResolverProvider = new InProcessNameResolverProvider(); - - - @Test - public void testRelativePath() { - InProcessNameResolver inProcessNameResolver = - inProcessNameResolverProvider.newNameResolver(URI.create("inprocess:proc.proc"), null); - assertThat(inProcessNameResolver).isNotNull(); - inProcessNameResolver.start(mockListener); - verify(mockListener).onResult(resultCaptor.capture()); - NameResolver.ResolutionResult result = resultCaptor.getValue(); - List list = result.getAddresses(); - assertThat(list).isNotNull(); - assertThat(list).hasSize(1); - EquivalentAddressGroup eag = list.get(0); - assertThat(eag).isNotNull(); - List addresses = eag.getAddresses(); - assertThat(addresses).hasSize(1); - assertThat(addresses.get(0)).isInstanceOf(InProcessSocketAddress.class); - InProcessSocketAddress domainSocketAddress = (InProcessSocketAddress) addresses.get(0); - assertThat(domainSocketAddress.getName()).isEqualTo("proc.proc"); - } - - @Test - public void testAbsolutePath() { - InProcessNameResolver inProcessNameResolver = - inProcessNameResolverProvider.newNameResolver(URI.create("inprocess:/proc.proc"), null); - assertThat(inProcessNameResolver).isNotNull(); - inProcessNameResolver.start(mockListener); - verify(mockListener).onResult(resultCaptor.capture()); - NameResolver.ResolutionResult result = resultCaptor.getValue(); - List list = result.getAddresses(); - assertThat(list).isNotNull(); - assertThat(list).hasSize(1); - EquivalentAddressGroup eag = list.get(0); - assertThat(eag).isNotNull(); - List addresses = eag.getAddresses(); - assertThat(addresses).hasSize(1); - assertThat(addresses.get(0)).isInstanceOf(InProcessSocketAddress.class); - InProcessSocketAddress domainSocketAddress = (InProcessSocketAddress) addresses.get(0); - assertThat(domainSocketAddress.getName()).isEqualTo("/proc.proc"); - } - - @Test - public void testAbsoluteAlternatePath() { - InProcessNameResolver udsNameResolver = - inProcessNameResolverProvider.newNameResolver(URI.create("inprocess:///proc.proc"), null); - assertThat(udsNameResolver).isNotNull(); - udsNameResolver.start(mockListener); - verify(mockListener).onResult(resultCaptor.capture()); - NameResolver.ResolutionResult result = resultCaptor.getValue(); - List list = result.getAddresses(); - assertThat(list).isNotNull(); - assertThat(list).hasSize(1); - EquivalentAddressGroup eag = list.get(0); - assertThat(eag).isNotNull(); - List addresses = eag.getAddresses(); - assertThat(addresses).hasSize(1); - assertThat(addresses.get(0)).isInstanceOf(InProcessSocketAddress.class); - InProcessSocketAddress domainSocketAddress = (InProcessSocketAddress) addresses.get(0); - assertThat(domainSocketAddress.getName()).isEqualTo("/proc.proc"); - } - - @Test - public void testWrongScheme() { - assertNull(inProcessNameResolverProvider.newNameResolver(URI.create( - "badscheme://localhost/proc.proc"), null)); - } - - @Test - public void testPathWithAuthority() { - try { - inProcessNameResolverProvider.newNameResolver( - URI.create("inprocess://localhost/proc.proc"), null); - fail("exception expected"); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessageThat().isEqualTo( - "non-null authority not supported"); - } - } -} diff --git a/inprocess/src/test/java/io/grpc/inprocess/InProcessNameResolverTest.java b/inprocess/src/test/java/io/grpc/inprocess/InProcessNameResolverTest.java deleted file mode 100644 index b48aab1232..0000000000 --- a/inprocess/src/test/java/io/grpc/inprocess/InProcessNameResolverTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2023 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.inprocess; - -import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.verify; - -import io.grpc.EquivalentAddressGroup; -import io.grpc.NameResolver; -import java.net.SocketAddress; -import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -/** Unit tests for {@link InProcessNameResolver}. */ -@RunWith(JUnit4.class) -public class InProcessNameResolverTest { - - @Rule - public final MockitoRule mocks = MockitoJUnit.rule(); - - @Mock - private NameResolver.Listener2 mockListener; - - @Captor - private ArgumentCaptor resultCaptor; - - private InProcessNameResolver inProcessNameResolver; - - @Test - public void testValidTargetPath() { - inProcessNameResolver = new InProcessNameResolver(null, "proc.proc"); - inProcessNameResolver.start(mockListener); - verify(mockListener).onResult(resultCaptor.capture()); - NameResolver.ResolutionResult result = resultCaptor.getValue(); - List list = result.getAddresses(); - assertThat(list).isNotNull(); - assertThat(list).hasSize(1); - EquivalentAddressGroup eag = list.get(0); - assertThat(eag).isNotNull(); - List addresses = eag.getAddresses(); - assertThat(addresses).hasSize(1); - assertThat(addresses.get(0)).isInstanceOf(InProcessSocketAddress.class); - InProcessSocketAddress socketAddress = (InProcessSocketAddress) addresses.get(0); - assertThat(socketAddress.getName()).isEqualTo("proc.proc"); - assertThat(inProcessNameResolver.getServiceAuthority()).isEqualTo("proc.proc"); - } - - @Test - public void testNonNullAuthority() { - try { - inProcessNameResolver = new InProcessNameResolver("authority", "proc.proc"); - fail("exception expected"); - } catch (IllegalArgumentException e) { - assertThat(e).hasMessageThat().isEqualTo("non-null authority not supported"); - } - } -}