当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.begin方法代码示例

本文整理汇总了Java中org.apache.flume.Transaction.begin方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.begin方法的具体用法?Java Transaction.begin怎么用?Java Transaction.begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.flume.Transaction的用法示例。


在下文中一共展示了Transaction.begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendAndAssertFail

import org.apache.flume.Transaction; //导入方法依赖的package包/类
private void sendAndAssertFail(Logger logger) throws Throwable {
  /*
   * Log4j internally defines levels as multiples of 10000. So if we
   * create levels directly using count, the level will be set as the
   * default.
   */
  int level = 20000;
  try {
    logger.log(Level.toLevel(level), "Test Msg");
  } catch (FlumeException ex) {
    ex.printStackTrace();
    throw ex.getCause();
  }
  Transaction transaction = ch.getTransaction();
  transaction.begin();
  Event event = ch.take();
  Assert.assertNull(event);
  transaction.commit();
  transaction.close();

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:22,代码来源:TestLog4jAppender.java

示例2: testPutFilenameHeader

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testPutFilenameHeader() throws IOException {
  File f1 = new File(tmpDir, "file1");
  Files.write("f1\n", f1, Charsets.UTF_8);

  Context context = new Context();
  context.put(POSITION_FILE, posFilePath);
  context.put(FILE_GROUPS, "fg");
  context.put(FILE_GROUPS_PREFIX + "fg", tmpDir.getAbsolutePath() + "/file.*");
  context.put(FILENAME_HEADER, "true");
  context.put(FILENAME_HEADER_KEY, "path");

  Configurables.configure(source, context);
  source.start();
  source.process();
  Transaction txn = channel.getTransaction();
  txn.begin();
  Event e = channel.take();
  txn.commit();
  txn.close();

  assertNotNull(e.getHeaders().get("path"));
  assertEquals(f1.getAbsolutePath(),
          e.getHeaders().get("path"));
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:26,代码来源:TestTaildirSource.java

示例3: testCommitAfterNoPutTake

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testCommitAfterNoPutTake() throws Exception {
  channel.start();
  Assert.assertTrue(channel.isOpen());
  Transaction transaction;
  transaction = channel.getTransaction();
  transaction.begin();
  transaction.commit();
  transaction.close();

  // ensure we can reopen log with no error
  channel.stop();
  channel = createFileChannel();
  channel.start();
  Assert.assertTrue(channel.isOpen());
  transaction = channel.getTransaction();
  transaction.begin();
  Assert.assertNull(channel.take());
  transaction.commit();
  transaction.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:22,代码来源:TestFileChannel.java

示例4: testPutTake

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testPutTake() throws InterruptedException, EventDeliveryException {
  Event event = EventBuilder.withBody("test event".getBytes());
  Context context = new Context();

  Configurables.configure(channel, context);

  Transaction transaction = channel.getTransaction();
  Assert.assertNotNull(transaction);

  transaction.begin();
  channel.put(event);
  transaction.commit();
  transaction.close();

  transaction = channel.getTransaction();
  Assert.assertNotNull(transaction);

  transaction.begin();
  Event event2 = channel.take();
  Assert.assertEquals(event, event2);
  transaction.commit();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:24,代码来源:TestMemoryChannel.java

示例5: putToChannel

import org.apache.flume.Transaction; //导入方法依赖的package包/类
public static void putToChannel(Channel in, Iterable<Event> records)
    throws EventDeliveryException {
  Transaction t = in.getTransaction();
  try {
    t.begin();
    for (Event record : records) {
      in.put(record);
    }
    t.commit();
  } catch (Throwable th) {
    t.rollback();
    Throwables.propagateIfInstanceOf(th, Error.class);
    Throwables.propagateIfInstanceOf(th, EventDeliveryException.class);
    throw new EventDeliveryException(th);
  } finally {
    t.close();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:19,代码来源:TestDatasetSink.java

示例6: testThreeEvents

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testThreeEvents() throws Exception {
  testUtility.createTable(tableName.getBytes(), columnFamily.getBytes());
  deleteTable = true;
  AsyncHBaseSink sink = new AsyncHBaseSink(testUtility.getConfiguration());
  Configurables.configure(sink, ctx);
  Channel channel = new MemoryChannel();
  Configurables.configure(channel, ctx);
  sink.setChannel(channel);
  sink.start();
  Transaction tx = channel.getTransaction();
  tx.begin();
  for (int i = 0; i < 3; i++) {
    Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
    channel.put(e);
  }
  tx.commit();
  tx.close();
  Assert.assertFalse(sink.isConfNull());
  sink.process();
  sink.stop();
  HTable table = new HTable(testUtility.getConfiguration(), tableName);
  byte[][] results = getResults(table, 3);
  byte[] out;
  int found = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (Arrays.equals(results[j], Bytes.toBytes(valBase + "-" + i))) {
        found++;
        break;
      }
    }
  }
  Assert.assertEquals(3, found);
  out = results[3];
  Assert.assertArrayEquals(Longs.toByteArray(3), out);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:38,代码来源:TestAsyncHBaseSink.java

示例7: testThreeEvents

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testThreeEvents() throws Exception {
  initContextForSimpleHbaseEventSerializer();
  ctx.put("batchSize", "3");
  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();
  for (int i = 0; i < 3; i++) {
    Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
    channel.put(e);
  }
  tx.commit();
  tx.close();
  sink.process();
  sink.stop();
  HTable table = new HTable(conf, tableName);
  byte[][] results = getResults(table, 3);
  byte[] out;
  int found = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (Arrays.equals(results[j], Bytes.toBytes(valBase + "-" + i))) {
        found++;
        break;
      }
    }
  }
  Assert.assertEquals(3, found);
  out = results[3];
  Assert.assertArrayEquals(Longs.toByteArray(3), out);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:37,代码来源:TestHBaseSink.java

示例8: putEvents

import org.apache.flume.Transaction; //导入方法依赖的package包/类
public static Set<String> putEvents(Channel channel, String prefix, int batchSize, int numEvents,
                                    boolean untilCapacityIsReached) throws Exception {
  Set<String> result = Sets.newHashSet();
  for (int i = 0; i < numEvents; i += batchSize) {
    Transaction transaction = channel.getTransaction();
    transaction.begin();
    try {
      Set<String> batch = Sets.newHashSet();
      for (int j = 0; j < batchSize; j++) {
        String s = prefix + "-" + i + "-" + j + "-" + UUID.randomUUID();
        Event event = EventBuilder.withBody(s.getBytes(Charsets.UTF_8));
        channel.put(event);
        batch.add(s);
      }
      transaction.commit();
      result.addAll(batch);
    } catch (Exception ex) {
      transaction.rollback();
      if (untilCapacityIsReached && ex instanceof ChannelException &&
          ("The channel has reached it's capacity. "
              + "This might be the result of a sink on the channel having too "
              + "low of batch size, a downstream system running slower than "
              + "normal, or that the channel capacity is just too low. "
              + "[channel=" + channel.getName() + "]").equals(ex.getMessage())) {
        break;
      }
      throw ex;
    } finally {
      transaction.close();
    }
  }
  return result;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:34,代码来源:TestUtils.java

示例9: testByteCapacityOverload

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test(expected = ChannelException.class)
public void testByteCapacityOverload() {
  Context context = new Context();
  Map<String, String> parms = new HashMap<String, String>();
  parms.put("byteCapacity", "2000");
  parms.put("byteCapacityBufferPercentage", "20");
  context.putAll(parms);
  Configurables.configure(channel,  context);

  byte[] eventBody = new byte[405];

  Transaction transaction = channel.getTransaction();
  transaction.begin();
  channel.put(EventBuilder.withBody(eventBody));
  channel.put(EventBuilder.withBody(eventBody));
  channel.put(EventBuilder.withBody(eventBody));
  transaction.commit();
  transaction.close();

  transaction = channel.getTransaction();
  transaction.begin();
  channel.put(EventBuilder.withBody(eventBody));
  channel.put(EventBuilder.withBody(eventBody));
  // this should kill  it
  transaction.commit();
  Assert.fail();

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:29,代码来源:TestMemoryChannel.java

示例10: takeEvent

import org.apache.flume.Transaction; //导入方法依赖的package包/类
private static Event takeEvent(Channel channel) {
  Transaction txn = channel.getTransaction();
  txn.begin();
  Event evt = channel.take();
  txn.commit();
  txn.close();
  return evt;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:9,代码来源:TestMultiportSyslogTCPSource.java

示例11: takeWithoutCommit

import org.apache.flume.Transaction; //导入方法依赖的package包/类
public static Set<String> takeWithoutCommit(Channel channel, Transaction tx,
        int number) {
  Set<String> events = Sets.newHashSet();
  tx.begin();
  for (int i = 0; i < number; i++) {
    Event e = channel.take();
    if (e == null) {
      break;
    }
    events.add(new String(e.getBody()));
  }
  return events;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:14,代码来源:TestUtils.java

示例12: process

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Override
public Status process() throws EventDeliveryException {
  Status status = Status.READY;
  Channel channel = getChannel();
  Transaction transaction = channel.getTransaction();

  if (resetConnectionFlag.get()) {
    resetConnection();
    // if the time to reset is long and the timeout is short
    // this may cancel the next reset request
    // this should however not be an issue
    resetConnectionFlag.set(false);
  }

  try {
    transaction.begin();

    verifyConnection();

    List<Event> batch = Lists.newLinkedList();

    for (int i = 0; i < client.getBatchSize(); i++) {
      Event event = channel.take();

      if (event == null) {
        break;
      }

      batch.add(event);
    }

    int size = batch.size();
    int batchSize = client.getBatchSize();

    if (size == 0) {
      sinkCounter.incrementBatchEmptyCount();
      status = Status.BACKOFF;
    } else {
      if (size < batchSize) {
        sinkCounter.incrementBatchUnderflowCount();
      } else {
        sinkCounter.incrementBatchCompleteCount();
      }
      sinkCounter.addToEventDrainAttemptCount(size);
      client.appendBatch(batch);
    }

    transaction.commit();
    sinkCounter.addToEventDrainSuccessCount(size);

  } catch (Throwable t) {
    transaction.rollback();
    if (t instanceof Error) {
      throw (Error) t;
    } else if (t instanceof ChannelException) {
      logger.error("Rpc Sink " + getName() + ": Unable to get event from" +
          " channel " + channel.getName() + ". Exception follows.", t);
      status = Status.BACKOFF;
    } else {
      destroyConnection();
      throw new EventDeliveryException("Failed to send events", t);
    }
  } finally {
    transaction.close();
  }

  return status;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:69,代码来源:AbstractRpcSink.java

示例13: testSslSinkWithNonSslServer

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testSslSinkWithNonSslServer() throws InterruptedException,
    EventDeliveryException, InstantiationException, IllegalAccessException {
  setUp();
  Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
  Server server = createServer(new MockAvroServer());

  server.start();

  Context context = new Context();

  context.put("hostname", hostname);
  context.put("port", String.valueOf(port));
  context.put("ssl", String.valueOf(true));
  context.put("trust-all-certs", String.valueOf(true));
  context.put("batch-size", String.valueOf(2));
  context.put("connect-timeout", String.valueOf(2000L));
  context.put("request-timeout", String.valueOf(3000L));

  Configurables.configure(sink, context);

  sink.start();
  Assert.assertTrue(LifecycleController.waitForOneOf(sink,
      LifecycleState.START_OR_ERROR, 5000));

  Transaction transaction = channel.getTransaction();

  transaction.begin();
  for (int i = 0; i < 10; i++) {
    channel.put(event);
  }
  transaction.commit();
  transaction.close();

  boolean failed = false;
  try {
    for (int i = 0; i < 5; i++) {
      sink.process();
      failed = true;
    }
  } catch (EventDeliveryException ex) {
    logger.info("Correctly failed to send event", ex);
  }


  sink.stop();
  Assert.assertTrue(LifecycleController.waitForOneOf(sink,
      LifecycleState.STOP_OR_ERROR, 5000));

  server.close();

  if (failed) {
    Assert.fail("SSL-enabled sink successfully connected to a non-SSL-enabled server, that's wrong.");
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:56,代码来源:TestAvroSink.java

示例14: testMultipleClients

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testMultipleClients() throws Exception {
  ExecutorService submitter = Executors.newCachedThreadPool();
  client = RpcClientFactory.getThriftInstance(props);
  Context context = new Context();
  context.put("capacity", "1000");
  context.put("transactionCapacity", "1000");
  channel.configure(context);
  configureSource();
  context.put(ThriftSource.CONFIG_BIND, "0.0.0.0");
  context.put(ThriftSource.CONFIG_PORT, String.valueOf(port));
  Configurables.configure(source, context);
  source.start();
  ExecutorCompletionService<Void> completionService = new ExecutorCompletionService(submitter);
  for (int i = 0; i < 30; i++) {
    completionService.submit(new SubmitHelper(i), null);
  }
  //wait for all threads to be done


  for (int i = 0; i < 30; i++) {
    completionService.take();
  }

  Transaction transaction = channel.getTransaction();
  transaction.begin();
  long after = System.currentTimeMillis();
  List<Integer> events = Lists.newArrayList();
  for (int i = 0; i < 300; i++) {
    Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertTrue(Long.valueOf(event.getHeaders().get("time")) < after);
    events.add(Integer.parseInt(new String(event.getBody())));
  }
  transaction.commit();
  transaction.close();

  Collections.sort(events);

  int index = 0;
  //30 batches of 10
  for (int i = 0; i < 30; i++) {
    for (int j = 0; j < 10; j++) {
      Assert.assertEquals(i, events.get(index++).intValue());
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:48,代码来源:TestThriftSource.java

示例15: testGetTransaction

import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testGetTransaction() throws Exception {
  final Transaction transaction = channel.getTransaction();

  executor.submit(new Runnable() {
      @Override
      public void run() {
        Assert.assertNotSame(transaction, channel.getTransaction());
      }
    }).get();

  Assert.assertSame(transaction, channel.getTransaction());

  transaction.begin();

  executor.submit(new Runnable() {
      @Override
      public void run() {
        Assert.assertNotSame(transaction, channel.getTransaction());
      }
    }).get();
  Assert.assertSame(transaction, channel.getTransaction());

  transaction.commit();

  executor.submit(new Runnable() {
      @Override
      public void run() {
        Assert.assertNotSame(transaction, channel.getTransaction());
      }
    }).get();
  Assert.assertSame(transaction, channel.getTransaction());

  transaction.close();

  executor.submit(new Runnable() {
      @Override
      public void run() {
        Assert.assertNotSame(transaction, channel.getTransaction());
      }
    }).get();
  Assert.assertNotSame(transaction, channel.getTransaction());
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:44,代码来源:TestBasicChannelSemantics.java


注:本文中的org.apache.flume.Transaction.begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。