org.apache.flume.serialization.EventDeserializer Java Examples

The following examples show how to use org.apache.flume.serialization.EventDeserializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 6 votes vote down vote up
private void validateReset(EventDeserializer des) throws IOException {
    Event evt = des.readEvent();
    assertEquals("Everyday Italian", new String(evt.getBody()));
    des.mark();

    List<Event> events = des.readEvents(3);
    assertEquals(3, events.size());
    assertEquals("Harry Potter", new String(events.get(0).getBody()));
    assertEquals("XQuery Kick Start", new String(events.get(1).getBody()));
    assertEquals("Learning XML", new String(events.get(2).getBody()));

    des.reset(); // reset!

    events = des.readEvents(3);
    assertEquals(3, events.size());
    assertEquals("Harry Potter", new String(events.get(0).getBody()));
    assertEquals("XQuery Kick Start", new String(events.get(1).getBody()));
    assertEquals("Learning XML", new String(events.get(2).getBody()));

    evt = des.readEvent();
    Assert.assertNull("Event should be null because there are no more books " + "left to read", evt);

}
 
Example #2
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 6 votes vote down vote up
private void validateReadAndMarkWithHeader(EventDeserializer des) throws IOException {
    Event evt;

    evt = des.readEvent();
    System.out.println(evt.getHeaders().get("myHeader"));
    assertTrue(evt.getHeaders().get("myHeader").contains("Giada De Laurentiis"));
    des.mark();

    evt = des.readEvent();
    assertTrue(evt.getHeaders().get("myHeader").contains("J K. Rowling"));
    des.mark(); // reset!

    List<Event> readEvents = des.readEvents(2);
    assertEquals(2, readEvents.size());

    evt = des.readEvent();
    assertNull("Event should be null because there are no more books " + "left to read", evt);

    des.mark();
    des.mark();
    des.close();
}
 
Example #3
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 6 votes vote down vote up
private void validateReadAndMark(EventDeserializer des) throws IOException {
    Event evt;

    evt = des.readEvent();
    assertTrue(new String(evt.getBody()).contains("Giada De Laurentiis"));
    des.mark();

    evt = des.readEvent();
    assertTrue(new String(evt.getBody()).contains("J K. Rowling"));
    des.mark(); // reset!

    List<Event> readEvents = des.readEvents(2);
    assertEquals(2, readEvents.size());

    evt = des.readEvent();
    assertNull("Event should be null because there are no more books " + "left to read", evt);

    des.mark();
    des.mark();
    des.close();
}
 
Example #4
Source File: TestBlobDeserializer.java    From mt-flume with Apache License 2.0 6 votes vote down vote up
private void validateMiniParse(EventDeserializer des) throws IOException {
  Event evt;

  des.mark();
  evt = des.readEvent();
  assertEquals(new String(evt.getBody()), mini);
  des.reset(); // reset!

  evt = des.readEvent();
  assertEquals("data should be repeated, " +
      "because we reset() the stream", new String(evt.getBody()), mini);

  evt = des.readEvent();
  assertNull("Event should be null because there are no lines " +
      "left to read", evt);

  des.mark();
  des.close();
}
 
Example #5
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadsAndMark() throws IOException {
    Context context = new Context();
    context.put("expression", "/bookstore/book");
    EventDeserializer des = new XmlXpathDeserializer.Builder().build(context, getTestInputStream());
    validateReadAndMark(des);
}
 
Example #6
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 5 votes vote down vote up
private void validateHeaders(EventDeserializer des) throws IOException {
    List<Event> events = des.readEvents(4);
    Assert.assertTrue(events.size() == 4);

    for (Event evt : events) {
        Assert.assertEquals(evt.getHeaders().get("author"), "J K. Rowling");
    }
}
 
Example #7
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 5 votes vote down vote up
@Test()
public void testXPathWithNS() throws IOException {
  Context context = new Context();
  context.put("expression", "/bookstore/book");
  EventDeserializer des = new XmlXpathDeserializer.Builder().build(context, getTestInputStream("ns.xml"));
  List<Event> events = des.readEvents(4);
  assertEquals(4, events.size());
  for (final Event event : events) {
    assertNotNull(event);
  }
}
 
Example #8
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeader() throws IOException {
  Context context = new Context();
  context.put("expression", "/bookstore/book");
  context.put("outputHeader", "myHeader");
  context.put("outputBody", "false");
  EventDeserializer des = new XmlXpathDeserializer.Builder().build(context, getTestInputStream());
  validateReadAndMarkWithHeader(des);
}
 
Example #9
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 5 votes vote down vote up
@Test
public void testReset() throws IOException {
    Context context = new Context();
    context.put("expression", "/bookstore/book/title/text()");
    EventDeserializer des = new XmlXpathDeserializer.Builder().build(context, getTestInputStream());
    validateReset(des);
}
 
Example #10
Source File: TailFileEventReader.java    From flume-plugin with Apache License 2.0 5 votes vote down vote up
public FileReader(File file, EventDeserializer deserializer,
                  ResettableFileInputStream in, DurablePositionTrack tracker,
                  boolean isSingleRotate, FinishMarker finishMarker) {
    this.file = file;
    this.in = in;
    this.isSingleRotate = isSingleRotate;
    this.tracker = tracker;
    this.deserializer = deserializer;
    this.currentFileKey = getFileKey(file);
    this.finishMarker = finishMarker;
}
 
Example #11
Source File: XmlXpathDeserializer.java    From ingestion with Apache License 2.0 5 votes vote down vote up
@Override
public EventDeserializer build(Context context, ResettableInputStream in) {
    if (!(in instanceof Seekable)) {
        throw new IllegalArgumentException(
                "Cannot use this deserializer without a Seekable input stream");
    }
    try {
        return new XmlXpathDeserializer(context, in);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example #12
Source File: TestBlobDeserializer.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Test
public void testMaxLineLength() throws IOException {
  String longLine = "abcdefghijklmnopqrstuvwxyz\n";
  Context ctx = new Context();
  ctx.put(BlobDeserializer.MAX_BLOB_LENGTH_KEY, "10");

  ResettableInputStream in = new ResettableTestStringInputStream(longLine);
  EventDeserializer des = new BlobDeserializer(ctx, in);

  assertEventBodyEquals("abcdefghij", des.readEvent());
  assertEventBodyEquals("klmnopqrst", des.readEvent());
  assertEventBodyEquals("uvwxyz\n", des.readEvent());
  assertNull(des.readEvent());
}
 
Example #13
Source File: TestBlobDeserializer.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Test
public void testBatch() throws IOException {
  ResettableInputStream in = new ResettableTestStringInputStream(mini);
  EventDeserializer des = new BlobDeserializer(new Context(), in);
  List<Event> events;

  events = des.readEvents(10); // try to read more than we should have
  assertEquals(1, events.size());
  assertEventBodyEquals(mini, events.get(0));

  des.mark();
  des.close();
}
 
Example #14
Source File: TestBlobDeserializer.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleViaFactory() throws IOException {
  ResettableInputStream in = new ResettableTestStringInputStream(mini);
  EventDeserializer des;
  des = EventDeserializerFactory.getInstance(BlobDeserializer.Builder.class.getName(), new Context(), in);
  validateMiniParse(des);
}
 
Example #15
Source File: TestBlobDeserializer.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleViaBuilder() throws IOException {
  ResettableInputStream in = new ResettableTestStringInputStream(mini);
  EventDeserializer.Builder builder = new BlobDeserializer.Builder();
  EventDeserializer des = builder.build(new Context(), in);
  validateMiniParse(des);
}
 
Example #16
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testBadXML() throws IOException {
  EventDeserializer des = new XmlXpathDeserializer.Builder().build(new Context(), getTestInputStream("bad.xml"));
}
 
Example #17
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testBadXPath() throws IOException {
  Context context = new Context();
  context.put("expression", "ñ/b\ngnklñ13");
  EventDeserializer des = new XmlXpathDeserializer.Builder().build(context, getTestInputStream());
}
 
Example #18
Source File: XmlXpathDeserializerTest.java    From ingestion with Apache License 2.0 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testNoOutputNoHeader() throws IOException {
  Context context = new Context();
  context.put("outputBody", "false");
  EventDeserializer des = new XmlXpathDeserializer.Builder().build(context, getTestInputStream());
}
 
Example #19
Source File: TestBlobDeserializer.java    From mt-flume with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimple() throws IOException {
  ResettableInputStream in = new ResettableTestStringInputStream(mini);
  EventDeserializer des = new BlobDeserializer(new Context(), in);
  validateMiniParse(des);
}
 
Example #20
Source File: ReliableSpoolDirectoryTailFileEventReader.java    From flume-ng-extends-source with MIT License 4 votes vote down vote up
public FileInfo(File file, EventDeserializer deserializer){
	this.file = file;
	this.length = file.length();
	this.lastModified = file.lastModified();
	this.deserializer = deserializer;
}
 
Example #21
Source File: MultiLineDeserializer.java    From flume-customized with Apache License 2.0 4 votes vote down vote up
@Override
public EventDeserializer build(Context context, ResettableInputStream in) {
    return new MultiLineDeserializer(context, in);
}
 
Example #22
Source File: ReliableSpoolDirectoryTailFileEventReader.java    From flume-ng-extends-source with MIT License votes vote down vote up
public EventDeserializer getDeserializer() { return deserializer; }