use of org.apache.flume.Context 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.Context 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.Context 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.Context 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);
}
use of org.apache.flume.Context in project apex-malhar by apache.
the class InterceptorTestHelper method testFiles.
public void testFiles() throws IOException, URISyntaxException {
Properties properties = new Properties();
properties.load(getClass().getResourceAsStream("/flume/conf/flume-conf.properties"));
String interceptor = null;
for (Entry<Object, Object> entry : properties.entrySet()) {
logger.debug("{} => {}", entry.getKey(), entry.getValue());
if (builder.getClass().getName().equals(entry.getValue().toString())) {
String key = entry.getKey().toString();
if (key.endsWith(".type")) {
interceptor = key.substring(0, key.length() - "type".length());
break;
}
}
}
assertNotNull(builder.getClass().getName(), interceptor);
@SuppressWarnings({ "null", "ConstantConditions" }) final int interceptorLength = interceptor.length();
HashMap<String, String> map = new HashMap<String, String>();
for (Entry<Object, Object> entry : properties.entrySet()) {
String key = entry.getKey().toString();
if (key.startsWith(interceptor)) {
map.put(key.substring(interceptorLength), entry.getValue().toString());
}
}
builder.configure(new Context(map));
Interceptor interceptorInstance = builder.build();
URL url = getClass().getResource("/test_data/gentxns/");
assertNotNull("Generated Transactions", url);
int records = 0;
File dir = new File(url.toURI());
for (File file : dir.listFiles()) {
records += processFile(file, interceptorInstance);
}
Assert.assertEquals("Total Records", 2200, records);
}
Aggregations