當前位置: 首頁>>代碼示例>>Java>>正文


Java EventBuilder類代碼示例

本文整理匯總了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());
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:TestEmbeddedAgent.java

示例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();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:21,代碼來源:TestRpcClientFactory.java

示例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();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:20,代碼來源:TestRpcClientFactory.java

示例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));
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:19,代碼來源:TestBucketWriter.java

示例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);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:19,代碼來源:TestMorphlineInterceptor.java

示例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();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:31,代碼來源:RpcTestUtils.java

示例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();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:32,代碼來源:TestNettyAvroRpcClient.java

示例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();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:TestNettyAvroRpcClient.java

示例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);
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:17,代碼來源:StressSource.java

示例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);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:TestMorphlineInterceptor.java

示例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;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:ThriftSource.java

示例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);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:25,代碼來源:TestBodyTextEventSerializer.java

示例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();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:19,代碼來源:TestKafkaSink.java

示例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);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:27,代碼來源:TestHBaseSink.java

示例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);
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:20,代碼來源:TestChannelProcessor.java


注:本文中的org.apache.flume.event.EventBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。