mirror of https://github.com/grpc/grpc-java.git
inprocess: Remove InProcessNameResolver
It was introduced in 15fc70be
but unused. It could be "used" from
inprocess: targets, but the in-process transport wasn't registered, so
would fail.
We do want an in-process name resolver, but we need to agree no the URI
format cross-language before we introduce it.
This commit is contained in:
parent
f2fc717749
commit
84baad12fc
|
@ -203,14 +203,12 @@ public class NameResolverRegistryTest {
|
|||
public void baseProviders() {
|
||||
Map<String, NameResolverProvider> 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
|
||||
|
|
|
@ -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<EquivalentAddressGroup> servers = new ArrayList<>(1);
|
||||
servers.add(new EquivalentAddressGroup(new InProcessSocketAddress(authority)));
|
||||
resolutionResultBuilder.setAddresses(Collections.unmodifiableList(servers));
|
||||
listener.onResult(resolutionResultBuilder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {}
|
||||
}
|
|
@ -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<Class<? extends SocketAddress>> getProducedSocketAddressTypes() {
|
||||
return Collections.singleton(InProcessSocketAddress.class);
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
io.grpc.inprocess.InProcessNameResolverProvider
|
|
@ -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<NameResolver.ResolutionResult> 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<EquivalentAddressGroup> list = result.getAddresses();
|
||||
assertThat(list).isNotNull();
|
||||
assertThat(list).hasSize(1);
|
||||
EquivalentAddressGroup eag = list.get(0);
|
||||
assertThat(eag).isNotNull();
|
||||
List<SocketAddress> 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<EquivalentAddressGroup> list = result.getAddresses();
|
||||
assertThat(list).isNotNull();
|
||||
assertThat(list).hasSize(1);
|
||||
EquivalentAddressGroup eag = list.get(0);
|
||||
assertThat(eag).isNotNull();
|
||||
List<SocketAddress> 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<EquivalentAddressGroup> list = result.getAddresses();
|
||||
assertThat(list).isNotNull();
|
||||
assertThat(list).hasSize(1);
|
||||
EquivalentAddressGroup eag = list.get(0);
|
||||
assertThat(eag).isNotNull();
|
||||
List<SocketAddress> 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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<NameResolver.ResolutionResult> 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<EquivalentAddressGroup> list = result.getAddresses();
|
||||
assertThat(list).isNotNull();
|
||||
assertThat(list).hasSize(1);
|
||||
EquivalentAddressGroup eag = list.get(0);
|
||||
assertThat(eag).isNotNull();
|
||||
List<SocketAddress> 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");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue