forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mobile: Remove HTTP server code from TestJni (envoyproxy#33169)
This PR removes the HTTP server code from TestJni. The tests have been updated to use either HttpTestServer or HttpProxyTestServer. This PR also moves test_server_interface.[h|cc] into its own build target. Risk Level: low (tests only) Testing: unit tests Docs Changes: n/a Release Notes: n/a Platform Specific Features: mobile Signed-off-by: Fredy Wijaya <[email protected]>
- Loading branch information
Showing
18 changed files
with
269 additions
and
171 deletions.
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.