Skip to content

Commit 9543382

Browse files
Rename NewFoo to Foo. (#54)
* Switch invoker to API version 1.0.2. * Rename NewFoo to Foo. Previously we had `BackgroundFunction` and `NewBackgroundFunction`, where the former was the original design where functions were methods that needed to have a particular signature and the latter was the newer design where functions are classes that implement a given interface. We retired `BackgroundFunction` etc a while ago, so we can rename `NewBackgroundFunction` to just `BackgroundFunction`. * Add a couple of missed cases.
1 parent 03ed53d commit 9543382

File tree

10 files changed

+35
-35
lines changed

10 files changed

+35
-35
lines changed

invoker/core/src/main/java/com/google/cloud/functions/invoker/NewBackgroundFunctionExecutor.java renamed to invoker/core/src/main/java/com/google/cloud/functions/invoker/BackgroundFunctionExecutor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@
4646
import javax.servlet.http.HttpServletResponse;
4747

4848
/** Executes the user's background function. */
49-
public final class NewBackgroundFunctionExecutor extends HttpServlet {
49+
public final class BackgroundFunctionExecutor extends HttpServlet {
5050
private static final Logger logger = Logger.getLogger("com.google.cloud.functions.invoker");
5151

5252
private final FunctionExecutor<?> functionExecutor;
5353

54-
private NewBackgroundFunctionExecutor(FunctionExecutor<?> functionExecutor) {
54+
private BackgroundFunctionExecutor(FunctionExecutor<?> functionExecutor) {
5555
this.functionExecutor = functionExecutor;
5656
}
5757

5858
/**
59-
* Makes a {@link NewHttpFunctionExecutor} for the given class.
59+
* Makes a {@link HttpFunctionExecutor} for the given class.
6060
*
6161
* @throws RuntimeException if either the class does not implement one of
6262
* {@link BackgroundFunction} or {@link RawBackgroundFunction},
6363
* or we are unable to construct an instance using its no-arg constructor.
6464
*/
65-
public static NewBackgroundFunctionExecutor forClass(Class<?> functionClass) {
65+
public static BackgroundFunctionExecutor forClass(Class<?> functionClass) {
6666
if (!BackgroundFunction.class.isAssignableFrom(functionClass)
6767
&& !RawBackgroundFunction.class.isAssignableFrom(functionClass)) {
6868
throw new RuntimeException(
@@ -95,7 +95,7 @@ public static NewBackgroundFunctionExecutor forClass(Class<?> functionClass) {
9595
}
9696
executor = new TypedFunctionExecutor<>(maybeTargetType.get(), backgroundFunction);
9797
}
98-
return new NewBackgroundFunctionExecutor(executor);
98+
return new BackgroundFunctionExecutor(executor);
9999
}
100100

101101
/**

invoker/core/src/main/java/com/google/cloud/functions/invoker/NewHttpFunctionExecutor.java renamed to invoker/core/src/main/java/com/google/cloud/functions/invoker/HttpFunctionExecutor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@
2525
import javax.servlet.http.HttpServletResponse;
2626

2727
/** Executes the user's method. */
28-
public class NewHttpFunctionExecutor extends HttpServlet {
28+
public class HttpFunctionExecutor extends HttpServlet {
2929
private static final Logger logger = Logger.getLogger("com.google.cloud.functions.invoker");
3030

3131
private final HttpFunction function;
3232

33-
private NewHttpFunctionExecutor(HttpFunction function) {
33+
private HttpFunctionExecutor(HttpFunction function) {
3434
this.function = function;
3535
}
3636

3737
/**
38-
* Makes a {@link NewHttpFunctionExecutor} for the given class.
38+
* Makes a {@link HttpFunctionExecutor} for the given class.
3939
*
4040
* @throws RuntimeException if either the given class does not implement {@link HttpFunction}
4141
* or we are unable to construct an instance using its no-arg constructor.
4242
*/
43-
public static NewHttpFunctionExecutor forClass(Class<?> functionClass) {
43+
public static HttpFunctionExecutor forClass(Class<?> functionClass) {
4444
if (!HttpFunction.class.isAssignableFrom(functionClass)) {
4545
throw new RuntimeException(
4646
"Class " + functionClass.getName() + " does not implement "
@@ -49,7 +49,7 @@ public static NewHttpFunctionExecutor forClass(Class<?> functionClass) {
4949
Class<? extends HttpFunction> httpFunctionClass = functionClass.asSubclass(HttpFunction.class);
5050
try {
5151
HttpFunction httpFunction = httpFunctionClass.getConstructor().newInstance();
52-
return new NewHttpFunctionExecutor(httpFunction);
52+
return new HttpFunctionExecutor(httpFunction);
5353
} catch (ReflectiveOperationException e) {
5454
throw new RuntimeException(
5555
"Could not construct an instance of " + functionClass.getName() + ": " + e, e);

invoker/core/src/main/java/com/google/cloud/functions/invoker/runner/Invoker.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import com.google.cloud.functions.BackgroundFunction;
2323
import com.google.cloud.functions.HttpFunction;
2424
import com.google.cloud.functions.RawBackgroundFunction;
25-
import com.google.cloud.functions.invoker.NewBackgroundFunctionExecutor;
26-
import com.google.cloud.functions.invoker.NewHttpFunctionExecutor;
25+
import com.google.cloud.functions.invoker.BackgroundFunctionExecutor;
26+
import com.google.cloud.functions.invoker.HttpFunctionExecutor;
2727
import com.google.cloud.functions.invoker.gcf.JsonLogHandler;
2828
import java.io.File;
2929
import java.io.IOException;
@@ -240,9 +240,9 @@ public void startServer() throws Exception {
240240

241241
HttpServlet servlet;
242242
if ("http".equals(functionSignatureType)) {
243-
servlet = NewHttpFunctionExecutor.forClass(functionClass);
243+
servlet = HttpFunctionExecutor.forClass(functionClass);
244244
} else if ("event".equals(functionSignatureType)) {
245-
servlet = NewBackgroundFunctionExecutor.forClass(functionClass);
245+
servlet = BackgroundFunctionExecutor.forClass(functionClass);
246246
} else if (functionSignatureType == null) {
247247
servlet = servletForDeducedSignatureType(functionClass);
248248
} else {
@@ -284,11 +284,11 @@ private Class<?> loadFunctionClass() throws ClassNotFoundException {
284284

285285
private HttpServlet servletForDeducedSignatureType(Class<?> functionClass) {
286286
if (HttpFunction.class.isAssignableFrom(functionClass)) {
287-
return NewHttpFunctionExecutor.forClass(functionClass);
287+
return HttpFunctionExecutor.forClass(functionClass);
288288
}
289289
if (BackgroundFunction.class.isAssignableFrom(functionClass)
290290
|| RawBackgroundFunction.class.isAssignableFrom(functionClass)) {
291-
return NewBackgroundFunctionExecutor.forClass(functionClass);
291+
return BackgroundFunctionExecutor.forClass(functionClass);
292292
}
293293
String error = String.format(
294294
"Could not determine function signature type from target %s. Either this should be"

invoker/core/src/test/java/com/google/cloud/functions/invoker/NewBackgroundFunctionExecutorTest.java renamed to invoker/core/src/test/java/com/google/cloud/functions/invoker/BackgroundFunctionExecutorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.google.cloud.functions.invoker;
22

3-
import static com.google.cloud.functions.invoker.NewBackgroundFunctionExecutor.backgroundFunctionTypeArgument;
3+
import static com.google.cloud.functions.invoker.BackgroundFunctionExecutor.backgroundFunctionTypeArgument;
44
import static com.google.common.truth.Truth8.assertThat;
55

66
import com.google.cloud.functions.BackgroundFunction;
@@ -11,7 +11,7 @@
1111
import org.junit.runners.JUnit4;
1212

1313
@RunWith(JUnit4.class)
14-
public class NewBackgroundFunctionExecutorTest {
14+
public class BackgroundFunctionExecutorTest {
1515
private static class PubSubMessage {
1616
String data;
1717
Map<String, String> attributes;

invoker/core/src/test/java/com/google/cloud/functions/invoker/IntegrationTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,19 @@ private static String fullTarget(String nameWithoutPackage) {
242242
.build();
243243

244244
@Test
245-
public void newHelloWorld() throws Exception {
246-
testHttpFunction(fullTarget("NewHelloWorld"),
245+
public void helloWorld() throws Exception {
246+
testHttpFunction(fullTarget("HelloWorld"),
247247
ImmutableList.of(
248248
TestCase.builder().setExpectedResponseText("hello\n").build(),
249249
FAVICON_TEST_CASE,
250250
ROBOTS_TXT_TEST_CASE));
251251
}
252252

253253
@Test
254-
public void newEcho() throws Exception {
254+
public void echo() throws Exception {
255255
String testText = "hello\nworld\n";
256256
testHttpFunction(
257-
fullTarget("NewEcho"),
257+
fullTarget("Echo"),
258258
ImmutableList.of(
259259
TestCase.builder()
260260
.setRequestText(testText)
@@ -270,12 +270,12 @@ public void newEcho() throws Exception {
270270
}
271271

272272
@Test
273-
public void newEchoUrl() throws Exception {
273+
public void echoUrl() throws Exception {
274274
String[] testUrls = {"/", "/foo/bar", "/?foo=bar&baz=buh", "/foo?bar=baz"};
275275
List<TestCase> testCases = Arrays.stream(testUrls)
276276
.map(url -> TestCase.builder().setUrl(url).setExpectedResponseText(url + "\n").build())
277277
.collect(toList());
278-
testHttpFunction(fullTarget("NewEchoUrl"), testCases);
278+
testHttpFunction(fullTarget("EchoUrl"), testCases);
279279
}
280280

281281
@Test
@@ -314,16 +314,16 @@ public void stackDriverLogging() throws Exception {
314314
}
315315

316316
@Test
317-
public void newBackground() throws Exception {
318-
newBackgroundTest("NewBackgroundSnoop");
317+
public void background() throws Exception {
318+
backgroundTest("BackgroundSnoop");
319319
}
320320

321321
@Test
322-
public void newTypedBackground() throws Exception {
323-
newBackgroundTest("NewTypedBackgroundSnoop");
322+
public void typedBackground() throws Exception {
323+
backgroundTest("TypedBackgroundSnoop");
324324
}
325325

326-
private void newBackgroundTest(String target) throws Exception {
326+
private void backgroundTest(String target) throws Exception {
327327
File snoopFile = snoopFile();
328328
String gcfRequestText = sampleLegacyEvent(snoopFile);
329329
JsonObject expectedJson = new Gson().fromJson(gcfRequestText, JsonObject.class);

invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/NewBackgroundSnoop.java renamed to invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/BackgroundSnoop.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* identical to the JSON payload that the Functions Framework received from the client in the test.
1717
* This will need to be rewritten when we switch to CloudEvents.
1818
*/
19-
public class NewBackgroundSnoop implements RawBackgroundFunction {
19+
public class BackgroundSnoop implements RawBackgroundFunction {
2020
@Override
2121
public void accept(String json, Context context) {
2222
Gson gson = new Gson();

invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/NewEcho.java renamed to invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/Echo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.io.OutputStream;
88
import java.util.stream.Collectors;
99

10-
public class NewEcho implements HttpFunction {
10+
public class Echo implements HttpFunction {
1111
@Override
1212
public void service(HttpRequest request, HttpResponse response) throws Exception {
1313
boolean binary = "application/octet-stream".equals(request.getContentType().orElse(null));

invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/NewEchoUrl.java renamed to invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/EchoUrl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.google.cloud.functions.HttpRequest;
55
import com.google.cloud.functions.HttpResponse;
66

7-
public class NewEchoUrl implements HttpFunction {
7+
public class EchoUrl implements HttpFunction {
88
@Override
99
public void service(HttpRequest request, HttpResponse response) throws Exception {
1010
StringBuilder url = new StringBuilder(request.getPath());

invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/NewHelloWorld.java renamed to invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/HelloWorld.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.google.cloud.functions.HttpRequest;
55
import com.google.cloud.functions.HttpResponse;
66

7-
public class NewHelloWorld implements HttpFunction {
7+
public class HelloWorld implements HttpFunction {
88
@Override
99
public void service(HttpRequest request, HttpResponse response) throws Exception {
1010
response.getWriter().write("hello\n");

invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/NewTypedBackgroundSnoop.java renamed to invoker/core/src/test/java/com/google/cloud/functions/invoker/testfunctions/TypedBackgroundSnoop.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* identical to the JSON payload that the Functions Framework received from the client in the test.
1717
* This will need to be rewritten when we switch to CloudEvents.
1818
*/
19-
public class NewTypedBackgroundSnoop
20-
implements BackgroundFunction<NewTypedBackgroundSnoop.Payload> {
19+
public class TypedBackgroundSnoop
20+
implements BackgroundFunction<TypedBackgroundSnoop.Payload> {
2121
public static class Payload {
2222
public int a;
2323
public int b;

0 commit comments

Comments
 (0)