diff --git a/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java b/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java index d7f668ab660b..6e707885dfa2 100644 --- a/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java +++ b/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java @@ -372,11 +372,7 @@ private static final class OutstandingBatch { this.batchSizeBytes = batchSizeBytes; } - public int getAttempt() { - return attempt; - } - - public int size() { + int size() { return outstandingPublishes.size(); } } diff --git a/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java b/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java index 5433eb753bca..7453cde8a446 100644 --- a/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java +++ b/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java @@ -149,7 +149,7 @@ private Subscriber(Builder builder) { closeables.add( new AutoCloseable() { @Override - public void close() throws IOException { + public void close() { alarmsExecutor.shutdown(); } }); diff --git a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java index f3b5dfe6e704..34f4f2cda60b 100644 --- a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java +++ b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/it/ITPubSubTest.java @@ -80,7 +80,7 @@ public static void setupClass() throws Exception { } @AfterClass - public static void tearDownClass() throws Exception { + public static void tearDownClass() { topicAdminClient.close(); subscriptionAdminClient.close(); } @@ -114,7 +114,7 @@ public void testTopicPolicy() { } @Test - public void testVPCPushSubscriber() throws Exception { + public void testVPCPushSubscriber() { assumeTrue(IS_VPC_TEST); ProjectTopicName topicName = ProjectTopicName.of(projectId, formatForTest("testing-vpc-push-subscriber-topic")); diff --git a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeScheduledExecutorService.java b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeScheduledExecutorService.java index b0ac68aa220e..e63b68748103 100644 --- a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeScheduledExecutorService.java +++ b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeScheduledExecutorService.java @@ -86,35 +86,6 @@ public ScheduledFuture scheduleWithFixedDelay( PendingCallableType.FIXED_DELAY)); } - /** - * This allows for adding expectations on future work to be scheduled ( {@link - * FakeScheduledExecutorService#schedule} or {@link - * FakeScheduledExecutorService#scheduleAtFixedRate} or {@link - * FakeScheduledExecutorService#scheduleWithFixedDelay}) based on its delay. - */ - public void setupScheduleExpectation(Duration delay) { - synchronized (expectedWorkQueue) { - expectedWorkQueue.add(delay); - } - } - - /** - * Blocks the current thread until all the work {@link - * FakeScheduledExecutorService#setupScheduleExpectation(Duration) expected} has been scheduled in - * the executor. - */ - public void waitForExpectedWork() { - synchronized (expectedWorkQueue) { - while (!expectedWorkQueue.isEmpty()) { - try { - expectedWorkQueue.wait(); - } catch (InterruptedException e) { - // Wait uninterruptibly - } - } - } - } - /** * This will advance the reference time of the executor and execute (in the same thread) any * outstanding callable which execution time has passed. @@ -232,7 +203,7 @@ ScheduledFuture schedulePendingCallable(PendingCallable callable) { return callable.getScheduledFuture(); } - static enum PendingCallableType { + enum PendingCallableType { NORMAL, FIXED_RATE, FIXED_DELAY @@ -252,7 +223,7 @@ class PendingCallable implements Comparable> { pendingCallable = new Callable() { @Override - public T call() throws Exception { + public T call() { runnable.run(); return null; } diff --git a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeSubscriberServiceImpl.java b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeSubscriberServiceImpl.java index e7d86e65acc9..c6336fa1cef7 100644 --- a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeSubscriberServiceImpl.java +++ b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/FakeSubscriberServiceImpl.java @@ -17,8 +17,6 @@ package com.google.cloud.pubsub.v1; import com.google.api.client.util.Preconditions; -import com.google.api.core.InternalApi; -import com.google.common.collect.ImmutableList; import com.google.protobuf.Empty; import com.google.pubsub.v1.AcknowledgeRequest; import com.google.pubsub.v1.GetSubscriptionRequest; @@ -61,7 +59,7 @@ class FakeSubscriberServiceImpl extends SubscriberImplBase { private final BlockingQueue pullResponses = new LinkedBlockingDeque<>(); private int currentStream; - public static enum CloseSide { + public enum CloseSide { SERVER, CLIENT } @@ -76,10 +74,6 @@ public ModifyAckDeadline(String ackId, long seconds) { this.seconds = seconds; } - public String getAckId() { - return ackId; - } - public long getSeconds() { return seconds; } @@ -207,23 +201,6 @@ public StreamObserver streamingPull( return stream.requestObserver; } - public void sendStreamingResponse(StreamingPullResponse pullResponse) - throws InterruptedException { - waitForRegistedSubscription(); - synchronized (openedStreams) { - waitForOpenedStreams(1); - openedStreams.get(getAndAdvanceCurrentStream()).responseObserver.onNext(pullResponse); - } - } - - public void setMessageAckDeadlineSeconds(int ackDeadline) { - messageAckDeadline.set(ackDeadline); - } - - public void enqueuePullResponse(PullResponse response) { - pullResponses.add(response); - } - @Override public void getSubscription( GetSubscriptionRequest request, StreamObserver responseObserver) { @@ -237,12 +214,6 @@ public void getSubscription( responseObserver.onCompleted(); } - /** Returns the number of times getSubscription is called. */ - @InternalApi - int getSubscriptionCalledCount() { - return getSubscriptionCalled.get(); - } - @Override public void pull(PullRequest request, StreamObserver responseObserver) { synchronized (receivedPullRequest) { @@ -293,26 +264,6 @@ public String waitForRegistedSubscription() throws InterruptedException { return subscription; } - public List waitAndConsumeReceivedAcks(int expectedCount) throws InterruptedException { - synchronized (acks) { - waitAtLeast(acks, expectedCount); - List receivedAcksCopy = ImmutableList.copyOf(acks.subList(0, expectedCount)); - acks.subList(0, expectedCount).clear(); - return receivedAcksCopy; - } - } - - public List waitAndConsumeModifyAckDeadlines(int expectedCount) - throws InterruptedException { - synchronized (modAckDeadlines) { - waitAtLeast(modAckDeadlines, expectedCount); - List modAckDeadlinesCopy = - ImmutableList.copyOf(modAckDeadlines.subList(0, expectedCount)); - modAckDeadlines.subList(0, expectedCount).clear(); - return modAckDeadlinesCopy; - } - } - public int waitForClosedStreams(int expectedCount) throws InterruptedException { synchronized (closedStreams) { waitAtLeast(closedStreams, expectedCount); @@ -341,50 +292,6 @@ private static void waitAtLeast(Collection collection, int target) } } - public void waitForStreamAckDeadline(int expectedValue) throws InterruptedException { - synchronized (messageAckDeadline) { - while (messageAckDeadline.get() != expectedValue) { - messageAckDeadline.wait(); - } - } - } - - public int getOpenedStreamsCount() { - return openedStreams.size(); - } - - public int getClosedStreamsCount() { - return closedStreams.size(); - } - - public List getAcks() { - return acks; - } - - public List getModifyAckDeadlines() { - return modAckDeadlines; - } - - public void reset() { - synchronized (subscriptionInitialized) { - synchronized (openedStreams) { - synchronized (acks) { - synchronized (modAckDeadlines) { - openedStreams.clear(); - closedStreams.clear(); - acks.clear(); - modAckDeadlines.clear(); - subscriptionInitialized.set(false); - subscription = ""; - pullResponses.clear(); - receivedPullRequest.clear(); - currentStream = 0; - } - } - } - } - } - private void addOpenedStream(Stream stream) { synchronized (openedStreams) { openedStreams.add(stream); diff --git a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MessageDispatcherTest.java b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MessageDispatcherTest.java index c4ca6e51a023..163475407f04 100644 --- a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MessageDispatcherTest.java +++ b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MessageDispatcherTest.java @@ -123,7 +123,7 @@ public void sendAckOperations( } @Test - public void testReceipt() throws Exception { + public void testReceipt() { dispatcher.processReceivedMessages(Collections.singletonList(TEST_MESSAGE)); dispatcher.processOutstandingAckOperations(); assertThat(sentModAcks) @@ -160,7 +160,7 @@ public void testExtension() throws Exception { } @Test - public void testExtension_Close() throws Exception { + public void testExtension_Close() { dispatcher.processReceivedMessages(Collections.singletonList(TEST_MESSAGE)); dispatcher.extendDeadlines(); assertThat(sentModAcks) diff --git a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/OpenCensusUtilTest.java b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/OpenCensusUtilTest.java index 329cf60288cc..d4230003907d 100644 --- a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/OpenCensusUtilTest.java +++ b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/OpenCensusUtilTest.java @@ -56,7 +56,7 @@ public class OpenCensusUtilTest { // Verifies that trace contexts propagated as an attribute are set as the parent link in the // message receiver and that the tag context is not change (for now). @Test - public void testOpenCensusMessageReceiver() throws Exception { + public void testOpenCensusMessageReceiver() { PubsubMessage message; SpanContext publisherContext; try (Scope traceScope = OpenCensusUtil.createScopedSpan(TEST_PARENT_LINK_NAME); @@ -143,7 +143,7 @@ private void assertSpanCount(int expected) { Stopwatch watch = Stopwatch.createStarted(); while (true) { Collection spanDatas = runningSpanStore.getRunningSpans(RECEIVER_FILTER); - if (spanDatas.size() == 1) { + if (spanDatas.size() == expected) { break; } Thread.yield(); diff --git a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java index 2901ae4b0a9d..fc34e5f890a2 100644 --- a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java +++ b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java @@ -68,8 +68,6 @@ public class PublisherImplTest { private Server testServer; - class FakeException extends Exception {} - @Before public void setUp() throws Exception { testPublisherServiceImpl = new FakePublisherServiceImpl(); @@ -454,7 +452,7 @@ public void testBuilderInvalidArguments() { builder.setBatchingSettings( Publisher.Builder.DEFAULT_BATCHING_SETTINGS .toBuilder() - .setRequestByteThreshold((Long) null) + .setRequestByteThreshold(null) .build()); fail("Should have thrown an NullPointerException"); } catch (NullPointerException expected) { @@ -513,7 +511,7 @@ public void testBuilderInvalidArguments() { builder.setBatchingSettings( Publisher.Builder.DEFAULT_BATCHING_SETTINGS .toBuilder() - .setElementCountThreshold((Long) null) + .setElementCountThreshold(null) .build()); fail("Should have thrown an NullPointerException"); } catch (NullPointerException expected) { diff --git a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java index 68b967e79f76..b8a98e97a9c7 100644 --- a/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java +++ b/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/SubscriberTest.java @@ -140,7 +140,7 @@ public void testFailedChannel_fatalError_subscriberFails() throws Exception { } } - private Subscriber startSubscriber(Builder testSubscriberBuilder) throws Exception { + private Subscriber startSubscriber(Builder testSubscriberBuilder) { Subscriber subscriber = testSubscriberBuilder.build(); subscriber.startAsync().awaitRunning(); return subscriber;