本文整理匯總了Java中org.apache.flume.Transaction.commit方法的典型用法代碼示例。如果您正苦於以下問題:Java Transaction.commit方法的具體用法?Java Transaction.commit怎麽用?Java Transaction.commit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.flume.Transaction
的用法示例。
在下文中一共展示了Transaction.commit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testLog4jAppender
import org.apache.flume.Transaction; //導入方法依賴的package包/類
@Test
public void testLog4jAppender() throws IOException {
configureSource();
PropertyConfigurator.configure(props);
Logger logger = LogManager.getLogger(TestLog4jAppender.class);
for (int count = 0; count <= 1000; count++) {
/*
* 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 = ((count % 5) + 1) * 10000;
String msg = "This is log message number" + String.valueOf(count);
logger.log(Level.toLevel(level), msg);
Transaction transaction = ch.getTransaction();
transaction.begin();
Event event = ch.take();
Assert.assertNotNull(event);
Assert.assertEquals(new String(event.getBody(), "UTF8"), msg);
Map<String, String> hdrs = event.getHeaders();
Assert.assertNotNull(hdrs.get(Log4jAvroHeaders.TIMESTAMP.toString()));
Assert.assertEquals(Level.toLevel(level),
Level.toLevel(Integer.valueOf(hdrs.get(Log4jAvroHeaders.LOG_LEVEL
.toString()))
));
Assert.assertEquals(logger.getName(),
hdrs.get(Log4jAvroHeaders.LOGGER_NAME.toString()));
Assert.assertEquals("UTF8",
hdrs.get(Log4jAvroHeaders.MESSAGE_ENCODING.toString()));
transaction.commit();
transaction.close();
}
}
示例2: testCapacityDisableOverflow
import org.apache.flume.Transaction; //導入方法依賴的package包/類
@Test
public void testCapacityDisableOverflow() {
Map<String, String> params = new HashMap<String, String>();
params.put("memoryCapacity", "2");
params.put("overflowCapacity", "0"); // overflow is disabled effectively
params.put("overflowTimeout", "0");
startChannel(params);
transactionalPutN(0, 2, channel);
boolean threw = false;
try {
transactionalPutN(2, 1, channel);
} catch (ChannelException e) {
threw = true;
}
Assert.assertTrue("Expecting ChannelFullException to be thrown", threw);
transactionalTakeN(0, 2, channel);
Transaction tx = channel.getTransaction();
tx.begin();
Assert.assertNull(channel.take());
tx.commit();
tx.close();
}
示例3: testTimeOut
import org.apache.flume.Transaction; //導入方法依賴的package包/類
@Test (expected = EventDeliveryException.class)
public void testTimeOut() throws Exception {
testUtility.createTable(tableName.getBytes(), columnFamily.getBytes());
deleteTable = true;
AsyncHBaseSink sink = new AsyncHBaseSink(testUtility.getConfiguration(), true, false);
Configurables.configure(sink, ctx);
Channel channel = new MemoryChannel();
Configurables.configure(channel, ctx);
sink.setChannel(channel);
channel.start();
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();
Assert.fail();
}
示例4: testRollback6
import org.apache.flume.Transaction; //導入方法依賴的package包/類
@Test
public void testRollback6() throws Exception {
final Transaction transaction = channel.getTransaction();
transaction.begin();
transaction.commit();
testIllegalState(new Runnable() {
@Override
public void run() {
transaction.rollback();
}
});
transaction.close();
testIllegalState(new Runnable() {
@Override
public void run() {
transaction.rollback();
}
});
}
示例5: testHeaders
import org.apache.flume.Transaction; //導入方法依賴的package包/類
@Test
public void testHeaders() throws InterruptedException, IOException {
bind();
Map flumeHeaders = new HashMap<CharSequence, ByteBuffer>();
flumeHeaders.put("hello", ByteBuffer.wrap("world".getBytes("UTF-8")));
ThriftFlumeEvent thriftEvent = new ThriftFlumeEvent(
1, Priority.INFO, ByteBuffer.wrap("foo".getBytes()),
0, "fooHost", flumeHeaders);
FlumeClient fClient = new FlumeClient("0.0.0.0", selectedPort);
fClient.append(thriftEvent);
// check if the event has arrived in the channel through OG thrift source
Transaction transaction = channel.getTransaction();
transaction.begin();
Event event = channel.take();
Assert.assertNotNull(event);
Assert.assertEquals("Event in channel has our header", "world",
event.getHeaders().get("hello"));
transaction.commit();
transaction.close();
stop();
}
示例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: doTestFixInvalidEvents
import org.apache.flume.Transaction; //導入方法依賴的package包/類
public void doTestFixInvalidEvents(boolean withCheckpoint, String eventHandler) throws Exception {
FileChannelIntegrityTool tool = new FileChannelIntegrityTool();
tool.run(new String[] {"-l", dataDir.toString(), "-e", eventHandler, "-DvalidatorValue=0"});
FileChannel channel = new FileChannel();
channel.setName("channel");
if (withCheckpoint) {
File[] cpFiles = origCheckpointDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.contains("lock") || name.contains("queueset")) {
return false;
}
return true;
}
});
for (File cpFile : cpFiles) {
Serialization.copyFile(cpFile, new File(checkpointDir, cpFile.getName()));
}
} else {
FileUtils.deleteDirectory(checkpointDir);
Assert.assertTrue(checkpointDir.mkdirs());
}
ctx.put(FileChannelConfiguration.CHECKPOINT_DIR, checkpointDir.toString());
ctx.put(FileChannelConfiguration.DATA_DIRS, dataDir.toString());
channel.configure(ctx);
channel.start();
Transaction tx = channel.getTransaction();
tx.begin();
int i = 0;
while (channel.take() != null) {
i++;
}
tx.commit();
tx.close();
channel.stop();
Assert.assertTrue(invalidEvent != 0);
Assert.assertEquals(25 - invalidEvent, i);
}
示例8: testMissingTable
import org.apache.flume.Transaction; //導入方法依賴的package包/類
@Test(expected = FlumeException.class)
public void testMissingTable() throws Exception {
deleteTable = false;
ctx.put("batchSize", "2");
AsyncHBaseSink sink = new AsyncHBaseSink(testUtility.getConfiguration());
Configurables.configure(sink, ctx);
//Reset the context to a higher batchSize
ctx.put("batchSize", "100");
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();
sink.process();
Assert.assertFalse(sink.isConfNull());
HTable table = new HTable(testUtility.getConfiguration(), tableName);
byte[][] results = getResults(table, 2);
byte[] out;
int found = 0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
if (Arrays.equals(results[j], Bytes.toBytes(valBase + "-" + i))) {
found++;
break;
}
}
}
Assert.assertEquals(2, found);
out = results[2];
Assert.assertArrayEquals(Longs.toByteArray(2), out);
sink.process();
sink.stop();
}
示例9: 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();
}
}
示例10: 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();
}
示例11: 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;
}
示例12: testPutBasenameHeader
import org.apache.flume.Transaction; //導入方法依賴的package包/類
/**
* Tests if SpoolDirectorySource sets basename headers on events correctly
*/
@Test
public void testPutBasenameHeader() throws IOException, InterruptedException {
Context context = new Context();
File f1 = new File(tmpDir.getAbsolutePath() + "/file1");
Files.write("file1line1\nfile1line2\nfile1line3\nfile1line4\n" +
"file1line5\nfile1line6\nfile1line7\nfile1line8\n",
f1, Charsets.UTF_8);
context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY,
tmpDir.getAbsolutePath());
context.put(SpoolDirectorySourceConfigurationConstants.BASENAME_HEADER,
"true");
context.put(SpoolDirectorySourceConfigurationConstants.BASENAME_HEADER_KEY,
"basenameHeaderKeyTest");
Configurables.configure(source, context);
source.start();
while (source.getSourceCounter().getEventAcceptedCount() < 8) {
Thread.sleep(10);
}
Transaction txn = channel.getTransaction();
txn.begin();
Event e = channel.take();
Assert.assertNotNull("Event must not be null", e);
Assert.assertNotNull("Event headers must not be null", e.getHeaders());
Assert.assertNotNull(e.getHeaders().get("basenameHeaderKeyTest"));
Assert.assertEquals(f1.getName(),
e.getHeaders().get("basenameHeaderKeyTest"));
txn.commit();
txn.close();
}
示例13: mappedWithMariaDB
import org.apache.flume.Transaction; //導入方法依賴的package包/類
@Test
public void mappedWithMariaDB() throws Exception {
Context ctx = new Context();
ctx.put("driver", "org.mariadb.jdbc.Driver");
ctx.put("connectionString", "jdbc:mariadb://106.103.234.62:3306/iotp");
ctx.put("table", "TB_LO_HIST_LOG");
ctx.put("sqlDialect", "MARIADB");
ctx.put("batchSize", "1");
ctx.put("username", "iotp");
ctx.put("password", "iotp");
ctx.put("dbcp.maxWait", "10000");
ctx.put("dbcp.initialSize", "1");
ctx.put("dbcp.maxActive", "3");
ctx.put("dbcp.testOnBorrow", "true");
ctx.put("dbcp.validationQuery", "SELECT 1");
ctx.put("dbcp.testWhileIdle", "true");
ctx.put("dbcp.minEvictableIdleTimeMillis", "55000");
ctx.put("dbcp.timeBetweenEvictionRunsMillis", "34000");
// 주의 : sql 설정 절대 금지!!
JDBCSink jdbcSink = new JDBCSink();
Configurables.configure(jdbcSink, ctx);
Context channelContext = new Context();
channelContext.put("capacity", "10000");
channelContext.put("transactionCapacity", "200");
Channel channel = new MemoryChannel();
channel.setName("junitChannel");
Configurables.configure(channel, channelContext);
jdbcSink.setChannel(channel);
channel.start();
jdbcSink.start();
Transaction tx = channel.getTransaction();
tx.begin();
Map<String, String> headers = new HashMap<String, String>();
Event event = EventBuilder.withBody(body.getBytes(), headers);
channel.put(event);
tx.commit();
tx.close();
jdbcSink.process();
jdbcSink.stop();
channel.stop();
}
示例14: 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());
}
示例15: testSslSinkWithNonTrustedCert
import org.apache.flume.Transaction; //導入方法依賴的package包/類
@Test
public void testSslSinkWithNonTrustedCert() throws Exception {
Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
src = new ThriftTestingSource(ThriftTestingSource.HandlerType.OK.name(), port,
ThriftRpcClient.COMPACT_PROTOCOL, "src/test/resources/keystorefile.jks",
"password", KeyManagerFactory.getDefaultAlgorithm(), "JKS");
Context context = new Context();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("ssl", 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);
channel.start();
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Transaction transaction = channel.getTransaction();
transaction.begin();
for (int i = 0; i < 11; i++) {
channel.put(event);
}
transaction.commit();
transaction.close();
boolean failed = false;
try {
for (int i = 0; i < 6; i++) {
Sink.Status status = sink.process();
failed = true;
}
} catch (EventDeliveryException ex) {
// This is correct
}
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
if (failed) {
Assert.fail("SSL-enabled sink successfully connected to a server with an " +
"untrusted certificate when it should have failed");
}
}