Skip to content

Commit b556485

Browse files
committed
---
yaml --- r: 3709 b: refs/heads/pubsub-alpha c: 8ae8a1b h: refs/heads/master i: 3707: 58f67e1
1 parent 7d3b710 commit b556485

12 files changed

Lines changed: 164 additions & 204 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 36a62ef856d199f8efd09501b5ba65c422c01f23
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 7406918e071dd2c5677a638ae2a06e7592b6542c
5-
refs/heads/pubsub-alpha: 7d48ec786a79a79281d4edccee782b6a62d2959d
5+
refs/heads/pubsub-alpha: 8ae8a1b160bbbd1e18bedf2a35d014449397ec3e
66
refs/heads/update-datastore: 47aae517c2cb33f1dccd909adaced73ec9d0f4df
77
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
88
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd

branches/pubsub-alpha/gcloud-java-bigquery/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
</exclusion>
4040
</exclusions>
4141
</dependency>
42+
<dependency>
43+
<groupId>${project.groupId}</groupId>
44+
<artifactId>gcloud-java-core</artifactId>
45+
<version>${project.version}</version>
46+
<type>test-jar</type>
47+
<scope>test</scope>
48+
</dependency>
4249
<dependency>
4350
<groupId>junit</groupId>
4451
<artifactId>junit</artifactId>

branches/pubsub-alpha/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/SerializationTest.java

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,25 @@
1717
package com.google.gcloud.bigquery;
1818

1919
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotSame;
2120

2221
import com.google.common.collect.ImmutableList;
2322
import com.google.common.collect.ImmutableMap;
2423
import com.google.gcloud.AuthCredentials;
24+
import com.google.gcloud.BaseSerializationTest;
2525
import com.google.gcloud.RestorableState;
2626
import com.google.gcloud.RetryParams;
2727
import com.google.gcloud.WriteChannel;
2828
import com.google.gcloud.bigquery.StandardTableDefinition.StreamingBuffer;
2929

3030
import org.junit.Test;
3131

32-
import java.io.ByteArrayInputStream;
33-
import java.io.ByteArrayOutputStream;
3432
import java.io.IOException;
35-
import java.io.ObjectInputStream;
36-
import java.io.ObjectOutputStream;
3733
import java.io.Serializable;
3834
import java.nio.charset.StandardCharsets;
3935
import java.util.List;
4036
import java.util.Map;
4137

42-
public class SerializationTest {
38+
public class SerializationTest extends BaseSerializationTest {
4339

4440
private static final Acl DOMAIN_ACCESS =
4541
Acl.of(new Acl.Domain("domain"), Acl.Role.WRITER);
@@ -231,27 +227,18 @@ public class SerializationTest {
231227
private static final Table TABLE = new Table(BIGQUERY, new TableInfo.BuilderImpl(TABLE_INFO));
232228
private static final Job JOB = new Job(BIGQUERY, new JobInfo.BuilderImpl(JOB_INFO));
233229

234-
@Test
235-
public void testServiceOptions() throws Exception {
230+
@Override
231+
public Serializable[] serializableObjects() {
236232
BigQueryOptions options = BigQueryOptions.builder()
237233
.projectId("p1")
238234
.authCredentials(AuthCredentials.createForAppEngine())
239235
.build();
240-
BigQueryOptions serializedCopy = serializeAndDeserialize(options);
241-
assertEquals(options, serializedCopy);
242-
243-
options = options.toBuilder()
236+
BigQueryOptions otherOptions = options.toBuilder()
244237
.projectId("p2")
245238
.retryParams(RetryParams.defaultInstance())
246239
.authCredentials(null)
247240
.build();
248-
serializedCopy = serializeAndDeserialize(options);
249-
assertEquals(options, serializedCopy);
250-
}
251-
252-
@Test
253-
public void testModelAndRequests() throws Exception {
254-
Serializable[] objects = {DOMAIN_ACCESS, GROUP_ACCESS, USER_ACCESS, VIEW_ACCESS, DATASET_ID,
241+
return new Serializable[]{DOMAIN_ACCESS, GROUP_ACCESS, USER_ACCESS, VIEW_ACCESS, DATASET_ID,
255242
DATASET_INFO, TABLE_ID, CSV_OPTIONS, STREAMING_BUFFER, TABLE_DEFINITION,
256243
EXTERNAL_TABLE_DEFINITION, VIEW_DEFINITION, TABLE_SCHEMA, TABLE_INFO, VIEW_INFO,
257244
EXTERNAL_TABLE_INFO, INLINE_FUNCTION, URI_FUNCTION, JOB_STATISTICS, EXTRACT_STATISTICS,
@@ -262,14 +249,7 @@ public void testModelAndRequests() throws Exception {
262249
BigQuery.DatasetOption.fields(), BigQuery.DatasetDeleteOption.deleteContents(),
263250
BigQuery.DatasetListOption.all(), BigQuery.TableOption.fields(),
264251
BigQuery.TableListOption.pageSize(42L), BigQuery.JobOption.fields(),
265-
BigQuery.JobListOption.allUsers(), DATASET, TABLE, JOB};
266-
for (Serializable obj : objects) {
267-
Object copy = serializeAndDeserialize(obj);
268-
assertEquals(obj, obj);
269-
assertEquals(obj, copy);
270-
assertNotSame(obj, copy);
271-
assertEquals(copy, copy);
272-
}
252+
BigQuery.JobListOption.allUsers(), DATASET, TABLE, JOB, options, otherOptions};
273253
}
274254

275255
@Test
@@ -288,17 +268,4 @@ public void testWriteChannelState() throws IOException, ClassNotFoundException {
288268
assertEquals(state.hashCode(), deserializedState.hashCode());
289269
assertEquals(state.toString(), deserializedState.toString());
290270
}
291-
292-
@SuppressWarnings("unchecked")
293-
private <T> T serializeAndDeserialize(T obj)
294-
throws IOException, ClassNotFoundException {
295-
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
296-
try (ObjectOutputStream output = new ObjectOutputStream(bytes)) {
297-
output.writeObject(obj);
298-
}
299-
try (ObjectInputStream input =
300-
new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
301-
return (T) input.readObject();
302-
}
303-
}
304271
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.gcloud;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotSame;
21+
22+
import org.junit.Test;
23+
24+
import java.io.ByteArrayInputStream;
25+
import java.io.ByteArrayOutputStream;
26+
import java.io.IOException;
27+
import java.io.ObjectInputStream;
28+
import java.io.ObjectOutputStream;
29+
import java.io.Serializable;
30+
31+
/**
32+
* Base class for serialization tests. To use this class in your tests override the
33+
* {@code serializableObjects()} method to return all objects that must be serializable.
34+
*/
35+
public abstract class BaseSerializationTest {
36+
37+
public abstract Serializable[] serializableObjects();
38+
39+
@Test
40+
public void testSerializableObjects() throws Exception {
41+
for (Serializable obj : serializableObjects()) {
42+
Object copy = serializeAndDeserialize(obj);
43+
assertEquals(obj, obj);
44+
assertEquals(obj, copy);
45+
assertEquals(obj.hashCode(), copy.hashCode());
46+
assertEquals(obj.toString(), copy.toString());
47+
assertNotSame(obj, copy);
48+
assertEquals(copy, copy);
49+
}
50+
}
51+
52+
@SuppressWarnings("unchecked")
53+
public <T> T serializeAndDeserialize(T obj)
54+
throws IOException, ClassNotFoundException {
55+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
56+
try (ObjectOutputStream output = new ObjectOutputStream(bytes)) {
57+
output.writeObject(obj);
58+
}
59+
try (ObjectInputStream input =
60+
new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
61+
return (T) input.readObject();
62+
}
63+
}
64+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.gcloud;
18+
19+
import com.google.common.collect.ImmutableList;
20+
21+
import java.io.Serializable;
22+
23+
public class SerializationTest extends BaseSerializationTest {
24+
25+
private static final PageImpl<String> PAGE =
26+
new PageImpl<>(null, "cursor", ImmutableList.of("string1", "string2"));
27+
private static final RetryParams RETRY_PARAMS = RetryParams.defaultInstance();
28+
29+
@Override
30+
public Serializable[] serializableObjects() {
31+
return new Serializable[]{PAGE, RETRY_PARAMS};
32+
}
33+
}

branches/pubsub-alpha/gcloud-java-datastore/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
</exclusion>
3434
</exclusions>
3535
</dependency>
36+
<dependency>
37+
<groupId>${project.groupId}</groupId>
38+
<artifactId>gcloud-java-core</artifactId>
39+
<version>${project.version}</version>
40+
<type>test-jar</type>
41+
<scope>test</scope>
42+
</dependency>
3643
<dependency>
3744
<groupId>junit</groupId>
3845
<artifactId>junit</artifactId>

branches/pubsub-alpha/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java

Lines changed: 10 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,17 @@
1717
package com.google.gcloud.datastore;
1818

1919
import static java.nio.charset.StandardCharsets.UTF_8;
20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotSame;
2220

2321
import com.google.api.services.datastore.DatastoreV1;
24-
import com.google.common.collect.ImmutableMultimap;
25-
import com.google.common.collect.Multimap;
2622
import com.google.gcloud.AuthCredentials;
23+
import com.google.gcloud.BaseSerializationTest;
2724
import com.google.gcloud.RetryParams;
2825
import com.google.gcloud.datastore.StructuredQuery.CompositeFilter;
2926
import com.google.gcloud.datastore.StructuredQuery.OrderBy;
3027
import com.google.gcloud.datastore.StructuredQuery.Projection;
3128
import com.google.gcloud.datastore.StructuredQuery.PropertyFilter;
3229

33-
import org.junit.Test;
34-
35-
import java.io.ByteArrayInputStream;
36-
import java.io.ByteArrayOutputStream;
37-
import java.io.IOException;
38-
import java.io.ObjectInputStream;
39-
import java.io.ObjectOutputStream;
40-
41-
public class SerializationTest {
30+
public class SerializationTest extends BaseSerializationTest {
4231

4332
private static final IncompleteKey INCOMPLETE_KEY1 =
4433
IncompleteKey.builder("ds", "k").ancestors(PathElement.of("p", 1)).build();
@@ -114,82 +103,23 @@ public class SerializationTest {
114103
.build();
115104
private static final ProjectionEntity PROJECTION_ENTITY = ProjectionEntity.fromPb(ENTITY1.toPb());
116105

117-
@SuppressWarnings("rawtypes")
118-
private static final Multimap<ValueType, Value> TYPE_TO_VALUES =
119-
ImmutableMultimap.<ValueType, Value>builder()
120-
.put(ValueType.NULL, NULL_VALUE)
121-
.put(ValueType.KEY, KEY_VALUE)
122-
.put(ValueType.STRING, STRING_VALUE)
123-
.putAll(ValueType.ENTITY, EMBEDDED_ENTITY_VALUE1, EMBEDDED_ENTITY_VALUE2,
124-
EMBEDDED_ENTITY_VALUE3)
125-
.put(ValueType.LIST, LIST_VALUE)
126-
.put(ValueType.LONG, LONG_VALUE)
127-
.put(ValueType.DOUBLE, DOUBLE_VALUE)
128-
.put(ValueType.BOOLEAN, BOOLEAN_VALUE)
129-
.put(ValueType.DATE_TIME, DATE_AND_TIME_VALUE)
130-
.put(ValueType.BLOB, BLOB_VALUE)
131-
.put(ValueType.RAW_VALUE, RAW_VALUE)
132-
.build();
133-
134-
@Test
135-
public void testServiceOptions() throws Exception {
106+
@Override
107+
public java.io.Serializable[] serializableObjects() {
136108
DatastoreOptions options = DatastoreOptions.builder()
137109
.authCredentials(AuthCredentials.createForAppEngine())
138110
.normalizeDataset(false)
139111
.projectId("ds1")
140112
.build();
141-
DatastoreOptions serializedCopy = serializeAndDeserialize(options);
142-
assertEquals(options, serializedCopy);
143-
144-
options = options.toBuilder()
113+
DatastoreOptions otherOptions = options.toBuilder()
145114
.namespace("ns1")
146115
.retryParams(RetryParams.defaultInstance())
147116
.authCredentials(null)
148117
.force(true)
149118
.build();
150-
serializedCopy = serializeAndDeserialize(options);
151-
assertEquals(options, serializedCopy);
152-
}
153-
154-
@Test
155-
public void testValues() throws Exception {
156-
for (ValueType valueType : ValueType.values()) {
157-
for (Value<?> value : TYPE_TO_VALUES.get(valueType)) {
158-
Value<?> copy = serializeAndDeserialize(value);
159-
assertEquals(value, value);
160-
assertEquals(value, copy);
161-
assertNotSame(value, copy);
162-
assertEquals(copy, copy);
163-
assertEquals(value.get(), copy.get());
164-
}
165-
}
166-
}
167-
168-
@Test
169-
public void testTypes() throws Exception {
170-
Serializable<?>[] types = { KEY1, KEY2, INCOMPLETE_KEY1, INCOMPLETE_KEY2, ENTITY1, ENTITY2,
171-
ENTITY3, EMBEDDED_ENTITY, PROJECTION_ENTITY, DATE_TIME1, BLOB1, CURSOR1, GQL1, GQL2,
172-
QUERY1, QUERY2, QUERY3};
173-
for (Serializable<?> obj : types) {
174-
Object copy = serializeAndDeserialize(obj);
175-
assertEquals(obj, obj);
176-
assertEquals(obj, copy);
177-
assertNotSame(obj, copy);
178-
assertEquals(copy, copy);
179-
}
180-
}
181-
182-
private <T extends java.io.Serializable> T serializeAndDeserialize(T obj)
183-
throws IOException, ClassNotFoundException {
184-
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
185-
try (ObjectOutputStream output = new ObjectOutputStream(bytes)) {
186-
output.writeObject(obj);
187-
}
188-
try (ObjectInputStream input =
189-
new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
190-
@SuppressWarnings("unchecked")
191-
T result = (T) input.readObject();
192-
return result;
193-
}
119+
return new java.io.Serializable[]{KEY1, KEY2, INCOMPLETE_KEY1, INCOMPLETE_KEY2, ENTITY1,
120+
ENTITY2, ENTITY3, EMBEDDED_ENTITY, PROJECTION_ENTITY, DATE_TIME1, BLOB1, CURSOR1, GQL1,
121+
GQL2, QUERY1, QUERY2, QUERY3, NULL_VALUE, KEY_VALUE, STRING_VALUE, EMBEDDED_ENTITY_VALUE1,
122+
EMBEDDED_ENTITY_VALUE2, EMBEDDED_ENTITY_VALUE3, LIST_VALUE, LONG_VALUE, DOUBLE_VALUE,
123+
BOOLEAN_VALUE, DATE_AND_TIME_VALUE, BLOB_VALUE, RAW_VALUE, options, otherOptions};
194124
}
195125
}

branches/pubsub-alpha/gcloud-java-resourcemanager/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
</exclusion>
3434
</exclusions>
3535
</dependency>
36+
<dependency>
37+
<groupId>${project.groupId}</groupId>
38+
<artifactId>gcloud-java-core</artifactId>
39+
<version>${project.version}</version>
40+
<type>test-jar</type>
41+
<scope>test</scope>
42+
</dependency>
3643
<dependency>
3744
<groupId>junit</groupId>
3845
<artifactId>junit</artifactId>

0 commit comments

Comments
 (0)