Search in sources :

Example 1 with HTTPFault

use of io.envoyproxy.envoy.extensions.filters.http.fault.v3.HTTPFault in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseOverrideFilterConfigs_unsupportedAndRequired.

@Test
public void parseOverrideFilterConfigs_unsupportedAndRequired() {
    filterRegistry.register(FaultFilter.INSTANCE);
    HTTPFault httpFault = HTTPFault.newBuilder().setDelay(FaultDelay.newBuilder().setFixedDelay(Durations.fromNanos(3000))).build();
    Map<String, Any> configOverrides = ImmutableMap.of("envoy.fault", Any.pack(httpFault), "unsupported.filter", Any.pack(io.envoyproxy.envoy.config.route.v3.FilterConfig.newBuilder().setIsOptional(false).setConfig(Any.pack(StringValue.of("string value"))).build()));
    assertThat(ClientXdsClient.parseOverrideFilterConfigs(configOverrides, filterRegistry).getErrorDetail()).isEqualTo("HttpFilter [unsupported.filter]" + "(type.googleapis.com/google.protobuf.StringValue) is required but unsupported");
    configOverrides = ImmutableMap.of("envoy.fault", Any.pack(httpFault), "unsupported.filter", Any.pack(StringValue.of("string value")));
    assertThat(ClientXdsClient.parseOverrideFilterConfigs(configOverrides, filterRegistry).getErrorDetail()).isEqualTo("HttpFilter [unsupported.filter]" + "(type.googleapis.com/google.protobuf.StringValue) is required but unsupported");
}
Also used : HTTPFault(io.envoyproxy.envoy.extensions.filters.http.fault.v3.HTTPFault) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 2 with HTTPFault

use of io.envoyproxy.envoy.extensions.filters.http.fault.v3.HTTPFault in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseOverrideFilterConfigs_unsupportedButOptional.

@Test
public void parseOverrideFilterConfigs_unsupportedButOptional() {
    filterRegistry.register(FaultFilter.INSTANCE);
    HTTPFault httpFault = HTTPFault.newBuilder().setDelay(FaultDelay.newBuilder().setFixedDelay(Durations.fromNanos(3000))).build();
    Map<String, Any> configOverrides = ImmutableMap.of("envoy.fault", Any.pack(httpFault), "unsupported.filter", Any.pack(io.envoyproxy.envoy.config.route.v3.FilterConfig.newBuilder().setIsOptional(true).setConfig(Any.pack(StringValue.of("string value"))).build()));
    Map<String, FilterConfig> parsedConfigs = ClientXdsClient.parseOverrideFilterConfigs(configOverrides, filterRegistry).getStruct();
    assertThat(parsedConfigs).hasSize(1);
    assertThat(parsedConfigs).containsKey("envoy.fault");
}
Also used : HTTPFault(io.envoyproxy.envoy.extensions.filters.http.fault.v3.HTTPFault) FilterConfig(io.grpc.xds.Filter.FilterConfig) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 3 with HTTPFault

use of io.envoyproxy.envoy.extensions.filters.http.fault.v3.HTTPFault in project grpc-java by grpc.

the class FaultFilter method parseFilterConfig.

@Override
public ConfigOrError<FaultConfig> parseFilterConfig(Message rawProtoMessage) {
    HTTPFault httpFaultProto;
    if (!(rawProtoMessage instanceof Any)) {
        return ConfigOrError.fromError("Invalid config type: " + rawProtoMessage.getClass());
    }
    Any anyMessage = (Any) rawProtoMessage;
    try {
        httpFaultProto = anyMessage.unpack(HTTPFault.class);
    } catch (InvalidProtocolBufferException e) {
        return ConfigOrError.fromError("Invalid proto: " + e);
    }
    return parseHttpFault(httpFaultProto);
}
Also used : HTTPFault(io.envoyproxy.envoy.extensions.filters.http.fault.v3.HTTPFault) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Any(com.google.protobuf.Any)

Aggregations

Any (com.google.protobuf.Any)3 HTTPFault (io.envoyproxy.envoy.extensions.filters.http.fault.v3.HTTPFault)3 Test (org.junit.Test)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 FilterConfig (io.grpc.xds.Filter.FilterConfig)1