Search in sources :

Example 1 with Interceptor

use of org.apache.flume.interceptor.Interceptor in project apex-malhar by apache.

the class ColumnFilteringFormattingInterceptorTest method testInterceptEventWithPrefix.

@Test
public void testInterceptEventWithPrefix() {
    HashMap<String, String> contextMap = new HashMap<String, String>();
    contextMap.put(ColumnFilteringInterceptor.Constants.SRC_SEPARATOR, Byte.toString((byte) 2));
    contextMap.put(ColumnFilteringFormattingInterceptor.Constants.COLUMNS_FORMATTER, "\001{1}\001{2}\001{3}\001");
    ColumnFilteringFormattingInterceptor.Builder builder = new ColumnFilteringFormattingInterceptor.Builder();
    builder.configure(new Context(contextMap));
    Interceptor interceptor = builder.build();
    assertArrayEquals("Six Fields", "\001\001Second\001\001".getBytes(), interceptor.intercept(new InterceptorTestHelper.MyEvent("First\002\002Second\002\002\002".getBytes())).getBody());
}
Also used : Context(org.apache.flume.Context) HashMap(java.util.HashMap) Interceptor(org.apache.flume.interceptor.Interceptor) Test(org.junit.Test)

Example 2 with Interceptor

use of org.apache.flume.interceptor.Interceptor in project apex-malhar by apache.

the class ColumnFilteringInterceptorTest method testInterceptEventWithColumnZero.

@Test
public void testInterceptEventWithColumnZero() {
    HashMap<String, String> contextMap = new HashMap<String, String>();
    contextMap.put(ColumnFilteringInterceptor.Constants.DST_SEPARATOR, Byte.toString((byte) 1));
    contextMap.put(ColumnFilteringInterceptor.Constants.SRC_SEPARATOR, Byte.toString((byte) 2));
    contextMap.put(ColumnFilteringInterceptor.Constants.COLUMNS, "0");
    ColumnFilteringInterceptor.Builder builder = new ColumnFilteringInterceptor.Builder();
    builder.configure(new Context(contextMap));
    Interceptor interceptor = builder.build();
    assertArrayEquals("Empty Bytes", "\001".getBytes(), interceptor.intercept(new InterceptorTestHelper.MyEvent("".getBytes())).getBody());
    assertArrayEquals("One Field", "First\001".getBytes(), interceptor.intercept(new InterceptorTestHelper.MyEvent("First".getBytes())).getBody());
    assertArrayEquals("Two Fields", "\001".getBytes(), interceptor.intercept(new InterceptorTestHelper.MyEvent("\002First".getBytes())).getBody());
}
Also used : Context(org.apache.flume.Context) HashMap(java.util.HashMap) Interceptor(org.apache.flume.interceptor.Interceptor) Test(org.junit.Test)

Example 3 with Interceptor

use of org.apache.flume.interceptor.Interceptor in project apex-malhar by apache.

the class ColumnFilteringFormattingInterceptorTest method testInterceptEventWithColumnZero.

@Test
public void testInterceptEventWithColumnZero() {
    HashMap<String, String> contextMap = new HashMap<String, String>();
    contextMap.put(ColumnFilteringInterceptor.Constants.SRC_SEPARATOR, Byte.toString((byte) 2));
    contextMap.put(ColumnFilteringFormattingInterceptor.Constants.COLUMNS_FORMATTER, "{0}\001");
    ColumnFilteringFormattingInterceptor.Builder builder = new ColumnFilteringFormattingInterceptor.Builder();
    builder.configure(new Context(contextMap));
    Interceptor interceptor = builder.build();
    assertArrayEquals("Empty Bytes", "\001".getBytes(), interceptor.intercept(new InterceptorTestHelper.MyEvent("".getBytes())).getBody());
    assertArrayEquals("One Field", "First\001".getBytes(), interceptor.intercept(new InterceptorTestHelper.MyEvent("First".getBytes())).getBody());
    assertArrayEquals("Two Fields", "\001".getBytes(), interceptor.intercept(new InterceptorTestHelper.MyEvent("\002First".getBytes())).getBody());
}
Also used : Context(org.apache.flume.Context) HashMap(java.util.HashMap) Interceptor(org.apache.flume.interceptor.Interceptor) Test(org.junit.Test)

Example 4 with Interceptor

use of org.apache.flume.interceptor.Interceptor in project apex-malhar by apache.

the class ColumnFilteringFormattingInterceptorTest method testInterceptEventWithTerminatingSeparator.

@Test
public void testInterceptEventWithTerminatingSeparator() {
    HashMap<String, String> contextMap = new HashMap<String, String>();
    contextMap.put(ColumnFilteringInterceptor.Constants.SRC_SEPARATOR, Byte.toString((byte) 2));
    contextMap.put(ColumnFilteringFormattingInterceptor.Constants.COLUMNS_FORMATTER, "a{1}bc{2}def{3}");
    ColumnFilteringFormattingInterceptor.Builder builder = new ColumnFilteringFormattingInterceptor.Builder();
    builder.configure(new Context(contextMap));
    Interceptor interceptor = builder.build();
    byte[] body = interceptor.intercept(new InterceptorTestHelper.MyEvent("First\002\002Second\002\002\002".getBytes())).getBody();
    assertArrayEquals("Six Fields, " + new String(body), "abcSeconddef".getBytes(), body);
}
Also used : Context(org.apache.flume.Context) HashMap(java.util.HashMap) Interceptor(org.apache.flume.interceptor.Interceptor) Test(org.junit.Test)

Example 5 with Interceptor

use of org.apache.flume.interceptor.Interceptor in project apex-malhar by apache.

the class ColumnFilteringFormattingInterceptorTest method testInterceptEventWithLongSeparator.

@Test
public void testInterceptEventWithLongSeparator() {
    HashMap<String, String> contextMap = new HashMap<String, String>();
    contextMap.put(ColumnFilteringInterceptor.Constants.SRC_SEPARATOR, Byte.toString((byte) 2));
    contextMap.put(ColumnFilteringFormattingInterceptor.Constants.COLUMNS_FORMATTER, "a{1}bc{2}def{3}ghi");
    ColumnFilteringFormattingInterceptor.Builder builder = new ColumnFilteringFormattingInterceptor.Builder();
    builder.configure(new Context(contextMap));
    Interceptor interceptor = builder.build();
    byte[] body = interceptor.intercept(new InterceptorTestHelper.MyEvent("First\002\002Second\002\002\002".getBytes())).getBody();
    assertArrayEquals("Six Fields, " + new String(body), "abcSeconddefghi".getBytes(), body);
}
Also used : Context(org.apache.flume.Context) HashMap(java.util.HashMap) Interceptor(org.apache.flume.interceptor.Interceptor) Test(org.junit.Test)

Aggregations

Context (org.apache.flume.Context)7 Interceptor (org.apache.flume.interceptor.Interceptor)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)5 File (java.io.File)1 URL (java.net.URL)1 Properties (java.util.Properties)1