Skip to content

Commit

Permalink
android-interop-testing: Support get option in interop app
Browse files Browse the repository at this point in the history
  • Loading branch information
zsurocking committed Apr 27, 2017
1 parent a317912 commit 50a92e0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
3 changes: 2 additions & 1 deletion android-interop-testing/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

# Add any project specific keep options here:

-dontwarn android.test.**
-dontwarn com.google.common.**
-dontwarn javax.naming.**
-dontwarn okio.**
-dontwarn org.mockito.**
-dontwarn sun.reflect.**
-dontwarn android.test.**
# Ignores: can't find referenced class javax.lang.model.element.Modifier
-dontwarn com.google.errorprone.annotations.**
-keep class io.grpc.internal.DnsNameResolverProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@
import com.google.protobuf.nano.EmptyProtos;
import com.google.protobuf.nano.MessageNano;
import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
import io.grpc.ClientInterceptor;
import io.grpc.ClientInterceptors;
import io.grpc.ClientInterceptors.CheckedForwardingClientCall;
import io.grpc.ManagedChannel;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.StatusRuntimeException;
import io.grpc.android.integrationtest.nano.Messages;
import io.grpc.android.integrationtest.nano.Messages.Payload;
Expand Down Expand Up @@ -105,12 +110,17 @@ public void onCompleted() {

public InteropTester(String testCase,
ManagedChannel channel,
TestListener listener) {
TestListener listener,
boolean useGet) {
this.testCase = testCase;
this.listener = listener;
this.channel = channel;
blockingStub = TestServiceGrpc.newBlockingStub(channel);
asyncStub = TestServiceGrpc.newStub(channel);
Channel channelToUse = channel;
if (useGet) {
channelToUse = ClientInterceptors.intercept(channel, new SafeMethodChannelInterceptor());
}
blockingStub = TestServiceGrpc.newBlockingStub(channelToUse);
asyncStub = TestServiceGrpc.newStub(channelToUse);
}

@Override
Expand Down Expand Up @@ -759,4 +769,18 @@ private static boolean shouldSkip() {
}
return false;
}

private static final class SafeMethodChannelInterceptor implements ClientInterceptor {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new CheckedForwardingClientCall<ReqT, RespT>(
next.newCall(method.toBuilder().setSafe(true).build(), callOptions)) {
@Override
public void checkedStart(Listener<RespT> responseListener, Metadata headers) {
delegate().start(responseListener, headers);
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import com.google.android.gms.security.ProviderInstaller;
Expand All @@ -52,6 +53,7 @@ public class TesterActivity extends AppCompatActivity
private EditText hostEdit;
private EditText portEdit;
private TextView resultText;
private CheckBox getCheckBox;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -67,6 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {
hostEdit = (EditText) findViewById(R.id.host_edit_text);
portEdit = (EditText) findViewById(R.id.port_edit_text);
resultText = (TextView) findViewById(R.id.grpc_response_text);
getCheckBox = (CheckBox) findViewById(R.id.get_checkbox);

ProviderInstaller.installIfNeededAsync(this, this);
// Disable buttons until the security provider installing finishes.
Expand Down Expand Up @@ -120,7 +123,7 @@ private void startTest(String testCase) {
resultText.setText(result);
enableButtons(true);
}
}).execute();
}, getCheckBox.isChecked()).execute();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class TesterInstrumentation extends Instrumentation {
private boolean useTls;
private boolean useTestCa;
private String androidSocketFactoryTls;
private boolean useGet;

@Override
public void onCreate(Bundle args) {
Expand All @@ -66,6 +67,8 @@ public void onCreate(Bundle args) {
useTestCa = args.getString("use_test_ca") != null
? Boolean.parseBoolean(args.getString("use_test_ca")) : false;
androidSocketFactoryTls = args.getString("android_socket_factory_tls");
useGet = args.getString("use_get") != null
? Boolean.parseBoolean(args.getString("use_get")) : false;

InputStream testCa = null;
if (useTestCa) {
Expand Down Expand Up @@ -105,8 +108,8 @@ public void onPostTest(String result) {
finish(1, bundle);
}
}
}
).execute();
},
useGet).execute();
} catch (Throwable t) {
Bundle bundle = new Bundle();
bundle.putString("Exception encountered", t.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
android:inputType="numberDecimal"
android:hint="Enter Port"
/>
<CheckBox android:id="@+id/get_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/use_get"
/>
</LinearLayout>

<Button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">gRPC Integration Test</string>
<string name="use_get">Use GET</string>
</resources>

0 comments on commit 50a92e0

Please sign in to comment.