com.google.protobuf.Struct Java Examples
The following examples show how to use
com.google.protobuf.Struct.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatementBindingsTest.java From cloud-spanner-r2dbc with Apache License 2.0 | 8 votes |
@Test public void addBasicBinding() { StatementBindings statementBindings = new StatementBindings(); statementBindings.createBind("name", "John"); statementBindings.createBind("age", 50); statementBindings.createBind("array", new String[]{"a", "b"}); statementBindings.completeBinding(); assertThat(statementBindings.getTypes()) .containsExactly( entry("array", Type.newBuilder().setCode(TypeCode.ARRAY) .setArrayElementType(Type.newBuilder().setCode(TypeCode.STRING).build()).build()), entry("name", Type.newBuilder().setCode(TypeCode.STRING).build()), entry("age", Type.newBuilder().setCode(TypeCode.INT64).build()) ); assertThat(statementBindings.getBindings()) .containsExactly( Struct.newBuilder() .putFields("name", Value.newBuilder().setStringValue("John").build()) .putFields("age", Value.newBuilder().setStringValue("50").build()) .putFields("array", Value.newBuilder().setListValue( ListValue.newBuilder().addValues(Value.newBuilder().setStringValue("a").build()) .addValues(Value.newBuilder().setStringValue("b").build()).build()).build()) .build()); }
Example #2
Source File: SpannerStatement.java From cloud-spanner-r2dbc with Apache License 2.0 | 7 votes |
private Mono<SpannerResult> runStreamingSql(Struct params) { Flux<PartialResultSet> resultSetFlux = this.client.executeStreamingSql( this.ctx, this.sql, params, this.statementBindings.getTypes()); if (this.statementType == StatementType.SELECT) { PartialResultRowExtractor partialResultRowExtractor = new PartialResultRowExtractor(); return resultSetFlux .flatMapIterable(partialResultRowExtractor, this.config.getPartialResultSetFetchSize()) .transform(result -> Mono.just(new SpannerResult(result, Mono.just(0)))) .next(); } else { return resultSetFlux.last() .map(partialResultSet -> { long rowsUpdated = Math.max( partialResultSet.getStats().getRowCountExact(), partialResultSet.getStats().getRowCountLowerBound()); return Math.toIntExact(rowsUpdated); }) .map(rowCount -> new SpannerResult(Flux.empty(), Mono.just(rowCount))); } }
Example #3
Source File: StructUtil.java From rejoiner with Apache License 2.0 | 7 votes |
/** Convert a Struct to an ImmutableMap. */ public static ImmutableMap<String, Object> toMap(Struct struct) { return struct .getFieldsMap() .entrySet() .stream() .collect( ImmutableMap.toImmutableMap( entry -> entry.getKey(), entry -> { Value value = entry.getValue(); switch (value.getKindCase()) { case STRUCT_VALUE: return toMap(value.getStructValue()); case LIST_VALUE: return toList(value.getListValue()); default: return getScalarValue(value); } })); }
Example #4
Source File: ListValueTest.java From jackson-datatype-protobuf with Apache License 2.0 | 6 votes |
@Test public void itReadsMixedTypeValues() throws IOException { String json = "{\"listValue\":[null,1.5,\"test\",true,{\"key\":\"value\"},[\"nested\"]]}"; HasListValue message = camelCase().readValue(json, HasListValue.class); Struct struct = Struct.newBuilder().putFields("key", Value.newBuilder().setStringValue("value").build()).build(); ListValue list = ListValue.newBuilder().addValues(Value.newBuilder().setStringValue("nested")).build(); ListValue expected = ListValue .newBuilder() .addValues(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()) .addValues(Value.newBuilder().setNumberValue(1.5d).build()) .addValues(Value.newBuilder().setStringValue("test").build()) .addValues(Value.newBuilder().setBoolValue(true).build()) .addValues(Value.newBuilder().setStructValue(struct).build()) .addValues(Value.newBuilder().setListValue(list).build()) .build(); assertThat(message.hasListValue()).isTrue(); assertThat(message.getListValue()).isEqualTo(expected); }
Example #5
Source File: JsonMapperProviderTest.java From conductor with Apache License 2.0 | 6 votes |
@Test public void testSimpleMapping() throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper m = new JsonMapperProvider().get(); assertTrue(m.canSerialize(Any.class)); Struct struct1 = Struct.newBuilder().putFields( "some-key", Value.newBuilder().setStringValue("some-value").build() ).build(); Any source = Any.pack(struct1); StringWriter buf = new StringWriter(); m.writer().writeValue(buf, source); Any dest = m.reader().forType(Any.class).readValue(buf.toString()); assertEquals(source.getTypeUrl(), dest.getTypeUrl()); Struct struct2 = dest.unpack(Struct.class); assertTrue(struct2.containsFields("some-key")); assertEquals( struct1.getFieldsOrThrow("some-key").getStringValue(), struct2.getFieldsOrThrow("some-key").getStringValue() ); }
Example #6
Source File: MessageMarshallerTest.java From curiostack with MIT License | 6 votes |
@Test public void anyInMaps() throws Exception { TestAny.Builder testAny = TestAny.newBuilder(); testAny.putAnyMap("int32_wrapper", Any.pack(Int32Value.newBuilder().setValue(123).build())); testAny.putAnyMap("int64_wrapper", Any.pack(Int64Value.newBuilder().setValue(456).build())); testAny.putAnyMap("timestamp", Any.pack(Timestamps.parse("1969-12-31T23:59:59Z"))); testAny.putAnyMap("duration", Any.pack(Durations.parse("12345.1s"))); testAny.putAnyMap("field_mask", Any.pack(FieldMaskUtil.fromString("foo.bar,baz"))); Value numberValue = Value.newBuilder().setNumberValue(1.125).build(); Struct.Builder struct = Struct.newBuilder(); struct.putFields("number", numberValue); testAny.putAnyMap("struct", Any.pack(struct.build())); Value nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build(); testAny.putAnyMap( "list_value", Any.pack(ListValue.newBuilder().addValues(numberValue).addValues(nullValue).build())); testAny.putAnyMap("number_value", Any.pack(numberValue)); testAny.putAnyMap("any_value_number", Any.pack(Any.pack(numberValue))); testAny.putAnyMap("any_value_default", Any.pack(Any.getDefaultInstance())); testAny.putAnyMap("default", Any.getDefaultInstance()); assertMatchesUpstream(testAny.build(), TestAllTypes.getDefaultInstance()); }
Example #7
Source File: WellKnownTypeMarshaller.java From curiostack with MIT License | 6 votes |
@Override public void doMerge(JsonParser parser, int currentDepth, Message.Builder messageBuilder) throws IOException { Value.Builder builder = (Value.Builder) messageBuilder; JsonToken token = parser.currentToken(); if (token.isBoolean()) { builder.setBoolValue(ParseSupport.parseBool(parser)); } else if (token.isNumeric()) { builder.setNumberValue(ParseSupport.parseDouble(parser)); } else if (token == JsonToken.VALUE_NULL) { builder.setNullValue(NullValue.NULL_VALUE); } else if (token.isScalarValue()) { builder.setStringValue(ParseSupport.parseString(parser)); } else if (token == JsonToken.START_OBJECT) { Struct.Builder structBuilder = builder.getStructValueBuilder(); StructMarshaller.INSTANCE.mergeValue(parser, currentDepth + 1, structBuilder); } else if (token == JsonToken.START_ARRAY) { ListValue.Builder listValueBuilder = builder.getListValueBuilder(); ListValueMarshaller.INSTANCE.mergeValue(parser, currentDepth + 1, listValueBuilder); } else { throw new IllegalStateException("Unexpected json data: " + parser.getText()); } }
Example #8
Source File: SdsClientTest.java From grpc-java with Apache License 2.0 | 6 votes |
/** * Builds a {@link ConfigSource} for the given targetUri. * * @param channelType specifying "inproc" creates an Inprocess channel for testing. */ static ConfigSource buildConfigSource(String targetUri, String channelType) { GoogleGrpc.Builder googleGrpcBuilder = GoogleGrpc.newBuilder().setTargetUri(targetUri); if (channelType != null) { Struct.Builder structBuilder = Struct.newBuilder(); structBuilder.putFields( "channelType", Value.newBuilder().setStringValue(channelType).build()); googleGrpcBuilder.setConfig(structBuilder.build()); } return ConfigSource.newBuilder() .setApiConfigSource( ApiConfigSource.newBuilder() .setApiType(ApiConfigSource.ApiType.GRPC) .addGrpcServices( GrpcService.newBuilder().setGoogleGrpc(googleGrpcBuilder.build()).build()) .build()) .build(); }
Example #9
Source File: LoadReportClientTest.java From grpc-java with Apache License 2.0 | 6 votes |
private static LoadStatsRequest buildInitialRequest() { return LoadStatsRequest.newBuilder() .setNode( Node.newBuilder() .setId("LRS test") .setMetadata( Struct.newBuilder() .putFields( "TRAFFICDIRECTOR_NETWORK_HOSTNAME", Value.newBuilder().setStringValue("default").build()) .putFields( LoadReportClient.TARGET_NAME_METADATA_KEY, Value.newBuilder().setStringValue(TARGET_NAME).build()))) .build(); }
Example #10
Source File: StructTest.java From jackson-datatype-protobuf with Apache License 2.0 | 6 votes |
@Test public void itReadsAllStructValueTypes() throws IOException { String json = "{\"struct\":{\"null\":null,\"number\":1.5,\"string\":\"test\",\"boolean\":true,\"struct\":{\"key\":\"nested\"},\"list\":[\"nested\"]}}"; HasStruct message = camelCase().readValue(json, HasStruct.class); assertThat(message.hasStruct()).isTrue(); Map<String, Value> map = message.getStruct().getFieldsMap(); Value nested = Value.newBuilder().setStringValue("nested").build(); Struct nestedStruct = Struct.newBuilder().putFields("key", nested).build(); ListValue list = ListValue.newBuilder().addValues(nested).build(); assertThat(map.size()).isEqualTo(6); assertThat(map.get("null")).isEqualTo(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()); assertThat(map.get("number")).isEqualTo(Value.newBuilder().setNumberValue(1.5).build()); assertThat(map.get("string")).isEqualTo(Value.newBuilder().setStringValue("test").build()); assertThat(map.get("boolean")).isEqualTo(Value.newBuilder().setBoolValue(true).build()); assertThat(map.get("struct")).isEqualTo(Value.newBuilder().setStructValue(nestedStruct).build()); assertThat(map.get("list")).isEqualTo(Value.newBuilder().setListValue(list).build()); }
Example #11
Source File: ValueTest.java From jackson-datatype-protobuf with Apache License 2.0 | 6 votes |
@Test public void itReadsMixedListValue() throws IOException { String json = "{\"value\":[null,1.5,\"test\",true,{\"key\":\"nested\"},[\"nested\"]]}"; HasValue message = camelCase().readValue(json, HasValue.class); assertThat(message.hasValue()).isTrue(); Value value = message.getValue(); switch (value.getKindCase()) { case LIST_VALUE: ListValue list = value.getListValue(); Value nested = Value.newBuilder().setStringValue("nested").build(); Struct struct = Struct.newBuilder().putFields("key", nested).build(); ListValue nestedList = ListValue.newBuilder().addValues(nested).build(); assertThat(list.getValuesCount()).isEqualTo(6); assertThat(list.getValues(0)).isEqualTo(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()); assertThat(list.getValues(1)).isEqualTo(Value.newBuilder().setNumberValue(1.5).build()); assertThat(list.getValues(2)).isEqualTo(Value.newBuilder().setStringValue("test").build()); assertThat(list.getValues(3)).isEqualTo(Value.newBuilder().setBoolValue(true).build()); assertThat(list.getValues(4)).isEqualTo(Value.newBuilder().setStructValue(struct).build()); assertThat(list.getValues(5)).isEqualTo(Value.newBuilder().setListValue(nestedList).build()); break; default: fail("Unexpected value kind: " + value.getKindCase()); } }
Example #12
Source File: ValueTest.java From jackson-datatype-protobuf with Apache License 2.0 | 6 votes |
@Test public void itReadsMixedStruct() throws IOException { String json = "{\"value\":{\"null\":null,\"number\":1.5,\"string\":\"test\",\"boolean\":true,\"struct\":{\"key\":\"nested\"},\"list\":[\"nested\"]}}"; HasValue message = camelCase().readValue(json, HasValue.class); assertThat(message.hasValue()).isTrue(); Value value = message.getValue(); switch (value.getKindCase()) { case STRUCT_VALUE: Map<String, Value> map = value.getStructValue().getFieldsMap(); Value nested = Value.newBuilder().setStringValue("nested").build(); Struct nestedStruct = Struct.newBuilder().putFields("key", nested).build(); ListValue list = ListValue.newBuilder().addValues(nested).build(); assertThat(map.size()).isEqualTo(6); assertThat(map.get("null")).isEqualTo(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()); assertThat(map.get("number")).isEqualTo(Value.newBuilder().setNumberValue(1.5).build()); assertThat(map.get("string")).isEqualTo(Value.newBuilder().setStringValue("test").build()); assertThat(map.get("boolean")).isEqualTo(Value.newBuilder().setBoolValue(true).build()); assertThat(map.get("struct")).isEqualTo(Value.newBuilder().setStructValue(nestedStruct).build()); assertThat(map.get("list")).isEqualTo(Value.newBuilder().setListValue(list).build()); break; default: fail("Unexpected value kind: " + value.getKindCase()); } }
Example #13
Source File: ValueTest.java From jackson-datatype-protobuf with Apache License 2.0 | 6 votes |
@Test public void itWritesMixedListValue() throws IOException { Value nestedValue = Value.newBuilder().setStringValue("nested").build(); Struct struct = Struct.newBuilder().putFields("key", nestedValue).build(); ListValue nestedList = ListValue.newBuilder().addValues(nestedValue).build(); ListValue list = ListValue .newBuilder() .addValues(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()) .addValues(Value.newBuilder().setNumberValue(1.5d).build()) .addValues(Value.newBuilder().setStringValue("test").build()) .addValues(Value.newBuilder().setBoolValue(true).build()) .addValues(Value.newBuilder().setStructValue(struct).build()) .addValues(Value.newBuilder().setListValue(nestedList).build()) .build(); HasValue message = HasValue .newBuilder() .setValue(Value.newBuilder().setListValue(list).build()) .build(); String json = camelCase().writeValueAsString(message); assertThat(json).isEqualTo("{\"value\":[null,1.5,\"test\",true,{\"key\":\"nested\"},[\"nested\"]]}"); }
Example #14
Source File: ValueTest.java From jackson-datatype-protobuf with Apache License 2.0 | 5 votes |
@Test public void itWritesStructValue() throws IOException { Struct struct = Struct.newBuilder().putFields("key", Value.newBuilder().setStringValue("value").build()).build(); HasValue message = HasValue .newBuilder() .setValue(Value.newBuilder().setStructValue(struct).build()) .build(); String json = camelCase().writeValueAsString(message); assertThat(json).isEqualTo("{\"value\":{\"key\":\"value\"}}"); }
Example #15
Source File: ValueTest.java From jackson-datatype-protobuf with Apache License 2.0 | 5 votes |
@Test public void itWritesMixedStruct() throws IOException { Value nestedValue = Value.newBuilder().setStringValue("nested").build(); Struct nestedStruct = Struct.newBuilder().putFields("key", nestedValue).build(); ListValue list = ListValue.newBuilder().addValues(nestedValue).build(); Struct struct = Struct .newBuilder() .putFields("null", Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()) .putFields("number", Value.newBuilder().setNumberValue(1.5d).build()) .putFields("string", Value.newBuilder().setStringValue("test").build()) .putFields("boolean", Value.newBuilder().setBoolValue(true).build()) .putFields("struct", Value.newBuilder().setStructValue(nestedStruct).build()) .putFields("list", Value.newBuilder().setListValue(list).build()) .build(); HasValue message = HasValue .newBuilder() .setValue(Value.newBuilder().setStructValue(struct).build()) .build(); String json = camelCase().writeValueAsString(message); JsonNode node = camelCase().readTree(json).get("value"); assertThat(node.get("null").isNull()).isTrue(); assertThat(node.get("number").isNumber()).isTrue(); assertThat(node.get("number").numberValue().doubleValue()).isEqualTo(1.5d); assertThat(node.get("string").isTextual()).isTrue(); assertThat(node.get("string").textValue()).isEqualTo("test"); assertThat(node.get("boolean").isBoolean()).isTrue(); assertThat(node.get("boolean").booleanValue()).isTrue(); assertThat(node.get("struct").isObject()).isTrue(); assertThat(node.get("struct").size()).isEqualTo(1); assertThat(node.get("struct").get("key").isTextual()).isTrue(); assertThat(node.get("struct").get("key").textValue()).isEqualTo("nested"); assertThat(node.get("list").isArray()).isTrue(); assertThat(node.get("list").size()).isEqualTo(1); assertThat(node.get("list").get(0).isTextual()).isTrue(); assertThat(node.get("list").get(0).textValue()).isEqualTo("nested"); }
Example #16
Source File: XdsClientImplTestForListener.java From grpc-java with Apache License 2.0 | 5 votes |
private static Node getNodeToVerify() { Struct newMetadata = NODE.getMetadata().toBuilder() .putFields("TRAFFICDIRECTOR_PROXYLESS", Value.newBuilder().setStringValue("1").build()) .build(); Address listeningAddress = Address.newBuilder() .setSocketAddress( SocketAddress.newBuilder().setAddress("0.0.0.0").setPortValue(PORT).build()) .build(); return NODE.toBuilder() .setMetadata(newMetadata) .addListeningAddresses(listeningAddress) .build(); }
Example #17
Source File: Bootstrapper.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Converts Java representation of the given JSON value to protobuf's {@link * com.google.protobuf.Value} representation. * * <p>The given {@code rawObject} must be a valid JSON value in Java representation, which is * either a {@code Map<String, ?>}, {@code List<?>}, {@code String}, {@code Double}, * {@code Boolean}, or {@code null}. */ private static Value convertToValue(Object rawObject) { Value.Builder valueBuilder = Value.newBuilder(); if (rawObject == null) { valueBuilder.setNullValue(NullValue.NULL_VALUE); } else if (rawObject instanceof Double) { valueBuilder.setNumberValue((Double) rawObject); } else if (rawObject instanceof String) { valueBuilder.setStringValue((String) rawObject); } else if (rawObject instanceof Boolean) { valueBuilder.setBoolValue((Boolean) rawObject); } else if (rawObject instanceof Map) { Struct.Builder structBuilder = Struct.newBuilder(); @SuppressWarnings("unchecked") Map<String, ?> map = (Map<String, ?>) rawObject; for (Map.Entry<String, ?> entry : map.entrySet()) { structBuilder.putFields(entry.getKey(), convertToValue(entry.getValue())); } valueBuilder.setStructValue(structBuilder); } else if (rawObject instanceof List) { ListValue.Builder listBuilder = ListValue.newBuilder(); List<?> list = (List<?>) rawObject; for (Object obj : list) { listBuilder.addValues(convertToValue(obj)); } valueBuilder.setListValue(listBuilder); } return valueBuilder.build(); }
Example #18
Source File: SdsClient.java From grpc-java with Apache License 2.0 | 5 votes |
@VisibleForTesting static ChannelInfo extractChannelInfo(ConfigSource configSource) { checkNotNull(configSource, "configSource"); checkArgument( configSource.hasApiConfigSource(), "only configSource with ApiConfigSource supported"); ApiConfigSource apiConfigSource = configSource.getApiConfigSource(); checkArgument( ApiType.GRPC.equals(apiConfigSource.getApiType()), "only GRPC ApiConfigSource type supported"); checkArgument( apiConfigSource.getGrpcServicesCount() == 1, "expecting exactly 1 GrpcService in ApiConfigSource"); GrpcService grpcService = apiConfigSource.getGrpcServices(0); checkArgument( grpcService.hasGoogleGrpc() && !grpcService.hasEnvoyGrpc(), "only GoogleGrpc expected in GrpcService"); GoogleGrpc googleGrpc = grpcService.getGoogleGrpc(); CallCredentials callCredentials = getVerifiedCredentials(googleGrpc); String targetUri = googleGrpc.getTargetUri(); String channelType = null; if (googleGrpc.hasConfig()) { Struct struct = googleGrpc.getConfig(); Value value = struct.getFieldsMap().get("channelType"); channelType = value.getStringValue(); } checkArgument(!Strings.isNullOrEmpty(targetUri), "targetUri in GoogleGrpc is empty!"); return new ChannelInfo(targetUri, channelType, callCredentials); }
Example #19
Source File: FileBasedPluginCredential.java From grpc-java with Apache License 2.0 | 5 votes |
private static DataSource buildDataSourceFromConfigStruct(Struct secretValueStruct) { checkNotNull(secretValueStruct, "secretValueStruct"); if (secretValueStruct.containsFields(FILENAME)) { Value value = secretValueStruct.getFieldsOrThrow(FILENAME); return DataSource.newBuilder().setFilename(value.getStringValue()).build(); } else { throw new UnsupportedOperationException("only secret_data of filename type supported"); } }
Example #20
Source File: StructDeserializer.java From jackson-datatype-protobuf with Apache License 2.0 | 5 votes |
@Override protected void populate( Struct.Builder builder, JsonParser parser, DeserializationContext context ) throws IOException { List<Message> entries = readMap(builder, FIELDS_FIELD, parser, context); for (Message entry : entries) { builder.addRepeatedField(FIELDS_FIELD, entry); } }
Example #21
Source File: XdsClientImpl.java From grpc-java with Apache License 2.0 | 5 votes |
/** In case of Listener watcher metadata to be updated to include port. */ private void updateNodeMetadataForListenerRequest(int port) { Struct newMetadata = node.getMetadata().toBuilder() .putFields("TRAFFICDIRECTOR_PROXYLESS", Value.newBuilder().setStringValue("1").build()) .build(); Address listeningAddress = Address.newBuilder() .setSocketAddress( SocketAddress.newBuilder().setAddress("0.0.0.0").setPortValue(port).build()) .build(); node = node.toBuilder().setMetadata(newMetadata).addListeningAddresses(listeningAddress).build(); }
Example #22
Source File: LoadReportClient.java From grpc-java with Apache License 2.0 | 5 votes |
LoadReportClient( InternalLogId logId, String targetName, ManagedChannel channel, Node node, SynchronizationContext syncContext, ScheduledExecutorService scheduledExecutorService, BackoffPolicy.Provider backoffPolicyProvider, Supplier<Stopwatch> stopwatchSupplier) { this.channel = checkNotNull(channel, "channel"); this.syncContext = checkNotNull(syncContext, "syncContext"); this.timerService = checkNotNull(scheduledExecutorService, "timeService"); this.backoffPolicyProvider = checkNotNull(backoffPolicyProvider, "backoffPolicyProvider"); this.stopwatchSupplier = checkNotNull(stopwatchSupplier, "stopwatchSupplier"); this.retryStopwatch = stopwatchSupplier.get(); checkNotNull(targetName, "targetName"); checkNotNull(node, "node"); Struct metadata = node.getMetadata() .toBuilder() .putFields( TARGET_NAME_METADATA_KEY, Value.newBuilder().setStringValue(targetName).build()) .build(); this.node = node.toBuilder().setMetadata(metadata).build(); String logPrefix = checkNotNull(logId, "logId").toString().concat("-lrs-client"); logger = XdsLogger.withPrefix(logPrefix); }
Example #23
Source File: FindDatasetEntitiesTest.java From modeldb with Apache License 2.0 | 5 votes |
/** Validate check for protobuf struct type in KeyValueQuery not implemented */ @Test public void findDatasetVersionStructTypeNotImplemented() { LOGGER.info( "Check for protobuf struct type in KeyValueQuery not implemented test start........"); // Validate check for struct Type not implemented Value numValue = Value.newBuilder().setNumberValue(17.1716586149719).build(); Struct.Builder struct = Struct.newBuilder(); struct.putFields("number_value", numValue); struct.build(); Value structValue = Value.newBuilder().setStructValue(struct).build(); KeyValueQuery keyValueQuery = KeyValueQuery.newBuilder() .setKey("attributes.attribute_1") .setValue(structValue) .setOperator(OperatorEnum.Operator.LTE) .build(); FindDatasetVersions findDatasetVersions = FindDatasetVersions.newBuilder() .addDatasetVersionIds(datasetVersion1.getId()) .addPredicates(keyValueQuery) .build(); try { datasetVersionServiceStub.findDatasetVersions(findDatasetVersions); fail(); } catch (StatusRuntimeException exc) { Status status = Status.fromThrowable(exc); assertEquals(Status.UNIMPLEMENTED.getCode(), status.getCode()); } LOGGER.info( "Check for protobuf struct type in KeyValueQuery not implemented test stop........"); }
Example #24
Source File: StructSerializer.java From jackson-datatype-protobuf with Apache License 2.0 | 5 votes |
@Override public void serialize( Struct struct, JsonGenerator generator, SerializerProvider serializerProvider ) throws IOException { writeMap(FIELDS_FIELD, struct.getField(FIELDS_FIELD), generator, serializerProvider); }
Example #25
Source File: FindDatasetEntitiesTest.java From modeldb with Apache License 2.0 | 5 votes |
/** Validate check for protobuf struct type in KeyValueQuery not implemented */ @Test public void findDatasetStructTypeNotImplemented() { LOGGER.info( "check for protobuf struct type in KeyValueQuery not implemented test start........"); DatasetTest datasetTest = new DatasetTest(); // Validate check for struct Type not implemented Value numValue = Value.newBuilder().setNumberValue(17.1716586149719).build(); Struct.Builder struct = Struct.newBuilder(); struct.putFields("number_value", numValue); struct.build(); Value structValue = Value.newBuilder().setStructValue(struct).build(); KeyValueQuery keyValueQuery = KeyValueQuery.newBuilder() .setKey("attributes.attribute_1") .setValue(structValue) .setOperator(OperatorEnum.Operator.LTE) .build(); FindDatasets findDatasets = FindDatasets.newBuilder() .addDatasetIds(dataset1.getId()) .addPredicates(keyValueQuery) .build(); try { datasetServiceStub.findDatasets(findDatasets); fail(); } catch (StatusRuntimeException exc) { Status status = Status.fromThrowable(exc); assertEquals(Status.UNIMPLEMENTED.getCode(), status.getCode()); } LOGGER.info( "check for protobuf struct type in KeyValueQuery not implemented test start........"); }
Example #26
Source File: FindProjectEntitiesTest.java From modeldb with Apache License 2.0 | 5 votes |
/** Validate check for protobuf struct type in KeyValueQuery not implemented */ @Test public void findExperimentRunStructTypeNotImplemented() { LOGGER.info( "Check for protobuf struct type in KeyValueQuery not implemented test start......."); // Validate check for struct Type not implemented Value numValue = Value.newBuilder().setNumberValue(17.1716586149719).build(); Struct.Builder struct = Struct.newBuilder(); struct.putFields("number_value", numValue); struct.build(); Value structValue = Value.newBuilder().setStructValue(struct).build(); KeyValueQuery keyValueQuery = KeyValueQuery.newBuilder() .setKey("metrics.loss") .setValue(structValue) .setOperator(OperatorEnum.Operator.LTE) .build(); FindExperimentRuns findExperimentRuns = FindExperimentRuns.newBuilder() .setProjectId(project1.getId()) .setExperimentId(experiment1.getId()) .addPredicates(keyValueQuery) .build(); try { experimentRunServiceStub.findExperimentRuns(findExperimentRuns); fail(); } catch (StatusRuntimeException exc) { Status status = Status.fromThrowable(exc); assertEquals(Status.UNIMPLEMENTED.getCode(), status.getCode()); } LOGGER.info("Check for protobuf struct type in KeyValueQuery not implemented test stop......."); }
Example #27
Source File: StructTest.java From jackson-datatype-protobuf with Apache License 2.0 | 5 votes |
@Test public void itWritesAllStructValueTypes() throws IOException { Value nestedValue = Value.newBuilder().setStringValue("nested").build(); Struct nestedStruct = Struct.newBuilder().putFields("key", nestedValue).build(); ListValue list = ListValue.newBuilder().addValues(nestedValue).build(); Struct struct = Struct .newBuilder() .putFields("null", Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()) .putFields("number", Value.newBuilder().setNumberValue(1.5d).build()) .putFields("string", Value.newBuilder().setStringValue("test").build()) .putFields("boolean", Value.newBuilder().setBoolValue(true).build()) .putFields("struct", Value.newBuilder().setStructValue(nestedStruct).build()) .putFields("list", Value.newBuilder().setListValue(list).build()) .build(); HasStruct message = HasStruct .newBuilder() .setStruct(struct) .build(); String json = camelCase().writeValueAsString(message); JsonNode node = camelCase().readTree(json).get("struct"); assertThat(node.get("null").isNull()).isTrue(); assertThat(node.get("number").isNumber()).isTrue(); assertThat(node.get("number").numberValue().doubleValue()).isEqualTo(1.5d); assertThat(node.get("string").isTextual()).isTrue(); assertThat(node.get("string").textValue()).isEqualTo("test"); assertThat(node.get("boolean").isBoolean()).isTrue(); assertThat(node.get("boolean").booleanValue()).isTrue(); assertThat(node.get("struct").isObject()).isTrue(); assertThat(node.get("struct").size()).isEqualTo(1); assertThat(node.get("struct").get("key").isTextual()).isTrue(); assertThat(node.get("struct").get("key").textValue()).isEqualTo("nested"); assertThat(node.get("list").isArray()).isTrue(); assertThat(node.get("list").size()).isEqualTo(1); assertThat(node.get("list").get(0).isTextual()).isTrue(); assertThat(node.get("list").get(0).textValue()).isEqualTo("nested"); }
Example #28
Source File: FindProjectEntitiesTest.java From modeldb with Apache License 2.0 | 5 votes |
/** Validate check for protobuf struct type in KeyValueQuery not implemented */ @Test public void findExperimentsStructTypeNotImplemented() { LOGGER.info( "Check for protobuf struct type in KeyValueQuery not implemented in findExperiments test start........"); // Validate check for struct Type not implemented List<KeyValueQuery> predicates = new ArrayList<>(); Value numValue = Value.newBuilder().setNumberValue(17.1716586149719).build(); Struct.Builder struct = Struct.newBuilder(); struct.putFields("number_value", numValue); struct.build(); Value structValue = Value.newBuilder().setStructValue(struct).build(); KeyValueQuery keyValueQuery = KeyValueQuery.newBuilder() .setKey("attributes.attribute_1") .setValue(structValue) .setOperator(OperatorEnum.Operator.LTE) .build(); predicates.add(keyValueQuery); FindExperiments findExperiments = FindExperiments.newBuilder() .setProjectId(project1.getId()) .addAllPredicates(predicates) .build(); try { experimentServiceStub.findExperiments(findExperiments); fail(); } catch (StatusRuntimeException exc) { Status status = Status.fromThrowable(exc); assertEquals(Status.UNIMPLEMENTED.getCode(), status.getCode()); } LOGGER.info( "Check for protobuf struct type in KeyValueQuery not implemented in findExperiments test stop........"); }
Example #29
Source File: FindProjectEntitiesTest.java From modeldb with Apache License 2.0 | 5 votes |
/** Validate check for protobuf struct type in KeyValueQuery not implemented */ @Test public void findProjectStructTypeNotImplemented() { LOGGER.info( "check for protobuf struct type in KeyValueQuery not implemented test start................................"); // Validate check for struct Type not implemented List<KeyValueQuery> predicates = new ArrayList<>(); Value numValue = Value.newBuilder().setNumberValue(17.1716586149719).build(); Struct.Builder struct = Struct.newBuilder(); struct.putFields("number_value", numValue); struct.build(); Value structValue = Value.newBuilder().setStructValue(struct).build(); KeyValueQuery keyValueQuery = KeyValueQuery.newBuilder() .setKey("attributes.attribute_1") .setValue(structValue) .setOperator(OperatorEnum.Operator.LTE) .build(); predicates.add(keyValueQuery); FindProjects findProjects = FindProjects.newBuilder() .addProjectIds(project1.getId()) .addAllPredicates(predicates) .build(); try { projectServiceStub.findProjects(findProjects); fail(); } catch (StatusRuntimeException exc) { Status status = Status.fromThrowable(exc); assertEquals(Status.UNIMPLEMENTED.getCode(), status.getCode()); } LOGGER.info( "check for protobuf struct type in KeyValueQuery not implemented test stop................................"); }
Example #30
Source File: TestResources.java From java-control-plane with Apache License 2.0 | 5 votes |
private static Struct messageAsStruct(MessageOrBuilder message) { try { String json = JsonFormat.printer() .preservingProtoFieldNames() .print(message); Struct.Builder structBuilder = Struct.newBuilder(); JsonFormat.parser().merge(json, structBuilder); return structBuilder.build(); } catch (InvalidProtocolBufferException e) { throw new RuntimeException("Failed to convert protobuf message to struct", e); } }