File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2019 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
+ * http://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
+ // [START functions_log_stackdriver]
18
+ import java .io .IOException ;
19
+ import java .util .Base64 ;
20
+ import java .util .Map ;
21
+ import java .util .logging .Logger ;
22
+
23
+ public class LogEntry {
24
+
25
+ private static Logger LOGGER = Logger .getLogger (LogEntry .class .getName ());
26
+
27
+ public void helloPubSub (PubSubMessage message ) throws IOException {
28
+ String data = new String (Base64 .getDecoder ().decode (message .data .getBytes ("UTF-8" )));
29
+ if (data .isEmpty ()) {
30
+ data = "World" ;
31
+ }
32
+ LOGGER .info (String .format ("Hello, %s" , data ));
33
+ }
34
+ }
35
+
36
+ class PubSubMessage {
37
+ String data ;
38
+ Map <String , String > attributes ;
39
+ String messageId ;
40
+ String publishTime ;
41
+ }
42
+ // [END functions_log_stackdriver]
Original file line number Diff line number Diff line change @@ -179,6 +179,15 @@ public void filesTest() throws IOException {
179
179
assertThat (responseOut .toString (), containsString ("Files:" ));
180
180
}
181
181
182
+ @ Test
183
+ public void logEntry () throws IOException {
184
+ PubSubMessage message = new PubSubMessage ();
185
+ message .data = "data" ;
186
+ message .messageId = "id" ;
187
+ new LogEntry ().helloPubSub (message );
188
+ assertThat (responseOut .toString (), containsString ("" ));
189
+ }
190
+
182
191
@ Test
183
192
public void envTest () throws IOException {
184
193
environmentVariables .set ("FOO" , "BAR" );
You can’t perform that action at this time.
0 commit comments