本文整理汇总了Java中org.apache.flume.Transaction.rollback方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.rollback方法的具体用法?Java Transaction.rollback怎么用?Java Transaction.rollback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flume.Transaction
的用法示例。
在下文中一共展示了Transaction.rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPut2
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testPut2() throws Exception {
Transaction transaction = channel.getTransaction();
transaction.begin();
channel.put(events.get(0));
transaction.rollback();
testIllegalState(new Runnable() {
@Override
public void run() {
channel.put(events.get(0));
}
});
transaction.close();
testIllegalState(new Runnable() {
@Override
public void run() {
channel.put(events.get(0));
}
});
}
示例2: testTake2
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testTake2() throws Exception {
Transaction transaction = channel.getTransaction();
transaction.begin();
channel.take();
transaction.rollback();
testIllegalState(new Runnable() {
@Override
public void run() {
channel.take();
}
});
transaction.close();
testIllegalState(new Runnable() {
@Override
public void run() {
channel.take();
}
});
}
示例3: testCapacity
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testCapacity() throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.CAPACITY, String.valueOf(5));
overrides.put(FileChannelConfiguration.TRANSACTION_CAPACITY,
String.valueOf(5));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
fillChannel(channel, "fillup");
// take an event, roll it back, and
// then make sure a put fails
Transaction transaction;
transaction = channel.getTransaction();
transaction.begin();
Event event = channel.take();
Assert.assertNotNull(event);
transaction.rollback();
transaction.close();
// ensure the take the didn't change the state of the capacity
Assert.assertEquals(0, fillChannel(channel, "capacity").size());
// ensure we the events back
Assert.assertEquals(5, takeEvents(channel, 1, 5).size());
}
示例4: testCommit2
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testCommit2() throws Exception {
final Transaction transaction = channel.getTransaction();
transaction.begin();
transaction.rollback();
testIllegalState(new Runnable() {
@Override
public void run() {
transaction.commit();
}
});
transaction.close();
testIllegalState(new Runnable() {
@Override
public void run() {
transaction.commit();
}
});
}
示例5: remaining
import org.apache.flume.Transaction; //导入方法依赖的package包/类
public static int remaining(Channel ch) throws EventDeliveryException {
Transaction t = ch.getTransaction();
try {
t.begin();
int count = 0;
while (ch.take() != null) {
count += 1;
}
t.commit();
return count;
} catch (Throwable th) {
t.rollback();
Throwables.propagateIfInstanceOf(th, Error.class);
Throwables.propagateIfInstanceOf(th, EventDeliveryException.class);
throw new EventDeliveryException(th);
} finally {
t.close();
}
}
示例6: getFlumeEvent
import org.apache.flume.Transaction; //导入方法依赖的package包/类
private byte[] getFlumeEvent() {
Transaction transaction = channel.getTransaction();
transaction.begin();
Event event = channel.take();
Assert.assertNotNull(event);
try {
transaction.commit();
} catch (Throwable t) {
transaction.rollback();
} finally {
transaction.close();
}
logger.debug("Round trip event:{}", event);
return event.getBody();
}
示例7: process
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Override
public Status process() throws EventDeliveryException {
Status result = Status.READY;
Channel channel = getChannel();
Transaction transaction = channel.getTransaction();
Event event = null;
try {
transaction.begin();
event = channel.take();
if (event != null) {
if (logger.isInfoEnabled()) {
logger.info("Event: " + EventHelper.dumpEvent(event, maxBytesToLog));
}
} else {
// No event found, request back-off semantics from the sink runner
result = Status.BACKOFF;
}
transaction.commit();
} catch (Exception ex) {
transaction.rollback();
throw new EventDeliveryException("Failed to log event: " + event, ex);
} finally {
transaction.close();
}
return result;
}
示例8: process
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Override
public Status process() throws EventDeliveryException {
Status status = Status.READY;
Channel channel = getChannel();
Transaction transaction = channel.getTransaction();
Event event = null;
long eventCounter = counterGroup.get("events.success");
try {
transaction.begin();
int i = 0;
for (i = 0; i < batchSize; i++) {
event = channel.take();
if (++eventCounter % logEveryNEvents == 0) {
logger.info("Null sink {} successful processed {} events.", getName(), eventCounter);
}
if (event == null) {
status = Status.BACKOFF;
break;
}
}
transaction.commit();
counterGroup.addAndGet("events.success", (long) Math.min(batchSize, i));
counterGroup.incrementAndGet("transaction.success");
} catch (Exception ex) {
transaction.rollback();
counterGroup.incrementAndGet("transaction.failed");
logger.error("Failed to deliver event. Exception follows.", ex);
throw new EventDeliveryException("Failed to deliver event: " + event, ex);
} finally {
transaction.close();
}
return status;
}
示例9: testPut3
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testPut3() throws Exception {
Transaction transaction = channel.getTransaction();
transaction.begin();
channel.put(events.get(0));
final Transaction finalTransaction = transaction;
testChannelException(new Runnable() {
@Override
public void run() {
finalTransaction.commit();
}
});
transaction.rollback();
testIllegalState(new Runnable() {
@Override
public void run() {
channel.put(events.get(0));
}
});
transaction.close();
testIllegalState(new Runnable() {
@Override
public void run() {
channel.put(events.get(0));
}
});
}
示例10: testRollback1
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testRollback1() throws Exception {
final Transaction transaction = channel.getTransaction();
testIllegalState(new Runnable() {
@Override
public void run() {
transaction.rollback();
}
});
transaction.begin();
testWrongThread(new Runnable() {
@Override
public void run() {
transaction.rollback();
}
});
transaction.rollback();
testIllegalState(new Runnable() {
@Override
public void run() {
transaction.rollback();
}
});
transaction.close();
testIllegalState(new Runnable() {
@Override
public void run() {
transaction.rollback();
}
});
}
示例11: testRollback7
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testRollback7() throws Exception {
final Transaction transaction = channel.getTransaction();
transaction.begin();
testExceptions(new Runnable() {
@Override
public void run() {
transaction.commit();
}
});
transaction.rollback();
testIllegalState(new Runnable() {
@Override
public void run() {
transaction.rollback();
}
});
transaction.close();
testIllegalState(new Runnable() {
@Override
public void run() {
transaction.rollback();
}
});
}
示例12: testByteCapacityBufferEmptyingAfterRollback
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testByteCapacityBufferEmptyingAfterRollback() {
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 tx = channel.getTransaction();
tx.begin();
channel.put(EventBuilder.withBody(eventBody));
channel.put(EventBuilder.withBody(eventBody));
channel.put(EventBuilder.withBody(eventBody));
tx.rollback();
tx.close();
tx = channel.getTransaction();
tx.begin();
channel.put(EventBuilder.withBody(eventBody));
channel.put(EventBuilder.withBody(eventBody));
channel.put(EventBuilder.withBody(eventBody));
tx.commit();
tx.close();
}
示例13: commitAndCloseTransaction
import org.apache.flume.Transaction; //导入方法依赖的package包/类
private void commitAndCloseTransaction(Transaction txn) {
try {
txn.commit();
} catch (Throwable t) {
logger.error("Transaction commit failed, rolling back", t);
txn.rollback();
} finally {
txn.close();
}
}
示例14: testReconfigure
import org.apache.flume.Transaction; //导入方法依赖的package包/类
@Test
public void testReconfigure() throws InterruptedException, IOException {
final int NUM_RECONFIGS = 20;
for (int i = 0; i < NUM_RECONFIGS; i++) {
Context context = new Context();
File file = new File(tmpDir.getAbsolutePath() + "/file-" + i);
Files.write("File " + i, file, Charsets.UTF_8);
context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY,
tmpDir.getAbsolutePath());
Configurables.configure(source, context);
source.start();
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
Transaction txn = channel.getTransaction();
txn.begin();
try {
Event event = channel.take();
String content = new String(event.getBody(), Charsets.UTF_8);
Assert.assertEquals("File " + i, content);
txn.commit();
} catch (Throwable t) {
txn.rollback();
} finally {
txn.close();
}
source.stop();
Assert.assertFalse("Fatal error on iteration " + i, source.hasFatalError());
}
}
示例15: transactionalPutN
import org.apache.flume.Transaction; //导入方法依赖的package包/类
private static void transactionalPutN(int first, int count, AbstractChannel channel) {
Transaction tx = channel.getTransaction();
tx.begin();
try {
putN(first, count, channel);
tx.commit();
} catch (RuntimeException e) {
tx.rollback();
throw e;
} finally {
tx.close();
}
}