Package com.cloudera.flume.handlers.debug

Examples of com.cloudera.flume.handlers.debug.MemorySinkSource


   */
  @Test
  public void testThriftSend() throws IOException, InterruptedException {
    EventSource txt = new NoNlASCIISynthSource(25, 100);
    txt.open();
    MemorySinkSource mem = new MemorySinkSource();
    mem.open();
    EventUtil.dumpAll(txt, mem);
    txt.close();

    FlumeConfiguration conf = FlumeConfiguration.get();
    // this is a slight tweak to avoid port conflicts
    final int port = conf.getCollectorPort() + 1;
    final ThriftEventSource tes = new ThriftEventSource(port);
    tes.open();

    final CounterSink cnt = new CounterSink("count");
    cnt.open();
    Thread t = new Thread("drain") {
      public void run() {
        try {
          EventUtil.dumpAll(tes, cnt);
        } catch (IOException e) {
        } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    };
    t.start(); // drain the sink.

    // mem -> ThriftEventSink
    ThriftEventSink snk = new ThriftEventSink("0.0.0.0", port);
    snk.open();
    EventUtil.dumpAll(mem, snk);
    mem.close();
    snk.close();

    // a little delay to drain events at ThriftEventSource queue
    try {
      Thread.sleep(1000);
View Full Code Here


            // TODO (jon) this may have different sizes due to the host it is
            // running on . Needs to be fixed.
            EventSource txt = new NoNlASCIISynthSource(25, 100);

            txt.open();
            MemorySinkSource mem = new MemorySinkSource();
            mem.open();
            EventUtil.dumpAll(txt, mem);
            txt.close();

            // mem -> ThriftEventSink
            ThriftEventSink snk = new ThriftEventSink("0.0.0.0", port);
            snk.open();

            sendStarted.countDown();
            sendStarted.await();
            EventUtil.dumpAll(mem, snk);
            mem.close();
            snk.close();

            sendByteSum.addAndGet(snk.getSentBytes());
            LOG.info("sink " + id + " sent " + snk.getSentBytes() + " bytes");
            sendDone.countDown();
View Full Code Here

*/
public class TestExtractors {

  @Test
  public void testRegexExtractor() throws IOException, InterruptedException {
    MemorySinkSource mem = new MemorySinkSource();
    mem.open();
    RegexExtractor re1 = new RegexExtractor(mem, "(\\d:\\d)", 1, "colon");
    RegexExtractor re2 = new RegexExtractor(re1, "(.+)oo(.+)", 1, "oo");
    RegexExtractor re3 = new RegexExtractor(re2, "(.+)oo(.+)", 0, "full");
    RegexExtractor re4 = new RegexExtractor(re3, "(blah)blabh", 3, "empty");
    RegexExtractor re = new RegexExtractor(re4, "(.+)oo(.+)", 3, "outofrange");

    re.open();
    re.append(new EventImpl("1:2:3.4foobar5".getBytes()));
    re.close();

    mem.close();
    mem.open();
    Event e1 = mem.next();
    assertEquals("1:2", Attributes.readString(e1, "colon"));
    assertEquals("1:2:3.4f", Attributes.readString(e1, "oo"));
    assertEquals("1:2:3.4foobar5", Attributes.readString(e1, "full"));
    assertEquals("", Attributes.readString(e1, "empty"));
    assertEquals("", Attributes.readString(e1, "outofrange"));
View Full Code Here

    assertEquals("", Attributes.readString(e1, "outofrange"));
  }

  @Test
  public void testRegexAllExtractor() throws IOException, InterruptedException {
    MemorySinkSource mem = new MemorySinkSource();
    mem.open();
    ArrayList<String> names = new ArrayList<String>();
    names.add("d1");
    names.add(new String(""));
    names.add("d2");

    RegexAllExtractor re = new RegexAllExtractor(mem, "(\\d):(\\d):(\\d)",
        names);

    re.open();
    re.append(new EventImpl("1:2:3.4foobar5".getBytes()));
    re.close();

    mem.close();
    mem.open();
    Event e1 = mem.next();
    assertEquals("1", Attributes.readString(e1, "d1"));
    assertEquals(null, Attributes.readString(e1, ""));
    assertEquals("3", Attributes.readString(e1, "d2"));
  }
View Full Code Here

    assertEquals("3", Attributes.readString(e1, "d2"));
  }

  @Test
  public void testSplitExtractor() throws IOException, InterruptedException {
    MemorySinkSource mem = new MemorySinkSource();
    SplitExtractor re1 = new SplitExtractor(mem, "\\.", 1, "dot");
    SplitExtractor re2 = new SplitExtractor(re1, ":", 1, "colon");
    SplitExtractor re3 = new SplitExtractor(re2, "foobar", 1, "foobar");
    SplitExtractor re4 = new SplitExtractor(re3, "#", 1, "empty");
    SplitExtractor re5 = new SplitExtractor(re4, "foobar", 2, "outofrange");
    SplitExtractor re = new SplitExtractor(re5, "\\.|:|foobar", 3, "disj");

    re.open();
    re.append(new EventImpl("1:2:3.4foobar5".getBytes()));
    re.close();

    mem.close();
    mem.open();
    Event e1 = mem.next();
    assertEquals("4foobar5", Attributes.readString(e1, "dot"));
    assertEquals("2", Attributes.readString(e1, "colon"));
    assertEquals("5", Attributes.readString(e1, "foobar"));
    assertEquals("4", Attributes.readString(e1, "disj"));
    assertEquals("", Attributes.readString(e1, "empty"));
View Full Code Here

   * retry loop.
   */
  void recoverLog(final File dir, final String f) throws IOException,
      InterruptedException {
    LOG.info("Attempting to recover " + dir.getAbsolutePath() + " / " + f);
    MemorySinkSource strippedEvents = new MemorySinkSource();
    AckFramingState state = null;
    try {
      state = checkAndStripAckFraming(dir, f, strippedEvents);
    } catch (IOException e) {
      // try to restore as many as made it through
View Full Code Here

    // date gets when converted back assumes local time zone. This forces it to
    // the time zone expected by this test.
    TimeZone tz = TimeZone.getTimeZone("America/Denver");
    TimeZone.setDefault(tz);

    MemorySinkSource mem = new MemorySinkSource();
    EventImpl e = new EventImpl(
        "Test Event 26/Jul/2010:11:48:05 -0600".getBytes());
    Attributes.setString(e, "date", "26/Jul/2010:11:48:05 -0600");

    // Test Default flow
    DateExtractor d = new DateExtractor(mem, "date", "dd/MMM/yyyy:HH:mm:ss Z");
    // Test custom prefix
    DateExtractor d1 = new DateExtractor(d, "date", "dd/MMM/yyyy:HH:mm:ss Z",
        "test_");
    // Test custom prefix with no zero padding
    DateExtractor d2 = new DateExtractor(d1, "date", "dd/MMM/yyyy:HH:mm:ss Z",
        "test2_", false);

    d2.open();
    d2.append(e);
    d2.close();

    mem.close();
    mem.open();
    Event e1 = mem.next();
    assertEquals("26", Attributes.readString(e1, "dateday"));
    assertEquals("07", Attributes.readString(e1, "datemonth"));
    assertEquals("2010", Attributes.readString(e1, "dateyear"));
    assertEquals("11", Attributes.readString(e1, "datehr"));
    assertEquals("48", Attributes.readString(e1, "datemin"));
View Full Code Here

   */
  @Test
  public void testAvroSend() throws IOException, InterruptedException {
    EventSource txt = new NoNlASCIISynthSource(25, 100);
    txt.open();
    MemorySinkSource mem = new MemorySinkSource();
    mem.open();
    EventUtil.dumpAll(txt, mem);
    txt.close();

    FlumeConfiguration conf = FlumeConfiguration.get();
    // this is a slight tweak to avoid port conflicts
    final int port = conf.getCollectorPort() + 1;
    final AvroEventSource tes = new AvroEventSource(port);
    tes.open();

    final CounterSink cnt = new CounterSink("count");
    cnt.open();
    Thread t = new Thread("drain") {
      public void run() {
        try {
          EventUtil.dumpAll(tes, cnt);
        } catch (Exception e) {
        }
      }
    };
    t.start(); // drain the sink.

    // mem -> AvroEventSink
    AvroEventSink snk = new AvroEventSink("0.0.0.0", port);
    snk.open();
    EventUtil.dumpAll(mem, snk);
    mem.close();
    snk.close();

    // a little delay to drain events at AvroEventSource queue
    try {
      Thread.sleep(1000);
View Full Code Here

      Thread th = new Thread() {
        public void run() {
          try {
            EventSource txt = new NoNlASCIISynthSource(25, 100);
            txt.open();
            MemorySinkSource mem = new MemorySinkSource();
            mem.open();
            EventUtil.dumpAll(txt, mem);
            txt.close();

            // mem -> AvroEventSink
            AvroEventSink snk = new AvroEventSink("0.0.0.0", port);
            snk.open();

            sendStarted.countDown();
            sendStarted.await();
            EventUtil.dumpAll(mem, snk);
            mem.close();
            snk.close();

            sendByteSum.addAndGet(snk.getSentBytes());
            LOG.info("sink " + id + " sent " + snk.getSentBytes() + " bytes");
            sendDone.countDown();
View Full Code Here

  @Test
  public void testAvroDataFileWriteRead() throws IOException,
      FlumeSpecException, InterruptedException {

    MemorySinkSource mem = MemorySinkSource.cannedData("test ", 5);

    // setup sink.
    File f = FileUtil.createTempFile("avrodata", ".avro");
    f.deleteOnExit();
    LOG.info("filename before escaping: " + f.getAbsolutePath());
    String custom = "text(\""
        + StringEscapeUtils.escapeJava(f.getAbsolutePath())
        + "\", \"avrodata\")";
    LOG.info("sink to parse: " + custom);
    EventSink snk = FlumeBuilder.buildSink(new Context(), custom);
    snk.open();
    mem.open();
    EventUtil.dumpAll(mem, snk);
    snk.close();

    mem.open();
    DatumReader<EventImpl> dtm = new ReflectDatumReader<EventImpl>(
        EventImpl.class);
    DataFileReader<EventImpl> dr = new DataFileReader<EventImpl>(f, dtm);

    EventImpl eout = null;
    for (Object o : dr) {
      eout = (EventImpl) o; // TODO (jon) fix AVRO -- this is gross
      Event expected = mem.next();
      Assert.assertTrue(Arrays.equals(eout.getBody(), expected.getBody()));
    }
  }
View Full Code Here

TOP

Related Classes of com.cloudera.flume.handlers.debug.MemorySinkSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.