本文整理汇总了Java中org.apache.flume.event.EventBuilder类的典型用法代码示例。如果您正苦于以下问题:Java EventBuilder类的具体用法?Java EventBuilder怎么用?Java EventBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventBuilder类属于org.apache.flume.event包,在下文中一共展示了EventBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPutWithInterceptors
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
@Test(timeout = 30000L)
public void testPutWithInterceptors() throws Exception {
properties.put("source.interceptors", "i1");
properties.put("source.interceptors.i1.type", "static");
properties.put("source.interceptors.i1.key", "key2");
properties.put("source.interceptors.i1.value", "value2");
agent.configure(properties);
agent.start();
agent.put(EventBuilder.withBody(body, headers));
Event event;
while ((event = eventCollector.poll()) == null) {
Thread.sleep(500L);
}
Assert.assertNotNull(event);
Assert.assertArrayEquals(body, event.getBody());
Map<String, String> newHeaders = new HashMap<String, String>(headers);
newHeaders.put("key2", "value2");
Assert.assertEquals(newHeaders, event.getHeaders());
}
示例2: testThreeParamBatchAppend
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
@Test
public void testThreeParamBatchAppend() throws FlumeException,
EventDeliveryException {
int batchSize = 7;
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcClientFactory.getDefaultInstance(localhost, server.getPort(),
batchSize);
List<Event> events = new ArrayList<Event>();
for (int i = 0; i < batchSize; i++) {
events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
}
client.appendBatch(events);
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例3: testTwoParamBatchAppendOverflow
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
@Test
public void testTwoParamBatchAppendOverflow() throws FlumeException,
EventDeliveryException {
RpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcClientFactory.getDefaultInstance(localhost, server.getPort());
int batchSize = client.getBatchSize();
int moreThanBatch = batchSize + 1;
List<Event> events = new ArrayList<Event>();
for (int i = 0; i < moreThanBatch; i++) {
events.add(EventBuilder.withBody("evt: " + i, Charset.forName("UTF8")));
}
client.appendBatch(events);
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例4: testInUseSuffix
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
@Test
public void testInUseSuffix() throws IOException, InterruptedException {
final int ROLL_INTERVAL = 1000; // seconds. Make sure it doesn't change in course of test
final String SUFFIX = "WELCOME_TO_THE_HELLMOUNTH";
MockHDFSWriter hdfsWriter = new MockHDFSWriter();
HDFSTextSerializer serializer = new HDFSTextSerializer();
BucketWriter bucketWriter = new BucketWriter(
ROLL_INTERVAL, 0, 0, 0, ctx, "/tmp", "file", "", SUFFIX, null, null,
SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
Executors.newSingleThreadExecutor(), 0, 0);
Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
bucketWriter.append(e);
Assert.assertTrue("Incorrect in use suffix", hdfsWriter.getOpenedFilePath().contains(SUFFIX));
}
示例5: testNoOperation
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
@Test
public void testNoOperation() throws Exception {
Context context = new Context();
context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM,
RESOURCES_DIR + "/test-morphlines/noOperation.conf");
Event input = EventBuilder.withBody("foo", Charsets.UTF_8);
input.getHeaders().put("name", "nadja");
MorphlineInterceptor interceptor = build(context);
Event actual = interceptor.intercept(input);
interceptor.close();
Event expected = EventBuilder.withBody("foo".getBytes("UTF-8"),
ImmutableMap.of("name", "nadja"));
assertEqualsEvent(expected, actual);
List<Event> actualList = build(context).intercept(Collections.singletonList(input));
List<Event> expectedList = Collections.singletonList(expected);
assertEqualsEventList(expectedList, actualList);
}
示例6: handlerSimpleAppendTest
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
/**
* Helper method for testing simple (single) with compression level 6 appends on handlers
* @param handler
* @throws FlumeException
* @throws EventDeliveryException
*/
public static void handlerSimpleAppendTest(AvroSourceProtocol handler,
boolean enableServerCompression,
boolean enableClientCompression, int compressionLevel)
throws FlumeException, EventDeliveryException {
NettyAvroRpcClient client = null;
Server server = startServer(handler, 0, enableServerCompression);
try {
Properties starterProp = new Properties();
if (enableClientCompression) {
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "deflate");
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_LEVEL,
"" + compressionLevel);
} else {
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "none");
}
client = getStockLocalClient(server.getPort(), starterProp);
boolean isActive = client.isActive();
Assert.assertTrue("Client should be active", isActive);
client.append(EventBuilder.withBody("wheee!!!", Charset.forName("UTF8")));
} finally {
stopServer(server);
if (client != null) client.close();
}
}
示例7: testServerDisconnect
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
/**
* First connect the client, then shut down the server, then send a request.
* @throws FlumeException
* @throws EventDeliveryException
* @throws InterruptedException
*/
@Test(expected = EventDeliveryException.class)
public void testServerDisconnect() throws FlumeException,
EventDeliveryException, InterruptedException {
NettyAvroRpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcTestUtils.getStockLocalClient(server.getPort());
server.close();
Thread.sleep(1000L); // wait a second for the close to occur
try {
server.join();
} catch (InterruptedException ex) {
logger.warn("Thread interrupted during join()", ex);
Thread.currentThread().interrupt();
}
try {
client.append(EventBuilder.withBody("hello", Charset.forName("UTF8")));
} finally {
Assert.assertFalse("Client should not be active", client.isActive());
}
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例8: testClientClosedRequest
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
/**
* First connect the client, then close the client, then send a request.
* @throws FlumeException
* @throws EventDeliveryException
*/
@Test(expected = EventDeliveryException.class)
public void testClientClosedRequest() throws FlumeException,
EventDeliveryException {
NettyAvroRpcClient client = null;
Server server = RpcTestUtils.startServer(new OKAvroHandler());
try {
client = RpcTestUtils.getStockLocalClient(server.getPort());
client.close();
Assert.assertFalse("Client should not be active", client.isActive());
System.out.println("Yaya! I am not active after client close!");
client.append(EventBuilder.withBody("hello", Charset.forName("UTF8")));
} finally {
RpcTestUtils.stopServer(server);
if (client != null) client.close();
}
}
示例9: prepEventData
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
private void prepEventData(int bufferSize) {
buffer = new byte[bufferSize];
Arrays.fill(buffer, Byte.MAX_VALUE);
if (batchSize > 1) {
//Create event objects in case of batch test
eventBatchList = new ArrayList<Event>();
for (int i = 0; i < batchSize; i++) {
eventBatchList.add(EventBuilder.withBody(buffer));
}
} else {
//Create single event in case of non-batch test
event = EventBuilder.withBody(buffer);
}
}
示例10: testGrokIfNotMatchDropEventRetain
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
@Test
public void testGrokIfNotMatchDropEventRetain() throws Exception {
Context context = new Context();
context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM,
RESOURCES_DIR + "/test-morphlines/grokIfNotMatchDropRecord.conf");
String msg = "<164>Feb 4 10:46:14 syslog sshd[607]: Server listening on 0.0.0.0 port 22.";
Event input = EventBuilder.withBody(null, ImmutableMap.of(Fields.MESSAGE, msg));
Event actual = build(context).intercept(input);
Map<String, String> expected = new HashMap();
expected.put(Fields.MESSAGE, msg);
expected.put("syslog_pri", "164");
expected.put("syslog_timestamp", "Feb 4 10:46:14");
expected.put("syslog_hostname", "syslog");
expected.put("syslog_program", "sshd");
expected.put("syslog_pid", "607");
expected.put("syslog_message", "Server listening on 0.0.0.0 port 22.");
Event expectedEvent = EventBuilder.withBody(null, expected);
assertEqualsEvent(expectedEvent, actual);
}
示例11: appendBatch
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
@Override
public Status appendBatch(List<ThriftFlumeEvent> events) throws TException {
sourceCounter.incrementAppendBatchReceivedCount();
sourceCounter.addToEventReceivedCount(events.size());
List<Event> flumeEvents = Lists.newArrayList();
for (ThriftFlumeEvent event : events) {
flumeEvents.add(EventBuilder.withBody(event.getBody(), event.getHeaders()));
}
try {
getChannelProcessor().processEventBatch(flumeEvents);
} catch (ChannelException ex) {
logger.warn("Thrift source %s could not append events to the channel.", getName());
return Status.FAILED;
}
sourceCounter.incrementAppendBatchAcceptedCount();
sourceCounter.addToEventAcceptedCount(events.size());
return Status.OK;
}
示例12: testWithNewline
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
@Test
public void testWithNewline() throws FileNotFoundException, IOException {
OutputStream out = new FileOutputStream(testFile);
EventSerializer serializer =
EventSerializerFactory.getInstance("text", new Context(), out);
serializer.afterCreate();
serializer.write(EventBuilder.withBody("event 1", Charsets.UTF_8));
serializer.write(EventBuilder.withBody("event 2", Charsets.UTF_8));
serializer.write(EventBuilder.withBody("event 3", Charsets.UTF_8));
serializer.flush();
serializer.beforeClose();
out.flush();
out.close();
BufferedReader reader = new BufferedReader(new FileReader(testFile));
Assert.assertEquals("event 1", reader.readLine());
Assert.assertEquals("event 2", reader.readLine());
Assert.assertEquals("event 3", reader.readLine());
Assert.assertNull(reader.readLine());
reader.close();
FileUtils.forceDelete(testFile);
}
示例13: prepareAndSend
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
private Sink.Status prepareAndSend(Context context, String msg)
throws EventDeliveryException {
Sink kafkaSink = new KafkaSink();
Configurables.configure(kafkaSink, context);
Channel memoryChannel = new MemoryChannel();
Configurables.configure(memoryChannel, context);
kafkaSink.setChannel(memoryChannel);
kafkaSink.start();
Transaction tx = memoryChannel.getTransaction();
tx.begin();
Event event = EventBuilder.withBody(msg.getBytes());
memoryChannel.put(event);
tx.commit();
tx.close();
return kafkaSink.process();
}
示例14: testOneEvent
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
@Test
public void testOneEvent() throws Exception {
initContextForSimpleHbaseEventSerializer();
HBaseSink sink = new HBaseSink(conf);
Configurables.configure(sink, ctx);
Channel channel = new MemoryChannel();
Configurables.configure(channel, new Context());
sink.setChannel(channel);
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
Event e = EventBuilder.withBody(
Bytes.toBytes(valBase));
channel.put(e);
tx.commit();
tx.close();
sink.process();
sink.stop();
HTable table = new HTable(conf, tableName);
byte[][] results = getResults(table, 1);
byte[] out = results[0];
Assert.assertArrayEquals(e.getBody(), out);
out = results[1];
Assert.assertArrayEquals(Longs.toByteArray(1), out);
}
示例15: testExceptionFromGetTransaction
import org.apache.flume.event.EventBuilder; //导入依赖的package包/类
/**
* Ensure that we bubble up any specific exception thrown from getTransaction
* instead of another exception masking it such as an NPE
*/
@Test(expected = ChannelException.class)
public void testExceptionFromGetTransaction() {
// create a channel which unexpectedly throws a ChEx on getTransaction()
Channel ch = mock(Channel.class);
when(ch.getTransaction()).thenThrow(new ChannelException("doh!"));
ChannelSelector sel = new ReplicatingChannelSelector();
sel.setChannels(Lists.newArrayList(ch));
ChannelProcessor proc = new ChannelProcessor(sel);
List<Event> events = Lists.newArrayList();
events.add(EventBuilder.withBody("event 1", Charsets.UTF_8));
proc.processEventBatch(events);
}