Skip to content

Commit 551e9fd

Browse files
committed
Add serialization test for PubSub classes
1 parent 7a7574d commit 551e9fd

2 files changed

Lines changed: 109 additions & 1 deletion

File tree

gcloud-java-pubsub/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,20 @@
3030
<dependency>
3131
<groupId>io.grpc</groupId>
3232
<artifactId>grpc-all</artifactId>
33-
<version>0.12.0</version>
33+
<version>0.14.0</version>
3434
</dependency>
3535
<dependency>
3636
<groupId>com.google.auto.value</groupId>
3737
<artifactId>auto-value</artifactId>
3838
<version>1.1</version>
3939
</dependency>
40+
<dependency>
41+
<groupId>${project.groupId}</groupId>
42+
<artifactId>gcloud-java-core</artifactId>
43+
<version>${project.version}</version>
44+
<type>test-jar</type>
45+
<scope>test</scope>
46+
</dependency>
4047
<dependency>
4148
<groupId>junit</groupId>
4249
<artifactId>junit</artifactId>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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.pubsub;
18+
19+
import com.google.cloud.AuthCredentials;
20+
import com.google.cloud.BaseSerializationTest;
21+
import com.google.cloud.GrpcServiceOptions.ExecutorFactory;
22+
import com.google.cloud.Restorable;
23+
import com.google.cloud.pubsub.PubSub.ListOption;
24+
import com.google.cloud.pubsub.PubSub.PullOption;
25+
26+
import java.io.Serializable;
27+
import java.util.concurrent.ScheduledExecutorService;
28+
29+
public class SerializationTest extends BaseSerializationTest {
30+
31+
private static final PubSub PUB_SUB = PubSubOptions.builder()
32+
.projectId("p")
33+
.authCredentials(AuthCredentials.noAuth())
34+
.build().service();
35+
private static final Message MESSAGE = Message.of("payload");
36+
private static final com.google.pubsub.v1.ReceivedMessage RECEIVED_MESSAGE_PB =
37+
com.google.pubsub.v1.ReceivedMessage.newBuilder()
38+
.setMessage(MESSAGE.toPb())
39+
.setAckId("ackId")
40+
.build();
41+
private static final ReceivedMessage RECEIVED_MESSAGE =
42+
ReceivedMessage.fromPb(PUB_SUB, "subscription", RECEIVED_MESSAGE_PB);
43+
private static final SubscriptionInfo SUBSCRIPTION_INFO = SubscriptionInfo.of("topic", "sub");
44+
private static final Subscription SUBSCRIPTION =
45+
new Subscription(PUB_SUB, new SubscriptionInfo.BuilderImpl(SUBSCRIPTION_INFO));
46+
private static final SubscriptionId SUBSCRIPTION_ID = new SubscriptionId("project", "sub");
47+
private static final TopicInfo TOPIC_INFO = TopicInfo.of("topic");
48+
private static final Topic TOPIC =
49+
new Topic(PUB_SUB, new TopicInfo.BuilderImpl(TOPIC_INFO));
50+
private static final ListOption PAGE_TOKEN_OPTION = ListOption.pageToken("cursor");
51+
private static final ListOption PAGE_SIZE_OPTION = ListOption.pageSize(42);
52+
private static final PullOption MAX_QUEUED_CALLBACKS_OPTION = PullOption.maxQueuedCallbacks(42);
53+
private static final PullOption EXECUTOR_FACTORY_OPTION =
54+
PullOption.executorFactory(new TestExecutorFactory());
55+
56+
public static class TestExecutorFactory
57+
implements ExecutorFactory<ScheduledExecutorService>, Serializable {
58+
59+
private static final long serialVersionUID = -2154875338174302704L;
60+
61+
@Override
62+
public ScheduledExecutorService get() {
63+
return null;
64+
}
65+
66+
@Override
67+
public void release(ScheduledExecutorService executor) {
68+
// do nothing
69+
}
70+
71+
@Override
72+
public boolean equals(Object obj) {
73+
return obj instanceof TestExecutorFactory;
74+
}
75+
76+
@Override
77+
public int hashCode() {
78+
return 1;
79+
}
80+
}
81+
82+
@Override
83+
protected Serializable[] serializableObjects() {
84+
PubSubOptions options = PubSubOptions.builder()
85+
.projectId("p1")
86+
.initialTimeout(1234)
87+
.build();
88+
PubSubOptions otherOptions = options.toBuilder()
89+
.projectId("p2")
90+
.executorFactory(new TestExecutorFactory())
91+
.build();
92+
return new Serializable[]{options, otherOptions, MESSAGE, RECEIVED_MESSAGE, SUBSCRIPTION_INFO,
93+
SUBSCRIPTION, SUBSCRIPTION_ID, TOPIC_INFO, TOPIC, PAGE_TOKEN_OPTION, PAGE_SIZE_OPTION,
94+
MAX_QUEUED_CALLBACKS_OPTION, EXECUTOR_FACTORY_OPTION};
95+
}
96+
97+
@Override
98+
protected Restorable<?>[] restorableObjects() {
99+
return null;
100+
}
101+
}

0 commit comments

Comments
 (0)