Skip to content

Commit 38e44d5

Browse files
committed
---
yaml --- r: 2383 b: refs/heads/update-datastore c: dea8eff h: refs/heads/master i: 2381: a7d3d0c 2379: f90ae6f 2375: 7f8a6cc 2367: 804ccae
1 parent 6810c7e commit 38e44d5

2 files changed

Lines changed: 115 additions & 1 deletion

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
66
refs/heads/pubsub-alpha: 1a0e970f265af871e02274085b9662b3fe29058b
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
8-
refs/heads/update-datastore: 3fc189bbad20e177fcdc9592089357c79d25c2d0
8+
refs/heads/update-datastore: dea8effe8e4b2011dc87507d4d391081b3d4b37d
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
1010
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd
1111
refs/tags/v0.0.11: ffbfba48a6426ff63c08ff2117e58681f251fbf2
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright 2015 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.bigquery;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotSame;
21+
22+
import com.google.common.collect.ImmutableList;
23+
import com.google.gcloud.AuthCredentials;
24+
import com.google.gcloud.RetryParams;
25+
26+
import org.junit.Test;
27+
28+
import java.io.ByteArrayInputStream;
29+
import java.io.ByteArrayOutputStream;
30+
import java.io.IOException;
31+
import java.io.ObjectInputStream;
32+
import java.io.ObjectOutputStream;
33+
import java.io.Serializable;
34+
import java.util.List;
35+
36+
public class SerializationTest {
37+
38+
private static final Acl DOMAIN_ACCESS =
39+
new Acl(new Acl.Domain("domain"), Acl.Role.WRITER);
40+
private static final Acl GROUP_ACCESS =
41+
new Acl(Acl.Group.ofAllAuthenticatedUsers(), Acl.Role.READER);
42+
private static final Acl USER_ACCESS = new Acl(new Acl.User("user"), Acl.Role.OWNER);
43+
private static final Acl VIEW_ACCESS =
44+
new Acl(new Acl.View(TableId.of("project", "dataset", "table")), Acl.Role.WRITER);
45+
private static final List<Acl> ACCESS_RULES = ImmutableList.of(DOMAIN_ACCESS, GROUP_ACCESS,
46+
VIEW_ACCESS, USER_ACCESS);
47+
private static final Long CREATION_TIME = System.currentTimeMillis() - 10;
48+
private static final Long DEFAULT_TABLE_EXPIRATION = 100L;
49+
private static final String DESCRIPTION = "Description";
50+
private static final String ETAG = "0xFF00";
51+
private static final String FRIENDLY_NAME = "friendlyDataset";
52+
private static final String ID = "P/D:1";
53+
private static final Long LAST_MODIFIED = CREATION_TIME + 50;
54+
private static final String LOCATION = "";
55+
private static final String SELF_LINK = "http://bigquery/p/d";
56+
private static final DatasetId DATASET_ID = DatasetId.of("project", "dataset");
57+
private static final DatasetInfo DATASET_INFO = DatasetInfo.builder(DATASET_ID)
58+
.acl(ACCESS_RULES)
59+
.creationTime(CREATION_TIME)
60+
.defaultTableLifetime(DEFAULT_TABLE_EXPIRATION)
61+
.description(DESCRIPTION)
62+
.etag(ETAG)
63+
.friendlyName(FRIENDLY_NAME)
64+
.id(ID)
65+
.lastModified(LAST_MODIFIED)
66+
.location(LOCATION)
67+
.selfLink(SELF_LINK)
68+
.build();
69+
private static final TableId TABLE_ID = TableId.of("project", "dataset", "table");
70+
71+
@Test
72+
public void testServiceOptions() throws Exception {
73+
BigQueryOptions options = BigQueryOptions.builder()
74+
.projectId("p1")
75+
.authCredentials(AuthCredentials.createForAppEngine())
76+
.build();
77+
BigQueryOptions serializedCopy = serializeAndDeserialize(options);
78+
assertEquals(options, serializedCopy);
79+
80+
options = options.toBuilder()
81+
.projectId("p2")
82+
.retryParams(RetryParams.getDefaultInstance())
83+
.authCredentials(AuthCredentials.noCredentials())
84+
.build();
85+
serializedCopy = serializeAndDeserialize(options);
86+
assertEquals(options, serializedCopy);
87+
}
88+
89+
@Test
90+
public void testModelAndRequests() throws Exception {
91+
Serializable[] objects = {DOMAIN_ACCESS, GROUP_ACCESS, USER_ACCESS, VIEW_ACCESS, DATASET_ID,
92+
DATASET_INFO, TABLE_ID};
93+
for (Serializable obj : objects) {
94+
Object copy = serializeAndDeserialize(obj);
95+
assertEquals(obj, obj);
96+
assertEquals(obj, copy);
97+
assertNotSame(obj, copy);
98+
assertEquals(copy, copy);
99+
}
100+
}
101+
102+
@SuppressWarnings("unchecked")
103+
private <T extends java.io.Serializable> T serializeAndDeserialize(T obj)
104+
throws IOException, ClassNotFoundException {
105+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
106+
try (ObjectOutputStream output = new ObjectOutputStream(bytes)) {
107+
output.writeObject(obj);
108+
}
109+
try (ObjectInputStream input =
110+
new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
111+
return (T) input.readObject();
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)