Skip to content

Commit

Permalink
fix: add test coverage for cloudpubsub folder. (#218)
Browse files Browse the repository at this point in the history
* fix: Add a test for SinglePartitionPublisherBuilder.

* fix: Add a test for Versions.

* fix: Add a test for ChannelCache.

* fix: Improve ConnectedSubscriberImpl coverage.

* fix: Add a test for RoutingPublisher.

* fix: Add a test for PublisherBuilder.

* fix: Add test coverage for remaining builders.

* fix: Add licence headers.

* fix: Add test coverage for cloudpubsub folder.

* fix: Add test coverage for cloudpubsub folder.

* fix: Make PublisherSettingsTest actually instantiate a Publisher.

* fix: Add license headers.

* fix: Add AckSetTrackerImplTest

* fix: Update clirr to add change 7006 and put two stars after blanket ignored folders.
  • Loading branch information
dpcollins-google committed Aug 24, 2020
1 parent 3a9909e commit a70a60f
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 42 deletions.
93 changes: 56 additions & 37 deletions google-cloud-pubsublite/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- see http://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
<differences>
<!-- TODO: remove after next version release -->
<difference>
<differenceType>6001</differenceType>
<className>com/google/cloud/pubsublite/AdminClientSettings</className>
<field>DEFAULT_RETRY_SETTINGS</field>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/SubscriberSettings*</className>
<method>*</method>
</difference>
<!-- Blanket ignored files -->
<difference>
<differenceType>6000</differenceType>
<className>com/google/cloud/pubsublite/internal/*</className>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>6001</differenceType>
<className>com/google/cloud/pubsublite/internal/*</className>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7001</differenceType>
<className>com/google/cloud/pubsublite/internal/*</className>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/pubsublite/internal/*</className>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7006</differenceType>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
<to>*</to>
</difference>
<difference>
<differenceType>7011</differenceType>
Expand All @@ -40,106 +35,130 @@
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/pubsublite/internal/*</className>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/pubsublite/internal/*</className>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>8000</differenceType>
<className>com/google/cloud/pubsublite/internal/*</className>
<className>com/google/cloud/pubsublite/internal/**</className>
</difference>
<difference>
<differenceType>8001</differenceType>
<className>com/google/cloud/pubsublite/internal/*</className>
<className>com/google/cloud/pubsublite/internal/**</className>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/pubsublite/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>8000</differenceType>
<className>com/google/cloud/pubsublite/internal/**</className>
</difference>
<difference>
<differenceType>8001</differenceType>
<className>com/google/cloud/pubsublite/internal/**</className>
</difference>
<difference>
<differenceType>6000</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/*</className>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>6001</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/*</className>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7001</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/*</className>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/*</className>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7006</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
<method>*</method>
<to>*</to>
</difference>
<difference>
<differenceType>7011</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/*</className>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/*</className>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/*</className>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>8000</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/*</className>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
</difference>
<difference>
<differenceType>8001</differenceType>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/*</className>
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
</difference>
<difference>
<differenceType>6000</differenceType>
<className>com/google/cloud/pubsublite/v1/*</className>
<className>com/google/cloud/pubsublite/v1/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>6001</differenceType>
<className>com/google/cloud/pubsublite/v1/*</className>
<className>com/google/cloud/pubsublite/v1/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7001</differenceType>
<className>com/google/cloud/pubsublite/v1/*</className>
<className>com/google/cloud/pubsublite/v1/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/pubsublite/v1/*</className>
<className>com/google/cloud/pubsublite/v1/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7011</differenceType>
<className>com/google/cloud/pubsublite/v1/*</className>
<className>com/google/cloud/pubsublite/v1/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/pubsublite/v1/*</className>
<className>com/google/cloud/pubsublite/v1/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/pubsublite/v1/*</className>
<className>com/google/cloud/pubsublite/v1/**</className>
<method>*</method>
</difference>
<difference>
<differenceType>8000</differenceType>
<className>com/google/cloud/pubsublite/v1/*</className>
<className>com/google/cloud/pubsublite/v1/**</className>
</difference>
<difference>
<differenceType>8001</differenceType>
<className>com/google/cloud/pubsublite/v1/*</className>
<className>com/google/cloud/pubsublite/v1/**</className>
</difference>
</differences>
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ public abstract class PublisherSettings {

abstract Optional<PublisherServiceStub> stub();

// For testing.
abstract SinglePartitionPublisherBuilder.Builder underlyingBuilder();

// For testing.
abstract Optional<Integer> numPartitions();

public static Builder newBuilder() {
return new AutoValue_PublisherSettings.Builder();
return new AutoValue_PublisherSettings.Builder()
.setUnderlyingBuilder(SinglePartitionPublisherBuilder.newBuilder());
}

@AutoValue.Builder
Expand All @@ -75,6 +82,13 @@ public abstract Builder setMessageTransformer(

public abstract Builder setStub(PublisherServiceStub stub);

// For testing.
abstract Builder setUnderlyingBuilder(
SinglePartitionPublisherBuilder.Builder underlyingBuilder);

// For testing.
abstract Builder setNumPartitions(int numPartitions);

public abstract PublisherSettings build();
}

Expand All @@ -87,7 +101,7 @@ Publisher instantiate() throws StatusException {
.orElseGet(() -> MessageTransforms.fromCpsPublishTransformer(keyExtractor));

SinglePartitionPublisherBuilder.Builder singlePartitionPublisherBuilder =
SinglePartitionPublisherBuilder.newBuilder()
underlyingBuilder()
.setBatchingSettings(Optional.of(batchingSettings))
.setStub(stub())
.setContext(PubsubContext.of(FRAMEWORK));
Expand All @@ -97,6 +111,8 @@ Publisher instantiate() throws StatusException {
.setTopic(topicPath())
.setPublisherBuilder(singlePartitionPublisherBuilder);

numPartitions().ifPresent(wireBuilder::setNumPartitions);

return new WrappingPublisher(wireBuilder.build(), messageTransformer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract static class Builder {
public abstract Builder setTopic(TopicPath path);

// If a topic is specified in the underlying SinglePartitionPublisherBuilder, the value will be
// overwritten by the topic provided to the RouthingPublisherBuilder.
// overwritten by the topic provided to the RoutingPublisherBuilder.
public abstract Builder setPublisherBuilder(SinglePartitionPublisherBuilder.Builder builder);

// Optional parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import com.google.api.gax.batching.BatchingSettings;
import com.google.auto.value.AutoValue;
import com.google.cloud.pubsublite.Partition;
import com.google.cloud.pubsublite.PublishMetadata;
import com.google.cloud.pubsublite.TopicPath;
import com.google.cloud.pubsublite.internal.Publisher;
import com.google.cloud.pubsublite.proto.PublisherServiceGrpc;
import io.grpc.StatusException;
import java.util.Optional;
Expand Down Expand Up @@ -69,7 +71,7 @@ public abstract static class Builder {

abstract SinglePartitionPublisherBuilder autoBuild();

public SinglePartitionPublisher build() throws StatusException {
public Publisher<PublishMetadata> build() throws StatusException {
SinglePartitionPublisherBuilder builder = autoBuild();
PublisherBuilder.Builder publisherBuilder =
builder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.pubsublite.cloudpubsub;

import static org.mockito.Mockito.RETURNS_SELF;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

import com.google.cloud.pubsublite.CloudZone;
import com.google.cloud.pubsublite.ProjectNumber;
import com.google.cloud.pubsublite.PublishMetadata;
import com.google.cloud.pubsublite.TopicName;
import com.google.cloud.pubsublite.TopicPath;
import com.google.cloud.pubsublite.TopicPaths;
import com.google.cloud.pubsublite.internal.FakeApiService;
import com.google.cloud.pubsublite.internal.Publisher;
import com.google.cloud.pubsublite.internal.wire.SinglePartitionPublisherBuilder;
import com.google.cloud.pubsublite.proto.PublisherServiceGrpc;
import io.grpc.Channel;
import io.grpc.StatusException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Spy;

@RunWith(JUnit4.class)
public class PublisherSettingsTest {
TopicPath getPath() throws StatusException {
return TopicPaths.newBuilder()
.setProjectNumber(ProjectNumber.of(56))
.setZone(CloudZone.parse("us-central1-a"))
.setTopicName(TopicName.of("xyz"))
.build();
}

abstract static class FakePublisher extends FakeApiService
implements Publisher<PublishMetadata> {}

@Spy private FakePublisher underlying;

@Test
public void testSettings() throws StatusException {
initMocks(this);
Channel mockChannel = mock(Channel.class);
SinglePartitionPublisherBuilder.Builder mockBuilder =
mock(SinglePartitionPublisherBuilder.Builder.class, RETURNS_SELF);
when(mockBuilder.build()).thenReturn(underlying);
PublisherSettings.newBuilder()
.setTopicPath(getPath())
.setStub(PublisherServiceGrpc.newStub(mockChannel))
.setUnderlyingBuilder(mockBuilder)
.setNumPartitions(77)
.build()
.instantiate();
}
}
Loading

0 comments on commit a70a60f

Please sign in to comment.