本文整理汇总了Java中org.apache.flume.Context.put方法的典型用法代码示例。如果您正苦于以下问题:Java Context.put方法的具体用法?Java Context.put怎么用?Java Context.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flume.Context
的用法示例。
在下文中一共展示了Context.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSchemaLiteral
import org.apache.flume.Context; //导入方法依赖的package包/类
@Test
public void testSchemaLiteral() throws IOException {
File tempFile = newTestFile(true);
String target = tempFile.getAbsolutePath();
logger.info("Target: {}", target);
TransientPositionTracker tracker = new TransientPositionTracker(target);
Context context = new Context();
context.put(AvroEventDeserializer.CONFIG_SCHEMA_TYPE_KEY,
AvroEventDeserializer.AvroSchemaType.LITERAL.toString());
ResettableInputStream in =
new ResettableFileInputStream(tempFile, tracker);
EventDeserializer des =
new AvroEventDeserializer.Builder().build(context, in);
Event event = des.readEvent();
String eventSchema =
event.getHeaders().get(AvroEventDeserializer.AVRO_SCHEMA_HEADER_LITERAL);
Assert.assertEquals(schema.toString(), eventSchema);
}
示例2: setUp
import org.apache.flume.Context; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
// 1) prepare hive
TxnDbUtil.cleanDb();
TxnDbUtil.prepDb();
// 1) Setup tables
TestUtil.dropDB(conf, dbName);
String dbLocation = dbFolder.newFolder(dbName).getCanonicalPath() + ".db";
dbLocation = dbLocation.replaceAll("\\\\","/"); // for windows paths
TestUtil.createDbAndTable(driver, dbName, tblName, partVals, colNames, colTypes, partNames,
dbLocation);
// 2) Setup serializer
Context ctx = new Context();
ctx.put("serializer.fieldnames", COL1 + ",," + COL2 + ",");
serializer = new HiveDelimitedTextSerializer();
serializer.configure(ctx);
}
示例3: setUp
import org.apache.flume.Context; //导入方法依赖的package包/类
public void setUp(String compressionType, int compressionLevel) {
if (sink != null) {
throw new RuntimeException("double setup");
}
sink = new AvroSink();
channel = new MemoryChannel();
Context context = new Context();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
if (compressionType.equals("deflate")) {
context.put("compression-type", compressionType);
context.put("compression-level", Integer.toString(compressionLevel));
}
sink.setChannel(channel);
Configurables.configure(sink, context);
Configurables.configure(channel, context);
}
示例4: initContextForSimpleHbaseEventSerializer
import org.apache.flume.Context; //导入方法依赖的package包/类
/**
* Set up {@link Context} for use with {@link SimpleHbaseEventSerializer}.
*/
private void initContextForSimpleHbaseEventSerializer() {
ctx = new Context();
ctx.put("table", tableName);
ctx.put("columnFamily", columnFamily);
ctx.put("serializer", SimpleHbaseEventSerializer.class.getName());
ctx.put("serializer.payloadColumn", plCol);
ctx.put("serializer.incrementColumn", inColumn);
}
示例5: shouldNotAllowConfigurationWithIllegalRegex
import org.apache.flume.Context; //导入方法依赖的package包/类
@Test
public void shouldNotAllowConfigurationWithIllegalRegex() throws Exception {
try {
Context context = new Context();
context.put(RegexExtractorInterceptor.REGEX, "?&?&&&?&?&?&&&??");
fixtureBuilder.configure(context);
fixtureBuilder.build();
Assert.fail();
} catch (IllegalArgumentException ex) {
// Pass...
}
}
示例6: testFLUME1847
import org.apache.flume.Context; //导入方法依赖的package包/类
/**
* Test fails without FLUME-1847
*/
@Test(expected = ConfigurationException.class)
public void testFLUME1847() throws Exception {
Context context = new Context();
context.put("type", "something");
SourceConfiguration sourceConfig = new SourceConfiguration("src");
sourceConfig.configure(context);
}
示例7: testCustomSelector
import org.apache.flume.Context; //导入方法依赖的package包/类
@Test
public void testCustomSelector() throws Exception {
Channel ch = new MockChannel();
int n = 10;
int numEvents = n;
for (int i = 0; i < numEvents; i++) {
ch.put(new MockEvent("test" + i));
}
MockSink s1 = new MockSink(1);
s1.setChannel(ch);
// s1 always fails
s1.setFail(true);
MockSink s2 = new MockSink(2);
s2.setChannel(ch);
MockSink s3 = new MockSink(3);
s3.setChannel(ch);
List<Sink> sinks = new ArrayList<Sink>();
sinks.add(s1);
sinks.add(s2);
sinks.add(s3);
// This selector will result in all events going to s2
Context ctx = getContext(FixedOrderSelector.class.getCanonicalName());
ctx.put("selector." + FixedOrderSelector.SET_ME, "foo");
LoadBalancingSinkProcessor lbsp = getProcessor(sinks, ctx);
Sink.Status s = Sink.Status.READY;
while (s != Sink.Status.BACKOFF) {
s = lbsp.process();
}
Assert.assertTrue(s1.getEvents().size() == 0);
Assert.assertTrue(s2.getEvents().size() == n);
Assert.assertTrue(s3.getEvents().size() == 0);
}
示例8: createAndConfigureMemoryChannel
import org.apache.flume.Context; //导入方法依赖的package包/类
private Channel createAndConfigureMemoryChannel(HBaseSink sink) {
Channel channel = new MemoryChannel();
Context channelCtx = new Context();
channelCtx.put("capacity", String.valueOf(1000L));
channelCtx.put("transactionCapacity", String.valueOf(1000L));
Configurables.configure(channel, channelCtx);
sink.setChannel(channel);
channel.start();
return channel;
}
示例9: testGzipDurabilityWithSerializer
import org.apache.flume.Context; //导入方法依赖的package包/类
@Test
public void testGzipDurabilityWithSerializer() throws Exception {
Context context = new Context();
context.put("serializer", "AVRO_EVENT");
HDFSCompressedDataStream writer = new HDFSCompressedDataStream();
writer.configure(context);
writer.open(fileURI, factory.getCodec(new Path(fileURI)),
SequenceFile.CompressionType.BLOCK);
String[] bodies = { "yarf!", "yarfing!" };
writeBodies(writer, bodies);
int found = 0;
int expected = bodies.length;
List<String> expectedBodies = Lists.newArrayList(bodies);
GZIPInputStream cmpIn = new GZIPInputStream(new FileInputStream(file));
DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
DataFileStream<GenericRecord> avroStream =
new DataFileStream<GenericRecord>(cmpIn, reader);
GenericRecord record = new GenericData.Record(avroStream.getSchema());
while (avroStream.hasNext()) {
avroStream.next(record);
CharsetDecoder decoder = Charsets.UTF_8.newDecoder();
String bodyStr = decoder.decode((ByteBuffer) record.get("body"))
.toString();
expectedBodies.remove(bodyStr);
found++;
}
avroStream.close();
cmpIn.close();
Assert.assertTrue("Found = " + found + ", Expected = " + expected
+ ", Left = " + expectedBodies.size() + " " + expectedBodies,
expectedBodies.size() == 0);
}
示例10: testPreserveExisting
import org.apache.flume.Context; //导入方法依赖的package包/类
@Test
public void testPreserveExisting() throws Exception {
Context context = new Context();
context.put(UUIDInterceptor.HEADER_NAME, ID);
context.put(UUIDInterceptor.PRESERVE_EXISTING_NAME, "true");
Event event = new SimpleEvent();
event.getHeaders().put(ID, "foo");
assertEquals("foo", build(context).intercept(event).getHeaders().get(ID));
}
示例11: shouldReturnMillisFromPattern
import org.apache.flume.Context; //导入方法依赖的package包/类
@Test
public void shouldReturnMillisFromPattern() {
RegexExtractorInterceptorMillisSerializer fixture =
new RegexExtractorInterceptorMillisSerializer();
Context context = new Context();
String pattern = "yyyy-MM-dd HH:mm:ss";
context.put("pattern", pattern);
fixture.configure(context);
DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
long time = (System.currentTimeMillis() / 1000L) * 1000L;
Assert.assertEquals(String.valueOf(time),
fixture.serialize(formatter.print(time)));
}
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:15,代码来源:TestRegexExtractorInterceptorMillisSerializer.java
示例12: testValidSortOrder
import org.apache.flume.Context; //导入方法依赖的package包/类
@Test
public void testValidSortOrder() {
Context context = new Context();
context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY,
tmpDir.getAbsolutePath());
context.put(SpoolDirectorySourceConfigurationConstants.CONSUME_ORDER,
"oLdESt");
Configurables.configure(source, context);
context.put(SpoolDirectorySourceConfigurationConstants.CONSUME_ORDER,
"yoUnGest");
Configurables.configure(source, context);
context.put(SpoolDirectorySourceConfigurationConstants.CONSUME_ORDER,
"rAnDom");
Configurables.configure(source, context);
}
示例13: testPutFilenameHeader
import org.apache.flume.Context; //导入方法依赖的package包/类
@Test
public void testPutFilenameHeader() 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.FILENAME_HEADER,
"true");
context.put(SpoolDirectorySourceConfigurationConstants.FILENAME_HEADER_KEY,
"fileHeaderKeyTest");
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("fileHeaderKeyTest"));
Assert.assertEquals(f1.getAbsolutePath(),
e.getHeaders().get("fileHeaderKeyTest"));
txn.commit();
txn.close();
}
示例14: setUpClass
import org.apache.flume.Context; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
selectedPort = findFreePort();
source = new HTTPSource();
channel = new MemoryChannel();
httpsSource = new HTTPSource();
httpsSource.setName("HTTPS Source");
Context ctx = new Context();
ctx.put("capacity", "100");
Configurables.configure(channel, ctx);
List<Channel> channels = new ArrayList<Channel>(1);
channels.add(channel);
ChannelSelector rcs = new ReplicatingChannelSelector();
rcs.setChannels(channels);
source.setChannelProcessor(new ChannelProcessor(rcs));
channel.start();
httpsSource.setChannelProcessor(new ChannelProcessor(rcs));
// HTTP context
Context context = new Context();
context.put("port", String.valueOf(selectedPort));
context.put("host", "0.0.0.0");
// SSL context props
Context sslContext = new Context();
sslContext.put(HTTPSourceConfigurationConstants.SSL_ENABLED, "true");
sslPort = findFreePort();
sslContext.put(HTTPSourceConfigurationConstants.CONFIG_PORT,
String.valueOf(sslPort));
sslContext.put(HTTPSourceConfigurationConstants.SSL_KEYSTORE_PASSWORD, "password");
sslContext.put(HTTPSourceConfigurationConstants.SSL_KEYSTORE,
"src/test/resources/jettykeystore");
Configurables.configure(source, context);
Configurables.configure(httpsSource, sslContext);
source.start();
httpsSource.start();
}
示例15: test
import org.apache.flume.Context; //导入方法依赖的package包/类
@Test
public void test() throws FileNotFoundException, IOException {
// Snappy currently broken on Mac in OpenJDK 7 per FLUME-2012
Assume.assumeTrue(!"Mac OS X".equals(System.getProperty("os.name")) ||
!System.getProperty("java.version").startsWith("1.7."));
//Schema schema = new Schema.Parser().parse(schemaFile);
// create the file, write some data
OutputStream out = new FileOutputStream(testFile);
String builderName = SyslogAvroEventSerializer.Builder.class.getName();
Context ctx = new Context();
ctx.put("syncInterval", "4096");
ctx.put("compressionCodec", "snappy");
EventSerializer serializer =
EventSerializerFactory.getInstance(builderName, ctx, out);
serializer.afterCreate(); // must call this when a file is newly created
List<Event> events = generateSyslogEvents();
for (Event e : events) {
serializer.write(e);
}
serializer.flush();
serializer.beforeClose();
out.flush();
out.close();
// now try to read the file back
DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
DataFileReader<GenericRecord> fileReader =
new DataFileReader<GenericRecord>(testFile, reader);
GenericRecord record = new GenericData.Record(fileReader.getSchema());
int numEvents = 0;
while (fileReader.hasNext()) {
fileReader.next(record);
int facility = (Integer) record.get("facility");
int severity = (Integer) record.get("severity");
long timestamp = (Long) record.get("timestamp");
String hostname = record.get("hostname").toString();
String message = record.get("message").toString();
Assert.assertEquals("Facility should be 1", 1, facility);
System.out.println(timestamp + ": " + message);
numEvents++;
}
fileReader.close();
Assert.assertEquals("Should have found a total of 3 events", 3, numEvents);
FileUtils.forceDelete(testFile);
}