use of org.apache.flume.interceptor.Interceptor 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);
}
use of org.apache.flume.interceptor.Interceptor in project apex-malhar by apache.
the class InterceptorTestHelper method testIntercept_Event.
public void testIntercept_Event() {
builder.configure(new Context(context));
Interceptor interceptor = builder.build();
assertArrayEquals("Empty Bytes", "\001\001\001".getBytes(), interceptor.intercept(new MyEvent("".getBytes())).getBody());
assertArrayEquals("One Separator", "\001\001\001".getBytes(), interceptor.intercept(new MyEvent("\002".getBytes())).getBody());
assertArrayEquals("Two Separators", "\001\001\001".getBytes(), interceptor.intercept(new MyEvent("\002\002".getBytes())).getBody());
assertArrayEquals("One Field", "\001\001\001".getBytes(), interceptor.intercept(new MyEvent("First".getBytes())).getBody());
assertArrayEquals("Two Fields", "First\001\001\001".getBytes(), interceptor.intercept(new MyEvent("\002First".getBytes())).getBody());
assertArrayEquals("Two Fields", "\001\001\001".getBytes(), interceptor.intercept(new MyEvent("First\001".getBytes())).getBody());
assertArrayEquals("Two Fields", "Second\001\001\001".getBytes(), interceptor.intercept(new MyEvent("First\002Second".getBytes())).getBody());
assertArrayEquals("Three Fields", "Second\001\001\001".getBytes(), interceptor.intercept(new MyEvent("First\002Second\002".getBytes())).getBody());
assertArrayEquals("Three Fields", "\001Second\001\001".getBytes(), interceptor.intercept(new MyEvent("First\002\002Second".getBytes())).getBody());
assertArrayEquals("Four Fields", "\001Second\001\001".getBytes(), interceptor.intercept(new MyEvent("First\002\002Second\002".getBytes())).getBody());
assertArrayEquals("Five Fields", "\001Second\001\001".getBytes(), interceptor.intercept(new MyEvent("First\002\002Second\002\002".getBytes())).getBody());
assertArrayEquals("Six Fields", "\001Second\001\001".getBytes(), interceptor.intercept(new MyEvent("First\002\002Second\002\002\002".getBytes())).getBody());
}
Aggregations