Skip to content

Commit 2359f92

Browse files
committed
---
yaml --- r: 3717 b: refs/heads/pubsub-alpha c: 0a113cd h: refs/heads/master i: 3715: 8ea5f46
1 parent b3ec7e6 commit 2359f92

17 files changed

Lines changed: 269 additions & 371 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: 353d2db0962c6a3bd3823cf24c83d0b128fd41d5
5+
refs/heads/pubsub-alpha: 0a113cd7431722d0c10d849a2760a41eb2ce4d87
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: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@
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>
4942
<dependency>
5043
<groupId>junit</groupId>
5144
<artifactId>junit</artifactId>

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQueryException.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.gcloud.RetryHelper.RetryInterruptedException;
2323

2424
import java.io.IOException;
25-
import java.util.Objects;
2625
import java.util.Set;
2726

2827
/**
@@ -74,23 +73,6 @@ protected Set<Error> retryableErrors() {
7473
return RETRYABLE_ERRORS;
7574
}
7675

77-
@Override
78-
public boolean equals(Object obj) {
79-
if (obj == this) {
80-
return true;
81-
}
82-
if (!(obj instanceof BigQueryException)) {
83-
return false;
84-
}
85-
BigQueryException other = (BigQueryException) obj;
86-
return super.equals(other) && Objects.equals(error, other.error);
87-
}
88-
89-
@Override
90-
public int hashCode() {
91-
return Objects.hash(super.hashCode(), error);
92-
}
93-
9476
/**
9577
* Translate RetryHelperException to the BigQueryException that caused the error. This method will
9678
* always throw an exception.

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

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,30 @@
1616

1717
package com.google.gcloud.bigquery;
1818

19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotSame;
21+
1922
import com.google.common.collect.ImmutableList;
2023
import com.google.common.collect.ImmutableMap;
2124
import com.google.gcloud.AuthCredentials;
22-
import com.google.gcloud.BaseSerializationTest;
23-
import com.google.gcloud.Restorable;
25+
import com.google.gcloud.RestorableState;
26+
import com.google.gcloud.RetryParams;
27+
import com.google.gcloud.WriteChannel;
2428
import com.google.gcloud.bigquery.StandardTableDefinition.StreamingBuffer;
2529

30+
import org.junit.Test;
31+
32+
import java.io.ByteArrayInputStream;
33+
import java.io.ByteArrayOutputStream;
34+
import java.io.IOException;
35+
import java.io.ObjectInputStream;
36+
import java.io.ObjectOutputStream;
2637
import java.io.Serializable;
2738
import java.nio.charset.StandardCharsets;
2839
import java.util.List;
2940
import java.util.Map;
3041

31-
public class SerializationTest extends BaseSerializationTest {
42+
public class SerializationTest {
3243

3344
private static final Acl DOMAIN_ACCESS =
3445
Acl.of(new Acl.Domain("domain"), Acl.Role.WRITER);
@@ -219,40 +230,75 @@ public class SerializationTest extends BaseSerializationTest {
219230
new Dataset(BIGQUERY, new DatasetInfo.BuilderImpl(DATASET_INFO));
220231
private static final Table TABLE = new Table(BIGQUERY, new TableInfo.BuilderImpl(TABLE_INFO));
221232
private static final Job JOB = new Job(BIGQUERY, new JobInfo.BuilderImpl(JOB_INFO));
222-
private static final BigQueryException BIG_QUERY_EXCEPTION =
223-
new BigQueryException(42, "message", BIGQUERY_ERROR);
224233

225-
@Override
226-
protected Serializable[] serializableObjects() {
234+
@Test
235+
public void testServiceOptions() throws Exception {
227236
BigQueryOptions options = BigQueryOptions.builder()
228237
.projectId("p1")
229238
.authCredentials(AuthCredentials.createForAppEngine())
230239
.build();
231-
BigQueryOptions otherOptions = options.toBuilder()
240+
BigQueryOptions serializedCopy = serializeAndDeserialize(options);
241+
assertEquals(options, serializedCopy);
242+
243+
options = options.toBuilder()
232244
.projectId("p2")
245+
.retryParams(RetryParams.defaultInstance())
233246
.authCredentials(null)
234247
.build();
235-
return new Serializable[]{DOMAIN_ACCESS, GROUP_ACCESS, USER_ACCESS, VIEW_ACCESS, DATASET_ID,
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,
236255
DATASET_INFO, TABLE_ID, CSV_OPTIONS, STREAMING_BUFFER, TABLE_DEFINITION,
237256
EXTERNAL_TABLE_DEFINITION, VIEW_DEFINITION, TABLE_SCHEMA, TABLE_INFO, VIEW_INFO,
238257
EXTERNAL_TABLE_INFO, INLINE_FUNCTION, URI_FUNCTION, JOB_STATISTICS, EXTRACT_STATISTICS,
239258
LOAD_STATISTICS, QUERY_STATISTICS, BIGQUERY_ERROR, JOB_STATUS, JOB_ID,
240259
COPY_JOB_CONFIGURATION, EXTRACT_JOB_CONFIGURATION, LOAD_CONFIGURATION,
241260
LOAD_JOB_CONFIGURATION, QUERY_JOB_CONFIGURATION, JOB_INFO, INSERT_ALL_REQUEST,
242-
INSERT_ALL_RESPONSE, FIELD_VALUE, QUERY_REQUEST, QUERY_RESPONSE, BIG_QUERY_EXCEPTION,
261+
INSERT_ALL_RESPONSE, FIELD_VALUE, QUERY_REQUEST, QUERY_RESPONSE,
243262
BigQuery.DatasetOption.fields(), BigQuery.DatasetDeleteOption.deleteContents(),
244263
BigQuery.DatasetListOption.all(), BigQuery.TableOption.fields(),
245264
BigQuery.TableListOption.pageSize(42L), BigQuery.JobOption.fields(),
246-
BigQuery.JobListOption.allUsers(), DATASET, TABLE, JOB, options, otherOptions};
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+
}
247273
}
248274

249-
@Override
250-
protected Restorable<?>[] restorableObjects() {
251-
BigQueryOptions options = BigQueryOptions.builder().projectId("p2").build();
275+
@Test
276+
public void testWriteChannelState() throws IOException, ClassNotFoundException {
277+
BigQueryOptions options = BigQueryOptions.builder()
278+
.projectId("p2")
279+
.retryParams(RetryParams.defaultInstance())
280+
.build();
252281
// avoid closing when you don't want partial writes upon failure
253282
@SuppressWarnings("resource")
254283
TableDataWriteChannel writer =
255284
new TableDataWriteChannel(options, LOAD_CONFIGURATION, "upload-id");
256-
return new Restorable<?>[]{writer};
285+
RestorableState<WriteChannel> state = writer.capture();
286+
RestorableState<WriteChannel> deserializedState = serializeAndDeserialize(state);
287+
assertEquals(state, deserializedState);
288+
assertEquals(state.hashCode(), deserializedState.hashCode());
289+
assertEquals(state.toString(), deserializedState.toString());
290+
}
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+
}
257303
}
258304
}

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,8 @@ private static class NoAuthCredentialsState
276276
public AuthCredentials restore() {
277277
return INSTANCE;
278278
}
279-
280-
@Override
281-
public int hashCode() {
282-
return getClass().getName().hashCode();
283-
}
284-
285-
@Override
286-
public boolean equals(Object obj) {
287-
return obj instanceof NoAuthCredentialsState;
288-
}
289279
}
290280

291-
private NoAuthCredentials() {}
292-
293281
@Override
294282
public GoogleCredentials credentials() {
295283
return null;

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/gcloud/BaseServiceException.java

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@
3232
*/
3333
public class BaseServiceException extends RuntimeException {
3434

35-
private static final long serialVersionUID = 759921776378760835L;
36-
public static final int UNKNOWN_CODE = 0;
37-
38-
private final int code;
39-
private final boolean retryable;
40-
private final String reason;
41-
private final boolean idempotent;
42-
private final String location;
43-
private final String debugInfo;
44-
4535
protected static final class Error implements Serializable {
4636

4737
private static final long serialVersionUID = -4019600198652965721L;
@@ -89,6 +79,16 @@ public int hashCode() {
8979
}
9080
}
9181

82+
private static final long serialVersionUID = 759921776378760835L;
83+
public static final int UNKNOWN_CODE = 0;
84+
85+
private final int code;
86+
private final boolean retryable;
87+
private final String reason;
88+
private final boolean idempotent;
89+
private final String location;
90+
private final String debugInfo;
91+
9292
public BaseServiceException(IOException exception, boolean idempotent) {
9393
super(message(exception), exception);
9494
int code = UNKNOWN_CODE;
@@ -198,31 +198,6 @@ protected String debugInfo() {
198198
return debugInfo;
199199
}
200200

201-
@Override
202-
public boolean equals(Object obj) {
203-
if (obj == this) {
204-
return true;
205-
}
206-
if (!(obj instanceof BaseServiceException)) {
207-
return false;
208-
}
209-
BaseServiceException other = (BaseServiceException) obj;
210-
return Objects.equals(getCause(), other.getCause())
211-
&& Objects.equals(getMessage(), other.getMessage())
212-
&& code == other.code
213-
&& retryable == other.retryable
214-
&& Objects.equals(reason, other.reason)
215-
&& idempotent == other.idempotent
216-
&& Objects.equals(location, other.location)
217-
&& Objects.equals(debugInfo, other.debugInfo);
218-
}
219-
220-
@Override
221-
public int hashCode() {
222-
return Objects.hash(getCause(), getMessage(), code, retryable, reason, idempotent, location,
223-
debugInfo);
224-
}
225-
226201
protected static String reason(GoogleJsonError error) {
227202
if (error.getErrors() != null && !error.getErrors().isEmpty()) {
228203
return error.getErrors().get(0).getReason();

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/gcloud/ExceptionHandler.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.io.Serializable;
2828
import java.lang.reflect.Method;
29-
import java.util.Objects;
3029
import java.util.Set;
3130
import java.util.concurrent.Callable;
3231

@@ -260,26 +259,6 @@ boolean shouldRetry(Exception ex) {
260259
return retryResult == Interceptor.RetryResult.RETRY;
261260
}
262261

263-
@Override
264-
public int hashCode() {
265-
return Objects.hash(interceptors, retriableExceptions, nonRetriableExceptions, retryInfo);
266-
}
267-
268-
@Override
269-
public boolean equals(Object obj) {
270-
if (obj == this) {
271-
return true;
272-
}
273-
if (!(obj instanceof ExceptionHandler)) {
274-
return false;
275-
}
276-
ExceptionHandler other = (ExceptionHandler) obj;
277-
return Objects.equals(interceptors, other.interceptors)
278-
&& Objects.equals(retriableExceptions, other.retriableExceptions)
279-
&& Objects.equals(nonRetriableExceptions, other.nonRetriableExceptions)
280-
&& Objects.equals(retryInfo, other.retryInfo);
281-
}
282-
283262
/**
284263
* Returns an instance which retry any checked exception and abort on any runtime exception.
285264
*/

branches/pubsub-alpha/gcloud-java-core/src/test/java/com/google/gcloud/BaseSerializationTest.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)