Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
PHP streaming retry and exception tests (#1306)
Browse files Browse the repository at this point in the history
* Remove retry settings from PHP streaming methods
* Update exception tests
  • Loading branch information
michaelbausor authored May 30, 2017
1 parent 4de4575 commit a7603d7
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 40 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/google/api/codegen/GapicContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ protected boolean isSupported(Method method) {
return !method.getRequestStreaming() && !method.getResponseStreaming();
}

/**
* Returns true when the method supports retrying. By default, all supported methods support
* retrying. TODO: when isSupported is removed, this should return true.
*/
public boolean isRetryingSupported(Method method) {
return isSupported(method);
}

/** Returns a list of RPC methods supported by the context. */
public List<Method> getSupportedMethods(Interface apiInterface) {
List<Method> simples = new ArrayList<>(apiInterface.getMethods().size());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright 2016 Google Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.api.codegen.clientconfig.php;

import com.google.api.codegen.clientconfig.ClientConfigGapicContext;
import com.google.api.codegen.config.GapicProductConfig;
import com.google.api.tools.framework.model.Method;
import com.google.api.tools.framework.model.Model;

public class PhpClientConfigGapicContext extends ClientConfigGapicContext {

/** Constructs the client config codegen context. */
public PhpClientConfigGapicContext(Model model, GapicProductConfig config) {
super(model, config);
}

@Override
public boolean isRetryingSupported(Method method) {
return isSupported(method) && !method.getRequestStreaming() && !method.getResponseStreaming();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.api.codegen.SnippetSetRunner;
import com.google.api.codegen.clientconfig.ClientConfigGapicContext;
import com.google.api.codegen.clientconfig.ClientConfigSnippetSetRunner;
import com.google.api.codegen.clientconfig.php.PhpClientConfigGapicContext;
import com.google.api.codegen.config.GapicProductConfig;
import com.google.api.codegen.config.PackageMetadataConfig;
import com.google.api.codegen.nodejs.NodeJSCodePathMapper;
Expand Down Expand Up @@ -260,7 +261,7 @@ public static List<GapicProvider<? extends Object>> defaultCreate(
CommonGapicProvider.<Interface>newBuilder()
.setModel(model)
.setView(new InterfaceView())
.setContext(new ClientConfigGapicContext(model, productConfig))
.setContext(new PhpClientConfigGapicContext(model, productConfig))
.setSnippetSetRunner(
new ClientConfigSnippetSetRunner<Interface>(
SnippetSetRunner.SNIPPET_RESOURCE_ROOT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@
retryCodesName = methodConfig.getRetryCodesConfigName, \
retryParamsName = methodConfig.getRetrySettingsConfigName
"{@method.getSimpleName}": {
@if or(and(retryCodesName, retryParamsName), isBatching)
@if or(and(and(retryCodesName, retryParamsName), context.isRetryingSupported(method)), isBatching)
"timeout_millis": {@timeout},
@else
"timeout_millis": {@timeout}
@end
@if and(retryCodesName, retryParamsName)
@if and(and(retryCodesName, retryParamsName), context.isRetryingSupported(method))
"retry_codes_name": "{@retryCodesName}",
@if isBatching
"retry_params_name": "{@retryParamsName}",
Expand Down
9 changes: 7 additions & 2 deletions src/main/resources/com/google/api/codegen/php/test.snip
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
$this->assertTrue($grpcStub->isExhausted());

$status = new stdClass();
$status->code = Grpc\STATUS_INTERNAL;
$status->code = Grpc\STATUS_DATA_LOSS;
$status->details = 'internal error';
$grpcStub->addResponse(null, $status);

Expand All @@ -152,6 +152,8 @@
$this->assertEquals($status->details, $ex->getMessage());
}

// Call getReceivedCalls to ensure the stub is exhausted
$grpcStub->getReceivedCalls();
$this->assertTrue($grpcStub->isExhausted());
}
@end
Expand Down Expand Up @@ -253,7 +255,7 @@
$grpcStub->addResponse($incompleteOperation);

$status = new stdClass();
$status->code = Grpc\STATUS_INTERNAL;
$status->code = Grpc\STATUS_DATA_LOSS;
$status->details = 'internal error';
$operationsStub->addResponse(null, $status);

Expand All @@ -278,6 +280,9 @@
$this->assertEquals($status->details, $ex->getMessage());
}

// Call getReceivedCalls to ensure the stubs are exhausted
$grpcStub->getReceivedCalls();
$operationsStub->getReceivedCalls();
$this->assertTrue($grpcStub->isExhausted());
$this->assertTrue($operationsStub->isExhausted());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,16 @@
"retry_params_name": "default"
},
"StreamShelves": {
"timeout_millis": 30000,
"retry_codes_name": "idempotent",
"retry_params_name": "default"
"timeout_millis": 30000
},
"StreamBooks": {
"timeout_millis": 30000,
"retry_codes_name": "idempotent",
"retry_params_name": "default"
"timeout_millis": 30000
},
"DiscussBook": {
"timeout_millis": 30000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default"
"timeout_millis": 30000
},
"MonologAboutBook": {
"timeout_millis": 30000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default"
"timeout_millis": 30000
},
"FindRelatedBooks": {
"timeout_millis": 3000,
Expand Down
Loading

0 comments on commit a7603d7

Please sign in to comment.