com.google.protobuf.UInt32Value Java Examples

The following examples show how to use com.google.protobuf.UInt32Value. 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: DefaultAppAutoScalingCallbackService.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<ScalableTargetResourceInfo> setScalableTargetResourceInfo(String jobId,
                                                                            ScalableTargetResourceInfo scalableTargetResourceInfo,
                                                                            CallMetadata callMetadata) {
    logger.info("(BEFORE setting job instances) for jobId {} :: {}", jobId, scalableTargetResourceInfo);
    JobCapacityWithOptionalAttributes jobCapacityWithOptionalAttributes = JobCapacityWithOptionalAttributes.newBuilder()
            .setDesired(UInt32Value.newBuilder().setValue(scalableTargetResourceInfo.getDesiredCapacity()).build()).build();
    JobCapacityUpdateWithOptionalAttributes jobCapacityRequest = JobCapacityUpdateWithOptionalAttributes.newBuilder()
            .setJobId(jobId)
            .setJobCapacityWithOptionalAttributes(jobCapacityWithOptionalAttributes).build();
    return jobServiceGateway.updateJobCapacityWithOptionalAttributes(jobCapacityRequest, callMetadata)
            .andThen(getScalableTargetResourceInfo(jobId, callMetadata).map(scalableTargetResourceInfoReturned -> {
                scalableTargetResourceInfoReturned.setScalingStatus(ScalingStatus.Pending.name());
                logger.info("(set job instances) Returning value Instances for jobId {} :: {}", jobId, scalableTargetResourceInfo);
                return scalableTargetResourceInfoReturned;
            }));
}
 
Example #2
Source File: GoogleCloudStorageGrpcReadChannelTest.java    From hadoop-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void multipleSequentialsReadsSucceedWithValidObjectChecksum() throws Exception {
  fakeService.setObject(
      DEFAULT_OBJECT.toBuilder()
          .setCrc32C(UInt32Value.newBuilder().setValue(DEFAULT_OBJECT_CRC32C))
          .build());
  GoogleCloudStorageReadOptions options =
      GoogleCloudStorageReadOptions.builder().setGrpcChecksumsEnabled(true).build();
  GoogleCloudStorageGrpcReadChannel readChannel = newReadChannel(options);

  ByteBuffer firstBuffer = ByteBuffer.allocate(100);
  ByteBuffer secondBuffer = ByteBuffer.allocate(OBJECT_SIZE - 100);
  readChannel.read(firstBuffer);
  readChannel.read(secondBuffer);

  assertArrayEquals(fakeService.data.substring(0, 100).toByteArray(), firstBuffer.array());
  assertArrayEquals(fakeService.data.substring(100).toByteArray(), secondBuffer.array());
}
 
Example #3
Source File: GoogleCloudStorageGrpcReadChannelTest.java    From hadoop-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void multipleReadsIgnoreObjectChecksumForLatestGenerationReads() throws Exception {
  fakeService.setObject(
      DEFAULT_OBJECT.toBuilder().setCrc32C(UInt32Value.newBuilder().setValue(0)).build());
  GoogleCloudStorageReadOptions options =
      GoogleCloudStorageReadOptions.builder().setGrpcChecksumsEnabled(true).build();
  GoogleCloudStorageGrpcReadChannel readChannel = newReadChannel(options);

  ByteBuffer firstBuffer = ByteBuffer.allocate(100);
  ByteBuffer secondBuffer = ByteBuffer.allocate(OBJECT_SIZE - 100);
  readChannel.read(firstBuffer);
  readChannel.read(secondBuffer);

  assertArrayEquals(fakeService.data.substring(0, 100).toByteArray(), firstBuffer.array());
  assertArrayEquals(fakeService.data.substring(100).toByteArray(), secondBuffer.array());
}
 
Example #4
Source File: GoogleCloudStorageGrpcWriteChannelTest.java    From hadoop-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void writeSendsSingleInsertObjectRequest() throws Exception {
  GoogleCloudStorageGrpcWriteChannel writeChannel = newWriteChannel();

  ByteString data = ByteString.copyFromUtf8("test data");
  writeChannel.initialize();
  writeChannel.write(data.asReadOnlyByteBuffer());
  writeChannel.close();

  InsertObjectRequest expectedInsertRequest =
      InsertObjectRequest.newBuilder()
          .setUploadId(UPLOAD_ID)
          .setChecksummedData(
              ChecksummedData.newBuilder()
                  .setContent(data)
                  .setCrc32C(UInt32Value.newBuilder().setValue(uInt32Value(863614154))))
          .setObjectChecksums(
              ObjectChecksums.newBuilder()
                  .setCrc32C(UInt32Value.newBuilder().setValue(uInt32Value(863614154))))
          .setFinishWrite(true)
          .build();

  verify(fakeService, times(1)).startResumableWrite(eq(START_REQUEST), any());
  verify(fakeService.insertRequestObserver, times(1)).onNext(expectedInsertRequest);
  verify(fakeService.insertRequestObserver, atLeast(1)).onCompleted();
}
 
Example #5
Source File: XdsClientTestHelper.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
static io.envoyproxy.envoy.api.v2.endpoint.LocalityLbEndpoints buildLocalityLbEndpoints(
    String region, String zone, String subZone,
    List<io.envoyproxy.envoy.api.v2.endpoint.LbEndpoint> lbEndpoints,
    int loadBalancingWeight, int priority) {
  return
      io.envoyproxy.envoy.api.v2.endpoint.LocalityLbEndpoints.newBuilder()
          .setLocality(
              io.envoyproxy.envoy.api.v2.core.Locality.newBuilder()
                  .setRegion(region)
                  .setZone(zone)
                  .setSubZone(subZone))
          .addAllLbEndpoints(lbEndpoints)
          .setLoadBalancingWeight(UInt32Value.of(loadBalancingWeight))
          .setPriority(priority)
          .build();
}
 
Example #6
Source File: JobManagementSpringResourceTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetCapacityWithOptionalAttributes() throws Exception {
    JobCapacityWithOptionalAttributes restRequest = JobCapacityWithOptionalAttributes.newBuilder()
            .setMin(UInt32Value.newBuilder().setValue(1).build())
            .setDesired(UInt32Value.newBuilder().setValue(2).build())
            .setMax(UInt32Value.newBuilder().setValue(3).build())
            .build();
    JobCapacityUpdateWithOptionalAttributes forwardedRequest = JobCapacityUpdateWithOptionalAttributes.newBuilder()
            .setJobId(JOB_ID_1)
            .setJobCapacityWithOptionalAttributes(restRequest)
            .build();

    when(jobServiceGatewayMock.updateJobCapacityWithOptionalAttributes(forwardedRequest, JUNIT_REST_CALL_METADATA)).thenReturn(Completable.complete());
    SpringMockMvcUtil.doPut(mockMvc, String.format("/api/v3/jobs/%s/capacityAttributes", JOB_ID_1), restRequest);

    verify(jobServiceGatewayMock, times(1)).updateJobCapacityWithOptionalAttributes(forwardedRequest, JUNIT_REST_CALL_METADATA);
}
 
Example #7
Source File: JobScenarioBuilder.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public JobScenarioBuilder updateJobCapacityMax(int max, int unchangedMin, int unchangedDesired) {
    logger.info("[{}] Changing job {} capacity max to {}...", discoverActiveTest(), jobId, max);
    Stopwatch stopWatch = Stopwatch.createStarted();

    TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();

    client.updateJobCapacityWithOptionalAttributes(
            JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId)
                    .setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setMax(UInt32Value.newBuilder().setValue(max).build()).build()).build(),
            responseObserver);

    rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));

    expectJobUpdateEvent(job -> {
        ServiceJobExt ext = (ServiceJobExt) job.getJobDescriptor().getExtensions();
        Capacity capacity = ext.getCapacity();
        return capacity.getMax() == max && capacity.getMin() == unchangedMin && capacity.getDesired() == unchangedDesired;
    }, "Job capacity update did not complete in time");

    logger.info("[{}] Job {} scaled to new max size in {}ms", discoverActiveTest(), jobId, stopWatch.elapsed(TimeUnit.MILLISECONDS));
    return this;
}
 
Example #8
Source File: JobScenarioBuilder.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public JobScenarioBuilder updateJobCapacityMin(int min, int unchangedMax, int unchangedDesired) {
    logger.info("[{}] Changing job {} capacity min to {}...", discoverActiveTest(), jobId, min);
    Stopwatch stopWatch = Stopwatch.createStarted();

    TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();

    client.updateJobCapacityWithOptionalAttributes(
            JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId)
                    .setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setMin(UInt32Value.newBuilder().setValue(min).build()).build()).build(),
            responseObserver);

    rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));

    expectJobUpdateEvent(job -> {
        ServiceJobExt ext = (ServiceJobExt) job.getJobDescriptor().getExtensions();
        Capacity capacity = ext.getCapacity();
        return capacity.getMin() == min && capacity.getMax() == unchangedMax && capacity.getDesired() == unchangedDesired;
    }, "Job capacity update did not complete in time");

    logger.info("[{}] Job {} scaled to new min size in {}ms", discoverActiveTest(), jobId, stopWatch.elapsed(TimeUnit.MILLISECONDS));
    return this;
}
 
Example #9
Source File: JobScenarioBuilder.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public JobScenarioBuilder updateJobCapacityMaxInvalid(int targetMax) {
    logger.info("[{}] Changing job {} capacity max to {}...", discoverActiveTest(), jobId, targetMax);
    TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
    client.updateJobCapacityWithOptionalAttributes(
            JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId)
                    .setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setMax(UInt32Value.newBuilder().setValue(targetMax).build()).build()).build(),
            responseObserver);

    await().timeout(TIMEOUT_MS, TimeUnit.MILLISECONDS).until(responseObserver::hasError);
    Throwable error = responseObserver.getError();
    assertThat(error).isNotNull();
    assertThat(error).isInstanceOf(StatusRuntimeException.class);
    StatusRuntimeException statusRuntimeException = (StatusRuntimeException) error;
    assertThat(statusRuntimeException.getStatus().getCode() == Status.Code.INVALID_ARGUMENT).isTrue();

    return this;
}
 
Example #10
Source File: JobScenarioBuilder.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public JobScenarioBuilder updateJobCapacityDesiredInvalid(int targetDesired, int currentDesired) {
    logger.info("[{}] Changing job {} capacity desired to {}...", discoverActiveTest(), jobId, targetDesired);
    TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
    client.updateJobCapacityWithOptionalAttributes(
            JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId)
                    .setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setDesired(UInt32Value.newBuilder().setValue(targetDesired).build()).build()).build(),
            responseObserver);

    await().timeout(TIMEOUT_MS, TimeUnit.MILLISECONDS).until(responseObserver::hasError);
    Throwable error = responseObserver.getError();
    assertThat(error).isNotNull();
    assertThat(error).isInstanceOf(StatusRuntimeException.class);
    StatusRuntimeException statusRuntimeException = (StatusRuntimeException) error;
    assertThat(statusRuntimeException.getStatus().getCode() == Status.Code.INVALID_ARGUMENT).isTrue();

    // Make sure desired count is unchanged
    Job job = getJob();
    JobDescriptor.JobDescriptorExt ext = job.getJobDescriptor().getExtensions();
    int currentCapacity = ext instanceof BatchJobExt ? ((BatchJobExt) ext).getSize() : ((ServiceJobExt) ext).getCapacity().getDesired();
    assertThat(currentCapacity).isEqualTo(currentDesired);
    return this;
}
 
Example #11
Source File: JobScenarioBuilder.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
public JobScenarioBuilder updateJobCapacityDesired(int desired, int unchangedMin, int unchangedMax) {
    logger.info("[{}] Changing job {} capacity desired to {}...", discoverActiveTest(), jobId, desired);
    Stopwatch stopWatch = Stopwatch.createStarted();

    TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();

    client.updateJobCapacityWithOptionalAttributes(
            JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId)
                    .setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setDesired(UInt32Value.newBuilder().setValue(desired).build()).build()).build(),
            responseObserver);

    rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));

    expectJobUpdateEvent(job -> {
        ServiceJobExt ext = (ServiceJobExt) job.getJobDescriptor().getExtensions();
        Capacity capacity = ext.getCapacity();
        return capacity.getDesired() == desired && capacity.getMin() == unchangedMin && capacity.getMax() == unchangedMax;
    }, "Job capacity update did not complete in time");

    logger.info("[{}] Job {} scaled to new desired size in {}ms", discoverActiveTest(), jobId, stopWatch.elapsed(TimeUnit.MILLISECONDS));
    return this;
}
 
Example #12
Source File: EnvoyServerProtoDataTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
private static FilterChain createInFilter() {
  FilterChain filterChain =
      FilterChain.newBuilder()
          .setFilterChainMatch(
              FilterChainMatch.newBuilder()
                  .setDestinationPort(UInt32Value.of(8000))
                  .addPrefixRanges(CidrRange.newBuilder()
                      .setAddressPrefix("10.20.0.15")
                      .setPrefixLen(UInt32Value.of(32))
                      .build())
                  .addApplicationProtocols("managed-mtls")
                  .build())
          .setTransportSocket(TransportSocket.newBuilder().setName("tls")
              .setTypedConfig(Any.pack(CommonTlsContextTestsUtil.buildTestDownstreamTlsContext()))
              .build())
          .addFilters(Filter.newBuilder()
              .setName("envoy.http_connection_manager")
              .setTypedConfig(Any.newBuilder()
                  .setTypeUrl(
                      "type.googleapis.com/envoy.config.filter.network.http_connection_manager"
                          + ".v2.HttpConnectionManager"))
              .build())
          .build();
  return filterChain;
}
 
Example #13
Source File: EnvoyServerProtoDataTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private static FilterChain createDeprecatedInFilter() {
  FilterChain filterChain =
      FilterChain.newBuilder()
          .setFilterChainMatch(
              FilterChainMatch.newBuilder()
                  .setDestinationPort(UInt32Value.of(8000))
                  .addPrefixRanges(CidrRange.newBuilder()
                      .setAddressPrefix("10.20.0.15")
                      .setPrefixLen(UInt32Value.of(32)).build())
                  .addApplicationProtocols("managed-mtls")
                  .build())
          .setTlsContext(CommonTlsContextTestsUtil.buildTestDownstreamTlsContext())
          .addFilters(Filter.newBuilder()
              .setName("envoy.http_connection_manager")
              .setTypedConfig(Any.newBuilder()
                  .setTypeUrl(
                      "type.googleapis.com/envoy.config.filter.network.http_connection_manager"
                          + ".v2.HttpConnectionManager"))
              .build())
          .build();
  return filterChain;
}
 
Example #14
Source File: WrappedPrimitiveTest.java    From jackson-datatype-protobuf with Apache License 2.0 6 votes vote down vote up
@Test
public void itSetsFieldsWhenZeroInJson() throws IOException {
  String json = camelCase().writeValueAsString(defaultPopulatedJsonNode(camelCase()));
  HasWrappedPrimitives message = camelCase().readValue(json, HasWrappedPrimitives.class);
  assertThat(message.hasDoubleWrapper()).isTrue();
  assertThat(message.getDoubleWrapper()).isEqualTo(DoubleValue.getDefaultInstance());
  assertThat(message.hasFloatWrapper()).isTrue();
  assertThat(message.getFloatWrapper()).isEqualTo(FloatValue.getDefaultInstance());
  assertThat(message.hasInt64Wrapper()).isTrue();
  assertThat(message.getInt64Wrapper()).isEqualTo(Int64Value.getDefaultInstance());
  assertThat(message.hasUint64Wrapper()).isTrue();
  assertThat(message.getUint64Wrapper()).isEqualTo(UInt64Value.getDefaultInstance());
  assertThat(message.hasInt32Wrapper()).isTrue();
  assertThat(message.getInt32Wrapper()).isEqualTo(Int32Value.getDefaultInstance());
  assertThat(message.hasUint32Wrapper()).isTrue();
  assertThat(message.getUint32Wrapper()).isEqualTo(UInt32Value.getDefaultInstance());
  assertThat(message.hasBoolWrapper()).isTrue();
  assertThat(message.getBoolWrapper()).isEqualTo(BoolValue.getDefaultInstance());
  assertThat(message.hasStringWrapper()).isTrue();
  assertThat(message.getStringWrapper()).isEqualTo(StringValue.getDefaultInstance());
  assertThat(message.hasBytesWrapper()).isTrue();
  assertThat(message.getBytesWrapper()).isEqualTo(BytesValue.getDefaultInstance());
}
 
Example #15
Source File: WrappedPrimitiveTest.java    From jackson-datatype-protobuf with Apache License 2.0 5 votes vote down vote up
private static HasWrappedPrimitives defaultPopulatedMessage() {
  return HasWrappedPrimitives
          .newBuilder()
          .setDoubleWrapper(DoubleValue.getDefaultInstance())
          .setFloatWrapper(FloatValue.getDefaultInstance())
          .setInt64Wrapper(Int64Value.getDefaultInstance())
          .setUint64Wrapper(UInt64Value.getDefaultInstance())
          .setInt32Wrapper(Int32Value.getDefaultInstance())
          .setUint32Wrapper(UInt32Value.getDefaultInstance())
          .setBoolWrapper(BoolValue.getDefaultInstance())
          .setStringWrapper(StringValue.getDefaultInstance())
          .setBytesWrapper(BytesValue.getDefaultInstance())
          .build();
}
 
Example #16
Source File: EnvoyServerProtoDataTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private static FilterChain createOutFilter() {
  FilterChain filterChain =
      FilterChain.newBuilder()
          .setFilterChainMatch(
              FilterChainMatch.newBuilder()
                  .setDestinationPort(UInt32Value.of(8000))
                  .build())
          .addFilters(Filter.newBuilder()
              .setName("envoy.http_connection_manager")
              .build())
          .build();
  return filterChain;
}
 
Example #17
Source File: XdsClientTestHelper.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
static io.envoyproxy.envoy.api.v2.endpoint.LbEndpoint buildLbEndpoint(String address,
    int port, HealthStatus healthStatus, int loadbalancingWeight) {
  return
      io.envoyproxy.envoy.api.v2.endpoint.LbEndpoint.newBuilder()
          .setEndpoint(
              io.envoyproxy.envoy.api.v2.endpoint.Endpoint.newBuilder().setAddress(
                  Address.newBuilder().setSocketAddress(
                      SocketAddress.newBuilder().setAddress(address).setPortValue(port))))
          .setHealthStatus(healthStatus)
          .setLoadBalancingWeight(UInt32Value.of(loadbalancingWeight))
          .build();
}
 
Example #18
Source File: XdsNameResolverIntegrationTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a RouteAction for a weighted cluster route. The given map is keyed by cluster name and
 * valued by the weight of the cluster.
 */
private static RouteAction buildWeightedClusterRoute(Map<String, Integer> clusterWeights) {
  WeightedCluster.Builder builder = WeightedCluster.newBuilder();
  for (Map.Entry<String, Integer> entry : clusterWeights.entrySet()) {
    builder.addClusters(
        ClusterWeight.newBuilder()
          .setName(entry.getKey())
          .setWeight(UInt32Value.of(entry.getValue())));
  }
  return RouteAction.newBuilder()
      .setWeightedClusters(builder)
      .build();
}
 
Example #19
Source File: EnvoyProtoDataTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void convertClusterWeight() {
  io.envoyproxy.envoy.api.v2.route.WeightedCluster.ClusterWeight proto =
      io.envoyproxy.envoy.api.v2.route.WeightedCluster.ClusterWeight.newBuilder()
          .setName("cluster-foo")
          .setWeight(UInt32Value.newBuilder().setValue(30)).build();
  ClusterWeight struct = ClusterWeight.fromEnvoyProtoClusterWeight(proto);
  assertThat(struct.getName()).isEqualTo("cluster-foo");
  assertThat(struct.getWeight()).isEqualTo(30);
}
 
Example #20
Source File: XdsClientImplTestForListener.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
static FilterChainMatch buildFilterChainMatch(int destPort, CidrRange...prefixRanges) {
  return
      FilterChainMatch.newBuilder()
          .setDestinationPort(UInt32Value.of(destPort))
          .addAllPrefixRanges(Arrays.asList(prefixRanges))
          .build();
}
 
Example #21
Source File: GoogleCloudStorageGrpcReadChannelTest.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public void getObjectMedia(
    GetObjectMediaRequest request, StreamObserver<GetObjectMediaResponse> responseObserver) {
  if (getMediaException != null) {
    responseObserver.onError(getMediaException);
  } else {
    int readStart = (int) request.getReadOffset();
    int readEnd =
        request.getReadLimit() > 0
            ? (int) Math.min(object.getSize(), readStart + request.getReadLimit())
            : (int) object.getSize();
    for (int position = readStart; position < readEnd; position += CHUNK_SIZE) {
      ByteString messageData =
          data.substring(position, Math.min((int) object.getSize(), position + CHUNK_SIZE));
      int crc32c = Hashing.crc32c().hashBytes(messageData.toByteArray()).asInt();
      if (alterMessageChecksum) {
        crc32c += 1;
      }
      GetObjectMediaResponse response =
          GetObjectMediaResponse.newBuilder()
              .setChecksummedData(
                  ChecksummedData.newBuilder()
                      .setContent(messageData)
                      .setCrc32C(UInt32Value.newBuilder().setValue(crc32c)))
              .build();
      responseObserver.onNext(response);
    }
    responseObserver.onCompleted();
  }
}
 
Example #22
Source File: GoogleCloudStorageGrpcReadChannelTest.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void singleReadSucceedsWithValidObjectChecksum() throws Exception {
  fakeService.setObject(
      DEFAULT_OBJECT.toBuilder()
          .setCrc32C(UInt32Value.newBuilder().setValue(DEFAULT_OBJECT_CRC32C))
          .build());
  GoogleCloudStorageReadOptions options =
      GoogleCloudStorageReadOptions.builder().setGrpcChecksumsEnabled(true).build();
  GoogleCloudStorageGrpcReadChannel readChannel = newReadChannel(options);

  ByteBuffer buffer = ByteBuffer.allocate(OBJECT_SIZE);
  readChannel.read(buffer);

  assertArrayEquals(fakeService.data.toByteArray(), buffer.array());
}
 
Example #23
Source File: GoogleCloudStorageGrpcReadChannelTest.java    From hadoop-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void partialReadSucceedsWithInvalidObjectChecksum() throws Exception {
  fakeService.setObject(
      DEFAULT_OBJECT.toBuilder().setCrc32C(UInt32Value.newBuilder().setValue(0)).build());
  GoogleCloudStorageReadOptions options =
      GoogleCloudStorageReadOptions.builder().setGrpcChecksumsEnabled(true).build();
  GoogleCloudStorageGrpcReadChannel readChannel = newReadChannel(options);

  ByteBuffer buffer = ByteBuffer.allocate(OBJECT_SIZE - 10);
  readChannel.read(buffer);

  assertArrayEquals(
      fakeService.data.substring(0, OBJECT_SIZE - 10).toByteArray(), buffer.array());
}
 
Example #24
Source File: Model.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the service config based on a sequence of sources of heterogeneous types. Sources of the
 * same type will be merged together, and those applicable to the framework will be attached to
 * it.
 */
public void setConfigSources(Iterable<ConfigSource> configs) {

  // Merge configs of same type.
  Map<Descriptor, ConfigSource.Builder> mergedConfigs = Maps.newHashMap();
  for (ConfigSource config : configs) {
    Descriptor descriptor = config.getConfig().getDescriptorForType();
    ConfigSource.Builder builder = mergedConfigs.get(descriptor);
    if (builder == null) {
      mergedConfigs.put(descriptor, config.toBuilder());
    } else if (experiments.isExperimentEnabled(PROTO3_CONFIG_MERGING_EXPERIMENT)) {
      builder.mergeFromWithProto3Semantics(config);
    } else {
      builder.mergeFrom(config);
    }
  }

  // Pick the configs we know and care about (currently, Service and Legacy).
  ConfigSource.Builder serviceConfig = mergedConfigs.get(Service.getDescriptor());
  if (serviceConfig != null) {
    setServiceConfig(serviceConfig.build());
  } else {
    // Set empty config.
    setServiceConfig(
        ConfigSource.newBuilder(
                Service.newBuilder()
                    .setConfigVersion(
                        UInt32Value.newBuilder().setValue(Model.getDefaultConfigVersion()))
                    .build())
            .build());
  }

}
 
Example #25
Source File: TopLevelBuilder.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
/** Sets special configuration needed for 3rd party Endpoints APIs. */
private void applyThirdPartyApiSettings(Service.Builder serviceBuilder) {
  serviceBuilder.getControlBuilder().setEnvironment(ControlConfigUtil.PROD_SERVICE_CONTROL);

  // Set the config version to 3.
  serviceBuilder.setConfigVersion(
      UInt32Value.newBuilder().setValue(TOOLS_CONFIG_VERSION).build());
}
 
Example #26
Source File: WellKnownTypeMarshaller.java    From curiostack with MIT License 4 votes vote down vote up
UInt32ValueMarshaller() {
  super(UInt32Value.getDefaultInstance());
}
 
Example #27
Source File: WellKnownTypeMarshaller.java    From curiostack with MIT License 4 votes vote down vote up
@Override
protected final void doMerge(JsonParser parser, int unused, Message.Builder messageBuilder)
    throws IOException {
  UInt32Value.Builder builder = (UInt32Value.Builder) messageBuilder;
  builder.setValue(ParseSupport.parseUInt32(parser));
}
 
Example #28
Source File: AllMapValuesTest.java    From jackson-datatype-protobuf with Apache License 2.0 4 votes vote down vote up
private static HasAllMapValues hasAllMapValues() {
  Value value = Value.newBuilder().setStringValue("test").build();
  ByteString byteString = ByteString.copyFromUtf8("test");
  Any any = Any
          .newBuilder()
          .setTypeUrl("type.googleapis.com/google.protobuf.Value")
          .setValue(value.toByteString())
          .build();
  return HasAllMapValues
          .newBuilder()
          .putDoubleMap("double", 1.5d)
          .putFloatMap("float", 2.5f)
          .putInt32Map("int32", 1)
          .putInt64Map("int64", 2)
          .putUint32Map("uint32", 3)
          .putUint64Map("uint64", 4)
          .putSint32Map("sint32", 5)
          .putSint64Map("sint64", 6)
          .putFixed32Map("fixed32", 7)
          .putFixed64Map("fixed64", 8)
          .putSfixed32Map("sfixed32", 9)
          .putSfixed64Map("sfixed64", 10)
          .putBoolMap("bool", true)
          .putStringMap("string", "test")
          .putBytesMap("bytes", byteString)
          .putAnyMap("any", any)
          .putDurationMap("duration", Duration.newBuilder().setSeconds(30).build())
          .putFieldMaskMap("field_mask", FieldMask.newBuilder().addPaths("path_one").addPaths("path_two").build())
          .putListValueMap("list_value", ListValue.newBuilder().addValues(value).build())
          .putNullValueMap("null_value", NullValue.NULL_VALUE)
          .putStructMap("struct", Struct.newBuilder().putFields("field", value).build())
          .putTimestampMap("timestamp", Timestamp.newBuilder().setSeconds(946684800).build())
          .putValueMap("value", value)
          .putDoubleWrapperMap("double_wrapper", DoubleValue.newBuilder().setValue(3.5d).build())
          .putFloatWrapperMap("float_wrapper", FloatValue.newBuilder().setValue(4.5f).build())
          .putInt32WrapperMap("int32_wrapper", Int32Value.newBuilder().setValue(11).build())
          .putInt64WrapperMap("int64_wrapper", Int64Value.newBuilder().setValue(12).build())
          .putUint32WrapperMap("uint32_wrapper", UInt32Value.newBuilder().setValue(13).build())
          .putUint64WrapperMap("uint64_wrapper", UInt64Value.newBuilder().setValue(14).build())
          .putBoolWrapperMap("bool_wrapper", BoolValue.newBuilder().setValue(true).build())
          .putStringWrapperMap("string_wrapper", StringValue.newBuilder().setValue("test").build())
          .putBytesWrapperMap("bytes_wrapper", BytesValue.newBuilder().setValue(byteString).build())
          .putEnumMap("enum", EnumProto3.FIRST)
          .putProto2MessageMap("proto2", AllFields.newBuilder().setString("proto2").build())
          .putProto3MessageMap("proto3", AllFieldsProto3.newBuilder().setString("proto3").build())
          .build();
}
 
Example #29
Source File: ProtobufModule.java    From jackson-datatype-protobuf with Apache License 2.0 4 votes vote down vote up
@Override
public void setupModule(SetupContext context) {
  SimpleSerializers serializers = new SimpleSerializers();
  serializers.addSerializer(new MessageSerializer(config));
  serializers.addSerializer(new DurationSerializer());
  serializers.addSerializer(new FieldMaskSerializer());
  serializers.addSerializer(new ListValueSerializer());
  serializers.addSerializer(new NullValueSerializer());
  serializers.addSerializer(new StructSerializer());
  serializers.addSerializer(new TimestampSerializer());
  serializers.addSerializer(new ValueSerializer());
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(DoubleValue.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(FloatValue.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(Int64Value.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(UInt64Value.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(Int32Value.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(UInt32Value.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(BoolValue.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(StringValue.class));
  serializers.addSerializer(new WrappedPrimitiveSerializer<>(BytesValue.class));

  context.addSerializers(serializers);

  context.addDeserializers(new MessageDeserializerFactory(config));
  SimpleDeserializers deserializers = new SimpleDeserializers();
  deserializers.addDeserializer(Duration.class, new DurationDeserializer());
  deserializers.addDeserializer(FieldMask.class, new FieldMaskDeserializer());
  deserializers.addDeserializer(ListValue.class, new ListValueDeserializer().buildAtEnd());
  deserializers.addDeserializer(NullValue.class, new NullValueDeserializer());
  deserializers.addDeserializer(Struct.class, new StructDeserializer().buildAtEnd());
  deserializers.addDeserializer(Timestamp.class, new TimestampDeserializer());
  deserializers.addDeserializer(Value.class, new ValueDeserializer().buildAtEnd());
  deserializers.addDeserializer(DoubleValue.class, wrappedPrimitiveDeserializer(DoubleValue.class));
  deserializers.addDeserializer(FloatValue.class, wrappedPrimitiveDeserializer(FloatValue.class));
  deserializers.addDeserializer(Int64Value.class, wrappedPrimitiveDeserializer(Int64Value.class));
  deserializers.addDeserializer(UInt64Value.class, wrappedPrimitiveDeserializer(UInt64Value.class));
  deserializers.addDeserializer(Int32Value.class, wrappedPrimitiveDeserializer(Int32Value.class));
  deserializers.addDeserializer(UInt32Value.class, wrappedPrimitiveDeserializer(UInt32Value.class));
  deserializers.addDeserializer(BoolValue.class, wrappedPrimitiveDeserializer(BoolValue.class));
  deserializers.addDeserializer(StringValue.class, wrappedPrimitiveDeserializer(StringValue.class));
  deserializers.addDeserializer(BytesValue.class, wrappedPrimitiveDeserializer(BytesValue.class));
  context.addDeserializers(deserializers);
  context.setMixInAnnotations(MessageOrBuilder.class, MessageOrBuilderMixin.class);
}
 
Example #30
Source File: WellKnownTypeMarshaller.java    From curiostack with MIT License 4 votes vote down vote up
@Override
protected final void doWrite(UInt32Value message, JsonGenerator gen) throws IOException {
  SerializeSupport.printUnsignedInt32(message.getValue(), gen);
}