package com.cloudera.flume.conf;
import static org.junit.Assert.assertEquals;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import org.junit.Test;
@Test
public void testHex()
throws RecognitionException, FlumeSpecException {
String hex = "0x1234";
CommonTree thex = FlumeBuilder.parseLiteral(hex);
String outHex = FlumeSpecGen.genArg(thex);
assertEquals(hex, outHex);
}
@Test
public void testDec()
throws RecognitionException, FlumeSpecException {
String orig = "12234";
CommonTree tree = FlumeBuilder.parseLiteral(orig);
String out = FlumeSpecGen.genArg(tree);
assertEquals(orig, out);
}
@Test
public void testString()
throws RecognitionException, FlumeSpecException {
String orig = "\"This is a a string\"";
CommonTree tree = FlumeBuilder.parseLiteral(orig);
String out = FlumeSpecGen.genArg(tree);
assertEquals(orig, out);
}
@Test
public void testSource()
throws RecognitionException, FlumeSpecException {
String orig = "twitter";
CommonTree tree = FlumeBuilder.parseSource(orig);
String out = FlumeSpecGen.genEventSource(tree);
assertEquals(orig, out);
orig = "text( \"/tmp/file\" )";
tree = FlumeBuilder.parseSource(orig);
out = FlumeSpecGen.genEventSource(tree);
assertEquals(orig, out);
}
@Test
public void testSink()
throws RecognitionException, FlumeSpecException {
String orig = "null";
CommonTree tree = FlumeBuilder.parseSink(orig);
String out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
orig = "tsink( 1234 )";
tree = FlumeBuilder.parseSink(orig);
out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
orig = "text( \"/tmp/file\" )";
tree = FlumeBuilder.parseSink(orig);
out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
}
@Test
FlumeSpecException {
String orig = "{ flakey( .90 ) => null }";
CommonTree tree = FlumeBuilder.parseSink(orig);
String out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
orig = "{ intervalSampler( 20 ) => tsink( 1234 ) }";
tree = FlumeBuilder.parseSink(orig);
out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
orig = "{ stubbornAppend => { flakey( .90 ) => text( \"/tmp/file\" ) } }";
tree = FlumeBuilder.parseSink(orig);
out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
}
@Test
public void testMulti()
throws RecognitionException, FlumeSpecException {
String orig = "[ counter( \"foo\" ), counter( \"bar\" ), counter( \"baz\" ) ]";
CommonTree tree = FlumeBuilder.parseSink(orig);
String out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
}
@Test
public void testLet()
throws RecognitionException, FlumeSpecException {
String orig = "let foo := counter( \"foo\" ) in foo";
CommonTree tree = FlumeBuilder.parseSink(orig);
String out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
}
@Test
public void testBackup()
throws RecognitionException, FlumeSpecException {
String orig = "< counter( \"foo\" ) ? counter( \"bar\" ) >";
CommonTree tree = FlumeBuilder.parseSink(orig);
String out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
}
@Test
public void testRoll()
throws RecognitionException, FlumeSpecException {
String orig = "roll( 12345 ) { counter( \"foo\" ) }";
CommonTree tree = FlumeBuilder.parseSink(orig);
String out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
}
@Test
public void testFailchain()
throws RecognitionException, FlumeSpecException {
String orig = "failchain( \"foo\", \"bar\" ) { counter( \"%s\" ) }";
CommonTree tree = FlumeBuilder.parseSink(orig);
String out = FlumeSpecGen.genEventSink(tree);
assertEquals(orig, out);
}
}