use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class RlsRequestFactoryTest method create_pathMatches.
@Test
public void create_pathMatches() {
Metadata metadata = new Metadata();
metadata.put(Metadata.Key.of("User", Metadata.ASCII_STRING_MARSHALLER), "test");
metadata.put(Metadata.Key.of("X-Google-Id", Metadata.ASCII_STRING_MARSHALLER), "123");
metadata.put(Metadata.Key.of("foo", Metadata.ASCII_STRING_MARSHALLER), "bar");
RouteLookupRequest request = factory.create("com.google.service1", "Create", metadata);
assertThat(request.keyMap()).containsExactly("user", "test", "id", "123", "server-1", "bigtable.googleapis.com", "const-key-1", "const-value-1");
}
use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class RlsRequestFactoryTest method create_pathFallbackMatches.
@Test
public void create_pathFallbackMatches() {
Metadata metadata = new Metadata();
metadata.put(Metadata.Key.of("Parent", Metadata.ASCII_STRING_MARSHALLER), "test");
metadata.put(Metadata.Key.of("Password", Metadata.ASCII_STRING_MARSHALLER), "hunter2");
metadata.put(Metadata.Key.of("foo", Metadata.ASCII_STRING_MARSHALLER), "bar");
RouteLookupRequest request = factory.create("com.google.service1", "Update", metadata);
assertThat(request.keyMap()).containsExactly("user", "test", "password", "hunter2", "service-2", "com.google.service1", "const-key-2", "const-value-2");
}
use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class RlsRequestFactoryTest method create_unknownPath.
@Test
public void create_unknownPath() {
Metadata metadata = new Metadata();
metadata.put(Metadata.Key.of("User", Metadata.ASCII_STRING_MARSHALLER), "test");
metadata.put(Metadata.Key.of("X-Google-Id", Metadata.ASCII_STRING_MARSHALLER), "123");
metadata.put(Metadata.Key.of("foo", Metadata.ASCII_STRING_MARSHALLER), "bar");
RouteLookupRequest request = factory.create("abc.def.service999", "Update", metadata);
assertThat(request.keyMap()).isEmpty();
}
use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class CachingRlsLbClientTest method get_noError_lifeCycle.
@Test
public void get_noError_lifeCycle() throws Exception {
setUpRlsLbClient();
InOrder inOrder = inOrder(evictionListener);
RouteLookupRequest routeLookupRequest = RouteLookupRequest.create(ImmutableMap.of("server", "bigtable.googleapis.com", "service-key", "foo", "method-key", "bar"));
rlsServerImpl.setLookupTable(ImmutableMap.of(routeLookupRequest, RouteLookupResponse.create(ImmutableList.of("target"), "header")));
// initial request
CachedRouteLookupResponse resp = getInSyncContext(routeLookupRequest);
assertThat(resp.isPending()).isTrue();
// server response
fakeTimeProvider.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.hasData()).isTrue();
// cache hit for staled entry
fakeTimeProvider.forwardTime(ROUTE_LOOKUP_CONFIG.staleAgeInNanos(), TimeUnit.NANOSECONDS);
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.hasData()).isTrue();
// async refresh finishes
fakeTimeProvider.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
inOrder.verify(evictionListener).onEviction(eq(routeLookupRequest), any(CacheEntry.class), eq(EvictionType.REPLACED));
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.hasData()).isTrue();
// existing cache expired
fakeTimeProvider.forwardTime(ROUTE_LOOKUP_CONFIG.maxAgeInNanos(), TimeUnit.NANOSECONDS);
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.isPending()).isTrue();
inOrder.verify(evictionListener).onEviction(eq(routeLookupRequest), any(CacheEntry.class), eq(EvictionType.EXPIRED));
inOrder.verifyNoMoreInteractions();
}
use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class CachingRlsLbClientTest method get_updatesLbState.
@Test
public void get_updatesLbState() throws Exception {
setUpRlsLbClient();
InOrder inOrder = inOrder(helper);
RouteLookupRequest routeLookupRequest = RouteLookupRequest.create(ImmutableMap.of("server", "bigtable.googleapis.com", "service-key", "service1", "method-key", "create"));
rlsServerImpl.setLookupTable(ImmutableMap.of(routeLookupRequest, RouteLookupResponse.create(ImmutableList.of("primary.cloudbigtable.googleapis.com"), "header-rls-data-value")));
// valid channel
CachedRouteLookupResponse resp = getInSyncContext(routeLookupRequest);
assertThat(resp.isPending()).isTrue();
fakeTimeProvider.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.hasData()).isTrue();
ArgumentCaptor<SubchannelPicker> pickerCaptor = ArgumentCaptor.forClass(SubchannelPicker.class);
ArgumentCaptor<ConnectivityState> stateCaptor = ArgumentCaptor.forClass(ConnectivityState.class);
inOrder.verify(helper, times(2)).updateBalancingState(stateCaptor.capture(), pickerCaptor.capture());
assertThat(new HashSet<>(pickerCaptor.getAllValues())).hasSize(1);
assertThat(stateCaptor.getAllValues()).containsExactly(ConnectivityState.CONNECTING, ConnectivityState.READY);
Metadata headers = new Metadata();
PickResult pickResult = pickerCaptor.getValue().pickSubchannel(new PickSubchannelArgsImpl(TestMethodDescriptors.voidMethod().toBuilder().setFullMethodName("service1/create").build(), headers, CallOptions.DEFAULT));
assertThat(pickResult.getStatus().isOk()).isTrue();
assertThat(pickResult.getSubchannel()).isNotNull();
assertThat(headers.get(RLS_DATA_KEY)).isEqualTo("header-rls-data-value");
// move backoff further back to only test error behavior
fakeBackoffProvider.nextPolicy = createBackoffPolicy(100, TimeUnit.MILLISECONDS);
// try to get invalid
RouteLookupRequest invalidRouteLookupRequest = RouteLookupRequest.create(ImmutableMap.<String, String>of());
CachedRouteLookupResponse errorResp = getInSyncContext(invalidRouteLookupRequest);
assertThat(errorResp.isPending()).isTrue();
fakeTimeProvider.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
errorResp = getInSyncContext(invalidRouteLookupRequest);
assertThat(errorResp.hasError()).isTrue();
// Channel is still READY because the subchannel for method /service1/create is still READY.
// Method /doesn/exists will use fallback child balancer and fail immediately.
inOrder.verify(helper).updateBalancingState(eq(ConnectivityState.READY), pickerCaptor.capture());
pickResult = pickerCaptor.getValue().pickSubchannel(new PickSubchannelArgsImpl(TestMethodDescriptors.voidMethod().toBuilder().setFullMethodName("doesn/exists").build(), headers, CallOptions.DEFAULT));
assertThat(pickResult.getStatus().getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(pickResult.getStatus().getDescription()).isEqualTo("fallback not available");
}
Aggregations