Skip to content

Commit

Permalink
fix: Fix assorted lint errors. (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpcollins-google committed Jun 16, 2020
1 parent d2a90d8 commit 403efb6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void createSubscribers() throws StatusException {
leakedReceiver.handleAssignment(ImmutableSet.of(Partition.of(1)));
verify(subscriberFactory).New(Partition.of(1));
verify(sub1).startAsync();
clearInvocations(sub1);
reset(sub1);

Subscriber sub2 = spy(FakeSubscriber.class);
when(subscriberFactory.New(Partition.of(2))).thenReturn(sub2);
Expand All @@ -101,7 +101,7 @@ public void createAndEvict() throws StatusException {
leakedReceiver.handleAssignment(ImmutableSet.of(Partition.of(1)));
verify(subscriberFactory).New(Partition.of(1));
verify(sub1).startAsync();
clearInvocations(sub1);
reset(sub1);

Subscriber sub2 = spy(FakeSubscriber.class);
when(subscriberFactory.New(Partition.of(2))).thenReturn(sub2);
Expand All @@ -117,7 +117,7 @@ private Subscriber initSub1() throws StatusException {
leakedReceiver.handleAssignment(ImmutableSet.of(Partition.of(1)));
verify(subscriberFactory).New(Partition.of(1));
verify(sub1).startAsync();
clearInvocations(sub1);
reset(sub1);
return sub1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

Expand Down Expand Up @@ -180,8 +180,8 @@ private void initialize() {
.onNext(initialRequest());
assigner = FACTORY.New(stub::assignPartitions, mockOutputStream, initialRequest());
verify(mockRequestStream).onNext(initialRequest());
clearInvocations(mockRequestStream);
clearInvocations(mockOutputStream);
reset(mockRequestStream);
reset(mockOutputStream);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.pubsublite.internal.wire;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;

import com.google.cloud.pubsublite.Message;
import com.google.cloud.pubsublite.Offset;
Expand All @@ -41,7 +42,7 @@ public void onClientFlowRequestIncrementsTokens() throws StatusException {
batcher.onClientFlowRequest(clientFlowRequest);

assertThat(batcher.releasePendingRequest().get()).isEqualTo(clientFlowRequest);
assertThat(batcher.releasePendingRequest().isPresent()).isFalse();
assertThat(batcher.releasePendingRequest()).isEmpty();
assertThat(batcher.requestForRestart().get()).isEqualTo(clientFlowRequest);
assertThat(batcher.requestForRestart().get()).isEqualTo(clientFlowRequest);
}
Expand All @@ -65,9 +66,10 @@ public void onMessagesDecrementsClientTokens() throws StatusException {

@Test
public void shouldExpediteBatchRequestChecksByteRatio() throws StatusException {
batcher.onClientFlowRequest(
FlowControlRequest.newBuilder().setAllowedBytes(100).setAllowedMessages(100).build());
batcher.releasePendingRequest();
FlowControlRequest request =
FlowControlRequest.newBuilder().setAllowedBytes(100).setAllowedMessages(100).build();
batcher.onClientFlowRequest(request);
assertThat(batcher.releasePendingRequest()).hasValue(request);

batcher.onClientFlowRequest(FlowControlRequest.newBuilder().setAllowedBytes(10).build());
assertThat(batcher.shouldExpediteBatchRequest()).isFalse();
Expand All @@ -78,9 +80,10 @@ public void shouldExpediteBatchRequestChecksByteRatio() throws StatusException {

@Test
public void shouldExpediteBatchRequestChecksMessageRatio() throws StatusException {
batcher.onClientFlowRequest(
FlowControlRequest.newBuilder().setAllowedBytes(100).setAllowedMessages(100).build());
batcher.releasePendingRequest();
FlowControlRequest request =
FlowControlRequest.newBuilder().setAllowedBytes(100).setAllowedMessages(100).build();
batcher.onClientFlowRequest(request);
assertThat(batcher.releasePendingRequest()).hasValue(request);

batcher.onClientFlowRequest(FlowControlRequest.newBuilder().setAllowedMessages(80).build());
assertThat(batcher.shouldExpediteBatchRequest()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.cloud.pubsublite.internal.StatusExceptionMatcher.assertFutureThrowsCode;
import static com.google.common.truth.Truth.assertThat;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -60,7 +61,6 @@
import io.grpc.stub.StreamObserver;
import io.grpc.testing.GrpcCleanupRule;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -182,7 +182,7 @@ public void batchesFlowControlRequests() throws Exception {
subscriber.allowFlow(deltaFlowRequest);
verifyZeroInteractions(mockConnectedSubscriber);

allowFlowLatch.await(SubscriberImpl.FLOW_REQUESTS_FLUSH_INTERVAL_MS * 4, TimeUnit.MILLISECONDS);
allowFlowLatch.await(SubscriberImpl.FLOW_REQUESTS_FLUSH_INTERVAL_MS * 4, MILLISECONDS);
FlowControlRequest expectedBatchFlowRequest =
FlowControlRequest.newBuilder().setAllowedBytes(200).setAllowedMessages(20).build();
verify(mockConnectedSubscriber).allowFlow(expectedBatchFlowRequest);
Expand Down

0 comments on commit 403efb6

Please sign in to comment.