Skip to content

Commit ed055ef

Browse files
ludochrenovate-botgae-java-bot
authored
Merge from main (#471)
* Hardcode several JavaRuntimeParams values. PiperOrigin-RevId: 860637485 Change-Id: Ibbd87902f4ef73e3620180ad870dc8200a40b417 * Modernize Java syntax to JDK17 level in App Engine code base. PiperOrigin-RevId: 861206703 Change-Id: If6a63e7bae3d33e833cf752ee8313d88b9dffa86 * Update all non-major dependencies * Refactor: Use lambda expressions and Character.valueOf. PiperOrigin-RevId: 862378286 Change-Id: I140e95ffda132265f442bc1d222c587331e367d6 * Update all non-major dependencies * Refactor AppEngineWebXmlInitialParse to allow mocking environment variables and add a test. New Test Permutations We added new test cases to AppEngineWebXmlInitialParseTest.java to ensure full coverage of Runtime, Jetty, and Jakarta EE version combinations: testJava17WithExperimentEnableJetty12: Verifies that when the environment variable EXPERIMENT_ENABLE_JETTY12_FOR_JAVA is set to true for the java17 runtime (simulated via envProvider), the configuration correctly defaults to appengine.use.EE8=true (Jetty 12.0 in EE8 mode) instead of the standard Jetty 9.4 legacy mode. testHttpConnectorExperiment: Verifies that when EXPERIMENT_ENABLE_HTTP_CONNECTOR_FOR_JAVA is set to true, the system properties appengine.use.HttpConnector and appengine.ignore.cancelerror are automatically enabled. testJava17WithJetty121: Verifies that for the java17 runtime, enabling appengine.use.jetty121 alone does not inadvertently enable Jakarta EE 8, 10, or 11. It confirms that the configuration remains valid with only the Jetty 12.1 flag set. testJava17WithEE8AndJetty121: Verifies that for java17, explicitly enabling both appengine.use.EE8 and appengine.use.jetty121 correctly sets both properties to true, supporting the legacy EE8 environment on the newer Jetty infrastructure. testJava21WithEE10Explicit: Confirms that explicitly setting appengine.use.EE10 for java21 (which is the default) works as expected, ensuring EE10 is true and jetty121 remains false (mapping to Jetty 12.0). testJava21WithEE8AndJetty121: Verifies that for java21, combining appengine.use.EE8 with appengine.use.jetty121 correctly enables both flags. Environment Variable Emulation To reliably test logic dependent on environment variables (such as EXPERIMENT_ENABLE_JETTY12_FOR_JAVA or EXPERIMENT_ENABLE_HTTP_CONNECTOR_FOR_JAVA) without modifying the actual system environment or affecting other tests: The AppEngineWebXmlInitialParse class now accepts a custom envProvider (a UnaryOperator<String>) via the package-private setEnvProvider method. By default, this provider delegates to System::getenv. In tests, we inject a lambda function (e.g., key -> "true") to simulate specific environment variables being set. This allows us to verify that the parser correctly activates experimental features or defaults based on the environment. testSystemPropertyOverrideRuntime: This test sets the GAE_RUNTIME system property to "java21" (while the XML specifies "java17") and verifies that the runtime logic correctly switches to "java21" behavior (defaulting to EE10). This kills the mutant where runtimeId re-fetching from system properties (line 178) was removed, as the test would fail if runtimeId remained "java17". testSystemPropertyOverrideRuntimeWithWhitespace: This test sets GAE_RUNTIME to " java21 " (with whitespace) and asserts that the code correctly handles it as "java21" (setting EE10 to true). This kills the mutant where the trim() call (lines 179-181) was removed, as the test would fail if the whitespace prevented the "java21" logic from triggering. testLogEE8: This test captures the logs generated by AppEngineWebXmlInitialParse and asserts that "appengine.use.EE8=true" is logged when EE8 is enabled. This kills the mutant where the logging logic for EE8 (lines 249-251) was removed. PiperOrigin-RevId: 862787419 Change-Id: I1bc08a2ee06faa1018f0f225e8ca90f358cc094d * Update all non-major dependencies * Refactor StringBuilder usage to use append() calls. PiperOrigin-RevId: 863263787 Change-Id: I5b7805c536e69fd544fc71edadd0d799e3e5c145 * Update dependency org.apache.maven.plugins:maven-compiler-plugin to v3.15.0 * Update Jetty versions and servlet API jar. Update Jetty 12.0.x to 12.0.32 and Jetty 12.1.x to 12.1.6. Also, update the Jetty servlet API jar from 4.0.6 to 4.0.9 in the Jetty121EE8Sdk configuration. PiperOrigin-RevId: 864150501 Change-Id: Idc20a1e9abda7b10f9a0e695ad979d3e6cbaa7a2 * Re-enable and migrate RemoteDatastoreTest to Proto2 API and move remaining internal tests to open source. PiperOrigin-RevId: 865415153 Change-Id: I26706754398304cfe4567583ffb84e0d9f2d73f1 * Move AppInfoFactory to a common package as it is not Jetty specific and can be shared across all Jetty versions. PiperOrigin-RevId: 865965002 Change-Id: I04d68e5e83ee9219c20b4fac974070a400bbb662 --------- Co-authored-by: Mend Renovate <bot@renovateapp.com> Co-authored-by: GAE Java Team <gae-java-bot@google.com>
1 parent 347b9d6 commit ed055ef

42 files changed

Lines changed: 3001 additions & 852 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

remoteapi/pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,37 @@
5656
<groupId>com.google.appengine</groupId>
5757
<artifactId>appengine-api-1.0-sdk</artifactId>
5858
</dependency>
59+
<dependency>
60+
<groupId>junit</groupId>
61+
<artifactId>junit</artifactId>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>com.google.truth</groupId>
66+
<artifactId>truth</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.google.truth.extensions</groupId>
71+
<artifactId>truth-proto-extension</artifactId>
72+
<version>1.4.5</version>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.mockito</groupId>
77+
<artifactId>mockito-core</artifactId>
78+
<scope>test</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>com.google.protobuf</groupId>
82+
<artifactId>protobuf-java</artifactId>
83+
<optional>true</optional>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.apache.httpcomponents</groupId>
87+
<artifactId>httpclient</artifactId>
88+
<optional>true</optional>
89+
</dependency>
5990
</dependencies>
6091
<build>
6192
<plugins>

remoteapi/src/main/java/com/google/appengine/tools/remoteapi/RemoteDatastore.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.protobuf.Message;
2424
import com.google.storage.onestore.v3_bytes.proto2api.OnestoreEntity;
2525
import java.util.ArrayList;
26-
import java.util.Collection;
2726
import java.util.HashSet;
2827
import java.util.Iterator;
2928
import java.util.List;
@@ -195,12 +194,11 @@ static boolean rewriteQueryAppIds(DatastoreV3Pb.Query.Builder query, String remo
195194
reserialize = true;
196195
query.getAncestorBuilder().setApp(remoteAppId);
197196
}
198-
for (DatastoreV3Pb.Query.Filter filter : query.getFilterList()) {
199-
for (OnestoreEntity.Property prop : filter.getPropertyList()) {
200-
OnestoreEntity.PropertyValue propValue = prop.getValue();
201-
if (propValue.hasReferenceValue()) {
197+
for (DatastoreV3Pb.Query.Filter.Builder filter : query.getFilterBuilderList()) {
198+
for (OnestoreEntity.Property.Builder prop : filter.getPropertyBuilderList()) {
199+
if (prop.getValue().hasReferenceValue()) {
202200
OnestoreEntity.PropertyValue.ReferenceValue.Builder ref =
203-
propValue.getReferenceValue().toBuilder();
201+
prop.getValueBuilder().getReferenceValueBuilder();
204202
if (!ref.getApp().equals(remoteAppId)) {
205203
reserialize = true;
206204
ref.setApp(remoteAppId);
@@ -268,7 +266,7 @@ private byte[] handleGet(byte[] originalRequestBytes) {
268266
mergeFromBytes(rewrittenReq, originalRequestBytes);
269267

270268
// Update the Request so that all References have the remoteAppId.
271-
boolean reserialize = rewriteRequestReferences(rewrittenReq.getKeyList(), remoteAppId);
269+
boolean reserialize = rewriteRequestReferences(rewrittenReq.getKeyBuilderList(), remoteAppId);
272270
if (rewrittenReq.hasTransaction()) {
273271
return handleGetWithTransaction(rewrittenReq.build());
274272
} else {
@@ -326,7 +324,7 @@ private byte[] handleDelete(byte[] requestBytes) {
326324
DatastoreV3Pb.DeleteRequest.Builder request = DatastoreV3Pb.DeleteRequest.newBuilder();
327325
mergeFromBytes(request, requestBytes);
328326

329-
boolean reserialize = rewriteRequestReferences(request.getKeyList(), remoteAppId);
327+
boolean reserialize = rewriteRequestReferences(request.getKeyBuilderList(), remoteAppId);
330328
if (reserialize) {
331329
// The request was mutated, so we need to reserialize it.
332330
requestBytes = request.build().toByteArray();
@@ -348,12 +346,12 @@ private byte[] handleDelete(byte[] requestBytes) {
348346
*/
349347
/* @VisibleForTesting */
350348
static boolean rewriteRequestReferences(
351-
Collection<OnestoreEntity.Reference> references, String remoteAppId) {
349+
List<OnestoreEntity.Reference.Builder> references, String remoteAppId) {
352350

353351
boolean reserialize = false;
354-
for (OnestoreEntity.Reference refToCheck : references) {
352+
for (OnestoreEntity.Reference.Builder refToCheck : references) {
355353
if (!refToCheck.getApp().equals(remoteAppId)) {
356-
refToCheck = refToCheck.toBuilder().setApp(remoteAppId).build();
354+
refToCheck.setApp(remoteAppId);
357355
reserialize = true;
358356
}
359357
}

remoteapi/src/main/java/com/google/appengine/tools/remoteapi/RemoteRpc.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Copyright 2021 Google LLC
43
*
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.appengine.tools.remoteapi;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertThrows;
21+
import static org.junit.Assert.assertTrue;
22+
23+
import com.google.api.client.http.LowLevelHttpRequest;
24+
import com.google.api.client.http.LowLevelHttpResponse;
25+
import com.google.api.client.testing.http.MockHttpTransport;
26+
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
27+
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
28+
import com.google.appengine.tools.remoteapi.AppEngineClient.Response;
29+
import com.google.appengine.tools.remoteapi.testing.StubCredential;
30+
import java.io.IOException;
31+
import java.util.Arrays;
32+
import org.junit.Test;
33+
import org.junit.runner.RunWith;
34+
import org.junit.runners.JUnit4;
35+
36+
/**
37+
* Test for {@link OAuthClient}.
38+
*/
39+
@RunWith(JUnit4.class)
40+
public class OAuthClientTest {
41+
42+
private static final String APP_ID = "appid";
43+
44+
private static class SimpleHttpTransport extends MockHttpTransport {
45+
private final byte[] responseBytes;
46+
47+
private String lastMethod = null;
48+
private String lastUrl = null;
49+
50+
SimpleHttpTransport(byte[] responseBytes) {
51+
this.responseBytes = responseBytes;
52+
}
53+
54+
@Override
55+
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
56+
lastMethod = method;
57+
lastUrl = url;
58+
return new MockLowLevelHttpRequest() {
59+
@Override
60+
public LowLevelHttpResponse execute() throws IOException {
61+
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
62+
response.setContent(Arrays.copyOf(responseBytes, responseBytes.length));
63+
return response;
64+
}
65+
};
66+
}
67+
68+
String getLastMethod() {
69+
return lastMethod;
70+
}
71+
72+
String getLastUrl() {
73+
return lastUrl;
74+
}
75+
}
76+
77+
@Test
78+
public void testConstructor() {
79+
RemoteApiOptions noOAuthCredential = new RemoteApiOptions()
80+
.credentials("email", "password")
81+
.httpTransport(new SimpleHttpTransport(new byte[] {}));
82+
assertThrows(IllegalArgumentException.class, () -> new OAuthClient(noOAuthCredential, APP_ID));
83+
84+
RemoteApiOptions noHttpTransport = new RemoteApiOptions()
85+
.oauthCredential(new StubCredential());
86+
assertThrows(IllegalStateException.class, () -> new OAuthClient(noHttpTransport, APP_ID));
87+
}
88+
89+
@Test
90+
public void testGet() throws Exception {
91+
byte[] expectedResponseBytes = new byte[] {42};
92+
93+
SimpleHttpTransport transport = new SimpleHttpTransport(expectedResponseBytes);
94+
RemoteApiOptions options = new RemoteApiOptions()
95+
.server("example.com", 8080)
96+
.oauthCredential(new StubCredential())
97+
.httpTransport(transport);
98+
99+
Response response = new OAuthClient(options, APP_ID)
100+
.get("/foo");
101+
assertTrue(Arrays.equals(expectedResponseBytes, response.getBodyAsBytes()));
102+
assertEquals("GET", transport.getLastMethod());
103+
assertEquals("http://example.com:8080/foo", transport.getLastUrl());
104+
}
105+
106+
@Test
107+
public void testPost() throws Exception {
108+
byte[] expectedResponseBytes = new byte[] {42};
109+
110+
SimpleHttpTransport transport = new SimpleHttpTransport(expectedResponseBytes);
111+
RemoteApiOptions options = new RemoteApiOptions()
112+
.server("example.com", 443)
113+
.oauthCredential(new StubCredential())
114+
.httpTransport(transport);
115+
116+
Response response = new OAuthClient(options, APP_ID)
117+
.post("/foo", "application/json", new byte[]{1});
118+
assertTrue(Arrays.equals(expectedResponseBytes, response.getBodyAsBytes()));
119+
assertEquals("POST", transport.getLastMethod());
120+
assertEquals("https://example.com:443/foo", transport.getLastUrl());
121+
}
122+
}

0 commit comments

Comments
 (0)