コード例 #1
0
 protected void fillKafkaToConfig(MJob job) {
   MConfigList toConfig = job.getToJobConfig();
   toConfig.getStringInput("toJobConfig.topic").setValue(topic);
   List<String> topics = new ArrayList<String>(1);
   topics.add(topic);
   testUtil.initTopicList(topics);
 }
コード例 #2
0
  /**
   * Compare strings in content to the messages in Kafka topic
   *
   * @param content
   * @throws UnsupportedEncodingException
   */
  protected void validateContent(String[] content) throws UnsupportedEncodingException {

    Set<String> inputSet = new HashSet<String>(Arrays.asList(content));
    Set<String> outputSet = new HashSet<String>();

    for (String str : content) {
      MessageAndMetadata<byte[], byte[]> fetchedMsg = testUtil.getNextMessageFromConsumer(topic);
      outputSet.add(toText(new String(fetchedMsg.message(), "UTF-8")));
    }

    Assert.assertEquals(inputSet, outputSet);
  }
コード例 #3
0
public class KafkaConnectorTestCase extends ConnectorTestCase {
  private static TestUtil testUtil = TestUtil.getInstance();
  protected String topic;

  @BeforeClass(alwaysRun = true)
  public void startKafka() throws Exception {
    // starts Kafka server and its dependent zookeeper
    testUtil.prepare();
  }

  @AfterClass(alwaysRun = true)
  public void stopKafka() throws IOException {
    testUtil.tearDown();
  }

  protected void fillKafkaLinkConfig(MLink link) {
    MConfigList configs = link.getConnectorLinkConfig();
    configs.getStringInput("linkConfig.brokerList").setValue(testUtil.getKafkaServerUrl());
    configs.getStringInput("linkConfig.zookeeperConnect").setValue(testUtil.getZkUrl());
  }

  protected void fillKafkaToConfig(MJob job) {
    MConfigList toConfig = job.getToJobConfig();
    toConfig.getStringInput("toJobConfig.topic").setValue(topic);
    List<String> topics = new ArrayList<String>(1);
    topics.add(topic);
    testUtil.initTopicList(topics);
  }

  /**
   * Compare strings in content to the messages in Kafka topic
   *
   * @param content
   * @throws UnsupportedEncodingException
   */
  protected void validateContent(String[] content) throws UnsupportedEncodingException {

    Set<String> inputSet = new HashSet<String>(Arrays.asList(content));
    Set<String> outputSet = new HashSet<String>();

    for (String str : content) {
      MessageAndMetadata<byte[], byte[]> fetchedMsg = testUtil.getNextMessageFromConsumer(topic);
      outputSet.add(toText(new String(fetchedMsg.message(), "UTF-8")));
    }

    Assert.assertEquals(inputSet, outputSet);
  }
}
コード例 #4
0
 protected void fillKafkaLinkConfig(MLink link) {
   MConfigList configs = link.getConnectorLinkConfig();
   configs.getStringInput("linkConfig.brokerList").setValue(testUtil.getKafkaServerUrl());
   configs.getStringInput("linkConfig.zookeeperConnect").setValue(testUtil.getZkUrl());
 }
コード例 #5
0
 @AfterClass(alwaysRun = true)
 public void stopKafka() throws IOException {
   testUtil.tearDown();
 }
コード例 #6
0
 @BeforeClass(alwaysRun = true)
 public void startKafka() throws Exception {
   // starts Kafka server and its dependent zookeeper
   testUtil.prepare();
 }