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
feat: allow to stop the invoker #128
feat: allow to stop the invoker #128
Conversation
c88cd9c
to
0f99963
Compare
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.
Thanks for doing this! I think it will be very useful for people testing their functions. I did have a few requests.
invoker/core/src/main/java/com/google/cloud/functions/invoker/runner/Invoker.java
Outdated
Show resolved
Hide resolved
b2a1b0a
to
de3ba8d
Compare
That looks great, thanks! Do you know why the indentation of some lines has changed? The changes don't look like improvements. |
de3ba8d
to
f9ae5af
Compare
@eamonnmcmanus sorry, something may happens when I try to fix the format issue using the Google formatter tool. I revert the identation changes. |
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.
The google-java-format check is failing because of these diffs:
8:25:13.000000000 -0800
+++ - 2022-02-21 08:27:05.000000000 -0800
@@ -228,8 +228,8 @@
}
/**
- * This will start the server and wait (join) for function calls.
- * To start the server inside a unit or integration test, use {@link #startTestServer()} instead.
+ * This will start the server and wait (join) for function calls. To start the server inside a
+ * unit or integration test, use {@link #startTestServer()} instead.
*
* @see #stopServer()
* @throws Exception
@@ -238,31 +238,21 @@
startServer(true);
}
-
/**
* This will start the server and return.
*
- * This method is designed to be used for unit or integration testing only.
- * For other use cases use {@link #startServer()}.
+ * <p>This method is designed to be used for unit or integration testing only. For other use cases
+ * use {@link #startServer()}.
*
- * Inside a test a typical usage will be:
- * {@code
- * // Create an invoker
- * Invoker invoker = new Invoker(
- * 8081,
- * "org.example.MyHttpFunction",
- * "http",
- * Thread.currentThread().getContextClassLoader()
- * );
+ * <p>Inside a test a typical usage will be: {@code // Create an invoker Invoker invoker = new
+ * Invoker( 8081, "org.example.MyHttpFunction", "http",
+ * Thread.currentThread().getContextClassLoader() );
*
- * // Start the test server
- * invoker.startTestServer();
+ * <p>// Start the test server invoker.startTestServer();
*
- * // Test the function
+ * <p>// Test the function
*
- * // Stop the test server
- * invoker.stopServer();
- * }
+ * <p>// Stop the test server invoker.stopServer(); }
*
* @see #stopServer()
* @throws Exception
@@ -317,7 +307,6 @@
*
* @see #startServer()
* @see #startTestServer()
- *
* @throws Exception
*/
public void stopServer() throws Exception {
I am not sure why you are seeing the indentation change when you run g-j-f. Perhaps --aosp
is set? Anyway the main thing is that you need <pre>...</pre>
around the {@code...}
block.
public void startServer() throws Exception { | ||
Server server = new Server(port); | ||
startServer(true); |
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.
Could you put something like this first?
if (server != null) {
throw new IllegalStateException("Server already started");
}
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.
Would it be better to do it inside the startServer(boolean)
method instead of here ?
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.
Yes, you are right of course.
* @throws Exception | ||
*/ | ||
public void stopServer() throws Exception { | ||
server.stop(); |
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.
And here:
if (server == null) {
throw new IllegalStateException("Server not started");
}
(which is a bit nicer than NullPointerException
).
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.
Maybe setting the server to null after stopping it so the same invoker can be stoped and stated again without needed to create it again ?
This can be convenient if someone want to stop it / start it inside a @Before
and create it inside an @BeforeAll
?
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.
Yes, thanks for catching that, it should indeed be set to null after the stop()
call.
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.
Changes done
f9ae5af
to
7963208
Compare
7963208
to
e2e0987
Compare
Thanks again! I'll fix the formatting problems myself, since the formatter works fine for me. |
Thanks @eamonnmcmanus to have run the formater for me. |
🤖 I have created a release *beep* *boop* --- ## 1.0.0 (2022-09-07) ### Features * allow to stop the invoker ([GoogleCloudPlatform#128](https://github.com/anniefu/functions-framework-java/issues/128)) ([14908ca](14908ca)) * enable converting CloudEvent requests to Background Event requests ([GoogleCloudPlatform#123](https://github.com/anniefu/functions-framework-java/issues/123)) ([1c4a014](1c4a014)) * Increase maximum concurrent requests for jetty server to 1000. ([GoogleCloudPlatform#144](https://github.com/anniefu/functions-framework-java/issues/144)) ([439d0b5](439d0b5)) ### Bug Fixes * Add build env vars support for function deployment. ([GoogleCloudPlatform#133](https://github.com/anniefu/functions-framework-java/issues/133)) ([0e052f3](0e052f3)) * bump dependency versions ([GoogleCloudPlatform#134](https://github.com/anniefu/functions-framework-java/issues/134)) ([faff79d](faff79d)) * make user function exceptions log level SEVERE ([GoogleCloudPlatform#113](https://github.com/anniefu/functions-framework-java/issues/113)) ([1684c0e](1684c0e)) * update conformance tests ([GoogleCloudPlatform#108](https://github.com/anniefu/functions-framework-java/issues/108)) ([72852d0](72852d0)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Allow to stop the invoker so it can be easily used inside an integration test like this.
Fixes #18