Skip to content

Commit 3dcab0c

Browse files
authored
chore: update GSON dependency (GoogleCloudPlatform#7188)
* chore: update GSON dependency * add retries * lint * fix deletion * update retry for function * fix delete * add retries and lint * lint
1 parent 1ac62be commit 3dcab0c

File tree

33 files changed

+126
-77
lines changed

33 files changed

+126
-77
lines changed

appengine-java11/gaeinfo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Copyright 2019 Google LLC
6666
<dependency>
6767
<groupId>com.google.code.gson</groupId>
6868
<artifactId>gson</artifactId>
69-
<version>2.8.8</version>
69+
<version>2.8.9</version>
7070
<scope>provided</scope>
7171
</dependency>
7272

appengine-java8/firebase-tictactoe/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<dependency>
5858
<groupId>com.google.code.gson</groupId>
5959
<artifactId>gson</artifactId>
60-
<version>2.8.8</version>
60+
<version>2.8.9</version>
6161
</dependency>
6262
<dependency>
6363
<groupId>com.googlecode.objectify</groupId>

appengine-java8/gaeinfo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Copyright 2017 Google Inc.
6262
<dependency>
6363
<groupId>com.google.code.gson</groupId>
6464
<artifactId>gson</artifactId>
65-
<version>2.8.8</version>
65+
<version>2.8.9</version>
6666
</dependency>
6767

6868
<dependency>

appengine-java8/metadata/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Copyright 2017 Google Inc.
5757
<dependency>
5858
<groupId>com.google.code.gson</groupId>
5959
<artifactId>gson</artifactId>
60-
<version>2.8.8</version>
60+
<version>2.8.9</version>
6161
</dependency>
6262

6363
<dependency>

bigtable/scheduled-backups/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ limitations under the License.
4646
<dependency>
4747
<groupId>com.google.code.gson</groupId>
4848
<artifactId>gson</artifactId>
49-
<version>2.8.8</version>
49+
<version>2.8.9</version>
5050
</dependency>
5151
<dependency>
5252
<groupId>com.google.cloud</groupId>

bigtable/scheduled-backups/src/test/java/com/example/cloud/bigtable/scheduledbackups/CreateBackupTestIT.java

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import java.util.List;
4242
import java.util.Map;
4343
import java.util.UUID;
44-
import java.util.concurrent.TimeUnit;
44+
import java.util.logging.Logger;
4545
import org.apache.http.client.HttpClient;
4646
import org.apache.http.client.methods.HttpPost;
4747
import org.apache.http.conn.HttpHostConnectException;
@@ -51,14 +51,14 @@
5151
import org.junit.BeforeClass;
5252
import org.junit.Test;
5353

54-
5554
public class CreateBackupTestIT {
5655
private static final String PROJECT_ENV = "GOOGLE_CLOUD_PROJECT";
5756
private static final String INSTANCE_ID = "ins-" + UUID.randomUUID().toString().substring(0, 10);
5857
private static final String CLUSTER_ID = "cl-" + UUID.randomUUID().toString().substring(0, 10);
5958
private static final String TABLE_ID = "tbl-" + UUID.randomUUID().toString().substring(0, 10);
6059
private static final String ZONE_ID = "us-east1-b";
6160
private static final String COLUMN_FAMILY_NAME = "cf1";
61+
private static final Logger logger = Logger.getLogger(CreateBackupTestIT.class.getName());
6262

6363
private static String projectId;
6464

@@ -80,34 +80,31 @@ private static String requireEnv(String varName) {
8080
@BeforeClass
8181
public static void setUp() throws IOException {
8282
projectId = requireEnv(PROJECT_ENV);
83-
8483
try (BigtableInstanceAdminClient instanceAdmin =
8584
BigtableInstanceAdminClient.create(projectId)) {
86-
CreateInstanceRequest request = CreateInstanceRequest.of(INSTANCE_ID)
87-
.addCluster(CLUSTER_ID, ZONE_ID, 1, StorageType.SSD);
85+
CreateInstanceRequest request =
86+
CreateInstanceRequest.of(INSTANCE_ID).addCluster(CLUSTER_ID, ZONE_ID, 1, StorageType.SSD);
8887
Instance instance = instanceAdmin.createInstance(request);
8988
} catch (IOException e) {
90-
System.out.println("Error during BeforeClass while creating instance: \n" + e.toString());
91-
throw(e);
89+
logger.info("Error during BeforeClass while creating instance: \n" + e.toString());
90+
throw (e);
9291
}
9392

9493
try (BigtableTableAdminClient tableAdmin =
9594
BigtableTableAdminClient.create(projectId, INSTANCE_ID)) {
9695
// Create a table.
9796
tableAdmin.createTable(CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_NAME));
9897
} catch (IOException e) {
99-
System.out.println("Error during BeforeClass while creating table: \n" + e.toString());
100-
throw(e);
98+
logger.info("Error during BeforeClass while creating table: \n" + e.toString());
99+
throw (e);
101100
}
102101

103102
// Get the sample's base directory (the one containing a pom.xml file)
104103
String baseDir = System.getProperty("basedir");
105104

106105
// Emulate the function locally by running the Functions Framework Maven plugin
107-
emulatorProcess = new ProcessBuilder()
108-
.command("mvn", "function:run")
109-
.directory(new File(baseDir))
110-
.start();
106+
emulatorProcess =
107+
new ProcessBuilder().command("mvn", "function:run").directory(new File(baseDir)).start();
111108
}
112109

113110
@AfterClass
@@ -119,19 +116,19 @@ public static void cleanUp() throws IOException {
119116
}
120117
tableAdmin.deleteTable(TABLE_ID);
121118
} catch (IOException e) {
122-
System.out.println("Error during AfterClass while deleting backup and table: \n"
123-
+ e.toString());
124-
throw(e);
119+
logger.info("Error during AfterClass while deleting backup and table: \n" + e.toString());
120+
throw (e);
125121
}
126122

127123
try (BigtableInstanceAdminClient instanceAdmin =
128124
BigtableInstanceAdminClient.create(projectId)) {
129125
instanceAdmin.deleteInstance(INSTANCE_ID);
130126
} catch (IOException e) {
131-
System.out.println("Error during AfterClass while deleting instance: \n" + e.toString());
127+
logger.info("Error during AfterClass while deleting instance: \n" + e.toString());
132128
throw (e);
133129
}
134-
// Terminate the running Functions Framework Maven plugin process (if it's still running)
130+
// Terminate the running Functions Framework Maven plugin process (if it's still
131+
// running)
135132
if (emulatorProcess.isAlive()) {
136133
emulatorProcess.destroy();
137134
}
@@ -140,46 +137,65 @@ public static void cleanUp() throws IOException {
140137
@Test
141138
public void testCreateBackup() throws Throwable {
142139
String functionUrl = BASE_URL + "/createBackup";
143-
String msg = String.format(
144-
"{\"projectId\":\"%s\", \"instanceId\":\"%s\", \"tableId\":\"%s\", \"clusterId\":\"%s\","
145-
+ "\"expireHours\":%d}",
146-
projectId, INSTANCE_ID, TABLE_ID, CLUSTER_ID, 8);
140+
String msg =
141+
String.format(
142+
"{\"projectId\":\"%s\", \"instanceId\":\"%s\", \"tableId\":\"%s\", "
143+
+ "\"clusterId\":\"%s\", \"expireHours\":%d}",
144+
projectId, INSTANCE_ID, TABLE_ID, CLUSTER_ID, 8);
147145
String msgBase64 = Base64.getEncoder().encodeToString(msg.getBytes(StandardCharsets.UTF_8));
148146
Map<String, String> msgMap = new HashMap<>();
149147
msgMap.put("data", msgBase64);
150148
Map<String, Map<String, String>> dataMap = new HashMap<>();
151149
dataMap.put("data", msgMap);
152150
String jsonStr = gson.toJson(dataMap);
153151

154-
HttpPost postRequest = new HttpPost(URI.create(functionUrl));
152+
HttpPost postRequest = new HttpPost(URI.create(functionUrl));
155153
postRequest.setEntity(new StringEntity(jsonStr));
156154

157155
// The Functions Framework Maven plugin process takes time to start up
158156
// Use resilience4j to retry the test HTTP request until the plugin responds
159-
RetryRegistry registry = RetryRegistry.of(RetryConfig.custom()
160-
.maxAttempts(8)
161-
.retryExceptions(HttpHostConnectException.class)
162-
.intervalFunction(IntervalFunction.ofExponentialBackoff(200, 2))
163-
.build());
157+
RetryRegistry registry =
158+
RetryRegistry.of(
159+
RetryConfig.custom()
160+
.maxAttempts(12)
161+
.retryExceptions(HttpHostConnectException.class)
162+
.retryOnResult(
163+
u -> {
164+
// Retry if the Functions Framework process has no stdout content
165+
// See `retryOnResultPredicate` here:
166+
// https://resilience4j.readme.io/docs/retry
167+
try {
168+
return emulatorProcess.getErrorStream().available() == 0;
169+
} catch (IOException e) {
170+
return true;
171+
}
172+
})
173+
.intervalFunction(IntervalFunction.ofExponentialBackoff(200, 2))
174+
.build());
164175
Retry retry = registry.retry("my");
165176

166177
// Perform the request-retry process
167-
CheckedRunnable retriableFunc = Retry.decorateCheckedRunnable(
168-
retry, () -> client.execute(postRequest));
178+
CheckedRunnable retriableFunc =
179+
Retry.decorateCheckedRunnable(retry, () -> client.execute(postRequest));
169180
retriableFunc.run();
170-
// Wait 2 mins for the backup to be created.
171-
TimeUnit.MINUTES.sleep(2);
181+
172182
// Check if backup exists
173183
List<String> backups = new ArrayList<String>();
174-
try (BigtableTableAdminClient tableAdmin =
175-
BigtableTableAdminClient.create(projectId, INSTANCE_ID)) {
176-
backups = tableAdmin.listBackups(CLUSTER_ID);
177-
} catch (IOException e) {
178-
System.out.println("Unable to list backups: \n" + e.toString());
179-
throw (e);
184+
int maxAttempts = 5;
185+
for (int count = 0; count < maxAttempts; count++) {
186+
try (BigtableTableAdminClient tableAdmin =
187+
BigtableTableAdminClient.create(projectId, INSTANCE_ID)) {
188+
backups = tableAdmin.listBackups(CLUSTER_ID);
189+
assertThat(backups.size()).isEqualTo(1);
190+
String expectedBackupPrefix = TABLE_ID + "-backup-";
191+
assertThat(backups.get(0).contains(expectedBackupPrefix));
192+
return;
193+
} catch (Exception e) {
194+
logger.info("Unable to list backups: \n" + e.toString());
195+
logger.info("Attempt " + count + " failed. Retrying.");
196+
Thread.sleep(3000);
197+
}
180198
}
181-
assertThat(backups.size()).isEqualTo(1);
182-
String expectedBackupPrefix = TABLE_ID + "-backup-";
183-
assertThat(backups.get(0).contains(expectedBackupPrefix));
199+
assertThat(false);
184200
}
185201
}

compute/signed-metadata/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<dependency>
4646
<groupId>com.google.code.gson</groupId>
4747
<artifactId>gson</artifactId>
48-
<version>2.8.8</version>
48+
<version>2.8.9</version>
4949
</dependency>
5050
<dependency>
5151
<groupId>com.google.guava</groupId>

container-registry/vulnerability-notification-function/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<dependency>
5050
<groupId>com.google.code.gson</groupId>
5151
<artifactId>gson</artifactId>
52-
<version>2.8.8</version>
52+
<version>2.8.9</version>
5353
</dependency>
5454

5555
<dependency>

endpoints/getting-started/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<dependency>
5252
<groupId>com.google.code.gson</groupId>
5353
<artifactId>gson</artifactId>
54-
<version>2.8.8</version>
54+
<version>2.8.9</version>
5555
<scope>compile</scope>
5656
</dependency>
5757
</dependencies>

endpoints/multiple-versions/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<dependency>
5757
<groupId>com.google.code.gson</groupId>
5858
<artifactId>gson</artifactId>
59-
<version>2.8.8</version>
59+
<version>2.8.9</version>
6060
<scope>compile</scope>
6161
</dependency>
6262
<dependency>

0 commit comments

Comments
 (0)