public List<ReceivedMessage> fetchMessages() {
    List<ReceivedMessage> messageList = new ArrayList<>();
    try (SubscriberStub subscriber = pubsubQueueClient.getSubscriber(subscriberStubSettings)) {
      String subscriptionName = ProjectSubscriptionName.format(googleProjectId, pubsubSubscriptionId);
      long startTime = System.currentTimeMillis();
      long unAckedMessages = pubsubQueueClient.getNumUnAckedMessages(this.pubsubSubscriptionId);
      LOG.info("Found unacked messages " + unAckedMessages);
      while (messageList.size() < unAckedMessages && messageList.size() < maxMessagesPerSync
          && ((System.currentTimeMillis() - startTime) < (maxFetchTimePerSyncSecs * 1000))) {
        PullResponse pullResponse = pubsubQueueClient.makePullRequest(subscriber, subscriptionName, batchSize);
        messageList.addAll(pullResponse.getReceivedMessagesList());
      }
      return messageList;
    } catch (Exception e) {
      throw new HoodieException("Error when fetching metadata", e);
    }
  }
@Test
  public void testFetchMessagesZeroTimeout() throws IOException {
    doNothing().when(mockSubscriber).close();
    when(mockPubsubQueueClient.getSubscriber(any())).thenReturn(mockSubscriber);
    when(mockPubsubQueueClient.getNumUnAckedMessages(SUBSCRIPTION_ID)).thenReturn(100L);
    PubsubMessagesFetcher fetcher = new PubsubMessagesFetcher(
        PROJECT_ID, SUBSCRIPTION_ID, SMALL_BATCH_SIZE,
        MAX_MESSAGES_IN_REQUEST, 0, mockPubsubQueueClient
    );

    List<ReceivedMessage> messages = fetcher.fetchMessages();
    assertEquals(0, messages.size());
  }