Skip to content

Commit

Permalink
fix: Fail hard in subscribe() call on assignment failure (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpcollins-google committed Aug 16, 2021
1 parent 33f452c commit 4d15dcc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Expand Up @@ -209,7 +209,7 @@ public void subscribe(
consumer = Optional.of(consumerFactory.newConsumer());
try {
assigner = Optional.of(assignerFactory.New(newAssignmentReceiver(consumerRebalanceListener)));
assigner.get().startAsync();
assigner.get().startAsync().awaitRunning();
} catch (ApiException e) {
throw toKafka(e);
}
Expand Down
Expand Up @@ -42,6 +42,7 @@
import com.google.cloud.pubsublite.internal.CheckedApiException;
import com.google.cloud.pubsublite.internal.CursorClient;
import com.google.cloud.pubsublite.internal.TopicStatsClient;
import com.google.cloud.pubsublite.internal.testing.FakeApiService;
import com.google.cloud.pubsublite.internal.testing.UnitTestExamples;
import com.google.cloud.pubsublite.internal.wire.Assigner;
import com.google.cloud.pubsublite.internal.wire.AssignerFactory;
Expand Down Expand Up @@ -80,6 +81,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.Spy;

@RunWith(JUnit4.class)
public class PubsubLiteConsumerTest {
Expand Down Expand Up @@ -112,7 +114,9 @@ private static <T> T example(Class<T> klass) {
@Mock AdminClient adminClient;
@Mock TopicStatsClient topicStatsClient;

@Mock Assigner assigner;
abstract static class FakeAssigner extends FakeApiService implements Assigner {}

@Spy FakeAssigner assigner;
@Mock SingleSubscriptionConsumer underlying;

Consumer<byte[], byte[]> consumer;
Expand Down Expand Up @@ -305,6 +309,7 @@ public void validSubscribe() throws Exception {
verify(consumerFactory).newConsumer();
verify(assignerFactory).New(any());
verify(assigner).startAsync();
verify(assigner).awaitRunning();
receiver.get().handleAssignment(ImmutableSet.of(Partition.of(5)));
verify(listener)
.onPartitionsAssigned(
Expand Down

0 comments on commit 4d15dcc

Please sign in to comment.