Skip to content

Commit 2c18cba

Browse files
committed
---
yaml --- r: 7463 b: refs/heads/tswast-patch-1 c: 3eca483 h: refs/heads/master i: 7461: 96e0911 7459: 97802a7 7455: dc6b08d
1 parent 856076f commit 2c18cba

8 files changed

Lines changed: 286 additions & 75 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: e1ee4898eecd4966bd2af7530168d30ada2bb5ed
60+
refs/heads/tswast-patch-1: 3eca483f3d05ac5a120671fd4a4034df81653a5b
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-core/src/test/java/com/google/cloud/SerializationTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package com.google.cloud;
1818

19+
import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor;
20+
import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor.ValueType;
1921
import com.google.cloud.ServiceAccountSigner.SigningException;
2022
import com.google.common.collect.ImmutableList;
23+
import com.google.common.collect.ImmutableMap;
2124

2225
import java.io.ByteArrayInputStream;
2326
import java.io.IOException;
@@ -39,6 +42,15 @@ public class SerializationTest extends BaseSerializationTest {
3942
private static final SomeIamPolicy SOME_IAM_POLICY = new SomeIamPolicy.Builder().build();
4043
private static final WaitForOption CHECKING_PERIOD =
4144
WaitForOption.checkEvery(42, TimeUnit.SECONDS);
45+
private static final LabelDescriptor LABEL_DESCRIPTOR =
46+
new LabelDescriptor("project_id", ValueType.STRING, "The project id");
47+
private static final MonitoredResourceDescriptor MONITORED_RESOURCE_DESCRIPTOR =
48+
MonitoredResourceDescriptor.builder("global")
49+
.labels(ImmutableList.of(LABEL_DESCRIPTOR))
50+
.build();
51+
private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.builder("global")
52+
.labels(ImmutableMap.of("project_id", "project"))
53+
.build();
4254
private static final String JSON_KEY = "{\n"
4355
+ " \"private_key_id\": \"somekeyid\",\n"
4456
+ " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS"
@@ -91,7 +103,8 @@ public Builder toBuilder() {
91103
@Override
92104
protected Serializable[] serializableObjects() {
93105
return new Serializable[]{BASE_SERVICE_EXCEPTION, EXCEPTION_HANDLER, IDENTITY, PAGE,
94-
RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD};
106+
RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD, LABEL_DESCRIPTOR,
107+
MONITORED_RESOURCE_DESCRIPTOR, MONITORED_RESOURCE};
95108
}
96109

97110
@Override

branches/tswast-patch-1/gcloud-java-logging/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
<artifactId>auto-value</artifactId>
4848
<version>1.1</version>
4949
</dependency>
50+
<dependency>
51+
<groupId>${project.groupId}</groupId>
52+
<artifactId>gcloud-java-core</artifactId>
53+
<version>${project.version}</version>
54+
<type>test-jar</type>
55+
<scope>test</scope>
56+
</dependency>
5057
<dependency>
5158
<groupId>junit</groupId>
5259
<artifactId>junit</artifactId>

branches/tswast-patch-1/gcloud-java-logging/src/main/java/com/google/cloud/logging/HttpRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class HttpRequest implements Serializable {
5353
/**
5454
* The HTTP request method.
5555
*/
56-
enum RequestMethod {
56+
public enum RequestMethod {
5757
GET,
5858
HEAD,
5959
PUT,
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
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+
package com.google.cloud.logging;
18+
19+
import static com.google.cloud.logging.Logging.EntryListOption;
20+
import static com.google.cloud.logging.Logging.SortingField;
21+
import static com.google.cloud.logging.Logging.SortingOrder;
22+
import static com.google.cloud.logging.Logging.WriteOption;
23+
import static org.junit.Assert.assertEquals;
24+
25+
import com.google.cloud.MonitoredResource;
26+
import com.google.cloud.logging.Logging.ListOption;
27+
import com.google.common.collect.ImmutableMap;
28+
29+
import org.junit.Test;
30+
31+
import java.util.Map;
32+
33+
public class LoggingTest {
34+
35+
private static final int PAGE_SIZE = 42;
36+
private static final String PAGE_TOKEN = "page token";
37+
private static final String FILTER = "filter";
38+
private static final Map<String, String> LABELS = ImmutableMap.of("key", "value");
39+
private static final String LOG_NAME = "logName";
40+
private static final MonitoredResource RESOURCE =
41+
MonitoredResource.of("global", ImmutableMap.of("project_id", "p"));
42+
43+
@Test
44+
public void testListOption() {
45+
// page token
46+
ListOption listOption = ListOption.pageToken(PAGE_TOKEN);
47+
assertEquals(PAGE_TOKEN, listOption.value());
48+
assertEquals(ListOption.OptionType.PAGE_TOKEN, listOption.optionType());
49+
// page size
50+
listOption = ListOption.pageSize(PAGE_SIZE);
51+
assertEquals(PAGE_SIZE, listOption.value());
52+
assertEquals(ListOption.OptionType.PAGE_SIZE, listOption.optionType());
53+
}
54+
55+
@Test
56+
public void testEntryListOption() {
57+
EntryListOption listOption = EntryListOption.pageToken(PAGE_TOKEN);
58+
assertEquals(PAGE_TOKEN, listOption.value());
59+
assertEquals(EntryListOption.OptionType.PAGE_TOKEN, listOption.optionType());
60+
// page size
61+
listOption = EntryListOption.pageSize(PAGE_SIZE);
62+
assertEquals(PAGE_SIZE, listOption.value());
63+
assertEquals(EntryListOption.OptionType.PAGE_SIZE, listOption.optionType());
64+
// filter
65+
listOption = EntryListOption.filter(FILTER);
66+
assertEquals(FILTER, listOption.value());
67+
assertEquals(EntryListOption.OptionType.FILTER, listOption.optionType());
68+
// sort order
69+
listOption = EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.ASCENDING);
70+
assertEquals("timestamp asc", listOption.value());
71+
assertEquals(EntryListOption.OptionType.ORDER_BY, listOption.optionType());
72+
listOption = EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.DESCENDING);
73+
assertEquals("timestamp desc", listOption.value());
74+
assertEquals(EntryListOption.OptionType.ORDER_BY, listOption.optionType());
75+
}
76+
77+
@Test
78+
public void testWriteOption() {
79+
WriteOption writeOption = WriteOption.labels(LABELS);
80+
assertEquals(LABELS, writeOption.value());
81+
assertEquals(WriteOption.OptionType.LABELS, writeOption.optionType());
82+
writeOption = WriteOption.logName(LOG_NAME);
83+
assertEquals(LOG_NAME, writeOption.value());
84+
assertEquals(WriteOption.OptionType.LOG_NAME, writeOption.optionType());
85+
writeOption = WriteOption.resource(RESOURCE);
86+
assertEquals(RESOURCE, writeOption.value());
87+
assertEquals(WriteOption.OptionType.RESOURCE, writeOption.optionType());
88+
}
89+
}

branches/tswast-patch-1/gcloud-java-logging/src/test/java/com/google/cloud/logging/MetricTest.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,30 @@ public class MetricTest {
4646
.build();
4747
private final Logging serviceMockReturnsOptions = createStrictMock(Logging.class);
4848
private final LoggingOptions mockOptions = createMock(LoggingOptions.class);
49-
private Logging pubsub;
49+
private Logging logging;
5050
private Metric expectedMetric;
5151
private Metric metric;
5252

5353
private void initializeExpectedMetric(int optionsCalls) {
5454
expect(serviceMockReturnsOptions.options()).andReturn(mockOptions).times(optionsCalls);
5555
replay(serviceMockReturnsOptions);
56-
pubsub = createStrictMock(Logging.class);
56+
logging = createStrictMock(Logging.class);
5757
expectedMetric = new Metric(serviceMockReturnsOptions, new Metric.BuilderImpl(METRIC_INFO));
5858
}
5959

6060
private void initializeMetric() {
61-
metric = new Metric(pubsub, new Metric.BuilderImpl(METRIC_INFO));
61+
metric = new Metric(logging, new Metric.BuilderImpl(METRIC_INFO));
6262
}
6363

6464
@After
6565
public void tearDown() throws Exception {
66-
verify(pubsub, serviceMockReturnsOptions);
66+
verify(logging, serviceMockReturnsOptions);
6767
}
6868

6969
@Test
7070
public void testBuilder() {
7171
initializeExpectedMetric(2);
72-
replay(pubsub);
72+
replay(logging);
7373
MetricInfo builtMetric = expectedMetric.toBuilder()
7474
.name(NEW_NAME)
7575
.filter(NEW_FILTER)
@@ -83,7 +83,7 @@ public void testBuilder() {
8383
@Test
8484
public void testToBuilder() {
8585
initializeExpectedMetric(2);
86-
replay(pubsub);
86+
replay(logging);
8787
compareMetric(expectedMetric, expectedMetric.toBuilder().build());
8888
}
8989

@@ -93,9 +93,9 @@ public void testReload() {
9393
MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build();
9494
Metric expectedMetric =
9595
new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo));
96-
expect(pubsub.options()).andReturn(mockOptions);
97-
expect(pubsub.getMetric(NAME)).andReturn(expectedMetric);
98-
replay(pubsub);
96+
expect(logging.options()).andReturn(mockOptions);
97+
expect(logging.getMetric(NAME)).andReturn(expectedMetric);
98+
replay(logging);
9999
initializeMetric();
100100
Metric updatedMetric = metric.reload();
101101
compareMetric(expectedMetric, updatedMetric);
@@ -104,9 +104,9 @@ public void testReload() {
104104
@Test
105105
public void testReloadNull() {
106106
initializeExpectedMetric(1);
107-
expect(pubsub.options()).andReturn(mockOptions);
108-
expect(pubsub.getMetric(NAME)).andReturn(null);
109-
replay(pubsub);
107+
expect(logging.options()).andReturn(mockOptions);
108+
expect(logging.getMetric(NAME)).andReturn(null);
109+
replay(logging);
110110
initializeMetric();
111111
assertNull(metric.reload());
112112
}
@@ -116,10 +116,10 @@ public void testReloadAsync() throws ExecutionException, InterruptedException {
116116
initializeExpectedMetric(2);
117117
MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build();
118118
Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo));
119-
expect(pubsub.options()).andReturn(mockOptions);
120-
expect(pubsub.getMetricAsync(NAME))
119+
expect(logging.options()).andReturn(mockOptions);
120+
expect(logging.getMetricAsync(NAME))
121121
.andReturn(Futures.immediateFuture(expectedMetric));
122-
replay(pubsub);
122+
replay(logging);
123123
initializeMetric();
124124
Metric updatedMetric = metric.reloadAsync().get();
125125
compareMetric(expectedMetric, updatedMetric);
@@ -128,9 +128,9 @@ public void testReloadAsync() throws ExecutionException, InterruptedException {
128128
@Test
129129
public void testReloadAsyncNull() throws ExecutionException, InterruptedException {
130130
initializeExpectedMetric(1);
131-
expect(pubsub.options()).andReturn(mockOptions);
132-
expect(pubsub.getMetricAsync(NAME)).andReturn(Futures.<Metric>immediateFuture(null));
133-
replay(pubsub);
131+
expect(logging.options()).andReturn(mockOptions);
132+
expect(logging.getMetricAsync(NAME)).andReturn(Futures.<Metric>immediateFuture(null));
133+
replay(logging);
134134
initializeMetric();
135135
assertNull(metric.reloadAsync().get());
136136
}
@@ -140,9 +140,9 @@ public void testUpdate() {
140140
initializeExpectedMetric(2);
141141
MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build();
142142
Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo));
143-
expect(pubsub.options()).andReturn(mockOptions);
144-
expect(pubsub.update(updatedInfo)).andReturn(expectedMetric);
145-
replay(pubsub);
143+
expect(logging.options()).andReturn(mockOptions);
144+
expect(logging.update(updatedInfo)).andReturn(expectedMetric);
145+
replay(logging);
146146
initializeMetric();
147147
Metric updatedMetric = metric.update(updatedInfo);
148148
compareMetric(expectedMetric, updatedMetric);
@@ -153,9 +153,9 @@ public void testUpdateAsync() throws ExecutionException, InterruptedException {
153153
initializeExpectedMetric(2);
154154
MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build();
155155
Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo));
156-
expect(pubsub.options()).andReturn(mockOptions);
157-
expect(pubsub.updateAsync(updatedInfo)).andReturn(Futures.immediateFuture(expectedMetric));
158-
replay(pubsub);
156+
expect(logging.options()).andReturn(mockOptions);
157+
expect(logging.updateAsync(updatedInfo)).andReturn(Futures.immediateFuture(expectedMetric));
158+
replay(logging);
159159
initializeMetric();
160160
Metric updatedMetric = metric.updateAsync(updatedInfo).get();
161161
compareMetric(expectedMetric, updatedMetric);
@@ -164,39 +164,39 @@ public void testUpdateAsync() throws ExecutionException, InterruptedException {
164164
@Test
165165
public void testDeleteTrue() {
166166
initializeExpectedMetric(1);
167-
expect(pubsub.options()).andReturn(mockOptions);
168-
expect(pubsub.deleteMetric(NAME)).andReturn(true);
169-
replay(pubsub);
167+
expect(logging.options()).andReturn(mockOptions);
168+
expect(logging.deleteMetric(NAME)).andReturn(true);
169+
replay(logging);
170170
initializeMetric();
171171
assertTrue(metric.delete());
172172
}
173173

174174
@Test
175175
public void testDeleteFalse() {
176176
initializeExpectedMetric(1);
177-
expect(pubsub.options()).andReturn(mockOptions);
178-
expect(pubsub.deleteMetric(NAME)).andReturn(false);
179-
replay(pubsub);
177+
expect(logging.options()).andReturn(mockOptions);
178+
expect(logging.deleteMetric(NAME)).andReturn(false);
179+
replay(logging);
180180
initializeMetric();
181181
assertFalse(metric.delete());
182182
}
183183

184184
@Test
185185
public void testDeleteAsyncTrue() throws ExecutionException, InterruptedException {
186186
initializeExpectedMetric(1);
187-
expect(pubsub.options()).andReturn(mockOptions);
188-
expect(pubsub.deleteMetricAsync(NAME)).andReturn(Futures.immediateFuture(true));
189-
replay(pubsub);
187+
expect(logging.options()).andReturn(mockOptions);
188+
expect(logging.deleteMetricAsync(NAME)).andReturn(Futures.immediateFuture(true));
189+
replay(logging);
190190
initializeMetric();
191191
assertTrue(metric.deleteAsync().get());
192192
}
193193

194194
@Test
195195
public void testDeleteAsyncFalse() throws ExecutionException, InterruptedException {
196196
initializeExpectedMetric(1);
197-
expect(pubsub.options()).andReturn(mockOptions);
198-
expect(pubsub.deleteMetricAsync(NAME)).andReturn(Futures.immediateFuture(false));
199-
replay(pubsub);
197+
expect(logging.options()).andReturn(mockOptions);
198+
expect(logging.deleteMetricAsync(NAME)).andReturn(Futures.immediateFuture(false));
199+
replay(logging);
200200
initializeMetric();
201201
assertFalse(metric.deleteAsync().get());
202202
}

0 commit comments

Comments
 (0)