コード例 #1
0
  @Test
  public void testSendWithNoEndpoint() throws Exception {
    Meta meta = m_metaHolder.getMeta();
    reset(m_metaHolder);
    Topic topic = meta.findTopic(TEST_TOPIC);
    for (Partition p : topic.getPartitions()) {
      p.setEndpoint(null);
    }
    when(m_metaHolder.getMeta()).thenReturn(meta);

    brokerActionsWhenReceivedSendMessageCmd( //
        MessageSendAnswer.NoOp);

    List<Pair<String, String>> appProperties = Arrays.asList(new Pair<String, String>("a", "A"));
    Future<SendResult> future =
        sendAsync(TEST_TOPIC, "pKey", "body", "rKey", appProperties, false, null);

    try {
      future.get(
          lookup(ProducerConfig.class).getBrokerSenderSendTimeoutMillis() + 200L,
          TimeUnit.MILLISECONDS);
      fail();
    } catch (TimeoutException e) {
      // do nothing
    } catch (Exception e) {
      fail();
    }
    assertFalse(future.isDone());

    List<Command> brokerReceivedCmds = getBrokerReceivedCmds();
    assertEquals(0, brokerReceivedCmds.size());
  }
コード例 #2
0
  @Test
  public void testGetEndpointFailed() throws Exception {
    brokerActions4PollMessageCmd(
        PullMessageAnswer.BASIC.channel(m_channel).creator(SIMPLE_CREATOR));
    TestMessageListener listener = new TestMessageListener().receiveCount(1);
    ConsumerHolder holder = Consumer.getInstance().start(TEST_TOPIC, TEST_GROUP, listener);
    long preCost = listener.waitUntilReceivedAllMessage();
    Assert.assertEquals(1, listener.getReceivedMessages().size());
    holder.close();
    listener.countDownAll();

    Meta meta = loadLocalMeta();
    meta.getEndpoints().clear();
    when(m_metaHolder.getMeta()).thenReturn(meta);

    brokerActions4PollMessageCmd(
        PullMessageAnswer.BASIC.channel(m_channel).creator(SIMPLE_CREATOR));
    listener = new TestMessageListener().receiveCount(1);
    holder = Consumer.getInstance().start(TEST_TOPIC, TEST_GROUP, listener);
    listener.waitUntilReceivedAllMessage(preCost * 2);
    Assert.assertEquals(0, listener.getReceivedMessages().size());
    holder.close();
    listener.countDownAll();
  }