Search in sources :

Example 6 with Struct

use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.Struct in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseOverrideHttpFilter_typedStructMigration.

@Test
public void parseOverrideHttpFilter_typedStructMigration() {
    filterRegistry.register(new TestFilter());
    Struct rawStruct0 = Struct.newBuilder().putFields("name", Value.newBuilder().setStringValue("default0").build()).build();
    Struct rawStruct1 = Struct.newBuilder().putFields("name", Value.newBuilder().setStringValue("default1").build()).build();
    Map<String, Any> rawFilterMap = ImmutableMap.of("struct-0", Any.pack(com.github.udpa.udpa.type.v1.TypedStruct.newBuilder().setTypeUrl("test-url").setValue(rawStruct0).build()), "struct-1", Any.pack(TypedStruct.newBuilder().setTypeUrl("test-url").setValue(rawStruct1).build()));
    Map<String, FilterConfig> map = ClientXdsClient.parseOverrideFilterConfigs(rawFilterMap, filterRegistry).getStruct();
    assertThat(((SimpleFilterConfig) map.get("struct-0")).getConfig()).isEqualTo(rawStruct0);
    assertThat(((SimpleFilterConfig) map.get("struct-1")).getConfig()).isEqualTo(rawStruct1);
}
Also used : FilterConfig(io.grpc.xds.Filter.FilterConfig) Any(com.google.protobuf.Any) Struct(com.google.protobuf.Struct) TypedStruct(com.github.udpa.udpa.type.v1.TypedStruct) Test(org.junit.Test)

Example 7 with Struct

use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.Struct in project curiostack by curioswitch.

the class MessageMarshallerTest method struct.

@Test
public void struct() throws Exception {
    // Build a struct with all possible values.
    TestStruct.Builder builder = TestStruct.newBuilder();
    Struct.Builder structBuilder = builder.getStructValueBuilder();
    structBuilder.putFields("null_value", Value.newBuilder().setNullValueValue(0).build());
    structBuilder.putFields("number_value", Value.newBuilder().setNumberValue(1.25).build());
    structBuilder.putFields("string_value", Value.newBuilder().setStringValue("hello").build());
    Struct.Builder subStructBuilder = Struct.newBuilder();
    subStructBuilder.putFields("number_value", Value.newBuilder().setNumberValue(1234).build());
    structBuilder.putFields("struct_value", Value.newBuilder().setStructValue(subStructBuilder.build()).build());
    ListValue.Builder listBuilder = ListValue.newBuilder();
    listBuilder.addValues(Value.newBuilder().setNumberValue(1.125).build());
    listBuilder.addValues(Value.newBuilder().setNullValueValue(0).build());
    structBuilder.putFields("list_value", Value.newBuilder().setListValue(listBuilder.build()).build());
    TestStruct message = builder.build();
    assertMatchesUpstream(message);
    builder = TestStruct.newBuilder();
    builder.setValue(Value.newBuilder().setNullValueValue(0).build());
    message = builder.build();
    assertMatchesUpstream(message);
    builder = TestStruct.newBuilder();
    listBuilder = builder.getListValueBuilder();
    listBuilder.addValues(Value.newBuilder().setNumberValue(31831.125).build());
    listBuilder.addValues(Value.newBuilder().setNullValueValue(0).build());
    message = builder.build();
    assertMatchesUpstream(message);
}
Also used : ListValue(com.google.protobuf.ListValue) TestStruct(com.google.protobuf.util.JsonTestProto.TestStruct) Struct(com.google.protobuf.Struct) TestStruct(com.google.protobuf.util.JsonTestProto.TestStruct) Test(org.junit.Test)

Example 8 with Struct

use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.Struct in project google-cloud-java by GoogleCloudPlatform.

the class StructsTest method testNewStruct.

@Test
public void testNewStruct() {
    Struct struct = Structs.newStruct(MAP);
    checkStructField(struct, "null", NULL_VALUE);
    checkStructField(struct, "number", NUMBER_VALUE);
    checkStructField(struct, "string", STRING_VALUE);
    checkStructField(struct, "boolean", BOOLEAN_VALUE);
    checkStructField(struct, "list", LIST_VALUE);
    checkStructField(struct, "struct", STRUCT_VALUE);
    assertEquals(STRUCT, struct);
}
Also used : Struct(com.google.protobuf.Struct) Test(org.junit.Test)

Example 9 with Struct

use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.Struct in project google-cloud-java by GoogleCloudPlatform.

the class StructsTest method testNumbers.

@Test
public void testNumbers() {
    int intNumber = Integer.MIN_VALUE;
    long longNumber = Long.MAX_VALUE;
    float floatNumber = Float.MIN_VALUE;
    double doubleNumber = Double.MAX_VALUE;
    Map<String, Object> map = ImmutableMap.<String, Object>of("int", intNumber, "long", longNumber, "float", floatNumber, "double", doubleNumber);
    Struct struct = Structs.newStruct(map);
    checkStructField(struct, "int", Value.newBuilder().setNumberValue(intNumber).build());
    checkStructField(struct, "long", Value.newBuilder().setNumberValue(longNumber).build());
    checkStructField(struct, "float", Value.newBuilder().setNumberValue(floatNumber).build());
    checkStructField(struct, "double", Value.newBuilder().setNumberValue(doubleNumber).build());
    Map<String, Object> convertedMap = Structs.asMap(struct);
    assertTrue(convertedMap.get("int") instanceof Double);
    assertTrue(convertedMap.get("long") instanceof Double);
    assertTrue(convertedMap.get("float") instanceof Double);
    assertTrue(convertedMap.get("double") instanceof Double);
    int convertedInteger = ((Double) convertedMap.get("int")).intValue();
    long convertedLong = ((Double) convertedMap.get("long")).longValue();
    float convertedFloat = ((Double) convertedMap.get("float")).floatValue();
    double convertedDouble = (Double) convertedMap.get("double");
    assertEquals(intNumber, convertedInteger);
    assertEquals(longNumber, convertedLong);
    assertEquals(floatNumber, convertedFloat, 0);
    assertEquals(doubleNumber, convertedDouble, 0);
}
Also used : Struct(com.google.protobuf.Struct) Test(org.junit.Test)

Example 10 with Struct

use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.Struct in project google-cloud-java by GoogleCloudPlatform.

the class StructsTest method testNewStructEmpty.

@Test
public void testNewStructEmpty() {
    Struct struct = Structs.newStruct(EMPTY_MAP);
    assertTrue(struct.getFieldsMap().isEmpty());
}
Also used : Struct(com.google.protobuf.Struct) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 Struct (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.Struct)9 Struct (com.google.protobuf.Struct)8 PortablePipelineOptions (org.apache.beam.sdk.options.PortablePipelineOptions)5 ListValue (com.google.protobuf.ListValue)3 TestStruct (com.google.protobuf.util.JsonTestProto.TestStruct)3 JobInfo (org.apache.beam.runners.fnexecution.provisioning.JobInfo)3 StateRequestHandler (org.apache.beam.runners.fnexecution.state.StateRequestHandler)3 TypedStruct (com.github.udpa.udpa.type.v1.TypedStruct)2 Any (com.google.protobuf.Any)2 BoolValue (com.google.protobuf.BoolValue)2 BytesValue (com.google.protobuf.BytesValue)2 DoubleValue (com.google.protobuf.DoubleValue)2 FloatValue (com.google.protobuf.FloatValue)2 Int32Value (com.google.protobuf.Int32Value)2 Int64Value (com.google.protobuf.Int64Value)2 NullValue (com.google.protobuf.NullValue)2 StringValue (com.google.protobuf.StringValue)2 UInt32Value (com.google.protobuf.UInt32Value)2 UInt64Value (com.google.protobuf.UInt64Value)2