-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mobile: Remove HTTP server code from TestJni #33169
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
mobile/test/java/io/envoyproxy/envoymobile/engine/testing/HttpProxyTestServerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.envoyproxy.envoymobile.engine.testing; | ||
|
||
/** An HTTP proxy test server factory. */ | ||
public final class HttpProxyTestServerFactory { | ||
/** The supported {@link HttpProxyTestServer} types. */ | ||
public static class Type { | ||
public static final int HTTP_PROXY = 3; | ||
public static final int HTTPS_PROXY = 4; | ||
|
||
private Type() {} | ||
} | ||
|
||
/** The instance of {@link HttpProxyTestServer}. */ | ||
public static class HttpProxyTestServer { | ||
private final long handle; // Used by the native code. | ||
private final int port; | ||
|
||
private HttpProxyTestServer(long handle, int port) { | ||
this.handle = handle; | ||
this.port = port; | ||
} | ||
|
||
/** Returns the server port. */ | ||
public int getPort() { return port; } | ||
|
||
/** Shuts down the server. */ | ||
public native void shutdown(); | ||
} | ||
|
||
static { System.loadLibrary("envoy_jni_http_proxy_test_server_factory"); } | ||
|
||
/** | ||
* Starts the HTTP proxy server. | ||
* | ||
* @param type the value in {@link HttpProxyTestServerFactory.Type} | ||
*/ | ||
public static native HttpProxyTestServer start(int type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <jni.h> | ||
|
||
#include "test/common/integration/test_server.h" | ||
|
||
#include "extension_registry.h" | ||
#include "library/jni/jni_helper.h" | ||
#include "library/jni/jni_utility.h" | ||
|
||
// NOLINT(namespace-envoy) | ||
|
||
extern "C" JNIEXPORT jobject JNICALL | ||
Java_io_envoyproxy_envoymobile_engine_testing_HttpProxyTestServerFactory_start(JNIEnv* env, jclass, | ||
jint type) { | ||
Envoy::JNI::JniHelper jni_helper(env); | ||
|
||
Envoy::ExtensionRegistry::registerFactories(); | ||
Envoy::TestServer* test_server = new Envoy::TestServer(); | ||
test_server->startTestServer(static_cast<Envoy::TestServerType>(type)); | ||
|
||
auto java_http_proxy_server_factory_class = jni_helper.findClass( | ||
"io/envoyproxy/envoymobile/engine/testing/HttpProxyTestServerFactory$HttpProxyTestServer"); | ||
auto java_init_method_id = | ||
jni_helper.getMethodId(java_http_proxy_server_factory_class.get(), "<init>", "(JI)V"); | ||
int port = test_server->getServerPort(); | ||
return jni_helper | ||
.newObject(java_http_proxy_server_factory_class.get(), java_init_method_id, | ||
reinterpret_cast<jlong>(test_server), static_cast<jint>(port)) | ||
.release(); | ||
} | ||
|
||
extern "C" JNIEXPORT void JNICALL | ||
Java_io_envoyproxy_envoymobile_engine_testing_HttpProxyTestServerFactory_00024HttpProxyTestServer_shutdown( | ||
JNIEnv* env, jobject instance) { | ||
Envoy::JNI::JniHelper jni_helper(env); | ||
auto java_class = jni_helper.getObjectClass(instance); | ||
auto java_handle_field_id = jni_helper.getFieldId(java_class.get(), "handle", "J"); | ||
jlong java_handle = jni_helper.getLongField(instance, java_handle_field_id); | ||
Envoy::TestServer* test_server = reinterpret_cast<Envoy::TestServer*>(java_handle); | ||
test_server->shutdownTestServer(); | ||
delete test_server; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't this part of the previous PR? I think tip-of-tree needs to be sync'ed with this branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for the proxy test server.