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());
}
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());
}
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());
}
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);
}
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);
}
Aggregations