You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flume.apache.org by mp...@apache.org on 2016/07/08 22:50:53 UTC
[1/9] flume git commit: FLUME-2941. Integrate checkstyle for test
classes
Repository: flume
Updated Branches:
refs/heads/trunk c8c0f9b84 -> cfbf11568
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSSource.java b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSSource.java
index 5423f8f..cdc09b5 100644
--- a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSSource.java
+++ b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSSource.java
@@ -61,6 +61,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
private InitialContextFactory contextFactory;
private File baseDir;
private File passwordFile;
+
@SuppressWarnings("unchecked")
@Override
void afterSetup() throws Exception {
@@ -79,10 +80,11 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
}).when(channelProcessor).processEventBatch(any(List.class));
consumerFactory = mock(JMSMessageConsumerFactory.class);
consumer = spy(create());
- when(consumerFactory.create(any(InitialContext.class), any(ConnectionFactory.class), anyString(),
- any(JMSDestinationType.class), any(JMSDestinationLocator.class), anyString(), anyInt(), anyLong(),
- any(JMSMessageConverter.class), any(Optional.class),
- any(Optional.class))).thenReturn(consumer);
+ when(consumerFactory.create(any(InitialContext.class), any(ConnectionFactory.class),
+ anyString(), any(JMSDestinationType.class),
+ any(JMSDestinationLocator.class), anyString(), anyInt(), anyLong(),
+ any(JMSMessageConverter.class), any(Optional.class),
+ any(Optional.class))).thenReturn(consumer);
when(initialContext.lookup(anyString())).thenReturn(connectionFactory);
contextFactory = mock(InitialContextFactory.class);
when(contextFactory.create(any(Properties.class))).thenReturn(initialContext);
@@ -97,10 +99,12 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
context.put(JMSSourceConfiguration.PROVIDER_URL, "dummy:1414");
context.put(JMSSourceConfiguration.INITIAL_CONTEXT_FACTORY, "ldap://dummy:389");
}
+
@Override
void afterTearDown() throws Exception {
FileUtils.deleteDirectory(baseDir);
}
+
@Test
public void testStop() throws Exception {
source.configure(context);
@@ -108,38 +112,45 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
source.stop();
verify(consumer).close();
}
+
@Test(expected = IllegalArgumentException.class)
public void testConfigureWithoutInitialContextFactory() throws Exception {
context.put(JMSSourceConfiguration.INITIAL_CONTEXT_FACTORY, "");
source.configure(context);
}
+
@Test(expected = IllegalArgumentException.class)
public void testConfigureWithoutProviderURL() throws Exception {
context.put(JMSSourceConfiguration.PROVIDER_URL, "");
source.configure(context);
}
+
@Test(expected = IllegalArgumentException.class)
public void testConfigureWithoutDestinationName() throws Exception {
context.put(JMSSourceConfiguration.DESTINATION_NAME, "");
source.configure(context);
}
+
@Test(expected = FlumeException.class)
public void testConfigureWithBadDestinationType() throws Exception {
context.put(JMSSourceConfiguration.DESTINATION_TYPE, "DUMMY");
source.configure(context);
}
+
@Test(expected = IllegalArgumentException.class)
public void testConfigureWithEmptyDestinationType() throws Exception {
context.put(JMSSourceConfiguration.DESTINATION_TYPE, "");
source.configure(context);
}
+
@SuppressWarnings("unchecked")
@Test
public void testStartConsumerCreateThrowsException() throws Exception {
- when(consumerFactory.create(any(InitialContext.class), any(ConnectionFactory.class), anyString(),
- any(JMSDestinationType.class), any(JMSDestinationLocator.class), anyString(), anyInt(), anyLong(),
- any(JMSMessageConverter.class), any(Optional.class),
- any(Optional.class))).thenThrow(new RuntimeException());
+ when(consumerFactory.create(any(InitialContext.class), any(ConnectionFactory.class),
+ anyString(), any(JMSDestinationType.class),
+ any(JMSDestinationLocator.class), anyString(), anyInt(), anyLong(),
+ any(JMSMessageConverter.class), any(Optional.class),
+ any(Optional.class))).thenThrow(new RuntimeException());
source.configure(context);
source.start();
try {
@@ -149,28 +160,33 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
}
}
+
@Test(expected = FlumeException.class)
public void testConfigureWithContextLookupThrowsException() throws Exception {
when(initialContext.lookup(anyString())).thenThrow(new NamingException());
source.configure(context);
}
+
@Test(expected = FlumeException.class)
public void testConfigureWithContextCreateThrowsException() throws Exception {
when(contextFactory.create(any(Properties.class)))
.thenThrow(new NamingException());
source.configure(context);
}
+
@Test(expected = IllegalArgumentException.class)
public void testConfigureWithInvalidBatchSize() throws Exception {
context.put(JMSSourceConfiguration.BATCH_SIZE, "0");
source.configure(context);
}
+
@Test(expected = FlumeException.class)
public void testConfigureWithInvalidPasswordFile() throws Exception {
context.put(JMSSourceConfiguration.PASSWORD_FILE,
"/dev/does/not/exist/nor/will/ever/exist");
source.configure(context);
}
+
@Test
public void testConfigureWithUserNameButNoPasswordFile() throws Exception {
context.put(JMSSourceConfiguration.USERNAME, "dummy");
@@ -180,6 +196,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
Assert.assertEquals(batchSize, events.size());
assertBodyIsExpected(events);
}
+
@Test
public void testConfigureWithUserNameAndPasswordFile() throws Exception {
context.put(JMSSourceConfiguration.USERNAME, "dummy");
@@ -191,11 +208,13 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
Assert.assertEquals(batchSize, events.size());
assertBodyIsExpected(events);
}
+
@Test(expected = FlumeException.class)
public void testConfigureWithInvalidConverterClass() throws Exception {
context.put(JMSSourceConfiguration.CONVERTER_TYPE, "not a valid classname");
source.configure(context);
}
+
@Test
public void testProcessNoStart() throws Exception {
try {
@@ -205,6 +224,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
}
}
+
@Test
public void testNonDefaultConverter() throws Exception {
// tests that a classname can be specified
@@ -217,24 +237,26 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
assertBodyIsExpected(events);
verify(consumer).commit();
}
- public static class NonBuilderNonConfigurableConverter
- implements JMSMessageConverter {
+
+ public static class NonBuilderNonConfigurableConverter implements JMSMessageConverter {
@Override
public List<Event> convert(Message message) throws JMSException {
throw new UnsupportedOperationException();
}
}
- public static class NonBuilderConfigurableConverter
- implements JMSMessageConverter, Configurable {
+
+ public static class NonBuilderConfigurableConverter implements JMSMessageConverter, Configurable {
@Override
public List<Event> convert(Message message) throws JMSException {
throw new UnsupportedOperationException();
}
+
@Override
public void configure(Context context) {
}
}
+
@Test
public void testNonBuilderConfigurableConverter() throws Exception {
// tests that a non builder by configurable converter works
@@ -247,6 +269,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
assertBodyIsExpected(events);
verify(consumer).commit();
}
+
@Test
public void testNonBuilderNonConfigurableConverter() throws Exception {
// tests that a non builder non configurable converter
@@ -259,6 +282,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
assertBodyIsExpected(events);
verify(consumer).commit();
}
+
@Test
public void testProcessFullBatch() throws Exception {
source.configure(context);
@@ -268,6 +292,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
assertBodyIsExpected(events);
verify(consumer).commit();
}
+
@Test
public void testProcessNoEvents() throws Exception {
when(messageConsumer.receive(anyLong())).thenReturn(null);
@@ -277,6 +302,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
Assert.assertEquals(0, events.size());
verify(consumer).commit();
}
+
@Test
public void testProcessPartialBatch() throws Exception {
when(messageConsumer.receiveNoWait()).thenReturn(message, (Message)null);
@@ -287,6 +313,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
assertBodyIsExpected(events);
verify(consumer).commit();
}
+
@SuppressWarnings("unchecked")
@Test
public void testProcessChannelProcessorThrowsChannelException() throws Exception {
@@ -297,6 +324,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
Assert.assertEquals(Status.BACKOFF, source.process());
verify(consumer).rollback();
}
+
@SuppressWarnings("unchecked")
@Test
public void testProcessChannelProcessorThrowsError() throws Exception {
@@ -312,6 +340,7 @@ public class TestJMSSource extends JMSMessageConsumerTestBase {
}
verify(consumer).rollback();
}
+
@Test
public void testProcessReconnect() throws Exception {
source.configure(context);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedKafka.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedKafka.java b/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedKafka.java
index affac03..b72c532 100644
--- a/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedKafka.java
+++ b/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedKafka.java
@@ -16,9 +16,9 @@
*/
package org.apache.flume.source.kafka;
+import kafka.admin.AdminUtils;
import kafka.server.KafkaConfig;
import kafka.server.KafkaServerStartable;
-import kafka.admin.AdminUtils;
import kafka.utils.ZkUtils;
import org.I0Itec.zkclient.ZkClient;
import org.apache.commons.io.FileUtils;
@@ -70,8 +70,9 @@ public class KafkaSourceEmbeddedKafka {
props.put("host.name", "localhost");
props.put("port", String.valueOf(serverPort));
props.put("log.dir", dir.getAbsolutePath());
- if (properties != null)
+ if (properties != null) {
props.putAll(props);
+ }
KafkaConfig config = new KafkaConfig(props);
kafkaServer = new KafkaServerStartable(config);
kafkaServer.startup();
@@ -134,12 +135,12 @@ public class KafkaSourceEmbeddedKafka {
// Create a ZooKeeper client
int sessionTimeoutMs = 10000;
int connectionTimeoutMs = 10000;
- ZkClient zkClient = ZkUtils.createZkClient(HOST + ":" + zkPort, sessionTimeoutMs, connectionTimeoutMs);
+ ZkClient zkClient =
+ ZkUtils.createZkClient(HOST + ":" + zkPort, sessionTimeoutMs, connectionTimeoutMs);
ZkUtils zkUtils = ZkUtils.apply(zkClient, false);
int replicationFactor = 1;
Properties topicConfig = new Properties();
- AdminUtils.createTopic(zkUtils, topicName, numPartitions,
- replicationFactor, topicConfig);
+ AdminUtils.createTopic(zkUtils, topicName, numPartitions, replicationFactor, topicConfig);
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedZookeeper.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedZookeeper.java b/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedZookeeper.java
index db144c2..f04fc64 100644
--- a/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedZookeeper.java
+++ b/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/KafkaSourceEmbeddedZookeeper.java
@@ -31,7 +31,6 @@ public class KafkaSourceEmbeddedZookeeper {
private NIOServerCnxnFactory factory;
File dir;
-
public KafkaSourceEmbeddedZookeeper(int zkPort) {
int tickTime = 2000;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/TestKafkaSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/TestKafkaSource.java b/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/TestKafkaSource.java
index b4250de..1598741 100644
--- a/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/TestKafkaSource.java
+++ b/flume-ng-sources/flume-kafka-source/src/test/java/org/apache/flume/source/kafka/TestKafkaSource.java
@@ -17,29 +17,18 @@
package org.apache.flume.source.kafka;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.regex.Pattern;
-
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import junit.framework.Assert;
import kafka.common.TopicExistsException;
-
import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.EncoderFactory;
import org.apache.avro.specific.SpecificDatumWriter;
-import org.apache.flume.*;
+import org.apache.flume.ChannelException;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.flume.EventDeliveryException;
+import org.apache.flume.FlumeException;
import org.apache.flume.PollableSource.Status;
import org.apache.flume.channel.ChannelProcessor;
import org.apache.flume.source.avro.AvroFlumeEvent;
@@ -52,11 +41,36 @@ import org.mockito.stubbing.Answer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.flume.source.kafka.KafkaSourceConstants.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+import static org.apache.flume.source.kafka.KafkaSourceConstants.AVRO_EVENT;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.BATCH_DURATION_MS;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.BATCH_SIZE;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.BOOTSTRAP_SERVERS;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.DEFAULT_AUTO_COMMIT;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.KAFKA_CONSUMER_PREFIX;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.OLD_GROUP_ID;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.PARTITION_HEADER;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.TIMESTAMP_HEADER;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.TOPIC;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.TOPICS;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.TOPICS_REGEX;
+import static org.apache.flume.source.kafka.KafkaSourceConstants.TOPIC_HEADER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
public class TestKafkaSource {
- private static final Logger log =
- LoggerFactory.getLogger(TestKafkaSource.class);
+ private static final Logger log = LoggerFactory.getLogger(TestKafkaSource.class);
private KafkaSource kafkaSource;
private KafkaSourceEmbeddedKafka kafkaServer;
@@ -243,10 +257,10 @@ public class TestKafkaSource {
}
@SuppressWarnings("unchecked")
- @Test(expected= FlumeException.class)
- public void testNonExistingKafkaServer() throws EventDeliveryException,
- SecurityException, NoSuchFieldException, IllegalArgumentException,
- IllegalAccessException, InterruptedException {
+ @Test(expected = FlumeException.class)
+ public void testNonExistingKafkaServer() throws EventDeliveryException, SecurityException,
+ NoSuchFieldException, IllegalArgumentException,
+ IllegalAccessException, InterruptedException {
context.put(TOPICS, topic0);
context.put(BOOTSTRAP_SERVERS,"blabla:666");
kafkaSource.configure(context);
@@ -258,8 +272,7 @@ public class TestKafkaSource {
}
@Test
- public void testBatchTime() throws InterruptedException,
- EventDeliveryException {
+ public void testBatchTime() throws InterruptedException, EventDeliveryException {
context.put(TOPICS, topic0);
context.put(BATCH_DURATION_MS, "250");
kafkaSource.configure(context);
@@ -267,7 +280,7 @@ public class TestKafkaSource {
Thread.sleep(500L);
- for (int i=1; i<5000; i++) {
+ for (int i = 1; i < 5000; i++) {
kafkaServer.produce(topic0, "", "hello, world " + i);
}
Thread.sleep(500L);
@@ -277,8 +290,7 @@ public class TestKafkaSource {
Status status = kafkaSource.process();
long endTime = System.currentTimeMillis();
assertEquals(Status.READY, status);
- assertTrue(endTime - startTime <
- (context.getLong(BATCH_DURATION_MS) + error));
+ assertTrue(endTime - startTime < (context.getLong(BATCH_DURATION_MS) + error));
}
// Consume event, stop source, start again and make sure we are not
@@ -302,13 +314,11 @@ public class TestKafkaSource {
kafkaSource.start();
Thread.sleep(500L);
Assert.assertEquals(Status.BACKOFF, kafkaSource.process());
-
}
// Remove channel processor and test if we can consume events again
@Test
- public void testNonCommit() throws EventDeliveryException,
- InterruptedException {
+ public void testNonCommit() throws EventDeliveryException, InterruptedException {
context.put(TOPICS, topic0);
context.put(BATCH_SIZE,"1");
context.put(BATCH_DURATION_MS,"30000");
@@ -328,15 +338,11 @@ public class TestKafkaSource {
log.debug("re-process to good channel - this should work");
kafkaSource.process();
- Assert.assertEquals("hello, world", new String(events.get(0).getBody(),
- Charsets.UTF_8));
-
-
+ Assert.assertEquals("hello, world", new String(events.get(0).getBody(), Charsets.UTF_8));
}
@Test
- public void testTwoBatches() throws InterruptedException,
- EventDeliveryException {
+ public void testTwoBatches() throws InterruptedException, EventDeliveryException {
context.put(TOPICS, topic0);
context.put(BATCH_SIZE,"1");
context.put(BATCH_DURATION_MS, "30000");
@@ -348,20 +354,17 @@ public class TestKafkaSource {
Thread.sleep(500L);
kafkaSource.process();
- Assert.assertEquals("event 1", new String(events.get(0).getBody(),
- Charsets.UTF_8));
+ Assert.assertEquals("event 1", new String(events.get(0).getBody(), Charsets.UTF_8));
events.clear();
kafkaServer.produce(topic0, "", "event 2");
Thread.sleep(500L);
kafkaSource.process();
- Assert.assertEquals("event 2", new String(events.get(0).getBody(),
- Charsets.UTF_8));
+ Assert.assertEquals("event 2", new String(events.get(0).getBody(), Charsets.UTF_8));
}
@Test
- public void testTwoBatchesWithAutocommit() throws InterruptedException,
- EventDeliveryException {
+ public void testTwoBatchesWithAutocommit() throws InterruptedException, EventDeliveryException {
context.put(TOPICS, topic0);
context.put(BATCH_SIZE,"1");
context.put(BATCH_DURATION_MS,"30000");
@@ -374,23 +377,20 @@ public class TestKafkaSource {
Thread.sleep(500L);
kafkaSource.process();
- Assert.assertEquals("event 1", new String(events.get(0).getBody(),
- Charsets.UTF_8));
+ Assert.assertEquals("event 1", new String(events.get(0).getBody(), Charsets.UTF_8));
events.clear();
kafkaServer.produce(topic0, "", "event 2");
Thread.sleep(500L);
kafkaSource.process();
- Assert.assertEquals("event 2", new String(events.get(0).getBody(),
- Charsets.UTF_8));
-
+ Assert.assertEquals("event 2", new String(events.get(0).getBody(), Charsets.UTF_8));
}
@SuppressWarnings("unchecked")
@Test
- public void testNullKey() throws EventDeliveryException,
- SecurityException, NoSuchFieldException, IllegalArgumentException,
- IllegalAccessException, InterruptedException {
+ public void testNullKey() throws EventDeliveryException, SecurityException, NoSuchFieldException,
+ IllegalArgumentException, IllegalAccessException,
+ InterruptedException {
context.put(TOPICS, topic0);
context.put(BATCH_SIZE, "1");
kafkaSource.configure(context);
@@ -406,8 +406,7 @@ public class TestKafkaSource {
Assert.assertEquals(Status.BACKOFF, kafkaSource.process());
Assert.assertEquals(1, events.size());
- Assert.assertEquals("hello, world", new String(events.get(0).getBody(),
- Charsets.UTF_8));
+ Assert.assertEquals("hello, world", new String(events.get(0).getBody(), Charsets.UTF_8));
}
@Test
@@ -430,7 +429,8 @@ public class TestKafkaSource {
public void testKafkaProperties() {
Context context = new Context();
context.put(TOPICS, "test1, test2");
- context.put(KAFKA_CONSUMER_PREFIX + ConsumerConfig.GROUP_ID_CONFIG, "override.default.group.id");
+ context.put(KAFKA_CONSUMER_PREFIX + ConsumerConfig.GROUP_ID_CONFIG,
+ "override.default.group.id");
context.put(KAFKA_CONSUMER_PREFIX + "fake.property", "kafka.property.value");
context.put(BOOTSTRAP_SERVERS, "real-bootstrap-servers-list");
context.put(KAFKA_CONSUMER_PREFIX + "bootstrap.servers", "bad-bootstrap-servers-list");
@@ -439,21 +439,17 @@ public class TestKafkaSource {
Properties kafkaProps = source.getConsumerProps();
//check that we have defaults set
- assertEquals(
- String.valueOf(DEFAULT_AUTO_COMMIT),
- kafkaProps.getProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG));
+ assertEquals(String.valueOf(DEFAULT_AUTO_COMMIT),
+ kafkaProps.getProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG));
//check that kafka properties override the default and get correct name
- assertEquals(
- "override.default.group.id",
- kafkaProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG));
+ assertEquals("override.default.group.id",
+ kafkaProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG));
//check that any kafka property gets in
- assertEquals(
- "kafka.property.value",
- kafkaProps.getProperty("fake.property"));
+ assertEquals("kafka.property.value",
+ kafkaProps.getProperty("fake.property"));
//check that documented property overrides defaults
- assertEquals(
- "real-bootstrap-servers-list",
- kafkaProps.getProperty("bootstrap.servers"));
+ assertEquals("real-bootstrap-servers-list",
+ kafkaProps.getProperty("bootstrap.servers"));
}
@Test
@@ -469,22 +465,16 @@ public class TestKafkaSource {
KafkaSource.Subscriber<List<String>> subscriber = source.getSubscriber();
//check topic was set
- assertEquals(
- "old.topic",
- subscriber.get().get(0));
+ assertEquals("old.topic", subscriber.get().get(0));
//check that kafka old properties override the default and get correct name
- assertEquals(
- "old.groupId",
- kafkaProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG));
+ assertEquals("old.groupId", kafkaProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG));
source = new KafkaSource();
context.put(KAFKA_CONSUMER_PREFIX + ConsumerConfig.GROUP_ID_CONFIG, "override.old.group.id");
source.doConfigure(context);
kafkaProps = source.getConsumerProps();
//check that kafka new properties override old
- assertEquals(
- "override.old.group.id",
- kafkaProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG));
+ assertEquals("override.old.group.id", kafkaProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG));
context.clear();
context.put(BOOTSTRAP_SERVERS, "real-bootstrap-servers-list");
@@ -493,9 +483,8 @@ public class TestKafkaSource {
source.doConfigure(context);
kafkaProps = source.getConsumerProps();
//check defaults set
- assertEquals(
- KafkaSourceConstants.DEFAULT_GROUP_ID,
- kafkaProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG));
+ assertEquals(KafkaSourceConstants.DEFAULT_GROUP_ID,
+ kafkaProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG));
}
@Test
@@ -568,8 +557,7 @@ public class TestKafkaSource {
Event event = events.get(0);
- Assert.assertEquals("hello, world", new String(event.getBody(),
- Charsets.UTF_8));
+ Assert.assertEquals("hello, world", new String(event.getBody(), Charsets.UTF_8));
Assert.assertEquals("value1", e.getHeaders().get("header1"));
Assert.assertEquals("value2", e.getHeaders().get("header2"));
@@ -577,8 +565,7 @@ public class TestKafkaSource {
event = events.get(1);
- Assert.assertEquals("hello, world2", new String(event.getBody(),
- Charsets.UTF_8));
+ Assert.assertEquals("hello, world2", new String(event.getBody(), Charsets.UTF_8));
Assert.assertEquals("value1", e.getHeaders().get("header1"));
Assert.assertEquals("value2", e.getHeaders().get("header2"));
@@ -603,7 +590,6 @@ public class TestKafkaSource {
}).when(channelProcessor).processEventBatch(any(List.class));
return channelProcessor;
-
}
ChannelProcessor createBadChannel() {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirEventReader.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirEventReader.java b/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirEventReader.java
index 1896883..bcfe4bb 100644
--- a/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirEventReader.java
+++ b/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirEventReader.java
@@ -19,20 +19,6 @@
package org.apache.flume.source.taildir;
-import static org.apache.flume.source.taildir.TaildirSourceConfigurationConstants.*;
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.flume.Event;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
import com.google.common.collect.HashBasedTable;
@@ -41,6 +27,22 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import com.google.common.io.Files;
+import org.apache.flume.Event;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.flume.source.taildir.TaildirSourceConfigurationConstants
+ .BYTE_OFFSET_HEADER_KEY;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class TestTaildirEventReader {
private File tmpDir;
@@ -85,7 +87,8 @@ public class TestTaildirEventReader {
}
private ReliableTaildirEventReader getReader(boolean addByteOffset) {
- Map<String, String> filePaths = ImmutableMap.of("testFiles", tmpDir.getAbsolutePath() + "/file.*");
+ Map<String, String> filePaths = ImmutableMap.of("testFiles",
+ tmpDir.getAbsolutePath() + "/file.*");
Table<String, String, String> headerTable = HashBasedTable.create();
return getReader(filePaths, headerTable, addByteOffset);
}
@@ -472,7 +475,8 @@ public class TestTaildirEventReader {
@Test
public void testNewLineBoundaries() throws IOException {
File f1 = new File(tmpDir, "file1");
- Files.write("file1line1\nfile1line2\rfile1line2\nfile1line3\r\nfile1line4\n", f1, Charsets.UTF_8);
+ Files.write("file1line1\nfile1line2\rfile1line2\nfile1line3\r\nfile1line4\n",
+ f1, Charsets.UTF_8);
ReliableTaildirEventReader reader = getReader();
List<String> out = Lists.newArrayList();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirMatcher.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirMatcher.java b/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirMatcher.java
index 4bff841..c341054 100644
--- a/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirMatcher.java
+++ b/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirMatcher.java
@@ -33,7 +33,10 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
public class TestTaildirMatcher {
private File tmpDir;
@@ -55,10 +58,10 @@ public class TestTaildirMatcher {
*/
private void append(String fileName) throws IOException {
File f;
- if(!files.containsKey(fileName)){
+ if (!files.containsKey(fileName)) {
f = new File(tmpDir, fileName);
files.put(fileName, f);
- }else{
+ } else {
f = files.get(fileName);
}
Files.append(fileName + "line\n", f, Charsets.UTF_8);
@@ -67,7 +70,7 @@ public class TestTaildirMatcher {
/**
* Translate a list of files to list of filename strings.
*/
- private static List<String> filesToNames(List<File> origList){
+ private static List<String> filesToNames(List<File> origList) {
Function<File, String> file2nameFn = new Function<File, String>() {
@Override
public String apply(File input) {
@@ -102,7 +105,9 @@ public class TestTaildirMatcher {
append("file0");
append("file1");
- TaildirMatcher tm = new TaildirMatcher("f1", tmpDir.getAbsolutePath() + File.separator + "file.*", isCachingNeeded);
+ TaildirMatcher tm = new TaildirMatcher("f1",
+ tmpDir.getAbsolutePath() + File.separator + "file.*",
+ isCachingNeeded);
List<String> files = filesToNames(tm.getMatchingFiles());
assertEquals(msgAlreadyExistingFile, 2, files.size());
assertTrue(msgAlreadyExistingFile, files.contains("file1"));
@@ -136,7 +141,9 @@ public class TestTaildirMatcher {
append("file0");
append("file1");
- TaildirMatcher tm = new TaildirMatcher("f1", tmpDir.getAbsolutePath() + File.separator + "file.*", false);
+ TaildirMatcher tm = new TaildirMatcher("f1",
+ tmpDir.getAbsolutePath() + File.separator + "file.*",
+ false);
List<String> files = filesToNames(tm.getMatchingFiles());
assertEquals(msgAlreadyExistingFile, 2, files.size());
assertTrue(msgAlreadyExistingFile, files.contains("file1"));
@@ -167,7 +174,9 @@ public class TestTaildirMatcher {
@Test
public void testEmtpyDirMatching() throws Exception {
- TaildirMatcher tm = new TaildirMatcher("empty", tmpDir.getAbsolutePath() + File.separator + ".*", isCachingNeeded);
+ TaildirMatcher tm = new TaildirMatcher("empty",
+ tmpDir.getAbsolutePath() + File.separator + ".*",
+ isCachingNeeded);
List<File> files = tm.getMatchingFiles();
assertNotNull(msgEmptyDir, files);
assertTrue(msgEmptyDir, files.isEmpty());
@@ -175,7 +184,10 @@ public class TestTaildirMatcher {
@Test
public void testNoMatching() throws Exception {
- TaildirMatcher tm = new TaildirMatcher("nomatch", tmpDir.getAbsolutePath() + File.separator + "abracadabra_nonexisting", isCachingNeeded);
+ TaildirMatcher tm = new TaildirMatcher(
+ "nomatch",
+ tmpDir.getAbsolutePath() + File.separator + "abracadabra_nonexisting",
+ isCachingNeeded);
List<File> files = tm.getMatchingFiles();
assertNotNull(msgNoMatch, files);
assertTrue(msgNoMatch, files.isEmpty());
@@ -183,7 +195,8 @@ public class TestTaildirMatcher {
@Test(expected = IllegalStateException.class)
public void testNonExistingDir() {
- TaildirMatcher tm = new TaildirMatcher("exception", "/abracadabra/doesntexist/.*", isCachingNeeded);
+ TaildirMatcher tm = new TaildirMatcher("exception", "/abracadabra/doesntexist/.*",
+ isCachingNeeded);
}
@Test
@@ -191,7 +204,8 @@ public class TestTaildirMatcher {
new File(tmpDir, "outerFile").createNewFile();
new File(tmpDir, "recursiveDir").mkdir();
new File(tmpDir + File.separator + "recursiveDir", "innerFile").createNewFile();
- TaildirMatcher tm = new TaildirMatcher("f1", tmpDir.getAbsolutePath() + File.separator + ".*", isCachingNeeded);
+ TaildirMatcher tm = new TaildirMatcher("f1", tmpDir.getAbsolutePath() + File.separator + ".*",
+ isCachingNeeded);
List<String> files = filesToNames(tm.getMatchingFiles());
assertEquals(msgSubDirs, 1, files.size());
@@ -207,9 +221,13 @@ public class TestTaildirMatcher {
append("c.log.yyyy.MM-02");
// Tail a.log and b.log
- TaildirMatcher tm1 = new TaildirMatcher("ab", tmpDir.getAbsolutePath() + File.separator + "[ab].log", isCachingNeeded);
+ TaildirMatcher tm1 = new TaildirMatcher("ab",
+ tmpDir.getAbsolutePath() + File.separator + "[ab].log",
+ isCachingNeeded);
// Tail files that starts with c.log
- TaildirMatcher tm2 = new TaildirMatcher("c", tmpDir.getAbsolutePath() + File.separator + "c.log.*", isCachingNeeded);
+ TaildirMatcher tm2 = new TaildirMatcher("c",
+ tmpDir.getAbsolutePath() + File.separator + "c.log.*",
+ isCachingNeeded);
List<String> files1 = filesToNames(tm1.getMatchingFiles());
List<String> files2 = filesToNames(tm2.getMatchingFiles());
@@ -217,11 +235,16 @@ public class TestTaildirMatcher {
assertEquals(2, files1.size());
assertEquals(2, files2.size());
// Make sure we got every file
- assertTrue("Regex pattern for ab should have matched a.log file", files1.contains("a.log"));
- assertFalse("Regex pattern for ab should NOT have matched a.log.1 file", files1.contains("a.log.1"));
- assertTrue("Regex pattern for ab should have matched b.log file", files1.contains("b.log"));
- assertTrue("Regex pattern for c should have matched c.log.yyyy-MM-01 file", files2.contains("c.log.yyyy.MM-01"));
- assertTrue("Regex pattern for c should have matched c.log.yyyy-MM-02 file", files2.contains("c.log.yyyy.MM-02"));
+ assertTrue("Regex pattern for ab should have matched a.log file",
+ files1.contains("a.log"));
+ assertFalse("Regex pattern for ab should NOT have matched a.log.1 file",
+ files1.contains("a.log.1"));
+ assertTrue("Regex pattern for ab should have matched b.log file",
+ files1.contains("b.log"));
+ assertTrue("Regex pattern for c should have matched c.log.yyyy-MM-01 file",
+ files2.contains("c.log.yyyy.MM-01"));
+ assertTrue("Regex pattern for c should have matched c.log.yyyy-MM-02 file",
+ files2.contains("c.log.yyyy.MM-02"));
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirSource.java b/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirSource.java
index f6289cd..e090b74 100644
--- a/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirSource.java
+++ b/flume-ng-sources/flume-taildir-source/src/test/java/org/apache/flume/source/taildir/TestTaildirSource.java
@@ -17,14 +17,9 @@
package org.apache.flume.source.taildir;
-import static org.apache.flume.source.taildir.TaildirSourceConfigurationConstants.*;
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
import org.apache.flume.Context;
@@ -40,9 +35,21 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import com.google.common.base.Charsets;
-import com.google.common.collect.Lists;
-import com.google.common.io.Files;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.flume.source.taildir.TaildirSourceConfigurationConstants.FILE_GROUPS;
+import static org.apache.flume.source.taildir.TaildirSourceConfigurationConstants
+ .FILE_GROUPS_PREFIX;
+import static org.apache.flume.source.taildir.TaildirSourceConfigurationConstants.HEADERS_PREFIX;
+import static org.apache.flume.source.taildir.TaildirSourceConfigurationConstants.POSITION_FILE;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class TestTaildirSource {
static TaildirSource source;
@@ -274,10 +281,11 @@ public class TestTaildirSource {
line1b, line2b, line3b, // file2
line1d, line2d, line3d, // file4
line1c, line2c, line3c // file3
- );
- for(int i =0; i!=expected.size(); ++i) {
- expected.set(i, expected.get(i).trim() );
+ );
+ for (int i = 0; i != expected.size(); ++i) {
+ expected.set(i, expected.get(i).trim());
}
- assertArrayEquals("Files not consumed in expected order", expected.toArray(), consumedOrder.toArray());
+ assertArrayEquals("Files not consumed in expected order", expected.toArray(),
+ consumedOrder.toArray());
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestFileChannel.java
----------------------------------------------------------------------
diff --git a/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestFileChannel.java b/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestFileChannel.java
index 4a80b8c..6a98292 100644
--- a/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestFileChannel.java
+++ b/flume-ng-tests/src/test/java/org/apache/flume/test/agent/TestFileChannel.java
@@ -18,14 +18,8 @@
*/
package org.apache.flume.test.agent;
-import java.io.File;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-import java.util.regex.Pattern;
-
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
import org.apache.flume.test.util.StagedInstall;
import org.apache.log4j.Logger;
import org.junit.After;
@@ -33,9 +27,11 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import com.google.common.base.Charsets;
-import com.google.common.base.Splitter;
-import com.google.common.io.Files;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
public class TestFileChannel {
@@ -48,61 +44,57 @@ public class TestFileChannel {
@Before
public void setUp() throws Exception {
- /* Create 3 temp dirs, each used as value within agentProps */
-
- final File sinkOutputDir = Files.createTempDir();
- tempResources.add(sinkOutputDir);
- final String sinkOutputDirPath = sinkOutputDir.getCanonicalPath();
- LOGGER.info("Created rolling file sink's output dir: "
- + sinkOutputDirPath);
-
- final File channelCheckpointDir = Files.createTempDir();
- tempResources.add(channelCheckpointDir);
- final String channelCheckpointDirPath = channelCheckpointDir
- .getCanonicalPath();
- LOGGER.info("Created file channel's checkpoint dir: "
- + channelCheckpointDirPath);
-
- final File channelDataDir = Files.createTempDir();
- tempResources.add(channelDataDir);
- final String channelDataDirPath = channelDataDir.getCanonicalPath();
- LOGGER.info("Created file channel's data dir: "
- + channelDataDirPath);
-
- /* Build props to pass to flume agent */
-
- Properties agentProps = new Properties();
-
- // Active sets
- agentProps.put("a1.channels", "c1");
- agentProps.put("a1.sources", "r1");
- agentProps.put("a1.sinks", "k1");
-
- // c1
- agentProps.put("a1.channels.c1.type", "FILE");
- agentProps.put("a1.channels.c1.checkpointDir", channelCheckpointDirPath);
- agentProps.put("a1.channels.c1.dataDirs", channelDataDirPath);
-
- // r1
- agentProps.put("a1.sources.r1.channels", "c1");
- agentProps.put("a1.sources.r1.type", "EXEC");
- agentProps.put("a1.sources.r1.command", "seq 1 100");
-
- // k1
- agentProps.put("a1.sinks.k1.channel", "c1");
- agentProps.put("a1.sinks.k1.type", "FILE_ROLL");
- agentProps.put("a1.sinks.k1.sink.directory", sinkOutputDirPath);
- agentProps.put("a1.sinks.k1.sink.rollInterval", "0");
-
- this.agentProps = agentProps;
- this.sinkOutputDir = sinkOutputDir;
+ /* Create 3 temp dirs, each used as value within agentProps */
+
+ final File sinkOutputDir = Files.createTempDir();
+ tempResources.add(sinkOutputDir);
+ final String sinkOutputDirPath = sinkOutputDir.getCanonicalPath();
+ LOGGER.info("Created rolling file sink's output dir: " + sinkOutputDirPath);
+
+ final File channelCheckpointDir = Files.createTempDir();
+ tempResources.add(channelCheckpointDir);
+ final String channelCheckpointDirPath = channelCheckpointDir.getCanonicalPath();
+ LOGGER.info("Created file channel's checkpoint dir: " + channelCheckpointDirPath);
+
+ final File channelDataDir = Files.createTempDir();
+ tempResources.add(channelDataDir);
+ final String channelDataDirPath = channelDataDir.getCanonicalPath();
+ LOGGER.info("Created file channel's data dir: " + channelDataDirPath);
+
+ /* Build props to pass to flume agent */
+
+ Properties agentProps = new Properties();
+
+ // Active sets
+ agentProps.put("a1.channels", "c1");
+ agentProps.put("a1.sources", "r1");
+ agentProps.put("a1.sinks", "k1");
+
+ // c1
+ agentProps.put("a1.channels.c1.type", "FILE");
+ agentProps.put("a1.channels.c1.checkpointDir", channelCheckpointDirPath);
+ agentProps.put("a1.channels.c1.dataDirs", channelDataDirPath);
+
+ // r1
+ agentProps.put("a1.sources.r1.channels", "c1");
+ agentProps.put("a1.sources.r1.type", "EXEC");
+ agentProps.put("a1.sources.r1.command", "seq 1 100");
+
+ // k1
+ agentProps.put("a1.sinks.k1.channel", "c1");
+ agentProps.put("a1.sinks.k1.type", "FILE_ROLL");
+ agentProps.put("a1.sinks.k1.sink.directory", sinkOutputDirPath);
+ agentProps.put("a1.sinks.k1.sink.rollInterval", "0");
+
+ this.agentProps = agentProps;
+ this.sinkOutputDir = sinkOutputDir;
}
@After
public void tearDown() throws Exception {
StagedInstall.getInstance().stopAgent();
for (File tempResource : tempResources) {
- tempResource.delete();
+ tempResource.delete();
}
agentProps = null;
}
@@ -110,7 +102,7 @@ public class TestFileChannel {
/**
* File channel in/out test. Verifies that all events inserted into the
* file channel are received by the sink in order.
- *
+ * <p>
* The EXEC source creates 100 events where the event bodies have
* sequential numbers. The source puts those events into the file channel,
* and the FILE_ROLL The sink is expected to take all 100 events in FIFO
@@ -119,38 +111,36 @@ public class TestFileChannel {
* @throws Exception
*/
@Test
- public void testInOut() throws Exception {
- LOGGER.debug("testInOut() started.");
-
- StagedInstall.getInstance().startAgent("a1", agentProps);
- TimeUnit.SECONDS.sleep(10); // Wait for source and sink to finish
- // TODO make this more deterministic
-
- /* Create expected output */
-
- StringBuffer sb = new StringBuffer();
- for (int i = 1; i <= 100; i++) {
- sb.append(i).append("\n");
- }
- String expectedOutput = sb.toString();
- LOGGER.info("Created expected output: " + expectedOutput);
-
- /* Create actual output file */
-
- File[] sinkOutputDirChildren = sinkOutputDir.listFiles();
- // Only 1 file should be in FILE_ROLL sink's dir (rolling is disabled)
- Assert.assertEquals("Expected FILE_ROLL sink's dir to have only 1 child," +
- " but found " + sinkOutputDirChildren.length + " children.",
- 1, sinkOutputDirChildren.length);
- File actualOutput = sinkOutputDirChildren[0];
-
- if (!Files.toString(actualOutput, Charsets.UTF_8).equals(expectedOutput)) {
- LOGGER.error("Actual output doesn't match expected output.\n");
- throw new AssertionError("FILE_ROLL sink's actual output doesn't " +
- "match expected output.");
- }
-
- LOGGER.debug("testInOut() ended.");
- }
+ public void testInOut() throws Exception {
+ LOGGER.debug("testInOut() started.");
+ StagedInstall.getInstance().startAgent("a1", agentProps);
+ TimeUnit.SECONDS.sleep(10); // Wait for source and sink to finish
+ // TODO make this more deterministic
+
+ /* Create expected output */
+ StringBuffer sb = new StringBuffer();
+ for (int i = 1; i <= 100; i++) {
+ sb.append(i).append("\n");
+ }
+ String expectedOutput = sb.toString();
+ LOGGER.info("Created expected output: " + expectedOutput);
+
+ /* Create actual output file */
+
+ File[] sinkOutputDirChildren = sinkOutputDir.listFiles();
+ // Only 1 file should be in FILE_ROLL sink's dir (rolling is disabled)
+ Assert.assertEquals("Expected FILE_ROLL sink's dir to have only 1 child," +
+ " but found " + sinkOutputDirChildren.length + " children.",
+ 1, sinkOutputDirChildren.length);
+ File actualOutput = sinkOutputDirChildren[0];
+
+ if (!Files.toString(actualOutput, Charsets.UTF_8).equals(expectedOutput)) {
+ LOGGER.error("Actual output doesn't match expected output.\n");
+ throw new AssertionError("FILE_ROLL sink's actual output doesn't " +
+ "match expected output.");
+ }
+
+ LOGGER.debug("testInOut() ended.");
+ }
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java
----------------------------------------------------------------------
diff --git a/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java b/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java
index 973ff4a..51194b6 100644
--- a/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java
+++ b/flume-ng-tests/src/test/java/org/apache/flume/test/util/StagedInstall.java
@@ -18,6 +18,14 @@
*/
package org.apache.flume.test.util;
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.io.Files;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.log4j.Logger;
+
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
@@ -29,18 +37,8 @@ import java.net.Socket;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
-import com.google.common.base.Preconditions;
-import com.google.common.io.Files;
-import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
-import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
-import org.apache.log4j.Logger;
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
-
/**
* Attempts to setup a staged install using explicitly specified tar-ball
@@ -73,7 +71,7 @@ public class StagedInstall {
private static StagedInstall INSTANCE;
- public synchronized static StagedInstall getInstance() throws Exception {
+ public static synchronized StagedInstall getInstance() throws Exception {
if (INSTANCE == null) {
INSTANCE = new StagedInstall();
}
@@ -124,8 +122,7 @@ public class StagedInstall {
if (process != null) {
throw new Exception("A process is already running");
}
- LOGGER.info("Starting process for agent: " + agentName + " using config: "
- + properties);
+ LOGGER.info("Starting process for agent: " + agentName + " using config: " + properties);
File configFile = createConfigurationFile(agentName, properties);
configFilePath = configFile.getCanonicalPath();
@@ -252,7 +249,7 @@ public class StagedInstall {
File[] listBaseDirs = stageDir.listFiles();
if (listBaseDirs != null && listBaseDirs.length == 1
&& listBaseDirs[0].isDirectory()) {
- rootDir =listBaseDirs[0];
+ rootDir = listBaseDirs[0];
}
baseDir = rootDir;
@@ -417,7 +414,6 @@ public class StagedInstall {
if (testFile.exists() && testFile.isDirectory()) {
LOGGER.info("Found candidate dir: " + testFile.getCanonicalPath());
File[] candidateFiles = testFile.listFiles(new FileFilter() {
-
@Override
public boolean accept(File pathname) {
String name = pathname.getName();
@@ -426,7 +422,8 @@ public class StagedInstall {
return true;
}
return false;
- }});
+ }
+ });
// There should be at most one
if (candidateFiles != null && candidateFiles.length > 0) {
@@ -466,22 +463,22 @@ public class StagedInstall {
}
public static void waitUntilPortOpens(String host, int port, long timeout)
- throws IOException, InterruptedException{
+ throws IOException, InterruptedException {
long startTime = System.currentTimeMillis();
Socket socket;
boolean connected = false;
//See if port has opened for timeout.
- while(System.currentTimeMillis() - startTime < timeout){
- try{
+ while (System.currentTimeMillis() - startTime < timeout) {
+ try {
socket = new Socket(host, port);
socket.close();
connected = true;
break;
- } catch (IOException e){
+ } catch (IOException e) {
Thread.sleep(2000);
}
}
- if(!connected) {
+ if (!connected) {
throw new IOException("Port not opened within specified timeout.");
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-tests/src/test/java/org/apache/flume/test/util/SyslogAgent.java
----------------------------------------------------------------------
diff --git a/flume-ng-tests/src/test/java/org/apache/flume/test/util/SyslogAgent.java b/flume-ng-tests/src/test/java/org/apache/flume/test/util/SyslogAgent.java
index 7159549..c908fc1 100644
--- a/flume-ng-tests/src/test/java/org/apache/flume/test/util/SyslogAgent.java
+++ b/flume-ng-tests/src/test/java/org/apache/flume/test/util/SyslogAgent.java
@@ -60,7 +60,7 @@ public class SyslogAgent {
public String toString() {
return syslogSourceType;
}
- };
+ }
private Properties agentProps;
private File sinkOutputDir;
@@ -73,7 +73,6 @@ public class SyslogAgent {
public SyslogAgent() throws IOException {
hostname = "localhost";
-
setRandomPort();
}
@@ -141,7 +140,7 @@ public class SyslogAgent {
while (client == null) {
try {
client = new BufferedOutputStream(new Socket(hostname, port).getOutputStream());
- } catch(IOException e) {
+ } catch (IOException e) {
if (++numberOfAttempts >= DEFAULT_ATTEMPTS) {
throw new AssertionError("Could not connect to source after "
+ DEFAULT_ATTEMPTS + " attempts with " + DEFAULT_TIMEOUT + " ms timeout.");
@@ -206,8 +205,8 @@ public class SyslogAgent {
// Only 1 file should be in FILE_ROLL sink's dir (rolling is disabled)
File[] sinkOutputDirChildren = sinkOutputDir.listFiles();
Assert.assertEquals("Expected FILE_ROLL sink's dir to have only 1 child," +
- " but found " + sinkOutputDirChildren.length + " children.",
- 1, sinkOutputDirChildren.length);
+ " but found " + sinkOutputDirChildren.length + " children.",
+ 1, sinkOutputDirChildren.length);
/* Wait for output file stats to be as expected. */
File outputDirChild = sinkOutputDirChildren[0];
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-tools/src/test/java/org/apache/flume/tools/TestFileChannelIntegrityTool.java
----------------------------------------------------------------------
diff --git a/flume-tools/src/test/java/org/apache/flume/tools/TestFileChannelIntegrityTool.java b/flume-tools/src/test/java/org/apache/flume/tools/TestFileChannelIntegrityTool.java
index a11126d..9fc5f2c 100644
--- a/flume-tools/src/test/java/org/apache/flume/tools/TestFileChannelIntegrityTool.java
+++ b/flume-tools/src/test/java/org/apache/flume/tools/TestFileChannelIntegrityTool.java
@@ -34,7 +34,6 @@ import org.apache.flume.channel.file.WriteOrderOracle;
import org.apache.flume.event.EventBuilder;
import org.junit.After;
import org.junit.AfterClass;
-import static org.fest.reflect.core.Reflection.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -47,6 +46,8 @@ import java.util.HashSet;
import java.util.Random;
import java.util.Set;
+import static org.fest.reflect.core.Reflection.field;
+import static org.fest.reflect.core.Reflection.method;
public class TestFileChannelIntegrityTool {
private static File baseDir;
@@ -61,7 +62,7 @@ public class TestFileChannelIntegrityTool {
private static int invalidEvent = 0;
@BeforeClass
- public static void setUpClass() throws Exception{
+ public static void setUpClass() throws Exception {
createDataFiles();
}
@@ -74,13 +75,13 @@ public class TestFileChannelIntegrityTool {
File[] dataFiles = origDataDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
- if(name.contains("lock")) {
+ if (name.contains("lock")) {
return false;
}
return true;
}
});
- for(File dataFile : dataFiles) {
+ for (File dataFile : dataFiles) {
Serialization.copyFile(dataFile, new File(dataDir, dataFile.getName()));
}
}
@@ -146,7 +147,7 @@ public class TestFileChannelIntegrityTool {
Transaction tx = channel.getTransaction();
tx.begin();
int i = 0;
- while(channel.take() != null) {
+ while (channel.take() != null) {
i++;
}
tx.commit();
@@ -161,7 +162,7 @@ public class TestFileChannelIntegrityTool {
File[] files = dataDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
- if(name.contains("lock") || name.contains("meta")) {
+ if (name.contains("lock") || name.contains("meta")) {
return false;
}
return true;
@@ -170,15 +171,13 @@ public class TestFileChannelIntegrityTool {
Random random = new Random();
int corrupted = 0;
for (File dataFile : files) {
- LogFile.SequentialReader reader =
- new LogFileV3.SequentialReader(dataFile, null, true);
+ LogFile.SequentialReader reader = new LogFileV3.SequentialReader(dataFile, null, true);
RandomAccessFile handle = new RandomAccessFile(dataFile, "rw");
long eventPosition1 = reader.getPosition();
LogRecord rec = reader.next();
//No point corrupting commits, so ignore them
- if(rec == null ||
- rec.getEvent().getClass().getName().
- equals("org.apache.flume.channel.file.Commit")) {
+ if (rec == null ||
+ rec.getEvent().getClass().getName().equals("org.apache.flume.channel.file.Commit")) {
handle.close();
reader.close();
continue;
@@ -190,8 +189,7 @@ public class TestFileChannelIntegrityTool {
corrupted++;
corruptFiles.add(dataFile.getName());
if (rec == null ||
- rec.getEvent().getClass().getName().
- equals("org.apache.flume.channel.file.Commit")) {
+ rec.getEvent().getClass().getName().equals("org.apache.flume.channel.file.Commit")) {
handle.close();
reader.close();
continue;
@@ -231,7 +229,7 @@ public class TestFileChannelIntegrityTool {
Transaction tx = channel.getTransaction();
tx.begin();
int i = 0;
- while(channel.take() != null) {
+ while (channel.take() != null) {
i++;
}
tx.commit();
@@ -241,14 +239,14 @@ public class TestFileChannelIntegrityTool {
files = dataDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
- if(name.contains(".bak")) {
+ if (name.contains(".bak")) {
return true;
}
return false;
}
});
Assert.assertEquals(corruptFiles.size(), files.length);
- for(File file : files) {
+ for (File file : files) {
String name = file.getName();
name = name.replaceAll(".bak", "");
Assert.assertTrue(corruptFiles.remove(name));
@@ -258,13 +256,13 @@ public class TestFileChannelIntegrityTool {
private static void createDataFiles() throws Exception {
final byte[] eventData = new byte[2000];
- for(int i = 0; i < 2000; i++) {
+ for (int i = 0; i < 2000; i++) {
eventData[i] = 1;
}
WriteOrderOracle.setSeed(System.currentTimeMillis());
event = EventBuilder.withBody(eventData);
baseDir = Files.createTempDir();
- if(baseDir.exists()) {
+ if (baseDir.exists()) {
FileUtils.deleteDirectory(baseDir);
}
baseDir = Files.createTempDir();
@@ -286,7 +284,7 @@ public class TestFileChannelIntegrityTool {
Transaction tx = channel.getTransaction();
tx.begin();
for (int i = 0; i < 5; i++) {
- if(i % 3 == 0) {
+ if (i % 3 == 0) {
event.getBody()[0] = 0;
invalidEvent++;
} else {
@@ -297,22 +295,19 @@ public class TestFileChannelIntegrityTool {
tx.commit();
tx.close();
}
- Log log = field("log")
- .ofType(Log.class)
- .in(channel)
- .get();
+ Log log = field("log").ofType(Log.class)
+ .in(channel)
+ .get();
Assert.assertTrue("writeCheckpoint returned false",
- method("writeCheckpoint")
- .withReturnType(Boolean.class)
- .withParameterTypes(Boolean.class)
- .in(log)
- .invoke(true));
+ method("writeCheckpoint").withReturnType(Boolean.class)
+ .withParameterTypes(Boolean.class)
+ .in(log)
+ .invoke(true));
channel.stop();
}
public static class DummyEventVerifier implements EventValidator {
-
private int value = 0;
private DummyEventVerifier(int val) {
@@ -325,7 +320,6 @@ public class TestFileChannelIntegrityTool {
}
public static class Builder implements EventValidator.Builder {
-
private int binaryValidator = 0;
@Override
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 85c0dc8..b50693e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -672,9 +672,7 @@ limitations under the License.
<suppressionsLocation>flume/checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<encoding>UTF-8</encoding>
- <consoleOutput>true</consoleOutput>
- <failsOnError>true</failsOnError>
- <includeTestSourceDirectory>false</includeTestSourceDirectory>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
<linkXRef>false</linkXRef>
</configuration>
<goals>
@@ -1474,7 +1472,7 @@ limitations under the License.
<suppressionsLocation>flume/checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<encoding>UTF-8</encoding>
- <includeTestSourceDirectory>false</includeTestSourceDirectory>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
<linkXRef>false</linkXRef>
</configuration>
</plugin>
[3/9] flume git commit: FLUME-2941. Integrate checkstyle for test
classes
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sdk/src/test/java/org/apache/flume/api/ThriftTestingSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/api/ThriftTestingSource.java b/flume-ng-sdk/src/test/java/org/apache/flume/api/ThriftTestingSource.java
index 70d2c1b..724f093 100644
--- a/flume-ng-sdk/src/test/java/org/apache/flume/api/ThriftTestingSource.java
+++ b/flume-ng-sdk/src/test/java/org/apache/flume/api/ThriftTestingSource.java
@@ -67,8 +67,7 @@ public class ThriftTestingSource {
@Override
public Status append(ThriftFlumeEvent event) throws TException {
- flumeEvents.add(EventBuilder.withBody(event.getBody(),
- event.getHeaders()));
+ flumeEvents.add(EventBuilder.withBody(event.getBody(), event.getHeaders()));
individualCount++;
return Status.OK;
}
@@ -80,8 +79,7 @@ public class ThriftTestingSource {
incompleteBatches++;
}
for (ThriftFlumeEvent event : events) {
- flumeEvents.add(EventBuilder.withBody(event.getBody(),
- event.getHeaders()));
+ flumeEvents.add(EventBuilder.withBody(event.getBody(), event.getHeaders()));
}
return Status.OK;
}
@@ -175,8 +173,7 @@ public class ThriftTestingSource {
}
@Override
- public Status appendBatch(List<ThriftFlumeEvent> events) throws
- TException {
+ public Status appendBatch(List<ThriftFlumeEvent> events) throws TException {
try {
if (delay != null) {
TimeUnit.MILLISECONDS.sleep(delay.get());
@@ -207,8 +204,8 @@ public class ThriftTestingSource {
}
public ThriftTestingSource(String handlerName, int port, String protocol) throws Exception {
- TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(new
- InetSocketAddress("0.0.0.0", port));
+ TNonblockingServerTransport serverTransport =
+ new TNonblockingServerSocket(new InetSocketAddress("0.0.0.0", port));
ThriftSourceProtocol.Iface handler = getHandler(handlerName);
TProtocolFactory transportProtocolFactory = null;
@@ -217,10 +214,9 @@ public class ThriftTestingSource {
} else {
transportProtocolFactory = new TCompactProtocol.Factory();
}
- server = new THsHaServer(new THsHaServer.Args
- (serverTransport).processor(
- new ThriftSourceProtocol.Processor(handler)).protocolFactory(
- transportProtocolFactory));
+ server = new THsHaServer(new THsHaServer.Args(serverTransport).processor(
+ new ThriftSourceProtocol.Processor(handler)).protocolFactory(
+ transportProtocolFactory));
Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
@@ -260,10 +256,8 @@ public class ThriftTestingSource {
args.protocolFactory(transportProtocolFactory);
args.inputTransportFactory(new TFastFramedTransport.Factory());
args.outputTransportFactory(new TFastFramedTransport.Factory());
- args.processor(new ThriftSourceProtocol
- .Processor<ThriftSourceProtocol.Iface>(handler));
- server = (TServer) serverClass.getConstructor(argsClass).newInstance
- (args);
+ args.processor(new ThriftSourceProtocol.Processor<ThriftSourceProtocol.Iface>(handler));
+ server = (TServer) serverClass.getConstructor(argsClass).newInstance(args);
Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
@@ -285,5 +279,4 @@ public class ThriftTestingSource {
server.stop();
}
-
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-dataset-sink/src/test/java/org/apache/flume/sink/kite/TestDatasetSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-dataset-sink/src/test/java/org/apache/flume/sink/kite/TestDatasetSink.java b/flume-ng-sinks/flume-dataset-sink/src/test/java/org/apache/flume/sink/kite/TestDatasetSink.java
index 621920d..3709577 100644
--- a/flume-ng-sinks/flume-dataset-sink/src/test/java/org/apache/flume/sink/kite/TestDatasetSink.java
+++ b/flume-ng-sinks/flume-dataset-sink/src/test/java/org/apache/flume/sink/kite/TestDatasetSink.java
@@ -18,27 +18,12 @@
package org.apache.flume.sink.kite;
-import org.apache.flume.sink.kite.parser.EntityParser;
-import org.apache.flume.sink.kite.policy.FailurePolicy;
import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.URI;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import javax.annotation.Nullable;
import org.apache.avro.Schema;
import org.apache.avro.file.DataFileWriter;
import org.apache.avro.generic.GenericData;
@@ -57,6 +42,8 @@ import org.apache.flume.Transaction;
import org.apache.flume.channel.MemoryChannel;
import org.apache.flume.conf.Configurables;
import org.apache.flume.event.SimpleEvent;
+import org.apache.flume.sink.kite.parser.EntityParser;
+import org.apache.flume.sink.kite.policy.FailurePolicy;
import org.apache.flume.source.avro.AvroFlumeEvent;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
@@ -74,7 +61,28 @@ import org.kitesdk.data.DatasetWriter;
import org.kitesdk.data.Datasets;
import org.kitesdk.data.PartitionStrategy;
import org.kitesdk.data.View;
-import static org.mockito.Mockito.*;
+
+import javax.annotation.Nullable;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class TestDatasetSink {
@@ -206,7 +214,8 @@ public class TestDatasetSink {
}
@Test
- public void testFileStore() throws EventDeliveryException, NonRecoverableEventException, NonRecoverableEventException {
+ public void testFileStore()
+ throws EventDeliveryException, NonRecoverableEventException, NonRecoverableEventException {
DatasetSink sink = sink(in, config);
// run the sink
@@ -307,31 +316,28 @@ public class TestDatasetSink {
sink.process();
sink.stop();
- Assert.assertEquals(
- Sets.newHashSet(expected),
- read(Datasets.load(FILE_DATASET_URI)));
+ Assert.assertEquals(Sets.newHashSet(expected), read(Datasets.load(FILE_DATASET_URI)));
Assert.assertEquals("Should have committed", 0, remaining(in));
}
@Test
public void testDatasetUpdate() throws EventDeliveryException {
// add an updated record that is missing the msg field
- GenericRecordBuilder updatedBuilder = new GenericRecordBuilder(
- UPDATED_SCHEMA);
+ GenericRecordBuilder updatedBuilder = new GenericRecordBuilder(UPDATED_SCHEMA);
GenericData.Record updatedRecord = updatedBuilder
- .set("id", "0")
- .set("priority", 1)
- .set("msg", "Priority 1 message!")
- .build();
+ .set("id", "0")
+ .set("priority", 1)
+ .set("msg", "Priority 1 message!")
+ .build();
// make a set of the expected records with the new schema
Set<GenericRecord> expectedAsUpdated = Sets.newHashSet();
for (GenericRecord record : expected) {
expectedAsUpdated.add(updatedBuilder
- .clear("priority")
- .set("id", record.get("id"))
- .set("msg", record.get("msg"))
- .build());
+ .clear("priority")
+ .set("id", record.get("id"))
+ .set("msg", record.get("msg"))
+ .build());
}
expectedAsUpdated.add(updatedRecord);
@@ -343,9 +349,9 @@ public class TestDatasetSink {
// update the dataset's schema
DatasetDescriptor updated = new DatasetDescriptor
- .Builder(Datasets.load(FILE_DATASET_URI).getDataset().getDescriptor())
- .schema(UPDATED_SCHEMA)
- .build();
+ .Builder(Datasets.load(FILE_DATASET_URI).getDataset().getDescriptor())
+ .schema(UPDATED_SCHEMA)
+ .build();
Datasets.update(FILE_DATASET_URI, updated);
// trigger a roll on the next process call to refresh the writer
@@ -358,15 +364,12 @@ public class TestDatasetSink {
sink.process();
sink.stop();
- Assert.assertEquals(
- expectedAsUpdated,
- read(Datasets.load(FILE_DATASET_URI)));
+ Assert.assertEquals(expectedAsUpdated, read(Datasets.load(FILE_DATASET_URI)));
Assert.assertEquals("Should have committed", 0, remaining(in));
}
@Test
- public void testMiniClusterStore()
- throws EventDeliveryException, IOException {
+ public void testMiniClusterStore() throws EventDeliveryException, IOException {
// setup a minicluster
MiniDFSCluster cluster = new MiniDFSCluster
.Builder(new Configuration())
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/HDFSTestSeqWriter.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/HDFSTestSeqWriter.java b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/HDFSTestSeqWriter.java
index 9c1cd09..f1dadf1 100644
--- a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/HDFSTestSeqWriter.java
+++ b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/HDFSTestSeqWriter.java
@@ -19,25 +19,27 @@
package org.apache.flume.sink.hdfs;
-import java.io.IOException;
-
import org.apache.flume.Event;
import org.apache.hadoop.io.SequenceFile.CompressionType;
import org.apache.hadoop.io.compress.CompressionCodec;
+import java.io.IOException;
+
public class HDFSTestSeqWriter extends HDFSSequenceFile {
- protected volatile boolean closed, opened;
+ protected volatile boolean closed;
+ protected volatile boolean opened;
private int openCount = 0;
+
HDFSTestSeqWriter(int openCount) {
this.openCount = openCount;
}
@Override
- public void open(String filePath, CompressionCodec codeC,
- CompressionType compType) throws IOException {
+ public void open(String filePath, CompressionCodec codeC, CompressionType compType)
+ throws IOException {
super.open(filePath, codeC, compType);
- if(closed) {
+ if (closed) {
opened = true;
}
}
@@ -52,7 +54,7 @@ public class HDFSTestSeqWriter extends HDFSSequenceFile {
throw new IOException("Injected fault");
} else if (e.getHeaders().containsKey("fault-until-reopen")) {
// opening first time.
- if(openCount == 1) {
+ if (openCount == 1) {
throw new IOException("Injected fault-until-reopen");
}
} else if (e.getHeaders().containsKey("slow")) {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockDataStream.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockDataStream.java b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockDataStream.java
index f0c6e7e..a85a99f 100644
--- a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockDataStream.java
+++ b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockDataStream.java
@@ -30,9 +30,9 @@ class MockDataStream extends HDFSDataStream {
MockDataStream(FileSystem fs) {
this.fs = fs;
}
+
@Override
- protected FileSystem getDfs(Configuration conf,
- Path dstPath) throws IOException{
+ protected FileSystem getDfs(Configuration conf, Path dstPath) throws IOException {
return fs;
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFileSystem.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFileSystem.java b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFileSystem.java
index 4443335..a079b83 100644
--- a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFileSystem.java
+++ b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFileSystem.java
@@ -42,8 +42,7 @@ public class MockFileSystem extends FileSystem {
int currentRenameAttempts;
boolean closeSucceed = true;
- public MockFileSystem(FileSystem fs,
- int numberOfRetriesRequired) {
+ public MockFileSystem(FileSystem fs, int numberOfRetriesRequired) {
this.fs = fs;
this.numberOfRetriesRequired = numberOfRetriesRequired;
}
@@ -67,17 +66,14 @@ public class MockFileSystem extends FileSystem {
@Override
public FSDataOutputStream create(Path arg0) throws IOException {
- //throw new IOException ("HI there2");
- latestOutputStream = new MockFsDataOutputStream(
- fs.create(arg0), closeSucceed);
-
+ latestOutputStream = new MockFsDataOutputStream(fs.create(arg0), closeSucceed);
return latestOutputStream;
}
@Override
- public FSDataOutputStream create(Path arg0, FsPermission arg1,
- boolean arg2, int arg3, short arg4, long arg5, Progressable arg6)
- throws IOException {
+ public FSDataOutputStream create(Path arg0, FsPermission arg1, boolean arg2, int arg3,
+ short arg4, long arg5, Progressable arg6)
+ throws IOException {
throw new IOException("Not a real file system");
}
@@ -126,11 +122,9 @@ public class MockFileSystem extends FileSystem {
@Override
public boolean rename(Path arg0, Path arg1) throws IOException {
currentRenameAttempts++;
- logger.info(
- "Attempting to Rename: '" + currentRenameAttempts + "' of '" +
- numberOfRetriesRequired + "'");
- if (currentRenameAttempts >= numberOfRetriesRequired ||
- numberOfRetriesRequired == 0) {
+ logger.info("Attempting to Rename: '" + currentRenameAttempts + "' of '" +
+ numberOfRetriesRequired + "'");
+ if (currentRenameAttempts >= numberOfRetriesRequired || numberOfRetriesRequired == 0) {
logger.info("Renaming file");
return fs.rename(arg0, arg1);
} else {
@@ -141,6 +135,5 @@ public class MockFileSystem extends FileSystem {
@Override
public void setWorkingDirectory(Path arg0) {
fs.setWorkingDirectory(arg0);
-
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFsDataOutputStream.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFsDataOutputStream.java b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFsDataOutputStream.java
index 35b034e..f5d579c 100644
--- a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFsDataOutputStream.java
+++ b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockFsDataOutputStream.java
@@ -17,21 +17,20 @@
+ */
package org.apache.flume.sink.hdfs;
-import java.io.IOException;
-
import org.apache.hadoop.fs.FSDataOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class MockFsDataOutputStream extends FSDataOutputStream{
+import java.io.IOException;
+
+public class MockFsDataOutputStream extends FSDataOutputStream {
private static final Logger logger =
LoggerFactory.getLogger(MockFsDataOutputStream.class);
boolean closeSucceed;
- public MockFsDataOutputStream(FSDataOutputStream wrapMe,
- boolean closeSucceed)
+ public MockFsDataOutputStream(FSDataOutputStream wrapMe, boolean closeSucceed)
throws IOException {
super(wrapMe.getWrappedStream(), null);
this.closeSucceed = closeSucceed;
@@ -39,8 +38,7 @@ public class MockFsDataOutputStream extends FSDataOutputStream{
@Override
public void close() throws IOException {
- logger.info(
- "Close Succeeded - " + closeSucceed);
+ logger.info("Close Succeeded - " + closeSucceed);
if (closeSucceed) {
logger.info("closing file");
super.close();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockHDFSWriter.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockHDFSWriter.java b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockHDFSWriter.java
index ec49b97..05c4316 100644
--- a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockHDFSWriter.java
+++ b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/MockHDFSWriter.java
@@ -68,7 +68,8 @@ public class MockHDFSWriter implements HDFSWriter {
filesOpened++;
}
- public void open(String filePath, CompressionCodec codec, CompressionType cType) throws IOException {
+ public void open(String filePath, CompressionCodec codec, CompressionType cType)
+ throws IOException {
this.filePath = filePath;
filesOpened++;
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestBucketWriter.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestBucketWriter.java b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestBucketWriter.java
index 2581f73..742deb0 100644
--- a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestBucketWriter.java
+++ b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestBucketWriter.java
@@ -18,14 +18,7 @@
*/
package org.apache.flume.sink.hdfs;
-import java.io.File;
-import java.io.IOException;
-import java.util.Calendar;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
+import com.google.common.base.Charsets;
import org.apache.flume.Clock;
import org.apache.flume.Context;
import org.apache.flume.Event;
@@ -46,12 +39,17 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Charsets;
+import java.io.File;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
public class TestBucketWriter {
- private static Logger logger =
- LoggerFactory.getLogger(TestBucketWriter.class);
+ private static Logger logger = LoggerFactory.getLogger(TestBucketWriter.class);
private Context ctx = new Context();
private static ScheduledExecutorService timedRollerPool;
@@ -74,11 +72,11 @@ public class TestBucketWriter {
public void testEventCountingRoller() throws IOException, InterruptedException {
int maxEvents = 100;
MockHDFSWriter hdfsWriter = new MockHDFSWriter();
- BucketWriter bucketWriter = new BucketWriter(0, 0, maxEvents, 0, ctx,
- "/tmp", "file", "", ".tmp", null, null, SequenceFile.CompressionType.NONE,
- hdfsWriter, timedRollerPool, proxy,
- new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0,
- null, null, 30000, Executors.newSingleThreadExecutor(), 0, 0);
+ BucketWriter bucketWriter = new BucketWriter(
+ 0, 0, maxEvents, 0, ctx, "/tmp", "file", "", ".tmp", null, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
+ Executors.newSingleThreadExecutor(), 0, 0);
Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
for (int i = 0; i < 1000; i++) {
@@ -98,12 +96,11 @@ public class TestBucketWriter {
public void testSizeRoller() throws IOException, InterruptedException {
int maxBytes = 300;
MockHDFSWriter hdfsWriter = new MockHDFSWriter();
- BucketWriter bucketWriter = new BucketWriter(0, maxBytes, 0, 0,
- ctx, "/tmp", "file", "", ".tmp", null, null,
- SequenceFile.CompressionType.NONE, hdfsWriter,timedRollerPool,
- proxy, new SinkCounter("test-bucket-writer-" +
- System.currentTimeMillis()),0, null, null, 30000,
- Executors.newSingleThreadExecutor(), 0, 0);
+ BucketWriter bucketWriter = new BucketWriter(
+ 0, maxBytes, 0, 0, ctx, "/tmp", "file", "", ".tmp", null, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
+ Executors.newSingleThreadExecutor(), 0, 0);
Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
for (int i = 0; i < 1000; i++) {
@@ -126,16 +123,16 @@ public class TestBucketWriter {
final AtomicBoolean calledBack = new AtomicBoolean(false);
MockHDFSWriter hdfsWriter = new MockHDFSWriter();
- BucketWriter bucketWriter = new BucketWriter(ROLL_INTERVAL, 0, 0, 0, ctx,
- "/tmp", "file", "", ".tmp", null, null, SequenceFile.CompressionType.NONE,
- hdfsWriter, timedRollerPool, proxy,
- new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()),
- 0, new HDFSEventSink.WriterCallback() {
- @Override
- public void run(String filePath) {
- calledBack.set(true);
- }
- }, null, 30000, Executors.newSingleThreadExecutor(), 0, 0);
+ BucketWriter bucketWriter = new BucketWriter(
+ ROLL_INTERVAL, 0, 0, 0, ctx, "/tmp", "file", "", ".tmp", null, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0,
+ new HDFSEventSink.WriterCallback() {
+ @Override
+ public void run(String filePath) {
+ calledBack.set(true);
+ }
+ }, null, 30000, Executors.newSingleThreadExecutor(), 0, 0);
Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
long startNanos = System.nanoTime();
@@ -149,12 +146,11 @@ public class TestBucketWriter {
Assert.assertTrue(bucketWriter.closed);
Assert.assertTrue(calledBack.get());
- bucketWriter = new BucketWriter(ROLL_INTERVAL, 0, 0, 0, ctx,
- "/tmp", "file", "", ".tmp", null, null, SequenceFile.CompressionType.NONE,
- hdfsWriter, timedRollerPool, proxy,
- new SinkCounter("test-bucket-writer-"
- + System.currentTimeMillis()), 0, null, null, 30000,
- Executors.newSingleThreadExecutor(), 0, 0);
+ bucketWriter = new BucketWriter(
+ ROLL_INTERVAL, 0, 0, 0, ctx, "/tmp", "file", "", ".tmp", null, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
+ Executors.newSingleThreadExecutor(), 0, 0);
// write one more event (to reopen a new file so we will roll again later)
bucketWriter.append(e);
@@ -193,17 +189,16 @@ public class TestBucketWriter {
private volatile boolean open = false;
public void configure(Context context) {
-
}
public void sync() throws IOException {
- if(!open) {
+ if (!open) {
throw new IOException("closed");
}
}
- public void open(String filePath, CompressionCodec codec,
- CompressionType cType) throws IOException {
+ public void open(String filePath, CompressionCodec codec, CompressionType cType)
+ throws IOException {
open = true;
}
@@ -225,19 +220,18 @@ public class TestBucketWriter {
open = true;
}
};
+
HDFSTextSerializer serializer = new HDFSTextSerializer();
File tmpFile = File.createTempFile("flume", "test");
tmpFile.deleteOnExit();
String path = tmpFile.getParent();
String name = tmpFile.getName();
- BucketWriter bucketWriter = new BucketWriter(ROLL_INTERVAL, 0, 0,
- 0, ctx, path, name, "", ".tmp", null, null,
- SequenceFile.CompressionType.NONE, hdfsWriter,
- timedRollerPool, proxy, new SinkCounter("test-bucket-writer-"
- + System.currentTimeMillis()),
- 0, null, null, 30000, Executors.newSingleThreadExecutor(),
- 0, 0);
+ BucketWriter bucketWriter = new BucketWriter(
+ ROLL_INTERVAL, 0, 0, 0, ctx, path, name, "", ".tmp", null, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
+ Executors.newSingleThreadExecutor(), 0, 0);
Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
for (int i = 0; i < NUM_EVENTS - 1; i++) {
@@ -252,62 +246,61 @@ public class TestBucketWriter {
@Test
public void testFileSuffixNotGiven() throws IOException, InterruptedException {
- final int ROLL_INTERVAL = 1000; // seconds. Make sure it doesn't change in course of test
- final String suffix = null;
-
- MockHDFSWriter hdfsWriter = new MockHDFSWriter();
- BucketWriter bucketWriter = new BucketWriter(ROLL_INTERVAL, 0,
- 0, 0, ctx, "/tmp", "file", "", ".tmp", suffix, null,
- SequenceFile.CompressionType.NONE, hdfsWriter,
- timedRollerPool, proxy, new SinkCounter("test-bucket-writer-"
- + System.currentTimeMillis()), 0, null, null, 30000,
+ final int ROLL_INTERVAL = 1000; // seconds. Make sure it doesn't change in course of test
+ final String suffix = null;
+
+ MockHDFSWriter hdfsWriter = new MockHDFSWriter();
+ BucketWriter bucketWriter = new BucketWriter(
+ ROLL_INTERVAL, 0, 0, 0, ctx, "/tmp", "file", "", ".tmp", suffix, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
Executors.newSingleThreadExecutor(), 0, 0);
- // Need to override system time use for test so we know what to expect
- final long testTime = System.currentTimeMillis();
- Clock testClock = new Clock() {
- public long currentTimeMillis() {
- return testTime;
- }
- };
- bucketWriter.setClock(testClock);
+ // Need to override system time use for test so we know what to expect
+ final long testTime = System.currentTimeMillis();
+ Clock testClock = new Clock() {
+ public long currentTimeMillis() {
+ return testTime;
+ }
+ };
+ bucketWriter.setClock(testClock);
- Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
- bucketWriter.append(e);
+ Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
+ bucketWriter.append(e);
- Assert.assertTrue("Incorrect suffix", hdfsWriter.getOpenedFilePath().endsWith(Long.toString(testTime+1) + ".tmp"));
+ Assert.assertTrue("Incorrect suffix", hdfsWriter.getOpenedFilePath().endsWith(
+ Long.toString(testTime + 1) + ".tmp"));
}
- @Test
- public void testFileSuffixGiven() throws IOException, InterruptedException {
- final int ROLL_INTERVAL = 1000; // seconds. Make sure it doesn't change in course of test
- final String suffix = ".avro";
+ @Test
+ public void testFileSuffixGiven() throws IOException, InterruptedException {
+ final int ROLL_INTERVAL = 1000; // seconds. Make sure it doesn't change in course of test
+ final String suffix = ".avro";
- MockHDFSWriter hdfsWriter = new MockHDFSWriter();
- BucketWriter bucketWriter = new BucketWriter(ROLL_INTERVAL, 0,
- 0, 0, ctx, "/tmp", "file", "", ".tmp", suffix, null,
- SequenceFile.CompressionType.NONE, hdfsWriter,
- timedRollerPool, proxy, new SinkCounter(
- "test-bucket-writer-" + System.currentTimeMillis()), 0,
- null, null, 30000, Executors.newSingleThreadExecutor(), 0, 0);
+ MockHDFSWriter hdfsWriter = new MockHDFSWriter();
+ BucketWriter bucketWriter = new BucketWriter(
+ ROLL_INTERVAL, 0, 0, 0, ctx, "/tmp", "file", "", ".tmp", suffix, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
+ Executors.newSingleThreadExecutor(), 0, 0);
- // Need to override system time use for test so we know what to expect
+ // Need to override system time use for test so we know what to expect
- final long testTime = System.currentTimeMillis();
+ final long testTime = System.currentTimeMillis();
- Clock testClock = new Clock() {
- public long currentTimeMillis() {
- return testTime;
- }
- };
- bucketWriter.setClock(testClock);
+ Clock testClock = new Clock() {
+ public long currentTimeMillis() {
+ return testTime;
+ }
+ };
+ bucketWriter.setClock(testClock);
- Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
- bucketWriter.append(e);
+ Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
+ bucketWriter.append(e);
- Assert.assertTrue("Incorrect suffix", hdfsWriter.getOpenedFilePath().endsWith(
- Long.toString(testTime + 1) + suffix + ".tmp"));
- }
+ Assert.assertTrue("Incorrect suffix",hdfsWriter.getOpenedFilePath().endsWith(
+ Long.toString(testTime + 1) + suffix + ".tmp"));
+ }
@Test
public void testFileSuffixCompressed()
@@ -316,13 +309,11 @@ public class TestBucketWriter {
final String suffix = ".foo";
MockHDFSWriter hdfsWriter = new MockHDFSWriter();
- BucketWriter bucketWriter = new BucketWriter(ROLL_INTERVAL, 0, 0,
- 0, ctx, "/tmp", "file", "", ".tmp", suffix,
- HDFSEventSink.getCodec("gzip"),
- SequenceFile.CompressionType.BLOCK, hdfsWriter,
- timedRollerPool, proxy, new SinkCounter("test-bucket-writer-"
- + System.currentTimeMillis()), 0, null, null, 30000,
- Executors.newSingleThreadExecutor(), 0, 0
+ BucketWriter bucketWriter = new BucketWriter(
+ ROLL_INTERVAL, 0, 0, 0, ctx, "/tmp", "file", "", ".tmp", suffix,
+ HDFSEventSink.getCodec("gzip"), SequenceFile.CompressionType.BLOCK, hdfsWriter,
+ timedRollerPool, proxy, new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()),
+ 0, null, null, 30000, Executors.newSingleThreadExecutor(), 0, 0
);
// Need to override system time use for test so we know what to expect
@@ -338,8 +329,8 @@ public class TestBucketWriter {
Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
bucketWriter.append(e);
- Assert.assertTrue("Incorrect suffix",hdfsWriter.getOpenedFilePath()
- .endsWith(Long.toString(testTime+1) + suffix + ".tmp"));
+ Assert.assertTrue("Incorrect suffix", hdfsWriter.getOpenedFilePath().endsWith(
+ Long.toString(testTime + 1) + suffix + ".tmp"));
}
@Test
@@ -349,12 +340,11 @@ public class TestBucketWriter {
MockHDFSWriter hdfsWriter = new MockHDFSWriter();
HDFSTextSerializer formatter = new HDFSTextSerializer();
- BucketWriter bucketWriter = new BucketWriter(ROLL_INTERVAL, 0, 0,
- 0, ctx, "/tmp", "file", PREFIX, ".tmp", null, null,
- SequenceFile.CompressionType.NONE, hdfsWriter,
- timedRollerPool, proxy, new SinkCounter(
- "test-bucket-writer-" + System.currentTimeMillis()), 0,
- null, null, 30000, Executors.newSingleThreadExecutor(), 0, 0);
+ BucketWriter bucketWriter = new BucketWriter(
+ ROLL_INTERVAL, 0, 0, 0, ctx, "/tmp", "file", PREFIX, ".tmp", null, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
+ Executors.newSingleThreadExecutor(), 0, 0);
Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
bucketWriter.append(e);
@@ -369,12 +359,11 @@ public class TestBucketWriter {
MockHDFSWriter hdfsWriter = new MockHDFSWriter();
HDFSTextSerializer serializer = new HDFSTextSerializer();
- BucketWriter bucketWriter = new BucketWriter(ROLL_INTERVAL, 0, 0,
- 0, ctx, "/tmp", "file", "", SUFFIX, null, null,
- SequenceFile.CompressionType.NONE, hdfsWriter,
- timedRollerPool, proxy, new SinkCounter(
- "test-bucket-writer-" + System.currentTimeMillis()), 0,
- null, null, 30000, Executors.newSingleThreadExecutor(), 0, 0);
+ BucketWriter bucketWriter = new BucketWriter(
+ ROLL_INTERVAL, 0, 0, 0, ctx, "/tmp", "file", "", SUFFIX, null, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
+ Executors.newSingleThreadExecutor(), 0, 0);
Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
bucketWriter.append(e);
@@ -389,18 +378,16 @@ public class TestBucketWriter {
final AtomicBoolean callbackCalled = new AtomicBoolean(false);
MockHDFSWriter hdfsWriter = new MockHDFSWriter();
- BucketWriter bucketWriter = new BucketWriter(ROLL_INTERVAL, 0, 0,
- 0, ctx, "/tmp", "file", "", SUFFIX, null, null,
- SequenceFile.CompressionType.NONE,
- hdfsWriter, timedRollerPool, proxy,
- new SinkCounter(
- "test-bucket-writer-" + System.currentTimeMillis()), 0,
- new HDFSEventSink.WriterCallback() {
- @Override
- public void run(String filePath) {
- callbackCalled.set(true);
- }
- }, "blah", 30000, Executors.newSingleThreadExecutor(), 0, 0);
+ BucketWriter bucketWriter = new BucketWriter(
+ ROLL_INTERVAL, 0, 0, 0, ctx, "/tmp", "file", "", SUFFIX, null, null,
+ SequenceFile.CompressionType.NONE, hdfsWriter, timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0,
+ new HDFSEventSink.WriterCallback() {
+ @Override
+ public void run(String filePath) {
+ callbackCalled.set(true);
+ }
+ }, "blah", 30000, Executors.newSingleThreadExecutor(), 0, 0);
Event e = EventBuilder.withBody("foo", Charsets.UTF_8);
bucketWriter.append(e);
@@ -420,13 +407,13 @@ public class TestBucketWriter {
SequenceFileRenameRetryCoreTest(1, false);
SequenceFileRenameRetryCoreTest(5, false);
SequenceFileRenameRetryCoreTest(2, false);
-
}
- public void SequenceFileRenameRetryCoreTest(int numberOfRetriesRequired, boolean closeSucceed) throws Exception {
- String hdfsPath = "file:///tmp/flume-test."
- + Calendar.getInstance().getTimeInMillis() + "."
- + Thread.currentThread().getId();
+ public void SequenceFileRenameRetryCoreTest(int numberOfRetriesRequired, boolean closeSucceed)
+ throws Exception {
+ String hdfsPath = "file:///tmp/flume-test." +
+ Calendar.getInstance().getTimeInMillis() +
+ "." + Thread.currentThread().getId();
Context context = new Context();
Configuration conf = new Configuration();
@@ -435,22 +422,16 @@ public class TestBucketWriter {
fs.delete(dirPath, true);
fs.mkdirs(dirPath);
context.put("hdfs.path", hdfsPath);
- context.put("hdfs.closeTries",
- String.valueOf(numberOfRetriesRequired));
+ context.put("hdfs.closeTries", String.valueOf(numberOfRetriesRequired));
context.put("hdfs.rollCount", "1");
context.put("hdfs.retryInterval", "1");
context.put("hdfs.callTimeout", Long.toString(1000));
- MockFileSystem mockFs = new
- MockFileSystem(fs,
- numberOfRetriesRequired, closeSucceed);
- BucketWriter bucketWriter = new BucketWriter(0, 0, 1, 1, ctx,
- hdfsPath, hdfsPath, "singleBucket", ".tmp", null, null,
- null, new MockDataStream(mockFs),
- timedRollerPool, proxy,
- new SinkCounter(
- "test-bucket-writer-" + System.currentTimeMillis()),
- 0, null, null, 30000, Executors.newSingleThreadExecutor(), 1,
- numberOfRetriesRequired);
+ MockFileSystem mockFs = new MockFileSystem(fs, numberOfRetriesRequired, closeSucceed);
+ BucketWriter bucketWriter = new BucketWriter(
+ 0, 0, 1, 1, ctx, hdfsPath, hdfsPath, "singleBucket", ".tmp", null, null,
+ null, new MockDataStream(mockFs), timedRollerPool, proxy,
+ new SinkCounter("test-bucket-writer-" + System.currentTimeMillis()), 0, null, null, 30000,
+ Executors.newSingleThreadExecutor(), 1, numberOfRetriesRequired);
bucketWriter.setFileSystem(mockFs);
// At this point, we checked if isFileClosed is available in
@@ -463,8 +444,7 @@ public class TestBucketWriter {
TimeUnit.SECONDS.sleep(numberOfRetriesRequired + 2);
Assert.assertTrue("Expected " + numberOfRetriesRequired + " " +
- "but got " + bucketWriter.renameTries.get(),
- bucketWriter.renameTries.get() ==
- numberOfRetriesRequired);
+ "but got " + bucketWriter.renameTries.get(),
+ bucketWriter.renameTries.get() == numberOfRetriesRequired);
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestHDFSEventSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestHDFSEventSink.java b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestHDFSEventSink.java
index 23862eb..73f016b 100644
--- a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestHDFSEventSink.java
+++ b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestHDFSEventSink.java
@@ -71,7 +71,6 @@ import org.slf4j.LoggerFactory;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
-
public class TestHDFSEventSink {
private HDFSEventSink sink;
@@ -118,8 +117,7 @@ public class TestHDFSEventSink {
@After
public void tearDown() {
- if (System.getenv("hdfs_keepFiles") == null)
- dirCleanup();
+ if (System.getenv("hdfs_keepFiles") == null) dirCleanup();
}
@Test
@@ -176,7 +174,7 @@ public class TestHDFSEventSink {
List<String> bodies = Lists.newArrayList();
// push the event batches into channel to roll twice
- for (i = 1; i <= (rollCount*10)/batchSize; i++) {
+ for (i = 1; i <= (rollCount * 10) / batchSize; i++) {
Transaction txn = channel.getTransaction();
txn.begin();
for (j = 1; j <= batchSize; j++) {
@@ -200,7 +198,7 @@ public class TestHDFSEventSink {
// loop through all the files generated and check their contains
FileStatus[] dirStat = fs.listStatus(dirPath);
- Path fList[] = FileUtil.stat2Paths(dirStat);
+ Path[] fList = FileUtil.stat2Paths(dirStat);
// check that the roll happened correctly for the given data
long expectedFiles = totalEvents / rollCount;
@@ -353,7 +351,7 @@ public class TestHDFSEventSink {
// loop through all the files generated and check their contains
FileStatus[] dirStat = fs.listStatus(dirPath);
- Path fList[] = FileUtil.stat2Paths(dirStat);
+ Path[] fList = FileUtil.stat2Paths(dirStat);
// check that the roll happened correctly for the given data
long expectedFiles = totalEvents / rollCount;
@@ -432,7 +430,7 @@ public class TestHDFSEventSink {
// loop through all the files generated and check their contains
FileStatus[] dirStat = fs.listStatus(dirPath);
- Path fList[] = FileUtil.stat2Paths(dirStat);
+ Path[] fList = FileUtil.stat2Paths(dirStat);
// check that the roll happened correctly for the given data
long expectedFiles = totalEvents / rollCount;
@@ -508,7 +506,7 @@ public class TestHDFSEventSink {
// loop through all the files generated and check their contains
FileStatus[] dirStat = fs.listStatus(dirPath);
- Path fList[] = FileUtil.stat2Paths(dirStat);
+ Path[] fList = FileUtil.stat2Paths(dirStat);
// check that the roll happened correctly for the given data
long expectedFiles = totalEvents / rollCount;
@@ -519,8 +517,8 @@ public class TestHDFSEventSink {
}
@Test
- public void testSimpleAppendLocalTime() throws InterruptedException,
- LifecycleException, EventDeliveryException, IOException {
+ public void testSimpleAppendLocalTime()
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
final long currentTime = System.currentTimeMillis();
Clock clk = new Clock() {
@Override
@@ -536,7 +534,7 @@ public class TestHDFSEventSink {
final int numBatches = 4;
String newPath = testPath + "/singleBucket/%s" ;
String expectedPath = testPath + "/singleBucket/" +
- String.valueOf(currentTime/1000);
+ String.valueOf(currentTime / 1000);
int totalEvents = 0;
int i = 1, j = 1;
@@ -576,7 +574,7 @@ public class TestHDFSEventSink {
eventDate.clear();
eventDate.set(2011, i, i, i, 0); // yy mm dd
event.getHeaders().put("timestamp",
- String.valueOf(eventDate.getTimeInMillis()));
+ String.valueOf(eventDate.getTimeInMillis()));
event.getHeaders().put("hostname", "Host" + i);
String body = "Test." + i + "." + j;
event.setBody(body.getBytes());
@@ -595,13 +593,13 @@ public class TestHDFSEventSink {
// loop through all the files generated and check their contains
FileStatus[] dirStat = fs.listStatus(dirPath);
- Path fList[] = FileUtil.stat2Paths(dirStat);
+ Path[] fList = FileUtil.stat2Paths(dirStat);
// check that the roll happened correctly for the given data
long expectedFiles = totalEvents / rollCount;
if (totalEvents % rollCount > 0) expectedFiles++;
Assert.assertEquals("num files wrong, found: " +
- Lists.newArrayList(fList), expectedFiles, fList.length);
+ Lists.newArrayList(fList), expectedFiles, fList.length);
verifyOutputSequenceFiles(fs, conf, dirPath.toUri().getPath(), fileName, bodies);
// The clock in bucketpath is static, so restore the real clock
sink.setBucketClock(new SystemClock());
@@ -750,10 +748,10 @@ public class TestHDFSEventSink {
private List<String> getAllFiles(String input) {
List<String> output = Lists.newArrayList();
File dir = new File(input);
- if(dir.isFile()) {
+ if (dir.isFile()) {
output.add(dir.getAbsolutePath());
- } else if(dir.isDirectory()) {
- for(String file : dir.list()) {
+ } else if (dir.isDirectory()) {
+ for (String file : dir.list()) {
File subDir = new File(dir, file);
output.addAll(getAllFiles(subDir.getAbsolutePath()));
}
@@ -761,16 +759,17 @@ public class TestHDFSEventSink {
return output;
}
- private void verifyOutputSequenceFiles(FileSystem fs, Configuration conf, String dir, String prefix, List<String> bodies) throws IOException {
+ private void verifyOutputSequenceFiles(FileSystem fs, Configuration conf, String dir,
+ String prefix, List<String> bodies) throws IOException {
int found = 0;
int expected = bodies.size();
- for(String outputFile : getAllFiles(dir)) {
+ for (String outputFile : getAllFiles(dir)) {
String name = (new File(outputFile)).getName();
- if(name.startsWith(prefix)) {
+ if (name.startsWith(prefix)) {
SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(outputFile), conf);
LongWritable key = new LongWritable();
BytesWritable value = new BytesWritable();
- while(reader.next(key, value)) {
+ while (reader.next(key, value)) {
String body = new String(value.getBytes(), 0, value.getLength());
if (bodies.contains(body)) {
LOG.debug("Found event body: {}", body);
@@ -792,16 +791,17 @@ public class TestHDFSEventSink {
}
- private void verifyOutputTextFiles(FileSystem fs, Configuration conf, String dir, String prefix, List<String> bodies) throws IOException {
+ private void verifyOutputTextFiles(FileSystem fs, Configuration conf, String dir, String prefix,
+ List<String> bodies) throws IOException {
int found = 0;
int expected = bodies.size();
- for(String outputFile : getAllFiles(dir)) {
+ for (String outputFile : getAllFiles(dir)) {
String name = (new File(outputFile)).getName();
- if(name.startsWith(prefix)) {
+ if (name.startsWith(prefix)) {
FSDataInputStream input = fs.open(new Path(outputFile));
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String body = null;
- while((body = reader.readLine()) != null) {
+ while ((body = reader.readLine()) != null) {
bodies.remove(body);
found++;
}
@@ -814,12 +814,13 @@ public class TestHDFSEventSink {
}
- private void verifyOutputAvroFiles(FileSystem fs, Configuration conf, String dir, String prefix, List<String> bodies) throws IOException {
+ private void verifyOutputAvroFiles(FileSystem fs, Configuration conf, String dir, String prefix,
+ List<String> bodies) throws IOException {
int found = 0;
int expected = bodies.size();
- for(String outputFile : getAllFiles(dir)) {
+ for (String outputFile : getAllFiles(dir)) {
String name = (new File(outputFile)).getName();
- if(name.startsWith(prefix)) {
+ if (name.startsWith(prefix)) {
FSDataInputStream input = fs.open(new Path(outputFile));
DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
DataFileStream<GenericRecord> avroStream =
@@ -840,7 +841,7 @@ public class TestHDFSEventSink {
}
Assert.assertTrue("Found = " + found + ", Expected = " +
expected + ", Left = " + bodies.size() + " " + bodies,
- bodies.size() == 0);
+ bodies.size() == 0);
}
/**
@@ -849,9 +850,9 @@ public class TestHDFSEventSink {
* This relies on Transactional rollback semantics for durability and
* the behavior of the BucketWriter class of close()ing upon IOException.
*/
- @Test
- public void testCloseReopen() throws InterruptedException,
- LifecycleException, EventDeliveryException, IOException {
+ @Test
+ public void testCloseReopen()
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
LOG.debug("Starting...");
final int numBatches = 4;
@@ -924,8 +925,8 @@ public class TestHDFSEventSink {
* a new one is used for the next set of events.
*/
@Test
- public void testCloseReopenOnRollTime() throws InterruptedException,
- LifecycleException, EventDeliveryException, IOException {
+ public void testCloseReopenOnRollTime()
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
LOG.debug("Starting...");
final int numBatches = 4;
@@ -973,7 +974,7 @@ public class TestHDFSEventSink {
eventDate.clear();
eventDate.set(2011, i, i, i, 0); // yy mm dd
event.getHeaders().put("timestamp",
- String.valueOf(eventDate.getTimeInMillis()));
+ String.valueOf(eventDate.getTimeInMillis()));
event.getHeaders().put("hostname", "Host" + i);
String body = "Test." + i + "." + j;
event.setBody(body.getBytes());
@@ -997,9 +998,9 @@ public class TestHDFSEventSink {
Assert.assertTrue(badWriterFactory.openCount.get() >= 2);
LOG.info("Total number of bucket writers opened: {}",
- badWriterFactory.openCount.get());
+ badWriterFactory.openCount.get());
verifyOutputSequenceFiles(fs, conf, dirPath.toUri().getPath(), fileName,
- bodies);
+ bodies);
}
/**
@@ -1007,8 +1008,8 @@ public class TestHDFSEventSink {
* sfWriters map.
*/
@Test
- public void testCloseRemovesFromSFWriters() throws InterruptedException,
- LifecycleException, EventDeliveryException, IOException {
+ public void testCloseRemovesFromSFWriters()
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
LOG.debug("Starting...");
final String fileName = "FlumeData";
@@ -1055,7 +1056,7 @@ public class TestHDFSEventSink {
eventDate.clear();
eventDate.set(2011, i, i, i, 0); // yy mm dd
event.getHeaders().put("timestamp",
- String.valueOf(eventDate.getTimeInMillis()));
+ String.valueOf(eventDate.getTimeInMillis()));
event.getHeaders().put("hostname", "Host" + i);
String body = "Test." + i + "." + j;
event.setBody(body.getBytes());
@@ -1080,9 +1081,9 @@ public class TestHDFSEventSink {
sink.stop();
LOG.info("Total number of bucket writers opened: {}",
- badWriterFactory.openCount.get());
+ badWriterFactory.openCount.get());
verifyOutputSequenceFiles(fs, conf, dirPath.toUri().getPath(), fileName,
- bodies);
+ bodies);
}
@@ -1163,8 +1164,9 @@ public class TestHDFSEventSink {
* append using slow sink writer with specified append timeout
* verify that the data is written correctly to files
*/
- private void slowAppendTestHelper (long appendTimeout) throws InterruptedException, IOException,
- LifecycleException, EventDeliveryException, IOException {
+ private void slowAppendTestHelper(long appendTimeout)
+ throws InterruptedException, IOException, LifecycleException, EventDeliveryException,
+ IOException {
final String fileName = "FlumeData";
final long rollCount = 5;
final long batchSize = 2;
@@ -1230,7 +1232,7 @@ public class TestHDFSEventSink {
// loop through all the files generated and check their contains
FileStatus[] dirStat = fs.listStatus(dirPath);
- Path fList[] = FileUtil.stat2Paths(dirStat);
+ Path[] fList = FileUtil.stat2Paths(dirStat);
// check that the roll happened correctly for the given data
// Note that we'll end up with two files with only a head
@@ -1292,7 +1294,7 @@ public class TestHDFSEventSink {
Transaction txn = channel.getTransaction();
txn.begin();
- for(int i=0; i < 10; i++) {
+ for (int i = 0; i < 10; i++) {
Event event = new SimpleEvent();
event.setBody(("test event " + i).getBytes());
channel.put(event);
@@ -1317,9 +1319,9 @@ public class TestHDFSEventSink {
FileStatus[] dirStat = fs.listStatus(dirPath);
Path[] fList = FileUtil.stat2Paths(dirStat);
Assert.assertEquals("Incorrect content of the directory " + StringUtils.join(fList, ","),
- 2, fList.length);
+ 2, fList.length);
Assert.assertTrue(!fList[0].getName().endsWith(".tmp") &&
- !fList[1].getName().endsWith(".tmp"));
+ !fList[1].getName().endsWith(".tmp"));
fs.close();
}
@@ -1338,8 +1340,7 @@ public class TestHDFSEventSink {
}
@Test
- public void testBadConfigurationForRetryIntervalZero() throws
- Exception {
+ public void testBadConfigurationForRetryIntervalZero() throws Exception {
Context context = getContextForRetryTests();
context.put("hdfs.retryInterval", "0");
@@ -1348,43 +1349,41 @@ public class TestHDFSEventSink {
}
@Test
- public void testBadConfigurationForRetryIntervalNegative() throws
- Exception {
+ public void testBadConfigurationForRetryIntervalNegative() throws Exception {
Context context = getContextForRetryTests();
context.put("hdfs.retryInterval", "-1");
Configurables.configure(sink, context);
Assert.assertEquals(1, sink.getTryCount());
}
+
@Test
- public void testBadConfigurationForRetryCountZero() throws
- Exception {
+ public void testBadConfigurationForRetryCountZero() throws Exception {
Context context = getContextForRetryTests();
context.put("hdfs.closeTries" ,"0");
Configurables.configure(sink, context);
Assert.assertEquals(Integer.MAX_VALUE, sink.getTryCount());
}
+
@Test
- public void testBadConfigurationForRetryCountNegative() throws
- Exception {
+ public void testBadConfigurationForRetryCountNegative() throws Exception {
Context context = getContextForRetryTests();
context.put("hdfs.closeTries" ,"-4");
Configurables.configure(sink, context);
Assert.assertEquals(Integer.MAX_VALUE, sink.getTryCount());
}
+
@Test
- public void testRetryRename() throws InterruptedException,
- LifecycleException,
- EventDeliveryException, IOException {
+ public void testRetryRename()
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
testRetryRename(true);
testRetryRename(false);
}
- private void testRetryRename(boolean closeSucceed) throws InterruptedException,
- LifecycleException,
- EventDeliveryException, IOException {
+ private void testRetryRename(boolean closeSucceed)
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
LOG.debug("Starting...");
String newPath = testPath + "/retryBucket";
@@ -1441,8 +1440,8 @@ public class TestHDFSEventSink {
Collection<BucketWriter> writers = sink.getSfWriters().values();
int totalRenameAttempts = 0;
- for(BucketWriter writer: writers) {
- LOG.info("Rename tries = "+ writer.renameTries.get());
+ for (BucketWriter writer : writers) {
+ LOG.info("Rename tries = " + writer.renameTries.get());
totalRenameAttempts += writer.renameTries.get();
}
// stop clears the sfWriters map, so we need to compute the
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestSequenceFileSerializerFactory.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestSequenceFileSerializerFactory.java b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestSequenceFileSerializerFactory.java
index 6381edc..974e857 100644
--- a/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestSequenceFileSerializerFactory.java
+++ b/flume-ng-sinks/flume-hdfs-sink/src/test/java/org/apache/flume/sink/hdfs/TestSequenceFileSerializerFactory.java
@@ -47,8 +47,7 @@ public class TestSequenceFileSerializerFactory {
@Test
public void getCustomFormatter() {
- SequenceFileSerializer formatter = SequenceFileSerializerFactory
- .getSerializer(
+ SequenceFileSerializer formatter = SequenceFileSerializerFactory.getSerializer(
"org.apache.flume.sink.hdfs.MyCustomSerializer$Builder", new Context());
assertTrue(formatter != null);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveSink.java b/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveSink.java
index 46724f2..c417404 100644
--- a/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveSink.java
+++ b/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveSink.java
@@ -55,8 +55,8 @@ import java.util.UUID;
public class TestHiveSink {
// 1) partitioned table
- final static String dbName = "testing";
- final static String tblName = "alerts";
+ static final String dbName = "testing";
+ static final String tblName = "alerts";
public static final String PART1_NAME = "continent";
public static final String PART2_NAME = "country";
@@ -72,8 +72,8 @@ public class TestHiveSink {
private final ArrayList<String> partitionVals;
// 2) un-partitioned table
- final static String dbName2 = "testing2";
- final static String tblName2 = "alerts2";
+ static final String dbName2 = "testing2";
+ static final String tblName2 = "alerts2";
final String[] colNames2 = {COL1,COL2};
private String[] colTypes2 = { "int", "string" };
@@ -88,7 +88,6 @@ public class TestHiveSink {
@Rule
public TemporaryFolder dbFolder = new TemporaryFolder();
-
private static final Logger LOG = LoggerFactory.getLogger(HiveSink.class);
public TestHiveSink() throws Exception {
@@ -182,8 +181,8 @@ public class TestHiveSink {
TestUtil.dropDB(conf, dbName2);
String dbLocation = dbFolder.newFolder(dbName2).getCanonicalPath() + ".db";
dbLocation = dbLocation.replaceAll("\\\\","/"); // for windows paths
- TestUtil.createDbAndTable(driver, dbName2, tblName2, null, colNames2, colTypes2
- , null, dbLocation);
+ TestUtil.createDbAndTable(driver, dbName2, tblName2, null, colNames2, colTypes2,
+ null, dbLocation);
try {
int totalRecords = 4;
@@ -282,7 +281,7 @@ public class TestHiveSink {
String body = j + ",blah,This is a log message,other stuff";
event.setBody(body.getBytes());
eventDate.clear();
- eventDate.set(2014, 03, 03, j%batchCount, 1); // yy mm dd hh mm
+ eventDate.set(2014, 03, 03, j % batchCount, 1); // yy mm dd hh mm
event.getHeaders().put( "timestamp",
String.valueOf(eventDate.getTimeInMillis()) );
event.getHeaders().put( PART1_NAME, "Asia" );
@@ -317,7 +316,7 @@ public class TestHiveSink {
throws EventDeliveryException, IOException, CommandNeedRetryException {
int batchSize = 2;
int batchCount = 3;
- int totalRecords = batchCount*batchSize;
+ int totalRecords = batchCount * batchSize;
Context context = new Context();
context.put("hive.metastore", metaStoreURI);
context.put("hive.database", dbName);
@@ -340,7 +339,7 @@ public class TestHiveSink {
txn.begin();
for (int j = 1; j <= batchSize; j++) {
Event event = new SimpleEvent();
- String body = i*j + ",blah,This is a log message,other stuff";
+ String body = i * j + ",blah,This is a log message,other stuff";
event.setBody(body.getBytes());
bodies.add(body);
channel.put(event);
@@ -361,7 +360,7 @@ public class TestHiveSink {
public void testJsonSerializer() throws Exception {
int batchSize = 2;
int batchCount = 2;
- int totalRecords = batchCount*batchSize;
+ int totalRecords = batchCount * batchSize;
Context context = new Context();
context.put("hive.metastore",metaStoreURI);
context.put("hive.database",dbName);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveWriter.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveWriter.java b/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveWriter.java
index 41bf0f6..4d7c9bb 100644
--- a/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveWriter.java
+++ b/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestHiveWriter.java
@@ -42,8 +42,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class TestHiveWriter {
- final static String dbName = "testing";
- final static String tblName = "alerts";
+ static final String dbName = "testing";
+ static final String tblName = "alerts";
public static final String PART1_NAME = "continent";
public static final String PART2_NAME = "country";
@@ -106,8 +106,8 @@ public class TestHiveWriter {
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);
+ TestUtil.createDbAndTable(driver, dbName, tblName, partVals, colNames, colTypes, partNames,
+ dbLocation);
// 2) Setup serializer
Context ctx = new Context();
@@ -120,8 +120,8 @@ public class TestHiveWriter {
public void testInstantiate() throws Exception {
HiveEndPoint endPoint = new HiveEndPoint(metaStoreURI, dbName, tblName, partVals);
SinkCounter sinkCounter = new SinkCounter(this.getClass().getName());
- HiveWriter writer = new HiveWriter(endPoint, 10, true, timeout
- , callTimeoutPool, "flumetest", serializer, sinkCounter);
+ HiveWriter writer = new HiveWriter(endPoint, 10, true, timeout, callTimeoutPool, "flumetest",
+ serializer, sinkCounter);
writer.close();
}
@@ -130,8 +130,8 @@ public class TestHiveWriter {
public void testWriteBasic() throws Exception {
HiveEndPoint endPoint = new HiveEndPoint(metaStoreURI, dbName, tblName, partVals);
SinkCounter sinkCounter = new SinkCounter(this.getClass().getName());
- HiveWriter writer = new HiveWriter(endPoint, 10, true, timeout
- , callTimeoutPool, "flumetest", serializer, sinkCounter);
+ HiveWriter writer = new HiveWriter(endPoint, 10, true, timeout, callTimeoutPool, "flumetest",
+ serializer, sinkCounter);
writeEvents(writer,3);
writer.flush(false);
@@ -144,8 +144,8 @@ public class TestHiveWriter {
HiveEndPoint endPoint = new HiveEndPoint(metaStoreURI, dbName, tblName, partVals);
SinkCounter sinkCounter = new SinkCounter(this.getClass().getName());
- HiveWriter writer = new HiveWriter(endPoint, 10, true, timeout
- , callTimeoutPool, "flumetest", serializer, sinkCounter);
+ HiveWriter writer = new HiveWriter(endPoint, 10, true, timeout, callTimeoutPool, "flumetest",
+ serializer, sinkCounter);
checkRecordCountInTable(0);
SimpleEvent event = new SimpleEvent();
@@ -184,8 +184,8 @@ public class TestHiveWriter {
int txnPerBatch = 3;
- HiveWriter writer = new HiveWriter(endPoint, txnPerBatch, true, timeout
- , callTimeoutPool, "flumetest", serializer, sinkCounter);
+ HiveWriter writer = new HiveWriter(endPoint, txnPerBatch, true, timeout, callTimeoutPool,
+ "flumetest", serializer, sinkCounter);
Assert.assertEquals(writer.getRemainingTxns(),2);
writer.flush(true);
@@ -275,14 +275,13 @@ public class TestHiveWriter {
ctx.put("serializer.serdeSeparator", "ab");
try {
serializer3.configure(ctx);
- Assert.assertTrue("Bad serdeSeparator character was accepted" ,false);
- } catch (Exception e){
+ Assert.assertTrue("Bad serdeSeparator character was accepted", false);
+ } catch (Exception e) {
// expect an exception
}
}
-
@Test
public void testSecondWriterBeforeFirstCommits() throws Exception {
// here we open a new writer while the first is still writing (not committed)
@@ -295,13 +294,13 @@ public class TestHiveWriter {
SinkCounter sinkCounter1 = new SinkCounter(this.getClass().getName());
SinkCounter sinkCounter2 = new SinkCounter(this.getClass().getName());
- HiveWriter writer1 = new HiveWriter(endPoint1, 10, true, timeout
- , callTimeoutPool, "flumetest", serializer, sinkCounter1);
+ HiveWriter writer1 = new HiveWriter(endPoint1, 10, true, timeout, callTimeoutPool, "flumetest",
+ serializer, sinkCounter1);
writeEvents(writer1, 3);
- HiveWriter writer2 = new HiveWriter(endPoint2, 10, true, timeout
- , callTimeoutPool, "flumetest", serializer, sinkCounter2);
+ HiveWriter writer2 = new HiveWriter(endPoint2, 10, true, timeout, callTimeoutPool, "flumetest",
+ serializer, sinkCounter2);
writeEvents(writer2, 3);
writer2.flush(false); // commit
@@ -311,7 +310,6 @@ public class TestHiveWriter {
writer2.close();
}
-
@Test
public void testSecondWriterAfterFirstCommits() throws Exception {
// here we open a new writer after the first writer has committed one txn
@@ -324,16 +322,16 @@ public class TestHiveWriter {
SinkCounter sinkCounter1 = new SinkCounter(this.getClass().getName());
SinkCounter sinkCounter2 = new SinkCounter(this.getClass().getName());
- HiveWriter writer1 = new HiveWriter(endPoint1, 10, true, timeout
- , callTimeoutPool, "flumetest", serializer, sinkCounter1);
+ HiveWriter writer1 = new HiveWriter(endPoint1, 10, true, timeout, callTimeoutPool, "flumetest",
+ serializer, sinkCounter1);
writeEvents(writer1, 3);
writer1.flush(false); // commit
- HiveWriter writer2 = new HiveWriter(endPoint2, 10, true, timeout
- , callTimeoutPool, "flumetest", serializer, sinkCounter2);
+ HiveWriter writer2 = new HiveWriter(endPoint2, 10, true, timeout, callTimeoutPool, "flumetest",
+ serializer, sinkCounter2);
writeEvents(writer2, 3);
writer2.flush(false); // commit
@@ -342,8 +340,8 @@ public class TestHiveWriter {
writer2.close();
}
-
- private void writeEvents(HiveWriter writer, int count) throws InterruptedException, HiveWriter.WriteException {
+ private void writeEvents(HiveWriter writer, int count)
+ throws InterruptedException, HiveWriter.WriteException {
SimpleEvent event = new SimpleEvent();
for (int i = 1; i <= count; i++) {
event.setBody((i + ",xyz,Hello world,abc").getBytes());
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestUtil.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestUtil.java b/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestUtil.java
index 107789f..1fcb4eb 100644
--- a/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestUtil.java
+++ b/flume-ng-sinks/flume-hive-sink/src/test/java/org/apache/flume/sink/hive/TestUtil.java
@@ -46,7 +46,7 @@ import java.util.List;
public class TestUtil {
- private final static String txnMgr = "org.apache.hadoop.hive.ql.lockmgr.DbTxnManager";
+ private static final String txnMgr = "org.apache.hadoop.hive.ql.lockmgr.DbTxnManager";
/**
* Set up the configuration so it will use the DbTxnManager, concurrency will be set to true,
@@ -81,7 +81,7 @@ public class TestUtil {
runDDL(driver, crtTbl);
System.out.println("crtTbl = " + crtTbl);
- if (partNames!=null && partNames.length!=0) {
+ if (partNames != null && partNames.length != 0) {
String addPart = "alter table " + tableName + " add partition ( " +
getTablePartsStr2(partNames, partVals) + " )";
runDDL(driver, addPart);
@@ -96,7 +96,8 @@ public class TestUtil {
}
// delete db and all tables in it
- public static void dropDB(HiveConf conf, String databaseName) throws HiveException, MetaException {
+ public static void dropDB(HiveConf conf, String databaseName)
+ throws HiveException, MetaException {
IMetaStoreClient client = new HiveMetaStoreClient(conf);
try {
for (String table : client.listTableNamesByFilter(databaseName, "", (short)-1)) {
@@ -110,9 +111,9 @@ public class TestUtil {
private static String getTableColumnsStr(String[] colNames, String[] colTypes) {
StringBuffer sb = new StringBuffer();
- for (int i=0; i < colNames.length; ++i) {
+ for (int i = 0; i < colNames.length; ++i) {
sb.append(colNames[i] + " " + colTypes[i]);
- if (i<colNames.length-1) {
+ if (i < colNames.length - 1) {
sb.append(",");
}
}
@@ -121,13 +122,13 @@ public class TestUtil {
// converts partNames into "partName1 string, partName2 string"
private static String getTablePartsStr(String[] partNames) {
- if (partNames==null || partNames.length==0) {
+ if (partNames == null || partNames.length == 0) {
return "";
}
StringBuffer sb = new StringBuffer();
- for (int i=0; i < partNames.length; ++i) {
+ for (int i = 0; i < partNames.length; ++i) {
sb.append(partNames[i] + " string");
- if (i < partNames.length-1) {
+ if (i < partNames.length - 1) {
sb.append(",");
}
}
@@ -137,9 +138,9 @@ public class TestUtil {
// converts partNames,partVals into "partName1=val1, partName2=val2"
private static String getTablePartsStr2(String[] partNames, List<String> partVals) {
StringBuffer sb = new StringBuffer();
- for (int i=0; i < partVals.size(); ++i) {
+ for (int i = 0; i < partVals.size(); ++i) {
sb.append(partNames[i] + " = '" + partVals.get(i) + "'");
- if (i < partVals.size()-1) {
+ if (i < partVals.size() - 1) {
sb.append(",");
}
}
@@ -147,7 +148,7 @@ public class TestUtil {
}
public static ArrayList<String> listRecordsInTable(Driver driver, String dbName, String tblName)
- throws CommandNeedRetryException, IOException {
+ throws CommandNeedRetryException, IOException {
driver.run("select * from " + dbName + "." + tblName);
ArrayList<String> res = new ArrayList<String>();
driver.getResults(res);
@@ -155,8 +156,9 @@ public class TestUtil {
}
public static ArrayList<String> listRecordsInPartition(Driver driver, String dbName,
- String tblName, String continent, String country)
- throws CommandNeedRetryException, IOException {
+ String tblName, String continent,
+ String country)
+ throws CommandNeedRetryException, IOException {
driver.run("select * from " + dbName + "." + tblName + " where continent='"
+ continent + "' and country='" + country + "'");
ArrayList<String> res = new ArrayList<String>();
@@ -164,9 +166,9 @@ public class TestUtil {
return res;
}
-
public static class RawFileSystem extends RawLocalFileSystem {
private static final URI NAME;
+
static {
try {
NAME = new URI("raw:///");
@@ -211,9 +213,10 @@ public class TestUtil {
FsPermission.createImmutable(mod), "owen", "users", path);
}
}
+
private static boolean runDDL(Driver driver, String sql) throws QueryFailedException {
int retryCount = 1; // # of times to retry if first attempt fails
- for (int attempt=0; attempt <= retryCount; ++attempt) {
+ for (int attempt = 0; attempt <= retryCount; ++attempt) {
try {
driver.run(sql);
return true;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-irc-sink/src/test/java/org/apache/flume/sink/irc/TestIRCSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-irc-sink/src/test/java/org/apache/flume/sink/irc/TestIRCSink.java b/flume-ng-sinks/flume-irc-sink/src/test/java/org/apache/flume/sink/irc/TestIRCSink.java
index e6c065e..32517d1 100644
--- a/flume-ng-sinks/flume-irc-sink/src/test/java/org/apache/flume/sink/irc/TestIRCSink.java
+++ b/flume-ng-sinks/flume-irc-sink/src/test/java/org/apache/flume/sink/irc/TestIRCSink.java
@@ -19,7 +19,12 @@ package org.apache.flume.sink.irc;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
-import org.apache.flume.*;
+import org.apache.flume.Channel;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.flume.EventDeliveryException;
+import org.apache.flume.Sink;
+import org.apache.flume.Transaction;
import org.apache.flume.channel.MemoryChannel;
import org.apache.flume.conf.Configurables;
import org.apache.flume.event.EventBuilder;
@@ -116,7 +121,9 @@ public class TestIRCSink {
try {
Socket socket = ss.accept();
process(socket);
- } catch (Exception ex) {/* noop */ }
+ } catch (Exception ex) {
+ /* noop */
+ }
}
} catch (IOException e) {
// noop
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/AbstractElasticSearchSinkTest.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/AbstractElasticSearchSinkTest.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/AbstractElasticSearchSinkTest.java
index f9272fa..9fbd747 100644
--- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/AbstractElasticSearchSinkTest.java
+++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/AbstractElasticSearchSinkTest.java
@@ -18,17 +18,6 @@
*/
package org.apache.flume.sink.elasticsearch;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.BATCH_SIZE;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.CLUSTER_NAME;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.INDEX_NAME;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.INDEX_TYPE;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.TTL;
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Map;
-
import org.apache.flume.Channel;
import org.apache.flume.Context;
import org.apache.flume.Event;
@@ -51,6 +40,17 @@ import org.joda.time.DateTimeUtils;
import org.junit.After;
import org.junit.Before;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Map;
+
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.BATCH_SIZE;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.CLUSTER_NAME;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.INDEX_NAME;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.INDEX_TYPE;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.TTL;
+import static org.junit.Assert.assertEquals;
+
public abstract class AbstractElasticSearchSinkTest {
static final String DEFAULT_INDEX_NAME = "flume";
@@ -136,7 +136,8 @@ public abstract class AbstractElasticSearchSinkTest {
.setTypes(DEFAULT_INDEX_TYPE).setQuery(query).execute().actionGet();
}
- void assertSearch(int expectedHits, SearchResponse response, Map<String, Object> expectedBody, Event... events) {
+ void assertSearch(int expectedHits, SearchResponse response, Map<String, Object> expectedBody,
+ Event... events) {
SearchHits hitResponse = response.getHits();
assertEquals(expectedHits, hitResponse.getTotalHits());
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchIndexRequestBuilderFactory.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchIndexRequestBuilderFactory.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchIndexRequestBuilderFactory.java
index 8022111..b62254e 100644
--- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchIndexRequestBuilderFactory.java
+++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchIndexRequestBuilderFactory.java
@@ -18,15 +18,7 @@
*/
package org.apache.flume.sink.elasticsearch;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.Map;
-
+import com.google.common.collect.Maps;
import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.conf.ComponentConfiguration;
@@ -39,7 +31,14 @@ import org.elasticsearch.common.io.FastByteArrayOutputStream;
import org.junit.Before;
import org.junit.Test;
-import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.util.Map;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class TestElasticSearchIndexRequestBuilderFactory
extends AbstractElasticSearchSinkTest {
@@ -70,7 +69,7 @@ public class TestElasticSearchIndexRequestBuilderFactory
@Test
public void indexNameShouldBePrefixDashFormattedTimestamp() {
long millis = 987654321L;
- assertEquals("prefix-"+factory.fastDateFormat.format(millis),
+ assertEquals("prefix-" + factory.fastDateFormat.format(millis),
factory.getIndexName("prefix", millis));
}
@@ -135,7 +134,7 @@ public class TestElasticSearchIndexRequestBuilderFactory
assertEquals(indexPrefix + '-'
+ ElasticSearchIndexRequestBuilderFactory.df.format(FIXED_TIME_MILLIS),
- indexRequestBuilder.request().index());
+ indexRequestBuilder.request().index());
assertEquals(indexType, indexRequestBuilder.request().type());
assertArrayEquals(FakeEventSerializer.FAKE_BYTES,
indexRequestBuilder.request().source().array());
@@ -154,7 +153,7 @@ public class TestElasticSearchIndexRequestBuilderFactory
assertEquals(indexPrefix + '-'
+ ElasticSearchIndexRequestBuilderFactory.df.format(1213141516L),
- indexRequestBuilder.request().index());
+ indexRequestBuilder.request().index());
}
@Test
@@ -174,7 +173,7 @@ public class TestElasticSearchIndexRequestBuilderFactory
assertEquals(indexValue + '-'
+ ElasticSearchIndexRequestBuilderFactory.df.format(FIXED_TIME_MILLIS),
- indexRequestBuilder.request().index());
+ indexRequestBuilder.request().index());
assertEquals(typeValue, indexRequestBuilder.request().type());
}
@@ -192,7 +191,8 @@ public class TestElasticSearchIndexRequestBuilderFactory
static class FakeEventSerializer implements ElasticSearchEventSerializer {
static final byte[] FAKE_BYTES = new byte[]{9, 8, 7, 6};
- boolean configuredWithContext, configuredWithComponentConfiguration;
+ boolean configuredWithContext;
+ boolean configuredWithComponentConfiguration;
@Override
public BytesStream getContentBuilder(Event event) throws IOException {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java
index ab9587d..65b4dab 100644
--- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java
+++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchLogStashEventSerializer.java
@@ -18,6 +18,7 @@
*/
package org.apache.flume.sink.elasticsearch;
+import com.google.gson.JsonParser;
import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.event.EventBuilder;
@@ -28,9 +29,6 @@ import org.junit.Test;
import java.util.Date;
import java.util.Map;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonElement;
-
import static org.apache.flume.sink.elasticsearch.ElasticSearchEventSerializer.charset;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.junit.Assert.assertEquals;
@@ -56,26 +54,25 @@ public class TestElasticSearchLogStashEventSerializer {
Event event = EventBuilder.withBody(message.getBytes(charset));
event.setHeaders(headers);
- XContentBuilder expected = jsonBuilder()
- .startObject();
- expected.field("@message", new String(message.getBytes(), charset));
- expected.field("@timestamp", new Date(timestamp));
- expected.field("@source", "flume_tail_src");
- expected.field("@type", "sometype");
- expected.field("@source_host", "test@localhost");
- expected.field("@source_path", "/tmp/test");
-
- expected.startObject("@fields");
- expected.field("timestamp", String.valueOf(timestamp));
- expected.field("src_path", "/tmp/test");
- expected.field("host", "test@localhost");
- expected.field("headerNameTwo", "headerValueTwo");
- expected.field("source", "flume_tail_src");
- expected.field("headerNameOne", "headerValueOne");
- expected.field("type", "sometype");
- expected.endObject();
-
- expected.endObject();
+ XContentBuilder expected = jsonBuilder().startObject();
+ expected.field("@message", new String(message.getBytes(), charset));
+ expected.field("@timestamp", new Date(timestamp));
+ expected.field("@source", "flume_tail_src");
+ expected.field("@type", "sometype");
+ expected.field("@source_host", "test@localhost");
+ expected.field("@source_path", "/tmp/test");
+
+ expected.startObject("@fields");
+ expected.field("timestamp", String.valueOf(timestamp));
+ expected.field("src_path", "/tmp/test");
+ expected.field("host", "test@localhost");
+ expected.field("headerNameTwo", "headerValueTwo");
+ expected.field("source", "flume_tail_src");
+ expected.field("headerNameOne", "headerValueOne");
+ expected.field("type", "sometype");
+ expected.endObject();
+
+ expected.endObject();
XContentBuilder actual = fixture.getContentBuilder(event);
@@ -102,26 +99,25 @@ public class TestElasticSearchLogStashEventSerializer {
Event event = EventBuilder.withBody(message.getBytes(charset));
event.setHeaders(headers);
- XContentBuilder expected = jsonBuilder().
- startObject();
- expected.field("@message", new String(message.getBytes(), charset));
- expected.field("@timestamp", new Date(timestamp));
- expected.field("@source", "flume_tail_src");
- expected.field("@type", "sometype");
- expected.field("@source_host", "test@localhost");
- expected.field("@source_path", "/tmp/test");
-
- expected.startObject("@fields");
- expected.field("timestamp", String.valueOf(timestamp));
- expected.field("src_path", "/tmp/test");
- expected.field("host", "test@localhost");
- expected.field("headerNameTwo", "headerValueTwo");
- expected.field("source", "flume_tail_src");
- expected.field("headerNameOne", "headerValueOne");
- expected.field("type", "sometype");
- expected.endObject();
-
- expected.endObject();
+ XContentBuilder expected = jsonBuilder().startObject();
+ expected.field("@message", new String(message.getBytes(), charset));
+ expected.field("@timestamp", new Date(timestamp));
+ expected.field("@source", "flume_tail_src");
+ expected.field("@type", "sometype");
+ expected.field("@source_host", "test@localhost");
+ expected.field("@source_path", "/tmp/test");
+
+ expected.startObject("@fields");
+ expected.field("timestamp", String.valueOf(timestamp));
+ expected.field("src_path", "/tmp/test");
+ expected.field("host", "test@localhost");
+ expected.field("headerNameTwo", "headerValueTwo");
+ expected.field("source", "flume_tail_src");
+ expected.field("headerNameOne", "headerValueOne");
+ expected.field("type", "sometype");
+ expected.endObject();
+
+ expected.endObject();
XContentBuilder actual = fixture.getContentBuilder(event);
[9/9] flume git commit: FLUME-2941. Integrate checkstyle for test
classes
Posted by mp...@apache.org.
FLUME-2941. Integrate checkstyle for test classes
Also make test code conform to style guidelines.
Additionally, this patch makes style violations fatal to the build.
This patch is whitespace-only from a code perspective. After stripping
line numbers, the generated test bytecode before and after these changes
is identical.
Code review: https://reviews.apache.org/r/49830/
Reviewed by Hari.
Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/cfbf1156
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/cfbf1156
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/cfbf1156
Branch: refs/heads/trunk
Commit: cfbf1156858af9ae26975fefc94594d91c8cd3f4
Parents: c8c0f9b
Author: Mike Percy <mp...@apache.org>
Authored: Wed Jun 29 21:18:20 2016 -0700
Committer: Mike Percy <mp...@apache.org>
Committed: Fri Jul 8 15:48:26 2016 -0700
----------------------------------------------------------------------
flume-checkstyle/pom.xml | 8 -
.../resources/flume/checkstyle-suppressions.xml | 18 +-
.../src/main/resources/flume/checkstyle.xml | 2 +-
.../flume/auth/TestFlumeAuthenticator.java | 16 +-
.../flume/channel/file/CountingSinkRunner.java | 22 +-
.../channel/file/CountingSourceRunner.java | 21 +-
.../flume/channel/file/TestCheckpoint.java | 4 +-
.../file/TestEventQueueBackingStoreFactory.java | 140 ++++---
.../flume/channel/file/TestEventUtils.java | 4 +-
.../flume/channel/file/TestFileChannel.java | 139 ++++---
.../file/TestFileChannelFormatRegression.java | 21 +-
.../channel/file/TestFileChannelRestart.java | 208 +++++-----
.../channel/file/TestFileChannelRollback.java | 16 +-
.../flume/channel/file/TestFlumeEventQueue.java | 200 +++++-----
.../flume/channel/file/TestIntegration.java | 33 +-
.../org/apache/flume/channel/file/TestLog.java | 308 +++++++++------
.../apache/flume/channel/file/TestLogFile.java | 153 ++++----
.../file/TestTransactionEventRecordV2.java | 10 +-
.../file/TestTransactionEventRecordV3.java | 34 +-
.../apache/flume/channel/file/TestUtils.java | 122 +++---
.../encryption/CipherProviderTestSuite.java | 5 +
.../file/encryption/EncryptionTestUtils.java | 95 +++--
.../encryption/TestAESCTRNoPaddingProvider.java | 10 +-
.../encryption/TestFileChannelEncryption.java | 98 +++--
.../file/encryption/TestJCEFileKeyProvider.java | 69 ++--
.../jdbc/BaseJdbcChannelProviderTest.java | 28 +-
.../apache/flume/channel/jdbc/MockEvent.java | 3 +-
.../flume/channel/jdbc/MockEventUtils.java | 22 +-
.../jdbc/TestDerbySchemaHandlerQueries.java | 2 -
.../flume/channel/kafka/TestKafkaChannel.java | 67 ++--
.../channel/TestSpillableMemoryChannel.java | 386 +++++++++----------
.../TestLoadBalancingLog4jAppender.java | 51 ++-
.../log4jappender/TestLog4jAppender.java | 32 +-
.../TestLog4jAppenderWithAvro.java | 5 +-
.../AbstractBasicChannelSemanticsTest.java | 7 +-
.../flume/channel/TestChannelProcessor.java | 32 +-
.../apache/flume/channel/TestMemoryChannel.java | 40 +-
.../channel/TestMemoryChannelConcurrency.java | 100 ++---
.../channel/TestMemoryChannelTransaction.java | 12 +-
.../TestReliableSpoolingFileEventReader.java | 201 +++++-----
.../flume/formatter/output/TestBucketPath.java | 52 +--
.../TestMonitoredCounterGroup.java | 50 +--
.../http/TestHTTPMetricsServer.java | 24 +-
.../kafka/KafkaSourceCounterTest.java | 78 ++--
...gexExtractorInterceptorMillisSerializer.java | 10 +-
...tractorInterceptorPassThroughSerializer.java | 3 +-
.../TestSearchAndReplaceInterceptor.java | 2 +-
.../SyslogAvroEventSerializer.java | 45 ++-
.../TestAvroEventDeserializer.java | 1 +
.../TestDurablePositionTracker.java | 3 +-
.../TestFlumeEventAvroEventSerializer.java | 24 +-
.../TestResettableFileInputStream.java | 26 +-
.../TestSyslogAvroEventSerializer.java | 2 +-
.../org/apache/flume/sink/TestAvroSink.java | 87 ++---
.../flume/sink/TestDefaultSinkFactory.java | 3 +-
.../flume/sink/TestFailoverSinkProcessor.java | 10 +-
.../sink/TestLoadBalancingSinkProcessor.java | 60 ++-
.../apache/flume/sink/TestRollingFileSink.java | 30 +-
.../org/apache/flume/sink/TestThriftSink.java | 11 +-
.../source/TestAbstractPollableSource.java | 24 +-
.../org/apache/flume/source/TestAvroSource.java | 34 +-
.../org/apache/flume/source/TestExecSource.java | 336 ++++++++--------
.../source/TestMultiportSyslogTCPSource.java | 1 +
.../apache/flume/source/TestNetcatSource.java | 79 ++--
.../source/TestSequenceGeneratorSource.java | 8 +-
.../flume/source/TestSpoolDirectorySource.java | 42 +-
.../apache/flume/source/TestStressSource.java | 2 +-
.../apache/flume/source/TestSyslogParser.java | 12 +-
.../flume/source/TestSyslogTcpSource.java | 12 +-
.../flume/source/TestSyslogUdpSource.java | 19 +-
.../apache/flume/source/TestSyslogUtils.java | 162 ++++----
.../apache/flume/source/TestThriftSource.java | 29 +-
.../http/FlumeHttpServletRequestWrapper.java | 4 +-
.../flume/source/http/TestHTTPSource.java | 153 ++++----
.../flume/tools/TestTimestampRoundDownUtil.java | 10 +-
.../org/apache/flume/tools/TestVersionInfo.java | 4 +-
.../flume/agent/embedded/TestEmbeddedAgent.java | 24 +-
.../TestEmbeddedAgentConfiguration.java | 18 +-
.../TestEmbeddedAgentEmbeddedSource.java | 15 +-
.../agent/embedded/TestEmbeddedAgentState.java | 30 +-
.../source/avroLegacy/TestLegacyAvroSource.java | 27 +-
.../thriftLegacy/TestThriftLegacySource.java | 30 +-
.../node/TestAbstractConfigurationProvider.java | 71 ++--
...tAbstractZooKeeperConfigurationProvider.java | 25 +-
.../org/apache/flume/node/TestApplication.java | 2 +-
...lingPropertiesFileConfigurationProvider.java | 1 -
...TestPropertiesFileConfigurationProvider.java | 24 +-
.../apache/flume/source/TestNetcatSource.java | 38 +-
.../java/org/apache/flume/api/RpcTestUtils.java | 77 ++--
.../apache/flume/api/TestFailoverRpcClient.java | 4 +-
.../flume/api/TestLoadBalancingRpcClient.java | 107 ++---
.../flume/api/TestNettyAvroRpcClient.java | 26 +-
.../apache/flume/api/TestThriftRpcClient.java | 41 +-
.../apache/flume/api/ThriftTestingSource.java | 27 +-
.../apache/flume/sink/kite/TestDatasetSink.java | 79 ++--
.../flume/sink/hdfs/HDFSTestSeqWriter.java | 16 +-
.../apache/flume/sink/hdfs/MockDataStream.java | 4 +-
.../apache/flume/sink/hdfs/MockFileSystem.java | 23 +-
.../flume/sink/hdfs/MockFsDataOutputStream.java | 12 +-
.../apache/flume/sink/hdfs/MockHDFSWriter.java | 3 +-
.../flume/sink/hdfs/TestBucketWriter.java | 274 ++++++-------
.../flume/sink/hdfs/TestHDFSEventSink.java | 127 +++---
.../hdfs/TestSequenceFileSerializerFactory.java | 3 +-
.../apache/flume/sink/hive/TestHiveSink.java | 21 +-
.../apache/flume/sink/hive/TestHiveWriter.java | 50 ++-
.../org/apache/flume/sink/hive/TestUtil.java | 33 +-
.../org/apache/flume/sink/irc/TestIRCSink.java | 11 +-
.../AbstractElasticSearchSinkTest.java | 25 +-
...ElasticSearchIndexRequestBuilderFactory.java | 30 +-
...estElasticSearchLogStashEventSerializer.java | 82 ++--
.../elasticsearch/TestElasticSearchSink.java | 52 +--
.../TestElasticSearchSinkCreation.java | 2 +-
.../client/RoundRobinListTest.java | 3 +-
.../client/TestElasticSearchClientFactory.java | 10 +-
.../client/TestElasticSearchRestClient.java | 35 +-
.../hbase/IncrementAsyncHBaseSerializer.java | 6 +-
.../flume/sink/hbase/TestAsyncHBaseSink.java | 114 +++---
.../apache/flume/sink/hbase/TestHBaseSink.java | 129 ++++---
.../hbase/TestRegexHbaseEventSerializer.java | 37 +-
.../apache/flume/sink/kafka/TestKafkaSink.java | 89 ++---
.../flume/sink/kafka/util/KafkaLocal.java | 57 ++-
.../flume/sink/kafka/util/ZooKeeperLocal.java | 75 ++--
.../solr/morphline/TestBlobDeserializer.java | 10 +-
.../morphline/TestMorphlineInterceptor.java | 57 +--
.../solr/morphline/TestMorphlineSolrSink.java | 19 +-
.../source/jms/JMSMessageConsumerTestBase.java | 13 +-
.../jms/TestDefaultJMSMessageConverter.java | 2 +-
.../source/jms/TestIntegrationActiveMQ.java | 23 +-
.../source/jms/TestJMSMessageConsumer.java | 3 +-
.../apache/flume/source/jms/TestJMSSource.java | 53 ++-
.../source/kafka/KafkaSourceEmbeddedKafka.java | 11 +-
.../kafka/KafkaSourceEmbeddedZookeeper.java | 1 -
.../flume/source/kafka/TestKafkaSource.java | 152 ++++----
.../source/taildir/TestTaildirEventReader.java | 36 +-
.../source/taildir/TestTaildirMatcher.java | 57 ++-
.../flume/source/taildir/TestTaildirSource.java | 38 +-
.../flume/test/agent/TestFileChannel.java | 178 ++++-----
.../apache/flume/test/util/StagedInstall.java | 39 +-
.../org/apache/flume/test/util/SyslogAgent.java | 9 +-
.../tools/TestFileChannelIntegrityTool.java | 54 ++-
pom.xml | 6 +-
141 files changed, 3523 insertions(+), 3423 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-checkstyle/pom.xml
----------------------------------------------------------------------
diff --git a/flume-checkstyle/pom.xml b/flume-checkstyle/pom.xml
index 31db3c0..74ebf6b 100644
--- a/flume-checkstyle/pom.xml
+++ b/flume-checkstyle/pom.xml
@@ -21,14 +21,6 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <!--
- <parent>
- <artifactId>flume-parent</artifactId>
- <groupId>org.apache.flume</groupId>
- <version>1.7.0-SNAPSHOT</version>
- </parent>
- -->
-
<groupId>org.apache.flume</groupId>
<artifactId>flume-checkstyle</artifactId>
<name>Flume checkstyle project</name>
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-checkstyle/src/main/resources/flume/checkstyle-suppressions.xml
----------------------------------------------------------------------
diff --git a/flume-checkstyle/src/main/resources/flume/checkstyle-suppressions.xml b/flume-checkstyle/src/main/resources/flume/checkstyle-suppressions.xml
index 49c8834..2642baa 100644
--- a/flume-checkstyle/src/main/resources/flume/checkstyle-suppressions.xml
+++ b/flume-checkstyle/src/main/resources/flume/checkstyle-suppressions.xml
@@ -12,21 +12,29 @@
<suppress checks="PackageName"
files="org/apache/flume/source/avroLegacy|org/apache/flume/source/thriftLegacy"/>
+ <!-- Allow unicode escapes in tests -->
+ <suppress checks="AvoidEscapedUnicodeCharacters"
+ files="Test.*\.java"/>
+
<!-- TODO: Rearrange methods in below classes to keep overloaded methods adjacent -->
<suppress checks="OverloadMethodsDeclarationOrder"
- files="channel/file|RpcClientFactory\.java|BucketPath\.java|SinkGroup\.java|DefaultSinkProcessor\.java|RegexExtractorInterceptorMillisSerializer\.java|SimpleAsyncHbaseEventSerializer\.java|hdfs/BucketWriter\.java"/>
+ files="channel/file|RpcClientFactory\.java|BucketPath\.java|SinkGroup\.java|DefaultSinkProcessor\.java|RegexExtractorInterceptorMillisSerializer\.java|SimpleAsyncHbaseEventSerializer\.java|hdfs/BucketWriter\.java|AbstractBasicChannelSemanticsTest\.java"/>
<!-- TODO: Fix inner class names to follow standard convention -->
<suppress checks="TypeName"
files="SyslogUDPSource\.java|SyslogTcpSource\.java|TaildirSource\.java"/>
+ <!-- TODO: Method names must follow standard Java naming conventions -->
+ <suppress checks="MethodNameCheck"
+ files="TestBucketWriter\.java|TestSyslogUtils\.java"/>
+
<!-- TODO: Add default cases to switch statements -->
<suppress checks="MissingSwitchDefault"
- files="SyslogUtils\.java|ReliableTaildirEventReader\.java"/>
+ files="SyslogUtils\.java|ReliableTaildirEventReader\.java|AbstractBasicChannelSemanticsTest\.java"/>
<!-- TODO: Avoid empty catch blocks -->
<suppress checks="EmptyCatchBlock"
- files="channel/file/LogFile\.java"/>
+ files="channel/file/LogFile\.java|TestDatasetSink\.java|CountingSourceRunner\.java|CountingSinkRunner\.java|TestKafkaChannel\.java|TestTaildirSource\.java|TestChannelProcessor\.java|TestHiveSink\.java|AbstractBasicChannelSemanticsTest\.java|TestJMSSource\.java|TestEmbeddedAgent\.java|TestAsyncHBaseSink\.java"/>
<!-- TODO: Avoid empty if blocks -->
<suppress checks="EmptyBlockCheck"
@@ -34,10 +42,10 @@
<!-- TODO: Fix line length issues -->
<suppress checks="LineLengthCheck"
- files="channel/MemoryChannel\.java|ReliableSpoolingFileEventReader\.java"/>
+ files="channel/MemoryChannel\.java|ReliableSpoolingFileEventReader\.java|TestAvroSink\.java"/>
<!-- TODO: Move helper classes to their own files -->
<suppress checks="OneTopLevelClass"
- files="KafkaSource\.java|KafkaChannel\.java|KafkaSink\.java"/>
+ files="KafkaSource\.java|KafkaChannel\.java|KafkaSink\.java|TestElasticSearchSink\.java"/>
</suppressions>
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-checkstyle/src/main/resources/flume/checkstyle.xml
----------------------------------------------------------------------
diff --git a/flume-checkstyle/src/main/resources/flume/checkstyle.xml b/flume-checkstyle/src/main/resources/flume/checkstyle.xml
index e8913f0..fdbcb5d 100644
--- a/flume-checkstyle/src/main/resources/flume/checkstyle.xml
+++ b/flume-checkstyle/src/main/resources/flume/checkstyle.xml
@@ -18,7 +18,7 @@
<module name = "Checker">
<property name="charset" value="UTF-8"/>
- <property name="severity" value="warning"/>
+ <property name="severity" value="error"/>
<property name="fileExtensions" value="java, properties, xml"/>
<!-- Checks for whitespace -->
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-auth/src/test/java/org/apache/flume/auth/TestFlumeAuthenticator.java
----------------------------------------------------------------------
diff --git a/flume-ng-auth/src/test/java/org/apache/flume/auth/TestFlumeAuthenticator.java b/flume-ng-auth/src/test/java/org/apache/flume/auth/TestFlumeAuthenticator.java
index 5a8860d..0dc8872 100644
--- a/flume-ng-auth/src/test/java/org/apache/flume/auth/TestFlumeAuthenticator.java
+++ b/flume-ng-auth/src/test/java/org/apache/flume/auth/TestFlumeAuthenticator.java
@@ -17,15 +17,19 @@
*/
package org.apache.flume.auth;
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
import org.apache.hadoop.minikdc.MiniKdc;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class TestFlumeAuthenticator {
@@ -132,7 +136,7 @@ public class TestFlumeAuthenticator {
String principal = "flume";
File keytab = new File(workDir, "flume2.keytab");
kdc.createPrincipal(keytab, principal);
- String expResult = principal+"@" + kdc.getRealm();
+ String expResult = principal + "@" + kdc.getRealm();
// Clear the previous statically stored logged in credentials
FlumeAuthenticationUtil.clearCredentials();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSinkRunner.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSinkRunner.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSinkRunner.java
index 0733dc4..a303994 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSinkRunner.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSinkRunner.java
@@ -18,11 +18,10 @@
*/
package org.apache.flume.channel.file;
-import java.util.List;
-
+import com.google.common.collect.Lists;
import org.apache.flume.Sink;
-import com.google.common.collect.Lists;
+import java.util.List;
public class CountingSinkRunner extends Thread {
private int count;
@@ -30,39 +29,46 @@ public class CountingSinkRunner extends Thread {
private final Sink sink;
private volatile boolean run;
private final List<Exception> errors = Lists.newArrayList();
+
public CountingSinkRunner(Sink sink) {
this(sink, Integer.MAX_VALUE);
}
+
public CountingSinkRunner(Sink sink, int until) {
this.sink = sink;
this.until = until;
}
+
@Override
public void run() {
run = true;
- while(run && count < until) {
+ while (run && count < until) {
boolean error = true;
try {
- if(Sink.Status.READY.equals(sink.process())) {
+ if (Sink.Status.READY.equals(sink.process())) {
count++;
error = false;
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
errors.add(ex);
}
- if(error) {
+ if (error) {
try {
Thread.sleep(1000L);
- } catch (InterruptedException e) {}
+ } catch (InterruptedException e) {
+ }
}
}
}
+
public void shutdown() {
run = false;
}
+
public int getCount() {
return count;
}
+
public List<Exception> getErrors() {
return errors;
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSourceRunner.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSourceRunner.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSourceRunner.java
index b6abc35..1119990 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSourceRunner.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/CountingSourceRunner.java
@@ -33,19 +33,23 @@ public class CountingSourceRunner extends Thread {
private final PollableSource source;
private volatile boolean run;
private final List<Exception> errors = Lists.newArrayList();
+
public CountingSourceRunner(PollableSource source) {
this(source, Integer.MAX_VALUE);
}
+
public CountingSourceRunner(PollableSource source, int until) {
this(source, until, null);
}
+
public CountingSourceRunner(PollableSource source, Channel channel) {
this(source, Integer.MAX_VALUE, channel);
}
+
public CountingSourceRunner(PollableSource source, int until, Channel channel) {
this.source = source;
this.until = until;
- if(channel != null) {
+ if (channel != null) {
ReplicatingChannelSelector selector = new ReplicatingChannelSelector();
List<Channel> channels = Lists.newArrayList();
channels.add(channel);
@@ -53,32 +57,37 @@ public class CountingSourceRunner extends Thread {
this.source.setChannelProcessor(new ChannelProcessor(selector));
}
}
+
@Override
public void run() {
run = true;
- while(run && count < until) {
+ while (run && count < until) {
boolean error = true;
try {
- if(PollableSource.Status.READY.equals(source.process())) {
+ if (PollableSource.Status.READY.equals(source.process())) {
count++;
error = false;
}
- } catch(Exception ex) {
+ } catch (Exception ex) {
errors.add(ex);
}
- if(error) {
+ if (error) {
try {
Thread.sleep(1000L);
- } catch (InterruptedException e) {}
+ } catch (InterruptedException e) {
+ }
}
}
}
+
public void shutdown() {
run = false;
}
+
public int getCount() {
return count;
}
+
public List<Exception> getErrors() {
return errors;
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestCheckpoint.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestCheckpoint.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestCheckpoint.java
index c1de12e..cd1dcd9 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestCheckpoint.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestCheckpoint.java
@@ -28,11 +28,11 @@ import org.junit.Before;
import org.junit.Test;
public class TestCheckpoint {
-
File file;
File inflightPuts;
File inflightTakes;
File queueSet;
+
@Before
public void setup() throws IOException {
file = File.createTempFile("Checkpoint", "");
@@ -42,10 +42,12 @@ public class TestCheckpoint {
Assert.assertTrue(file.isFile());
Assert.assertTrue(file.canWrite());
}
+
@After
public void cleanup() {
file.delete();
}
+
@Test
public void testSerialization() throws Exception {
EventQueueBackingStore backingStore =
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventQueueBackingStoreFactory.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventQueueBackingStoreFactory.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventQueueBackingStoreFactory.java
index 52c706d..0939454 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventQueueBackingStoreFactory.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventQueueBackingStoreFactory.java
@@ -18,31 +18,29 @@
*/
package org.apache.flume.channel.file;
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+import com.google.protobuf.InvalidProtocolBufferException;
import junit.framework.Assert;
-
import org.apache.commons.io.FileUtils;
+import org.apache.flume.channel.file.proto.ProtosFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import com.google.common.collect.Lists;
-import com.google.common.io.Files;
-import com.google.protobuf.InvalidProtocolBufferException;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.RandomAccessFile;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import java.util.Random;
-import org.apache.flume.channel.file.proto.ProtosFactory;
public class TestEventQueueBackingStoreFactory {
- static final List<Long> pointersInTestCheckpoint = Arrays.asList(new Long[] {
+ static final List<Long> pointersInTestCheckpoint = Arrays.asList(new Long[]{
8589936804L,
4294969563L,
12884904153L,
@@ -59,6 +57,7 @@ public class TestEventQueueBackingStoreFactory {
File inflightTakes;
File inflightPuts;
File queueSetDir;
+
@Before
public void setup() throws IOException {
baseDir = Files.createTempDir();
@@ -67,42 +66,46 @@ public class TestEventQueueBackingStoreFactory {
inflightPuts = new File(baseDir, "puts");
queueSetDir = new File(baseDir, "queueset");
TestUtils.copyDecompressed("fileformat-v2-checkpoint.gz", checkpoint);
-
}
+
@After
public void teardown() {
FileUtils.deleteQuietly(baseDir);
}
+
@Test
public void testWithNoFlag() throws Exception {
verify(EventQueueBackingStoreFactory.get(checkpoint, 10, "test"),
- Serialization.VERSION_3, pointersInTestCheckpoint);
+ Serialization.VERSION_3, pointersInTestCheckpoint);
}
+
@Test
public void testWithFlag() throws Exception {
verify(EventQueueBackingStoreFactory.get(checkpoint, 10, "test", true),
- Serialization.VERSION_3, pointersInTestCheckpoint);
+ Serialization.VERSION_3, pointersInTestCheckpoint);
}
+
@Test
public void testNoUprade() throws Exception {
verify(EventQueueBackingStoreFactory.get(checkpoint, 10, "test", false),
- Serialization.VERSION_2, pointersInTestCheckpoint);
+ Serialization.VERSION_2, pointersInTestCheckpoint);
}
- @Test (expected = BadCheckpointException.class)
+
+ @Test(expected = BadCheckpointException.class)
public void testDecreaseCapacity() throws Exception {
Assert.assertTrue(checkpoint.delete());
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
EventQueueBackingStoreFactory.get(checkpoint, 9, "test");
Assert.fail();
}
- @Test (expected = BadCheckpointException.class)
+ @Test(expected = BadCheckpointException.class)
public void testIncreaseCapacity() throws Exception {
Assert.assertTrue(checkpoint.delete());
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
EventQueueBackingStoreFactory.get(checkpoint, 11, "test");
Assert.fail();
@@ -112,22 +115,21 @@ public class TestEventQueueBackingStoreFactory {
public void testNewCheckpoint() throws Exception {
Assert.assertTrue(checkpoint.delete());
verify(EventQueueBackingStoreFactory.get(checkpoint, 10, "test", false),
- Serialization.VERSION_3, Collections.<Long>emptyList());
+ Serialization.VERSION_3, Collections.<Long>emptyList());
}
- @Test (expected = BadCheckpointException.class)
+ @Test(expected = BadCheckpointException.class)
public void testCheckpointBadVersion() throws Exception {
- RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
+ RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
try {
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
- backingStore.close();
- writer.seek(
- EventQueueBackingStoreFile.INDEX_VERSION * Serialization.SIZE_OF_LONG);
- writer.writeLong(94L);
- writer.getFD().sync();
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
+ backingStore.close();
+ writer.seek(EventQueueBackingStoreFile.INDEX_VERSION * Serialization.SIZE_OF_LONG);
+ writer.writeLong(94L);
+ writer.getFD().sync();
- backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
+ backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
} finally {
writer.close();
}
@@ -138,15 +140,13 @@ public class TestEventQueueBackingStoreFactory {
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
try {
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
- backingStore.close();
- writer.seek(
- EventQueueBackingStoreFile.INDEX_CHECKPOINT_MARKER *
- Serialization.SIZE_OF_LONG);
- writer.writeLong(EventQueueBackingStoreFile.CHECKPOINT_INCOMPLETE);
- writer.getFD().sync();
- backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
+ backingStore.close();
+ writer.seek(EventQueueBackingStoreFile.INDEX_CHECKPOINT_MARKER * Serialization.SIZE_OF_LONG);
+ writer.writeLong(EventQueueBackingStoreFile.CHECKPOINT_INCOMPLETE);
+ writer.getFD().sync();
+ backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
} finally {
writer.close();
}
@@ -156,12 +156,10 @@ public class TestEventQueueBackingStoreFactory {
public void testCheckpointVersionNotEqualToMeta() throws Exception {
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
try {
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
- writer.seek(
- EventQueueBackingStoreFile.INDEX_VERSION
- * Serialization.SIZE_OF_LONG);
+ writer.seek(EventQueueBackingStoreFile.INDEX_VERSION * Serialization.SIZE_OF_LONG);
writer.writeLong(2L);
writer.getFD().sync();
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
@@ -174,8 +172,8 @@ public class TestEventQueueBackingStoreFactory {
public void testCheckpointVersionNotEqualToMeta2() throws Exception {
FileOutputStream os = null;
try {
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
Assert.assertTrue(checkpoint.exists());
Assert.assertTrue(Serialization.getMetaDataFile(checkpoint).length() != 0);
@@ -183,8 +181,7 @@ public class TestEventQueueBackingStoreFactory {
ProtosFactory.Checkpoint meta = ProtosFactory.Checkpoint.parseDelimitedFrom(is);
Assert.assertNotNull(meta);
is.close();
- os = new FileOutputStream(
- Serialization.getMetaDataFile(checkpoint));
+ os = new FileOutputStream(Serialization.getMetaDataFile(checkpoint));
meta.toBuilder().setVersion(2).build().writeDelimitedTo(os);
os.flush();
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
@@ -197,12 +194,10 @@ public class TestEventQueueBackingStoreFactory {
public void testCheckpointOrderIdNotEqualToMeta() throws Exception {
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
try {
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
- writer.seek(
- EventQueueBackingStoreFile.INDEX_WRITE_ORDER_ID
- * Serialization.SIZE_OF_LONG);
+ writer.seek(EventQueueBackingStoreFile.INDEX_WRITE_ORDER_ID * Serialization.SIZE_OF_LONG);
writer.writeLong(2L);
writer.getFD().sync();
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
@@ -215,8 +210,8 @@ public class TestEventQueueBackingStoreFactory {
public void testCheckpointOrderIdNotEqualToMeta2() throws Exception {
FileOutputStream os = null;
try {
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
Assert.assertTrue(checkpoint.exists());
Assert.assertTrue(Serialization.getMetaDataFile(checkpoint).length() != 0);
@@ -225,7 +220,7 @@ public class TestEventQueueBackingStoreFactory {
Assert.assertNotNull(meta);
is.close();
os = new FileOutputStream(
- Serialization.getMetaDataFile(checkpoint));
+ Serialization.getMetaDataFile(checkpoint));
meta.toBuilder().setWriteOrderID(1).build().writeDelimitedTo(os);
os.flush();
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
@@ -234,11 +229,10 @@ public class TestEventQueueBackingStoreFactory {
}
}
-
@Test(expected = BadCheckpointException.class)
public void testTruncateMeta() throws Exception {
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
Assert.assertTrue(checkpoint.exists());
File metaFile = Serialization.getMetaDataFile(checkpoint);
@@ -250,10 +244,10 @@ public class TestEventQueueBackingStoreFactory {
backingStore = EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
}
- @Test (expected = InvalidProtocolBufferException.class)
+ @Test(expected = InvalidProtocolBufferException.class)
public void testCorruptMeta() throws Throwable {
- EventQueueBackingStore backingStore = EventQueueBackingStoreFactory.
- get(checkpoint, 10, "test");
+ EventQueueBackingStore backingStore =
+ EventQueueBackingStoreFactory.get(checkpoint, 10, "test");
backingStore.close();
Assert.assertTrue(checkpoint.exists());
File metaFile = Serialization.getMetaDataFile(checkpoint);
@@ -270,17 +264,13 @@ public class TestEventQueueBackingStoreFactory {
}
}
-
-
-
private void verify(EventQueueBackingStore backingStore, long expectedVersion,
- List<Long> expectedPointers)
- throws Exception {
- FlumeEventQueue queue = new FlumeEventQueue(backingStore, inflightTakes,
- inflightPuts, queueSetDir);
+ List<Long> expectedPointers) throws Exception {
+ FlumeEventQueue queue =
+ new FlumeEventQueue(backingStore, inflightTakes, inflightPuts, queueSetDir);
List<Long> actualPointers = Lists.newArrayList();
FlumeEventPointer ptr;
- while((ptr = queue.removeHead(0L)) != null) {
+ while ((ptr = queue.removeHead(0L)) != null) {
actualPointers.add(ptr.toLong());
}
Assert.assertEquals(expectedPointers, actualPointers);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventUtils.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventUtils.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventUtils.java
index c72e3f2..26f9cae 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventUtils.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestEventUtils.java
@@ -28,7 +28,7 @@ public class TestEventUtils {
@Test
public void testPutEvent() {
FlumeEvent event = new FlumeEvent(null, new byte[5]);
- Put put = new Put(1l, 1l, event);
+ Put put = new Put(1L, 1L, event);
Event returnEvent = EventUtils.getEventFromTransactionEvent(put);
Assert.assertNotNull(returnEvent);
Assert.assertEquals(5, returnEvent.getBody().length);
@@ -36,7 +36,7 @@ public class TestEventUtils {
@Test
public void testInvalidEvent() {
- Take take = new Take(1l, 1l);
+ Take take = new Take(1L, 1L);
Event returnEvent = EventUtils.getEventFromTransactionEvent(take);
Assert.assertNull(returnEvent);
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannel.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannel.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannel.java
index bb22e26..bfc2d0d 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannel.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannel.java
@@ -18,8 +18,22 @@
*/
package org.apache.flume.channel.file;
-import static org.apache.flume.channel.file.TestUtils.*;
-import static org.fest.reflect.core.Reflection.*;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.apache.flume.ChannelException;
+import org.apache.flume.Event;
+import org.apache.flume.Transaction;
+import org.apache.flume.channel.file.FileChannel.FileBackedTransaction;
+import org.apache.flume.channel.file.FlumeEventQueue.InflightEventWrapper;
+import org.apache.flume.conf.Configurables;
+import org.apache.flume.event.EventBuilder;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FilenameFilter;
@@ -32,7 +46,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Random;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
@@ -41,23 +54,15 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import org.apache.flume.ChannelException;
-import org.apache.flume.Event;
-import org.apache.flume.Transaction;
-import org.apache.flume.conf.Configurables;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import org.apache.flume.channel.file.FileChannel.FileBackedTransaction;
-import org.apache.flume.channel.file.FlumeEventQueue.InflightEventWrapper;
-import org.apache.flume.event.EventBuilder;
+import static org.apache.flume.channel.file.TestUtils.compareInputAndOut;
+import static org.apache.flume.channel.file.TestUtils.consumeChannel;
+import static org.apache.flume.channel.file.TestUtils.fillChannel;
+import static org.apache.flume.channel.file.TestUtils.forceCheckpoint;
+import static org.apache.flume.channel.file.TestUtils.putEvents;
+import static org.apache.flume.channel.file.TestUtils.putWithoutCommit;
+import static org.apache.flume.channel.file.TestUtils.takeEvents;
+import static org.apache.flume.channel.file.TestUtils.takeWithoutCommit;
+import static org.fest.reflect.core.Reflection.field;
public class TestFileChannel extends TestFileChannelBase {
@@ -68,6 +73,7 @@ public class TestFileChannel extends TestFileChannelBase {
public void setup() throws Exception {
super.setup();
}
+
@After
public void teardown() {
super.teardown();
@@ -146,23 +152,22 @@ public class TestFileChannel extends TestFileChannelBase {
//Simulate multiple sources, so separate thread - txns are thread local,
//so a new txn wont be created here unless it is in a different thread.
final CountDownLatch latch = new CountDownLatch(1);
- Executors.newSingleThreadExecutor().submit(
- new Runnable() {
- @Override
- public void run() {
- Transaction tx = channel.getTransaction();
- input.addAll(putWithoutCommit(channel, tx, "failAfterPut", 3));
- try {
- latch.await();
- tx.commit();
- } catch (InterruptedException e) {
- tx.rollback();
- Throwables.propagate(e);
- } finally {
- tx.close();
- }
- }
- });
+ Executors.newSingleThreadExecutor().submit(new Runnable() {
+ @Override
+ public void run() {
+ Transaction tx = channel.getTransaction();
+ input.addAll(putWithoutCommit(channel, tx, "failAfterPut", 3));
+ try {
+ latch.await();
+ tx.commit();
+ } catch (InterruptedException e) {
+ tx.rollback();
+ Throwables.propagate(e);
+ } finally {
+ tx.close();
+ }
+ }
+ });
forceCheckpoint(channel);
tx.commit();
tx.close();
@@ -198,7 +203,7 @@ public class TestFileChannel extends TestFileChannelBase {
Assert.assertTrue(channel.isOpen());
Set<String> in = Sets.newHashSet();
try {
- while(true) {
+ while (true) {
in.addAll(putEvents(channel, "reconfig", 1, 1));
}
} catch (ChannelException e) {
@@ -206,12 +211,13 @@ public class TestFileChannel extends TestFileChannelBase {
+ "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()+"]", e.getMessage());
+ + channel.getName() + "]", e.getMessage());
}
Configurables.configure(channel, createContext());
Set<String> out = takeEvents(channel, 1, Integer.MAX_VALUE);
compareInputAndOut(in, out);
}
+
@Test
public void testPut() throws Exception {
channel.start();
@@ -225,6 +231,7 @@ public class TestFileChannel extends TestFileChannelBase {
Set<String> actual = takeEvents(channel, 1);
compareInputAndOut(expected, actual);
}
+
@Test
public void testCommitAfterNoPutTake() throws Exception {
channel.start();
@@ -246,6 +253,7 @@ public class TestFileChannel extends TestFileChannelBase {
transaction.commit();
transaction.close();
}
+
@Test
public void testCapacity() throws Exception {
Map<String, String> overrides = Maps.newHashMap();
@@ -270,6 +278,7 @@ public class TestFileChannel extends TestFileChannelBase {
// ensure we the events back
Assert.assertEquals(5, takeEvents(channel, 1, 5).size());
}
+
/**
* This test is here to make sure we can replay a full queue
* when we have a PUT with a lower txid than the take which
@@ -287,16 +296,14 @@ public class TestFileChannel extends TestFileChannelBase {
// the idea here is we will fill up the channel
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.KEEP_ALIVE, String.valueOf(10L));
- overrides.put(FileChannelConfiguration.CAPACITY, String.valueOf(10));
- overrides.put(FileChannelConfiguration.TRANSACTION_CAPACITY,
- String.valueOf(10));
+ overrides.put(FileChannelConfiguration.CAPACITY, String.valueOf(10L));
+ overrides.put(FileChannelConfiguration.TRANSACTION_CAPACITY, String.valueOf(10L));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
fillChannel(channel, "fillup");
// then do a put which will block but it will be assigned a tx id
- Future<String> put = Executors.newSingleThreadExecutor()
- .submit(new Callable<String>() {
+ Future<String> put = Executors.newSingleThreadExecutor().submit(new Callable<String>() {
@Override
public String call() throws Exception {
Set<String> result = putEvents(channel, "blocked-put", 1, 1);
@@ -321,6 +328,7 @@ public class TestFileChannel extends TestFileChannelBase {
channel.start();
Assert.assertTrue(channel.isOpen());
}
+
@Test
public void testThreaded() throws IOException, InterruptedException {
channel.start();
@@ -328,12 +336,9 @@ public class TestFileChannel extends TestFileChannelBase {
int numThreads = 10;
final CountDownLatch producerStopLatch = new CountDownLatch(numThreads);
final CountDownLatch consumerStopLatch = new CountDownLatch(numThreads);
- final List<Exception> errors = Collections
- .synchronizedList(new ArrayList<Exception>());
- final Set<String> expected = Collections.synchronizedSet(
- new HashSet<String>());
- final Set<String> actual = Collections.synchronizedSet(
- new HashSet<String>());
+ final List<Exception> errors = Collections.synchronizedList(new ArrayList<Exception>());
+ final Set<String> expected = Collections.synchronizedSet(new HashSet<String>());
+ final Set<String> actual = Collections.synchronizedSet(new HashSet<String>());
for (int i = 0; i < numThreads; i++) {
final int id = i;
Thread t = new Thread() {
@@ -363,15 +368,15 @@ public class TestFileChannel extends TestFileChannelBase {
@Override
public void run() {
try {
- while(!producerStopLatch.await(1, TimeUnit.SECONDS) ||
- expected.size() > actual.size()) {
+ while (!producerStopLatch.await(1, TimeUnit.SECONDS) ||
+ expected.size() > actual.size()) {
if (id % 2 == 0) {
actual.addAll(takeEvents(channel, 1, Integer.MAX_VALUE));
} else {
actual.addAll(takeEvents(channel, 5, Integer.MAX_VALUE));
}
}
- if(actual.isEmpty()) {
+ if (actual.isEmpty()) {
LOG.error("Found nothing!");
} else {
LOG.info("Completed some takes " + actual.size());
@@ -388,12 +393,13 @@ public class TestFileChannel extends TestFileChannelBase {
t.start();
}
Assert.assertTrue("Timed out waiting for producers",
- producerStopLatch.await(30, TimeUnit.SECONDS));
+ producerStopLatch.await(30, TimeUnit.SECONDS));
Assert.assertTrue("Timed out waiting for consumer",
- consumerStopLatch.await(30, TimeUnit.SECONDS));
+ consumerStopLatch.await(30, TimeUnit.SECONDS));
Assert.assertEquals(Collections.EMPTY_LIST, errors);
compareInputAndOut(expected, actual);
}
+
@Test
public void testLocking() throws IOException {
channel.start();
@@ -403,7 +409,6 @@ public class TestFileChannel extends TestFileChannelBase {
Assert.assertTrue(!fileChannel.isOpen());
}
-
/**
* Test contributed by Brock Noland during code review.
* @throws Exception
@@ -437,11 +442,11 @@ public class TestFileChannel extends TestFileChannelBase {
}
@Test
- public void testPutForceCheckpointCommitReplay() throws Exception{
+ public void testPutForceCheckpointCommitReplay() throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.CAPACITY, String.valueOf(2));
overrides.put(FileChannelConfiguration.TRANSACTION_CAPACITY,
- String.valueOf(2));
+ String.valueOf(2));
overrides.put(FileChannelConfiguration.CHECKPOINT_INTERVAL, "10000");
FileChannel channel = createFileChannel(overrides);
channel.start();
@@ -578,28 +583,22 @@ public class TestFileChannel extends TestFileChannelBase {
testChannelDiesOnCorruptEvent(true);
}
-
@Test
- public void testChannelDiesOnCorruptEventNoFsync() throws
- Exception {
+ public void testChannelDiesOnCorruptEventNoFsync() throws Exception {
testChannelDiesOnCorruptEvent(false);
}
-
-
- private void testChannelDiesOnCorruptEvent(boolean fsyncPerTxn)
- throws Exception {
+ private void testChannelDiesOnCorruptEvent(boolean fsyncPerTxn) throws Exception {
Map<String, String> overrides = new HashMap<String, String>();
- overrides.put(FileChannelConfiguration.FSYNC_PER_TXN,
- String.valueOf(fsyncPerTxn));
+ overrides.put(FileChannelConfiguration.FSYNC_PER_TXN, String.valueOf(fsyncPerTxn));
final FileChannel channel = createFileChannel(overrides);
channel.start();
putEvents(channel,"test-corrupt-event",100,100);
- for(File dataDir : dataDirs) {
+ for (File dataDir : dataDirs) {
File[] files = dataDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
- if(!name.endsWith("meta") && !name.contains("lock")){
+ if (!name.endsWith("meta") && !name.contains("lock")) {
return true;
}
return false;
@@ -624,7 +623,7 @@ public class TestFileChannel extends TestFileChannelBase {
Assert.assertTrue(ex.getMessage().contains("Log is closed"));
throw ex;
}
- if(fsyncPerTxn) {
+ if (fsyncPerTxn) {
Assert.fail();
} else {
// The corrupt event must be missing, the rest should be
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelFormatRegression.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelFormatRegression.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelFormatRegression.java
index c95122b..f0638f9 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelFormatRegression.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelFormatRegression.java
@@ -18,14 +18,7 @@
*/
package org.apache.flume.channel.file;
-import static org.apache.flume.channel.file.TestUtils.*;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
+import com.google.common.collect.Maps;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -33,8 +26,14 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.Maps;
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import static org.apache.flume.channel.file.TestUtils.compareInputAndOut;
+import static org.apache.flume.channel.file.TestUtils.takeEvents;
public class TestFileChannelFormatRegression extends TestFileChannelBase {
protected static final Logger LOG = LoggerFactory
@@ -60,8 +59,8 @@ public class TestFileChannelFormatRegression extends TestFileChannelBase {
new File(checkpointDir, "checkpoint"));
for (int i = 0; i < dataDirs.length; i++) {
int fileIndex = i + 1;
- TestUtils.copyDecompressed("fileformat-v2-log-"+fileIndex+".gz",
- new File(dataDirs[i], "log-" + fileIndex));
+ TestUtils.copyDecompressed("fileformat-v2-log-" + fileIndex + ".gz",
+ new File(dataDirs[i], "log-" + fileIndex));
}
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.CAPACITY, String.valueOf(10));
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRestart.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRestart.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRestart.java
index d5fe6fb..d21f140 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRestart.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRestart.java
@@ -55,8 +55,7 @@ import static org.apache.flume.channel.file.TestUtils.takeWithoutCommit;
import static org.fest.reflect.core.Reflection.*;
public class TestFileChannelRestart extends TestFileChannelBase {
- protected static final Logger LOG = LoggerFactory
- .getLogger(TestFileChannelRestart.class);
+ protected static final Logger LOG = LoggerFactory.getLogger(TestFileChannelRestart.class);
@Before
public void setup() throws Exception {
@@ -72,8 +71,8 @@ public class TestFileChannelRestart extends TestFileChannelBase {
protected FileChannel createFileChannel(Map<String, String> overrides) {
// FLUME-2482, making sure scheduled checkpoint never gets called
overrides.put(FileChannelConfiguration.CHECKPOINT_INTERVAL, "6000000");
- return TestUtils.createFileChannel(checkpointDir.getAbsolutePath(),
- dataDir, backupDir.getAbsolutePath(), overrides);
+ return TestUtils.createFileChannel(checkpointDir.getAbsolutePath(), dataDir,
+ backupDir.getAbsolutePath(), overrides);
}
@Test
@@ -116,14 +115,14 @@ public class TestFileChannelRestart extends TestFileChannelBase {
}
public void doTestRestart(boolean useLogReplayV1,
- boolean forceCheckpoint, boolean deleteCheckpoint,
- boolean useFastReplay) throws Exception {
+ boolean forceCheckpoint, boolean deleteCheckpoint,
+ boolean useFastReplay) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_LOG_REPLAY_V1,
- String.valueOf(useLogReplayV1));
+ String.valueOf(useLogReplayV1));
overrides.put(
- FileChannelConfiguration.USE_FAST_REPLAY,
- String.valueOf(useFastReplay));
+ FileChannelConfiguration.USE_FAST_REPLAY,
+ String.valueOf(useFastReplay));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
@@ -132,7 +131,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
forceCheckpoint(channel);
}
channel.stop();
- if(deleteCheckpoint) {
+ if (deleteCheckpoint) {
File checkpoint = new File(checkpointDir, "checkpoint");
Assert.assertTrue(checkpoint.delete());
File checkpointMetaData = Serialization.getMetaDataFile(checkpoint);
@@ -146,19 +145,17 @@ public class TestFileChannelRestart extends TestFileChannelBase {
}
@Test
- public void testRestartWhenMetaDataExistsButCheckpointDoesNot() throws
- Exception {
+ public void testRestartWhenMetaDataExistsButCheckpointDoesNot() throws Exception {
doTestRestartWhenMetaDataExistsButCheckpointDoesNot(false);
}
@Test
- public void testRestartWhenMetaDataExistsButCheckpointDoesNotWithBackup()
- throws Exception {
+ public void testRestartWhenMetaDataExistsButCheckpointDoesNotWithBackup() throws Exception {
doTestRestartWhenMetaDataExistsButCheckpointDoesNot(true);
}
- private void doTestRestartWhenMetaDataExistsButCheckpointDoesNot(
- boolean backup) throws Exception {
+ private void doTestRestartWhenMetaDataExistsButCheckpointDoesNot(boolean backup)
+ throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
@@ -167,7 +164,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
channel.stop();
@@ -186,19 +183,16 @@ public class TestFileChannelRestart extends TestFileChannelBase {
}
@Test
- public void testRestartWhenCheckpointExistsButMetaDoesNot() throws Exception{
+ public void testRestartWhenCheckpointExistsButMetaDoesNot() throws Exception {
doTestRestartWhenCheckpointExistsButMetaDoesNot(false);
}
@Test
- public void testRestartWhenCheckpointExistsButMetaDoesNotWithBackup() throws
- Exception{
+ public void testRestartWhenCheckpointExistsButMetaDoesNotWithBackup() throws Exception {
doTestRestartWhenCheckpointExistsButMetaDoesNot(true);
}
-
- private void doTestRestartWhenCheckpointExistsButMetaDoesNot(boolean backup)
- throws Exception {
+ private void doTestRestartWhenCheckpointExistsButMetaDoesNot(boolean backup) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
@@ -207,7 +201,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
channel.stop();
@@ -235,8 +229,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
doTestRestartWhenNoCheckpointExists(true);
}
- private void doTestRestartWhenNoCheckpointExists(boolean backup) throws
- Exception {
+ private void doTestRestartWhenNoCheckpointExists(boolean backup) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
@@ -245,7 +238,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
channel.stop();
@@ -273,7 +266,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
doTestBadCheckpointVersion(true);
}
- private void doTestBadCheckpointVersion(boolean backup) throws Exception{
+ private void doTestBadCheckpointVersion(boolean backup) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
@@ -282,14 +275,14 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
channel.stop();
File checkpoint = new File(checkpointDir, "checkpoint");
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
writer.seek(EventQueueBackingStoreFile.INDEX_VERSION *
- Serialization.SIZE_OF_LONG);
+ Serialization.SIZE_OF_LONG);
writer.writeLong(2L);
writer.getFD().sync();
writer.close();
@@ -311,8 +304,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
doTestBadCheckpointMetaVersion(true);
}
- private void doTestBadCheckpointMetaVersion(boolean backup) throws
- Exception {
+ private void doTestBadCheckpointMetaVersion(boolean backup) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
@@ -321,7 +313,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
channel.stop();
@@ -331,7 +323,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Assert.assertNotNull(meta);
is.close();
FileOutputStream os = new FileOutputStream(
- Serialization.getMetaDataFile(checkpoint));
+ Serialization.getMetaDataFile(checkpoint));
meta.toBuilder().setVersion(2).build().writeDelimitedTo(os);
os.flush();
channel = createFileChannel(overrides);
@@ -348,13 +340,11 @@ public class TestFileChannelRestart extends TestFileChannelBase {
}
@Test
- public void testDifferingOrderIDCheckpointAndMetaVersionWithBackup() throws
- Exception {
+ public void testDifferingOrderIDCheckpointAndMetaVersionWithBackup() throws Exception {
doTestDifferingOrderIDCheckpointAndMetaVersion(true);
}
- private void doTestDifferingOrderIDCheckpointAndMetaVersion(boolean backup)
- throws Exception {
+ private void doTestDifferingOrderIDCheckpointAndMetaVersion(boolean backup) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
@@ -363,7 +353,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
channel.stop();
@@ -373,7 +363,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Assert.assertNotNull(meta);
is.close();
FileOutputStream os = new FileOutputStream(
- Serialization.getMetaDataFile(checkpoint));
+ Serialization.getMetaDataFile(checkpoint));
meta.toBuilder().setWriteOrderID(12).build().writeDelimitedTo(os);
os.flush();
channel = createFileChannel(overrides);
@@ -385,12 +375,12 @@ public class TestFileChannelRestart extends TestFileChannelBase {
}
@Test
- public void testIncompleteCheckpoint() throws Exception{
+ public void testIncompleteCheckpoint() throws Exception {
doTestIncompleteCheckpoint(false);
}
@Test
- public void testIncompleteCheckpointWithCheckpoint() throws Exception{
+ public void testIncompleteCheckpointWithCheckpoint() throws Exception {
doTestIncompleteCheckpoint(true);
}
@@ -403,14 +393,14 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
channel.stop();
File checkpoint = new File(checkpointDir, "checkpoint");
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
writer.seek(EventQueueBackingStoreFile.INDEX_CHECKPOINT_MARKER
- * Serialization.SIZE_OF_LONG);
+ * Serialization.SIZE_OF_LONG);
writer.writeLong(EventQueueBackingStoreFile.CHECKPOINT_INCOMPLETE);
writer.getFD().sync();
writer.close();
@@ -443,30 +433,30 @@ public class TestFileChannelRestart extends TestFileChannelBase {
}
@Test
- public void testFastReplayWithCheckpoint() throws Exception{
+ public void testFastReplayWithCheckpoint() throws Exception {
testFastReplay(false, true);
}
@Test
- public void testFastReplayWithBadCheckpoint() throws Exception{
+ public void testFastReplayWithBadCheckpoint() throws Exception {
testFastReplay(true, true);
}
@Test
- public void testNoFastReplayWithCheckpoint() throws Exception{
+ public void testNoFastReplayWithCheckpoint() throws Exception {
testFastReplay(false, false);
}
@Test
- public void testNoFastReplayWithBadCheckpoint() throws Exception{
+ public void testNoFastReplayWithBadCheckpoint() throws Exception {
testFastReplay(true, false);
}
- private void testFastReplay(boolean shouldCorruptCheckpoint,
- boolean useFastReplay) throws Exception{
+ private void testFastReplay(boolean shouldCorruptCheckpoint, boolean useFastReplay)
+ throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_FAST_REPLAY,
- String.valueOf(useFastReplay));
+ String.valueOf(useFastReplay));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
@@ -477,7 +467,8 @@ public class TestFileChannelRestart extends TestFileChannelBase {
if (shouldCorruptCheckpoint) {
File checkpoint = new File(checkpointDir, "checkpoint");
RandomAccessFile writer = new RandomAccessFile(
- Serialization.getMetaDataFile(checkpoint), "rw");
+ Serialization.getMetaDataFile(checkpoint),
+ "rw");
writer.seek(10);
writer.writeLong(new Random().nextLong());
writer.getFD().sync();
@@ -495,14 +486,13 @@ public class TestFileChannelRestart extends TestFileChannelBase {
compareInputAndOut(in, out);
}
- private void doTestCorruptInflights(String name,
- boolean backup) throws Exception {
+ private void doTestCorruptInflights(String name, boolean backup) throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, String.valueOf(backup));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
- final Set<String> in1 = putEvents(channel, "restart-",10, 100);
+ final Set<String> in1 = putEvents(channel, "restart-", 10, 100);
Assert.assertEquals(100, in1.size());
Executors.newSingleThreadScheduledExecutor().submit(new Runnable() {
@Override
@@ -516,7 +506,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in2 = putWithoutCommit(channel, tx, "restart", 100);
Assert.assertEquals(100, in2.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
tx.commit();
@@ -554,13 +544,12 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
channel.stop();
File checkpoint = new File(checkpointDir, "checkpoint");
- RandomAccessFile writer = new RandomAccessFile(
- Serialization.getMetaDataFile(checkpoint), "rw");
+ RandomAccessFile writer = new RandomAccessFile(Serialization.getMetaDataFile(checkpoint), "rw");
writer.setLength(0);
writer.getFD().sync();
writer.close();
@@ -591,13 +580,12 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> in = putEvents(channel, "restart", 10, 100);
Assert.assertEquals(100, in.size());
forceCheckpoint(channel);
- if(backup) {
+ if (backup) {
Thread.sleep(2000);
}
channel.stop();
File checkpoint = new File(checkpointDir, "checkpoint");
- RandomAccessFile writer = new RandomAccessFile(
- Serialization.getMetaDataFile(checkpoint), "rw");
+ RandomAccessFile writer = new RandomAccessFile(Serialization.getMetaDataFile(checkpoint), "rw");
writer.seek(10);
writer.writeLong(new Random().nextLong());
writer.getFD().sync();
@@ -618,11 +606,10 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Assert.assertFalse(backupRestored);
}
}
-
+
//This test will fail without FLUME-1893
@Test
- public void testCorruptCheckpointVersionMostSignificant4Bytes()
- throws Exception {
+ public void testCorruptCheckpointVersionMostSignificant4Bytes() throws Exception {
Map<String, String> overrides = Maps.newHashMap();
channel = createFileChannel(overrides);
channel.start();
@@ -634,8 +621,8 @@ public class TestFileChannelRestart extends TestFileChannelBase {
File checkpoint = new File(checkpointDir, "checkpoint");
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
writer.seek(EventQueueBackingStoreFile.INDEX_VERSION *
- Serialization.SIZE_OF_LONG);
- writer.write(new byte[]{(byte)1, (byte)5});
+ Serialization.SIZE_OF_LONG);
+ writer.write(new byte[] { (byte) 1, (byte) 5 });
writer.getFD().sync();
writer.close();
channel = createFileChannel(overrides);
@@ -648,8 +635,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
//This test will fail without FLUME-1893
@Test
- public void testCorruptCheckpointCompleteMarkerMostSignificant4Bytes()
- throws Exception {
+ public void testCorruptCheckpointCompleteMarkerMostSignificant4Bytes() throws Exception {
Map<String, String> overrides = Maps.newHashMap();
channel = createFileChannel(overrides);
channel.start();
@@ -661,8 +647,8 @@ public class TestFileChannelRestart extends TestFileChannelBase {
File checkpoint = new File(checkpointDir, "checkpoint");
RandomAccessFile writer = new RandomAccessFile(checkpoint, "rw");
writer.seek(EventQueueBackingStoreFile.INDEX_CHECKPOINT_MARKER *
- Serialization.SIZE_OF_LONG);
- writer.write(new byte[]{(byte) 1, (byte) 5});
+ Serialization.SIZE_OF_LONG);
+ writer.write(new byte[] { (byte) 1, (byte) 5 });
writer.getFD().sync();
writer.close();
channel = createFileChannel(overrides);
@@ -674,8 +660,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
}
@Test
- public void testWithExtraLogs()
- throws Exception {
+ public void testWithExtraLogs() throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.CAPACITY, "10");
overrides.put(FileChannelConfiguration.TRANSACTION_CAPACITY, "10");
@@ -702,27 +687,24 @@ public class TestFileChannelRestart extends TestFileChannelBase {
// Make sure the entire channel was not replayed, only the events from the
// backup.
@Test
- public void testBackupUsedEnsureNoFullReplayWithoutCompression() throws
- Exception {
+ public void testBackupUsedEnsureNoFullReplayWithoutCompression() throws Exception {
testBackupUsedEnsureNoFullReplay(false);
}
+
@Test
- public void testBackupUsedEnsureNoFullReplayWithCompression() throws
- Exception {
+ public void testBackupUsedEnsureNoFullReplayWithCompression() throws Exception {
testBackupUsedEnsureNoFullReplay(true);
}
private void testBackupUsedEnsureNoFullReplay(boolean compressedBackup)
- throws Exception {
+ throws Exception {
File dataDir = Files.createTempDir();
File tempBackup = Files.createTempDir();
Map<String, String> overrides = Maps.newHashMap();
- overrides.put(FileChannelConfiguration.DATA_DIRS,
- dataDir.getAbsolutePath());
- overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS,
- "true");
+ overrides.put(FileChannelConfiguration.DATA_DIRS, dataDir.getAbsolutePath());
+ overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, "true");
overrides.put(FileChannelConfiguration.COMPRESS_BACKUP_CHECKPOINT,
- String.valueOf(compressedBackup));
+ String.valueOf(compressedBackup));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
@@ -734,8 +716,8 @@ public class TestFileChannelRestart extends TestFileChannelBase {
in = putEvents(channel, "restart", 10, 100);
takeEvents(channel, 10, 100);
Assert.assertEquals(100, in.size());
- for(File file : backupDir.listFiles()) {
- if(file.getName().equals(Log.FILE_LOCK)) {
+ for (File file : backupDir.listFiles()) {
+ if (file.getName().equals(Log.FILE_LOCK)) {
continue;
}
Files.copy(file, new File(tempBackup, file.getName()));
@@ -749,8 +731,8 @@ public class TestFileChannelRestart extends TestFileChannelBase {
// tests), so throw away the backup and force the use of an older backup by
// bringing in the copy of the last backup before the checkpoint.
Serialization.deleteAllFiles(backupDir, Log.EXCLUDES);
- for(File file : tempBackup.listFiles()) {
- if(file.getName().equals(Log.FILE_LOCK)) {
+ for (File file : tempBackup.listFiles()) {
+ if (file.getName().equals(Log.FILE_LOCK)) {
continue;
}
Files.copy(file, new File(backupDir, file.getName()));
@@ -782,7 +764,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Assert.assertTrue(channel.isOpen());
putEvents(channel, prefix, 10, 100);
Set<String> origFiles = Sets.newHashSet();
- for(File dir : dataDirs) {
+ for (File dir : dataDirs) {
origFiles.addAll(Lists.newArrayList(dir.list()));
}
forceCheckpoint(channel);
@@ -792,7 +774,7 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Set<String> newFiles = Sets.newHashSet();
int olderThanCheckpoint = 0;
int totalMetaFiles = 0;
- for(File dir : dataDirs) {
+ for (File dir : dataDirs) {
File[] metadataFiles = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
@@ -803,8 +785,8 @@ public class TestFileChannelRestart extends TestFileChannelBase {
}
});
totalMetaFiles = metadataFiles.length;
- for(File metadataFile : metadataFiles) {
- if(metadataFile.lastModified() < beforeSecondCheckpoint) {
+ for (File metadataFile : metadataFiles) {
+ if (metadataFile.lastModified() < beforeSecondCheckpoint) {
olderThanCheckpoint++;
}
}
@@ -824,13 +806,13 @@ public class TestFileChannelRestart extends TestFileChannelBase {
takeEvents(channel, 10, 50);
forceCheckpoint(channel);
newFiles = Sets.newHashSet();
- for(File dir : dataDirs) {
+ for (File dir : dataDirs) {
newFiles.addAll(Lists.newArrayList(dir.list()));
}
Assert.assertTrue(!newFiles.containsAll(origFiles));
}
- @Test (expected = IOException.class)
+ @Test(expected = IOException.class)
public void testSlowBackup() throws Throwable {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS, "true");
@@ -858,10 +840,10 @@ public class TestFileChannelRestart extends TestFileChannelBase {
public void testCompressBackup() throws Throwable {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS,
- "true");
+ "true");
overrides.put(FileChannelConfiguration.MAX_FILE_SIZE, "1000");
overrides.put(FileChannelConfiguration.COMPRESS_BACKUP_CHECKPOINT,
- "true");
+ "true");
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
@@ -873,36 +855,34 @@ public class TestFileChannelRestart extends TestFileChannelBase {
Assert.assertTrue(compressedBackupCheckpoint.exists());
- Serialization.decompressFile(compressedBackupCheckpoint,
- uncompressedBackupCheckpoint);
+ Serialization.decompressFile(compressedBackupCheckpoint, uncompressedBackupCheckpoint);
File checkpoint = new File(checkpointDir, "checkpoint");
- Assert.assertTrue(FileUtils.contentEquals(checkpoint,
- uncompressedBackupCheckpoint));
+ Assert.assertTrue(FileUtils.contentEquals(checkpoint, uncompressedBackupCheckpoint));
channel.stop();
}
@Test
public void testToggleCheckpointCompressionFromTrueToFalse()
- throws Exception {
+ throws Exception {
restartToggleCompression(true);
}
@Test
public void testToggleCheckpointCompressionFromFalseToTrue()
- throws Exception {
+ throws Exception {
restartToggleCompression(false);
}
public void restartToggleCompression(boolean originalCheckpointCompressed)
- throws Exception {
+ throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.USE_DUAL_CHECKPOINTS,
- "true");
+ "true");
overrides.put(FileChannelConfiguration.MAX_FILE_SIZE, "1000");
overrides.put(FileChannelConfiguration.COMPRESS_BACKUP_CHECKPOINT,
- String.valueOf(originalCheckpointCompressed));
+ String.valueOf(originalCheckpointCompressed));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
@@ -910,17 +890,17 @@ public class TestFileChannelRestart extends TestFileChannelBase {
forceCheckpoint(channel);
Thread.sleep(2000);
Assert.assertEquals(compressedBackupCheckpoint.exists(),
- originalCheckpointCompressed);
+ originalCheckpointCompressed);
Assert.assertEquals(uncompressedBackupCheckpoint.exists(),
- !originalCheckpointCompressed);
+ !originalCheckpointCompressed);
channel.stop();
File checkpoint = new File(checkpointDir, "checkpoint");
Assert.assertTrue(checkpoint.delete());
File checkpointMetaData = Serialization.getMetaDataFile(
- checkpoint);
+ checkpoint);
Assert.assertTrue(checkpointMetaData.delete());
overrides.put(FileChannelConfiguration.COMPRESS_BACKUP_CHECKPOINT,
- String.valueOf(!originalCheckpointCompressed));
+ String.valueOf(!originalCheckpointCompressed));
channel = createFileChannel(overrides);
channel.start();
Assert.assertTrue(channel.isOpen());
@@ -929,21 +909,21 @@ public class TestFileChannelRestart extends TestFileChannelBase {
forceCheckpoint(channel);
Thread.sleep(2000);
Assert.assertEquals(compressedBackupCheckpoint.exists(),
- !originalCheckpointCompressed);
+ !originalCheckpointCompressed);
Assert.assertEquals(uncompressedBackupCheckpoint.exists(),
- originalCheckpointCompressed);
+ originalCheckpointCompressed);
}
private static void slowdownBackup(FileChannel channel) {
Log log = field("log").ofType(Log.class).in(channel).get();
FlumeEventQueue queue = field("queue")
- .ofType(FlumeEventQueue.class)
- .in(log).get();
+ .ofType(FlumeEventQueue.class)
+ .in(log).get();
EventQueueBackingStore backingStore = field("backingStore")
- .ofType(EventQueueBackingStore.class)
- .in(queue).get();
+ .ofType(EventQueueBackingStore.class)
+ .in(queue).get();
field("slowdownBackup").ofType(Boolean.class).in(backingStore).set(true);
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRollback.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRollback.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRollback.java
index 23fc64b..c06d498 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRollback.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFileChannelRollback.java
@@ -18,11 +18,7 @@
*/
package org.apache.flume.channel.file;
-import static org.apache.flume.channel.file.TestUtils.*;
-
-import java.util.Collections;
-import java.util.Set;
-
+import com.google.common.base.Charsets;
import org.apache.flume.Transaction;
import org.apache.flume.event.EventBuilder;
import org.apache.flume.sink.LoggerSink;
@@ -33,8 +29,12 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Charsets;
+import java.util.Collections;
+import java.util.Set;
+import static org.apache.flume.channel.file.TestUtils.compareInputAndOut;
+import static org.apache.flume.channel.file.TestUtils.putEvents;
+import static org.apache.flume.channel.file.TestUtils.takeEvents;
public class TestFileChannelRollback extends TestFileChannelBase {
protected static final Logger LOG = LoggerFactory
@@ -117,11 +117,11 @@ public class TestFileChannelRollback extends TestFileChannelBase {
transaction.rollback();
transaction.close();
- while(runner.isAlive()) {
+ while (runner.isAlive()) {
Thread.sleep(10L);
}
Assert.assertEquals(numEvents - 1, runner.getCount());
- for(Exception ex : runner.getErrors()) {
+ for (Exception ex : runner.getErrors()) {
LOG.warn("Sink had error", ex);
}
Assert.assertEquals(Collections.EMPTY_LIST, runner.getErrors());
[4/9] flume git commit: FLUME-2941. Integrate checkstyle for test
classes
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
index c59fdd4..3ad8282 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
@@ -22,7 +22,11 @@ import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import junit.framework.Assert;
-import org.apache.flume.*;
+import org.apache.flume.Channel;
+import org.apache.flume.ChannelSelector;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.flume.Transaction;
import org.apache.flume.channel.ChannelProcessor;
import org.apache.flume.channel.MemoryChannel;
import org.apache.flume.channel.ReplicatingChannelSelector;
@@ -41,11 +45,22 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import javax.net.ssl.*;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Type;
-import java.net.*;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URL;
+import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.util.ArrayList;
@@ -114,9 +129,10 @@ public class TestHTTPSource {
sslContext.put(HTTPSourceConfigurationConstants.SSL_ENABLED, "true");
sslPort = findFreePort();
sslContext.put(HTTPSourceConfigurationConstants.CONFIG_PORT,
- String.valueOf(sslPort));
+ String.valueOf(sslPort));
sslContext.put(HTTPSourceConfigurationConstants.SSL_KEYSTORE_PASSWORD, "password");
- sslContext.put(HTTPSourceConfigurationConstants.SSL_KEYSTORE, "src/test/resources/jettykeystore");
+ sslContext.put(HTTPSourceConfigurationConstants.SSL_KEYSTORE,
+ "src/test/resources/jettykeystore");
Configurables.configure(source, context);
Configurables.configure(httpsSource, sslContext);
@@ -180,7 +196,7 @@ public class TestHTTPSource {
private void doTestForbidden(HttpRequestBase request) throws Exception {
HttpResponse response = httpClient.execute(request);
Assert.assertEquals(HttpServletResponse.SC_FORBIDDEN,
- response.getStatusLine().getStatusCode());
+ response.getStatusLine().getStatusCode());
}
@Test
@@ -286,10 +302,8 @@ public class TestHTTPSource {
}
- private ResultWrapper putWithEncoding(String encoding, int n)
- throws Exception{
- Type listType = new TypeToken<List<JSONEvent>>() {
- }.getType();
+ private ResultWrapper putWithEncoding(String encoding, int n) throws Exception {
+ Type listType = new TypeToken<List<JSONEvent>>() {}.getType();
List<JSONEvent> events = Lists.newArrayList();
Random rand = new Random();
for (int i = 0; i < n; i++) {
@@ -341,25 +355,25 @@ public class TestHTTPSource {
String json = gson.toJson(events, listType);
HttpsURLConnection httpsURLConnection = null;
try {
- TrustManager[] trustAllCerts = {new X509TrustManager() {
- @Override
- public void checkClientTrusted(
- java.security.cert.X509Certificate[] x509Certificates, String s)
- throws CertificateException {
- // noop
+ TrustManager[] trustAllCerts = {
+ new X509TrustManager() {
+ @Override
+ public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates,
+ String s) throws CertificateException {
+ // noop
+ }
+
+ @Override
+ public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates,
+ String s) throws CertificateException {
+ // noop
+ }
+
+ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
}
-
- @Override
- public void checkServerTrusted(
- java.security.cert.X509Certificate[] x509Certificates, String s)
- throws CertificateException {
- // noop
- }
-
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- }};
+ };
SSLContext sc = null;
javax.net.ssl.SSLSocketFactory factory = null;
@@ -376,14 +390,13 @@ public class TestHTTPSource {
};
sc.init(null, trustAllCerts, new SecureRandom());
- if(protocol != null) {
+ if (protocol != null) {
factory = new DisabledProtocolsSocketFactory(sc.getSocketFactory(), protocol);
} else {
factory = sc.getSocketFactory();
}
HttpsURLConnection.setDefaultSSLSocketFactory(factory);
- HttpsURLConnection.setDefaultHostnameVerifier(
- SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+ HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
URL sslUrl = new URL("https://0.0.0.0:" + sslPort);
httpsURLConnection = (HttpsURLConnection) sslUrl.openConnection();
httpsURLConnection.setDoInput(true);
@@ -396,14 +409,14 @@ public class TestHTTPSource {
Transaction transaction = channel.getTransaction();
transaction.begin();
- for(int i = 0; i < 10; i++) {
+ for (int i = 0; i < 10; i++) {
Event e = channel.take();
Assert.assertNotNull(e);
Assert.assertEquals(String.valueOf(i), e.getHeaders().get("MsgNum"));
}
- transaction.commit();
- transaction.close();
+ transaction.commit();
+ transaction.close();
} finally {
httpsURLConnection.disconnect();
}
@@ -416,38 +429,37 @@ public class TestHTTPSource {
List<JSONEvent> events = Lists.newArrayList();
Random rand = new Random();
for (int i = 0; i < 10; i++) {
- Map<String, String> input = Maps.newHashMap();
- for (int j = 0; j < 10; j++) {
- input.put(String.valueOf(i) + String.valueOf(j), String.valueOf(i));
- }
- input.put("MsgNum", String.valueOf(i));
- JSONEvent e = new JSONEvent();
- e.setHeaders(input);
- e.setBody(String.valueOf(rand.nextGaussian()).getBytes("UTF-8"));
- events.add(e);
+ Map<String, String> input = Maps.newHashMap();
+ for (int j = 0; j < 10; j++) {
+ input.put(String.valueOf(i) + String.valueOf(j), String.valueOf(i));
+ }
+ input.put("MsgNum", String.valueOf(i));
+ JSONEvent e = new JSONEvent();
+ e.setHeaders(input);
+ e.setBody(String.valueOf(rand.nextGaussian()).getBytes("UTF-8"));
+ events.add(e);
}
Gson gson = new Gson();
String json = gson.toJson(events, listType);
HttpURLConnection httpURLConnection = null;
try {
- URL url = new URL("http://0.0.0.0:" + sslPort);
- httpURLConnection = (HttpURLConnection) url.openConnection();
- httpURLConnection.setDoInput(true);
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setRequestMethod("POST");
- httpURLConnection.getOutputStream().write(json.getBytes());
- httpURLConnection.getResponseCode();
-
- Assert.fail("HTTP Client cannot connect to HTTPS source");
+ URL url = new URL("http://0.0.0.0:" + sslPort);
+ httpURLConnection = (HttpURLConnection) url.openConnection();
+ httpURLConnection.setDoInput(true);
+ httpURLConnection.setDoOutput(true);
+ httpURLConnection.setRequestMethod("POST");
+ httpURLConnection.getOutputStream().write(json.getBytes());
+ httpURLConnection.getResponseCode();
+
+ Assert.fail("HTTP Client cannot connect to HTTPS source");
} catch (Exception exception) {
- Assert.assertTrue("Exception expected", true);
+ Assert.assertTrue("Exception expected", true);
} finally {
- httpURLConnection.disconnect();
+ httpURLConnection.disconnect();
}
}
- private void takeWithEncoding(String encoding, int n, List<JSONEvent> events)
- throws Exception{
+ private void takeWithEncoding(String encoding, int n, List<JSONEvent> events) throws Exception {
Transaction tx = channel.getTransaction();
tx.begin();
Event e = null;
@@ -459,7 +471,7 @@ public class TestHTTPSource {
}
Event current = events.get(i++);
Assert.assertEquals(new String(current.getBody(), encoding),
- new String(e.getBody(), encoding));
+ new String(e.getBody(), encoding));
Assert.assertEquals(current.getHeaders(), e.getHeaders());
}
Assert.assertEquals(n, events.size());
@@ -480,7 +492,8 @@ public class TestHTTPSource {
private class ResultWrapper {
public final HttpResponse response;
public final List<JSONEvent> events;
- public ResultWrapper(HttpResponse resp, List<JSONEvent> events){
+
+ public ResultWrapper(HttpResponse resp, List<JSONEvent> events) {
this.response = resp;
this.events = events;
}
@@ -508,43 +521,39 @@ public class TestHTTPSource {
}
@Override
- public Socket createSocket(Socket socket, String s, int i, boolean b)
- throws IOException {
+ public Socket createSocket(Socket socket, String s, int i, boolean b) throws IOException {
SSLSocket sc = (SSLSocket) socketFactory.createSocket(socket, s, i, b);
sc.setEnabledProtocols(protocols);
return sc;
}
@Override
- public Socket createSocket(String s, int i)
- throws IOException, UnknownHostException {
- SSLSocket sc = (SSLSocket)socketFactory.createSocket(s, i);
+ public Socket createSocket(String s, int i) throws IOException, UnknownHostException {
+ SSLSocket sc = (SSLSocket) socketFactory.createSocket(s, i);
sc.setEnabledProtocols(protocols);
return sc;
}
@Override
public Socket createSocket(String s, int i, InetAddress inetAddress, int i2)
- throws IOException, UnknownHostException {
- SSLSocket sc = (SSLSocket)socketFactory.createSocket(s, i, inetAddress,
- i2);
+ throws IOException, UnknownHostException {
+ SSLSocket sc = (SSLSocket) socketFactory.createSocket(s, i, inetAddress, i2);
sc.setEnabledProtocols(protocols);
return sc;
}
@Override
- public Socket createSocket(InetAddress inetAddress, int i)
- throws IOException {
- SSLSocket sc = (SSLSocket)socketFactory.createSocket(inetAddress, i);
+ public Socket createSocket(InetAddress inetAddress, int i) throws IOException {
+ SSLSocket sc = (SSLSocket) socketFactory.createSocket(inetAddress, i);
sc.setEnabledProtocols(protocols);
return sc;
}
@Override
public Socket createSocket(InetAddress inetAddress, int i,
- InetAddress inetAddress2, int i2) throws IOException {
- SSLSocket sc = (SSLSocket)socketFactory.createSocket(inetAddress, i,
- inetAddress2, i2);
+ InetAddress inetAddress2, int i2) throws IOException {
+ SSLSocket sc = (SSLSocket) socketFactory.createSocket(inetAddress, i,
+ inetAddress2, i2);
sc.setEnabledProtocols(protocols);
return sc;
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/tools/TestTimestampRoundDownUtil.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/tools/TestTimestampRoundDownUtil.java b/flume-ng-core/src/test/java/org/apache/flume/tools/TestTimestampRoundDownUtil.java
index cc7eac0..1ac11ab 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/tools/TestTimestampRoundDownUtil.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/tools/TestTimestampRoundDownUtil.java
@@ -18,7 +18,6 @@
package org.apache.flume.tools;
-
import java.util.Calendar;
import junit.framework.Assert;
@@ -38,8 +37,7 @@ public class TestTimestampRoundDownUtil {
cal2.set(2012, 5, 15, 15, 12, 0);
cal2.set(Calendar.MILLISECOND, 0);
long timeToVerify = cal2.getTimeInMillis();
- long ret = TimestampRoundDownUtil.
- roundDownTimeStampSeconds(cal.getTimeInMillis(), 60);
+ long ret = TimestampRoundDownUtil.roundDownTimeStampSeconds(cal.getTimeInMillis(), 60);
System.out.println("Cal 1: " + cal.toString());
System.out.println("Cal 2: " + cal2.toString());
Assert.assertEquals(timeToVerify, ret);
@@ -56,8 +54,7 @@ public class TestTimestampRoundDownUtil {
cal2.set(2012, 5, 15, 15, 10, 0);
cal2.set(Calendar.MILLISECOND, 0);
long timeToVerify = cal2.getTimeInMillis();
- long ret = TimestampRoundDownUtil.
- roundDownTimeStampMinutes(cal.getTimeInMillis(), 5);
+ long ret = TimestampRoundDownUtil.roundDownTimeStampMinutes(cal.getTimeInMillis(), 5);
System.out.println("Cal 1: " + cal.toString());
System.out.println("Cal 2: " + cal2.toString());
Assert.assertEquals(timeToVerify, ret);
@@ -74,8 +71,7 @@ public class TestTimestampRoundDownUtil {
cal2.set(2012, 5, 15, 14, 0, 0);
cal2.set(Calendar.MILLISECOND, 0);
long timeToVerify = cal2.getTimeInMillis();
- long ret = TimestampRoundDownUtil.
- roundDownTimeStampHours(cal.getTimeInMillis(), 2);
+ long ret = TimestampRoundDownUtil.roundDownTimeStampHours(cal.getTimeInMillis(), 2);
System.out.println("Cal 1: " + ret);
System.out.println("Cal 2: " + cal2.toString());
Assert.assertEquals(timeToVerify, ret);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java b/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java
index b463899..0bdc820 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java
@@ -51,8 +51,8 @@ public class TestVersionInfo {
!VersionInfo.getSrcChecksum().equals("Unknown"));
// check getBuildVersion() return format
- assertTrue("getBuildVersion returned unexpected format",VersionInfo.
- getBuildVersion().matches(".+from.+by.+on.+source checksum.+"));
+ assertTrue("getBuildVersion returned unexpected format",
+ VersionInfo.getBuildVersion().matches(".+from.+by.+on.+source checksum.+"));
//"Unknown" when build without svn or git
assertNotNull("getRevision returned null", VersionInfo.getRevision());
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgent.java
----------------------------------------------------------------------
diff --git a/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgent.java b/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgent.java
index 241e2b5..032a4f8 100644
--- a/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgent.java
+++ b/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgent.java
@@ -95,14 +95,14 @@ public class TestEmbeddedAgent {
@After
public void tearDown() throws Exception {
- if(agent != null) {
+ if (agent != null) {
try {
agent.stop();
} catch (Exception e) {
LOGGER.debug("Error shutting down agent", e);
}
}
- if(nettyServer != null) {
+ if (nettyServer != null) {
try {
nettyServer.close();
} catch (Exception e) {
@@ -118,7 +118,7 @@ public class TestEmbeddedAgent {
agent.put(EventBuilder.withBody(body, headers));
Event event;
- while((event = eventCollector.poll()) == null) {
+ while ((event = eventCollector.poll()) == null) {
Thread.sleep(500L);
}
Assert.assertNotNull(event);
@@ -135,7 +135,7 @@ public class TestEmbeddedAgent {
agent.putAll(events);
Event event;
- while((event = eventCollector.poll()) == null) {
+ while ((event = eventCollector.poll()) == null) {
Thread.sleep(500L);
}
Assert.assertNotNull(event);
@@ -155,7 +155,7 @@ public class TestEmbeddedAgent {
agent.put(EventBuilder.withBody(body, headers));
Event event;
- while((event = eventCollector.poll()) == null) {
+ while ((event = eventCollector.poll()) == null) {
Thread.sleep(500L);
}
Assert.assertNotNull(event);
@@ -176,13 +176,13 @@ public class TestEmbeddedAgent {
embedAgent.putAll(events);
Event event;
- while((event = eventCollector.poll()) == null) {
+ while ((event = eventCollector.poll()) == null) {
Thread.sleep(500L);
}
Assert.assertNotNull(event);
Assert.assertArrayEquals(body, event.getBody());
Assert.assertEquals(headers, event.getHeaders());
- if(embedAgent != null) {
+ if (embedAgent != null) {
try {
embedAgent.stop();
} catch (Exception e) {
@@ -191,14 +191,13 @@ public class TestEmbeddedAgent {
}
}
-
static class EventCollector implements AvroSourceProtocol {
private final Queue<AvroFlumeEvent> eventQueue =
new LinkedBlockingQueue<AvroFlumeEvent>();
public Event poll() {
AvroFlumeEvent avroEvent = eventQueue.poll();
- if(avroEvent != null) {
+ if (avroEvent != null) {
return EventBuilder.withBody(avroEvent.getBody().array(),
toStringMap(avroEvent.getHeaders()));
}
@@ -216,10 +215,9 @@ public class TestEmbeddedAgent {
return Status.OK;
}
}
- private static Map<String, String> toStringMap(
- Map<CharSequence, CharSequence> charSeqMap) {
- Map<String, String> stringMap =
- new HashMap<String, String>();
+
+ private static Map<String, String> toStringMap(Map<CharSequence, CharSequence> charSeqMap) {
+ Map<String, String> stringMap = new HashMap<String, String>();
for (Map.Entry<CharSequence, CharSequence> entry : charSeqMap.entrySet()) {
stringMap.put(entry.getKey().toString(), entry.getValue().toString());
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentConfiguration.java
----------------------------------------------------------------------
diff --git a/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentConfiguration.java b/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentConfiguration.java
index f4a9a58..ed26294 100644
--- a/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentConfiguration.java
+++ b/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentConfiguration.java
@@ -34,8 +34,7 @@ public class TestEmbeddedAgentConfiguration {
@Before
public void setUp() throws Exception {
properties = Maps.newHashMap();
- properties.put("source.type", EmbeddedAgentConfiguration.
- SOURCE_TYPE_EMBEDDED);
+ properties.put("source.type", EmbeddedAgentConfiguration.SOURCE_TYPE_EMBEDDED);
properties.put("channel.type", "memory");
properties.put("channel.capacity", "200");
properties.put("sinks", "sink1 sink2");
@@ -50,28 +49,23 @@ public class TestEmbeddedAgentConfiguration {
properties.put("source.interceptors.i1.type", "timestamp");
}
-
@Test
public void testFullSourceType() throws Exception {
- doTestExcepted(EmbeddedAgentConfiguration.
- configure("test1", properties));
+ doTestExcepted(EmbeddedAgentConfiguration.configure("test1", properties));
}
@Test
public void testMissingSourceType() throws Exception {
Assert.assertNotNull(properties.remove("source.type"));
- doTestExcepted(EmbeddedAgentConfiguration.
- configure("test1", properties));
+ doTestExcepted(EmbeddedAgentConfiguration.configure("test1", properties));
}
@Test
public void testShortSourceType() throws Exception {
properties.put("source.type", "EMBEDDED");
- doTestExcepted(EmbeddedAgentConfiguration.
- configure("test1", properties));
+ doTestExcepted(EmbeddedAgentConfiguration.configure("test1", properties));
}
-
public void doTestExcepted(Map<String, String> actual) throws Exception {
Map<String, String> expected = Maps.newHashMap();
expected.put("test1.channels", "channel-test1");
@@ -91,8 +85,8 @@ public class TestEmbeddedAgentConfiguration {
expected.put("test1.sinks.sink2.type", "avro");
expected.put("test1.sources", "source-test1");
expected.put("test1.sources.source-test1.channels", "channel-test1");
- expected.put("test1.sources.source-test1.type", EmbeddedAgentConfiguration.
- SOURCE_TYPE_EMBEDDED);
+ expected.put("test1.sources.source-test1.type",
+ EmbeddedAgentConfiguration.SOURCE_TYPE_EMBEDDED);
expected.put("test1.sources.source-test1.interceptors", "i1");
expected.put("test1.sources.source-test1.interceptors.i1.type", "timestamp");
Assert.assertEquals(expected, actual);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentEmbeddedSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentEmbeddedSource.java b/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentEmbeddedSource.java
index 9d85e6e..c122a12 100644
--- a/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentEmbeddedSource.java
+++ b/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentEmbeddedSource.java
@@ -51,7 +51,6 @@ public class TestEmbeddedAgentEmbeddedSource {
private Channel channel;
private SinkRunner sinkRunner;
-
@Before
public void setUp() throws Exception {
@@ -81,26 +80,31 @@ public class TestEmbeddedAgentEmbeddedSource {
result.put("source", sourceRunner);
return ImmutableMap.copyOf(result);
}
+
@Override
public ImmutableMap<String, SinkRunner> getSinkRunners() {
Map<String, SinkRunner> result = Maps.newHashMap();
result.put("sink", sinkRunner);
return ImmutableMap.copyOf(result);
}
+
@Override
public ImmutableMap<String, Channel> getChannels() {
Map<String, Channel> result = Maps.newHashMap();
result.put("channel", channel);
return ImmutableMap.copyOf(result);
}
+
@Override
public void addSourceRunner(String name, SourceRunner sourceRunner) {
throw new UnsupportedOperationException();
}
+
@Override
public void addSinkRunner(String name, SinkRunner sinkRunner) {
throw new UnsupportedOperationException();
}
+
@Override
public void addChannel(String name, Channel channel) {
throw new UnsupportedOperationException();
@@ -122,7 +126,6 @@ public class TestEmbeddedAgentEmbeddedSource {
verify(sinkRunner, times(1)).start();
}
-
@Test
public void testStop() {
agent.configure(properties);
@@ -138,16 +141,19 @@ public class TestEmbeddedAgentEmbeddedSource {
doThrow(new LocalRuntimeException()).when(sourceRunner).start();
startExpectingLocalRuntimeException();
}
+
@Test
public void testStartChannelThrowsException() {
doThrow(new LocalRuntimeException()).when(channel).start();
startExpectingLocalRuntimeException();
}
+
@Test
public void testStartSinkThrowsException() {
doThrow(new LocalRuntimeException()).when(sinkRunner).start();
startExpectingLocalRuntimeException();
}
+
private void startExpectingLocalRuntimeException() {
agent.configure(properties);
try {
@@ -160,9 +166,11 @@ public class TestEmbeddedAgentEmbeddedSource {
verify(channel, times(1)).stop();
verify(sinkRunner, times(1)).stop();
}
+
private static class LocalRuntimeException extends RuntimeException {
private static final long serialVersionUID = 116546244849853151L;
}
+
@Test
public void testPut() throws EventDeliveryException {
Event event = new SimpleEvent();
@@ -171,6 +179,7 @@ public class TestEmbeddedAgentEmbeddedSource {
agent.put(event);
verify(source, times(1)).put(event);
}
+
@Test
public void testPutAll() throws EventDeliveryException {
Event event = new SimpleEvent();
@@ -181,12 +190,14 @@ public class TestEmbeddedAgentEmbeddedSource {
agent.putAll(events);
verify(source, times(1)).putAll(events);
}
+
@Test(expected = IllegalStateException.class)
public void testPutNotStarted() throws EventDeliveryException {
Event event = new SimpleEvent();
agent.configure(properties);
agent.put(event);
}
+
@Test(expected = IllegalStateException.class)
public void testPutAllNotStarted() throws EventDeliveryException {
Event event = new SimpleEvent();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentState.java
----------------------------------------------------------------------
diff --git a/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentState.java b/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentState.java
index a14a87e..0f0ad23 100644
--- a/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentState.java
+++ b/flume-ng-embedded-agent/src/test/java/org/apache/flume/agent/embedded/TestEmbeddedAgentState.java
@@ -18,19 +18,19 @@
*/
package org.apache.flume.agent.embedded;
-import java.util.Map;
-
+import com.google.common.base.Throwables;
+import com.google.common.collect.Maps;
import org.apache.flume.FlumeException;
import org.junit.Before;
import org.junit.Test;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Maps;
+import java.util.Map;
public class TestEmbeddedAgentState {
private static final String HOSTNAME = "localhost";
private EmbeddedAgent agent;
private Map<String, String> properties;
+
@Before
public void setUp() throws Exception {
agent = new EmbeddedAgent("dummy");
@@ -47,13 +47,13 @@ public class TestEmbeddedAgentState {
properties.put("processor.type", "load_balance");
}
- @Test(expected=FlumeException.class)
+ @Test(expected = FlumeException.class)
public void testConfigureWithBadSourceType() {
properties.put(EmbeddedAgentConfiguration.SOURCE_TYPE, "bad");
agent.configure(properties);
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testConfigureWhileStarted() {
try {
agent.configure(properties);
@@ -63,13 +63,14 @@ public class TestEmbeddedAgentState {
}
agent.configure(properties);
}
+
@Test
public void testConfigureMultipleTimes() {
agent.configure(properties);
agent.configure(properties);
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testStartWhileStarted() {
try {
agent.configure(properties);
@@ -79,15 +80,18 @@ public class TestEmbeddedAgentState {
}
agent.start();
}
- @Test(expected=IllegalStateException.class)
+
+ @Test(expected = IllegalStateException.class)
public void testStartUnconfigured() {
agent.start();
}
- @Test(expected=IllegalStateException.class)
+
+ @Test(expected = IllegalStateException.class)
public void testStopBeforeConfigure() {
agent.stop();
}
- @Test(expected=IllegalStateException.class)
+
+ @Test(expected = IllegalStateException.class)
public void testStoppedWhileStopped() {
try {
agent.configure(properties);
@@ -96,7 +100,8 @@ public class TestEmbeddedAgentState {
}
agent.stop();
}
- @Test(expected=IllegalStateException.class)
+
+ @Test(expected = IllegalStateException.class)
public void testStopAfterStop() {
try {
agent.configure(properties);
@@ -107,7 +112,8 @@ public class TestEmbeddedAgentState {
}
agent.stop();
}
- @Test(expected=IllegalStateException.class)
+
+ @Test(expected = IllegalStateException.class)
public void testStopAfterConfigure() {
try {
agent.configure(properties);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-legacy-sources/flume-avro-source/src/test/java/org/apache/flume/source/avroLegacy/TestLegacyAvroSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-legacy-sources/flume-avro-source/src/test/java/org/apache/flume/source/avroLegacy/TestLegacyAvroSource.java b/flume-ng-legacy-sources/flume-avro-source/src/test/java/org/apache/flume/source/avroLegacy/TestLegacyAvroSource.java
index 6e3eb53..610aa64 100644
--- a/flume-ng-legacy-sources/flume-avro-source/src/test/java/org/apache/flume/source/avroLegacy/TestLegacyAvroSource.java
+++ b/flume-ng-legacy-sources/flume-avro-source/src/test/java/org/apache/flume/source/avroLegacy/TestLegacyAvroSource.java
@@ -19,13 +19,9 @@
package org.apache.flume.source.avroLegacy;
-import java.io.IOException;
-import java.net.URL;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
+import com.cloudera.flume.handlers.avro.AvroFlumeOGEvent;
+import com.cloudera.flume.handlers.avro.FlumeOGEventAvroServer;
+import com.cloudera.flume.handlers.avro.Priority;
import org.apache.avro.ipc.HttpTransceiver;
import org.apache.avro.ipc.Transceiver;
import org.apache.avro.ipc.specific.SpecificRequestor;
@@ -40,9 +36,6 @@ import org.apache.flume.channel.ReplicatingChannelSelector;
import org.apache.flume.conf.Configurables;
import org.apache.flume.lifecycle.LifecycleController;
import org.apache.flume.lifecycle.LifecycleState;
-import com.cloudera.flume.handlers.avro.AvroFlumeOGEvent;
-import com.cloudera.flume.handlers.avro.FlumeOGEventAvroServer;
-import com.cloudera.flume.handlers.avro.Priority;
import org.jboss.netty.channel.ChannelException;
import org.junit.Assert;
import org.junit.Before;
@@ -50,6 +43,12 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
public class TestLegacyAvroSource {
@@ -143,10 +142,10 @@ public class TestLegacyAvroSource {
FlumeOGEventAvroServer client = SpecificRequestor.getClient(
FlumeOGEventAvroServer.class, http);
- AvroFlumeOGEvent avroEvent = AvroFlumeOGEvent.newBuilder().setHost("foo").
- setPriority(Priority.INFO).setNanos(0).setTimestamp(1).
- setFields(new HashMap<CharSequence, ByteBuffer> ()).
- setBody(ByteBuffer.wrap("foo".getBytes())).build();
+ AvroFlumeOGEvent avroEvent = AvroFlumeOGEvent.newBuilder().setHost("foo")
+ .setPriority(Priority.INFO).setNanos(0).setTimestamp(1)
+ .setFields(new HashMap<CharSequence, ByteBuffer>())
+ .setBody(ByteBuffer.wrap("foo".getBytes())).build();
client.append(avroEvent);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-legacy-sources/flume-thrift-source/src/test/java/org/apache/flume/source/thriftLegacy/TestThriftLegacySource.java
----------------------------------------------------------------------
diff --git a/flume-ng-legacy-sources/flume-thrift-source/src/test/java/org/apache/flume/source/thriftLegacy/TestThriftLegacySource.java b/flume-ng-legacy-sources/flume-thrift-source/src/test/java/org/apache/flume/source/thriftLegacy/TestThriftLegacySource.java
index d8a6872..f228dde 100644
--- a/flume-ng-legacy-sources/flume-thrift-source/src/test/java/org/apache/flume/source/thriftLegacy/TestThriftLegacySource.java
+++ b/flume-ng-legacy-sources/flume-thrift-source/src/test/java/org/apache/flume/source/thriftLegacy/TestThriftLegacySource.java
@@ -19,15 +19,10 @@
package org.apache.flume.source.thriftLegacy;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
+import com.cloudera.flume.handlers.thrift.Priority;
+import com.cloudera.flume.handlers.thrift.ThriftFlumeEvent;
+import com.cloudera.flume.handlers.thrift.ThriftFlumeEventServer.Client;
import org.apache.flume.Channel;
-import org.apache.flume.ChannelException;
import org.apache.flume.ChannelSelector;
import org.apache.flume.Context;
import org.apache.flume.Event;
@@ -39,25 +34,27 @@ import org.apache.flume.channel.ReplicatingChannelSelector;
import org.apache.flume.conf.Configurables;
import org.apache.flume.lifecycle.LifecycleController;
import org.apache.flume.lifecycle.LifecycleState;
-
-import com.cloudera.flume.handlers.thrift.Priority;
-import com.cloudera.flume.handlers.thrift.ThriftFlumeEvent;
-import com.cloudera.flume.handlers.thrift.ThriftFlumeEventServer.Client;
-//EventStatus.java Priority.java ThriftFlumeEvent.java ThriftFlumeEventServer.java
-
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+//EventStatus.java Priority.java ThriftFlumeEvent.java ThriftFlumeEventServer.java
+
public class TestThriftLegacySource {
private static final Logger logger = LoggerFactory
@@ -75,7 +72,8 @@ public class TestThriftLegacySource {
this.host = host;
this.port = port;
}
- public void append(ThriftFlumeEvent evt){
+
+ public void append(ThriftFlumeEvent evt) {
TTransport transport;
try {
transport = new TSocket(host, port);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractConfigurationProvider.java b/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractConfigurationProvider.java
index 15a478d..e27d8f7 100644
--- a/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractConfigurationProvider.java
+++ b/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractConfigurationProvider.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,8 @@
*/
package org.apache.flume.node;
-import java.util.Map;
-
+import com.google.common.collect.Maps;
import junit.framework.Assert;
-
import org.apache.flume.Channel;
import org.apache.flume.ChannelException;
import org.apache.flume.Context;
@@ -36,7 +34,7 @@ import org.apache.flume.sink.AbstractSink;
import org.apache.flume.source.AbstractSource;
import org.junit.Test;
-import com.google.common.collect.Maps;
+import java.util.Map;
public class TestAbstractConfigurationProvider {
@@ -44,7 +42,7 @@ public class TestAbstractConfigurationProvider {
public void testDispoableChannel() throws Exception {
String agentName = "agent1";
Map<String, String> properties = getPropertiesForChannel(agentName,
- DisposableChannel.class.getName());
+ DisposableChannel.class.getName());
MemoryConfigurationProvider provider =
new MemoryConfigurationProvider(agentName, properties);
MaterializedConfiguration config1 = provider.getConfiguration();
@@ -60,7 +58,7 @@ public class TestAbstractConfigurationProvider {
public void testReusableChannel() throws Exception {
String agentName = "agent1";
Map<String, String> properties = getPropertiesForChannel(agentName,
- RecyclableChannel.class.getName());
+ RecyclableChannel.class.getName());
MemoryConfigurationProvider provider =
new MemoryConfigurationProvider(agentName, properties);
@@ -79,7 +77,7 @@ public class TestAbstractConfigurationProvider {
public void testUnspecifiedChannel() throws Exception {
String agentName = "agent1";
Map<String, String> properties = getPropertiesForChannel(agentName,
- UnspecifiedChannel.class.getName());
+ UnspecifiedChannel.class.getName());
MemoryConfigurationProvider provider =
new MemoryConfigurationProvider(agentName, properties);
@@ -98,9 +96,11 @@ public class TestAbstractConfigurationProvider {
public void testReusableChannelNotReusedLater() throws Exception {
String agentName = "agent1";
Map<String, String> propertiesReusable = getPropertiesForChannel(agentName,
- RecyclableChannel.class.getName());
+ RecyclableChannel.class
+ .getName());
Map<String, String> propertiesDispoable = getPropertiesForChannel(agentName,
- DisposableChannel.class.getName());
+ DisposableChannel.class
+ .getName());
MemoryConfigurationProvider provider =
new MemoryConfigurationProvider(agentName, propertiesReusable);
MaterializedConfiguration config1 = provider.getConfiguration();
@@ -127,7 +127,7 @@ public class TestAbstractConfigurationProvider {
String channelType = "memory";
String sinkType = "null";
Map<String, String> properties = getProperties(agentName, sourceType,
- channelType, sinkType);
+ channelType, sinkType);
MemoryConfigurationProvider provider =
new MemoryConfigurationProvider(agentName, properties);
MaterializedConfiguration config = provider.getConfiguration();
@@ -135,6 +135,7 @@ public class TestAbstractConfigurationProvider {
Assert.assertTrue(config.getChannels().size() == 1);
Assert.assertTrue(config.getSinkRunners().size() == 1);
}
+
@Test
public void testChannelThrowsExceptionDuringConfiguration() throws Exception {
String agentName = "agent1";
@@ -142,7 +143,7 @@ public class TestAbstractConfigurationProvider {
String channelType = UnconfigurableChannel.class.getName();
String sinkType = "null";
Map<String, String> properties = getProperties(agentName, sourceType,
- channelType, sinkType);
+ channelType, sinkType);
MemoryConfigurationProvider provider =
new MemoryConfigurationProvider(agentName, properties);
MaterializedConfiguration config = provider.getConfiguration();
@@ -150,6 +151,7 @@ public class TestAbstractConfigurationProvider {
Assert.assertTrue(config.getChannels().size() == 0);
Assert.assertTrue(config.getSinkRunners().size() == 0);
}
+
@Test
public void testSinkThrowsExceptionDuringConfiguration() throws Exception {
String agentName = "agent1";
@@ -157,7 +159,7 @@ public class TestAbstractConfigurationProvider {
String channelType = "memory";
String sinkType = UnconfigurableSink.class.getName();
Map<String, String> properties = getProperties(agentName, sourceType,
- channelType, sinkType);
+ channelType, sinkType);
MemoryConfigurationProvider provider =
new MemoryConfigurationProvider(agentName, properties);
MaterializedConfiguration config = provider.getConfiguration();
@@ -165,6 +167,7 @@ public class TestAbstractConfigurationProvider {
Assert.assertTrue(config.getChannels().size() == 1);
Assert.assertTrue(config.getSinkRunners().size() == 0);
}
+
@Test
public void testSourceAndSinkThrowExceptionDuringConfiguration()
throws Exception {
@@ -173,7 +176,7 @@ public class TestAbstractConfigurationProvider {
String channelType = "memory";
String sinkType = UnconfigurableSink.class.getName();
Map<String, String> properties = getProperties(agentName, sourceType,
- channelType, sinkType);
+ channelType, sinkType);
MemoryConfigurationProvider provider =
new MemoryConfigurationProvider(agentName, properties);
MaterializedConfiguration config = provider.getConfiguration();
@@ -181,8 +184,10 @@ public class TestAbstractConfigurationProvider {
Assert.assertTrue(config.getChannels().size() == 0);
Assert.assertTrue(config.getSinkRunners().size() == 0);
}
+
private Map<String, String> getProperties(String agentName,
- String sourceType, String channelType, String sinkType) {
+ String sourceType, String channelType,
+ String sinkType) {
Map<String, String> properties = Maps.newHashMap();
properties.put(agentName + ".sources", "source1");
properties.put(agentName + ".channels", "channel1");
@@ -195,12 +200,14 @@ public class TestAbstractConfigurationProvider {
properties.put(agentName + ".sinks.sink1.channel", "channel1");
return properties;
}
+
private Map<String, String> getPropertiesForChannel(String agentName, String channelType) {
return getProperties(agentName, "seq", channelType, "null");
}
public static class MemoryConfigurationProvider extends AbstractConfigurationProvider {
private Map<String, String> properties;
+
public MemoryConfigurationProvider(String agentName, Map<String, String> properties) {
super(agentName);
this.properties = properties;
@@ -215,81 +222,95 @@ public class TestAbstractConfigurationProvider {
return new FlumeConfiguration(properties);
}
}
+
@Disposable
public static class DisposableChannel extends AbstractChannel {
@Override
public void put(Event event) throws ChannelException {
throw new UnsupportedOperationException();
}
+
@Override
public Event take() throws ChannelException {
throw new UnsupportedOperationException();
- }
+ }
+
@Override
public Transaction getTransaction() {
throw new UnsupportedOperationException();
}
}
+
@Recyclable
public static class RecyclableChannel extends AbstractChannel {
@Override
public void put(Event event) throws ChannelException {
throw new UnsupportedOperationException();
}
+
@Override
public Event take() throws ChannelException {
throw new UnsupportedOperationException();
- }
+ }
+
@Override
public Transaction getTransaction() {
throw new UnsupportedOperationException();
}
}
+
public static class UnspecifiedChannel extends AbstractChannel {
@Override
public void put(Event event) throws ChannelException {
throw new UnsupportedOperationException();
}
+
@Override
public Event take() throws ChannelException {
throw new UnsupportedOperationException();
- }
+ }
+
@Override
public Transaction getTransaction() {
throw new UnsupportedOperationException();
}
}
+
public static class UnconfigurableChannel extends AbstractChannel {
@Override
public void configure(Context context) {
throw new RuntimeException("expected");
}
+
@Override
public void put(Event event) throws ChannelException {
throw new UnsupportedOperationException();
}
+
@Override
public Event take() throws ChannelException {
throw new UnsupportedOperationException();
- }
+ }
+
@Override
public Transaction getTransaction() {
throw new UnsupportedOperationException();
}
}
- public static class UnconfigurableSource extends AbstractSource
- implements Configurable {
+
+ public static class UnconfigurableSource extends AbstractSource implements Configurable {
@Override
public void configure(Context context) {
throw new RuntimeException("expected");
}
}
- public static class UnconfigurableSink extends AbstractSink
- implements Configurable {
+
+ public static class UnconfigurableSink extends AbstractSink implements Configurable {
@Override
public void configure(Context context) {
throw new RuntimeException("expected");
}
+
@Override
public Status process() throws EventDeliveryException {
throw new UnsupportedOperationException();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractZooKeeperConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractZooKeeperConfigurationProvider.java b/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractZooKeeperConfigurationProvider.java
index 1ab4127..2e30634 100644
--- a/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractZooKeeperConfigurationProvider.java
+++ b/flume-ng-node/src/test/java/org/apache/flume/node/TestAbstractZooKeeperConfigurationProvider.java
@@ -18,15 +18,10 @@
package org.apache.flume.node;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import junit.framework.Assert;
-
import org.apache.commons.io.IOUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -38,8 +33,11 @@ import org.apache.flume.conf.FlumeConfigurationError;
import org.junit.After;
import org.junit.Before;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
public abstract class TestAbstractZooKeeperConfigurationProvider {
@@ -48,8 +46,7 @@ public abstract class TestAbstractZooKeeperConfigurationProvider {
protected static final String AGENT_NAME = "a1";
protected static final String AGENT_PATH =
- AbstractZooKeeperConfigurationProvider.DEFAULT_ZK_BASE_PATH
- + "/" + AGENT_NAME;
+ AbstractZooKeeperConfigurationProvider.DEFAULT_ZK_BASE_PATH + "/" + AGENT_NAME;
protected TestingServer zkServer;
protected CuratorFramework client;
@@ -112,10 +109,8 @@ public abstract class TestAbstractZooKeeperConfigurationProvider {
expected.add("host2 PROPERTY_VALUE_NULL");
expected.add("host2 AGENT_CONFIGURATION_INVALID");
List<String> actual = Lists.newArrayList();
- for (FlumeConfigurationError error : configuration
- .getConfigurationErrors()) {
- actual.add(error.getComponentName() + " "
- + error.getErrorType().toString());
+ for (FlumeConfigurationError error : configuration.getConfigurationErrors()) {
+ actual.add(error.getComponentName() + " " + error.getErrorType().toString());
}
Collections.sort(expected);
Collections.sort(actual);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java
----------------------------------------------------------------------
diff --git a/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java b/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java
index 930f2a2..affbd8c 100644
--- a/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java
+++ b/flume-ng-node/src/test/java/org/apache/flume/node/TestApplication.java
@@ -44,13 +44,13 @@ import com.google.common.io.Files;
public class TestApplication {
-
private File baseDir;
@Before
public void setup() throws Exception {
baseDir = Files.createTempDir();
}
+
@After
public void tearDown() throws Exception {
FileUtils.deleteDirectory(baseDir);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-node/src/test/java/org/apache/flume/node/TestPollingPropertiesFileConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/flume-ng-node/src/test/java/org/apache/flume/node/TestPollingPropertiesFileConfigurationProvider.java b/flume-ng-node/src/test/java/org/apache/flume/node/TestPollingPropertiesFileConfigurationProvider.java
index eed22ee..480f6a5 100644
--- a/flume-ng-node/src/test/java/org/apache/flume/node/TestPollingPropertiesFileConfigurationProvider.java
+++ b/flume-ng-node/src/test/java/org/apache/flume/node/TestPollingPropertiesFileConfigurationProvider.java
@@ -36,7 +36,6 @@ import com.google.common.io.Files;
public class TestPollingPropertiesFileConfigurationProvider {
-
private static final File TESTFILE = new File(
TestPollingPropertiesFileConfigurationProvider.class.getClassLoader()
.getResource("flume-conf.properties").getFile());
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-node/src/test/java/org/apache/flume/node/TestPropertiesFileConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/flume-ng-node/src/test/java/org/apache/flume/node/TestPropertiesFileConfigurationProvider.java b/flume-ng-node/src/test/java/org/apache/flume/node/TestPropertiesFileConfigurationProvider.java
index 84a8cfd..4875c56 100644
--- a/flume-ng-node/src/test/java/org/apache/flume/node/TestPropertiesFileConfigurationProvider.java
+++ b/flume-ng-node/src/test/java/org/apache/flume/node/TestPropertiesFileConfigurationProvider.java
@@ -17,13 +17,9 @@
*/
package org.apache.flume.node;
-import java.io.File;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import junit.framework.Assert;
-
import org.apache.flume.conf.FlumeConfiguration;
import org.apache.flume.conf.FlumeConfiguration.AgentConfiguration;
import org.apache.flume.conf.FlumeConfigurationError;
@@ -33,14 +29,15 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
public class TestPropertiesFileConfigurationProvider {
-
- private static final Logger LOGGER = LoggerFactory
- .getLogger(TestPropertiesFileConfigurationProvider.class);
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(TestPropertiesFileConfigurationProvider.class);
private static final File TESTFILE = new File(
TestPropertiesFileConfigurationProvider.class.getClassLoader()
@@ -83,23 +80,20 @@ public class TestPropertiesFileConfigurationProvider {
expected.add("host2 PROPERTY_VALUE_NULL");
expected.add("host2 AGENT_CONFIGURATION_INVALID");
List<String> actual = Lists.newArrayList();
- for(FlumeConfigurationError error : configuration.getConfigurationErrors()) {
+ for (FlumeConfigurationError error : configuration.getConfigurationErrors()) {
actual.add(error.getComponentName() + " " + error.getErrorType().toString());
}
Collections.sort(expected);
Collections.sort(actual);
Assert.assertEquals(expected, actual);
-
AgentConfiguration agentConfiguration =
configuration.getConfigurationFor("host1");
Assert.assertNotNull(agentConfiguration);
-
LOGGER.info(agentConfiguration.getPrevalidationConfig());
LOGGER.info(agentConfiguration.getPostvalidationConfig());
-
Set<String> sources = Sets.newHashSet("source1");
Set<String> sinks = Sets.newHashSet("sink1");
Set<String> channels = Sets.newHashSet("channel1");
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-node/src/test/java/org/apache/flume/source/TestNetcatSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-node/src/test/java/org/apache/flume/source/TestNetcatSource.java b/flume-ng-node/src/test/java/org/apache/flume/source/TestNetcatSource.java
index 91fbf63..a597a31 100644
--- a/flume-ng-node/src/test/java/org/apache/flume/source/TestNetcatSource.java
+++ b/flume-ng-node/src/test/java/org/apache/flume/source/TestNetcatSource.java
@@ -19,19 +19,6 @@
package org.apache.flume.source;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.Writer;
-import java.net.InetSocketAddress;
-import java.nio.channels.Channels;
-import java.nio.channels.SocketChannel;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.Collection;
-import java.util.Arrays;
-
import com.google.common.collect.Lists;
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
@@ -49,12 +36,25 @@ import org.apache.flume.lifecycle.LifecycleException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
-import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Writer;
+import java.net.InetSocketAddress;
+import java.nio.channels.Channels;
+import java.nio.channels.SocketChannel;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
@RunWith(value = Parameterized.class)
public class TestNetcatSource {
@@ -72,7 +72,7 @@ public class TestNetcatSource {
@Parameters
public static Collection data() {
Object[][] data = new Object[][] { { true }, { false } };
- return Arrays.asList(data);
+ return Arrays.asList(data);
}
@Before
@@ -99,7 +99,7 @@ public class TestNetcatSource {
ExecutorService executor = Executors.newFixedThreadPool(3);
boolean bound = false;
- for(int i = 0; i < 100 && !bound; i++) {
+ for (int i = 0; i < 100 && !bound; i++) {
try {
Context context = new Context();
context.put("bind", "0.0.0.0");
@@ -131,10 +131,10 @@ public class TestNetcatSource {
writer.flush();
if (ackEveryEvent) {
- String response = reader.readLine();
- Assert.assertEquals("Server should return OK", "OK", response);
+ String response = reader.readLine();
+ Assert.assertEquals("Server should return OK", "OK", response);
} else {
- Assert.assertFalse("Server should not return anything", reader.ready());
+ Assert.assertFalse("Server should not return anything", reader.ready());
}
clientChannel.close();
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sdk/src/test/java/org/apache/flume/api/RpcTestUtils.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/api/RpcTestUtils.java b/flume-ng-sdk/src/test/java/org/apache/flume/api/RpcTestUtils.java
index 8806860..d9355f7 100644
--- a/flume-ng-sdk/src/test/java/org/apache/flume/api/RpcTestUtils.java
+++ b/flume-ng-sdk/src/test/java/org/apache/flume/api/RpcTestUtils.java
@@ -18,13 +18,6 @@
*/
package org.apache.flume.api;
-import java.net.InetSocketAddress;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import java.util.concurrent.Executors;
-
import junit.framework.Assert;
import org.apache.avro.AvroRemoteException;
import org.apache.avro.ipc.NettyServer;
@@ -47,6 +40,13 @@ import org.jboss.netty.handler.codec.compression.ZlibEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.net.InetSocketAddress;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.Executors;
+
/**
* Helpers for Netty Avro RPC testing
*/
@@ -75,7 +75,9 @@ public class RpcTestUtils {
* @throws FlumeException
* @throws EventDeliveryException
*/
- public static void handlerSimpleAppendTest(AvroSourceProtocol handler, boolean enableServerCompression, boolean enableClientCompression, int compressionLevel)
+ public static void handlerSimpleAppendTest(AvroSourceProtocol handler,
+ boolean enableServerCompression,
+ boolean enableClientCompression, int compressionLevel)
throws FlumeException, EventDeliveryException {
NettyAvroRpcClient client = null;
Server server = startServer(handler, 0, enableServerCompression);
@@ -83,7 +85,8 @@ public class RpcTestUtils {
Properties starterProp = new Properties();
if (enableClientCompression) {
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "deflate");
- starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_LEVEL, "" + compressionLevel);
+ starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_LEVEL,
+ "" + compressionLevel);
} else {
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "none");
}
@@ -108,7 +111,9 @@ public class RpcTestUtils {
* @throws FlumeException
* @throws EventDeliveryException
*/
- public static void handlerBatchAppendTest(AvroSourceProtocol handler, boolean enableServerCompression, boolean enableClientCompression, int compressionLevel)
+ public static void handlerBatchAppendTest(AvroSourceProtocol handler,
+ boolean enableServerCompression,
+ boolean enableClientCompression, int compressionLevel)
throws FlumeException, EventDeliveryException {
NettyAvroRpcClient client = null;
Server server = startServer(handler, 0 , enableServerCompression);
@@ -117,7 +122,8 @@ public class RpcTestUtils {
Properties starterProp = new Properties();
if (enableClientCompression) {
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "deflate");
- starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_LEVEL, "" + compressionLevel);
+ starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_LEVEL,
+ "" + compressionLevel);
} else {
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_COMPRESSION_TYPE, "none");
}
@@ -161,28 +167,24 @@ public class RpcTestUtils {
/**
* Start a NettyServer, wait a moment for it to spin up, and return it.
*/
- public static Server startServer(AvroSourceProtocol handler, int port, boolean enableCompression) {
- Responder responder = new SpecificResponder(AvroSourceProtocol.class,
- handler);
+ public static Server startServer(AvroSourceProtocol handler, int port,
+ boolean enableCompression) {
+ Responder responder = new SpecificResponder(AvroSourceProtocol.class, handler);
Server server;
if (enableCompression) {
- server = new NettyServer(responder,
- new InetSocketAddress(localhost, port),
- new NioServerSocketChannelFactory
- (Executors .newCachedThreadPool(), Executors.newCachedThreadPool()),
- new CompressionChannelPipelineFactory(), null);
+ server = new NettyServer(responder, new InetSocketAddress(localhost, port),
+ new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
+ Executors.newCachedThreadPool()),
+ new CompressionChannelPipelineFactory(), null);
} else {
- server = new NettyServer(responder,
- new InetSocketAddress(localhost, port));
+ server = new NettyServer(responder, new InetSocketAddress(localhost, port));
}
server.start();
logger.info("Server started on hostname: {}, port: {}",
- new Object[] { localhost, Integer.toString(server.getPort()) });
+ new Object[] { localhost, Integer.toString(server.getPort()) });
try {
-
Thread.sleep(300L);
-
} catch (InterruptedException ex) {
logger.error("Thread interrupted. Exception follows.", ex);
Thread.currentThread().interrupt();
@@ -298,15 +300,13 @@ public class RpcTestUtils {
@Override
public Status append(AvroFlumeEvent event) throws AvroRemoteException {
logger.info("Failed: Received event from append(): {}",
- new String(event.getBody().array(), Charset.forName("UTF8")));
+ new String(event.getBody().array(), Charset.forName("UTF8")));
return Status.FAILED;
}
@Override
- public Status appendBatch(List<AvroFlumeEvent> events) throws
- AvroRemoteException {
- logger.info("Failed: Received {} events from appendBatch()",
- events.size());
+ public Status appendBatch(List<AvroFlumeEvent> events) throws AvroRemoteException {
+ logger.info("Failed: Received {} events from appendBatch()", events.size());
return Status.FAILED;
}
@@ -320,15 +320,14 @@ public class RpcTestUtils {
@Override
public Status append(AvroFlumeEvent event) throws AvroRemoteException {
logger.info("Unknown: Received event from append(): {}",
- new String(event.getBody().array(), Charset.forName("UTF8")));
+ new String(event.getBody().array(), Charset.forName("UTF8")));
return Status.UNKNOWN;
}
@Override
- public Status appendBatch(List<AvroFlumeEvent> events) throws
- AvroRemoteException {
+ public Status appendBatch(List<AvroFlumeEvent> events) throws AvroRemoteException {
logger.info("Unknown: Received {} events from appendBatch()",
- events.size());
+ events.size());
return Status.UNKNOWN;
}
@@ -342,22 +341,18 @@ public class RpcTestUtils {
@Override
public Status append(AvroFlumeEvent event) throws AvroRemoteException {
logger.info("Throwing: Received event from append(): {}",
- new String(event.getBody().array(), Charset.forName("UTF8")));
+ new String(event.getBody().array(), Charset.forName("UTF8")));
throw new AvroRemoteException("Handler smash!");
}
@Override
- public Status appendBatch(List<AvroFlumeEvent> events) throws
- AvroRemoteException {
- logger.info("Throwing: Received {} events from appendBatch()",
- events.size());
+ public Status appendBatch(List<AvroFlumeEvent> events) throws AvroRemoteException {
+ logger.info("Throwing: Received {} events from appendBatch()", events.size());
throw new AvroRemoteException("Handler smash!");
}
-
}
- private static class CompressionChannelPipelineFactory implements
- ChannelPipelineFactory {
+ private static class CompressionChannelPipelineFactory implements ChannelPipelineFactory {
@Override
public ChannelPipeline getPipeline() throws Exception {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sdk/src/test/java/org/apache/flume/api/TestFailoverRpcClient.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestFailoverRpcClient.java b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestFailoverRpcClient.java
index 64dc181..c3eb205 100644
--- a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestFailoverRpcClient.java
+++ b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestFailoverRpcClient.java
@@ -113,9 +113,7 @@ public class TestFailoverRpcClient {
server5.close();
Thread.sleep(1000L); // wait a second for the close to occur
Server server6 = RpcTestUtils.startServer(new OKAvroHandler(), s1Port);
- client
- .append(EventBuilder.withBody("Had a whole watermelon?",
- Charset.forName("UTF8")));
+ client.append(EventBuilder.withBody("Had a whole watermelon?", Charset.forName("UTF8")));
Assert.assertEquals(new InetSocketAddress("localhost", s1Port),
client.getLastConnectedServerAddress());
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sdk/src/test/java/org/apache/flume/api/TestLoadBalancingRpcClient.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestLoadBalancingRpcClient.java b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestLoadBalancingRpcClient.java
index 5d6828b..dc53d3f 100644
--- a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestLoadBalancingRpcClient.java
+++ b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestLoadBalancingRpcClient.java
@@ -18,14 +18,7 @@
*/
package org.apache.flume.api;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-
import junit.framework.Assert;
-
import org.apache.avro.ipc.Server;
import org.apache.flume.Event;
import org.apache.flume.EventDeliveryException;
@@ -37,12 +30,16 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class TestLoadBalancingRpcClient {
- private static final Logger LOGGER = LoggerFactory
- .getLogger(TestLoadBalancingRpcClient.class);
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+public class TestLoadBalancingRpcClient {
+ private static final Logger LOGGER = LoggerFactory.getLogger(TestLoadBalancingRpcClient.class);
- @Test(expected=FlumeException.class)
+ @Test(expected = FlumeException.class)
public void testCreatingLbClientSingleHost() {
Server server1 = null;
RpcClient c = null;
@@ -61,9 +58,10 @@ public class TestLoadBalancingRpcClient {
@Test
public void testTwoHostFailover() throws Exception {
- Server s1 = null, s2 = null;
+ Server s1 = null;
+ Server s2 = null;
RpcClient c = null;
- try{
+ try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
@@ -100,9 +98,10 @@ public class TestLoadBalancingRpcClient {
// This will fail without FLUME-1823
@Test(expected = EventDeliveryException.class)
public void testTwoHostFailoverThrowAfterClose() throws Exception {
- Server s1 = null, s2 = null;
+ Server s1 = null;
+ Server s2 = null;
RpcClient c = null;
- try{
+ try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
@@ -140,13 +139,15 @@ public class TestLoadBalancingRpcClient {
/**
* Ensure that we can tolerate a host that is completely down.
+ *
* @throws Exception
*/
@Test
public void testTwoHostsOneDead() throws Exception {
LOGGER.info("Running testTwoHostsOneDead...");
Server s1 = null;
- RpcClient c1 = null, c2 = null;
+ RpcClient c1 = null;
+ RpcClient c2 = null;
try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
s1 = RpcTestUtils.startServer(h1);
@@ -186,9 +187,10 @@ public class TestLoadBalancingRpcClient {
@Test
public void testTwoHostFailoverBatch() throws Exception {
- Server s1 = null, s2 = null;
+ Server s1 = null;
+ Server s2 = null;
RpcClient c = null;
- try{
+ try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
@@ -225,9 +227,10 @@ public class TestLoadBalancingRpcClient {
@Test
public void testLbDefaultClientTwoHosts() throws Exception {
- Server s1 = null, s2 = null;
+ Server s1 = null;
+ Server s2 = null;
RpcClient c = null;
- try{
+ try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
@@ -258,9 +261,10 @@ public class TestLoadBalancingRpcClient {
@Test
public void testLbDefaultClientTwoHostsBatch() throws Exception {
- Server s1 = null, s2 = null;
+ Server s1 = null;
+ Server s2 = null;
RpcClient c = null;
- try{
+ try {
LoadBalancedAvroHandler h1 = new LoadBalancedAvroHandler();
LoadBalancedAvroHandler h2 = new LoadBalancedAvroHandler();
@@ -296,10 +300,10 @@ public class TestLoadBalancingRpcClient {
Server[] s = new Server[NUM_HOSTS];
LoadBalancedAvroHandler[] h = new LoadBalancedAvroHandler[NUM_HOSTS];
RpcClient c = null;
- try{
+ try {
Properties p = new Properties();
StringBuilder hostList = new StringBuilder("");
- for (int i = 0; i<NUM_HOSTS; i++) {
+ for (int i = 0; i < NUM_HOSTS; i++) {
h[i] = new LoadBalancedAvroHandler();
s[i] = RpcTestUtils.startServer(h[i]);
String name = "h" + i;
@@ -328,7 +332,7 @@ public class TestLoadBalancingRpcClient {
Assert.assertTrue("Very unusual distribution", counts.size() > 2);
Assert.assertTrue("Missing events", total == NUM_EVENTS);
} finally {
- for (int i = 0; i<NUM_HOSTS; i++) {
+ for (int i = 0; i < NUM_HOSTS; i++) {
if (s[i] != null) s[i].close();
}
}
@@ -341,10 +345,10 @@ public class TestLoadBalancingRpcClient {
Server[] s = new Server[NUM_HOSTS];
LoadBalancedAvroHandler[] h = new LoadBalancedAvroHandler[NUM_HOSTS];
RpcClient c = null;
- try{
+ try {
Properties p = new Properties();
StringBuilder hostList = new StringBuilder("");
- for (int i = 0; i<NUM_HOSTS; i++) {
+ for (int i = 0; i < NUM_HOSTS; i++) {
h[i] = new LoadBalancedAvroHandler();
s[i] = RpcTestUtils.startServer(h[i]);
String name = "h" + i;
@@ -373,7 +377,7 @@ public class TestLoadBalancingRpcClient {
Assert.assertTrue("Very unusual distribution", counts.size() > 2);
Assert.assertTrue("Missing events", total == NUM_EVENTS);
} finally {
- for (int i = 0; i<NUM_HOSTS; i++) {
+ for (int i = 0; i < NUM_HOSTS; i++) {
if (s[i] != null) s[i].close();
}
}
@@ -386,10 +390,10 @@ public class TestLoadBalancingRpcClient {
Server[] s = new Server[NUM_HOSTS];
LoadBalancedAvroHandler[] h = new LoadBalancedAvroHandler[NUM_HOSTS];
RpcClient c = null;
- try{
+ try {
Properties p = new Properties();
StringBuilder hostList = new StringBuilder("");
- for (int i = 0; i<NUM_HOSTS; i++) {
+ for (int i = 0; i < NUM_HOSTS; i++) {
h[i] = new LoadBalancedAvroHandler();
s[i] = RpcTestUtils.startServer(h[i]);
String name = "h" + i;
@@ -418,24 +422,23 @@ public class TestLoadBalancingRpcClient {
Assert.assertTrue("Very unusual distribution", counts.size() == 1);
Assert.assertTrue("Missing events", total == NUM_EVENTS);
} finally {
- for (int i = 0; i<NUM_HOSTS; i++) {
+ for (int i = 0; i < NUM_HOSTS; i++) {
if (s[i] != null) s[i].close();
}
}
}
@Test
- public void testLbClientTenHostRoundRobinDistributionBatch() throws Exception
- {
+ public void testLbClientTenHostRoundRobinDistributionBatch() throws Exception {
final int NUM_HOSTS = 10;
final int NUM_EVENTS = 1000;
Server[] s = new Server[NUM_HOSTS];
LoadBalancedAvroHandler[] h = new LoadBalancedAvroHandler[NUM_HOSTS];
RpcClient c = null;
- try{
+ try {
Properties p = new Properties();
StringBuilder hostList = new StringBuilder("");
- for (int i = 0; i<NUM_HOSTS; i++) {
+ for (int i = 0; i < NUM_HOSTS; i++) {
h[i] = new LoadBalancedAvroHandler();
s[i] = RpcTestUtils.startServer(h[i]);
String name = "h" + i;
@@ -464,7 +467,7 @@ public class TestLoadBalancingRpcClient {
Assert.assertTrue("Very unusual distribution", counts.size() == 1);
Assert.assertTrue("Missing events", total == NUM_EVENTS);
} finally {
- for (int i = 0; i<NUM_HOSTS; i++) {
+ for (int i = 0; i < NUM_HOSTS; i++) {
if (s[i] != null) s[i].close();
}
}
@@ -474,10 +477,10 @@ public class TestLoadBalancingRpcClient {
public void testRandomBackoff() throws Exception {
Properties p = new Properties();
List<LoadBalancedAvroHandler> hosts =
- new ArrayList<LoadBalancedAvroHandler>();
+ new ArrayList<LoadBalancedAvroHandler>();
List<Server> servers = new ArrayList<Server>();
StringBuilder hostList = new StringBuilder("");
- for(int i = 0; i < 3;i++){
+ for (int i = 0; i < 3; i++) {
LoadBalancedAvroHandler s = new LoadBalancedAvroHandler();
hosts.add(s);
Server srv = RpcTestUtils.startServer(s);
@@ -499,7 +502,7 @@ public class TestLoadBalancingRpcClient {
// TODO: there is a remote possibility that s0 or s2
// never get hit by the random assignment
// and thus not backoffed, causing the test to fail
- for(int i=0; i < 50; i++) {
+ for (int i = 0; i < 50; i++) {
// a well behaved runner would always check the return.
c.append(EventBuilder.withBody(("test" + String.valueOf(i)).getBytes()));
}
@@ -525,11 +528,12 @@ public class TestLoadBalancingRpcClient {
Assert.assertEquals(50, hosts.get(1).getAppendCount());
Assert.assertEquals(0, hosts.get(2).getAppendCount());
}
+
@Test
public void testRoundRobinBackoffInitialFailure() throws EventDeliveryException {
Properties p = new Properties();
List<LoadBalancedAvroHandler> hosts =
- new ArrayList<LoadBalancedAvroHandler>();
+ new ArrayList<LoadBalancedAvroHandler>();
List<Server> servers = new ArrayList<Server>();
StringBuilder hostList = new StringBuilder("");
for (int i = 0; i < 3; i++) {
@@ -572,13 +576,13 @@ public class TestLoadBalancingRpcClient {
public void testRoundRobinBackoffIncreasingBackoffs() throws Exception {
Properties p = new Properties();
List<LoadBalancedAvroHandler> hosts =
- new ArrayList<LoadBalancedAvroHandler>();
+ new ArrayList<LoadBalancedAvroHandler>();
List<Server> servers = new ArrayList<Server>();
StringBuilder hostList = new StringBuilder("");
for (int i = 0; i < 3; i++) {
LoadBalancedAvroHandler s = new LoadBalancedAvroHandler();
hosts.add(s);
- if(i == 1) {
+ if (i == 1) {
s.setFailed();
}
Server srv = RpcTestUtils.startServer(s);
@@ -620,16 +624,17 @@ public class TestLoadBalancingRpcClient {
c.append(EventBuilder.withBody("testing".getBytes()));
}
- Assert.assertEquals( 2 + 2 + 1 + (numEvents/3), hosts.get(0).getAppendCount());
- Assert.assertEquals((numEvents/3), hosts.get(1).getAppendCount());
- Assert.assertEquals(1 + 1 + 2 + (numEvents/3), hosts.get(2).getAppendCount());
+ Assert.assertEquals(2 + 2 + 1 + (numEvents / 3), hosts.get(0).getAppendCount());
+ Assert.assertEquals((numEvents / 3), hosts.get(1).getAppendCount());
+ Assert.assertEquals(1 + 1 + 2 + (numEvents / 3), hosts.get(2).getAppendCount());
}
@Test
- public void testRoundRobinBackoffFailureRecovery() throws EventDeliveryException, InterruptedException {
+ public void testRoundRobinBackoffFailureRecovery()
+ throws EventDeliveryException, InterruptedException {
Properties p = new Properties();
List<LoadBalancedAvroHandler> hosts =
- new ArrayList<LoadBalancedAvroHandler>();
+ new ArrayList<LoadBalancedAvroHandler>();
List<Server> servers = new ArrayList<Server>();
StringBuilder hostList = new StringBuilder("");
for (int i = 0; i < 3; i++) {
@@ -660,13 +665,13 @@ public class TestLoadBalancingRpcClient {
Thread.sleep(3000);
int numEvents = 60;
- for(int i = 0; i < numEvents; i++){
+ for (int i = 0; i < numEvents; i++) {
c.append(EventBuilder.withBody("testing".getBytes()));
}
- Assert.assertEquals(2 + (numEvents/3) , hosts.get(0).getAppendCount());
- Assert.assertEquals(0 + (numEvents/3), hosts.get(1).getAppendCount());
- Assert.assertEquals(1 + (numEvents/3), hosts.get(2).getAppendCount());
+ Assert.assertEquals(2 + (numEvents / 3), hosts.get(0).getAppendCount());
+ Assert.assertEquals(0 + (numEvents / 3), hosts.get(1).getAppendCount());
+ Assert.assertEquals(1 + (numEvents / 3), hosts.get(2).getAppendCount());
}
private List<Event> getBatchedEvent(int index) {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sdk/src/test/java/org/apache/flume/api/TestNettyAvroRpcClient.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestNettyAvroRpcClient.java b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestNettyAvroRpcClient.java
index cf4f415..6cd1454 100644
--- a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestNettyAvroRpcClient.java
+++ b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestNettyAvroRpcClient.java
@@ -87,7 +87,7 @@ public class TestNettyAvroRpcClient {
* @throws FlumeException
* @throws EventDeliveryException
*/
- @Test(expected=org.apache.flume.EventDeliveryException.class)
+ @Test(expected = org.apache.flume.EventDeliveryException.class)
public void testOKServerSimpleCompressionClientOnly() throws FlumeException,
EventDeliveryException {
RpcTestUtils.handlerSimpleAppendTest(new OKAvroHandler(), false, true, 6);
@@ -98,7 +98,7 @@ public class TestNettyAvroRpcClient {
* @throws FlumeException
* @throws EventDeliveryException
*/
- @Test(expected=org.apache.flume.EventDeliveryException.class)
+ @Test(expected = org.apache.flume.EventDeliveryException.class)
public void testOKServerSimpleCompressionServerOnly() throws FlumeException,
EventDeliveryException {
RpcTestUtils.handlerSimpleAppendTest(new OKAvroHandler(), true, false, 6);
@@ -142,7 +142,7 @@ public class TestNettyAvroRpcClient {
* @throws FlumeException
* @throws EventDeliveryException
*/
- @Test(expected=org.apache.flume.EventDeliveryException.class)
+ @Test(expected = org.apache.flume.EventDeliveryException.class)
public void testOKServerBatchCompressionServerOnly() throws FlumeException,
EventDeliveryException {
RpcTestUtils.handlerBatchAppendTest(new OKAvroHandler(), true, false, 6);
@@ -153,7 +153,7 @@ public class TestNettyAvroRpcClient {
* @throws FlumeException
* @throws EventDeliveryException
*/
- @Test(expected=org.apache.flume.EventDeliveryException.class)
+ @Test(expected = org.apache.flume.EventDeliveryException.class)
public void testOKServerBatchCompressionClientOnly() throws FlumeException,
EventDeliveryException {
RpcTestUtils.handlerBatchAppendTest(new OKAvroHandler(), false, true, 6);
@@ -164,7 +164,7 @@ public class TestNettyAvroRpcClient {
* Note: this test tries to connect to port 1 on localhost.
* @throws FlumeException
*/
- @Test(expected=FlumeException.class)
+ @Test(expected = FlumeException.class)
public void testUnableToConnect() throws FlumeException {
@SuppressWarnings("unused")
NettyAvroRpcClient client = new NettyAvroRpcClient();
@@ -214,7 +214,7 @@ public class TestNettyAvroRpcClient {
* @throws EventDeliveryException
* @throws InterruptedException
*/
- @Test(expected=EventDeliveryException.class)
+ @Test(expected = EventDeliveryException.class)
public void testServerDisconnect() throws FlumeException,
EventDeliveryException, InterruptedException {
NettyAvroRpcClient client = null;
@@ -245,7 +245,7 @@ public class TestNettyAvroRpcClient {
* @throws FlumeException
* @throws EventDeliveryException
*/
- @Test(expected=EventDeliveryException.class)
+ @Test(expected = EventDeliveryException.class)
public void testClientClosedRequest() throws FlumeException,
EventDeliveryException {
NettyAvroRpcClient client = null;
@@ -265,7 +265,7 @@ public class TestNettyAvroRpcClient {
/**
* Send an event to an online server that returns FAILED.
*/
- @Test(expected=EventDeliveryException.class)
+ @Test(expected = EventDeliveryException.class)
public void testFailedServerSimple() throws FlumeException,
EventDeliveryException {
@@ -276,7 +276,7 @@ public class TestNettyAvroRpcClient {
/**
* Send an event to an online server that returns UNKNOWN.
*/
- @Test(expected=EventDeliveryException.class)
+ @Test(expected = EventDeliveryException.class)
public void testUnknownServerSimple() throws FlumeException,
EventDeliveryException {
@@ -287,7 +287,7 @@ public class TestNettyAvroRpcClient {
/**
* Send an event to an online server that throws an exception.
*/
- @Test(expected=EventDeliveryException.class)
+ @Test(expected = EventDeliveryException.class)
public void testThrowingServerSimple() throws FlumeException,
EventDeliveryException {
@@ -298,7 +298,7 @@ public class TestNettyAvroRpcClient {
/**
* Send a batch of events to a server that returns FAILED.
*/
- @Test(expected=EventDeliveryException.class)
+ @Test(expected = EventDeliveryException.class)
public void testFailedServerBatch() throws FlumeException,
EventDeliveryException {
@@ -309,7 +309,7 @@ public class TestNettyAvroRpcClient {
/**
* Send a batch of events to a server that returns UNKNOWN.
*/
- @Test(expected=EventDeliveryException.class)
+ @Test(expected = EventDeliveryException.class)
public void testUnknownServerBatch() throws FlumeException,
EventDeliveryException {
@@ -320,7 +320,7 @@ public class TestNettyAvroRpcClient {
/**
* Send a batch of events to a server that always throws exceptions.
*/
- @Test(expected=EventDeliveryException.class)
+ @Test(expected = EventDeliveryException.class)
public void testThrowingServerBatch() throws FlumeException,
EventDeliveryException {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java
----------------------------------------------------------------------
diff --git a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java
index a8baaa8..b03fc8d 100644
--- a/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java
+++ b/flume-ng-sdk/src/test/java/org/apache/flume/api/TestThriftRpcClient.java
@@ -50,12 +50,10 @@ public class TestThriftRpcClient {
public void setUp() throws Exception {
props.setProperty("hosts", "h1");
port = random.nextInt(40000) + 1024;
- props.setProperty(RpcClientConfigurationConstants.CONFIG_CLIENT_TYPE,
- "thrift");
- props.setProperty("hosts.h1", "0.0.0.0:"+ String.valueOf(port));
+ props.setProperty(RpcClientConfigurationConstants.CONFIG_CLIENT_TYPE, "thrift");
+ props.setProperty("hosts.h1", "0.0.0.0:" + String.valueOf(port));
props.setProperty(RpcClientConfigurationConstants.CONFIG_BATCH_SIZE, "10");
- props.setProperty(RpcClientConfigurationConstants.CONFIG_REQUEST_TIMEOUT,
- "2000");
+ props.setProperty(RpcClientConfigurationConstants.CONFIG_REQUEST_TIMEOUT, "2000");
props.setProperty(ThriftRpcClient.CONFIG_PROTOCOL, ThriftRpcClient.COMPACT_PROTOCOL);
}
@@ -71,13 +69,11 @@ public class TestThriftRpcClient {
* @param count
* @throws Exception
*/
- public static void insertEvents(RpcClient client,
- int count) throws Exception {
+ public static void insertEvents(RpcClient client, int count) throws Exception {
for (int i = 0; i < count; i++) {
Map<String, String> header = new HashMap<String, String>();
header.put(SEQ, String.valueOf(i));
- client.append(EventBuilder.withBody(String.valueOf(i).getBytes(),
- header));
+ client.append(EventBuilder.withBody(String.valueOf(i).getBytes(), header));
}
}
@@ -149,22 +145,20 @@ public class TestThriftRpcClient {
@Test
public void testError() throws Throwable {
try {
- src = new ThriftTestingSource(ThriftTestingSource.HandlerType.ERROR
- .name(), port, ThriftRpcClient.COMPACT_PROTOCOL);
- client = (ThriftRpcClient) RpcClientFactory.getThriftInstance("0.0.0" +
- ".0", port);
+ src = new ThriftTestingSource(ThriftTestingSource.HandlerType.ERROR.name(), port,
+ ThriftRpcClient.COMPACT_PROTOCOL);
+ client = (ThriftRpcClient) RpcClientFactory.getThriftInstance("0.0.0" + ".0", port);
insertEvents(client, 2); //2 events
} catch (EventDeliveryException ex) {
- Assert.assertEquals("Failed to send event. ",
- ex.getMessage());
+ Assert.assertEquals("Failed to send event. ", ex.getMessage());
}
}
@Test (expected = TimeoutException.class)
public void testTimeout() throws Throwable {
try {
- src = new ThriftTestingSource(ThriftTestingSource.HandlerType.TIMEOUT
- .name(), port, ThriftRpcClient.COMPACT_PROTOCOL);
+ src = new ThriftTestingSource(ThriftTestingSource.HandlerType.TIMEOUT.name(), port,
+ ThriftRpcClient.COMPACT_PROTOCOL);
client = (ThriftRpcClient) RpcClientFactory.getThriftInstance(props);
insertEvents(client, 2); //2 events
} catch (EventDeliveryException ex) {
@@ -174,10 +168,9 @@ public class TestThriftRpcClient {
@Test
public void testMultipleThreads() throws Throwable {
- src = new ThriftTestingSource(ThriftTestingSource.HandlerType.OK.name(),
- port, ThriftRpcClient.COMPACT_PROTOCOL);
- client = (ThriftRpcClient) RpcClientFactory.getThriftInstance("0.0.0" +
- ".0", port, 10);
+ src = new ThriftTestingSource(ThriftTestingSource.HandlerType.OK.name(), port,
+ ThriftRpcClient.COMPACT_PROTOCOL);
+ client = (ThriftRpcClient) RpcClientFactory.getThriftInstance("0.0.0" + ".0", port, 10);
int threadCount = 100;
ExecutorService submissionSvc = Executors.newFixedThreadPool(threadCount);
ArrayList<Future<?>> futures = new ArrayList<Future<?>>(threadCount);
@@ -194,18 +187,18 @@ public class TestThriftRpcClient {
}
}));
}
- for(int i = 0; i < threadCount; i++) {
+ for (int i = 0; i < threadCount; i++) {
futures.get(i).get();
}
ArrayList<String> events = new ArrayList<String>();
- for(Event e: src.flumeEvents) {
+ for (Event e : src.flumeEvents) {
events.add(new String(e.getBody()));
}
int count = 0;
Collections.sort(events);
for (int i = 0; i < events.size();) {
- for(int j = 0; j < threadCount; j++) {
+ for (int j = 0; j < threadCount; j++) {
Assert.assertEquals(String.valueOf(count), events.get(i++));
}
count++;
[2/9] flume git commit: FLUME-2941. Integrate checkstyle for test
classes
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSink.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSink.java
index a58f344..69acc06 100644
--- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSink.java
+++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSink.java
@@ -18,25 +18,7 @@
*/
package org.apache.flume.sink.elasticsearch;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.BATCH_SIZE;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.CLUSTER_NAME;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.HOSTNAMES;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.INDEX_NAME;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.INDEX_TYPE;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.SERIALIZER;
-import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.TTL;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.TimeZone;
-import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.time.FastDateFormat;
-
import org.apache.flume.Channel;
import org.apache.flume.Context;
import org.apache.flume.Event;
@@ -56,6 +38,24 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.BATCH_SIZE;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.CLUSTER_NAME;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.HOSTNAMES;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.INDEX_NAME;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.INDEX_TYPE;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.SERIALIZER;
+import static org.apache.flume.sink.elasticsearch.ElasticSearchSinkConstants.TTL;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
public class TestElasticSearchSink extends AbstractElasticSearchSinkTest {
private ElasticSearchSink fixture;
@@ -373,23 +373,22 @@ public class TestElasticSearchSink extends AbstractElasticSearchSinkTest {
public static final class CustomElasticSearchIndexRequestBuilderFactory
extends AbstractElasticSearchIndexRequestBuilderFactory {
- static String actualIndexName, actualIndexType;
+ static String actualIndexName;
+ static String actualIndexType;
static byte[] actualEventBody;
static boolean hasContext;
public CustomElasticSearchIndexRequestBuilderFactory() {
- super(FastDateFormat.getInstance("HH_mm_ss_SSS",
- TimeZone.getTimeZone("EST5EDT")));
+ super(FastDateFormat.getInstance("HH_mm_ss_SSS", TimeZone.getTimeZone("EST5EDT")));
}
@Override
- protected void prepareIndexRequest(IndexRequestBuilder indexRequest,
- String indexName, String indexType, Event event) throws IOException {
+ protected void prepareIndexRequest(IndexRequestBuilder indexRequest, String indexName,
+ String indexType, Event event) throws IOException {
actualIndexName = indexName;
actualIndexType = indexType;
actualEventBody = event.getBody();
- indexRequest.setIndex(indexName).setType(indexType)
- .setSource(event.getBody());
+ indexRequest.setIndex(indexName).setType(indexType).setSource(event.getBody());
}
@Override
@@ -458,7 +457,8 @@ public class TestElasticSearchSink extends AbstractElasticSearchSinkTest {
class FakeEventSerializer implements ElasticSearchEventSerializer {
static final byte[] FAKE_BYTES = new byte[] { 9, 8, 7, 6 };
- boolean configuredWithContext, configuredWithComponentConfiguration;
+ boolean configuredWithContext;
+ boolean configuredWithComponentConfiguration;
@Override
public BytesStream getContentBuilder(Event event) throws IOException {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSinkCreation.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSinkCreation.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSinkCreation.java
index b5a4d2f..2a36439 100644
--- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSinkCreation.java
+++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/TestElasticSearchSinkCreation.java
@@ -28,7 +28,7 @@ import org.junit.Test;
public class TestElasticSearchSinkCreation {
-private SinkFactory sinkFactory;
+ private SinkFactory sinkFactory;
@Before
public void setUp() {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/RoundRobinListTest.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/RoundRobinListTest.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/RoundRobinListTest.java
index 38e7399..0d1d092 100644
--- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/RoundRobinListTest.java
+++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/RoundRobinListTest.java
@@ -17,10 +17,11 @@
package org.apache.flume.sink.elasticsearch.client;
import java.util.Arrays;
-import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class RoundRobinListTest {
private RoundRobinList<String> fixture;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchClientFactory.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchClientFactory.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchClientFactory.java
index 4b70b65..c3f07b0 100644
--- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchClientFactory.java
+++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchClientFactory.java
@@ -21,10 +21,10 @@ package org.apache.flume.sink.elasticsearch.client;
import org.apache.flume.sink.elasticsearch.ElasticSearchEventSerializer;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertThat;
-import org.mockito.Mock;
import static org.mockito.MockitoAnnotations.initMocks;
public class TestElasticSearchClientFactory {
@@ -44,7 +44,7 @@ public class TestElasticSearchClientFactory {
public void shouldReturnTransportClient() throws Exception {
String[] hostNames = { "127.0.0.1" };
Object o = factory.getClient(ElasticSearchClientFactory.TransportClient,
- hostNames, "test", serializer, null);
+ hostNames, "test", serializer, null);
assertThat(o, instanceOf(ElasticSearchTransportClient.class));
}
@@ -52,13 +52,13 @@ public class TestElasticSearchClientFactory {
public void shouldReturnRestClient() throws NoSuchClientTypeException {
String[] hostNames = { "127.0.0.1" };
Object o = factory.getClient(ElasticSearchClientFactory.RestClient,
- hostNames, "test", serializer, null);
+ hostNames, "test", serializer, null);
assertThat(o, instanceOf(ElasticSearchRestClient.class));
}
- @Test(expected=NoSuchClientTypeException.class)
+ @Test(expected = NoSuchClientTypeException.class)
public void shouldThrowNoSuchClientTypeException() throws NoSuchClientTypeException {
- String[] hostNames = {"127.0.0.1"};
+ String[] hostNames = { "127.0.0.1" };
factory.getClient("not_existing_client", hostNames, "test", null, null);
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java
index 1fe983a..9551c81 100644
--- a/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java
+++ b/flume-ng-sinks/flume-ng-elasticsearch-sink/src/test/java/org/apache/flume/sink/elasticsearch/client/TestElasticSearchRestClient.java
@@ -25,6 +25,15 @@ import org.apache.flume.Event;
import org.apache.flume.EventDeliveryException;
import org.apache.flume.sink.elasticsearch.ElasticSearchEventSerializer;
import org.apache.flume.sink.elasticsearch.IndexNameBuilder;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.util.EntityUtils;
+import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.BytesStream;
import org.junit.Before;
@@ -38,16 +47,12 @@ import java.util.List;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.StatusLine;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.util.EntityUtils;
-import org.elasticsearch.common.bytes.BytesArray;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.isA;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
public class TestElasticSearchRestClient {
@@ -126,15 +131,16 @@ public class TestElasticSearchRestClient {
verify(httpClient).execute(argument.capture());
assertEquals("http://host1/_bulk", argument.getValue().getURI().toString());
- assertTrue(verifyJsonEvents("{\"index\":{\"_type\":\"bar_type\",\"_index\":\"foo_index\",\"_ttl\":\"123\"}}\n",
- MESSAGE_CONTENT, EntityUtils.toString(argument.getValue().getEntity())));
+ assertTrue(verifyJsonEvents(
+ "{\"index\":{\"_type\":\"bar_type\",\"_index\":\"foo_index\",\"_ttl\":\"123\"}}\n",
+ MESSAGE_CONTENT, EntityUtils.toString(argument.getValue().getEntity())));
}
private boolean verifyJsonEvents(String expectedIndex, String expectedBody, String actual) {
Iterator<String> it = Splitter.on("\n").split(actual).iterator();
JsonParser parser = new JsonParser();
JsonObject[] arr = new JsonObject[2];
- for(int i = 0; i < 2; i++) {
+ for (int i = 0; i < 2; i++) {
arr[i] = (JsonObject) parser.parse(it.next());
}
return arr[0].equals(parser.parse(expectedIndex)) && arr[1].equals(parser.parse(expectedBody));
@@ -156,7 +162,8 @@ public class TestElasticSearchRestClient {
public void shouldRetryBulkOperation() throws Exception {
ArgumentCaptor<HttpPost> argument = ArgumentCaptor.forClass(HttpPost.class);
- when(httpStatus.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR, HttpStatus.SC_OK);
+ when(httpStatus.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR,
+ HttpStatus.SC_OK);
when(httpResponse.getStatusLine()).thenReturn(httpStatus);
when(httpClient.execute(any(HttpUriRequest.class))).thenReturn(httpResponse);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/IncrementAsyncHBaseSerializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/IncrementAsyncHBaseSerializer.java b/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/IncrementAsyncHBaseSerializer.java
index b8aefe8..9a2be5a 100644
--- a/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/IncrementAsyncHBaseSerializer.java
+++ b/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/IncrementAsyncHBaseSerializer.java
@@ -37,6 +37,7 @@ public class IncrementAsyncHBaseSerializer implements AsyncHbaseEventSerializer
private byte[] cf;
private byte[] column;
private Event currentEvent;
+
@Override
public void initialize(byte[] table, byte[] cf) {
this.table = table;
@@ -55,10 +56,9 @@ public class IncrementAsyncHBaseSerializer implements AsyncHbaseEventSerializer
@Override
public List<AtomicIncrementRequest> getIncrements() {
- List<AtomicIncrementRequest> incrs
- = new ArrayList<AtomicIncrementRequest>();
+ List<AtomicIncrementRequest> incrs = new ArrayList<AtomicIncrementRequest>();
AtomicIncrementRequest incr = new AtomicIncrementRequest(table,
- currentEvent.getBody(), cf, column, 1);
+ currentEvent.getBody(), cf, column, 1);
incrs.add(incr);
return incrs;
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java b/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java
index b4bbd6b..f8faa1e 100644
--- a/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java
+++ b/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestAsyncHBaseSink.java
@@ -176,7 +176,7 @@ public class TestAsyncHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -189,9 +189,9 @@ public class TestAsyncHBaseSink {
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))){
+ 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;
}
@@ -209,8 +209,7 @@ public class TestAsyncHBaseSink {
public void testTimeOut() throws Exception {
testUtility.createTable(tableName.getBytes(), columnFamily.getBytes());
deleteTable = true;
- AsyncHBaseSink sink = new AsyncHBaseSink(testUtility.getConfiguration(),
- true, false);
+ AsyncHBaseSink sink = new AsyncHBaseSink(testUtility.getConfiguration(), true, false);
Configurables.configure(sink, ctx);
Channel channel = new MemoryChannel();
Configurables.configure(channel, ctx);
@@ -219,7 +218,7 @@ public class TestAsyncHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -245,7 +244,7 @@ public class TestAsyncHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -253,7 +252,7 @@ public class TestAsyncHBaseSink {
tx.close();
int count = 0;
Status status = Status.READY;
- while(status != Status.BACKOFF){
+ while (status != Status.BACKOFF) {
count++;
status = sink.process();
}
@@ -264,9 +263,9 @@ public class TestAsyncHBaseSink {
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))){
+ 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;
}
@@ -278,26 +277,21 @@ public class TestAsyncHBaseSink {
}
@Test
- public void testMultipleBatchesBatchIncrementsWithCoalescing()
- throws Exception {
+ public void testMultipleBatchesBatchIncrementsWithCoalescing() throws Exception {
doTestMultipleBatchesBatchIncrements(true);
}
@Test
- public void testMultipleBatchesBatchIncrementsNoCoalescing()
- throws Exception {
+ public void testMultipleBatchesBatchIncrementsNoCoalescing() throws Exception {
doTestMultipleBatchesBatchIncrements(false);
}
- public void doTestMultipleBatchesBatchIncrements(boolean coalesce) throws
- Exception {
+ public void doTestMultipleBatchesBatchIncrements(boolean coalesce) throws Exception {
testUtility.createTable(tableName.getBytes(), columnFamily.getBytes());
deleteTable = true;
- AsyncHBaseSink sink = new AsyncHBaseSink(testUtility.getConfiguration(),
- false, true);
+ AsyncHBaseSink sink = new AsyncHBaseSink(testUtility.getConfiguration(), false, true);
if (coalesce) {
- ctx.put(HBaseSinkConfigurationConstants.CONFIG_COALESCE_INCREMENTS,
- "true");
+ ctx.put(HBaseSinkConfigurationConstants.CONFIG_COALESCE_INCREMENTS, "true");
}
ctx.put("batchSize", "2");
ctx.put("serializer", IncrementAsyncHBaseSerializer.class.getName());
@@ -309,7 +303,7 @@ public class TestAsyncHBaseSink {
ctx.put("serializer", SimpleAsyncHbaseEventSerializer.class.getName());
//Restore the no coalescing behavior
ctx.put(HBaseSinkConfigurationConstants.CONFIG_COALESCE_INCREMENTS,
- "false");
+ "false");
Channel channel = new MemoryChannel();
Configurables.configure(channel, ctx);
sink.setChannel(channel);
@@ -335,7 +329,7 @@ public class TestAsyncHBaseSink {
Assert.assertEquals(7, count);
HTable table = new HTable(testUtility.getConfiguration(), tableName);
Scan scan = new Scan();
- scan.addColumn(columnFamily.getBytes(),"test".getBytes());
+ scan.addColumn(columnFamily.getBytes(), "test".getBytes());
scan.setStartRow(Bytes.toBytes(valBase));
ResultScanner rs = table.getScanner(scan);
int i = 0;
@@ -358,19 +352,19 @@ public class TestAsyncHBaseSink {
}
@Test
- public void testWithoutConfigurationObject() throws Exception{
+ public void testWithoutConfigurationObject() throws Exception {
testUtility.createTable(tableName.getBytes(), columnFamily.getBytes());
deleteTable = true;
ctx.put("batchSize", "2");
ctx.put(HBaseSinkConfigurationConstants.ZK_QUORUM,
- ZKConfig.getZKQuorumServersString(testUtility.getConfiguration()) );
+ ZKConfig.getZKQuorumServersString(testUtility.getConfiguration()));
ctx.put(HBaseSinkConfigurationConstants.ZK_ZNODE_PARENT,
- testUtility.getConfiguration().get(HConstants.ZOOKEEPER_ZNODE_PARENT));
+ testUtility.getConfiguration().get(HConstants.ZOOKEEPER_ZNODE_PARENT));
AsyncHBaseSink sink = new AsyncHBaseSink();
Configurables.configure(sink, ctx);
// Reset context to values usable by other tests.
ctx.put(HBaseSinkConfigurationConstants.ZK_QUORUM, null);
- ctx.put(HBaseSinkConfigurationConstants.ZK_ZNODE_PARENT,null);
+ ctx.put(HBaseSinkConfigurationConstants.ZK_ZNODE_PARENT, null);
ctx.put("batchSize", "100");
Channel channel = new MemoryChannel();
Configurables.configure(channel, ctx);
@@ -378,7 +372,7 @@ public class TestAsyncHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -386,7 +380,7 @@ public class TestAsyncHBaseSink {
tx.close();
int count = 0;
Status status = Status.READY;
- while(status != Status.BACKOFF){
+ while (status != Status.BACKOFF) {
count++;
status = sink.process();
}
@@ -401,9 +395,9 @@ public class TestAsyncHBaseSink {
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))){
+ 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;
}
@@ -428,7 +422,7 @@ public class TestAsyncHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -440,9 +434,9 @@ public class TestAsyncHBaseSink {
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))){
+ 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;
}
@@ -457,7 +451,7 @@ public class TestAsyncHBaseSink {
// We only have support for getting File Descriptor count for Unix from the JDK
private long getOpenFileDescriptorCount() {
- if(os instanceof UnixOperatingSystemMXBean){
+ if (os instanceof UnixOperatingSystemMXBean) {
return ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount();
} else {
return -1;
@@ -476,13 +470,13 @@ public class TestAsyncHBaseSink {
*/
@Test
public void testFDLeakOnShutdown() throws Exception {
- if(getOpenFileDescriptorCount() < 0) {
+ if (getOpenFileDescriptorCount() < 0) {
return;
}
testUtility.createTable(tableName.getBytes(), columnFamily.getBytes());
deleteTable = true;
AsyncHBaseSink sink = new AsyncHBaseSink(testUtility.getConfiguration(),
- true, false);
+ true, false);
ctx.put("maxConsecutiveFails", "1");
Configurables.configure(sink, ctx);
Channel channel = new MemoryChannel();
@@ -492,7 +486,7 @@ public class TestAsyncHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -503,7 +497,7 @@ public class TestAsyncHBaseSink {
// Since the isTimeOutTest is set to true, transaction will fail
// with EventDeliveryException
- for(int i = 0; i < 10; i ++) {
+ for (int i = 0; i < 10; i++) {
try {
sink.process();
} catch (EventDeliveryException ex) {
@@ -511,18 +505,20 @@ public class TestAsyncHBaseSink {
}
long increaseInFD = getOpenFileDescriptorCount() - initialFDCount;
Assert.assertTrue("File Descriptor leak detected. FDs have increased by " +
- increaseInFD + " from an initial FD count of " + initialFDCount, increaseInFD < 50);
+ increaseInFD + " from an initial FD count of " + initialFDCount,
+ increaseInFD < 50);
}
/**
* This test must run last - it shuts down the minicluster :D
+ *
* @throws Exception
*/
@Ignore("For dev builds only:" +
- "This test takes too long, and this has to be run after all other" +
- "tests, since it shuts down the minicluster. " +
- "Comment out all other tests" +
- "and uncomment this annotation to run this test.")
+ "This test takes too long, and this has to be run after all other" +
+ "tests, since it shuts down the minicluster. " +
+ "Comment out all other tests" +
+ "and uncomment this annotation to run this test.")
@Test(expected = EventDeliveryException.class)
public void testHBaseFailure() throws Exception {
ctx.put("batchSize", "2");
@@ -538,7 +534,7 @@ public class TestAsyncHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -550,9 +546,9 @@ public class TestAsyncHBaseSink {
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))){
+ 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;
}
@@ -565,21 +561,23 @@ public class TestAsyncHBaseSink {
sink.process();
sink.stop();
}
+
/**
* Makes Hbase scans to get rows in the payload column and increment column
* in the table given. Expensive, so tread lightly.
* Calling this function multiple times for the same result set is a bad
* idea. Cache the result set once it is returned by this function.
+ *
* @param table
* @param numEvents Number of events inserted into the table
* @return
* @throws IOException
*/
- private byte[][] getResults(HTable table, int numEvents) throws IOException{
- byte[][] results = new byte[numEvents+1][];
+ private byte[][] getResults(HTable table, int numEvents) throws IOException {
+ byte[][] results = new byte[numEvents + 1][];
Scan scan = new Scan();
- scan.addColumn(columnFamily.getBytes(),plCol.getBytes());
- scan.setStartRow( Bytes.toBytes("default"));
+ scan.addColumn(columnFamily.getBytes(), plCol.getBytes());
+ scan.setStartRow(Bytes.toBytes("default"));
ResultScanner rs = table.getScanner(scan);
byte[] out = null;
int i = 0;
@@ -587,10 +585,10 @@ public class TestAsyncHBaseSink {
for (Result r = rs.next(); r != null; r = rs.next()) {
out = r.getValue(columnFamily.getBytes(), plCol.getBytes());
- if(i >= results.length - 1){
+ if (i >= results.length - 1) {
rs.close();
throw new FlumeException("More results than expected in the table." +
- "Expected = " + numEvents +". Found = " + i);
+ "Expected = " + numEvents + ". Found = " + i);
}
results[i++] = out;
System.out.println(out);
@@ -601,7 +599,7 @@ public class TestAsyncHBaseSink {
Assert.assertEquals(i, results.length - 1);
scan = new Scan();
- scan.addColumn(columnFamily.getBytes(),inColumn.getBytes());
+ scan.addColumn(columnFamily.getBytes(), inColumn.getBytes());
scan.setStartRow(Bytes.toBytes("incRow"));
rs = table.getScanner(scan);
out = null;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestHBaseSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestHBaseSink.java b/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestHBaseSink.java
index ab65a38..217913b 100644
--- a/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestHBaseSink.java
+++ b/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestHBaseSink.java
@@ -18,14 +18,6 @@
*/
package org.apache.flume.sink.hbase;
-import static org.mockito.Mockito.*;
-
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.NavigableMap;
import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
@@ -54,14 +46,25 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.ZKConfig;
import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableMap;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.spy;
+
public class TestHBaseSink {
private static final Logger logger =
LoggerFactory.getLogger(TestHBaseSink.class);
@@ -140,8 +143,7 @@ public class TestHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- Event e = EventBuilder.withBody(
- Bytes.toBytes(valBase));
+ Event e = EventBuilder.withBody(Bytes.toBytes(valBase));
channel.put(e);
tx.commit();
tx.close();
@@ -195,7 +197,7 @@ public class TestHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -207,9 +209,9 @@ public class TestHBaseSink {
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))){
+ 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;
}
@@ -234,14 +236,14 @@ public class TestHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
tx.commit();
tx.close();
int count = 0;
- while(sink.process() != Status.BACKOFF){
+ while (sink.process() != Status.BACKOFF) {
count++;
}
sink.stop();
@@ -250,9 +252,9 @@ public class TestHBaseSink {
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))){
+ 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;
}
@@ -284,7 +286,7 @@ public class TestHBaseSink {
logger.info("Writing data into channel");
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -313,9 +315,9 @@ public class TestHBaseSink {
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))){
+ 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;
}
@@ -328,15 +330,17 @@ public class TestHBaseSink {
}
// TODO: Move this test to a different class and run it stand-alone.
+
/**
* This test must run last - it shuts down the minicluster :D
+ *
* @throws Exception
*/
@Ignore("For dev builds only:" +
- "This test takes too long, and this has to be run after all other" +
- "tests, since it shuts down the minicluster. " +
- "Comment out all other tests" +
- "and uncomment this annotation to run this test.")
+ "This test takes too long, and this has to be run after all other" +
+ "tests, since it shuts down the minicluster. " +
+ "Comment out all other tests" +
+ "and uncomment this annotation to run this test.")
@Test(expected = EventDeliveryException.class)
public void testHBaseFailure() throws Exception {
initContextForSimpleHbaseEventSerializer();
@@ -351,7 +355,7 @@ public class TestHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
@@ -362,9 +366,9 @@ public class TestHBaseSink {
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))){
+ 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;
}
@@ -378,22 +382,22 @@ public class TestHBaseSink {
sink.stop();
}
-
/**
* Makes Hbase scans to get rows in the payload column and increment column
* in the table given. Expensive, so tread lightly.
* Calling this function multiple times for the same result set is a bad
* idea. Cache the result set once it is returned by this function.
+ *
* @param table
* @param numEvents Number of events inserted into the table
* @return
* @throws IOException
*/
- private byte[][] getResults(HTable table, int numEvents) throws IOException{
- byte[][] results = new byte[numEvents+1][];
+ private byte[][] getResults(HTable table, int numEvents) throws IOException {
+ byte[][] results = new byte[numEvents + 1][];
Scan scan = new Scan();
- scan.addColumn(columnFamily.getBytes(),plCol.getBytes());
- scan.setStartRow( Bytes.toBytes("default"));
+ scan.addColumn(columnFamily.getBytes(), plCol.getBytes());
+ scan.setStartRow(Bytes.toBytes("default"));
ResultScanner rs = table.getScanner(scan);
byte[] out = null;
int i = 0;
@@ -401,10 +405,10 @@ public class TestHBaseSink {
for (Result r = rs.next(); r != null; r = rs.next()) {
out = r.getValue(columnFamily.getBytes(), plCol.getBytes());
- if(i >= results.length - 1){
+ if (i >= results.length - 1) {
rs.close();
throw new FlumeException("More results than expected in the table." +
- "Expected = " + numEvents +". Found = " + i);
+ "Expected = " + numEvents + ". Found = " + i);
}
results[i++] = out;
System.out.println(out);
@@ -415,7 +419,7 @@ public class TestHBaseSink {
Assert.assertEquals(i, results.length - 1);
scan = new Scan();
- scan.addColumn(columnFamily.getBytes(),inColumn.getBytes());
+ scan.addColumn(columnFamily.getBytes(), inColumn.getBytes());
scan.setStartRow(Bytes.toBytes("incRow"));
rs = table.getScanner(scan);
out = null;
@@ -472,7 +476,7 @@ public class TestHBaseSink {
initContextForSimpleHbaseEventSerializer();
ctx.put("batchSize", "1");
ctx.put(HBaseSinkConfigurationConstants.CONFIG_SERIALIZER,
- "org.apache.flume.sink.hbase.MockSimpleHbaseEventSerializer");
+ "org.apache.flume.sink.hbase.MockSimpleHbaseEventSerializer");
HBaseSink sink = new HBaseSink(conf);
Configurables.configure(sink, ctx);
@@ -507,16 +511,16 @@ public class TestHBaseSink {
}
@Test
- public void testWithoutConfigurationObject() throws Exception{
+ public void testWithoutConfigurationObject() throws Exception {
initContextForSimpleHbaseEventSerializer();
Context tmpContext = new Context(ctx.getParameters());
tmpContext.put("batchSize", "2");
tmpContext.put(HBaseSinkConfigurationConstants.ZK_QUORUM,
- ZKConfig.getZKQuorumServersString(conf) );
+ ZKConfig.getZKQuorumServersString(conf));
System.out.print(ctx.getString(HBaseSinkConfigurationConstants.ZK_QUORUM));
tmpContext.put(HBaseSinkConfigurationConstants.ZK_ZNODE_PARENT,
- conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
- HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT));
+ conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
+ HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT));
HBaseSink sink = new HBaseSink();
Configurables.configure(sink, tmpContext);
@@ -526,14 +530,14 @@ public class TestHBaseSink {
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
Event e = EventBuilder.withBody(Bytes.toBytes(valBase + "-" + i));
channel.put(e);
}
tx.commit();
tx.close();
Status status = Status.READY;
- while(status != Status.BACKOFF){
+ while (status != Status.BACKOFF) {
status = sink.process();
}
sink.stop();
@@ -541,9 +545,9 @@ public class TestHBaseSink {
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))){
+ 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;
}
@@ -555,37 +559,36 @@ public class TestHBaseSink {
}
@Test
- public void testZKQuorum() throws Exception{
+ public void testZKQuorum() throws Exception {
initContextForSimpleHbaseEventSerializer();
Context tmpContext = new Context(ctx.getParameters());
String zkQuorum = "zk1.flume.apache.org:3342, zk2.flume.apache.org:3342, " +
- "zk3.flume.apache.org:3342";
+ "zk3.flume.apache.org:3342";
tmpContext.put("batchSize", "2");
tmpContext.put(HBaseSinkConfigurationConstants.ZK_QUORUM, zkQuorum);
tmpContext.put(HBaseSinkConfigurationConstants.ZK_ZNODE_PARENT,
- conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
- HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT));
+ conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
+ HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT));
HBaseSink sink = new HBaseSink();
Configurables.configure(sink, tmpContext);
Assert.assertEquals("zk1.flume.apache.org,zk2.flume.apache.org," +
- "zk3.flume.apache.org", sink.getConfig().get(HConstants
- .ZOOKEEPER_QUORUM));
- Assert.assertEquals(String.valueOf(3342), sink.getConfig().get(HConstants
- .ZOOKEEPER_CLIENT_PORT));
+ "zk3.flume.apache.org", sink.getConfig().get(HConstants.ZOOKEEPER_QUORUM));
+ Assert.assertEquals(String.valueOf(3342),
+ sink.getConfig().get(HConstants.ZOOKEEPER_CLIENT_PORT));
}
- @Test (expected = FlumeException.class)
- public void testZKQuorumIncorrectPorts() throws Exception{
+ @Test(expected = FlumeException.class)
+ public void testZKQuorumIncorrectPorts() throws Exception {
initContextForSimpleHbaseEventSerializer();
Context tmpContext = new Context(ctx.getParameters());
String zkQuorum = "zk1.flume.apache.org:3345, zk2.flume.apache.org:3342, " +
- "zk3.flume.apache.org:3342";
+ "zk3.flume.apache.org:3342";
tmpContext.put("batchSize", "2");
tmpContext.put(HBaseSinkConfigurationConstants.ZK_QUORUM, zkQuorum);
tmpContext.put(HBaseSinkConfigurationConstants.ZK_ZNODE_PARENT,
- conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
- HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT));
+ conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
+ HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT));
HBaseSink sink = new HBaseSink();
Configurables.configure(sink, tmpContext);
Assert.fail();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestRegexHbaseEventSerializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestRegexHbaseEventSerializer.java b/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestRegexHbaseEventSerializer.java
index b102b49..24bcf37 100644
--- a/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestRegexHbaseEventSerializer.java
+++ b/flume-ng-sinks/flume-ng-hbase-sink/src/test/java/org/apache/flume/sink/hbase/TestRegexHbaseEventSerializer.java
@@ -18,17 +18,7 @@
*/
package org.apache.flume.sink.hbase;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.nio.charset.Charset;
-import java.util.Calendar;
-import java.util.List;
-import java.util.Map;
-
+import com.google.common.collect.Maps;
import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.event.EventBuilder;
@@ -39,7 +29,16 @@ import org.apache.hadoop.hbase.client.Row;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;
-import com.google.common.collect.Maps;
+import java.nio.charset.Charset;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class TestRegexHbaseEventSerializer {
@@ -76,8 +75,7 @@ public class TestRegexHbaseEventSerializer {
public void testRowIndexKey() throws Exception {
RegexHbaseEventSerializer s = new RegexHbaseEventSerializer();
Context context = new Context();
- context.put(RegexHbaseEventSerializer.REGEX_CONFIG,"^([^\t]+)\t([^\t]+)\t" +
- "([^\t]+)$");
+ context.put(RegexHbaseEventSerializer.REGEX_CONFIG,"^([^\t]+)\t([^\t]+)\t" + "([^\t]+)$");
context.put(RegexHbaseEventSerializer.COL_NAME_CONFIG, "col1,col2,ROW_KEY");
context.put("rowKeyIndex", "2");
s.configure(context);
@@ -115,9 +113,9 @@ public class TestRegexHbaseEventSerializer {
"referer,agent");
s.configure(context);
String logMsg = "33.22.11.00 - - [20/May/2011:07:01:19 +0000] " +
- "\"GET /wp-admin/css/install.css HTTP/1.0\" 200 813 " +
- "\"http://www.cloudera.com/wp-admin/install.php\" \"Mozilla/5.0 (comp" +
- "atible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)\"";
+ "\"GET /wp-admin/css/install.css HTTP/1.0\" 200 813 " +
+ "\"http://www.cloudera.com/wp-admin/install.php\" \"Mozilla/5.0 (comp" +
+ "atible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)\"";
Event e = EventBuilder.withBody(Bytes.toBytes(logMsg));
s.initialize(e, "CF".getBytes());
@@ -189,7 +187,7 @@ public class TestRegexHbaseEventSerializer {
}
- @Test
+ @Test
/** Test depositing of the header information. */
public void testDepositHeaders() throws Exception {
Charset charset = Charset.forName("KOI8-R");
@@ -222,7 +220,8 @@ public class TestRegexHbaseEventSerializer {
resultMap.put(new String(kv.getQualifier(), charset), kv.getValue());
}
- assertEquals(body, new String(resultMap.get(RegexHbaseEventSerializer.COLUMN_NAME_DEFAULT), charset));
+ assertEquals(body,
+ new String(resultMap.get(RegexHbaseEventSerializer.COLUMN_NAME_DEFAULT), charset));
assertEquals("value1", new String(resultMap.get("header1"), charset));
assertArrayEquals("\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u04352".getBytes(charset), resultMap.get("\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a2"));
assertEquals("\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u04352".length(), resultMap.get("\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a2").length);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/TestKafkaSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/TestKafkaSink.java b/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/TestKafkaSink.java
index f577e98..76eca37 100644
--- a/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/TestKafkaSink.java
+++ b/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/TestKafkaSink.java
@@ -18,8 +18,8 @@
package org.apache.flume.sink.kafka;
+import com.google.common.base.Charsets;
import kafka.message.MessageAndMetadata;
-
import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.DecoderFactory;
import org.apache.avro.specific.SpecificDatumReader;
@@ -41,8 +41,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import com.google.common.base.Charsets;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@@ -52,12 +50,21 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.AVRO_EVENT;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.BATCH_SIZE;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.BOOTSTRAP_SERVERS_CONFIG;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.BROKER_LIST_FLUME_KEY;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.DEFAULT_KEY_SERIALIZER;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.DEFAULT_TOPIC;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.KAFKA_PREFIX;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.KAFKA_PRODUCER_PREFIX;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.OLD_BATCH_SIZE;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.REQUIRED_ACKS_FLUME_KEY;
+import static org.apache.flume.sink.kafka.KafkaSinkConstants.TOPIC_CONFIG;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-import static org.apache.flume.sink.kafka.KafkaSinkConstants.*;
-
/**
* Unit tests for Kafka Sink
*/
@@ -86,40 +93,45 @@ public class TestKafkaSink {
KafkaSink kafkaSink = new KafkaSink();
Context context = new Context();
context.put(KAFKA_PREFIX + TOPIC_CONFIG, "");
- context.put(KAFKA_PRODUCER_PREFIX + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "override.default.serializer");
+ context.put(KAFKA_PRODUCER_PREFIX + ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
+ "override.default.serializer");
context.put("kafka.producer.fake.property", "kafka.property.value");
context.put("kafka.bootstrap.servers", "localhost:9092,localhost:9092");
- context.put("brokerList","real-broker-list");
- Configurables.configure(kafkaSink,context);
+ context.put("brokerList", "real-broker-list");
+ Configurables.configure(kafkaSink, context);
Properties kafkaProps = kafkaSink.getKafkaProps();
//check that we have defaults set
- assertEquals(
- kafkaProps.getProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG), DEFAULT_KEY_SERIALIZER);
+ assertEquals(kafkaProps.getProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG),
+ DEFAULT_KEY_SERIALIZER);
//check that kafka properties override the default and get correct name
- assertEquals(kafkaProps.getProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG), "override.default.serializer");
+ assertEquals(kafkaProps.getProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG),
+ "override.default.serializer");
//check that any kafka-producer property gets in
- assertEquals(kafkaProps.getProperty("fake.property"), "kafka.property.value");
+ assertEquals(kafkaProps.getProperty("fake.property"),
+ "kafka.property.value");
//check that documented property overrides defaults
- assertEquals(kafkaProps.getProperty("bootstrap.servers") ,"localhost:9092,localhost:9092");
+ assertEquals(kafkaProps.getProperty("bootstrap.servers"),
+ "localhost:9092,localhost:9092");
}
@Test
public void testOldProperties() {
KafkaSink kafkaSink = new KafkaSink();
Context context = new Context();
- context.put("topic","test-topic");
+ context.put("topic", "test-topic");
context.put(OLD_BATCH_SIZE, "300");
- context.put(BROKER_LIST_FLUME_KEY,"localhost:9092,localhost:9092");
+ context.put(BROKER_LIST_FLUME_KEY, "localhost:9092,localhost:9092");
context.put(REQUIRED_ACKS_FLUME_KEY, "all");
- Configurables.configure(kafkaSink,context);
+ Configurables.configure(kafkaSink, context);
Properties kafkaProps = kafkaSink.getKafkaProps();
assertEquals(kafkaSink.getTopic(), "test-topic");
- assertEquals(kafkaSink.getBatchSize(),300);
- assertEquals(kafkaProps.getProperty(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG),"localhost:9092,localhost:9092");
+ assertEquals(kafkaSink.getBatchSize(), 300);
+ assertEquals(kafkaProps.getProperty(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG),
+ "localhost:9092,localhost:9092");
assertEquals(kafkaProps.getProperty(ProducerConfig.ACKS_CONFIG), "all");
}
@@ -151,9 +163,8 @@ public class TestKafkaSink {
// ignore
}
- String fetchedMsg = new String((byte[])
- testUtil.getNextMessageFromConsumer(DEFAULT_TOPIC)
- .message());
+ String fetchedMsg = new String((byte[]) testUtil.getNextMessageFromConsumer(DEFAULT_TOPIC)
+ .message());
assertEquals(msg, fetchedMsg);
}
@@ -173,14 +184,13 @@ public class TestKafkaSink {
// ignore
}
- String fetchedMsg = new String((byte[]) testUtil.getNextMessageFromConsumer(TestConstants.STATIC_TOPIC).message());
+ String fetchedMsg = new String((byte[]) testUtil.getNextMessageFromConsumer(
+ TestConstants.STATIC_TOPIC).message());
assertEquals(msg, fetchedMsg);
}
@Test
public void testTopicAndKeyFromHeader() throws UnsupportedEncodingException {
-
-
Sink kafkaSink = new KafkaSink();
Context context = prepareDefaultContext();
Configurables.configure(kafkaSink, context);
@@ -210,19 +220,16 @@ public class TestKafkaSink {
}
MessageAndMetadata fetchedMsg =
- testUtil.getNextMessageFromConsumer(TestConstants.CUSTOM_TOPIC);
+ testUtil.getNextMessageFromConsumer(TestConstants.CUSTOM_TOPIC);
assertEquals(msg, new String((byte[]) fetchedMsg.message(), "UTF-8"));
assertEquals(TestConstants.CUSTOM_KEY,
- new String((byte[]) fetchedMsg.key(), "UTF-8"));
-
+ new String((byte[]) fetchedMsg.key(), "UTF-8"));
}
@SuppressWarnings("rawtypes")
@Test
public void testAvroEvent() throws IOException {
-
-
Sink kafkaSink = new KafkaSink();
Context context = prepareDefaultContext();
context.put(AVRO_EVENT, "true");
@@ -254,13 +261,12 @@ public class TestKafkaSink {
// ignore
}
- MessageAndMetadata fetchedMsg =
- testUtil.getNextMessageFromConsumer(TestConstants.CUSTOM_TOPIC);
+ MessageAndMetadata fetchedMsg = testUtil.getNextMessageFromConsumer(TestConstants.CUSTOM_TOPIC);
- ByteArrayInputStream in =
- new ByteArrayInputStream((byte[])fetchedMsg.message());
+ ByteArrayInputStream in = new ByteArrayInputStream((byte[]) fetchedMsg.message());
BinaryDecoder decoder = DecoderFactory.get().directBinaryDecoder(in, null);
- SpecificDatumReader<AvroFlumeEvent> reader = new SpecificDatumReader<AvroFlumeEvent>(AvroFlumeEvent.class);
+ SpecificDatumReader<AvroFlumeEvent> reader =
+ new SpecificDatumReader<AvroFlumeEvent>(AvroFlumeEvent.class);
AvroFlumeEvent avroevent = reader.read(null, decoder);
@@ -268,17 +274,15 @@ public class TestKafkaSink {
Map<CharSequence, CharSequence> eventHeaders = avroevent.getHeaders();
assertEquals(msg, eventBody);
- assertEquals(TestConstants.CUSTOM_KEY,
- new String((byte[]) fetchedMsg.key(), "UTF-8"));
+ assertEquals(TestConstants.CUSTOM_KEY, new String((byte[]) fetchedMsg.key(), "UTF-8"));
- assertEquals(TestConstants.HEADER_1_VALUE, eventHeaders.get(new Utf8(TestConstants.HEADER_1_KEY)).toString());
+ assertEquals(TestConstants.HEADER_1_VALUE,
+ eventHeaders.get(new Utf8(TestConstants.HEADER_1_KEY)).toString());
assertEquals(TestConstants.CUSTOM_KEY, eventHeaders.get(new Utf8("key")).toString());
-
}
@Test
- public void testEmptyChannel() throws UnsupportedEncodingException,
- EventDeliveryException {
+ public void testEmptyChannel() throws UnsupportedEncodingException, EventDeliveryException {
Sink kafkaSink = new KafkaSink();
Context context = prepareDefaultContext();
Configurables.configure(kafkaSink, context);
@@ -291,8 +295,7 @@ public class TestKafkaSink {
if (status != Sink.Status.BACKOFF) {
fail("Error Occurred");
}
- assertNull(
- testUtil.getNextMessageFromConsumer(DEFAULT_TOPIC));
+ assertNull(testUtil.getNextMessageFromConsumer(DEFAULT_TOPIC));
}
private Context prepareDefaultContext() {
@@ -304,7 +307,7 @@ public class TestKafkaSink {
}
private Sink.Status prepareAndSend(Context context, String msg)
- throws EventDeliveryException {
+ throws EventDeliveryException {
Sink kafkaSink = new KafkaSink();
Configurables.configure(kafkaSink, context);
Channel memoryChannel = new MemoryChannel();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/KafkaLocal.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/KafkaLocal.java b/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/KafkaLocal.java
index d8a45ef..6d89bd3 100644
--- a/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/KafkaLocal.java
+++ b/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/KafkaLocal.java
@@ -1,19 +1,19 @@
/**
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * limitations under the License.
*/
package org.apache.flume.sink.kafka.util;
@@ -30,23 +30,22 @@ import java.util.Properties;
*/
public class KafkaLocal {
- public KafkaServerStartable kafka;
- public ZooKeeperLocal zookeeper;
+ public KafkaServerStartable kafka;
+ public ZooKeeperLocal zookeeper;
- public KafkaLocal(Properties kafkaProperties) throws IOException,
- InterruptedException{
- KafkaConfig kafkaConfig = KafkaConfig.fromProps(kafkaProperties);
+ public KafkaLocal(Properties kafkaProperties) throws IOException, InterruptedException {
+ KafkaConfig kafkaConfig = KafkaConfig.fromProps(kafkaProperties);
- //start local kafka broker
- kafka = new KafkaServerStartable(kafkaConfig);
- }
+ // start local kafka broker
+ kafka = new KafkaServerStartable(kafkaConfig);
+ }
- public void start() throws Exception{
- kafka.startup();
- }
+ public void start() throws Exception {
+ kafka.startup();
+ }
- public void stop(){
- kafka.shutdown();
- }
+ public void stop() {
+ kafka.shutdown();
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/ZooKeeperLocal.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/ZooKeeperLocal.java b/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/ZooKeeperLocal.java
index 1a5728f..35c1e47 100644
--- a/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/ZooKeeperLocal.java
+++ b/flume-ng-sinks/flume-ng-kafka-sink/src/test/java/org/apache/flume/sink/kafka/util/ZooKeeperLocal.java
@@ -1,19 +1,19 @@
/**
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * limitations under the License.
*/
package org.apache.flume.sink.kafka.util;
@@ -33,30 +33,29 @@ import java.util.Properties;
*/
public class ZooKeeperLocal {
- private static final Logger logger =
- LoggerFactory.getLogger(ZooKeeperLocal.class);
- private ZooKeeperServerMain zooKeeperServer;
+ private static final Logger logger = LoggerFactory.getLogger(ZooKeeperLocal.class);
+ private ZooKeeperServerMain zooKeeperServer;
- public ZooKeeperLocal(Properties zkProperties) throws IOException{
- QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
+ public ZooKeeperLocal(Properties zkProperties) throws IOException {
+ QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
+ try {
+ quorumConfiguration.parseProperties(zkProperties);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ zooKeeperServer = new ZooKeeperServerMain();
+ final ServerConfig configuration = new ServerConfig();
+ configuration.readFrom(quorumConfiguration);
+
+ new Thread() {
+ public void run() {
try {
- quorumConfiguration.parseProperties(zkProperties);
- } catch(Exception e) {
- throw new RuntimeException(e);
+ zooKeeperServer.runFromConfig(configuration);
+ } catch (IOException e) {
+ logger.error("Zookeeper startup failed.", e);
}
-
- zooKeeperServer = new ZooKeeperServerMain();
- final ServerConfig configuration = new ServerConfig();
- configuration.readFrom(quorumConfiguration);
-
- new Thread() {
- public void run() {
- try {
- zooKeeperServer.runFromConfig(configuration);
- } catch (IOException e) {
- logger.error("Zookeeper startup failed.", e);
- }
- }
- }.start();
- }
+ }
+ }.start();
+ }
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestBlobDeserializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestBlobDeserializer.java b/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestBlobDeserializer.java
index 6172c68..be377ba 100644
--- a/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestBlobDeserializer.java
+++ b/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestBlobDeserializer.java
@@ -16,9 +16,7 @@
*/
package org.apache.flume.sink.solr.morphline;
-import java.io.IOException;
-import java.util.List;
-
+import com.google.common.base.Charsets;
import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.serialization.EventDeserializer;
@@ -28,7 +26,8 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import com.google.common.base.Charsets;
+import java.io.IOException;
+import java.util.List;
public class TestBlobDeserializer extends Assert {
@@ -61,7 +60,8 @@ public class TestBlobDeserializer extends Assert {
public void testSimpleViaFactory() throws IOException {
ResettableInputStream in = new ResettableTestStringInputStream(mini);
EventDeserializer des;
- des = EventDeserializerFactory.getInstance(BlobDeserializer.Builder.class.getName(), new Context(), in);
+ des = EventDeserializerFactory.getInstance(BlobDeserializer.Builder.class.getName(),
+ new Context(), in);
validateMiniParse(des);
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineInterceptor.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineInterceptor.java b/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineInterceptor.java
index 22cfe96..8d62d38 100644
--- a/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineInterceptor.java
+++ b/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineInterceptor.java
@@ -16,22 +16,21 @@
*/
package org.apache.flume.sink.solr.morphline;
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
+import com.google.common.base.Charsets;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.event.EventBuilder;
import org.junit.Assert;
import org.junit.Test;
-
import org.kitesdk.morphline.base.Fields;
-import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.io.Files;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class TestMorphlineInterceptor extends Assert {
@@ -40,13 +39,15 @@ public class TestMorphlineInterceptor extends Assert {
@Test
public void testNoOperation() throws Exception {
Context context = new Context();
- context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM, RESOURCES_DIR + "/test-morphlines/noOperation.conf");
+ context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM,
+ RESOURCES_DIR + "/test-morphlines/noOperation.conf");
Event input = EventBuilder.withBody("foo", Charsets.UTF_8);
input.getHeaders().put("name", "nadja");
MorphlineInterceptor interceptor = build(context);
Event actual = interceptor.intercept(input);
interceptor.close();
- Event expected = EventBuilder.withBody("foo".getBytes("UTF-8"), ImmutableMap.of("name", "nadja"));
+ Event expected = EventBuilder.withBody("foo".getBytes("UTF-8"),
+ ImmutableMap.of("name", "nadja"));
assertEqualsEvent(expected, actual);
List<Event> actualList = build(context).intercept(Collections.singletonList(input));
@@ -57,11 +58,13 @@ public class TestMorphlineInterceptor extends Assert {
@Test
public void testReadClob() throws Exception {
Context context = new Context();
- context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM, RESOURCES_DIR + "/test-morphlines/readClob.conf");
+ context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM,
+ RESOURCES_DIR + "/test-morphlines/readClob.conf");
Event input = EventBuilder.withBody("foo", Charsets.UTF_8);
input.getHeaders().put("name", "nadja");
Event actual = build(context).intercept(input);
- Event expected = EventBuilder.withBody(null, ImmutableMap.of("name", "nadja", Fields.MESSAGE, "foo"));
+ Event expected = EventBuilder.withBody(null,
+ ImmutableMap.of("name", "nadja", Fields.MESSAGE, "foo"));
assertEqualsEvent(expected, actual);
List<Event> actualList = build(context).intercept(Collections.singletonList(input));
@@ -72,7 +75,8 @@ public class TestMorphlineInterceptor extends Assert {
@Test
public void testGrokIfNotMatchDropEventRetain() throws Exception {
Context context = new Context();
- context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM, RESOURCES_DIR + "/test-morphlines/grokIfNotMatchDropRecord.conf");
+ context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM,
+ RESOURCES_DIR + "/test-morphlines/grokIfNotMatchDropRecord.conf");
String msg = "<164>Feb 4 10:46:14 syslog sshd[607]: Server listening on 0.0.0.0 port 22.";
Event input = EventBuilder.withBody(null, ImmutableMap.of(Fields.MESSAGE, msg));
@@ -94,8 +98,10 @@ public class TestMorphlineInterceptor extends Assert {
/* leading XXXXX does not match regex, thus we expect the event to be dropped */
public void testGrokIfNotMatchDropEventDrop() throws Exception {
Context context = new Context();
- context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM, RESOURCES_DIR + "/test-morphlines/grokIfNotMatchDropRecord.conf");
- String msg = "<XXXXXXXXXXXXX164>Feb 4 10:46:14 syslog sshd[607]: Server listening on 0.0.0.0 port 22.";
+ context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM,
+ RESOURCES_DIR + "/test-morphlines/grokIfNotMatchDropRecord.conf");
+ String msg = "<XXXXXXXXXXXXX164>Feb 4 10:46:14 syslog sshd[607]: Server listening on 0.0.0.0" +
+ " port 22.";
Event input = EventBuilder.withBody(null, ImmutableMap.of(Fields.MESSAGE, msg));
Event actual = build(context).intercept(input);
assertNull(actual);
@@ -105,10 +111,12 @@ public class TestMorphlineInterceptor extends Assert {
/** morphline says route to southpole if it's an avro file, otherwise route to northpole */
public void testIfDetectMimeTypeRouteToSouthPole() throws Exception {
Context context = new Context();
- context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM, RESOURCES_DIR + "/test-morphlines/ifDetectMimeType.conf");
+ context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM,
+ RESOURCES_DIR + "/test-morphlines/ifDetectMimeType.conf");
context.put(MorphlineHandlerImpl.MORPHLINE_VARIABLE_PARAM + ".MY.MIME_TYPE", "avro/binary");
- Event input = EventBuilder.withBody(Files.toByteArray(new File(RESOURCES_DIR + "/test-documents/sample-statuses-20120906-141433.avro")));
+ Event input = EventBuilder.withBody(Files.toByteArray(
+ new File(RESOURCES_DIR + "/test-documents/sample-statuses-20120906-141433.avro")));
Event actual = build(context).intercept(input);
Map<String, String> expected = new HashMap();
@@ -122,10 +130,12 @@ public class TestMorphlineInterceptor extends Assert {
/** morphline says route to southpole if it's an avro file, otherwise route to northpole */
public void testIfDetectMimeTypeRouteToNorthPole() throws Exception {
Context context = new Context();
- context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM, RESOURCES_DIR + "/test-morphlines/ifDetectMimeType.conf");
+ context.put(MorphlineHandlerImpl.MORPHLINE_FILE_PARAM,
+ RESOURCES_DIR + "/test-morphlines/ifDetectMimeType.conf");
context.put(MorphlineHandlerImpl.MORPHLINE_VARIABLE_PARAM + ".MY.MIME_TYPE", "avro/binary");
- Event input = EventBuilder.withBody(Files.toByteArray(new File(RESOURCES_DIR + "/test-documents/testPDF.pdf")));
+ Event input = EventBuilder.withBody(
+ Files.toByteArray(new File(RESOURCES_DIR + "/test-documents/testPDF.pdf")));
Event actual = build(context).intercept(input);
Map<String, String> expected = new HashMap();
@@ -140,8 +150,9 @@ public class TestMorphlineInterceptor extends Assert {
builder.configure(context);
return builder.build();
}
-
- private void assertEqualsEvent(Event x, Event y) { // b/c SimpleEvent doesn't implement equals() method :-(
+
+ // b/c SimpleEvent doesn't implement equals() method :-(
+ private void assertEqualsEvent(Event x, Event y) {
assertEquals(x.getHeaders(), y.getHeaders());
assertArrayEquals(x.getBody(), y.getBody());
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineSolrSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineSolrSink.java b/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineSolrSink.java
index 232c092..1bfae95 100644
--- a/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineSolrSink.java
+++ b/flume-ng-sinks/flume-ng-morphline-solr-sink/src/test/java/org/apache/flume/sink/solr/morphline/TestMorphlineSolrSink.java
@@ -87,8 +87,7 @@ public class TestMorphlineSolrSink extends SolrTestCaseJ4 {
initCore(
RESOURCES_DIR + "/solr/collection1/conf/solrconfig.xml",
RESOURCES_DIR + "/solr/collection1/conf/schema.xml",
- RESOURCES_DIR + "/solr"
- );
+ RESOURCES_DIR + "/solr");
}
@Before
@@ -139,9 +138,9 @@ public class TestMorphlineSolrSink extends SolrTestCaseJ4 {
int batchSize = SEQ_NUM2.incrementAndGet() % 2 == 0 ? 100 : 1;
DocumentLoader testServer = new SolrServerDocumentLoader(solrServer, batchSize);
MorphlineContext solrMorphlineContext = new SolrMorphlineContext.Builder()
- .setDocumentLoader(testServer)
- .setExceptionHandler(new FaultTolerance(false, false, SolrServerException.class.getName()))
- .setMetricRegistry(new MetricRegistry()).build();
+ .setDocumentLoader(testServer)
+ .setExceptionHandler(new FaultTolerance(false, false, SolrServerException.class.getName()))
+ .setMetricRegistry(new MetricRegistry()).build();
MorphlineHandlerImpl impl = new MorphlineHandlerImpl();
impl.setMorphlineContext(solrMorphlineContext);
@@ -302,9 +301,11 @@ public class TestMorphlineSolrSink extends SolrTestCaseJ4 {
QueryResponse rsp = query("*:*");
Iterator<SolrDocument> iter = rsp.getResults().iterator();
ListMultimap<String, String> expectedFieldValues;
- expectedFieldValues = ImmutableListMultimap.of("id", "1234567890", "text", "sample tweet one", "user_screen_name", "fake_user1");
+ expectedFieldValues = ImmutableListMultimap.of("id", "1234567890", "text", "sample tweet one",
+ "user_screen_name", "fake_user1");
assertEquals(expectedFieldValues, next(iter));
- expectedFieldValues = ImmutableListMultimap.of("id", "2345678901", "text", "sample tweet two", "user_screen_name", "fake_user2");
+ expectedFieldValues = ImmutableListMultimap.of("id", "2345678901", "text", "sample tweet two",
+ "user_screen_name", "fake_user2");
assertEquals(expectedFieldValues, next(iter));
assertFalse(iter.hasNext());
}
@@ -398,8 +399,8 @@ public class TestMorphlineSolrSink extends SolrTestCaseJ4 {
float secs = (System.currentTimeMillis() - startTime) / 1000.0f;
long numDocs = queryResultSetSize("*:*");
- LOGGER.info("Took secs: " + secs + ", iters/sec: " + (iters/secs));
- LOGGER.info("Took secs: " + secs + ", docs/sec: " + (numDocs/secs));
+ LOGGER.info("Took secs: " + secs + ", iters/sec: " + (iters / secs));
+ LOGGER.info("Took secs: " + secs + ", docs/sec: " + (numDocs / secs));
LOGGER.info("Iterations: " + iters + ", numDocs: " + numDocs);
LOGGER.info("sink: ", sink);
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/JMSMessageConsumerTestBase.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/JMSMessageConsumerTestBase.java b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/JMSMessageConsumerTestBase.java
index 6881967..b8466f7 100644
--- a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/JMSMessageConsumerTestBase.java
+++ b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/JMSMessageConsumerTestBase.java
@@ -92,13 +92,10 @@ public abstract class JMSMessageConsumerTestBase {
}
});
when(message.getText()).thenReturn(TEXT);
- when(connectionFactory.createConnection(USERNAME, PASSWORD)).
- thenReturn(connection);
- when(connection.createSession(true, Session.SESSION_TRANSACTED)).
- thenReturn(session);
+ when(connectionFactory.createConnection(USERNAME, PASSWORD)).thenReturn(connection);
+ when(connection.createSession(true, Session.SESSION_TRANSACTED)).thenReturn(session);
when(session.createQueue(destinationName)).thenReturn(queue);
- when(session.createConsumer(any(Destination.class), anyString()))
- .thenReturn(messageConsumer);
+ when(session.createConsumer(any(Destination.class), anyString())).thenReturn(messageConsumer);
when(messageConsumer.receiveNoWait()).thenReturn(message);
when(messageConsumer.receive(anyLong())).thenReturn(message);
destinationName = DESTINATION_NAME;
@@ -127,7 +124,7 @@ public abstract class JMSMessageConsumerTestBase {
}
void assertBodyIsExpected(List<Event> events) {
- for(Event event : events) {
+ for (Event event : events) {
assertEquals(TEXT, new String(event.getBody(), Charsets.UTF_8));
}
}
@@ -140,7 +137,7 @@ public abstract class JMSMessageConsumerTestBase {
@After
public void tearDown() throws Exception {
beforeTearDown();
- if(consumer != null) {
+ if (consumer != null) {
consumer.close();
}
afterTearDown();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java
index 8d413f7..0b2193c 100644
--- a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java
+++ b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestDefaultJMSMessageConverter.java
@@ -73,7 +73,7 @@ public class TestDefaultJMSMessageConverter {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
byte[] buffer = (byte[])invocation.getArguments()[0];
- if(buffer != null) {
+ if (buffer != null) {
assertEquals(buffer.length, BYTES.length);
System.arraycopy(BYTES, 0, buffer, 0, BYTES.length);
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestIntegrationActiveMQ.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestIntegrationActiveMQ.java b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestIntegrationActiveMQ.java
index e28e02a..53cc09a 100644
--- a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestIntegrationActiveMQ.java
+++ b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestIntegrationActiveMQ.java
@@ -56,9 +56,10 @@ import com.google.common.io.Files;
public class TestIntegrationActiveMQ {
- private final static String INITIAL_CONTEXT_FACTORY = "org.apache.activemq.jndi.ActiveMQInitialContextFactory";
+ private static final String INITIAL_CONTEXT_FACTORY =
+ "org.apache.activemq.jndi.ActiveMQInitialContextFactory";
public static final String BROKER_BIND_URL = "tcp://localhost:61516";
- private final static String DESTINATION_NAME = "test";
+ private static final String DESTINATION_NAME = "test";
private static final String USERNAME = "user";
private static final String PASSWORD = "pass";
// specific for dynamic queues on ActiveMq
@@ -115,15 +116,14 @@ public class TestIntegrationActiveMQ {
}
}).when(channelProcessor).processEventBatch(any(List.class));
source.setChannelProcessor(channelProcessor);
-
-
}
+
@After
public void tearDown() throws Exception {
- if(source != null) {
+ if (source != null) {
source.stop();
}
- if(broker != null) {
+ if (broker != null) {
broker.stop();
}
FileUtils.deleteDirectory(baseDir);
@@ -140,8 +140,7 @@ public class TestIntegrationActiveMQ {
Destination destination = session.createQueue(DESTINATION_NAME);
MessageProducer producer = session.createProducer(destination);
-
- for(String event : events) {
+ for (String event : events) {
TextMessage message = session.createTextMessage();
message.setText(event);
producer.send(message);
@@ -162,8 +161,7 @@ public class TestIntegrationActiveMQ {
Destination destination = session.createTopic(DESTINATION_NAME);
MessageProducer producer = session.createProducer(destination);
-
- for(String event : events) {
+ for (String event : events) {
TextMessage message = session.createTextMessage();
message.setText(event);
producer.send(message);
@@ -202,13 +200,14 @@ public class TestIntegrationActiveMQ {
Assert.assertEquals(Status.BACKOFF, source.process());
Assert.assertEquals(expected.size(), events.size());
List<String> actual = Lists.newArrayList();
- for(Event event : events) {
+ for (Event event : events) {
actual.add(new String(event.getBody(), Charsets.UTF_8));
}
Collections.sort(expected);
Collections.sort(actual);
Assert.assertEquals(expected, actual);
}
+
@Test
public void testTopic() throws Exception {
context.put(JMSSourceConfiguration.DESTINATION_TYPE,
@@ -229,7 +228,7 @@ public class TestIntegrationActiveMQ {
Assert.assertEquals(Status.BACKOFF, source.process());
Assert.assertEquals(expected.size(), events.size());
List<String> actual = Lists.newArrayList();
- for(Event event : events) {
+ for (Event event : events) {
actual.add(new String(event.getBody(), Charsets.UTF_8));
}
Collections.sort(expected);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSMessageConsumer.java
----------------------------------------------------------------------
diff --git a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSMessageConsumer.java b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSMessageConsumer.java
index 9bace82..dcb47d9 100644
--- a/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSMessageConsumer.java
+++ b/flume-ng-sources/flume-jms-source/src/test/java/org/apache/flume/source/jms/TestJMSMessageConsumer.java
@@ -105,8 +105,7 @@ public class TestJMSMessageConsumer extends JMSMessageConsumerTestBase {
@Test
public void testNoUserPass() throws Exception {
userName = Optional.absent();
- when(connectionFactory.createConnection(USERNAME, PASSWORD)).
- thenThrow(new AssertionError());
+ when(connectionFactory.createConnection(USERNAME, PASSWORD)).thenThrow(new AssertionError());
when(connectionFactory.createConnection()).thenReturn(connection);
consumer = create();
List<Event> events = consumer.take();
[5/9] flume git commit: FLUME-2941. Integrate checkstyle for test
classes
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/sink/TestRollingFileSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/sink/TestRollingFileSink.java b/flume-ng-core/src/test/java/org/apache/flume/sink/TestRollingFileSink.java
index bf4ed1f..e4d2e2e 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/sink/TestRollingFileSink.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/sink/TestRollingFileSink.java
@@ -19,11 +19,6 @@
package org.apache.flume.sink;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-
import org.apache.flume.Channel;
import org.apache.flume.Context;
import org.apache.flume.Event;
@@ -39,6 +34,11 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
public class TestRollingFileSink {
private static final Logger logger = LoggerFactory
@@ -108,8 +108,8 @@ public class TestRollingFileSink {
sink.stop();
for (String file : sink.getDirectory().list()) {
- BufferedReader reader = new BufferedReader(new FileReader(new File(
- sink.getDirectory(), file)));
+ BufferedReader reader =
+ new BufferedReader(new FileReader(new File(sink.getDirectory(), file)));
String lastLine = null;
String currentLine = null;
@@ -157,8 +157,8 @@ public class TestRollingFileSink {
sink.stop();
for (String file : sink.getDirectory().list()) {
- BufferedReader reader = new BufferedReader(new FileReader(new File(
- sink.getDirectory(), file)));
+ BufferedReader reader =
+ new BufferedReader(new FileReader(new File(sink.getDirectory(), file)));
String lastLine = null;
String currentLine = null;
@@ -174,7 +174,8 @@ public class TestRollingFileSink {
}
@Test
- public void testAppend3() throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
+ public void testAppend3()
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
File tmpDir = new File("target/tmpLog");
tmpDir.mkdirs();
cleanDirectory(tmpDir);
@@ -208,7 +209,8 @@ public class TestRollingFileSink {
sink.stop();
for (String file : sink.getDirectory().list()) {
- BufferedReader reader = new BufferedReader(new FileReader(new File(sink.getDirectory(), file)));
+ BufferedReader reader =
+ new BufferedReader(new FileReader(new File(sink.getDirectory(), file)));
String lastLine = null;
String currentLine = null;
@@ -223,7 +225,8 @@ public class TestRollingFileSink {
}
@Test
- public void testRollTime() throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
+ public void testRollTime()
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
File tmpDir = new File("target/tempLog");
tmpDir.mkdirs();
cleanDirectory(tmpDir);
@@ -258,7 +261,8 @@ public class TestRollingFileSink {
sink.stop();
for (String file : sink.getDirectory().list()) {
- BufferedReader reader = new BufferedReader(new FileReader(new File(sink.getDirectory(), file)));
+ BufferedReader reader =
+ new BufferedReader(new FileReader(new File(sink.getDirectory(), file)));
String lastLine = null;
String currentLine = null;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/sink/TestThriftSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/sink/TestThriftSink.java b/flume-ng-core/src/test/java/org/apache/flume/sink/TestThriftSink.java
index 1beec76..22dcf98 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/sink/TestThriftSink.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/sink/TestThriftSink.java
@@ -161,8 +161,7 @@ public class TestThriftSink {
@Test
public void testFailedConnect() throws Exception {
- Event event = EventBuilder.withBody("test event 1",
- Charset.forName("UTF8"));
+ Event event = EventBuilder.withBody("test event 1", Charset.forName("UTF8"));
sink.start();
@@ -185,7 +184,7 @@ public class TestThriftSink {
threwException = true;
}
Assert.assertTrue("Must throw EventDeliveryException if disconnected",
- threwException);
+ threwException);
}
src = new ThriftTestingSource(ThriftTestingSource.HandlerType.OK.name(),
@@ -283,7 +282,8 @@ public class TestThriftSink {
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
if (failed) {
- Assert.fail("SSL-enabled sink successfully connected to a non-SSL-enabled server, that's wrong.");
+ Assert.fail("SSL-enabled sink successfully connected to a non-SSL-enabled server, " +
+ "that's wrong.");
}
}
@@ -329,7 +329,8 @@ public class TestThriftSink {
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");
+ Assert.fail("SSL-enabled sink successfully connected to a server with an " +
+ "untrusted certificate when it should have failed");
}
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestAbstractPollableSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestAbstractPollableSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestAbstractPollableSource.java
index d385abe..0902db9 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestAbstractPollableSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestAbstractPollableSource.java
@@ -90,10 +90,12 @@ public class TestAbstractPollableSource {
Context context = new Context(inputConfigs);
source.configure(context);
- Assert.assertEquals("BackOffSleepIncrement should equal 42 but it equals " + source.getBackOffSleepIncrement(),
- 42l, source.getBackOffSleepIncrement());
- Assert.assertEquals("BackOffSleepIncrement should equal 42 but it equals " + source.getMaxBackOffSleepInterval(),
- 4242l, source.getMaxBackOffSleepInterval());
+ Assert.assertEquals("BackOffSleepIncrement should equal 42 but it equals " +
+ source.getBackOffSleepIncrement(),
+ 42L, source.getBackOffSleepIncrement());
+ Assert.assertEquals("BackOffSleepIncrement should equal 42 but it equals " +
+ source.getMaxBackOffSleepInterval(),
+ 4242L, source.getMaxBackOffSleepInterval());
}
@Test
@@ -119,14 +121,16 @@ public class TestAbstractPollableSource {
HashMap<String, String> inputConfigs = new HashMap<String,String>();
Assert.assertEquals("BackOffSleepIncrement should equal " +
- PollableSourceConstants.DEFAULT_BACKOFF_SLEEP_INCREMENT +
- " but it equals " + source.getBackOffSleepIncrement(),
- PollableSourceConstants.DEFAULT_BACKOFF_SLEEP_INCREMENT, source.getBackOffSleepIncrement());
+ PollableSourceConstants.DEFAULT_BACKOFF_SLEEP_INCREMENT +
+ " but it equals " + source.getBackOffSleepIncrement(),
+ PollableSourceConstants.DEFAULT_BACKOFF_SLEEP_INCREMENT,
+ source.getBackOffSleepIncrement());
Assert.assertEquals("BackOffSleepIncrement should equal " +
- PollableSourceConstants.DEFAULT_MAX_BACKOFF_SLEEP +
- " but it equals " + source.getMaxBackOffSleepInterval(),
- PollableSourceConstants.DEFAULT_MAX_BACKOFF_SLEEP, source.getMaxBackOffSleepInterval());
+ PollableSourceConstants.DEFAULT_MAX_BACKOFF_SLEEP +
+ " but it equals " + source.getMaxBackOffSleepInterval(),
+ PollableSourceConstants.DEFAULT_MAX_BACKOFF_SLEEP,
+ source.getMaxBackOffSleepInterval());
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestAvroSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestAvroSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestAvroSource.java
index c75d098..d73e5ad 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestAvroSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestAvroSource.java
@@ -135,42 +135,47 @@ public class TestAvroSource {
}
@Test
- public void testRequestWithCompressionOnClientAndServerOnLevel0() throws InterruptedException, IOException {
+ public void testRequestWithCompressionOnClientAndServerOnLevel0()
+ throws InterruptedException, IOException {
doRequest(true, true, 0);
}
@Test
- public void testRequestWithCompressionOnClientAndServerOnLevel1() throws InterruptedException, IOException {
+ public void testRequestWithCompressionOnClientAndServerOnLevel1()
+ throws InterruptedException, IOException {
doRequest(true, true, 1);
}
@Test
- public void testRequestWithCompressionOnClientAndServerOnLevel6() throws InterruptedException, IOException {
+ public void testRequestWithCompressionOnClientAndServerOnLevel6()
+ throws InterruptedException, IOException {
doRequest(true, true, 6);
}
@Test
- public void testRequestWithCompressionOnClientAndServerOnLevel9() throws InterruptedException, IOException {
+ public void testRequestWithCompressionOnClientAndServerOnLevel9()
+ throws InterruptedException, IOException {
doRequest(true, true, 9);
}
- @Test(expected=org.apache.avro.AvroRemoteException.class)
+ @Test(expected = org.apache.avro.AvroRemoteException.class)
public void testRequestWithCompressionOnServerOnly() throws InterruptedException, IOException {
//This will fail because both client and server need compression on
doRequest(true, false, 6);
}
- @Test(expected=org.apache.avro.AvroRemoteException.class)
+ @Test(expected = org.apache.avro.AvroRemoteException.class)
public void testRequestWithCompressionOnClientOnly() throws InterruptedException, IOException {
//This will fail because both client and server need compression on
doRequest(false, true, 6);
}
- private void doRequest(boolean serverEnableCompression, boolean clientEnableCompression, int compressionLevel) throws InterruptedException, IOException {
+ private void doRequest(boolean serverEnableCompression, boolean clientEnableCompression,
+ int compressionLevel) throws InterruptedException, IOException {
boolean bound = false;
for (int i = 0; i < 100 && !bound; i++) {
@@ -428,8 +433,7 @@ public class TestAvroSource {
false, false);
try {
doIpFilterTest(localhost, null, false, false);
- Assert.fail(
- "The null ipFilterRules config should have thrown an exception.");
+ Assert.fail("The null ipFilterRules config should have thrown an exception.");
} catch (FlumeException e) {
//Do nothing
}
@@ -502,15 +506,15 @@ public class TestAvroSource {
try {
if (testWithSSL) {
nettyTransceiver = new NettyTransceiver(
- new InetSocketAddress (dest, selectedPort),
- new SSLChannelFactory());
+ new InetSocketAddress(dest, selectedPort),
+ new SSLChannelFactory());
client = SpecificRequestor.getClient(
- AvroSourceProtocol.class, nettyTransceiver);
+ AvroSourceProtocol.class, nettyTransceiver);
} else {
nettyTransceiver = new NettyTransceiver(
- new InetSocketAddress (dest, selectedPort));
+ new InetSocketAddress(dest, selectedPort));
client = SpecificRequestor.getClient(
- AvroSourceProtocol.class, nettyTransceiver);
+ AvroSourceProtocol.class, nettyTransceiver);
}
AvroFlumeEvent avroEvent = new AvroFlumeEvent();
@@ -523,7 +527,7 @@ public class TestAvroSource {
Assert.assertEquals(Status.OK, status);
} catch (IOException e) {
Assert.assertTrue("Should have been allowed: " + ruleDefinition,
- !eventShouldBeAllowed);
+ !eventShouldBeAllowed);
return;
} finally {
if (nettyTransceiver != null) {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestExecSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestExecSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestExecSource.java
index afa93bf..6204d13 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestExecSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestExecSource.java
@@ -19,20 +19,8 @@
package org.apache.flume.source;
-
-import static org.junit.Assert.*;
-
-import java.io.*;
-import java.lang.management.ManagementFactory;
-import java.nio.charset.Charset;
-import java.util.*;
-import java.util.regex.Pattern;
-
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.SystemUtils;
@@ -47,22 +35,37 @@ import org.apache.flume.channel.MemoryChannel;
import org.apache.flume.channel.ReplicatingChannelSelector;
import org.apache.flume.conf.Configurables;
import org.apache.flume.lifecycle.LifecycleException;
-import org.junit.*;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-import com.google.common.base.Charsets;
-import com.google.common.collect.Lists;
-import com.google.common.io.Files;
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.management.ManagementFactory;
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
public class TestExecSource {
private AbstractSource source;
private Channel channel = new MemoryChannel();
-
private Context context = new Context();
-
private ChannelSelector rcs = new ReplicatingChannelSelector();
-
@Before
public void setUp() {
context.put("keep-alive", "1");
@@ -82,19 +85,19 @@ public class TestExecSource {
// Remove the MBean registered for Monitoring
ObjectName objName = null;
try {
- objName = new ObjectName("org.apache.flume.source"
- + ":type=" + source.getName());
+ objName = new ObjectName("org.apache.flume.source"
+ + ":type=" + source.getName());
- ManagementFactory.getPlatformMBeanServer().unregisterMBean(objName);
+ ManagementFactory.getPlatformMBeanServer().unregisterMBean(objName);
} catch (Exception ex) {
System.out.println("Failed to unregister the monitored counter: "
- + objName + ex.getMessage());
+ + objName + ex.getMessage());
}
}
@Test
public void testProcess() throws InterruptedException, LifecycleException,
- EventDeliveryException, IOException {
+ EventDeliveryException, IOException {
// Generates a random files for input\output
File inputFile = File.createTempFile("input", null);
@@ -104,16 +107,15 @@ public class TestExecSource {
// Generates input file with a random data set (10 lines, 200 characters each)
FileOutputStream outputStream1 = new FileOutputStream(inputFile);
- for (int i=0; i<10; i++) {
- outputStream1.write(
- RandomStringUtils.randomAlphanumeric(200).getBytes());
- outputStream1.write('\n');
+ for (int i = 0; i < 10; i++) {
+ outputStream1.write(RandomStringUtils.randomAlphanumeric(200).getBytes());
+ outputStream1.write('\n');
}
outputStream1.close();
String command = SystemUtils.IS_OS_WINDOWS ?
- String.format("cmd /c type %s", inputFile.getAbsolutePath()) :
- String.format("cat %s", inputFile.getAbsolutePath());
+ String.format("cmd /c type %s", inputFile.getAbsolutePath()) :
+ String.format("cat %s", inputFile.getAbsolutePath());
context.put("command", command);
context.put("keep-alive", "1");
context.put("capacity", "1000");
@@ -139,155 +141,150 @@ public class TestExecSource {
transaction.close();
Assert.assertEquals(FileUtils.checksumCRC32(inputFile),
- FileUtils.checksumCRC32(ouputFile));
+ FileUtils.checksumCRC32(ouputFile));
}
@Test
public void testShellCommandSimple() throws InterruptedException, LifecycleException,
- EventDeliveryException, IOException {
+ EventDeliveryException, IOException {
if (SystemUtils.IS_OS_WINDOWS) {
runTestShellCmdHelper("powershell -ExecutionPolicy Unrestricted -command",
- "1..5", new String[]{"1", "2", "3", "4", "5"});
+ "1..5", new String[] { "1", "2", "3", "4", "5" });
} else {
runTestShellCmdHelper("/bin/bash -c", "seq 5",
- new String[]{"1", "2", "3", "4", "5"});
+ new String[] { "1", "2", "3", "4", "5" });
}
}
@Test
- public void testShellCommandBackTicks()
- throws InterruptedException, LifecycleException, EventDeliveryException,
- IOException {
+ public void testShellCommandBackTicks() throws InterruptedException, LifecycleException,
+ EventDeliveryException, IOException {
// command with backticks
if (SystemUtils.IS_OS_WINDOWS) {
- runTestShellCmdHelper(
- "powershell -ExecutionPolicy Unrestricted -command", "$(1..5)",
- new String[]{"1", "2", "3", "4", "5"});
+ runTestShellCmdHelper("powershell -ExecutionPolicy Unrestricted -command", "$(1..5)",
+ new String[] { "1", "2", "3", "4", "5" });
} else {
runTestShellCmdHelper("/bin/bash -c", "echo `seq 5`",
- new String[]{"1 2 3 4 5"});
+ new String[] { "1 2 3 4 5" });
runTestShellCmdHelper("/bin/bash -c", "echo $(seq 5)",
- new String[]{"1 2 3 4 5"});
+ new String[] { "1 2 3 4 5" });
}
}
@Test
public void testShellCommandComplex()
- throws InterruptedException, LifecycleException, EventDeliveryException,
- IOException {
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
// command with wildcards & pipes
String[] expected = {"1234", "abcd", "ijk", "xyz", "zzz"};
// pipes
if (SystemUtils.IS_OS_WINDOWS) {
- runTestShellCmdHelper(
- "powershell -ExecutionPolicy Unrestricted -command",
- "'zzz','1234','xyz','abcd','ijk' | sort", expected);
+ runTestShellCmdHelper("powershell -ExecutionPolicy Unrestricted -command",
+ "'zzz','1234','xyz','abcd','ijk' | sort", expected);
} else {
runTestShellCmdHelper("/bin/bash -c",
- "echo zzz 1234 xyz abcd ijk | xargs -n1 echo | sort -f", expected);
+ "echo zzz 1234 xyz abcd ijk | xargs -n1 echo | sort -f", expected);
}
}
@Test
- public void testShellCommandScript()
- throws InterruptedException, LifecycleException, EventDeliveryException,
- IOException {
+ public void testShellCommandScript() throws InterruptedException, LifecycleException,
+ EventDeliveryException, IOException {
// mini script
if (SystemUtils.IS_OS_WINDOWS) {
runTestShellCmdHelper("powershell -ExecutionPolicy Unrestricted -command",
- "foreach ($i in 1..5) { $i }", new String[]{"1", "2", "3", "4", "5"});
+ "foreach ($i in 1..5) { $i }",
+ new String[] { "1", "2", "3", "4", "5" });
// shell arithmetic
runTestShellCmdHelper("powershell -ExecutionPolicy Unrestricted -command",
- "if(2+2 -gt 3) { 'good' } else { 'not good' } ", new String[]{"good"});
+ "if(2+2 -gt 3) { 'good' } else { 'not good' } ",
+ new String[] { "good" });
} else {
- runTestShellCmdHelper("/bin/bash -c", "for i in {1..5}; do echo $i;done"
- , new String[]{"1", "2", "3", "4", "5"});
+ runTestShellCmdHelper("/bin/bash -c", "for i in {1..5}; do echo $i;done",
+ new String[] { "1", "2", "3", "4", "5" });
// shell arithmetic
- runTestShellCmdHelper("/bin/bash -c", "if ((2+2>3)); " +
- "then echo good; else echo not good; fi", new String[]{"good"});
+ runTestShellCmdHelper("/bin/bash -c",
+ "if ((2+2>3)); " + "then echo good; else echo not good; fi",
+ new String[] { "good" });
}
}
@Test
public void testShellCommandEmbeddingAndEscaping()
- throws InterruptedException, LifecycleException, EventDeliveryException,
- IOException {
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
// mini script
String fileName = SystemUtils.IS_OS_WINDOWS ?
- "src\\test\\resources\\test_command.ps1" :
- "src/test/resources/test_command.txt";
+ "src\\test\\resources\\test_command.ps1" :
+ "src/test/resources/test_command.txt";
BufferedReader reader = new BufferedReader(new FileReader(fileName));
- try {
- String shell = SystemUtils.IS_OS_WINDOWS ?
- "powershell -ExecutionPolicy Unrestricted -command" :
- "/bin/bash -c";
- String command1 = reader.readLine();
- Assert.assertNotNull(command1);
- String[] output1 = new String[] {"'1'", "\"2\"", "\\3", "\\4"};
- runTestShellCmdHelper( shell, command1 , output1);
- String command2 = reader.readLine();
- Assert.assertNotNull(command2);
- String[] output2 = new String[]{"1","2","3","4","5" };
- runTestShellCmdHelper(shell, command2 , output2);
- String command3 = reader.readLine();
- Assert.assertNotNull(command3);
- String[] output3 = new String[]{"2","3","4","5","6" };
- runTestShellCmdHelper(shell, command3 , output3);
- } finally {
- reader.close();
- }
+ try {
+ String shell = SystemUtils.IS_OS_WINDOWS ?
+ "powershell -ExecutionPolicy Unrestricted -command" :
+ "/bin/bash -c";
+ String command1 = reader.readLine();
+ Assert.assertNotNull(command1);
+ String[] output1 = new String[] { "'1'", "\"2\"", "\\3", "\\4" };
+ runTestShellCmdHelper(shell, command1, output1);
+ String command2 = reader.readLine();
+ Assert.assertNotNull(command2);
+ String[] output2 = new String[] { "1", "2", "3", "4", "5" };
+ runTestShellCmdHelper(shell, command2, output2);
+ String command3 = reader.readLine();
+ Assert.assertNotNull(command3);
+ String[] output3 = new String[] { "2", "3", "4", "5", "6" };
+ runTestShellCmdHelper(shell, command3, output3);
+ } finally {
+ reader.close();
}
+ }
@Test
- public void testMonitoredCounterGroup() throws InterruptedException, LifecycleException,
- EventDeliveryException, IOException {
+ public void testMonitoredCounterGroup()
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
// mini script
if (SystemUtils.IS_OS_WINDOWS) {
runTestShellCmdHelper("powershell -ExecutionPolicy Unrestricted -command",
- "foreach ($i in 1..5) { $i }"
- , new String[]{"1", "2", "3", "4", "5"});
+ "foreach ($i in 1..5) { $i }",
+ new String[] { "1", "2", "3", "4", "5" });
} else {
- runTestShellCmdHelper("/bin/bash -c", "for i in {1..5}; do echo $i;done"
- , new String[]{"1", "2", "3", "4", "5"});
+ runTestShellCmdHelper("/bin/bash -c", "for i in {1..5}; do echo $i;done",
+ new String[] { "1", "2", "3", "4", "5" });
}
ObjectName objName = null;
try {
- objName = new ObjectName("org.apache.flume.source"
- + ":type=" + source.getName());
-
- MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
- String strAtts[] = {"Type", "EventReceivedCount", "EventAcceptedCount"};
- AttributeList attrList = mbeanServer.getAttributes(objName, strAtts);
-
- Assert.assertNotNull(attrList.get(0));
- Assert.assertEquals("Expected Value: Type", "Type",
- ((Attribute) attrList.get(0)).getName());
- Assert.assertEquals("Expected Value: SOURCE", "SOURCE",
- ((Attribute) attrList.get(0)).getValue());
-
- Assert.assertNotNull(attrList.get(1));
- Assert.assertEquals("Expected Value: EventReceivedCount", "EventReceivedCount",
- ((Attribute) attrList.get(1)).getName());
- Assert.assertEquals("Expected Value: 5", "5",
- ((Attribute) attrList.get(1)).getValue().toString());
-
- Assert.assertNotNull(attrList.get(2));
- Assert.assertEquals("Expected Value: EventAcceptedCount", "EventAcceptedCount",
- ((Attribute) attrList.get(2)).getName());
- Assert.assertEquals("Expected Value: 5", "5",
- ((Attribute) attrList.get(2)).getValue().toString());
+ objName = new ObjectName("org.apache.flume.source" + ":type=" + source.getName());
+
+ MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+ String[] strAtts = { "Type", "EventReceivedCount", "EventAcceptedCount" };
+ AttributeList attrList = mbeanServer.getAttributes(objName, strAtts);
+
+ Assert.assertNotNull(attrList.get(0));
+ Assert.assertEquals("Expected Value: Type", "Type",
+ ((Attribute) attrList.get(0)).getName());
+ Assert.assertEquals("Expected Value: SOURCE", "SOURCE",
+ ((Attribute) attrList.get(0)).getValue());
+
+ Assert.assertNotNull(attrList.get(1));
+ Assert.assertEquals("Expected Value: EventReceivedCount", "EventReceivedCount",
+ ((Attribute) attrList.get(1)).getName());
+ Assert.assertEquals("Expected Value: 5", "5",
+ ((Attribute) attrList.get(1)).getValue().toString());
+
+ Assert.assertNotNull(attrList.get(2));
+ Assert.assertEquals("Expected Value: EventAcceptedCount", "EventAcceptedCount",
+ ((Attribute) attrList.get(2)).getName());
+ Assert.assertEquals("Expected Value: 5", "5",
+ ((Attribute) attrList.get(2)).getValue().toString());
} catch (Exception ex) {
- System.out.println("Unable to retreive the monitored counter: "
- + objName + ex.getMessage());
+ System.out.println("Unable to retreive the monitored counter: " + objName + ex.getMessage());
}
}
@Test
- public void testBatchTimeout() throws InterruptedException, LifecycleException,
- EventDeliveryException, IOException {
+ public void testBatchTimeout()
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
String filePath = "/tmp/flume-execsource." + Thread.currentThread().getId();
String eventBody = "TestMessage";
@@ -296,12 +293,12 @@ public class TestExecSource {
context.put(ExecSourceConfigurationConstants.CONFIG_BATCH_SIZE, "50000");
context.put(ExecSourceConfigurationConstants.CONFIG_BATCH_TIME_OUT, "750");
context.put("shell", SystemUtils.IS_OS_WINDOWS ?
- "powershell -ExecutionPolicy Unrestricted -command" :
- "/bin/bash -c");
+ "powershell -ExecutionPolicy Unrestricted -command" :
+ "/bin/bash -c");
context.put("command", SystemUtils.IS_OS_WINDOWS ?
- "Get-Content " + filePath +
- " | Select-Object -Last 10" :
- ("tail -f " + filePath));
+ "Get-Content " + filePath +
+ " | Select-Object -Last 10" :
+ ("tail -f " + filePath));
Configurables.configure(source, context);
source.start();
@@ -310,15 +307,15 @@ public class TestExecSource {
transaction.begin();
for (int lineNumber = 0; lineNumber < 3; lineNumber++) {
- outputStream.write((eventBody).getBytes());
- outputStream.write(String.valueOf(lineNumber).getBytes());
- outputStream.write('\n');
- outputStream.flush();
+ outputStream.write((eventBody).getBytes());
+ outputStream.write(String.valueOf(lineNumber).getBytes());
+ outputStream.write('\n');
+ outputStream.flush();
}
outputStream.close();
Thread.sleep(1500);
- for(int i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
Event event = channel.take();
assertNotNull(event);
assertNotNull(event.getBody());
@@ -332,45 +329,37 @@ public class TestExecSource {
FileUtils.forceDelete(file);
}
- private void runTestShellCmdHelper(String shell, String command, String[] expectedOutput)
- throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
- context.put("shell", shell);
- context.put("command", command);
- Configurables.configure(source, context);
- source.start();
- // Some commands might take longer to complete, specially on Windows
- // or on slow environments (e.g. Travis CI).
- Thread.sleep(2500);
- Transaction transaction = channel.getTransaction();
- transaction.begin();
- try {
- List<String> output = Lists.newArrayList();
- Event event;
- while ((event = channel.take()) != null) {
- output.add(new String(event.getBody(), Charset.defaultCharset()));
- }
- transaction.commit();
-// System.out.println("command : " + command);
-// System.out.println("output : ");
-// for( String line : output )
-// System.out.println(line);
- Assert.assertArrayEquals(expectedOutput, output.toArray(new String[]{}));
- } finally {
- transaction.close();
- source.stop();
+ private void runTestShellCmdHelper(String shell, String command, String[] expectedOutput)
+ throws InterruptedException, LifecycleException, EventDeliveryException, IOException {
+ context.put("shell", shell);
+ context.put("command", command);
+ Configurables.configure(source, context);
+ source.start();
+ // Some commands might take longer to complete, specially on Windows
+ // or on slow environments (e.g. Travis CI).
+ Thread.sleep(2500);
+ Transaction transaction = channel.getTransaction();
+ transaction.begin();
+ try {
+ List<String> output = Lists.newArrayList();
+ Event event;
+ while ((event = channel.take()) != null) {
+ output.add(new String(event.getBody(), Charset.defaultCharset()));
}
+ transaction.commit();
+ Assert.assertArrayEquals(expectedOutput, output.toArray(new String[] {}));
+ } finally {
+ transaction.close();
+ source.stop();
}
-
+ }
@Test
public void testRestart() throws InterruptedException, LifecycleException,
- EventDeliveryException, IOException {
-
+ EventDeliveryException, IOException {
context.put(ExecSourceConfigurationConstants.CONFIG_RESTART_THROTTLE, "10");
context.put(ExecSourceConfigurationConstants.CONFIG_RESTART, "true");
-
- context.put("command",
- SystemUtils.IS_OS_WINDOWS ? "cmd /c echo flume" : "echo flume");
+ context.put("command", SystemUtils.IS_OS_WINDOWS ? "cmd /c echo flume" : "echo flume");
Configurables.configure(source, context);
source.start();
@@ -380,7 +369,7 @@ public class TestExecSource {
long start = System.currentTimeMillis();
- for(int i = 0; i < 5; i++) {
+ for (int i = 0; i < 5; i++) {
Event event = channel.take();
assertNotNull(event);
assertNotNull(event.getBody());
@@ -396,7 +385,6 @@ public class TestExecSource {
source.stop();
}
-
/**
* Tests to make sure that the shutdown mechanism works. There are races
* in this test if the system has another sleep command running with the
@@ -412,14 +400,12 @@ public class TestExecSource {
boolean searchForCommand = true;
while (searchForCommand) {
searchForCommand = false;
- String command = SystemUtils.IS_OS_WINDOWS ? ("cmd /c sleep " + seconds) :
- ("sleep " + seconds);
- String searchTxt = SystemUtils.IS_OS_WINDOWS ? ("sleep.exe") :
- ("\b" + command + "\b");
+ String command = SystemUtils.IS_OS_WINDOWS ? "cmd /c sleep " + seconds : "sleep " + seconds;
+ String searchTxt = SystemUtils.IS_OS_WINDOWS ? "sleep.exe" : "\b" + command + "\b";
Pattern pattern = Pattern.compile(searchTxt);
for (String line : exec(SystemUtils.IS_OS_WINDOWS ?
- "cmd /c tasklist /FI \"SESSIONNAME eq Console\"" :
- "ps -ef")) {
+ "cmd /c tasklist /FI \"SESSIONNAME eq Console\"" :
+ "ps -ef")) {
if (pattern.matcher(line).find()) {
seconds++;
searchForCommand = true;
@@ -444,9 +430,9 @@ public class TestExecSource {
source.stop();
Thread.sleep(1000L);
for (String line : exec(SystemUtils.IS_OS_WINDOWS ?
- "cmd /c tasklist /FI \"SESSIONNAME eq Console\"" :
- "ps -ef")) {
- if(pattern.matcher(line).find()) {
+ "cmd /c tasklist /FI \"SESSIONNAME eq Console\"" :
+ "ps -ef")) {
+ if (pattern.matcher(line).find()) {
Assert.fail("Found [" + line + "]");
}
}
@@ -457,23 +443,21 @@ public class TestExecSource {
Process process = new ProcessBuilder(commandArgs).start();
BufferedReader reader = null;
try {
- reader = new BufferedReader(
- new InputStreamReader(process.getInputStream()));
+ reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
List<String> result = Lists.newArrayList();
String line;
- while((line = reader.readLine()) != null) {
+ while ((line = reader.readLine()) != null) {
result.add(line);
}
return result;
} finally {
process.destroy();
- if(reader != null) {
+ if (reader != null) {
reader.close();
}
int exit = process.waitFor();
- if(exit != 0) {
- throw new IllegalStateException("Command [" + command + "] exited with "
- + exit);
+ if (exit != 0) {
+ throw new IllegalStateException("Command [" + command + "] exited with " + exit);
}
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java
index c3dc241..56c7881 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java
@@ -58,6 +58,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import static org.mockito.Mockito.*;
public class TestMultiportSyslogTCPSource {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestNetcatSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestNetcatSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestNetcatSource.java
index e11b4b6..99d413a 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestNetcatSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestNetcatSource.java
@@ -21,7 +21,11 @@ package org.apache.flume.source;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.LineIterator;
-import org.apache.flume.*;
+import org.apache.flume.Channel;
+import org.apache.flume.ChannelSelector;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.flume.Transaction;
import org.apache.flume.channel.ChannelProcessor;
import org.apache.flume.channel.MemoryChannel;
import org.apache.flume.channel.ReplicatingChannelSelector;
@@ -45,26 +49,27 @@ import java.util.ArrayList;
import java.util.List;
public class TestNetcatSource {
- private static final Logger logger = LoggerFactory
- .getLogger(TestAvroSource.class);
+ private static final Logger logger =
+ LoggerFactory.getLogger(TestAvroSource.class);
/**
* Five first sentences of the Fables "The Crow and the Fox"
* written by Jean de La Fontaine, French poet.
*
- * @see <a href="http://en.wikipedia.org/wiki/Jean_de_La_Fontaine">Jean de La Fontaine on wikipedia</a>
+ * @see <a href="http://en.wikipedia.org/wiki/Jean_de_La_Fontaine">Jean de La Fontaine on
+ * wikipedia</a>
*/
private final String french = "Ma�tre Corbeau, sur un arbre perch�, " +
- "Tenait en son bec un fromage. " +
- "Ma�tre Renard, par l'odeur all�ch�, " +
- "Lui tint � peu pr�s ce langage : " +
- "Et bonjour, Monsieur du Corbeau,";
+ "Tenait en son bec un fromage. " +
+ "Ma�tre Renard, par l'odeur all�ch�, " +
+ "Lui tint � peu pr�s ce langage : " +
+ "Et bonjour, Monsieur du Corbeau,";
private final String english = "At the top of a tree perched Master Crow; " +
- "In his beak he was holding a cheese. " +
- "Drawn by the smell, Master Fox spoke, below. " +
- "The words, more or less, were these: " +
- "\"Hey, now, Sir Crow! Good day, good day!";
+ "In his beak he was holding a cheese. " +
+ "Drawn by the smell, Master Fox spoke, below. " +
+ "The words, more or less, were these: " +
+ "\"Hey, now, Sir Crow! Good day, good day!";
private int selectedPort;
private NetcatSource source;
@@ -109,12 +114,14 @@ public class TestNetcatSource {
// Test on english text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, english, encoding);
- Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset),
+ getFlumeEvent());
}
// Test on french text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, french, encoding);
- Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset),
+ getFlumeEvent());
}
} finally {
netcatSocket.close();
@@ -137,12 +144,14 @@ public class TestNetcatSource {
// Test on english text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, english, encoding);
- Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset),
+ getFlumeEvent());
}
// Test on french text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, french, encoding);
- Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset),
+ getFlumeEvent());
}
} finally {
netcatSocket.close();
@@ -165,12 +174,14 @@ public class TestNetcatSource {
// Test on english text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, english, encoding);
- Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset),
+ getFlumeEvent());
}
// Test on french text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, french, encoding);
- Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset),
+ getFlumeEvent());
}
} finally {
netcatSocket.close();
@@ -193,12 +204,14 @@ public class TestNetcatSource {
// Test on english text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, english, encoding);
- Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset),
+ getFlumeEvent());
}
// Test on french text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, french, encoding);
- Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset),
+ getFlumeEvent());
}
} finally {
netcatSocket.close();
@@ -223,13 +236,15 @@ public class TestNetcatSource {
// Test on english text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, english, encoding);
- Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", english.getBytes(defaultCharset),
+ getFlumeEvent());
Assert.assertEquals("Socket contained the Ack", ackEvent, inputLineIterator.nextLine());
}
// Test on french text snippet
for (int i = 0; i < 20; i++) {
sendEvent(netcatSocket, french, encoding);
- Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event", french.getBytes(defaultCharset),
+ getFlumeEvent());
Assert.assertEquals("Socket contained the Ack", ackEvent, inputLineIterator.nextLine());
}
} finally {
@@ -251,7 +266,8 @@ public class TestNetcatSource {
Socket netcatSocket = new Socket(localhost, selectedPort);
try {
sendEvent(netcatSocket, "123456789", encoding);
- Assert.assertArrayEquals("Channel contained our event", "123456789".getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event",
+ "123456789".getBytes(defaultCharset), getFlumeEvent());
sendEvent(netcatSocket, english, encoding);
Assert.assertEquals("Channel does not contain an event", null, getRawFlumeEvent());
} finally {
@@ -276,18 +292,21 @@ public class TestNetcatSource {
LineIterator inputLineIterator = IOUtils.lineIterator(netcatSocket.getInputStream(), encoding);
try {
sendEvent(netcatSocket, "123456789", encoding);
- Assert.assertArrayEquals("Channel contained our event", "123456789".getBytes(defaultCharset), getFlumeEvent());
+ Assert.assertArrayEquals("Channel contained our event",
+ "123456789".getBytes(defaultCharset), getFlumeEvent());
Assert.assertEquals("Socket contained the Ack", ackEvent, inputLineIterator.nextLine());
sendEvent(netcatSocket, english, encoding);
Assert.assertEquals("Channel does not contain an event", null, getRawFlumeEvent());
- Assert.assertEquals("Socket contained the Error Ack", ackErrorEvent, inputLineIterator.nextLine());
+ Assert.assertEquals("Socket contained the Error Ack", ackErrorEvent, inputLineIterator
+ .nextLine());
} finally {
netcatSocket.close();
stopSource();
}
}
- private void startSource(String encoding, String ack, String batchSize, String maxLineLength) throws InterruptedException {
+ private void startSource(String encoding, String ack, String batchSize, String maxLineLength)
+ throws InterruptedException {
boolean bound = false;
for (int i = 0; i < 100 && !bound; i++) {
@@ -313,9 +332,9 @@ public class TestNetcatSource {
}
Assert.assertTrue("Reached start or error",
- LifecycleController.waitForOneOf(source, LifecycleState.START_OR_ERROR));
+ LifecycleController.waitForOneOf(source, LifecycleState.START_OR_ERROR));
Assert.assertEquals("Server is started", LifecycleState.START,
- source.getLifecycleState());
+ source.getLifecycleState());
}
private void sendEvent(Socket socket, String content, String encoding) throws IOException {
@@ -366,9 +385,9 @@ public class TestNetcatSource {
private void stopSource() throws InterruptedException {
source.stop();
Assert.assertTrue("Reached stop or error",
- LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR));
+ LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR));
Assert.assertEquals("Server is stopped", LifecycleState.STOP,
- source.getLifecycleState());
+ source.getLifecycleState());
logger.info("Source stopped");
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestSequenceGeneratorSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSequenceGeneratorSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestSequenceGeneratorSource.java
index 2bbcdaf..5d6cc29 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSequenceGeneratorSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestSequenceGeneratorSource.java
@@ -18,9 +18,6 @@
*/
package org.apache.flume.source;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
import org.apache.flume.Context;
@@ -36,6 +33,9 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import java.util.ArrayList;
+import java.util.List;
+
public class TestSequenceGeneratorSource {
private PollableSource source;
@@ -105,7 +105,7 @@ public class TestSequenceGeneratorSource {
for (long j = batchSize; j > 0; j--) {
Event event = channel.take();
- String expectedVal = String.valueOf(((i+1)*batchSize)-j);
+ String expectedVal = String.valueOf(((i + 1) * batchSize) - j);
String resultedVal = new String(event.getBody());
Assert.assertTrue("Expected " + expectedVal + " is not equals to " +
resultedVal, expectedVal.equals(resultedVal));
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestSpoolDirectorySource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSpoolDirectorySource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestSpoolDirectorySource.java
index 47fdc7a..82c5351 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSpoolDirectorySource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestSpoolDirectorySource.java
@@ -17,15 +17,9 @@
package org.apache.flume.source;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
+import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
+import com.google.common.io.Files;
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
import org.apache.flume.Context;
@@ -42,8 +36,13 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import com.google.common.base.Charsets;
-import com.google.common.io.Files;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
public class TestSpoolDirectorySource {
static SpoolDirectorySource source;
@@ -151,14 +150,13 @@ public class TestSpoolDirectorySource {
* Tests if SpoolDirectorySource sets basename headers on events correctly
*/
@Test
- public void testPutBasenameHeader() throws IOException,
- InterruptedException {
+ 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);
+ "file1line5\nfile1line6\nfile1line7\nfile1line8\n",
+ f1, Charsets.UTF_8);
context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY,
tmpDir.getAbsolutePath());
@@ -179,7 +177,7 @@ public class TestSpoolDirectorySource {
Assert.assertNotNull("Event headers must not be null", e.getHeaders());
Assert.assertNotNull(e.getHeaders().get("basenameHeaderKeyTest"));
Assert.assertEquals(f1.getName(),
- e.getHeaders().get("basenameHeaderKeyTest"));
+ e.getHeaders().get("basenameHeaderKeyTest"));
txn.commit();
txn.close();
}
@@ -233,7 +231,7 @@ public class TestSpoolDirectorySource {
baos.write(e.getBody());
baos.write('\n'); // newline characters are consumed in the process
e = channel.take();
- } while(e != null);
+ } while (e != null);
Assert.assertEquals("Event body is correct",
Arrays.toString(origBody.getBytes()),
@@ -371,7 +369,7 @@ public class TestSpoolDirectorySource {
context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY,
- tmpDir.getAbsolutePath());
+ tmpDir.getAbsolutePath());
context.put(SpoolDirectorySourceConfigurationConstants.BATCH_SIZE, "2");
Configurables.configure(source, context);
@@ -379,7 +377,7 @@ public class TestSpoolDirectorySource {
source.start();
// Wait for the source to read enough events to fill up the channel.
- while(!source.hitChannelException()) {
+ while (!source.hitChannelException()) {
Thread.sleep(50);
}
@@ -402,7 +400,7 @@ public class TestSpoolDirectorySource {
tx.close();
}
Assert.assertTrue("Expected to hit ChannelException, but did not!",
- source.hitChannelException());
+ source.hitChannelException());
Assert.assertEquals(8, dataOut.size());
source.stop();
}
@@ -424,7 +422,7 @@ public class TestSpoolDirectorySource {
Files.touch(f4);
context.put(SpoolDirectorySourceConfigurationConstants.SPOOL_DIRECTORY,
- tmpDir.getAbsolutePath());
+ tmpDir.getAbsolutePath());
Configurables.configure(source, context);
source.start();
@@ -432,8 +430,8 @@ public class TestSpoolDirectorySource {
Thread.sleep(5000);
Assert.assertFalse("Server did not error", source.hasFatalError());
- Assert.assertEquals("One message was read", 1,
- source.getSourceCounter().getEventAcceptedCount());
+ Assert.assertEquals("One message was read",
+ 1, source.getSourceCounter().getEventAcceptedCount());
source.stop();
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestStressSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestStressSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestStressSource.java
index a651281..06e663c 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestStressSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestStressSource.java
@@ -101,7 +101,7 @@ public class TestStressSource {
}
if (i < 3) {
verify(mockProcessor,
- times(i+1)).processEventBatch(getLastProcessedEventList(source));
+ times(i + 1)).processEventBatch(getLastProcessedEventList(source));
} else {
verify(mockProcessor,
times(1)).processEventBatch(getLastProcessedEventList(source));
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogParser.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogParser.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogParser.java
index 265157e..7edb9b7 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogParser.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogParser.java
@@ -20,17 +20,17 @@ package org.apache.flume.source;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
-import java.nio.charset.Charset;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.apache.flume.Event;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.junit.Assert;
import org.junit.Test;
+import java.nio.charset.Charset;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
public class TestSyslogParser {
@Test
public void testRfc5424DateParsing() {
@@ -84,7 +84,7 @@ public class TestSyslogParser {
Set<String> keepFields = new HashSet<String>();
Event event = parser.parseMessage(msg, charset, keepFields);
Assert.assertNull("Failure to parse known-good syslog message",
- event.getHeaders().get(SyslogUtils.EVENT_STATUS));
+ event.getHeaders().get(SyslogUtils.EVENT_STATUS));
}
// test that priority, timestamp and hostname are preserved in event body
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogTcpSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogTcpSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogTcpSource.java
index 239ba51..10ef8d8 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogTcpSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogTcpSource.java
@@ -41,7 +41,7 @@ import java.util.List;
public class TestSyslogTcpSource {
private static final org.slf4j.Logger logger =
- LoggerFactory.getLogger(TestSyslogTcpSource.class);
+ LoggerFactory.getLogger(TestSyslogTcpSource.class);
private SyslogTcpSource source;
private Channel channel;
private static final int TEST_SYSLOG_PORT = 0;
@@ -56,7 +56,7 @@ public class TestSyslogTcpSource {
private final String bodyWithTandH = "<10>" + stamp1 + " " + host1 + " " +
data1 + "\n";
- private void init(String keepFields){
+ private void init(String keepFields) {
source = new SyslogTcpSource();
channel = new MemoryChannel();
@@ -116,7 +116,7 @@ public class TestSyslogTcpSource {
logger.info(str);
if (keepFields.equals("true") || keepFields.equals("all")) {
Assert.assertArrayEquals(bodyWithTandH.trim().getBytes(),
- e.getBody());
+ e.getBody());
} else if (keepFields.equals("false") || keepFields.equals("none")) {
Assert.assertArrayEquals(data1.getBytes(), e.getBody());
} else if (keepFields.equals("hostname")) {
@@ -136,7 +136,7 @@ public class TestSyslogTcpSource {
}
@Test
- public void testRemoveFields() throws IOException{
+ public void testRemoveFields() throws IOException {
runKeepFieldsTest("none");
// Backwards compatibility
@@ -144,12 +144,12 @@ public class TestSyslogTcpSource {
}
@Test
- public void testKeepHostname() throws IOException{
+ public void testKeepHostname() throws IOException {
runKeepFieldsTest("hostname");
}
@Test
- public void testKeepTimestamp() throws IOException{
+ public void testKeepTimestamp() throws IOException {
runKeepFieldsTest("timestamp");
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUdpSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUdpSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUdpSource.java
index 8fc80be..e5b7a06 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUdpSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUdpSource.java
@@ -18,14 +18,7 @@
*/
package org.apache.flume.source;
-import java.util.ArrayList;
-import java.util.List;
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.InetAddress;
-import java.net.DatagramSocket;
import com.google.common.base.Charsets;
-import com.google.common.base.Strings;
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
import org.apache.flume.Context;
@@ -40,10 +33,16 @@ import org.junit.Assert;
import org.junit.Test;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
public class TestSyslogUdpSource {
private static final org.slf4j.Logger logger =
- LoggerFactory.getLogger(TestSyslogUdpSource.class);
+ LoggerFactory.getLogger(TestSyslogUdpSource.class);
private SyslogUDPSource source;
private Channel channel;
private static final int TEST_SYSLOG_PORT = 0;
@@ -192,12 +191,12 @@ public class TestSyslogUdpSource {
}
@Test
- public void testKeepHostname() throws IOException{
+ public void testKeepHostname() throws IOException {
runKeepFieldsTest("hostname");
}
@Test
- public void testKeepTimestamp() throws IOException{
+ public void testKeepTimestamp() throws IOException {
runKeepFieldsTest("timestamp");
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUtils.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUtils.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUtils.java
index 1c005ff..80d8dac 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUtils.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestSyslogUtils.java
@@ -18,7 +18,6 @@
*/
package org.apache.flume.source;
-
import org.apache.flume.Event;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
@@ -41,7 +40,7 @@ public class TestSyslogUtils {
String host1 = "ubuntu-11.cloudera.com";
String data1 = "some msg";
// timestamp with hh:mm format timezone with no version
- String msg1 = "<10>" + stamp1+ "+08:00" + " " + host1 + " " + data1 + "\n";
+ String msg1 = "<10>" + stamp1 + "+08:00" + " " + host1 + " " + data1 + "\n";
checkHeader(msg1, stamp1 + "+0800", format1, host1, data1);
}
@@ -62,7 +61,7 @@ public class TestSyslogUtils {
String host1 = "ubuntu-11.cloudera.com";
String data1 = "some msg";
// timestamp with 'Z' appended, translates to UTC
- String msg1 = "<10>1 " + stamp1+ "Z" + " " + host1 + " " + data1 + "\n";
+ String msg1 = "<10>1 " + stamp1 + "Z" + " " + host1 + " " + data1 + "\n";
checkHeader(msg1, stamp1 + "+0000", format1, host1, data1);
}
@@ -73,13 +72,13 @@ public class TestSyslogUtils {
String host1 = "ubuntu-11.cloudera.com";
String data1 = "some msg";
// timestamp with hh:mm format timezone
- String msg1 = "<10>1 " + stamp1+ "+08:00" + " " + host1 + " " + data1 + "\n";
+ String msg1 = "<10>1 " + stamp1 + "+08:00" + " " + host1 + " " + data1 + "\n";
checkHeader(msg1, stamp1 + "+0800", format1, host1, data1);
}
@Test
public void TestHeader4() throws ParseException {
- String host1 = "ubuntu-11.cloudera.com";
+ String host1 = "ubuntu-11.cloudera.com";
String data1 = "some msg";
// null format timestamp (-)
String msg1 = "<10>1 " + "-" + " " + host1 + " " + data1 + "\n";
@@ -104,7 +103,7 @@ public class TestSyslogUtils {
String host1 = "-";
String data1 = "some msg";
// null host
- String msg1 = "<10>1 " + stamp1+ "Z" + " " + host1 + " " + data1 + "\n";
+ String msg1 = "<10>1 " + stamp1 + "Z" + " " + host1 + " " + data1 + "\n";
checkHeader(msg1, stamp1 + "+0000", format1, null, data1);
}
@@ -115,7 +114,7 @@ public class TestSyslogUtils {
String host1 = "-";
String data1 = "some msg";
// null host
- String msg1 = "<10>1 " + stamp1+ "+08:00" + " " + host1 + " " + data1 + "\n";
+ String msg1 = "<10>1 " + stamp1 + "+08:00" + " " + host1 + " " + data1 + "\n";
checkHeader(msg1, stamp1 + "+0800", format1, null, data1);
}
@@ -141,8 +140,7 @@ public class TestSyslogUtils {
String data1 = "some msg";
// timestamp with 'Z' appended, translates to UTC
String msg1 = "<10>" + stamp1 + " " + host1 + " " + data1 + "\n";
- checkHeader(msg1, year + stamp1,
- format1, host1, data1);
+ checkHeader(msg1, year + stamp1, format1, host1, data1);
}
@Test
@@ -157,8 +155,7 @@ public class TestSyslogUtils {
String data1 = "some msg";
// timestamp with 'Z' appended, translates to UTC
String msg1 = "<10>" + stamp1 + " " + host1 + " " + data1 + "\n";
- checkHeader(msg1, year + stamp1,
- format1, host1, data1);
+ checkHeader(msg1, year + stamp1, format1, host1, data1);
}
@Test
@@ -187,21 +184,19 @@ public class TestSyslogUtils {
String host1 = "ubuntu-11.cloudera.com";
String data1 = "- hyphen_null_breaks_5424_pattern [07/Jun/2012:14:46:44 -0600]";
String msg1 = "<10>" + stamp1 + " " + host1 + " " + data1 + "\n";
- checkHeader(msg1, year + stamp1,
- format1, host1, data1);
+ checkHeader(msg1, year + stamp1, format1, host1, data1);
}
+ /* This test creates a series of dates that range from 10 months in the past to (5 days short
+ * of) one month in the future. This tests that the year addition code is clever enough to
+ * handle scenarios where the event received was generated in a different year to what flume
+ * considers to be "current" (e.g. where there has been some lag somewhere, especially when
+ * flicking over on New Year's eve, or when you are about to flick over and the flume's
+ * system clock is slightly slower than the Syslog source's clock).
+ */
@Test
public void TestRfc3164Dates() throws ParseException {
- /*
- * This test creates a series of dates that range from 10 months in the past to (5 days short of)
- * one month in the future. This tests that the year addition code is clever enough to handle scenarios
- * where the event received was generated in a different year to what flume considers to be "current"
- * (e.g. where there has been some lag somewhere, especially when flicking over on New Year's eve, or
- * when you are about to flick over and the flume's system clock is slightly slower than the Syslog
- * source's clock).
- */
- for (int i=-10; i<=1; i++) {
+ for (int i = -10; i <= 1; i++) {
SimpleDateFormat sdf = new SimpleDateFormat("MMM d hh:MM:ss");
Date date = new Date(System.currentTimeMillis());
Calendar cal = Calendar.getInstance();
@@ -210,7 +205,7 @@ public class TestSyslogUtils {
//Small tweak to avoid the 1 month in the future ticking over by a few seconds between now
//and when the checkHeader actually runs
- if (i==1) {
+ if (i == 1) {
cal.add(Calendar.DAY_OF_MONTH, -1);
}
@@ -223,8 +218,7 @@ public class TestSyslogUtils {
// timestamp with 'Z' appended, translates to UTC
String msg1 = "<10>" + stamp1 + " " + host1 + " " + data1 + "\n";
- checkHeader(msg1, year + stamp1,
- format1, host1, data1);
+ checkHeader(msg1, year + stamp1, format1, host1, data1);
}
}
@@ -234,16 +228,15 @@ public class TestSyslogUtils {
if (keepFields == null || keepFields.isEmpty()) {
util = new SyslogUtils(SyslogUtils.DEFAULT_SIZE, new HashSet<String>(), false);
} else {
- util = new SyslogUtils(
- SyslogUtils.DEFAULT_SIZE,
- SyslogUtils.chooseFieldsToKeep(keepFields),
- false);
+ util = new SyslogUtils(SyslogUtils.DEFAULT_SIZE,
+ SyslogUtils.chooseFieldsToKeep(keepFields),
+ false);
}
ChannelBuffer buff = ChannelBuffers.buffer(200);
buff.writeBytes(msg1.getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e.getHeaders();
@@ -251,13 +244,14 @@ public class TestSyslogUtils {
Assert.assertFalse(headers2.containsKey("timestamp"));
} else {
SimpleDateFormat formater = new SimpleDateFormat(format1, Locale.ENGLISH);
- Assert.assertEquals(String.valueOf(formater.parse(stamp1).getTime()), headers2.get("timestamp"));
+ Assert.assertEquals(String.valueOf(formater.parse(stamp1).getTime()),
+ headers2.get("timestamp"));
}
if (host1 == null) {
Assert.assertFalse(headers2.containsKey("host"));
} else {
String host2 = headers2.get("host");
- Assert.assertEquals(host2,host1);
+ Assert.assertEquals(host2, host1);
}
Assert.assertEquals(data1, new String(e.getBody()));
}
@@ -278,22 +272,20 @@ public class TestSyslogUtils {
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
- headers.get(SyslogUtils.EVENT_STATUS));
+ headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
-
}
/**
* Test bad event format 2: The first char is not <
*/
-
@Test
public void testExtractBadEvent2() {
String badData1 = "hi guys! <10> bad bad data\n";
@@ -301,22 +293,20 @@ public class TestSyslogUtils {
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
- headers.get(SyslogUtils.EVENT_STATUS));
+ headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
-
}
/**
* Test bad event format 3: Empty priority - <>
*/
-
@Test
public void testExtractBadEvent3() {
String badData1 = "<> bad bad data\n";
@@ -324,22 +314,20 @@ public class TestSyslogUtils {
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
- headers.get(SyslogUtils.EVENT_STATUS));
+ headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
-
}
/**
* Test bad event format 4: Priority too long
*/
-
@Test
public void testExtractBadEvent4() {
String badData1 = "<123123123123123123123123123123> bad bad data\n";
@@ -347,16 +335,15 @@ public class TestSyslogUtils {
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
- headers.get(SyslogUtils.EVENT_STATUS));
+ headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
-
}
/**
@@ -368,9 +355,9 @@ public class TestSyslogUtils {
String goodData1 = "Good good good data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
- buff.writeBytes((priority+goodData1).getBytes());
+ buff.writeBytes((priority + goodData1).getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
@@ -378,86 +365,81 @@ public class TestSyslogUtils {
Assert.assertEquals("2", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(null, headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(priority + goodData1.trim(),
- new String(e.getBody()).trim());
-
+ new String(e.getBody()).trim());
}
/**
* Bad event immediately followed by a good event
*/
@Test
- public void testBadEventGoodEvent(){
+ public void testBadEventGoodEvent() {
String badData1 = "hi guys! <10F> bad bad data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
String priority = "<10>";
String goodData1 = "Good good good data\n";
- buff.writeBytes((priority+goodData1).getBytes());
+ buff.writeBytes((priority + goodData1).getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
- headers.get(SyslogUtils.EVENT_STATUS));
- Assert.assertEquals(badData1.trim(), new String(e.getBody())
- .trim());
+ headers.get(SyslogUtils.EVENT_STATUS));
+ Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
Event e2 = util.extractEvent(buff);
- if(e2 == null){
+ if (e2 == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e2.getHeaders();
Assert.assertEquals("1", headers2.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("2", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
- Assert.assertEquals(null,
- headers2.get(SyslogUtils.EVENT_STATUS));
- Assert.assertEquals(priority + goodData1.trim(),
- new String(e2.getBody()).trim());
+ Assert.assertEquals(null, headers2.get(SyslogUtils.EVENT_STATUS));
+ Assert.assertEquals(priority + goodData1.trim(), new String(e2.getBody()).trim());
}
@Test
- public void testGoodEventBadEvent(){
+ public void testGoodEventBadEvent() {
String badData1 = "hi guys! <10F> bad bad data\n";
String priority = "<10>";
String goodData1 = "Good good good data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
- buff.writeBytes((priority+goodData1).getBytes());
+ buff.writeBytes((priority + goodData1).getBytes());
buff.writeBytes(badData1.getBytes());
Event e2 = util.extractEvent(buff);
- if(e2 == null){
+ if (e2 == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e2.getHeaders();
Assert.assertEquals("1", headers2.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("2", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(null,
- headers2.get(SyslogUtils.EVENT_STATUS));
+ headers2.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(priority + goodData1.trim(),
- new String(e2.getBody()).trim());
+ new String(e2.getBody()).trim());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
- headers.get(SyslogUtils.EVENT_STATUS));
+ headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
-
}
@Test
- public void testBadEventBadEvent(){
+ public void testBadEventBadEvent() {
String badData1 = "hi guys! <10F> bad bad data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
@@ -466,65 +448,63 @@ public class TestSyslogUtils {
buff.writeBytes((badData2).getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
- headers.get(SyslogUtils.EVENT_STATUS));
+ headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
Event e2 = util.extractEvent(buff);
- if(e2 == null){
+ if (e2 == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e2.getHeaders();
Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
- headers2.get(SyslogUtils.EVENT_STATUS));
+ headers2.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData2.trim(), new String(e2.getBody()).trim());
}
@Test
public void testGoodEventGoodEvent() {
-
String priority = "<10>";
String goodData1 = "Good good good data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
- buff.writeBytes((priority+goodData1).getBytes());
+ buff.writeBytes((priority + goodData1).getBytes());
String priority2 = "<20>";
String goodData2 = "Good really good data\n";
- buff.writeBytes((priority2+goodData2).getBytes());
+ buff.writeBytes((priority2 + goodData2).getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("1", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("2", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(null,
- headers.get(SyslogUtils.EVENT_STATUS));
+ headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(priority + goodData1.trim(),
- new String(e.getBody()).trim());
+ new String(e.getBody()).trim());
Event e2 = util.extractEvent(buff);
- if(e2 == null){
+ if (e2 == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e2.getHeaders();
Assert.assertEquals("2", headers2.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("4", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(null,
- headers.get(SyslogUtils.EVENT_STATUS));
+ headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(priority2 + goodData2.trim(),
- new String(e2.getBody()).trim());
-
+ new String(e2.getBody()).trim());
}
@Test
@@ -535,28 +515,27 @@ public class TestSyslogUtils {
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
Event e = util.extractEvent(buff);
- if(e == null){
+ if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("1", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("2", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INCOMPLETE.getSyslogStatus(),
- headers.get(SyslogUtils.EVENT_STATUS));
+ headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals("<10> bad b".trim(), new String(e.getBody()).trim());
Event e2 = util.extractEvent(buff);
- if(e2 == null){
+ if (e2 == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e2.getHeaders();
Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
- headers2.get(SyslogUtils.EVENT_STATUS));
+ headers2.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals("ad data ba".trim(), new String(e2.getBody()).trim());
-
}
@Test
@@ -580,7 +559,8 @@ public class TestSyslogUtils {
checkHeader("priority timestamp hostname", msg1, stamp1 + "+0800", format1, host1, data4);
String data5 = "<10>1 2012-04-13T11:11:11+08:00 ubuntu-11.cloudera.com some msg";
- checkHeader("priority version timestamp hostname", msg1, stamp1 + "+0800", format1, host1, data5);
+ checkHeader("priority version timestamp hostname", msg1, stamp1 + "+0800",
+ format1, host1, data5);
checkHeader("all", msg1, stamp1 + "+0800", format1, host1, data5);
checkHeader("true", msg1, stamp1 + "+0800", format1, host1, data5);
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/TestThriftSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/TestThriftSource.java b/flume-ng-core/src/test/java/org/apache/flume/source/TestThriftSource.java
index 3d2901a..cdaefaf 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/TestThriftSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/TestThriftSource.java
@@ -67,10 +67,9 @@ public class TestThriftSource {
port = random.nextInt(50000) + 1024;
props.clear();
props.setProperty("hosts", "h1");
- props.setProperty("hosts.h1", "0.0.0.0:"+ String.valueOf(port));
+ props.setProperty("hosts.h1", "0.0.0.0:" + String.valueOf(port));
props.setProperty(RpcClientConfigurationConstants.CONFIG_BATCH_SIZE, "10");
- props.setProperty(RpcClientConfigurationConstants.CONFIG_REQUEST_TIMEOUT,
- "2000");
+ props.setProperty(RpcClientConfigurationConstants.CONFIG_REQUEST_TIMEOUT, "2000");
channel = new MemoryChannel();
source = new ThriftSource();
}
@@ -110,7 +109,7 @@ public class TestThriftSource {
context.put("keymanager-type", KeyManagerFactory.getDefaultAlgorithm());
Configurables.configure(source, context);
source.start();
- for(int i = 0; i < 30; i++) {
+ for (int i = 0; i < 30; i++) {
client.append(EventBuilder.withBody(String.valueOf(i).getBytes()));
}
Transaction transaction = channel.getTransaction();
@@ -135,7 +134,7 @@ public class TestThriftSource {
context.put(ThriftSource.CONFIG_PORT, String.valueOf(port));
Configurables.configure(source, context);
source.start();
- for(int i = 0; i < 30; i++) {
+ for (int i = 0; i < 30; i++) {
client.append(EventBuilder.withBody(String.valueOf(i).getBytes()));
}
Transaction transaction = channel.getTransaction();
@@ -188,8 +187,8 @@ public class TestThriftSource {
int index = 0;
//30 batches of 10
- for(int i = 0; i < 30; i++) {
- for(int j = 0; j < 10; j++) {
+ for (int i = 0; i < 30; i++) {
+ for (int j = 0; j < 10; j++) {
Assert.assertEquals(i, events.get(index++).intValue());
}
}
@@ -233,8 +232,8 @@ public class TestThriftSource {
int index = 0;
//10 batches of 500
- for(int i = 0; i < 5; i++) {
- for(int j = 0; j < 500; j++) {
+ for (int i = 0; i < 5; i++) {
+ for (int j = 0; j < 500; j++) {
Assert.assertEquals(i, events.get(index++).intValue());
}
}
@@ -253,15 +252,14 @@ public class TestThriftSource {
context.put(ThriftSource.CONFIG_PORT, String.valueOf(port));
Configurables.configure(source, context);
source.start();
- ExecutorCompletionService<Void> completionService = new
- ExecutorCompletionService(submitter);
+ 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++) {
+ for (int i = 0; i < 30; i++) {
completionService.take();
}
@@ -282,19 +280,20 @@ public class TestThriftSource {
int index = 0;
//30 batches of 10
- for(int i = 0; i < 30; i++) {
- for(int j = 0; j < 10; j++) {
+ for (int i = 0; i < 30; i++) {
+ for (int j = 0; j < 10; j++) {
Assert.assertEquals(i, events.get(index++).intValue());
}
}
}
private class SubmitHelper implements Runnable {
-
private final int i;
+
public SubmitHelper(int i) {
this.i = i;
}
+
@Override
public void run() {
List<Event> events = Lists.newArrayList();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/source/http/FlumeHttpServletRequestWrapper.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/http/FlumeHttpServletRequestWrapper.java b/flume-ng-core/src/test/java/org/apache/flume/source/http/FlumeHttpServletRequestWrapper.java
index 6b94b2e..475d92f 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/http/FlumeHttpServletRequestWrapper.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/http/FlumeHttpServletRequestWrapper.java
@@ -40,7 +40,9 @@ class FlumeHttpServletRequestWrapper implements HttpServletRequest {
private BufferedReader reader;
String charset;
- public FlumeHttpServletRequestWrapper(String data, String charset) throws UnsupportedEncodingException {
+
+ public FlumeHttpServletRequestWrapper(String data, String charset)
+ throws UnsupportedEncodingException {
reader = new BufferedReader(new InputStreamReader(
new ByteArrayInputStream(data.getBytes(charset)), charset));
this.charset = charset;
[7/9] flume git commit: FLUME-2941. Integrate checkstyle for test
classes
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/EncryptionTestUtils.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/EncryptionTestUtils.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/EncryptionTestUtils.java
index 6ca3246..f290035 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/EncryptionTestUtils.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/EncryptionTestUtils.java
@@ -18,18 +18,6 @@
*/
package org.apache.flume.channel.file.encryption;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.security.Key;
-import java.security.KeyStore;
-import java.util.List;
-import java.util.Map;
-
-import javax.crypto.KeyGenerator;
-
-import org.apache.flume.channel.file.TestUtils;
-
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
@@ -37,6 +25,16 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
import com.google.common.io.Resources;
+import org.apache.flume.channel.file.TestUtils;
+
+import javax.crypto.KeyGenerator;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.security.Key;
+import java.security.KeyStore;
+import java.util.List;
+import java.util.Map;
public class EncryptionTestUtils {
@@ -50,33 +48,32 @@ public class EncryptionTestUtils {
throw Throwables.propagate(e);
}
}
- public static void createKeyStore(File keyStoreFile,
- File keyStorePasswordFile, Map<String, File> keyAliasPassword)
- throws Exception {
+
+ public static void createKeyStore(File keyStoreFile, File keyStorePasswordFile,
+ Map<String, File> keyAliasPassword) throws Exception {
KeyStore ks = KeyStore.getInstance("jceks");
ks.load(null);
List<String> keysWithSeperatePasswords = Lists.newArrayList();
- for(String alias : keyAliasPassword.keySet()) {
+ for (String alias : keyAliasPassword.keySet()) {
Key key = newKey();
char[] password = null;
File passwordFile = keyAliasPassword.get(alias);
- if(passwordFile == null) {
- password = Files.toString(keyStorePasswordFile, Charsets.UTF_8)
- .toCharArray();
+ if (passwordFile == null) {
+ password = Files.toString(keyStorePasswordFile, Charsets.UTF_8).toCharArray();
} else {
keysWithSeperatePasswords.add(alias);
password = Files.toString(passwordFile, Charsets.UTF_8).toCharArray();
}
ks.setKeyEntry(alias, key, password, null);
}
- char[] keyStorePassword = Files.
- toString(keyStorePasswordFile, Charsets.UTF_8).toCharArray();
+ char[] keyStorePassword = Files.toString(keyStorePasswordFile, Charsets.UTF_8).toCharArray();
FileOutputStream outputStream = new FileOutputStream(keyStoreFile);
ks.store(outputStream, keyStorePassword);
outputStream.close();
}
- public static Map<String, File> configureTestKeyStore(File baseDir,
- File keyStoreFile) throws IOException {
+
+ public static Map<String, File> configureTestKeyStore(File baseDir, File keyStoreFile)
+ throws IOException {
Map<String, File> result = Maps.newHashMap();
if (System.getProperty("java.vendor").contains("IBM")) {
@@ -86,50 +83,52 @@ public class EncryptionTestUtils {
Resources.copy(Resources.getResource("sun-test.keystore"),
new FileOutputStream(keyStoreFile));
}
- /*
- Commands below:
- keytool -genseckey -alias key-0 -keypass keyPassword -keyalg AES \
- -keysize 128 -validity 9000 -keystore src/test/resources/test.keystore \
- -storetype jceks -storepass keyStorePassword
- keytool -genseckey -alias key-1 -keyalg AES -keysize 128 -validity 9000 \
- -keystore src/test/resources/test.keystore -storetype jceks \
- -storepass keyStorePassword
+
+ /* Commands below:
+ * keytool -genseckey -alias key-0 -keypass keyPassword -keyalg AES \
+ * -keysize 128 -validity 9000 -keystore src/test/resources/test.keystore \
+ * -storetype jceks -storepass keyStorePassword
+ * keytool -genseckey -alias key-1 -keyalg AES -keysize 128 -validity 9000 \
+ * -keystore src/test/resources/test.keystore -storetype jceks \
+ * -storepass keyStorePassword
*/
-// key-0 has own password, key-1 used key store password
- result.put("key-0",
- TestUtils.writeStringToFile(baseDir, "key-0", "keyPassword"));
+ // key-0 has own password, key-1 used key store password
+ result.put("key-0", TestUtils.writeStringToFile(baseDir, "key-0", "keyPassword"));
result.put("key-1", null);
return result;
}
- public static Map<String,String> configureForKeyStore(File keyStoreFile,
- File keyStorePasswordFile, Map<String, File> keyAliasPassword)
- throws Exception {
+
+ public static Map<String, String> configureForKeyStore(File keyStoreFile,
+ File keyStorePasswordFile,
+ Map<String, File> keyAliasPassword)
+ throws Exception {
Map<String, String> context = Maps.newHashMap();
List<String> keys = Lists.newArrayList();
Joiner joiner = Joiner.on(".");
- for(String alias : keyAliasPassword.keySet()) {
+ for (String alias : keyAliasPassword.keySet()) {
File passwordFile = keyAliasPassword.get(alias);
- if(passwordFile == null) {
+ if (passwordFile == null) {
keys.add(alias);
} else {
String propertyName = joiner.join(EncryptionConfiguration.KEY_PROVIDER,
- EncryptionConfiguration.JCE_FILE_KEYS, alias,
- EncryptionConfiguration.JCE_FILE_KEY_PASSWORD_FILE);
+ EncryptionConfiguration.JCE_FILE_KEYS,
+ alias,
+ EncryptionConfiguration.JCE_FILE_KEY_PASSWORD_FILE);
keys.add(alias);
context.put(propertyName, passwordFile.getAbsolutePath());
}
}
context.put(joiner.join(EncryptionConfiguration.KEY_PROVIDER,
- EncryptionConfiguration.JCE_FILE_KEY_STORE_FILE),
- keyStoreFile.getAbsolutePath());
- if(keyStorePasswordFile != null) {
+ EncryptionConfiguration.JCE_FILE_KEY_STORE_FILE),
+ keyStoreFile.getAbsolutePath());
+ if (keyStorePasswordFile != null) {
context.put(joiner.join(EncryptionConfiguration.KEY_PROVIDER,
- EncryptionConfiguration.JCE_FILE_KEY_STORE_PASSWORD_FILE),
- keyStorePasswordFile.getAbsolutePath());
+ EncryptionConfiguration.JCE_FILE_KEY_STORE_PASSWORD_FILE),
+ keyStorePasswordFile.getAbsolutePath());
}
context.put(joiner.join(EncryptionConfiguration.KEY_PROVIDER,
- EncryptionConfiguration.JCE_FILE_KEYS),
- Joiner.on(" ").join(keys));
+ EncryptionConfiguration.JCE_FILE_KEYS),
+ Joiner.on(" ").join(keys));
return context;
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestAESCTRNoPaddingProvider.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestAESCTRNoPaddingProvider.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestAESCTRNoPaddingProvider.java
index a7c7cb2..d483fcc 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestAESCTRNoPaddingProvider.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestAESCTRNoPaddingProvider.java
@@ -35,13 +35,13 @@ public class TestAESCTRNoPaddingProvider {
public void setup() throws Exception {
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
key = keyGen.generateKey();
- encryptor = CipherProviderFactory.
- getEncrypter(CipherProviderType.AESCTRNOPADDING.name(), key);
- decryptor = CipherProviderFactory.
- getDecrypter(CipherProviderType.AESCTRNOPADDING.name(), key,
- encryptor.getParameters());
+ encryptor = CipherProviderFactory.getEncrypter(
+ CipherProviderType.AESCTRNOPADDING.name(), key);
+ decryptor = CipherProviderFactory.getDecrypter(
+ CipherProviderType.AESCTRNOPADDING.name(), key, encryptor.getParameters());
cipherProviderTestSuite = new CipherProviderTestSuite(encryptor, decryptor);
}
+
@Test
public void test() throws Exception {
cipherProviderTestSuite.test();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestFileChannelEncryption.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestFileChannelEncryption.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestFileChannelEncryption.java
index d4537a8..4e5ab6f 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestFileChannelEncryption.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestFileChannelEncryption.java
@@ -18,18 +18,10 @@
*/
package org.apache.flume.channel.file.encryption;
-import static org.apache.flume.channel.file.TestUtils.*;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicBoolean;
-
+import com.google.common.base.Charsets;
+import com.google.common.base.Joiner;
+import com.google.common.collect.Maps;
+import com.google.common.io.Files;
import org.apache.flume.ChannelException;
import org.apache.flume.FlumeException;
import org.apache.flume.channel.file.FileChannelConfiguration;
@@ -42,10 +34,21 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Charsets;
-import com.google.common.base.Joiner;
-import com.google.common.collect.Maps;
-import com.google.common.io.Files;
+import java.io.File;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.apache.flume.channel.file.TestUtils.compareInputAndOut;
+import static org.apache.flume.channel.file.TestUtils.consumeChannel;
+import static org.apache.flume.channel.file.TestUtils.fillChannel;
+import static org.apache.flume.channel.file.TestUtils.putEvents;
+import static org.apache.flume.channel.file.TestUtils.takeEvents;
public class TestFileChannelEncryption extends TestFileChannelBase {
protected static final Logger LOGGER =
@@ -62,36 +65,39 @@ public class TestFileChannelEncryption extends TestFileChannelBase {
keyStoreFile = new File(baseDir, "keyStoreFile");
Assert.assertTrue(keyStoreFile.createNewFile());
keyAliasPassword = Maps.newHashMap();
- keyAliasPassword.putAll(EncryptionTestUtils.
- configureTestKeyStore(baseDir, keyStoreFile));
+ keyAliasPassword.putAll(EncryptionTestUtils.configureTestKeyStore(baseDir, keyStoreFile));
}
+
@After
public void teardown() {
super.teardown();
}
+
private Map<String, String> getOverrides() throws Exception {
Map<String, String> overrides = Maps.newHashMap();
overrides.put(FileChannelConfiguration.CAPACITY, String.valueOf(100));
- overrides.put(FileChannelConfiguration.TRANSACTION_CAPACITY,
- String.valueOf(100));
+ overrides.put(FileChannelConfiguration.TRANSACTION_CAPACITY, String.valueOf(100));
return overrides;
}
+
private Map<String, String> getOverridesForEncryption() throws Exception {
Map<String, String> overrides = getOverrides();
- Map<String, String> encryptionProps = EncryptionTestUtils.
- configureForKeyStore(keyStoreFile,
- keyStorePasswordFile, keyAliasPassword);
+ Map<String, String> encryptionProps =
+ EncryptionTestUtils.configureForKeyStore(keyStoreFile,
+ keyStorePasswordFile,
+ keyAliasPassword);
encryptionProps.put(EncryptionConfiguration.KEY_PROVIDER,
- KeyProviderType.JCEKSFILE.name());
+ KeyProviderType.JCEKSFILE.name());
encryptionProps.put(EncryptionConfiguration.CIPHER_PROVIDER,
- CipherProviderType.AESCTRNOPADDING.name());
+ CipherProviderType.AESCTRNOPADDING.name());
encryptionProps.put(EncryptionConfiguration.ACTIVE_KEY, "key-1");
- for(String key : encryptionProps.keySet()) {
+ for (String key : encryptionProps.keySet()) {
overrides.put(EncryptionConfiguration.ENCRYPTION_PREFIX + "." + key,
- encryptionProps.get(key));
+ encryptionProps.get(key));
}
return overrides;
}
+
/**
* Test fails without FLUME-1565
*/
@@ -222,15 +228,16 @@ public class TestFileChannelEncryption extends TestFileChannelBase {
channel = createFileChannel(noEncryptionOverrides);
channel.start();
- if(channel.isOpen()) {
+ if (channel.isOpen()) {
try {
takeEvents(channel, 1, 1);
Assert.fail("Channel was opened and take did not throw exception");
- } catch(ChannelException ex) {
+ } catch (ChannelException ex) {
// expected
}
}
}
+
@Test
public void testUnencyrptedAndEncryptedLogs() throws Exception {
Map<String, String> noEncryptionOverrides = getOverrides();
@@ -252,41 +259,46 @@ public class TestFileChannelEncryption extends TestFileChannelBase {
Set<String> out = consumeChannel(channel);
compareInputAndOut(in, out);
}
+
@Test
public void testBadKeyProviderInvalidValue() throws Exception {
Map<String, String> overrides = getOverridesForEncryption();
overrides.put(Joiner.on(".").join(EncryptionConfiguration.ENCRYPTION_PREFIX,
- EncryptionConfiguration.KEY_PROVIDER), "invalid");
+ EncryptionConfiguration.KEY_PROVIDER),
+ "invalid");
try {
channel = createFileChannel(overrides);
Assert.fail();
- } catch(FlumeException ex) {
- Assert.assertEquals("java.lang.ClassNotFoundException: invalid",
- ex.getMessage());
+ } catch (FlumeException ex) {
+ Assert.assertEquals("java.lang.ClassNotFoundException: invalid", ex.getMessage());
}
}
+
@Test
public void testBadKeyProviderInvalidClass() throws Exception {
Map<String, String> overrides = getOverridesForEncryption();
overrides.put(Joiner.on(".").join(EncryptionConfiguration.ENCRYPTION_PREFIX,
- EncryptionConfiguration.KEY_PROVIDER), String.class.getName());
+ EncryptionConfiguration.KEY_PROVIDER),
+ String.class.getName());
try {
channel = createFileChannel(overrides);
Assert.fail();
- } catch(FlumeException ex) {
- Assert.assertEquals("Unable to instantiate Builder from java.lang.String",
- ex.getMessage());
+ } catch (FlumeException ex) {
+ Assert.assertEquals("Unable to instantiate Builder from java.lang.String", ex.getMessage());
}
}
+
@Test
public void testBadCipherProviderInvalidValue() throws Exception {
Map<String, String> overrides = getOverridesForEncryption();
overrides.put(Joiner.on(".").join(EncryptionConfiguration.ENCRYPTION_PREFIX,
- EncryptionConfiguration.CIPHER_PROVIDER), "invalid");
+ EncryptionConfiguration.CIPHER_PROVIDER),
+ "invalid");
channel = createFileChannel(overrides);
channel.start();
Assert.assertFalse(channel.isOpen());
}
+
@Test
public void testBadCipherProviderInvalidClass() throws Exception {
Map<String, String> overrides = getOverridesForEncryption();
@@ -296,6 +308,7 @@ public class TestFileChannelEncryption extends TestFileChannelBase {
channel.start();
Assert.assertFalse(channel.isOpen());
}
+
@Test
public void testMissingKeyStoreFile() throws Exception {
Map<String, String> overrides = getOverridesForEncryption();
@@ -306,11 +319,12 @@ public class TestFileChannelEncryption extends TestFileChannelBase {
try {
channel = createFileChannel(overrides);
Assert.fail();
- } catch(RuntimeException ex) {
+ } catch (RuntimeException ex) {
Assert.assertTrue("Exception message is incorrect: " + ex.getMessage(),
ex.getMessage().startsWith("java.io.FileNotFoundException: /path/does/not/exist "));
}
}
+
@Test
public void testMissingKeyStorePasswordFile() throws Exception {
Map<String, String> overrides = getOverridesForEncryption();
@@ -321,11 +335,12 @@ public class TestFileChannelEncryption extends TestFileChannelBase {
try {
channel = createFileChannel(overrides);
Assert.fail();
- } catch(RuntimeException ex) {
+ } catch (RuntimeException ex) {
Assert.assertTrue("Exception message is incorrect: " + ex.getMessage(),
ex.getMessage().startsWith("java.io.FileNotFoundException: /path/does/not/exist "));
}
}
+
@Test
public void testBadKeyStorePassword() throws Exception {
Files.write("invalid", keyStorePasswordFile, Charsets.UTF_8);
@@ -334,11 +349,12 @@ public class TestFileChannelEncryption extends TestFileChannelBase {
channel = TestUtils.createFileChannel(checkpointDir.getAbsolutePath(),
dataDir, overrides);
Assert.fail();
- } catch(RuntimeException ex) {
+ } catch (RuntimeException ex) {
Assert.assertEquals("java.io.IOException: Keystore was tampered with, or " +
"password was incorrect", ex.getMessage());
}
}
+
@Test
public void testBadKeyAlias() throws Exception {
Map<String, String> overrides = getOverridesForEncryption();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestJCEFileKeyProvider.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestJCEFileKeyProvider.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestJCEFileKeyProvider.java
index f33cada..8214a05 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestJCEFileKeyProvider.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/TestJCEFileKeyProvider.java
@@ -18,12 +18,10 @@
*/
package org.apache.flume.channel.file.encryption;
-import java.io.File;
-import java.security.Key;
-import java.util.Map;
-
+import com.google.common.base.Charsets;
+import com.google.common.collect.Maps;
+import com.google.common.io.Files;
import junit.framework.Assert;
-
import org.apache.commons.io.FileUtils;
import org.apache.flume.Context;
import org.apache.flume.channel.file.TestUtils;
@@ -31,9 +29,9 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import com.google.common.base.Charsets;
-import com.google.common.collect.Maps;
-import com.google.common.io.Files;
+import java.io.File;
+import java.security.Key;
+import java.util.Map;
public class TestJCEFileKeyProvider {
private CipherProvider.Encryptor encryptor;
@@ -53,62 +51,69 @@ public class TestJCEFileKeyProvider {
Assert.assertTrue(keyStoreFile.createNewFile());
}
+
@After
public void cleanup() {
FileUtils.deleteQuietly(baseDir);
}
+
private void initializeForKey(Key key) {
- encryptor =
- new AESCTRNoPaddingProvider.EncryptorBuilder().setKey(key).build();
- decryptor =
- new AESCTRNoPaddingProvider.DecryptorBuilder()
- .setKey(key).setParameters(encryptor.getParameters()).build();
+ encryptor = new AESCTRNoPaddingProvider.EncryptorBuilder()
+ .setKey(key)
+ .build();
+ decryptor = new AESCTRNoPaddingProvider.DecryptorBuilder()
+ .setKey(key)
+ .setParameters(encryptor.getParameters())
+ .build();
}
+
@Test
public void testWithNewKeyStore() throws Exception {
createNewKeyStore();
EncryptionTestUtils.createKeyStore(keyStoreFile, keyStorePasswordFile,
keyAliasPassword);
- Context context = new Context(EncryptionTestUtils.
- configureForKeyStore(keyStoreFile,
- keyStorePasswordFile, keyAliasPassword));
+ Context context = new Context(
+ EncryptionTestUtils.configureForKeyStore(keyStoreFile,
+ keyStorePasswordFile,
+ keyAliasPassword));
Context keyProviderContext = new Context(
context.getSubProperties(EncryptionConfiguration.KEY_PROVIDER + "."));
- KeyProvider keyProvider = KeyProviderFactory.
- getInstance(KeyProviderType.JCEKSFILE.name(), keyProviderContext);
+ KeyProvider keyProvider =
+ KeyProviderFactory.getInstance(KeyProviderType.JCEKSFILE.name(), keyProviderContext);
testKeyProvider(keyProvider);
}
+
@Test
public void testWithExistingKeyStore() throws Exception {
- keyAliasPassword.putAll(EncryptionTestUtils.
- configureTestKeyStore(baseDir, keyStoreFile));
- Context context = new Context(EncryptionTestUtils.
- configureForKeyStore(keyStoreFile,
- keyStorePasswordFile, keyAliasPassword));
+ keyAliasPassword.putAll(EncryptionTestUtils.configureTestKeyStore(baseDir, keyStoreFile));
+ Context context = new Context(
+ EncryptionTestUtils.configureForKeyStore(keyStoreFile,
+ keyStorePasswordFile,
+ keyAliasPassword));
Context keyProviderContext = new Context(
context.getSubProperties(EncryptionConfiguration.KEY_PROVIDER + "."));
- KeyProvider keyProvider = KeyProviderFactory.
- getInstance(KeyProviderType.JCEKSFILE.name(), keyProviderContext);
+ KeyProvider keyProvider =
+ KeyProviderFactory.getInstance(KeyProviderType.JCEKSFILE.name(), keyProviderContext);
testKeyProvider(keyProvider);
}
+
private void createNewKeyStore() throws Exception {
- for(int i = 0; i < 10; i++) {
+ for (int i = 0; i < 10; i++) {
// create some with passwords, some without
- if(i % 2 == 0) {
+ if (i % 2 == 0) {
String alias = "test-" + i;
String password = String.valueOf(i);
- keyAliasPassword.put(alias,
- TestUtils.writeStringToFile(baseDir, alias, password));
+ keyAliasPassword.put(alias, TestUtils.writeStringToFile(baseDir, alias, password));
}
}
}
+
private void testKeyProvider(KeyProvider keyProvider) {
- for(String alias : keyAliasPassword.keySet()) {
+ for (String alias : keyAliasPassword.keySet()) {
Key key = keyProvider.getKey(alias);
initializeForKey(key);
String expected = "some text here " + alias;
- byte[] cipherText = encryptor.
- encrypt(expected.getBytes(Charsets.UTF_8));
+ byte[] cipherText = encryptor.encrypt(expected.getBytes(Charsets.UTF_8));
byte[] clearText = decryptor.decrypt(cipherText);
Assert.assertEquals(expected, new String(clearText, Charsets.UTF_8));
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/BaseJdbcChannelProviderTest.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/BaseJdbcChannelProviderTest.java b/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/BaseJdbcChannelProviderTest.java
index 85ad7fe..7031eb7 100644
--- a/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/BaseJdbcChannelProviderTest.java
+++ b/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/BaseJdbcChannelProviderTest.java
@@ -17,6 +17,17 @@
*/
package org.apache.flume.channel.jdbc;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.flume.Transaction;
+import org.apache.flume.channel.jdbc.impl.JdbcChannelProviderImpl;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -32,17 +43,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import org.apache.flume.Context;
-import org.apache.flume.Event;
-import org.apache.flume.Transaction;
-import org.apache.flume.channel.jdbc.impl.JdbcChannelProviderImpl;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public abstract class BaseJdbcChannelProviderTest {
private static final Logger LOGGER =
LoggerFactory.getLogger(BaseJdbcChannelProviderTest.class);
@@ -103,7 +103,7 @@ public abstract class BaseJdbcChannelProviderTest {
Set<MockEvent> events = new HashSet<MockEvent>();
for (int i = 1; i < 12; i++) {
- events.add(MockEventUtils.generateMockEvent(i, i, i, 61%i, 1));
+ events.add(MockEventUtils.generateMockEvent(i, i, i, 61 % i, 1));
}
Iterator<MockEvent> meIt = events.iterator();
@@ -170,7 +170,7 @@ public abstract class BaseJdbcChannelProviderTest {
new HashMap<String, List<MockEvent>>();
for (int i = 1; i < 121; i++) {
- MockEvent me = MockEventUtils.generateMockEvent(i, i, i, 61%i, 10);
+ MockEvent me = MockEventUtils.generateMockEvent(i, i, i, 61 % i, 10);
List<MockEvent> meList = eventMap.get(me.getChannel());
if (meList == null) {
meList = new ArrayList<MockEvent>();
@@ -227,7 +227,7 @@ public abstract class BaseJdbcChannelProviderTest {
Set<MockEvent> events = new HashSet<MockEvent>();
for (int i = 1; i < 81; i++) {
- events.add(MockEventUtils.generateMockEvent(i, i, i, 61%i, 5));
+ events.add(MockEventUtils.generateMockEvent(i, i, i, 61 % i, 5));
}
Iterator<MockEvent> meIt = events.iterator();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEvent.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEvent.java b/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEvent.java
index 1e412c5..6804a9f 100644
--- a/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEvent.java
+++ b/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEvent.java
@@ -27,8 +27,7 @@ public class MockEvent implements Event {
private final Map<String, String> headers;
private final String channel;
- public MockEvent(byte[] payload, Map<String, String> headers, String channel)
- {
+ public MockEvent(byte[] payload, Map<String, String> headers, String channel) {
this.payload = payload;
this.headers = headers;
this.channel = channel;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEventUtils.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEventUtils.java b/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEventUtils.java
index 10d8b51..e5ee324 100644
--- a/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEventUtils.java
+++ b/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/MockEventUtils.java
@@ -17,13 +17,13 @@
*/
package org.apache.flume.channel.jdbc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public final class MockEventUtils {
public static final Logger LOGGER =
@@ -70,20 +70,20 @@ public final class MockEventUtils {
* @param numChannels
* @return
*/
- public static MockEvent generateMockEvent(int payloadMargin,
- int headerNameMargin, int headerValueMargin, int numHeaders,
- int numChannels) {
+ public static MockEvent generateMockEvent(int payloadMargin, int headerNameMargin,
+ int headerValueMargin, int numHeaders,
+ int numChannels) {
int chIndex = 0;
if (numChannels > 1) {
- chIndex = Math.abs(RANDOM.nextInt())%numChannels;
+ chIndex = Math.abs(RANDOM.nextInt()) % numChannels;
}
- String channel = "test-"+chIndex;
+ String channel = "test-" + chIndex;
StringBuilder sb = new StringBuilder("New Event[payload size:");
int plTh = ConfigurationConstants.PAYLOAD_LENGTH_THRESHOLD;
- int plSize = Math.abs(RANDOM.nextInt())%plTh + payloadMargin;
+ int plSize = Math.abs(RANDOM.nextInt()) % plTh + payloadMargin;
sb.append(plSize).append(", numHeaders:").append(numHeaders);
sb.append(", channel:").append(channel);
@@ -93,8 +93,8 @@ public final class MockEventUtils {
Map<String, String> headers = new HashMap<String, String>();
for (int i = 0; i < numHeaders; i++) {
- int nmSize = Math.abs(RANDOM.nextInt())%nmTh + headerNameMargin;
- int vlSize = Math.abs(RANDOM.nextInt())%vlTh + headerValueMargin;
+ int nmSize = Math.abs(RANDOM.nextInt()) % nmTh + headerNameMargin;
+ int vlSize = Math.abs(RANDOM.nextInt()) % vlTh + headerValueMargin;
String name = generateHeaderString(nmSize);
String value = generateHeaderString(vlSize);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestDerbySchemaHandlerQueries.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestDerbySchemaHandlerQueries.java b/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestDerbySchemaHandlerQueries.java
index 362bcfa..cad972c 100644
--- a/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestDerbySchemaHandlerQueries.java
+++ b/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestDerbySchemaHandlerQueries.java
@@ -107,7 +107,6 @@ public class TestDerbySchemaHandlerQueries {
= "INSERT INTO FLUME.FL_HEADER (FLH_EVENT, FLH_NAME, FLH_VALUE, "
+ "FLH_NMSPILL, FLH_VLSPILL) VALUES ( ?, ?, ?, ?, ?)";
-
public static final String EXPECTED_STMT_INSERT_HEADER_NAME_SPILL
= "INSERT INTO FLUME.FL_NMSPILL (FLN_HEADER, FLN_SPILL) VALUES ( ?, ?)";
@@ -119,7 +118,6 @@ public class TestDerbySchemaHandlerQueries {
+ "FLE_ID = (SELECT MIN(FLE_ID) FROM FLUME.FL_EVENT WHERE "
+ "FLE_CHANNEL = ?)";
-
public static final String EXPECTED_STMT_FETCH_PAYLOAD_SPILL
= "SELECT FLP_SPILL FROM FLUME.FL_PLSPILL WHERE FLP_EVENT = ?";
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-kafka-channel/src/test/java/org/apache/flume/channel/kafka/TestKafkaChannel.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-kafka-channel/src/test/java/org/apache/flume/channel/kafka/TestKafkaChannel.java b/flume-ng-channels/flume-kafka-channel/src/test/java/org/apache/flume/channel/kafka/TestKafkaChannel.java
index d01346a..b63ac9b 100644
--- a/flume-ng-channels/flume-kafka-channel/src/test/java/org/apache/flume/channel/kafka/TestKafkaChannel.java
+++ b/flume-ng-channels/flume-kafka-channel/src/test/java/org/apache/flume/channel/kafka/TestKafkaChannel.java
@@ -130,19 +130,19 @@ public class TestKafkaChannel {
Properties consumerProps = channel.getConsumerProps();
Properties producerProps = channel.getProducerProps();
- Assert.assertEquals(producerProps.getProperty(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG),testUtil.getKafkaServerUrl());
- Assert.assertEquals(consumerProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG), "flume-something");
- Assert.assertEquals(consumerProps.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG), "earliest");
-
+ Assert.assertEquals(producerProps.getProperty(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG),
+ testUtil.getKafkaServerUrl());
+ Assert.assertEquals(consumerProps.getProperty(ConsumerConfig.GROUP_ID_CONFIG),
+ "flume-something");
+ Assert.assertEquals(consumerProps.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG),
+ "earliest");
}
-
@Test
public void testSuccess() throws Exception {
doTestSuccessRollback(false, false);
}
-
@Test
public void testSuccessInterleave() throws Exception {
doTestSuccessRollback(false, true);
@@ -212,8 +212,10 @@ public class TestKafkaChannel {
KafkaChannel channel = startChannel(false);
- KafkaProducer<String, byte[]> producer = new KafkaProducer<String, byte[]>(channel.getProducerProps());
- ProducerRecord<String, byte[]> data = new ProducerRecord<String, byte[]>(topic, "header-" + message, message.getBytes());
+ KafkaProducer<String, byte[]> producer =
+ new KafkaProducer<String, byte[]>(channel.getProducerProps());
+ ProducerRecord<String, byte[]> data =
+ new ProducerRecord<String, byte[]>(topic, "header-" + message, message.getBytes());
producer.send(data).get();
producer.flush();
producer.close();
@@ -234,7 +236,7 @@ public class TestKafkaChannel {
}
private Event takeEventWithoutCommittingTxn(KafkaChannel channel) {
- for (int i=0; i < 5; i++) {
+ for (int i = 0; i < 5; i++) {
Transaction txn = channel.getTransaction();
txn.begin();
@@ -255,17 +257,19 @@ public class TestKafkaChannel {
KafkaProducer<String, byte[]> producer = new KafkaProducer<String, byte[]>(props);
for (int i = 0; i < 50; i++) {
- ProducerRecord<String, byte[]> data = new ProducerRecord<String, byte[]>(topic, String.valueOf(i) + "-header", String.valueOf(i).getBytes());
+ ProducerRecord<String, byte[]> data =
+ new ProducerRecord<String, byte[]>(topic, String.valueOf(i) + "-header",
+ String.valueOf(i).getBytes());
producer.send(data).get();
}
ExecutorCompletionService<Void> submitterSvc = new
- ExecutorCompletionService<Void>(Executors.newCachedThreadPool());
- List<Event> events = pullEvents(channel, submitterSvc,
- 50, false, false);
+ ExecutorCompletionService<Void>(Executors.newCachedThreadPool());
+ List<Event> events = pullEvents(channel, submitterSvc, 50, false, false);
wait(submitterSvc, 5);
Map<Integer, String> finals = new HashMap<Integer, String>();
for (int i = 0; i < 50; i++) {
- finals.put(Integer.parseInt(new String(events.get(i).getBody())), events.get(i).getHeaders().get(KEY_HEADER));
+ finals.put(Integer.parseInt(new String(events.get(i).getBody())),
+ events.get(i).getHeaders().get(KEY_HEADER));
}
for (int i = 0; i < 50; i++) {
Assert.assertTrue(finals.keySet().contains(i));
@@ -284,7 +288,8 @@ public class TestKafkaChannel {
KafkaProducer<String, byte[]> producer = new KafkaProducer<String, byte[]>(props);
for (int i = 0; i < 50; i++) {
- ProducerRecord<String, byte[]> data = new ProducerRecord<String, byte[]>(topic, null, String.valueOf(i).getBytes());
+ ProducerRecord<String, byte[]> data =
+ new ProducerRecord<String, byte[]>(topic, null, String.valueOf(i).getBytes());
producer.send(data).get();
}
ExecutorCompletionService<Void> submitterSvc = new
@@ -323,14 +328,14 @@ public class TestKafkaChannel {
channel.put(EventBuilder.withBody(msgs.get(i).getBytes(), headers));
}
tx.commit();
- ExecutorCompletionService<Void> submitterSvc = new
- ExecutorCompletionService<Void>(Executors.newCachedThreadPool());
- List<Event> events = pullEvents(channel, submitterSvc,
- 50, false, false);
+ ExecutorCompletionService<Void> submitterSvc =
+ new ExecutorCompletionService<Void>(Executors.newCachedThreadPool());
+ List<Event> events = pullEvents(channel, submitterSvc, 50, false, false);
wait(submitterSvc, 5);
Map<Integer, String> finals = new HashMap<Integer, String>();
for (int i = 0; i < 50; i++) {
- finals.put(Integer.parseInt(new String(events.get(i).getBody())), events.get(i).getHeaders().get(KEY_HEADER));
+ finals.put(Integer.parseInt(new String(events.get(i).getBody())),
+ events.get(i).getHeaders().get(KEY_HEADER));
}
for (int i = 0; i < 50; i++) {
Assert.assertTrue(finals.keySet().contains(i));
@@ -403,13 +408,13 @@ public class TestKafkaChannel {
}
private void writeAndVerify(final boolean testRollbacks,
- final KafkaChannel channel, final boolean interleave) throws Exception {
+ final KafkaChannel channel, final boolean interleave)
+ throws Exception {
final List<List<Event>> events = createBaseList();
ExecutorCompletionService<Void> submitterSvc =
- new ExecutorCompletionService<Void>(Executors
- .newCachedThreadPool());
+ new ExecutorCompletionService<Void>(Executors.newCachedThreadPool());
putEvents(channel, events, submitterSvc);
@@ -418,11 +423,9 @@ public class TestKafkaChannel {
}
ExecutorCompletionService<Void> submitterSvc2 =
- new ExecutorCompletionService<Void>(Executors
- .newCachedThreadPool());
+ new ExecutorCompletionService<Void>(Executors.newCachedThreadPool());
- final List<Event> eventsPulled =
- pullEvents(channel, submitterSvc2, 50, testRollbacks, true);
+ final List<Event> eventsPulled = pullEvents(channel, submitterSvc2, 50, testRollbacks, true);
if (!interleave) {
wait(submitterSvc, 5);
@@ -586,18 +589,18 @@ public class TestKafkaChannel {
int numPartitions = 5;
int sessionTimeoutMs = 10000;
int connectionTimeoutMs = 10000;
- ZkUtils zkUtils = ZkUtils.apply(testUtil.getZkUrl(), sessionTimeoutMs, connectionTimeoutMs, false);
-
+ ZkUtils zkUtils =
+ ZkUtils.apply(testUtil.getZkUrl(), sessionTimeoutMs, connectionTimeoutMs, false);
int replicationFactor = 1;
Properties topicConfig = new Properties();
- AdminUtils.createTopic(zkUtils, topicName, numPartitions,
- replicationFactor, topicConfig);
+ AdminUtils.createTopic(zkUtils, topicName, numPartitions, replicationFactor, topicConfig);
}
public static void deleteTopic(String topicName) {
int sessionTimeoutMs = 10000;
int connectionTimeoutMs = 10000;
- ZkUtils zkUtils = ZkUtils.apply(testUtil.getZkUrl(), sessionTimeoutMs, connectionTimeoutMs, false);
+ ZkUtils zkUtils =
+ ZkUtils.apply(testUtil.getZkUrl(), sessionTimeoutMs, connectionTimeoutMs, false);
AdminUtils.deleteTopic(zkUtils, topicName);
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-spillable-memory-channel/src/test/java/org/apache/flume/channel/TestSpillableMemoryChannel.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-spillable-memory-channel/src/test/java/org/apache/flume/channel/TestSpillableMemoryChannel.java b/flume-ng-channels/flume-spillable-memory-channel/src/test/java/org/apache/flume/channel/TestSpillableMemoryChannel.java
index 1e4e819..848636b 100644
--- a/flume-ng-channels/flume-spillable-memory-channel/src/test/java/org/apache/flume/channel/TestSpillableMemoryChannel.java
+++ b/flume-ng-channels/flume-spillable-memory-channel/src/test/java/org/apache/flume/channel/TestSpillableMemoryChannel.java
@@ -24,10 +24,13 @@ import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
-
import java.util.UUID;
-import org.apache.flume.*;
+import org.apache.flume.ChannelException;
+import org.apache.flume.ChannelFullException;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.flume.Transaction;
import org.apache.flume.conf.Configurables;
import org.apache.flume.event.EventBuilder;
import org.apache.flume.channel.file.FileChannelConfiguration;
@@ -39,7 +42,6 @@ import org.junit.Test;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
-
public class TestSpillableMemoryChannel {
private SpillableMemoryChannel channel;
@@ -51,14 +53,14 @@ public class TestSpillableMemoryChannel {
Context context = new Context();
File checkPointDir = fileChannelDir.newFolder("checkpoint");
File dataDir = fileChannelDir.newFolder("data");
- context.put(FileChannelConfiguration.CHECKPOINT_DIR
- , checkPointDir.getAbsolutePath());
+ context.put(FileChannelConfiguration.CHECKPOINT_DIR, checkPointDir.getAbsolutePath());
context.put(FileChannelConfiguration.DATA_DIRS, dataDir.getAbsolutePath());
// Set checkpoint for 5 seconds otherwise test will run out of memory
context.put(FileChannelConfiguration.CHECKPOINT_INTERVAL, "5000");
- if (overrides != null)
+ if (overrides != null) {
context.putAll(overrides);
+ }
Configurables.configure(channel, context);
}
@@ -81,9 +83,9 @@ public class TestSpillableMemoryChannel {
startChannel(params);
}
-
static class NullFound extends RuntimeException {
public int expectedValue;
+
public NullFound(int expected) {
super("Expected " + expected + ", but null found");
expectedValue = expected;
@@ -92,9 +94,10 @@ public class TestSpillableMemoryChannel {
static class TooManyNulls extends RuntimeException {
private int nullsFound;
+
public TooManyNulls(int count) {
super("Total nulls found in thread ("
- + Thread.currentThread().getName() + ") : " + count);
+ + Thread.currentThread().getName() + ") : " + count);
nullsFound = count;
}
}
@@ -102,7 +105,7 @@ public class TestSpillableMemoryChannel {
@Before
public void setUp() {
channel = new SpillableMemoryChannel();
- channel.setName("spillChannel-" + UUID.randomUUID() );
+ channel.setName("spillChannel-" + UUID.randomUUID());
}
@After
@@ -117,7 +120,7 @@ public class TestSpillableMemoryChannel {
}
private static void takeNull(AbstractChannel channel) {
- channel.take();
+ channel.take();
}
private static void takeN(int first, int count, AbstractChannel channel) {
@@ -127,7 +130,7 @@ public class TestSpillableMemoryChannel {
if (e == null) {
throw new NullFound(i);
}
- Event expected = EventBuilder.withBody( String.valueOf(i).getBytes() );
+ Event expected = EventBuilder.withBody(String.valueOf(i).getBytes());
Assert.assertArrayEquals(e.getBody(), expected.getBody());
}
}
@@ -140,16 +143,14 @@ public class TestSpillableMemoryChannel {
if (e == null) {
try {
Thread.sleep(0);
- } catch (InterruptedException ex)
- { /* ignore */ }
+ } catch (InterruptedException ex) { /* ignore */ }
return i;
}
}
return i;
}
- private static void transactionalPutN(int first, int count,
- AbstractChannel channel) {
+ private static void transactionalPutN(int first, int count, AbstractChannel channel) {
Transaction tx = channel.getTransaction();
tx.begin();
try {
@@ -163,8 +164,7 @@ public class TestSpillableMemoryChannel {
}
}
- private static void transactionalTakeN(int first, int count,
- AbstractChannel channel) {
+ private static void transactionalTakeN(int first, int count, AbstractChannel channel) {
Transaction tx = channel.getTransaction();
tx.begin();
try {
@@ -184,14 +184,13 @@ public class TestSpillableMemoryChannel {
}
}
- private static int transactionalTakeN_NoCheck(int count
- , AbstractChannel channel) {
+ private static int transactionalTakeN_NoCheck(int count, AbstractChannel channel) {
Transaction tx = channel.getTransaction();
tx.begin();
try {
int eventCount = takeN_NoCheck(count, channel);
tx.commit();
- return eventCount;
+ return eventCount;
} catch (RuntimeException e) {
tx.rollback();
throw e;
@@ -204,8 +203,9 @@ public class TestSpillableMemoryChannel {
Transaction tx = channel.getTransaction();
tx.begin();
try {
- for (int i = 0; i < count; ++i)
+ for (int i = 0; i < count; ++i) {
takeNull(channel);
+ }
tx.commit();
} catch (AssertionError e) {
tx.rollback();
@@ -218,68 +218,63 @@ public class TestSpillableMemoryChannel {
}
}
- private Thread makePutThread(String threadName
- , final int first, final int count, final int batchSize
- , final AbstractChannel channel) {
- return
- new Thread(threadName) {
- public void run() {
- int maxdepth = 0;
- StopWatch watch = new StopWatch();
- for (int i = first; i<first+count; i=i+batchSize) {
- transactionalPutN(i, batchSize, channel);
+ private Thread makePutThread(String threadName, final int first, final int count,
+ final int batchSize, final AbstractChannel channel) {
+ return new Thread(threadName) {
+ public void run() {
+ int maxdepth = 0;
+ StopWatch watch = new StopWatch();
+ for (int i = first; i < first + count; i = i + batchSize) {
+ transactionalPutN(i, batchSize, channel);
+ }
+ watch.elapsed();
+ }
+ };
+ }
+
+ private static Thread makeTakeThread(String threadName, final int first, final int count,
+ final int batchSize, final AbstractChannel channel) {
+ return new Thread(threadName) {
+ public void run() {
+ StopWatch watch = new StopWatch();
+ for (int i = first; i < first + count; ) {
+ try {
+ transactionalTakeN(i, batchSize, channel);
+ i = i + batchSize;
+ } catch (NullFound e) {
+ i = e.expectedValue;
}
- watch.elapsed();
}
- };
- }
-
- private static Thread makeTakeThread(String threadName, final int first
- , final int count, final int batchSize, final AbstractChannel channel) {
- return
- new Thread(threadName) {
- public void run() {
- StopWatch watch = new StopWatch();
- for (int i = first; i < first+count; ) {
+ watch.elapsed();
+ }
+ };
+ }
+
+ private static Thread makeTakeThread_noCheck(String threadName, final int totalEvents,
+ final int batchSize, final AbstractChannel channel) {
+ return new Thread(threadName) {
+ public void run() {
+ int batchSz = batchSize;
+ StopWatch watch = new StopWatch();
+ int i = 0, attempts = 0;
+ while (i < totalEvents) {
+ int remaining = totalEvents - i;
+ batchSz = (remaining > batchSz) ? batchSz : remaining;
+ int takenCount = transactionalTakeN_NoCheck(batchSz, channel);
+ if (takenCount < batchSz) {
try {
- transactionalTakeN(i, batchSize, channel);
- i = i + batchSize;
- } catch (NullFound e) {
- i = e.expectedValue;
- }
+ Thread.sleep(20);
+ } catch (InterruptedException ex) { /* ignore */ }
}
- watch.elapsed();
- }
- };
- }
-
- private static Thread makeTakeThread_noCheck(String threadName
- , final int totalEvents, final int batchSize, final AbstractChannel channel) {
- return
- new Thread(threadName) {
- public void run() {
- int batchSz = batchSize;
- StopWatch watch = new StopWatch();
- int i = 0, attempts = 0 ;
- while(i < totalEvents) {
- int remaining = totalEvents - i;
- batchSz = (remaining > batchSz) ? batchSz : remaining;
- int takenCount = transactionalTakeN_NoCheck(batchSz, channel);
- if(takenCount < batchSz) {
- try {
- Thread.sleep(20);
- } catch (InterruptedException ex)
- { /* ignore */ }
- }
- i += takenCount;
- ++attempts;
- if(attempts > totalEvents * 3 ) {
- throw new TooManyNulls(attempts);
- }
+ i += takenCount;
+ ++attempts;
+ if (attempts > totalEvents * 3) {
+ throw new TooManyNulls(attempts);
}
- watch.elapsed(" items = " + i + ", attempts = " + attempts);
}
- };
+ watch.elapsed(" items = " + i + ", attempts = " + attempts);
+ }
+ };
}
@Test
@@ -292,37 +287,36 @@ public class TestSpillableMemoryChannel {
Transaction tx = channel.getTransaction();
tx.begin();
- putN(0,2,channel);
+ putN(0, 2, channel);
tx.commit();
tx.close();
tx = channel.getTransaction();
tx.begin();
- takeN(0,2,channel);
+ takeN(0, 2, channel);
tx.commit();
tx.close();
}
-
@Test
- public void testCapacityDisableOverflow() {
+ 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" );
+ params.put("overflowTimeout", "0");
startChannel(params);
- transactionalPutN(0,2,channel);
+ transactionalPutN(0, 2, channel);
boolean threw = false;
try {
- transactionalPutN(2,1,channel);
+ transactionalPutN(2, 1, channel);
} catch (ChannelException e) {
threw = true;
}
Assert.assertTrue("Expecting ChannelFullException to be thrown", threw);
- transactionalTakeN(0,2, channel);
+ transactionalTakeN(0, 2, channel);
Transaction tx = channel.getTransaction();
tx.begin();
@@ -332,7 +326,7 @@ public class TestSpillableMemoryChannel {
}
@Test
- public void testCapacityWithOverflow() {
+ public void testCapacityWithOverflow() {
Map<String, String> params = new HashMap<String, String>();
params.put("memoryCapacity", "2");
params.put("overflowCapacity", "4");
@@ -346,19 +340,19 @@ public class TestSpillableMemoryChannel {
boolean threw = false;
try {
- transactionalPutN(7,2,channel); // cannot fit in channel
+ transactionalPutN(7, 2, channel); // cannot fit in channel
} catch (ChannelFullException e) {
threw = true;
}
Assert.assertTrue("Expecting ChannelFullException to be thrown", threw);
- transactionalTakeN(1,2, channel);
- transactionalTakeN(3,2, channel);
- transactionalTakeN(5,2, channel);
+ transactionalTakeN(1, 2, channel);
+ transactionalTakeN(3, 2, channel);
+ transactionalTakeN(5, 2, channel);
}
@Test
- public void testRestart() {
+ public void testRestart() {
Map<String, String> params = new HashMap<String, String>();
params.put("memoryCapacity", "2");
params.put("overflowCapacity", "10");
@@ -372,8 +366,7 @@ public class TestSpillableMemoryChannel {
restartChannel(params);
// from overflow, as in memory stuff should be lost
- transactionalTakeN(3,2, channel);
-
+ transactionalTakeN(3, 2, channel);
}
@Test
@@ -382,35 +375,34 @@ public class TestSpillableMemoryChannel {
params.put("memoryCapacity", "10000000");
params.put("overflowCapacity", "20000000");
params.put(FileChannelConfiguration.TRANSACTION_CAPACITY, "10");
- params.put("overflowTimeout", "1" );
+ params.put("overflowTimeout", "1");
startChannel(params);
- transactionalPutN( 1,5,channel);
- transactionalPutN( 6,5,channel);
- transactionalPutN(11,5,channel); // these should go to overflow
+ transactionalPutN(1, 5, channel);
+ transactionalPutN(6, 5, channel);
+ transactionalPutN(11, 5, channel); // these should go to overflow
- transactionalTakeN(1,10, channel);
- transactionalTakeN(11,5, channel);
+ transactionalTakeN(1, 10, channel);
+ transactionalTakeN(11, 5, channel);
}
@Test
public void testOverflow() {
-
Map<String, String> params = new HashMap<String, String>();
params.put("memoryCapacity", "10");
params.put("overflowCapacity", "20");
params.put(FileChannelConfiguration.TRANSACTION_CAPACITY, "10");
- params.put("overflowTimeout", "1" );
+ params.put("overflowTimeout", "1");
startChannel(params);
- transactionalPutN( 1,5,channel);
- transactionalPutN( 6,5,channel);
- transactionalPutN(11,5,channel); // these should go to overflow
+ transactionalPutN(1, 5, channel);
+ transactionalPutN(6, 5, channel);
+ transactionalPutN(11, 5, channel); // these should go to overflow
- transactionalTakeN(1,10, channel);
- transactionalTakeN(11,5, channel);
+ transactionalTakeN(1, 10, channel);
+ transactionalTakeN(11, 5, channel);
}
@Test
@@ -419,29 +411,29 @@ public class TestSpillableMemoryChannel {
params.put("memoryCapacity", "10");
params.put("overflowCapacity", "10");
params.put(FileChannelConfiguration.TRANSACTION_CAPACITY, "5");
- params.put("overflowTimeout", "1" );
+ params.put("overflowTimeout", "1");
startChannel(params);
- transactionalPutN( 1,5,channel);
- transactionalPutN( 6,5,channel);
- transactionalPutN(11,5,channel); // into overflow
- transactionalPutN(16,5,channel); // into overflow
+ transactionalPutN(1, 5, channel);
+ transactionalPutN(6, 5, channel);
+ transactionalPutN(11, 5, channel); // into overflow
+ transactionalPutN(16, 5, channel); // into overflow
transactionalTakeN(1, 1, channel);
- transactionalTakeN(2, 5,channel);
- transactionalTakeN(7, 4,channel);
+ transactionalTakeN(2, 5, channel);
+ transactionalTakeN(7, 4, channel);
- transactionalPutN( 20,2,channel);
- transactionalPutN( 22,3,channel);
+ transactionalPutN(20, 2, channel);
+ transactionalPutN(22, 3, channel);
- transactionalTakeN( 11,3,channel); // from overflow
- transactionalTakeN( 14,5,channel); // from overflow
- transactionalTakeN( 19,2,channel); // from overflow
+ transactionalTakeN(11, 3, channel); // from overflow
+ transactionalTakeN(14, 5, channel); // from overflow
+ transactionalTakeN(19, 2, channel); // from overflow
}
@Test
- public void testByteCapacity() {
+ public void testByteCapacity() {
Map<String, String> params = new HashMap<String, String>();
params.put("memoryCapacity", "1000");
// configure to hold 8 events of 10 bytes each (plus 20% event header space)
@@ -449,12 +441,12 @@ public class TestSpillableMemoryChannel {
params.put("avgEventSize", "10");
params.put("overflowCapacity", "20");
params.put(FileChannelConfiguration.TRANSACTION_CAPACITY, "10");
- params.put("overflowTimeout", "1" );
+ params.put("overflowTimeout", "1");
startChannel(params);
transactionalPutN(1, 8, channel); // this wil max the byteCapacity
transactionalPutN(9, 10, channel);
- transactionalPutN(19,10, channel); // this will fill up the overflow
+ transactionalPutN(19, 10, channel); // this will fill up the overflow
boolean threw = false;
try {
@@ -463,7 +455,6 @@ public class TestSpillableMemoryChannel {
threw = true;
}
Assert.assertTrue("byteCapacity did not throw as expected", threw);
-
}
@Test
@@ -473,7 +464,7 @@ public class TestSpillableMemoryChannel {
params.put("memoryCapacity", "5");
params.put("overflowCapacity", "15");
params.put(FileChannelConfiguration.TRANSACTION_CAPACITY, "10");
- params.put("overflowTimeout", "1" );
+ params.put("overflowTimeout", "1");
startChannel(params);
transactionalPutN(1, 5, channel);
@@ -493,13 +484,13 @@ public class TestSpillableMemoryChannel {
transactionalTakeN(6, 5, channel); // from overflow
transactionalTakeN(11, 5, channel); // from overflow
- transactionalTakeN(16, 2,channel); // from overflow
+ transactionalTakeN(16, 2, channel); // from overflow
transactionalPutN(21, 5, channel);
tx = channel.getTransaction();
tx.begin();
- takeN(18,3, channel); // from overflow
+ takeN(18, 3, channel); // from overflow
takeNull(channel); // expect null since next event is in primary
tx.commit();
tx.close();
@@ -516,9 +507,8 @@ public class TestSpillableMemoryChannel {
params.put("overflowTimeout", "0");
startChannel(params);
-
//1 Rollback for Puts
- transactionalPutN(1,5, channel);
+ transactionalPutN(1, 5, channel);
Transaction tx = channel.getTransaction();
tx.begin();
putN(6, 5, channel);
@@ -530,8 +520,7 @@ public class TestSpillableMemoryChannel {
//2. verify things back to normal after put rollback
transactionalPutN(11, 5, channel);
- transactionalTakeN(11,5,channel);
-
+ transactionalTakeN(11, 5, channel);
//3 Rollback for Takes
transactionalPutN(16, 5, channel);
@@ -545,13 +534,12 @@ public class TestSpillableMemoryChannel {
transactionalTakeN_NoCheck(5, channel);
//4. verify things back to normal after take rollback
- transactionalPutN(21,5, channel);
- transactionalTakeN(21,5,channel);
+ transactionalPutN(21, 5, channel);
+ transactionalTakeN(21, 5, channel);
}
-
@Test
- public void testReconfigure() {
+ public void testReconfigure() {
//1) bring up with small capacity
Map<String, String> params = new HashMap<String, String>();
params.put("memoryCapacity", "10");
@@ -559,12 +547,12 @@ public class TestSpillableMemoryChannel {
params.put("overflowTimeout", "0");
startChannel(params);
- Assert.assertTrue("overflowTimeout setting did not reconfigure correctly"
- , channel.getOverflowTimeout() == 0);
- Assert.assertTrue("memoryCapacity did not reconfigure correctly"
- , channel.getMemoryCapacity() == 10);
- Assert.assertTrue("overflowCapacity did not reconfigure correctly"
- , channel.isOverflowDisabled() );
+ Assert.assertTrue("overflowTimeout setting did not reconfigure correctly",
+ channel.getOverflowTimeout() == 0);
+ Assert.assertTrue("memoryCapacity did not reconfigure correctly",
+ channel.getMemoryCapacity() == 10);
+ Assert.assertTrue("overflowCapacity did not reconfigure correctly",
+ channel.isOverflowDisabled());
transactionalPutN(1, 10, channel);
boolean threw = false;
@@ -574,8 +562,7 @@ public class TestSpillableMemoryChannel {
threw = true;
}
Assert.assertTrue("Expected the channel to fill up and throw an exception, "
- + "but it did not throw", threw);
-
+ + "but it did not throw", threw);
//2) Resize and verify
params = new HashMap<String, String>();
@@ -583,12 +570,13 @@ public class TestSpillableMemoryChannel {
params.put("overflowCapacity", "0");
reconfigureChannel(params);
- Assert.assertTrue("overflowTimeout setting did not reconfigure correctly"
- , channel.getOverflowTimeout() == SpillableMemoryChannel.defaultOverflowTimeout);
- Assert.assertTrue("memoryCapacity did not reconfigure correctly"
- , channel.getMemoryCapacity() == 20);
- Assert.assertTrue("overflowCapacity did not reconfigure correctly"
- , channel.isOverflowDisabled() );
+ Assert.assertTrue("overflowTimeout setting did not reconfigure correctly",
+ channel.getOverflowTimeout() ==
+ SpillableMemoryChannel.defaultOverflowTimeout);
+ Assert.assertTrue("memoryCapacity did not reconfigure correctly",
+ channel.getMemoryCapacity() == 20);
+ Assert.assertTrue("overflowCapacity did not reconfigure correctly",
+ channel.isOverflowDisabled());
// pull out the values inserted prior to reconfiguration
transactionalTakeN(1, 10, channel);
@@ -603,25 +591,25 @@ public class TestSpillableMemoryChannel {
threw = true;
}
Assert.assertTrue("Expected the channel to fill up and throw an exception, "
- + "but it did not throw", threw);
+ + "but it did not throw", threw);
transactionalTakeN(11, 10, channel);
transactionalTakeN(21, 10, channel);
-
// 3) Reconfigure with empty config and verify settings revert to default
params = new HashMap<String, String>();
reconfigureChannel(params);
- Assert.assertTrue("overflowTimeout setting did not reconfigure correctly"
- , channel.getOverflowTimeout() == SpillableMemoryChannel.defaultOverflowTimeout);
- Assert.assertTrue("memoryCapacity did not reconfigure correctly"
- , channel.getMemoryCapacity() == SpillableMemoryChannel.defaultMemoryCapacity);
- Assert.assertTrue("overflowCapacity did not reconfigure correctly"
- , channel.getOverflowCapacity() == SpillableMemoryChannel.defaultOverflowCapacity);
- Assert.assertFalse("overflowCapacity did not reconfigure correctly"
- , channel.isOverflowDisabled());
-
+ Assert.assertTrue("overflowTimeout setting did not reconfigure correctly",
+ channel.getOverflowTimeout() ==
+ SpillableMemoryChannel.defaultOverflowTimeout);
+ Assert.assertTrue("memoryCapacity did not reconfigure correctly",
+ channel.getMemoryCapacity() == SpillableMemoryChannel.defaultMemoryCapacity);
+ Assert.assertTrue("overflowCapacity did not reconfigure correctly",
+ channel.getOverflowCapacity() ==
+ SpillableMemoryChannel.defaultOverflowCapacity);
+ Assert.assertFalse("overflowCapacity did not reconfigure correctly",
+ channel.isOverflowDisabled());
// 4) Reconfiguring of overflow
params = new HashMap<String, String>();
@@ -631,19 +619,18 @@ public class TestSpillableMemoryChannel {
params.put("overflowTimeout", "1");
reconfigureChannel(params);
- transactionalPutN( 1,5, channel);
- transactionalPutN( 6,5, channel);
- transactionalPutN(11,5, channel);
- transactionalPutN(16,5, channel);
- threw=false;
+ transactionalPutN(1, 5, channel);
+ transactionalPutN(6, 5, channel);
+ transactionalPutN(11, 5, channel);
+ transactionalPutN(16, 5, channel);
+ threw = false;
try {
// should error out as both primary & overflow are full
- transactionalPutN(21,5, channel);
+ transactionalPutN(21, 5, channel);
} catch (ChannelException e) {
threw = true;
}
- Assert.assertTrue("Expected the last insertion to fail, but it didn't."
- , threw);
+ Assert.assertTrue("Expected the last insertion to fail, but it didn't.", threw);
// reconfig the overflow
params = new HashMap<String, String>();
@@ -654,10 +641,10 @@ public class TestSpillableMemoryChannel {
reconfigureChannel(params);
// should succeed now as we have made room in the overflow
- transactionalPutN(21,5, channel);
+ transactionalPutN(21, 5, channel);
- transactionalTakeN(1,10, channel);
- transactionalTakeN(11,5, channel);
+ transactionalTakeN(1, 10, channel);
+ transactionalTakeN(11, 5, channel);
transactionalTakeN(16, 5, channel);
transactionalTakeN(21, 5, channel);
}
@@ -666,13 +653,13 @@ public class TestSpillableMemoryChannel {
public void testParallelSingleSourceAndSink() throws InterruptedException {
Map<String, String> params = new HashMap<String, String>();
params.put("memoryCapacity", "1000020");
- params.put("overflowCapacity", "0");
+ params.put("overflowCapacity", "0");
params.put("overflowTimeout", "3");
startChannel(params);
// run source and sink concurrently
Thread sourceThd = makePutThread("src", 1, 500000, 100, channel);
- Thread sinkThd = makeTakeThread("sink", 1, 500000, 100, channel);
+ Thread sinkThd = makeTakeThread("sink", 1, 500000, 100, channel);
StopWatch watch = new StopWatch();
@@ -683,15 +670,15 @@ public class TestSpillableMemoryChannel {
sinkThd.join();
watch.elapsed();
- System.out.println("Max Queue size " + channel.getMaxMemQueueSize() );
+ System.out.println("Max Queue size " + channel.getMaxMemQueueSize());
}
@Test
public void testCounters() throws InterruptedException {
Map<String, String> params = new HashMap<String, String>();
- params.put("memoryCapacity", "5000");
- params.put("overflowCapacity","5000");
- params.put("transactionCapacity","5000");
+ params.put("memoryCapacity", "5000");
+ params.put("overflowCapacity", "5000");
+ params.put("transactionCapacity", "5000");
params.put("overflowTimeout", "0");
startChannel(params);
@@ -706,7 +693,7 @@ public class TestSpillableMemoryChannel {
Assert.assertEquals(5000, channel.channelCounter.getEventPutSuccessCount());
//2. empty mem queue
- Thread sinkThd = makeTakeThread("sink", 1, 5000, 1000, channel);
+ Thread sinkThd = makeTakeThread("sink", 1, 5000, 1000, channel);
sinkThd.start();
sinkThd.join();
Assert.assertEquals(0, channel.getTotalStored());
@@ -714,7 +701,6 @@ public class TestSpillableMemoryChannel {
Assert.assertEquals(5000, channel.channelCounter.getEventTakeAttemptCount());
Assert.assertEquals(5000, channel.channelCounter.getEventTakeSuccessCount());
-
//3. fill up mem & overflow
sourceThd = makePutThread("src", 1, 10000, 1000, channel);
sourceThd.start();
@@ -724,9 +710,8 @@ public class TestSpillableMemoryChannel {
Assert.assertEquals(15000, channel.channelCounter.getEventPutAttemptCount());
Assert.assertEquals(15000, channel.channelCounter.getEventPutSuccessCount());
-
//4. empty memory
- sinkThd = makeTakeThread("sink", 1, 5000, 1000, channel);
+ sinkThd = makeTakeThread("sink", 1, 5000, 1000, channel);
sinkThd.start();
sinkThd.join();
Assert.assertEquals(5000, channel.getTotalStored());
@@ -745,12 +730,10 @@ public class TestSpillableMemoryChannel {
Assert.assertEquals(15000, channel.channelCounter.getEventTakeAttemptCount());
Assert.assertEquals(15000, channel.channelCounter.getEventTakeSuccessCount());
-
-
//6. now do it concurrently
sourceThd = makePutThread("src1", 1, 5000, 1000, channel);
Thread sourceThd2 = makePutThread("src2", 1, 5000, 500, channel);
- sinkThd = makeTakeThread_noCheck("sink1", 5000, 1000, channel);
+ sinkThd = makeTakeThread_noCheck("sink1", 5000, 1000, channel);
sourceThd.start();
sourceThd2.start();
sinkThd.start();
@@ -759,8 +742,8 @@ public class TestSpillableMemoryChannel {
sinkThd.join();
Assert.assertEquals(5000, channel.getTotalStored());
Assert.assertEquals(5000, channel.channelCounter.getChannelSize());
- Thread sinkThd2 = makeTakeThread_noCheck("sink2", 2500, 500, channel);
- Thread sinkThd3 = makeTakeThread_noCheck("sink3", 2500, 1000, channel);
+ Thread sinkThd2 = makeTakeThread_noCheck("sink2", 2500, 500, channel);
+ Thread sinkThd3 = makeTakeThread_noCheck("sink3", 2500, 1000, channel);
sinkThd2.start();
sinkThd3.start();
sinkThd2.join();
@@ -769,30 +752,26 @@ public class TestSpillableMemoryChannel {
Assert.assertEquals(0, channel.channelCounter.getChannelSize());
Assert.assertEquals(25000, channel.channelCounter.getEventTakeSuccessCount());
Assert.assertEquals(25000, channel.channelCounter.getEventPutSuccessCount());
- Assert.assertTrue("TakeAttempt channel counter value larger than expected" ,
- 25000 <= channel.channelCounter.getEventTakeAttemptCount());
+ Assert.assertTrue("TakeAttempt channel counter value larger than expected",
+ 25000 <= channel.channelCounter.getEventTakeAttemptCount());
Assert.assertTrue("PutAttempt channel counter value larger than expected",
- 25000 <= channel.channelCounter.getEventPutAttemptCount());
+ 25000 <= channel.channelCounter.getEventPutAttemptCount());
}
- public ArrayList<Thread> createSourceThreads(int count, int totalEvents
- , int batchSize) {
+ public ArrayList<Thread> createSourceThreads(int count, int totalEvents, int batchSize) {
ArrayList<Thread> sourceThds = new ArrayList<Thread>();
for (int i = 0; i < count; ++i) {
- sourceThds.add( makePutThread("src" + i, 1, totalEvents/count
- , batchSize, channel) );
+ sourceThds.add(makePutThread("src" + i, 1, totalEvents / count, batchSize, channel));
}
return sourceThds;
}
- public ArrayList<Thread> createSinkThreads(int count, int totalEvents
- , int batchSize) {
+ public ArrayList<Thread> createSinkThreads(int count, int totalEvents, int batchSize) {
ArrayList<Thread> sinkThreads = new ArrayList<Thread>(count);
for (int i = 0; i < count; ++i) {
- sinkThreads.add( makeTakeThread_noCheck("sink"+i, totalEvents/count
- , batchSize, channel) );
+ sinkThreads.add(makeTakeThread_noCheck("sink" + i, totalEvents / count, batchSize, channel));
}
return sinkThreads;
}
@@ -803,13 +782,12 @@ public class TestSpillableMemoryChannel {
}
}
- public void joinThreads(ArrayList<Thread> threads)
- throws InterruptedException {
+ public void joinThreads(ArrayList<Thread> threads) throws InterruptedException {
for (Thread thread : threads) {
try {
thread.join();
} catch (InterruptedException e) {
- System.out.println("Interrupted while waiting on " + thread.getName() );
+ System.out.println("Interrupted while waiting on " + thread.getName());
throw e;
}
}
@@ -824,15 +802,13 @@ public class TestSpillableMemoryChannel {
Map<String, String> params = new HashMap<String, String>();
params.put("memoryCapacity", "0");
- params.put("overflowCapacity", "500020");
+ params.put("overflowCapacity", "500020");
params.put("overflowTimeout", "3");
startChannel(params);
ArrayList<Thread> sinks = createSinkThreads(sinkCount, eventCount, batchSize);
- ArrayList<Thread> sources = createSourceThreads(sourceCount
- , eventCount, batchSize);
-
+ ArrayList<Thread> sources = createSourceThreads(sourceCount, eventCount, batchSize);
StopWatch watch = new StopWatch();
startThreads(sinks);
@@ -845,7 +821,7 @@ public class TestSpillableMemoryChannel {
System.out.println("Total puts " + channel.drainOrder.totalPuts);
- System.out.println("Max Queue size " + channel.getMaxMemQueueSize() );
+ System.out.println("Max Queue size " + channel.getMaxMemQueueSize());
System.out.println(channel.memQueue.size());
System.out.println("done");
@@ -872,10 +848,10 @@ public class TestSpillableMemoryChannel {
if (elapsed < 10000) {
System.out.println(Thread.currentThread().getName()
- + " : [ " + elapsed + " ms ]. " + suffix);
+ + " : [ " + elapsed + " ms ]. " + suffix);
} else {
System.out.println(Thread.currentThread().getName()
- + " : [ " + elapsed / 1000 + " sec ]. " + suffix);
+ + " : [ " + elapsed / 1000 + " sec ]. " + suffix);
}
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLoadBalancingLog4jAppender.java
----------------------------------------------------------------------
diff --git a/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLoadBalancingLog4jAppender.java b/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLoadBalancingLog4jAppender.java
index 267ac1d..53795fb 100644
--- a/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLoadBalancingLog4jAppender.java
+++ b/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLoadBalancingLog4jAppender.java
@@ -65,7 +65,7 @@ public class TestLoadBalancingLog4jAppender {
private boolean slowDown = false;
@Before
- public void initiate() throws InterruptedException{
+ public void initiate() throws InterruptedException {
ch = new MemoryChannel();
configureChannel();
@@ -164,9 +164,9 @@ public class TestLoadBalancingLog4jAppender {
@Test
public void testRandomBackoffUnsafeMode() throws Exception {
File TESTFILE = new File(TestLoadBalancingLog4jAppender.class
- .getClassLoader()
- .getResource("flume-loadbalancing-backoff-log4jtest.properties")
- .getFile());
+ .getClassLoader()
+ .getResource("flume-loadbalancing-backoff-log4jtest.properties")
+ .getFile());
startSources(TESTFILE, true, new int[]{25430, 25431, 25432});
sources.get(0).setFail();
@@ -179,9 +179,9 @@ public class TestLoadBalancingLog4jAppender {
@Test (expected = EventDeliveryException.class)
public void testTimeout() throws Throwable {
File TESTFILE = new File(TestLoadBalancingLog4jAppender.class
- .getClassLoader()
- .getResource("flume-loadbalancinglog4jtest.properties")
- .getFile());
+ .getClassLoader()
+ .getResource("flume-loadbalancinglog4jtest.properties")
+ .getFile());
ch = new TestLog4jAppender.SlowMemoryChannel(2000);
configureChannel();
@@ -200,9 +200,9 @@ public class TestLoadBalancingLog4jAppender {
@Test(expected = EventDeliveryException.class)
public void testRandomBackoffNotUnsafeMode() throws Throwable {
File TESTFILE = new File(TestLoadBalancingLog4jAppender.class
- .getClassLoader()
- .getResource("flume-loadbalancing-backoff-log4jtest.properties")
- .getFile());
+ .getClassLoader()
+ .getResource("flume-loadbalancing-backoff-log4jtest.properties")
+ .getFile());
startSources(TESTFILE, false, new int[]{25430, 25431, 25432});
sources.get(0).setFail();
@@ -224,17 +224,17 @@ public class TestLoadBalancingLog4jAppender {
}
private void sendAndAssertFail() throws IOException {
- int level = 20000;
- String msg = "This is log message number" + String.valueOf(level);
- fixture.log(Level.toLevel(level), msg);
+ int level = 20000;
+ String msg = "This is log message number" + String.valueOf(level);
+ fixture.log(Level.toLevel(level), msg);
- Transaction transaction = ch.getTransaction();
- transaction.begin();
- Event event = ch.take();
- Assert.assertNull(event);
+ Transaction transaction = ch.getTransaction();
+ transaction.begin();
+ Event event = ch.take();
+ Assert.assertNull(event);
- transaction.commit();
- transaction.close();
+ transaction.commit();
+ transaction.close();
}
@@ -271,8 +271,7 @@ public class TestLoadBalancingLog4jAppender {
}
private void startSources(File log4jProps, boolean unsafeMode, int... ports)
- throws
- IOException {
+ throws IOException {
for (int port : ports) {
CountingAvroSource source = new CountingAvroSource(port);
Context context = new Context();
@@ -297,8 +296,8 @@ public class TestLoadBalancingLog4jAppender {
Properties props = new Properties();
props.load(reader);
props.setProperty("log4j.appender.out2.UnsafeMode",
- String.valueOf(unsafeMode));
- if(slowDown) {
+ String.valueOf(unsafeMode));
+ if (slowDown) {
props.setProperty("log4j.appender.out2.Timeout", String.valueOf(1000));
}
PropertyConfigurator.configure(props);
@@ -308,13 +307,13 @@ public class TestLoadBalancingLog4jAppender {
static class CountingAvroSource extends AvroSource {
AtomicInteger appendCount = new AtomicInteger();
volatile boolean isFail = false;
- private final int port2;
+ private final int port2;
public CountingAvroSource(int port) {
- port2 = port;
+ port2 = port;
}
- public void setOk() {
+ public void setOk() {
this.isFail = false;
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppender.java
----------------------------------------------------------------------
diff --git a/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppender.java b/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppender.java
index 1b840f3..c087b67 100644
--- a/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppender.java
+++ b/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppender.java
@@ -21,7 +21,10 @@ package org.apache.flume.clients.log4jappender;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
@@ -46,13 +49,13 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-public class TestLog4jAppender{
+public class TestLog4jAppender {
private AvroSource source;
private Channel ch;
private Properties props;
@Before
- public void initiate() throws Exception{
+ public void initiate() throws Exception {
int port = 25430;
source = new AvroSource();
ch = new MemoryChannel();
@@ -88,13 +91,13 @@ public class TestLog4jAppender{
configureSource();
PropertyConfigurator.configure(props);
Logger logger = LogManager.getLogger(TestLog4jAppender.class);
- for(int count = 0; count <= 1000; count++){
+ 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;
+ int level = ((count % 5) + 1) * 10000;
String msg = "This is log message number" + String.valueOf(count);
logger.log(Level.toLevel(level), msg);
@@ -146,11 +149,11 @@ public class TestLog4jAppender{
}
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.
- */
+ /*
+ * 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");
@@ -177,13 +180,13 @@ public class TestLog4jAppender{
PropertyConfigurator.configure(props);
Logger logger = LogManager.getLogger(TestLog4jAppender.class);
Thread.currentThread().setName("Log4jAppenderTest");
- for(int count = 0; count <= 100; count++){
+ for (int count = 0; count <= 100; 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;
+ int level = ((count % 5) + 1) * 10000;
String msg = "This is log message number" + String.valueOf(count);
logger.log(Level.toLevel(level), msg);
@@ -230,7 +233,7 @@ public class TestLog4jAppender{
props.put("log4j.appender.out2.Timeout", "1000");
props.put("log4j.appender.out2.layout", "org.apache.log4j.PatternLayout");
props.put("log4j.appender.out2.layout.ConversionPattern",
- "%-5p [%t]: %m%n");
+ "%-5p [%t]: %m%n");
PropertyConfigurator.configure(props);
Logger logger = LogManager.getLogger(TestLog4jAppender.class);
Thread.currentThread().setName("Log4jAppenderTest");
@@ -251,13 +254,12 @@ public class TestLog4jAppender{
@After
- public void cleanUp(){
+ public void cleanUp() {
source.stop();
ch.stop();
props.clear();
}
-
static class SlowMemoryChannel extends MemoryChannel {
private final int slowTime;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppenderWithAvro.java
----------------------------------------------------------------------
diff --git a/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppenderWithAvro.java b/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppenderWithAvro.java
index 5899c62..0607e3a 100644
--- a/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppenderWithAvro.java
+++ b/flume-ng-clients/flume-ng-log4jappender/src/test/java/org/apache/flume/clients/log4jappender/TestLog4jAppenderWithAvro.java
@@ -125,8 +125,7 @@ public class TestLog4jAppenderWithAvro {
Assert.assertNull(hdrs.get(Log4jAvroHeaders.MESSAGE_ENCODING.toString()));
Assert.assertEquals("Schema URL should be set",
- "file:///tmp/myrecord.avsc", hdrs.get(Log4jAvroHeaders.AVRO_SCHEMA_URL.toString
- ()));
+ "file:///tmp/myrecord.avsc", hdrs.get(Log4jAvroHeaders.AVRO_SCHEMA_URL.toString()));
Assert.assertNull("Schema string should not be set",
hdrs.get(Log4jAvroHeaders.AVRO_SCHEMA_LITERAL.toString()));
@@ -174,7 +173,7 @@ public class TestLog4jAppenderWithAvro {
}
@After
- public void cleanUp(){
+ public void cleanUp() {
source.stop();
ch.stop();
props.clear();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/channel/AbstractBasicChannelSemanticsTest.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/channel/AbstractBasicChannelSemanticsTest.java b/flume-ng-core/src/test/java/org/apache/flume/channel/AbstractBasicChannelSemanticsTest.java
index 59a804c..7600856 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/channel/AbstractBasicChannelSemanticsTest.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/channel/AbstractBasicChannelSemanticsTest.java
@@ -40,6 +40,7 @@ import com.google.common.base.Preconditions;
public abstract class AbstractBasicChannelSemanticsTest {
protected static List<Event> events;
+
static {
Event[] array = new Event[7];
for (int i = 0; i < array.length; ++i) {
@@ -61,7 +62,7 @@ public abstract class AbstractBasicChannelSemanticsTest {
THROW_RUNTIME,
THROW_CHANNEL,
SLEEP
- };
+ }
private Mode mode = Mode.NORMAL;
private boolean lastTransactionCommitted = false;
@@ -158,11 +159,11 @@ public abstract class AbstractBasicChannelSemanticsTest {
protected static class TestError extends Error {
static final long serialVersionUID = -1;
- };
+ }
protected static class TestRuntimeException extends RuntimeException {
static final long serialVersionUID = -1;
- };
+ }
protected void testException(Class<? extends Throwable> exceptionClass,
Runnable test) {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/channel/TestChannelProcessor.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/channel/TestChannelProcessor.java b/flume-ng-core/src/test/java/org/apache/flume/channel/TestChannelProcessor.java
index b37b823..93bc0cf 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/channel/TestChannelProcessor.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/channel/TestChannelProcessor.java
@@ -20,16 +20,22 @@ package org.apache.flume.channel;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.flume.*;
+import org.apache.flume.Channel;
+import org.apache.flume.ChannelException;
+import org.apache.flume.ChannelSelector;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.flume.Transaction;
import org.apache.flume.conf.Configurables;
import org.apache.flume.event.EventBuilder;
import org.junit.Assert;
import org.junit.Test;
-import static org.mockito.Mockito.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class TestChannelProcessor {
@@ -88,9 +94,9 @@ public class TestChannelProcessor {
public void testRequiredAndOptionalChannels() {
Context context = new Context();
ArrayList<Channel> channels = new ArrayList<Channel>();
- for(int i = 0; i < 4; i++) {
+ for (int i = 0; i < 4; i++) {
Channel ch = new MemoryChannel();
- ch.setName("ch"+i);
+ ch.setName("ch" + i);
Configurables.configure(ch, context);
channels.add(ch);
}
@@ -114,7 +120,7 @@ public class TestChannelProcessor {
} catch (InterruptedException e) {
}
- for(Channel channel : channels) {
+ for (Channel channel : channels) {
Transaction transaction = channel.getTransaction();
transaction.begin();
Event event_ch = channel.take();
@@ -124,18 +130,18 @@ public class TestChannelProcessor {
}
List<Event> events = Lists.newArrayList();
- for(int i = 0; i < 100; i ++) {
- events.add(EventBuilder.withBody("event "+i, Charsets.UTF_8));
+ for (int i = 0; i < 100; i++) {
+ events.add(EventBuilder.withBody("event " + i, Charsets.UTF_8));
}
processor.processEventBatch(events);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
}
- for(Channel channel : channels) {
+ for (Channel channel : channels) {
Transaction transaction = channel.getTransaction();
transaction.begin();
- for(int i = 0; i < 100; i ++) {
+ for (int i = 0; i < 100; i++) {
Event event_ch = channel.take();
Assert.assertNotNull(event_ch);
}
[8/9] flume git commit: FLUME-2941. Integrate checkstyle for test
classes
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFlumeEventQueue.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFlumeEventQueue.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFlumeEventQueue.java
index 1adb21a..f1700f9 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFlumeEventQueue.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestFlumeEventQueue.java
@@ -55,6 +55,7 @@ public class TestFlumeEventQueue {
File inflightTakes;
File inflightPuts;
File queueSetDir;
+
EventQueueBackingStoreSupplier() {
baseDir = Files.createTempDir();
checkpoint = new File(baseDir, "checkpoint");
@@ -62,62 +63,73 @@ public class TestFlumeEventQueue {
inflightPuts = new File(baseDir, "inflighttakes");
queueSetDir = new File(baseDir, "queueset");
}
+
File getCheckpoint() {
return checkpoint;
}
+
File getInflightPuts() {
return inflightPuts;
}
+
File getInflightTakes() {
return inflightTakes;
}
+
File getQueueSetDir() {
return queueSetDir;
}
+
void delete() {
FileUtils.deleteQuietly(baseDir);
}
- abstract EventQueueBackingStore get() throws Exception ;
+
+ abstract EventQueueBackingStore get() throws Exception;
}
@Parameters
public static Collection<Object[]> data() throws Exception {
- Object[][] data = new Object[][] { {
- new EventQueueBackingStoreSupplier() {
- @Override
- public EventQueueBackingStore get() throws Exception {
- Assert.assertTrue(baseDir.isDirectory() || baseDir.mkdirs());
- return new EventQueueBackingStoreFileV2(getCheckpoint(), 1000,
- "test");
+ Object[][] data = new Object[][] {
+ {
+ new EventQueueBackingStoreSupplier() {
+ @Override
+ public EventQueueBackingStore get() throws Exception {
+ Assert.assertTrue(baseDir.isDirectory() || baseDir.mkdirs());
+ return new EventQueueBackingStoreFileV2(getCheckpoint(), 1000,
+ "test");
+ }
}
- }
- }, {
- new EventQueueBackingStoreSupplier() {
- @Override
- public EventQueueBackingStore get() throws Exception {
- Assert.assertTrue(baseDir.isDirectory() || baseDir.mkdirs());
- return new EventQueueBackingStoreFileV3(getCheckpoint(), 1000,
- "test");
+ },
+ {
+ new EventQueueBackingStoreSupplier() {
+ @Override
+ public EventQueueBackingStore get() throws Exception {
+ Assert.assertTrue(baseDir.isDirectory() || baseDir.mkdirs());
+ return new EventQueueBackingStoreFileV3(getCheckpoint(), 1000, "test");
+ }
}
}
- } };
+ };
return Arrays.asList(data);
}
public TestFlumeEventQueue(EventQueueBackingStoreSupplier backingStoreSupplier) {
this.backingStoreSupplier = backingStoreSupplier;
}
+
@Before
public void setup() throws Exception {
backingStore = backingStoreSupplier.get();
}
+
@After
public void cleanup() throws IOException {
- if(backingStore != null) {
+ if (backingStore != null) {
backingStore.close();
}
backingStoreSupplier.delete();
}
+
@Test
public void testCapacity() throws Exception {
backingStore.close();
@@ -125,70 +137,76 @@ public class TestFlumeEventQueue {
Assert.assertTrue(checkpoint.delete());
backingStore = new EventQueueBackingStoreFileV2(checkpoint, 1, "test");
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
Assert.assertTrue(queue.addTail(pointer1));
Assert.assertFalse(queue.addTail(pointer2));
}
- @Test(expected=IllegalArgumentException.class)
+
+ @Test(expected = IllegalArgumentException.class)
public void testInvalidCapacityZero() throws Exception {
backingStore.close();
File checkpoint = backingStoreSupplier.getCheckpoint();
Assert.assertTrue(checkpoint.delete());
backingStore = new EventQueueBackingStoreFileV2(checkpoint, 0, "test");
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
}
- @Test(expected=IllegalArgumentException.class)
+
+ @Test(expected = IllegalArgumentException.class)
public void testInvalidCapacityNegative() throws Exception {
backingStore.close();
File checkpoint = backingStoreSupplier.getCheckpoint();
Assert.assertTrue(checkpoint.delete());
backingStore = new EventQueueBackingStoreFileV2(checkpoint, -1, "test");
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
}
+
@Test
public void testQueueIsEmptyAfterCreation() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
Assert.assertNull(queue.removeHead(0L));
}
+
@Test
public void addTail1() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
Assert.assertTrue(queue.addTail(pointer1));
Assert.assertEquals(pointer1, queue.removeHead(0));
Assert.assertEquals(Sets.newHashSet(), queue.getFileIDs());
}
+
@Test
public void addTail2() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
Assert.assertTrue(queue.addTail(pointer1));
Assert.assertTrue(queue.addTail(pointer2));
Assert.assertEquals(Sets.newHashSet(1, 2), queue.getFileIDs());
Assert.assertEquals(pointer1, queue.removeHead(0));
Assert.assertEquals(Sets.newHashSet(2), queue.getFileIDs());
}
+
@Test
public void addTailLarge() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
int size = 500;
Set<Integer> fileIDs = Sets.newHashSet();
for (int i = 1; i <= size; i++) {
@@ -203,23 +221,25 @@ public class TestFlumeEventQueue {
}
Assert.assertEquals(Sets.newHashSet(), queue.getFileIDs());
}
+
@Test
public void addHead1() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
Assert.assertTrue(queue.addHead(pointer1));
Assert.assertEquals(Sets.newHashSet(1), queue.getFileIDs());
Assert.assertEquals(pointer1, queue.removeHead(0));
Assert.assertEquals(Sets.newHashSet(), queue.getFileIDs());
}
+
@Test
public void addHead2() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
queue.replayComplete();
Assert.assertTrue(queue.addHead(pointer1));
Assert.assertTrue(queue.addHead(pointer2));
@@ -227,12 +247,13 @@ public class TestFlumeEventQueue {
Assert.assertEquals(pointer2, queue.removeHead(0));
Assert.assertEquals(Sets.newHashSet(1), queue.getFileIDs());
}
+
@Test
public void addHeadLarge() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
queue.replayComplete();
int size = 500;
Set<Integer> fileIDs = Sets.newHashSet();
@@ -248,12 +269,13 @@ public class TestFlumeEventQueue {
}
Assert.assertEquals(Sets.newHashSet(), queue.getFileIDs());
}
+
@Test
public void addTailRemove1() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
Assert.assertTrue(queue.addTail(pointer1));
Assert.assertEquals(Sets.newHashSet(1), queue.getFileIDs());
Assert.assertTrue(queue.remove(pointer1));
@@ -266,9 +288,9 @@ public class TestFlumeEventQueue {
@Test
public void addTailRemove2() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
Assert.assertTrue(queue.addTail(pointer1));
Assert.assertTrue(queue.addTail(pointer2));
Assert.assertTrue(queue.remove(pointer1));
@@ -279,31 +301,33 @@ public class TestFlumeEventQueue {
@Test
public void addHeadRemove1() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
queue.addHead(pointer1);
Assert.assertTrue(queue.remove(pointer1));
Assert.assertNull(queue.removeHead(0));
}
+
@Test
public void addHeadRemove2() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
Assert.assertTrue(queue.addHead(pointer1));
Assert.assertTrue(queue.addHead(pointer2));
Assert.assertTrue(queue.remove(pointer1));
queue.replayComplete();
Assert.assertEquals(pointer2, queue.removeHead(0));
}
+
@Test
public void testUnknownPointerDoesNotCauseSearch() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
Assert.assertTrue(queue.addHead(pointer1));
Assert.assertTrue(queue.addHead(pointer2));
Assert.assertFalse(queue.remove(pointer3)); // does search
@@ -312,44 +336,47 @@ public class TestFlumeEventQueue {
queue.replayComplete();
Assert.assertEquals(2, queue.getSearchCount());
}
- @Test(expected=IllegalStateException.class)
+
+ @Test(expected = IllegalStateException.class)
public void testRemoveAfterReplayComplete() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
queue.replayComplete();
queue.remove(pointer1);
}
+
@Test
public void testWrappingCorrectly() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
int size = Integer.MAX_VALUE;
for (int i = 1; i <= size; i++) {
- if(!queue.addHead(new FlumeEventPointer(i, i))) {
+ if (!queue.addHead(new FlumeEventPointer(i, i))) {
break;
}
}
- for (int i = queue.getSize()/2; i > 0; i--) {
+ for (int i = queue.getSize() / 2; i > 0; i--) {
Assert.assertNotNull(queue.removeHead(0));
}
// addHead below would throw an IndexOOBounds with
// bad version of FlumeEventQueue.convert
for (int i = 1; i <= size; i++) {
- if(!queue.addHead(new FlumeEventPointer(i, i))) {
+ if (!queue.addHead(new FlumeEventPointer(i, i))) {
break;
}
}
}
+
@Test
- public void testInflightPuts() throws Exception{
+ public void testInflightPuts() throws Exception {
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
long txnID1 = new Random().nextInt(Integer.MAX_VALUE - 1);
long txnID2 = txnID1 + 1;
queue.addWithoutCommit(new FlumeEventPointer(1, 1), txnID1);
@@ -358,16 +385,13 @@ public class TestFlumeEventQueue {
queue.checkpoint(true);
TimeUnit.SECONDS.sleep(3L);
queue = new FlumeEventQueue(backingStore,
- backingStoreSupplier.getInflightTakes(),
- backingStoreSupplier.getInflightPuts(),
- backingStoreSupplier.getQueueSetDir());
+ backingStoreSupplier.getInflightTakes(),
+ backingStoreSupplier.getInflightPuts(),
+ backingStoreSupplier.getQueueSetDir());
SetMultimap<Long, Long> deserializedMap = queue.deserializeInflightPuts();
- Assert.assertTrue(deserializedMap.get(
- txnID1).contains(new FlumeEventPointer(1, 1).toLong()));
- Assert.assertTrue(deserializedMap.get(
- txnID1).contains(new FlumeEventPointer(2, 1).toLong()));
- Assert.assertTrue(deserializedMap.get(
- txnID2).contains(new FlumeEventPointer(2, 2).toLong()));
+ Assert.assertTrue(deserializedMap.get(txnID1).contains(new FlumeEventPointer(1, 1).toLong()));
+ Assert.assertTrue(deserializedMap.get(txnID1).contains(new FlumeEventPointer(2, 1).toLong()));
+ Assert.assertTrue(deserializedMap.get(txnID2).contains(new FlumeEventPointer(2, 2).toLong()));
}
@Test
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestIntegration.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestIntegration.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestIntegration.java
index 2fbe116..a138ed4 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestIntegration.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestIntegration.java
@@ -18,13 +18,8 @@
*/
package org.apache.flume.channel.file;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-import java.util.concurrent.TimeUnit;
-
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
import org.apache.commons.io.FileUtils;
import org.apache.flume.Context;
import org.apache.flume.conf.Configurables;
@@ -37,8 +32,12 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.Lists;
-import com.google.common.io.Files;
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
public class TestIntegration {
@@ -58,19 +57,21 @@ public class TestIntegration {
dataDirs = new File[3];
dataDir = "";
for (int i = 0; i < dataDirs.length; i++) {
- dataDirs[i] = new File(baseDir, "data" + (i+1));
+ dataDirs[i] = new File(baseDir, "data" + (i + 1));
Assert.assertTrue(dataDirs[i].mkdirs() || dataDirs[i].isDirectory());
dataDir += dataDirs[i].getAbsolutePath() + ",";
}
dataDir = dataDir.substring(0, dataDir.length() - 1);
}
+
@After
public void teardown() {
- if(channel != null && channel.isOpen()) {
+ if (channel != null && channel.isOpen()) {
channel.stop();
}
FileUtils.deleteQuietly(baseDir);
}
+
@Test
public void testIntegration() throws IOException, InterruptedException {
// set shorter checkpoint and filesize to ensure
@@ -106,11 +107,11 @@ public class TestIntegration {
TimeUnit.SECONDS.sleep(30);
// shutdown source
sourceRunner.shutdown();
- while(sourceRunner.isAlive()) {
+ while (sourceRunner.isAlive()) {
Thread.sleep(10L);
}
// wait for queue to clear
- while(channel.getDepth() > 0) {
+ while (channel.getDepth() > 0) {
Thread.sleep(10L);
}
// shutdown size
@@ -122,15 +123,15 @@ public class TestIntegration {
logs.addAll(LogUtils.getLogs(dataDirs[i]));
}
LOG.info("Total Number of Logs = " + logs.size());
- for(File logFile : logs) {
+ for (File logFile : logs) {
LOG.info("LogFile = " + logFile);
}
LOG.info("Source processed " + sinkRunner.getCount());
LOG.info("Sink processed " + sourceRunner.getCount());
- for(Exception ex : sourceRunner.getErrors()) {
+ for (Exception ex : sourceRunner.getErrors()) {
LOG.warn("Source had error", ex);
}
- for(Exception ex : sinkRunner.getErrors()) {
+ for (Exception ex : sinkRunner.getErrors()) {
LOG.warn("Sink had error", ex);
}
Assert.assertEquals(sinkRunner.getCount(), sinkRunner.getCount());
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLog.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLog.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLog.java
index b1f59cd..f7f0950 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLog.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLog.java
@@ -18,14 +18,8 @@
*/
package org.apache.flume.channel.file;
-import static org.mockito.Mockito.*;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.channels.*;
-import java.util.Collection;
-import java.util.List;
-
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Assert;
@@ -34,8 +28,13 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.Lists;
-import com.google.common.io.Files;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class TestLog {
private static final Logger LOGGER = LoggerFactory.getLogger(TestLog.class);
@@ -45,6 +44,7 @@ public class TestLog {
private File checkpointDir;
private File[] dataDirs;
private long transactionID;
+
@Before
public void setup() throws IOException {
transactionID = 0;
@@ -56,15 +56,20 @@ public class TestLog {
dataDirs[i] = Files.createTempDir();
Assert.assertTrue(dataDirs[i].isDirectory());
}
- log = new Log.Builder().setCheckpointInterval(1L).setMaxFileSize(
- MAX_FILE_SIZE).setQueueSize(CAPACITY).setCheckpointDir(
- checkpointDir).setLogDirs(dataDirs).setCheckpointOnClose(false)
- .setChannelName("testlog").build();
+ log = new Log.Builder().setCheckpointInterval(1L)
+ .setMaxFileSize(MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setCheckpointOnClose(false)
+ .setChannelName("testlog")
+ .build();
log.replay();
}
+
@After
- public void cleanup() throws Exception{
- if(log != null) {
+ public void cleanup() throws Exception {
+ if (log != null) {
log.close();
}
FileUtils.deleteQuietly(checkpointDir);
@@ -72,13 +77,14 @@ public class TestLog {
FileUtils.deleteQuietly(dataDirs[i]);
}
}
+
/**
* Test that we can put, commit and then get. Note that get is
* not transactional so the commit is not required.
*/
@Test
public void testPutGet()
- throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
FlumeEvent eventIn = TestUtils.newPersistableEvent();
long transactionID = ++this.transactionID;
FlumeEventPointer eventPointer = log.put(transactionID, eventIn);
@@ -89,9 +95,10 @@ public class TestLog {
Assert.assertEquals(eventIn.getHeaders(), eventOut.getHeaders());
Assert.assertArrayEquals(eventIn.getBody(), eventOut.getBody());
}
+
@Test
public void testRoll()
- throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
log.shutdownWorker();
Thread.sleep(1000);
for (int i = 0; i < 1000; i++) {
@@ -105,9 +112,9 @@ public class TestLog {
Assert.assertArrayEquals(eventIn.getBody(), eventOut.getBody());
}
int logCount = 0;
- for(File dataDir : dataDirs) {
- for(File logFile : dataDir.listFiles()) {
- if(logFile.getName().startsWith("log-")) {
+ for (File dataDir : dataDirs) {
+ for (File logFile : dataDir.listFiles()) {
+ if (logFile.getName().startsWith("log-")) {
logCount++;
}
}
@@ -115,26 +122,30 @@ public class TestLog {
// 93 (*2 for meta) files with TestLog.MAX_FILE_SIZE=1000
Assert.assertEquals(186, logCount);
}
+
/**
* After replay of the log, we should find the event because the put
* was committed
*/
@Test
public void testPutCommit()
- throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
FlumeEvent eventIn = TestUtils.newPersistableEvent();
long transactionID = ++this.transactionID;
FlumeEventPointer eventPointerIn = log.put(transactionID, eventIn);
log.commitPut(transactionID);
log.close();
- log = new Log.Builder().setCheckpointInterval(
- Long.MAX_VALUE).setMaxFileSize(
- FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE).setQueueSize(
- CAPACITY).setCheckpointDir(checkpointDir).setLogDirs(
- dataDirs).setChannelName("testlog").build();
+ log = new Log.Builder().setCheckpointInterval(Long.MAX_VALUE)
+ .setMaxFileSize(FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .build();
log.replay();
takeAndVerify(eventPointerIn, eventIn);
}
+
/**
* After replay of the log, we should not find the event because the
* put was rolled back
@@ -146,39 +157,44 @@ public class TestLog {
log.put(transactionID, eventIn);
log.rollback(transactionID); // rolled back so it should not be replayed
log.close();
- log = new Log.Builder().setCheckpointInterval(
- Long.MAX_VALUE).setMaxFileSize(
- FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE).setQueueSize(
- CAPACITY).setCheckpointDir(checkpointDir).setLogDirs(
- dataDirs).setChannelName("testlog").build();
+ log = new Log.Builder().setCheckpointInterval(Long.MAX_VALUE)
+ .setMaxFileSize(FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .build();
log.replay();
FlumeEventQueue queue = log.getFlumeEventQueue();
Assert.assertNull(queue.removeHead(transactionID));
}
+
@Test
public void testMinimumRequiredSpaceTooSmallOnStartup() throws IOException,
- InterruptedException {
+ InterruptedException {
log.close();
- log = new Log.Builder().setCheckpointInterval(
- Long.MAX_VALUE).setMaxFileSize(
- FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE).setQueueSize(
- CAPACITY).setCheckpointDir(checkpointDir).setLogDirs(
- dataDirs).setChannelName("testlog").
- setMinimumRequiredSpace(Long.MAX_VALUE).build();
+ log = new Log.Builder().setCheckpointInterval(Long.MAX_VALUE)
+ .setMaxFileSize(FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .setMinimumRequiredSpace(Long.MAX_VALUE)
+ .build();
try {
log.replay();
Assert.fail();
} catch (IOException e) {
- Assert.assertTrue(e.getMessage(), e.getMessage()
- .startsWith("Usable space exhausted"));
+ Assert.assertTrue(e.getMessage(),
+ e.getMessage().startsWith("Usable space exhausted"));
}
}
+
/**
* There is a race here in that someone could take up some space
*/
@Test
- public void testMinimumRequiredSpaceTooSmallForPut() throws IOException,
- InterruptedException {
+ public void testMinimumRequiredSpaceTooSmallForPut() throws IOException, InterruptedException {
try {
doTestMinimumRequiredSpaceTooSmallForPut();
} catch (IOException e) {
@@ -189,23 +205,26 @@ public class TestLog {
doTestMinimumRequiredSpaceTooSmallForPut();
}
}
+
public void doTestMinimumRequiredSpaceTooSmallForPut() throws IOException,
- InterruptedException {
+ InterruptedException {
long minimumRequiredSpace = checkpointDir.getUsableSpace() -
- (10L* 1024L * 1024L);
+ (10L * 1024L * 1024L);
log.close();
- log = new Log.Builder().setCheckpointInterval(
- Long.MAX_VALUE).setMaxFileSize(
- FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE).setQueueSize(
- CAPACITY).setCheckpointDir(checkpointDir).setLogDirs(
- dataDirs).setChannelName("testlog").
- setMinimumRequiredSpace(minimumRequiredSpace)
- .setUsableSpaceRefreshInterval(1L).build();
+ log = new Log.Builder().setCheckpointInterval(Long.MAX_VALUE)
+ .setMaxFileSize(FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .setMinimumRequiredSpace(minimumRequiredSpace)
+ .setUsableSpaceRefreshInterval(1L)
+ .build();
log.replay();
File filler = new File(checkpointDir, "filler");
byte[] buffer = new byte[64 * 1024];
FileOutputStream out = new FileOutputStream(filler);
- while(checkpointDir.getUsableSpace() > minimumRequiredSpace) {
+ while (checkpointDir.getUsableSpace() > minimumRequiredSpace) {
out.write(buffer);
}
out.close();
@@ -215,10 +234,11 @@ public class TestLog {
log.put(transactionID, eventIn);
Assert.fail();
} catch (IOException e) {
- Assert.assertTrue(e.getMessage(), e.getMessage()
- .startsWith("Usable space exhausted"));
+ Assert.assertTrue(e.getMessage(),
+ e.getMessage().startsWith("Usable space exhausted"));
}
}
+
/**
* After replay of the log, we should not find the event because the take
* was committed
@@ -233,11 +253,13 @@ public class TestLog {
log.take(takeTransactionID, eventPointer);
log.commitTake(takeTransactionID);
log.close();
- new Log.Builder().setCheckpointInterval(
- Long.MAX_VALUE).setMaxFileSize(
- FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE).setQueueSize(
- 1).setCheckpointDir(checkpointDir).setLogDirs(dataDirs)
- .setChannelName("testlog").build();
+ new Log.Builder().setCheckpointInterval(Long.MAX_VALUE)
+ .setMaxFileSize(FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE)
+ .setQueueSize(1)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .build();
log.replay();
FlumeEventQueue queue = log.getFlumeEventQueue();
Assert.assertNull(queue.removeHead(0));
@@ -249,16 +271,18 @@ public class TestLog {
*/
@Test
public void testPutTakeRollbackLogReplayV1()
- throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
doPutTakeRollback(true);
}
+
@Test
public void testPutTakeRollbackLogReplayV2()
- throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
doPutTakeRollback(false);
}
+
public void doPutTakeRollback(boolean useLogReplayV1)
- throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
FlumeEvent eventIn = TestUtils.newPersistableEvent();
long putTransactionID = ++transactionID;
FlumeEventPointer eventPointerIn = log.put(putTransactionID, eventIn);
@@ -267,11 +291,14 @@ public class TestLog {
log.take(takeTransactionID, eventPointerIn);
log.rollback(takeTransactionID);
log.close();
- new Log.Builder().setCheckpointInterval(
- Long.MAX_VALUE).setMaxFileSize(
- FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE).setQueueSize(
- 1).setCheckpointDir(checkpointDir).setLogDirs(dataDirs)
- .setChannelName("testlog").setUseLogReplayV1(useLogReplayV1).build();
+ new Log.Builder().setCheckpointInterval(Long.MAX_VALUE)
+ .setMaxFileSize(FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE)
+ .setQueueSize(1)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .setUseLogReplayV1(useLogReplayV1)
+ .build();
log.replay();
takeAndVerify(eventPointerIn, eventIn);
}
@@ -281,11 +308,13 @@ public class TestLog {
long putTransactionID = ++transactionID;
log.commitPut(putTransactionID);
log.close();
- new Log.Builder().setCheckpointInterval(
- Long.MAX_VALUE).setMaxFileSize(
- FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE).setQueueSize(
- 1).setCheckpointDir(checkpointDir).setLogDirs(dataDirs)
- .setChannelName("testlog").build();
+ new Log.Builder().setCheckpointInterval(Long.MAX_VALUE)
+ .setMaxFileSize(FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE)
+ .setQueueSize(1)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .build();
log.replay();
FlumeEventQueue queue = log.getFlumeEventQueue();
FlumeEventPointer eventPointerOut = queue.removeHead(0);
@@ -297,11 +326,13 @@ public class TestLog {
long putTransactionID = ++transactionID;
log.commitTake(putTransactionID);
log.close();
- new Log.Builder().setCheckpointInterval(
- Long.MAX_VALUE).setMaxFileSize(
- FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE).setQueueSize(
- 1).setCheckpointDir(checkpointDir).setLogDirs(dataDirs)
- .setChannelName("testlog").build();
+ new Log.Builder().setCheckpointInterval(Long.MAX_VALUE)
+ .setMaxFileSize(FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE)
+ .setQueueSize(1)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .build();
log.replay();
FlumeEventQueue queue = log.getFlumeEventQueue();
FlumeEventPointer eventPointerOut = queue.removeHead(0);
@@ -313,11 +344,13 @@ public class TestLog {
long putTransactionID = ++transactionID;
log.rollback(putTransactionID);
log.close();
- new Log.Builder().setCheckpointInterval(
- Long.MAX_VALUE).setMaxFileSize(
- FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE).setQueueSize(
- 1).setCheckpointDir(checkpointDir).setLogDirs(dataDirs)
- .setChannelName("testlog").build();
+ new Log.Builder().setCheckpointInterval(Long.MAX_VALUE)
+ .setMaxFileSize(FileChannelConfiguration.DEFAULT_MAX_FILE_SIZE)
+ .setQueueSize(1)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .build();
log.replay();
FlumeEventQueue queue = log.getFlumeEventQueue();
FlumeEventPointer eventPointerOut = queue.removeHead(0);
@@ -337,7 +370,7 @@ public class TestLog {
File logGzip = new File(logDir, Log.PREFIX + i + ".gz");
Assert.assertTrue(metaDataFile.isFile() || metaDataFile.createNewFile());
Assert.assertTrue(metaDataTempFile.isFile() ||
- metaDataTempFile.createNewFile());
+ metaDataTempFile.createNewFile());
Assert.assertTrue(log.isFile() || logGzip.createNewFile());
}
List<File> actual = LogUtils.getLogs(logDir);
@@ -345,31 +378,38 @@ public class TestLog {
LogUtils.sort(expected);
Assert.assertEquals(expected, actual);
}
+
@Test
public void testReplayFailsWithAllEmptyLogMetaDataNormalReplay()
throws IOException, InterruptedException {
doTestReplayFailsWithAllEmptyLogMetaData(false);
}
+
@Test
public void testReplayFailsWithAllEmptyLogMetaDataFastReplay()
throws IOException, InterruptedException {
doTestReplayFailsWithAllEmptyLogMetaData(true);
}
+
public void doTestReplayFailsWithAllEmptyLogMetaData(boolean useFastReplay)
throws IOException, InterruptedException {
// setup log with correct fast replay parameter
log.close();
- log = new Log.Builder().setCheckpointInterval(1L).setMaxFileSize(
- MAX_FILE_SIZE).setQueueSize(CAPACITY).setCheckpointDir(
- checkpointDir).setLogDirs(dataDirs)
- .setChannelName("testlog").setUseFastReplay(useFastReplay).build();
+ log = new Log.Builder().setCheckpointInterval(1L)
+ .setMaxFileSize(MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .setUseFastReplay(useFastReplay)
+ .build();
log.replay();
FlumeEvent eventIn = TestUtils.newPersistableEvent();
long transactionID = ++this.transactionID;
log.put(transactionID, eventIn);
log.commitPut(transactionID);
log.close();
- if(useFastReplay) {
+ if (useFastReplay) {
FileUtils.deleteQuietly(checkpointDir);
Assert.assertTrue(checkpointDir.mkdir());
}
@@ -378,41 +418,50 @@ public class TestLog {
logFiles.addAll(LogUtils.getLogs(dataDirs[i]));
}
Assert.assertTrue(logFiles.size() > 0);
- for(File logFile : logFiles) {
+ for (File logFile : logFiles) {
File logFileMeta = Serialization.getMetaDataFile(logFile);
Assert.assertTrue(logFileMeta.delete());
Assert.assertTrue(logFileMeta.createNewFile());
}
- log = new Log.Builder().setCheckpointInterval(1L).setMaxFileSize(
- MAX_FILE_SIZE).setQueueSize(CAPACITY).setCheckpointDir(
- checkpointDir).setLogDirs(dataDirs)
- .setChannelName("testlog").setUseFastReplay(useFastReplay).build();
+ log = new Log.Builder().setCheckpointInterval(1L)
+ .setMaxFileSize(MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .setUseFastReplay(useFastReplay)
+ .build();
try {
log.replay();
Assert.fail();
- } catch(IllegalStateException expected) {
+ } catch (IllegalStateException expected) {
String msg = expected.getMessage();
Assert.assertNotNull(msg);
Assert.assertTrue(msg, msg.contains(".meta is empty, but log"));
}
}
+
@Test
public void testReplaySucceedsWithUnusedEmptyLogMetaDataNormalReplay()
- throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
FlumeEvent eventIn = TestUtils.newPersistableEvent();
long transactionID = ++this.transactionID;
FlumeEventPointer eventPointer = log.put(transactionID, eventIn);
log.commitPut(transactionID); // this is not required since
log.close();
- log = new Log.Builder().setCheckpointInterval(1L).setMaxFileSize(
- MAX_FILE_SIZE).setQueueSize(CAPACITY).setCheckpointDir(
- checkpointDir).setLogDirs(dataDirs)
- .setChannelName("testlog").build();
+ log = new Log.Builder().setCheckpointInterval(1L)
+ .setMaxFileSize(MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .build();
doTestReplaySucceedsWithUnusedEmptyLogMetaData(eventIn, eventPointer);
}
+
@Test
public void testReplaySucceedsWithUnusedEmptyLogMetaDataFastReplay()
- throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
FlumeEvent eventIn = TestUtils.newPersistableEvent();
long transactionID = ++this.transactionID;
FlumeEventPointer eventPointer = log.put(transactionID, eventIn);
@@ -421,18 +470,23 @@ public class TestLog {
checkpointDir = Files.createTempDir();
FileUtils.forceDeleteOnExit(checkpointDir);
Assert.assertTrue(checkpointDir.isDirectory());
- log = new Log.Builder().setCheckpointInterval(1L).setMaxFileSize(
- MAX_FILE_SIZE).setQueueSize(CAPACITY).setCheckpointDir(
- checkpointDir).setLogDirs(dataDirs)
- .setChannelName("testlog").setUseFastReplay(true).build();
+ log = new Log.Builder().setCheckpointInterval(1L)
+ .setMaxFileSize(MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setChannelName("testlog")
+ .setUseFastReplay(true)
+ .build();
doTestReplaySucceedsWithUnusedEmptyLogMetaData(eventIn, eventPointer);
}
+
public void doTestReplaySucceedsWithUnusedEmptyLogMetaData(FlumeEvent eventIn,
- FlumeEventPointer eventPointer) throws IOException,
- InterruptedException, NoopRecordException, CorruptEventException {
+ FlumeEventPointer eventPointer)
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
for (int i = 0; i < dataDirs.length; i++) {
- for(File logFile : LogUtils.getLogs(dataDirs[i])) {
- if(logFile.length() == 0L) {
+ for (File logFile : LogUtils.getLogs(dataDirs[i])) {
+ if (logFile.length() == 0L) {
File logFileMeta = Serialization.getMetaDataFile(logFile);
Assert.assertTrue(logFileMeta.delete());
Assert.assertTrue(logFileMeta.createNewFile());
@@ -445,16 +499,15 @@ public class TestLog {
Assert.assertEquals(eventIn.getHeaders(), eventOut.getHeaders());
Assert.assertArrayEquals(eventIn.getBody(), eventOut.getBody());
}
+
@Test
public void testCachedFSUsableSpace() throws Exception {
File fs = mock(File.class);
when(fs.getUsableSpace()).thenReturn(Long.MAX_VALUE);
- LogFile.CachedFSUsableSpace cachedFS =
- new LogFile.CachedFSUsableSpace(fs, 1000L);
+ LogFile.CachedFSUsableSpace cachedFS = new LogFile.CachedFSUsableSpace(fs, 1000L);
Assert.assertEquals(cachedFS.getUsableSpace(), Long.MAX_VALUE);
cachedFS.decrement(Integer.MAX_VALUE);
- Assert.assertEquals(cachedFS.getUsableSpace(),
- Long.MAX_VALUE - Integer.MAX_VALUE);
+ Assert.assertEquals(cachedFS.getUsableSpace(), Long.MAX_VALUE - Integer.MAX_VALUE);
try {
cachedFS.decrement(-1);
Assert.fail();
@@ -463,20 +516,22 @@ public class TestLog {
}
when(fs.getUsableSpace()).thenReturn(Long.MAX_VALUE - 1L);
Thread.sleep(1100);
- Assert.assertEquals(cachedFS.getUsableSpace(),
- Long.MAX_VALUE - 1L);
+ Assert.assertEquals(cachedFS.getUsableSpace(), Long.MAX_VALUE - 1L);
}
@Test
public void testCheckpointOnClose() throws Exception {
log.close();
- log = new Log.Builder().setCheckpointInterval(1L).setMaxFileSize(
- MAX_FILE_SIZE).setQueueSize(CAPACITY).setCheckpointDir(
- checkpointDir).setLogDirs(dataDirs).setCheckpointOnClose(true)
- .setChannelName("testLog").build();
+ log = new Log.Builder().setCheckpointInterval(1L)
+ .setMaxFileSize(MAX_FILE_SIZE)
+ .setQueueSize(CAPACITY)
+ .setCheckpointDir(checkpointDir)
+ .setLogDirs(dataDirs)
+ .setCheckpointOnClose(true)
+ .setChannelName("testLog")
+ .build();
log.replay();
-
// 1 Write One Event
FlumeEvent eventIn = TestUtils.newPersistableEvent();
log.put(transactionID, eventIn);
@@ -484,20 +539,19 @@ public class TestLog {
// 2 Check state of checkpoint before close
File checkPointMetaFile =
- FileUtils.listFiles(checkpointDir,new String[]{"meta"},false).iterator().next();
- long before = FileUtils.checksumCRC32( checkPointMetaFile );
+ FileUtils.listFiles(checkpointDir, new String[] { "meta" }, false).iterator().next();
+ long before = FileUtils.checksumCRC32(checkPointMetaFile);
// 3 Close Log
log.close();
// 4 Verify that checkpoint was modified on close
- long after = FileUtils.checksumCRC32( checkPointMetaFile );
- Assert.assertFalse( before == after );
+ long after = FileUtils.checksumCRC32(checkPointMetaFile);
+ Assert.assertFalse(before == after);
}
- private void takeAndVerify(FlumeEventPointer eventPointerIn,
- FlumeEvent eventIn)
- throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
+ private void takeAndVerify(FlumeEventPointer eventPointerIn, FlumeEvent eventIn)
+ throws IOException, InterruptedException, NoopRecordException, CorruptEventException {
FlumeEventQueue queue = log.getFlumeEventQueue();
FlumeEventPointer eventPointerOut = queue.removeHead(0);
Assert.assertNotNull(eventPointerOut);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLogFile.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLogFile.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLogFile.java
index 976a112..d945c7f 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLogFile.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestLogFile.java
@@ -18,6 +18,16 @@
*/
package org.apache.flume.channel.file;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Maps;
+import com.google.common.io.Files;
+import org.apache.commons.io.FileUtils;
+import org.apache.flume.channel.file.proto.ProtosFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -28,33 +38,21 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
-import org.apache.commons.io.FileUtils;
-import org.apache.flume.channel.file.proto.ProtosFactory;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.Maps;
-import com.google.common.io.Files;
-
public class TestLogFile {
private int fileID;
private long transactionID;
private LogFile.Writer logFileWriter;
private File dataDir;
private File dataFile;
+
@Before
public void setup() throws IOException {
fileID = 1;
@@ -65,28 +63,30 @@ public class TestLogFile {
logFileWriter = LogFileFactory.getWriter(dataFile, fileID,
Integer.MAX_VALUE, null, null, null, Long.MAX_VALUE, true, 0);
}
+
@After
public void cleanup() throws IOException {
try {
- if(logFileWriter != null) {
+ if (logFileWriter != null) {
logFileWriter.close();
}
} finally {
FileUtils.deleteQuietly(dataDir);
}
}
+
@Test
public void testWriterRefusesToOverwriteFile() throws IOException {
Assert.assertTrue(dataFile.isFile() || dataFile.createNewFile());
try {
LogFileFactory.getWriter(dataFile, fileID, Integer.MAX_VALUE, null, null,
- null, Long.MAX_VALUE, true, 0);
+ null, Long.MAX_VALUE, true, 0);
Assert.fail();
} catch (IllegalStateException e) {
- Assert.assertEquals("File already exists " + dataFile.getAbsolutePath(),
- e.getMessage());
+ Assert.assertEquals("File already exists " + dataFile.getAbsolutePath(), e.getMessage());
}
}
+
@Test
public void testWriterFailsWithDirectory() throws IOException {
FileUtils.deleteQuietly(dataFile);
@@ -94,30 +94,29 @@ public class TestLogFile {
Assert.assertTrue(dataFile.mkdirs());
try {
LogFileFactory.getWriter(dataFile, fileID, Integer.MAX_VALUE, null, null,
- null, Long.MAX_VALUE, true, 0);
+ null, Long.MAX_VALUE, true, 0);
Assert.fail();
} catch (IllegalStateException e) {
- Assert.assertEquals("File already exists " + dataFile.getAbsolutePath(),
- e.getMessage());
+ Assert.assertEquals("File already exists " + dataFile.getAbsolutePath(), e.getMessage());
}
}
+
@Test
public void testPutGet() throws InterruptedException, IOException {
final List<Throwable> errors =
Collections.synchronizedList(new ArrayList<Throwable>());
ExecutorService executorService = Executors.newFixedThreadPool(10);
CompletionService<Void> completionService = new ExecutorCompletionService
- <Void>(executorService);
- final LogFile.RandomReader logFileReader =
- LogFileFactory.getRandomReader(dataFile, null, true);
+ <Void>(executorService);
+ final LogFile.RandomReader logFileReader = LogFileFactory.getRandomReader(dataFile, null, true);
for (int i = 0; i < 1000; i++) {
// first try and throw failures
synchronized (errors) {
- for(Throwable throwable : errors) {
+ for (Throwable throwable : errors) {
Throwables.propagateIfInstanceOf(throwable, AssertionError.class);
}
// then throw errors
- for(Throwable throwable : errors) {
+ for (Throwable throwable : errors) {
Throwables.propagate(throwable);
}
}
@@ -134,7 +133,7 @@ public class TestLogFile {
FlumeEvent eventOut = logFileReader.get(offset);
Assert.assertEquals(eventIn.getHeaders(), eventOut.getHeaders());
Assert.assertTrue(Arrays.equals(eventIn.getBody(), eventOut.getBody()));
- } catch(Throwable throwable) {
+ } catch (Throwable throwable) {
synchronized (errors) {
errors.add(throwable);
}
@@ -143,26 +142,26 @@ public class TestLogFile {
}, null);
}
- for(int i = 0; i < 1000; i++) {
+ for (int i = 0; i < 1000; i++) {
completionService.take();
}
// first try and throw failures
- for(Throwable throwable : errors) {
+ for (Throwable throwable : errors) {
Throwables.propagateIfInstanceOf(throwable, AssertionError.class);
}
// then throw errors
- for(Throwable throwable : errors) {
+ for (Throwable throwable : errors) {
Throwables.propagate(throwable);
}
}
+
@Test
public void testReader() throws InterruptedException, IOException,
- CorruptEventException {
+ CorruptEventException {
Map<Integer, Put> puts = Maps.newHashMap();
for (int i = 0; i < 1000; i++) {
FlumeEvent eventIn = TestUtils.newPersistableEvent();
- Put put = new Put(++transactionID, WriteOrderOracle.next(),
- eventIn);
+ Put put = new Put(++transactionID, WriteOrderOracle.next(), eventIn);
ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
FlumeEventPointer ptr = logFileWriter.put(bytes);
puts.put(ptr.getOffset(), put);
@@ -170,14 +169,14 @@ public class TestLogFile {
LogFile.SequentialReader reader =
LogFileFactory.getSequentialReader(dataFile, null, true);
LogRecord entry;
- while((entry = reader.next()) != null) {
+ while ((entry = reader.next()) != null) {
Integer offset = entry.getOffset();
TransactionEventRecord record = entry.getEvent();
Put put = puts.get(offset);
FlumeEvent eventIn = put.getEvent();
Assert.assertEquals(put.getTransactionID(), record.getTransactionID());
Assert.assertTrue(record instanceof Put);
- FlumeEvent eventOut = ((Put)record).getEvent();
+ FlumeEvent eventOut = ((Put) record).getEvent();
Assert.assertEquals(eventIn.getHeaders(), eventOut.getHeaders());
Assert.assertTrue(Arrays.equals(eventIn.getBody(), eventOut.getBody()));
}
@@ -185,12 +184,12 @@ public class TestLogFile {
@Test
public void testReaderOldMetaFile() throws InterruptedException,
- IOException, CorruptEventException {
+ IOException, CorruptEventException {
Map<Integer, Put> puts = Maps.newHashMap();
for (int i = 0; i < 1000; i++) {
FlumeEvent eventIn = TestUtils.newPersistableEvent();
Put put = new Put(++transactionID, WriteOrderOracle.next(),
- eventIn);
+ eventIn);
ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
FlumeEventPointer ptr = logFileWriter.put(bytes);
puts.put(ptr.getOffset(), put);
@@ -202,7 +201,7 @@ public class TestLogFile {
Assert.fail("Renaming to meta.old failed");
}
LogFile.SequentialReader reader =
- LogFileFactory.getSequentialReader(dataFile, null, true);
+ LogFileFactory.getSequentialReader(dataFile, null, true);
Assert.assertTrue(metadataFile.exists());
Assert.assertFalse(oldMetadataFile.exists());
LogRecord entry;
@@ -219,14 +218,14 @@ public class TestLogFile {
}
}
- @Test
- public void testReaderTempMetaFile() throws InterruptedException,
- IOException, CorruptEventException {
+ @Test
+ public void testReaderTempMetaFile()
+ throws InterruptedException, IOException, CorruptEventException {
Map<Integer, Put> puts = Maps.newHashMap();
for (int i = 0; i < 1000; i++) {
FlumeEvent eventIn = TestUtils.newPersistableEvent();
Put put = new Put(++transactionID, WriteOrderOracle.next(),
- eventIn);
+ eventIn);
ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
FlumeEventPointer ptr = logFileWriter.put(bytes);
puts.put(ptr.getOffset(), put);
@@ -240,7 +239,7 @@ public class TestLogFile {
Assert.fail("Renaming to meta.temp failed");
}
LogFile.SequentialReader reader =
- LogFileFactory.getSequentialReader(dataFile, null, true);
+ LogFileFactory.getSequentialReader(dataFile, null, true);
Assert.assertTrue(metadataFile.exists());
Assert.assertFalse(tempMetadataFile.exists());
Assert.assertFalse(oldMetadataFile.exists());
@@ -257,9 +256,10 @@ public class TestLogFile {
Assert.assertTrue(Arrays.equals(eventIn.getBody(), eventOut.getBody()));
}
}
+
@Test
public void testWriteDelimitedTo() throws IOException {
- if(dataFile.isFile()) {
+ if (dataFile.isFile()) {
Assert.assertTrue(dataFile.delete());
}
Assert.assertTrue(dataFile.createNewFile());
@@ -270,25 +270,24 @@ public class TestLogFile {
metaDataBuilder.setCheckpointPosition(3);
metaDataBuilder.setCheckpointWriteOrderID(4);
LogFileV3.writeDelimitedTo(metaDataBuilder.build(), dataFile);
- ProtosFactory.LogFileMetaData metaData = ProtosFactory.LogFileMetaData.
- parseDelimitedFrom(new FileInputStream(dataFile));
+ ProtosFactory.LogFileMetaData metaData =
+ ProtosFactory.LogFileMetaData.parseDelimitedFrom(new FileInputStream(dataFile));
Assert.assertEquals(1, metaData.getVersion());
Assert.assertEquals(2, metaData.getLogFileID());
Assert.assertEquals(3, metaData.getCheckpointPosition());
Assert.assertEquals(4, metaData.getCheckpointWriteOrderID());
}
- @Test (expected = CorruptEventException.class)
+ @Test(expected = CorruptEventException.class)
public void testPutGetCorruptEvent() throws Exception {
final LogFile.RandomReader logFileReader =
- LogFileFactory.getRandomReader(dataFile, null, true);
+ LogFileFactory.getRandomReader(dataFile, null, true);
final FlumeEvent eventIn = TestUtils.newPersistableEvent(2500);
- final Put put = new Put(++transactionID, WriteOrderOracle.next(),
- eventIn);
+ final Put put = new Put(++transactionID, WriteOrderOracle.next(), eventIn);
ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
FlumeEventPointer ptr = logFileWriter.put(bytes);
- logFileWriter.commit(TransactionEventRecord.toByteBuffer(new Commit
- (transactionID, WriteOrderOracle.next())));
+ logFileWriter.commit(TransactionEventRecord.toByteBuffer(
+ new Commit(transactionID, WriteOrderOracle.next())));
logFileWriter.sync();
final int offset = ptr.getOffset();
RandomAccessFile writer = new RandomAccessFile(dataFile, "rw");
@@ -300,24 +299,22 @@ public class TestLogFile {
// Should have thrown an exception by now.
Assert.fail();
-
}
- @Test (expected = NoopRecordException.class)
+ @Test(expected = NoopRecordException.class)
public void testPutGetNoopEvent() throws Exception {
final LogFile.RandomReader logFileReader =
- LogFileFactory.getRandomReader(dataFile, null, true);
+ LogFileFactory.getRandomReader(dataFile, null, true);
final FlumeEvent eventIn = TestUtils.newPersistableEvent(2500);
- final Put put = new Put(++transactionID, WriteOrderOracle.next(),
- eventIn);
+ final Put put = new Put(++transactionID, WriteOrderOracle.next(), eventIn);
ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
FlumeEventPointer ptr = logFileWriter.put(bytes);
- logFileWriter.commit(TransactionEventRecord.toByteBuffer(new Commit
- (transactionID, WriteOrderOracle.next())));
+ logFileWriter.commit(TransactionEventRecord.toByteBuffer(
+ new Commit(transactionID, WriteOrderOracle.next())));
logFileWriter.sync();
final int offset = ptr.getOffset();
- LogFile.OperationRecordUpdater updater = new LogFile
- .OperationRecordUpdater(dataFile);
+ LogFile.OperationRecordUpdater updater =
+ new LogFile.OperationRecordUpdater(dataFile);
updater.markRecordAsNoop(offset);
logFileReader.get(offset);
@@ -330,40 +327,38 @@ public class TestLogFile {
File tempDir = Files.createTempDir();
File temp = new File(tempDir, "temp");
final RandomAccessFile tempFile = new RandomAccessFile(temp, "rw");
- for(int i = 0; i < 5000; i++) {
+ for (int i = 0; i < 5000; i++) {
tempFile.write(LogFile.OP_RECORD);
}
tempFile.seek(0);
LogFile.OperationRecordUpdater recordUpdater = new LogFile
- .OperationRecordUpdater(temp);
+ .OperationRecordUpdater(temp);
//Convert every 10th byte into a noop byte
- for(int i = 0; i < 5000; i+=10) {
+ for (int i = 0; i < 5000; i += 10) {
recordUpdater.markRecordAsNoop(i);
}
recordUpdater.close();
tempFile.seek(0);
// Verify every 10th byte is actually a NOOP
- for(int i = 0; i < 5000; i+=10) {
+ for (int i = 0; i < 5000; i += 10) {
tempFile.seek(i);
Assert.assertEquals(LogFile.OP_NOOP, tempFile.readByte());
}
-
}
@Test
- public void testOpRecordUpdaterWithFlumeEvents() throws Exception{
+ public void testOpRecordUpdaterWithFlumeEvents() throws Exception {
final FlumeEvent eventIn = TestUtils.newPersistableEvent(2500);
- final Put put = new Put(++transactionID, WriteOrderOracle.next(),
- eventIn);
+ final Put put = new Put(++transactionID, WriteOrderOracle.next(), eventIn);
ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
FlumeEventPointer ptr = logFileWriter.put(bytes);
- logFileWriter.commit(TransactionEventRecord.toByteBuffer(new Commit
- (transactionID, WriteOrderOracle.next())));
+ logFileWriter.commit(TransactionEventRecord.toByteBuffer(
+ new Commit(transactionID, WriteOrderOracle.next())));
logFileWriter.sync();
final int offset = ptr.getOffset();
- LogFile.OperationRecordUpdater updater = new LogFile
- .OperationRecordUpdater(dataFile);
+ LogFile.OperationRecordUpdater updater =
+ new LogFile.OperationRecordUpdater(dataFile);
updater.markRecordAsNoop(offset);
RandomAccessFile fileReader = new RandomAccessFile(dataFile, "rw");
Assert.assertEquals(LogFile.OP_NOOP, fileReader.readByte());
@@ -375,7 +370,7 @@ public class TestLogFile {
final CyclicBarrier barrier = new CyclicBarrier(20);
ExecutorService executorService = Executors.newFixedThreadPool(20);
ExecutorCompletionService<Void> completionService = new
- ExecutorCompletionService<Void>(executorService);
+ ExecutorCompletionService<Void>(executorService);
final LogFile.Writer writer = logFileWriter;
final AtomicLong txnId = new AtomicLong(++transactionID);
for (int i = 0; i < 20; i++) {
@@ -384,11 +379,11 @@ public class TestLogFile {
public Void call() {
try {
Put put = new Put(txnId.incrementAndGet(),
- WriteOrderOracle.next(), eventIn);
+ WriteOrderOracle.next(), eventIn);
ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
writer.put(bytes);
writer.commit(TransactionEventRecord.toByteBuffer(
- new Commit(txnId.get(), WriteOrderOracle.next())));
+ new Commit(txnId.get(), WriteOrderOracle.next())));
barrier.await();
writer.sync();
} catch (Exception ex) {
@@ -399,17 +394,15 @@ public class TestLogFile {
});
}
- for(int i = 0; i < 20; i++) {
+ for (int i = 0; i < 20; i++) {
completionService.take().get();
}
- //At least 250*20, but can be higher due to serialization overhead
+ // At least 250*20, but can be higher due to serialization overhead
Assert.assertTrue(logFileWriter.position() >= 5000);
Assert.assertEquals(1, writer.getSyncCount());
- Assert.assertTrue(logFileWriter.getLastCommitPosition() ==
- logFileWriter.getLastSyncPosition());
+ Assert.assertTrue(logFileWriter.getLastCommitPosition() == logFileWriter.getLastSyncPosition());
executorService.shutdown();
-
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV2.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV2.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV2.java
index 2356d90..1f07e1f 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV2.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV2.java
@@ -18,7 +18,8 @@
*/
package org.apache.flume.channel.file;
-import static org.mockito.Mockito.*;
+import junit.framework.Assert;
+import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -30,9 +31,8 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.HashMap;
-import junit.framework.Assert;
-
-import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
@SuppressWarnings("deprecation")
public class TestTransactionEventRecordV2 {
@@ -127,7 +127,7 @@ public class TestTransactionEventRecordV2 {
try {
TransactionEventRecord.fromDataInputV2(toDataInput(in));
Assert.fail();
- } catch(NullPointerException e) {
+ } catch (NullPointerException e) {
Assert.assertEquals("Unknown action ffff8000", e.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV3.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV3.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV3.java
index eb0ce04..512d290 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV3.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestTransactionEventRecordV3.java
@@ -18,7 +18,8 @@
*/
package org.apache.flume.channel.file;
-import static org.mockito.Mockito.*;
+import junit.framework.Assert;
+import org.junit.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -26,9 +27,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-import junit.framework.Assert;
-
-import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class TestTransactionEventRecordV3 {
@@ -52,6 +52,7 @@ public class TestTransactionEventRecordV3 {
Assert.assertEquals(TransactionEventRecord.Type.COMMIT.get(),
commit.getRecordType());
}
+
@Test
public void testPutSerialization() throws IOException, CorruptEventException {
Map<String, String> headers = new HashMap<String, String>();
@@ -69,9 +70,9 @@ public class TestTransactionEventRecordV3 {
Assert.assertEquals(headers, out.getEvent().getHeaders());
Assert.assertTrue(Arrays.equals(in.getEvent().getBody(), out.getEvent().getBody()));
}
+
@Test
- public void testPutSerializationNullHeader() throws IOException,
- CorruptEventException {
+ public void testPutSerializationNullHeader() throws IOException, CorruptEventException {
Put in = new Put(System.currentTimeMillis(),
WriteOrderOracle.next(),
new FlumeEvent(null, new byte[0]));
@@ -84,11 +85,10 @@ public class TestTransactionEventRecordV3 {
Assert.assertNotNull(out.getEvent().getHeaders());
Assert.assertTrue(Arrays.equals(in.getEvent().getBody(), out.getEvent().getBody()));
}
+
@Test
- public void testTakeSerialization() throws IOException,
- CorruptEventException {
- Take in = new Take(System.currentTimeMillis(),
- WriteOrderOracle.next(), 10, 20);
+ public void testTakeSerialization() throws IOException, CorruptEventException {
+ Take in = new Take(System.currentTimeMillis(), WriteOrderOracle.next(), 10, 20);
Take out = (Take)TransactionEventRecord.fromByteArray(toByteArray(in));
Assert.assertEquals(in.getClass(), out.getClass());
Assert.assertEquals(in.getRecordType(), out.getRecordType());
@@ -99,10 +99,8 @@ public class TestTransactionEventRecordV3 {
}
@Test
- public void testRollbackSerialization() throws IOException,
- CorruptEventException {
- Rollback in = new Rollback(System.currentTimeMillis(),
- WriteOrderOracle.next());
+ public void testRollbackSerialization() throws IOException, CorruptEventException {
+ Rollback in = new Rollback(System.currentTimeMillis(), WriteOrderOracle.next());
Rollback out = (Rollback)TransactionEventRecord.fromByteArray(toByteArray(in));
Assert.assertEquals(in.getClass(), out.getClass());
Assert.assertEquals(in.getRecordType(), out.getRecordType());
@@ -111,10 +109,8 @@ public class TestTransactionEventRecordV3 {
}
@Test
- public void testCommitSerialization() throws IOException,
- CorruptEventException {
- Commit in = new Commit(System.currentTimeMillis(),
- WriteOrderOracle.next());
+ public void testCommitSerialization() throws IOException, CorruptEventException {
+ Commit in = new Commit(System.currentTimeMillis(), WriteOrderOracle.next());
Commit out = (Commit)TransactionEventRecord.fromByteArray(toByteArray(in));
Assert.assertEquals(in.getClass(), out.getClass());
Assert.assertEquals(in.getRecordType(), out.getRecordType());
@@ -129,7 +125,7 @@ public class TestTransactionEventRecordV3 {
try {
TransactionEventRecord.fromByteArray(toByteArray(in));
Assert.fail();
- } catch(NullPointerException e) {
+ } catch (NullPointerException e) {
Assert.assertEquals("Unknown action ffff8000", e.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestUtils.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestUtils.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestUtils.java
index 61f38d2..0ec1831 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestUtils.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/TestUtils.java
@@ -18,7 +18,21 @@
*/
package org.apache.flume.channel.file;
-import static org.fest.reflect.core.Reflection.*;
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import com.google.common.io.ByteStreams;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+import org.apache.flume.Channel;
+import org.apache.flume.ChannelException;
+import org.apache.flume.Context;
+import org.apache.flume.Event;
+import org.apache.flume.Transaction;
+import org.apache.flume.conf.Configurables;
+import org.apache.flume.event.EventBuilder;
+import org.junit.Assert;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -36,22 +50,8 @@ import java.util.Set;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
-import org.apache.flume.Channel;
-import org.apache.flume.ChannelException;
-import org.apache.flume.Context;
-import org.apache.flume.Event;
-import org.apache.flume.Transaction;
-import org.apache.flume.conf.Configurables;
-import org.apache.flume.event.EventBuilder;
-import org.junit.Assert;
-
-import com.google.common.base.Charsets;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.common.io.ByteStreams;
-import com.google.common.io.Files;
-import com.google.common.io.Resources;
+import static org.fest.reflect.core.Reflection.field;
+import static org.fest.reflect.core.Reflection.method;
public class TestUtils {
@@ -119,7 +119,7 @@ public class TestUtils {
public static List<File> getAllLogs(File[] dataDirs) {
List<File> result = Lists.newArrayList();
- for(File dataDir : dataDirs) {
+ for (File dataDir : dataDirs) {
result.addAll(LogUtils.getLogs(dataDir));
}
return result;
@@ -139,24 +139,22 @@ public class TestUtils {
.invoke(true));
}
- public static Set<String> takeEvents(Channel channel, int batchSize)
- throws Exception {
+ public static Set<String> takeEvents(Channel channel, int batchSize) throws Exception {
return takeEvents(channel, batchSize, false);
}
- public static Set<String> takeEvents(Channel channel,
- int batchSize, boolean checkForCorruption) throws Exception {
+ public static Set<String> takeEvents(Channel channel, int batchSize, boolean checkForCorruption)
+ throws Exception {
return takeEvents(channel, batchSize, Integer.MAX_VALUE, checkForCorruption);
}
- public static Set<String> takeEvents(Channel channel,
- int batchSize, int numEvents) throws Exception {
+ public static Set<String> takeEvents(Channel channel, int batchSize, int numEvents)
+ throws Exception {
return takeEvents(channel, batchSize, numEvents, false);
}
- public static Set<String> takeEvents(Channel channel,
- int batchSize, int numEvents, boolean checkForCorruption) throws
- Exception {
+ public static Set<String> takeEvents(Channel channel, int batchSize, int numEvents,
+ boolean checkForCorruption) throws Exception {
Set<String> result = Sets.newHashSet();
for (int i = 0; i < numEvents; i += batchSize) {
Transaction transaction = channel.getTransaction();
@@ -169,16 +167,15 @@ public class TestUtils {
} catch (ChannelException ex) {
Throwable th = ex;
String msg;
- if(checkForCorruption) {
+ if (checkForCorruption) {
msg = "Corrupt event found. Please run File Channel";
th = ex.getCause();
} else {
msg = "Take list for FileBackedTransaction, capacity";
}
- Assert.assertTrue(th.getMessage().startsWith(
- msg));
- if(checkForCorruption) {
- throw (Exception) th;
+ Assert.assertTrue(th.getMessage().startsWith(msg));
+ if (checkForCorruption) {
+ throw (Exception)th;
}
transaction.commit();
return result;
@@ -204,16 +201,16 @@ public class TestUtils {
public static Set<String> consumeChannel(Channel channel) throws Exception {
return consumeChannel(channel, false);
}
- public static Set<String> consumeChannel(Channel channel,
- boolean checkForCorruption) throws Exception {
+ public static Set<String> consumeChannel(Channel channel, boolean checkForCorruption)
+ throws Exception {
Set<String> result = Sets.newHashSet();
int[] batchSizes = new int[] {
1000, 100, 10, 1
};
for (int i = 0; i < batchSizes.length; i++) {
- while(true) {
+ while (true) {
Set<String> batch = takeEvents(channel, batchSizes[i], checkForCorruption);
- if(batch.isEmpty()) {
+ if (batch.isEmpty()) {
break;
}
result.addAll(batch);
@@ -221,18 +218,16 @@ public class TestUtils {
}
return result;
}
- public static Set<String> fillChannel(Channel channel, String prefix)
- throws Exception {
+ public static Set<String> fillChannel(Channel channel, String prefix) throws Exception {
Set<String> result = Sets.newHashSet();
int[] batchSizes = new int[] {
1000, 100, 10, 1
};
for (int i = 0; i < batchSizes.length; i++) {
try {
- while(true) {
- Set<String> batch = putEvents(channel, prefix, batchSizes[i],
- Integer.MAX_VALUE, true);
- if(batch.isEmpty()) {
+ while (true) {
+ Set<String> batch = putEvents(channel, prefix, batchSizes[i], Integer.MAX_VALUE, true);
+ if (batch.isEmpty()) {
break;
}
result.addAll(batch);
@@ -243,19 +238,17 @@ public class TestUtils {
+ "size, a downstream system running slower than normal, or that "
+ "the channel capacity is just too low. [channel="
+ channel.getName() + "]").equals(e.getMessage())
- || e.getMessage().startsWith("Put queue for FileBackedTransaction " +
- "of capacity "));
+ || e.getMessage().startsWith("Put queue for FileBackedTransaction of capacity "));
}
}
return result;
}
- public static Set<String> putEvents(Channel channel, String prefix,
- int batchSize, int numEvents) throws Exception {
+ public static Set<String> putEvents(Channel channel, String prefix, int batchSize, int numEvents)
+ throws Exception {
return putEvents(channel, prefix, batchSize, numEvents, false);
}
- public static Set<String> putEvents(Channel channel, String prefix,
- int batchSize, int numEvents, boolean untilCapacityIsReached)
- throws Exception {
+ 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();
@@ -272,13 +265,12 @@ public class TestUtils {
result.addAll(batch);
} catch (Exception ex) {
transaction.rollback();
- if(untilCapacityIsReached && ex instanceof ChannelException &&
+ 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())) {
+ + "[channel=" + channel.getName() + "]").equals(ex.getMessage())) {
break;
}
throw ex;
@@ -288,6 +280,7 @@ public class TestUtils {
}
return result;
}
+
public static void copyDecompressed(String resource, File output)
throws IOException {
URL input = Resources.getResource(resource);
@@ -298,12 +291,11 @@ public class TestUtils {
gzis.close();
}
- public static Context createFileChannelContext(String checkpointDir,
- String dataDir, String backupDir, Map<String, String> overrides) {
+ public static Context createFileChannelContext(String checkpointDir, String dataDir,
+ String backupDir, Map<String, String> overrides) {
Context context = new Context();
- context.put(FileChannelConfiguration.CHECKPOINT_DIR,
- checkpointDir);
- if(backupDir != null) {
+ context.put(FileChannelConfiguration.CHECKPOINT_DIR, checkpointDir);
+ if (backupDir != null) {
context.put(FileChannelConfiguration.BACKUP_CHECKPOINT_DIR, backupDir);
}
context.put(FileChannelConfiguration.DATA_DIRS, dataDir);
@@ -312,22 +304,22 @@ public class TestUtils {
context.putAll(overrides);
return context;
}
- public static FileChannel createFileChannel(String checkpointDir,
- String dataDir, Map<String, String> overrides) {
+
+ public static FileChannel createFileChannel(String checkpointDir, String dataDir,
+ Map<String, String> overrides) {
return createFileChannel(checkpointDir, dataDir, null, overrides);
}
- public static FileChannel createFileChannel(String checkpointDir,
- String dataDir, String backupDir, Map<String, String> overrides) {
+ public static FileChannel createFileChannel(String checkpointDir, String dataDir,
+ String backupDir, Map<String, String> overrides) {
FileChannel channel = new FileChannel();
channel.setName("FileChannel-" + UUID.randomUUID());
- Context context = createFileChannelContext(checkpointDir, dataDir,
- backupDir, overrides);
+ Context context = createFileChannelContext(checkpointDir, dataDir, backupDir, overrides);
Configurables.configure(channel, context);
return channel;
}
- public static File writeStringToFile(File baseDir, String name,
- String text) throws IOException {
+
+ public static File writeStringToFile(File baseDir, String name, String text) throws IOException {
File passwordFile = new File(baseDir, name);
Files.write(text, passwordFile, Charsets.UTF_8);
return passwordFile;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/CipherProviderTestSuite.java
----------------------------------------------------------------------
diff --git a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/CipherProviderTestSuite.java b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/CipherProviderTestSuite.java
index 530ccf6..22848d2 100644
--- a/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/CipherProviderTestSuite.java
+++ b/flume-ng-channels/flume-file-channel/src/test/java/org/apache/flume/channel/file/encryption/CipherProviderTestSuite.java
@@ -32,24 +32,28 @@ public class CipherProviderTestSuite {
this.encryptor = encryptor;
this.decryptor = decryptor;
}
+
public void test() throws Exception {
testBasic();
testEmpty();
testNullPlainText();
testNullCipherText();
}
+
public void testBasic() throws Exception {
String expected = "mn state fair is the place to be";
byte[] cipherText = encryptor.encrypt(expected.getBytes(Charsets.UTF_8));
byte[] clearText = decryptor.decrypt(cipherText);
Assert.assertEquals(expected, new String(clearText, Charsets.UTF_8));
}
+
public void testEmpty() throws Exception {
String expected = "";
byte[] cipherText = encryptor.encrypt(new byte[]{});
byte[] clearText = decryptor.decrypt(cipherText);
Assert.assertEquals(expected, new String(clearText));
}
+
public void testNullPlainText() throws Exception {
try {
encryptor.encrypt(null);
@@ -58,6 +62,7 @@ public class CipherProviderTestSuite {
// expected
}
}
+
public void testNullCipherText() throws Exception {
try {
decryptor.decrypt(null);
[6/9] flume git commit: FLUME-2941. Integrate checkstyle for test
classes
Posted by mp...@apache.org.
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java b/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java
index 7851536..8921a19 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannel.java
@@ -19,10 +19,6 @@
package org.apache.flume.channel;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.LinkedBlockingDeque;
-
import org.apache.flume.Channel;
import org.apache.flume.ChannelException;
import org.apache.flume.Context;
@@ -34,8 +30,12 @@ import org.apache.flume.event.EventBuilder;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import static org.fest.reflect.core.Reflection.*;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingDeque;
+
+import static org.fest.reflect.core.Reflection.field;
public class TestMemoryChannel {
@@ -81,7 +81,7 @@ public class TestMemoryChannel {
Transaction transaction = channel.getTransaction();
transaction.begin();
- for(int i=0; i < 5; i++) {
+ for (int i = 0; i < 5; i++) {
channel.put(EventBuilder.withBody(String.format("test event %d", i).getBytes()));
}
transaction.commit();
@@ -124,7 +124,7 @@ public class TestMemoryChannel {
parms.put("transactionCapacity", "2");
context.putAll(parms);
Configurables.configure(channel, context);
- for(int i=0; i < 6; i++) {
+ for (int i = 0; i < 6; i++) {
transaction = channel.getTransaction();
transaction.begin();
Assert.assertNotNull(channel.take());
@@ -133,7 +133,7 @@ public class TestMemoryChannel {
}
}
- @Test(expected=ChannelException.class)
+ @Test(expected = ChannelException.class)
public void testTransactionPutCapacityOverload() {
Context context = new Context();
Map<String, String> parms = new HashMap<String, String>();
@@ -151,7 +151,7 @@ public class TestMemoryChannel {
Assert.fail();
}
- @Test(expected=ChannelException.class)
+ @Test(expected = ChannelException.class)
public void testCapacityOverload() {
Context context = new Context();
Map<String, String> parms = new HashMap<String, String>();
@@ -236,7 +236,7 @@ public class TestMemoryChannel {
tx.close();
}
- @Test(expected=ChannelException.class)
+ @Test(expected = ChannelException.class)
public void testByteCapacityOverload() {
Context context = new Context();
Map<String, String> parms = new HashMap<String, String>();
@@ -284,8 +284,7 @@ public class TestMemoryChannel {
try {
channel.put(EventBuilder.withBody(eventBody));
throw new RuntimeException("Put was able to overflow byte capacity.");
- } catch (ChannelException ce)
- {
+ } catch (ChannelException ce) {
//Do nothing
}
@@ -306,8 +305,7 @@ public class TestMemoryChannel {
try {
channel.put(EventBuilder.withBody(eventBody));
throw new RuntimeException("Put was able to overflow byte capacity.");
- } catch (ChannelException ce)
- {
+ } catch (ChannelException ce) {
//Do nothing
}
tx.commit();
@@ -370,7 +368,7 @@ public class TestMemoryChannel {
channel.put(EventBuilder.withBody(eventBody));
tx.commit();
Assert.fail();
- } catch ( ChannelException e ) {
+ } catch (ChannelException e) {
//success
tx.rollback();
} finally {
@@ -397,12 +395,12 @@ public class TestMemoryChannel {
tx = channel.getTransaction();
tx.begin();
try {
- for(int i = 0; i < 2; i++) {
+ for (int i = 0; i < 2; i++) {
channel.put(EventBuilder.withBody(eventBody));
}
tx.commit();
Assert.fail();
- } catch ( ChannelException e ) {
+ } catch (ChannelException e) {
//success
tx.rollback();
} finally {
@@ -418,12 +416,12 @@ public class TestMemoryChannel {
tx.begin();
try {
- for(int i = 0; i < 15; i++) {
+ for (int i = 0; i < 15; i++) {
channel.put(EventBuilder.withBody(eventBody));
}
tx.commit();
Assert.fail();
- } catch ( ChannelException e ) {
+ } catch (ChannelException e) {
//success
tx.rollback();
} finally {
@@ -438,12 +436,12 @@ public class TestMemoryChannel {
tx.begin();
try {
- for(int i = 0; i < 25; i++) {
+ for (int i = 0; i < 25; i++) {
channel.put(EventBuilder.withBody(eventBody));
}
tx.commit();
Assert.fail();
- } catch ( ChannelException e ) {
+ } catch (ChannelException e) {
//success
tx.rollback();
} finally {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelConcurrency.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelConcurrency.java b/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelConcurrency.java
index d4ba705..68aa117 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelConcurrency.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelConcurrency.java
@@ -17,15 +17,6 @@
*/
package org.apache.flume.channel;
-import java.util.Map.Entry;
-import java.util.Random;
-import java.util.concurrent.BrokenBarrierException;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.flume.Channel;
import org.apache.flume.ChannelException;
import org.apache.flume.Context;
@@ -37,6 +28,15 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import java.util.Map.Entry;
+import java.util.Random;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
public class TestMemoryChannelConcurrency {
private CyclicBarrier barrier;
@@ -120,10 +120,10 @@ public class TestMemoryChannelConcurrency {
}
/**
- * Works with a startgate/endgate latches to make sure all threads run at the same time. Threads randomly
- * choose to commit or rollback random numbers of actions, tagging them with the thread no.
- * The correctness check is made by recording committed entries into a map, and verifying the count
- * after the endgate
+ * Works with a startgate/endgate latches to make sure all threads run at the same time.
+ * Threads randomly choose to commit or rollback random numbers of actions, tagging them with the
+ * thread no. The correctness check is made by recording committed entries into a map, and
+ * verifying the count after the endgate.
* Since nothing is taking the puts out, allow for a big capacity
*
* @throws InterruptedException
@@ -135,7 +135,8 @@ public class TestMemoryChannelConcurrency {
context.put("keep-alive", "1");
context.put("capacity", "5000"); // theoretical maximum of 100 threads * 10 * 5
// because we're just grabbing the whole lot in one commit
- // normally a transactionCapacity significantly lower than the channel capacity would be recommended
+ // normally a transactionCapacity significantly lower than the channel capacity would be
+ // recommended
context.put("transactionCapacity", "5000");
Configurables.configure(channel, context);
final ConcurrentHashMap<String, AtomicInteger> committedPuts =
@@ -158,17 +159,17 @@ public class TestMemoryChannelConcurrency {
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
- for(int j = 0; j < 10; j++) {
+ for (int j = 0; j < 10; j++) {
int events = rng.nextInt(5) + 1;
Transaction tx = channel.getTransaction();
tx.begin();
- for(int k = 0; k < events; k++) {
+ for (int k = 0; k < events; k++) {
channel.put(EventBuilder.withBody(strtid.getBytes()));
}
- if(rng.nextBoolean()) {
+ if (rng.nextBoolean()) {
tx.commit();
AtomicInteger tcount = committedPuts.get(strtid);
- if(tcount == null) {
+ if (tcount == null) {
committedPuts.put(strtid, new AtomicInteger(events));
} else {
tcount.addAndGet(events);
@@ -186,7 +187,7 @@ public class TestMemoryChannelConcurrency {
startGate.countDown();
endGate.await();
- if(committedPuts.isEmpty()) {
+ if (committedPuts.isEmpty()) {
Assert.fail();
}
@@ -194,17 +195,17 @@ public class TestMemoryChannelConcurrency {
Transaction tx = channel.getTransaction();
tx.begin();
Event e;
- while((e = channel.take()) != null) {
+ while ((e = channel.take()) != null) {
String index = new String(e.getBody());
AtomicInteger remain = committedPuts.get(index);
int post = remain.decrementAndGet();
- if(post == 0) {
+ if (post == 0) {
committedPuts.remove(index);
}
}
tx.commit();
tx.close();
- if(!committedPuts.isEmpty()) {
+ if (!committedPuts.isEmpty()) {
Assert.fail();
}
}
@@ -216,10 +217,12 @@ public class TestMemoryChannelConcurrency {
context.put("keep-alive", "1");
context.put("capacity", "100"); // theoretical maximum of 100 threads * 10 * 5
// because we're just grabbing the whole lot in one commit
- // normally a transactionCapacity significantly lower than the channel capacity would be recommended
+ // normally a transactionCapacity significantly lower than the channel capacity would be
+ // recommended
context.put("transactionCapacity", "100");
Configurables.configure(channel, context);
- final ConcurrentHashMap<String, AtomicInteger> committedPuts = new ConcurrentHashMap<String, AtomicInteger>();
+ final ConcurrentHashMap<String, AtomicInteger> committedPuts =
+ new ConcurrentHashMap<String, AtomicInteger>();
final ConcurrentHashMap<String, AtomicInteger> committedTakes =
new ConcurrentHashMap<String, AtomicInteger>();
@@ -228,7 +231,7 @@ public class TestMemoryChannelConcurrency {
final CountDownLatch endGate = new CountDownLatch(threadCount);
// start a sink and source for each
- for (int i = 0; i < threadCount/2; i++) {
+ for (int i = 0; i < threadCount / 2; i++) {
Thread t = new Thread() {
@Override
public void run() {
@@ -241,23 +244,23 @@ public class TestMemoryChannelConcurrency {
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
- for(int j = 0; j < 10; j++) {
+ for (int j = 0; j < 10; j++) {
int events = rng.nextInt(5) + 1;
Transaction tx = channel.getTransaction();
tx.begin();
- for(int k = 0; k < events; k++) {
+ for (int k = 0; k < events; k++) {
channel.put(EventBuilder.withBody(strtid.getBytes()));
}
- if(rng.nextBoolean()) {
+ if (rng.nextBoolean()) {
try {
tx.commit();
AtomicInteger tcount = committedPuts.get(strtid);
- if(tcount == null) {
+ if (tcount == null) {
committedPuts.put(strtid, new AtomicInteger(events));
} else {
tcount.addAndGet(events);
}
- } catch(ChannelException e) {
+ } catch (ChannelException e) {
System.out.print("puts commit failed");
tx.rollback();
}
@@ -282,25 +285,25 @@ public class TestMemoryChannelConcurrency {
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
- for(int j = 0; j < 10; j++) {
+ for (int j = 0; j < 10; j++) {
int events = rng.nextInt(5) + 1;
Transaction tx = channel.getTransaction();
tx.begin();
Event[] taken = new Event[events];
int k;
- for(k = 0; k < events; k++) {
+ for (k = 0; k < events; k++) {
taken[k] = channel.take();
- if(taken[k] == null) break;
+ if (taken[k] == null) break;
}
- if(rng.nextBoolean()) {
+ if (rng.nextBoolean()) {
try {
tx.commit();
- for(Event e : taken) {
- if(e == null) break;
+ for (Event e : taken) {
+ if (e == null) break;
String index = new String(e.getBody());
- synchronized(takeMapLock) {
+ synchronized (takeMapLock) {
AtomicInteger remain = committedTakes.get(index);
- if(remain == null) {
+ if (remain == null) {
committedTakes.put(index, new AtomicInteger(1));
} else {
remain.incrementAndGet();
@@ -323,7 +326,7 @@ public class TestMemoryChannelConcurrency {
t.start();
}
startGate.countDown();
- if(!endGate.await(20, TimeUnit.SECONDS)) {
+ if (!endGate.await(20, TimeUnit.SECONDS)) {
Assert.fail("Not all threads ended succesfully");
}
@@ -333,11 +336,11 @@ public class TestMemoryChannelConcurrency {
Event e;
// first pull out what's left in the channel and remove it from the
// committed map
- while((e = channel.take()) != null) {
+ while ((e = channel.take()) != null) {
String index = new String(e.getBody());
AtomicInteger remain = committedPuts.get(index);
int post = remain.decrementAndGet();
- if(post == 0) {
+ if (post == 0) {
committedPuts.remove(index);
}
}
@@ -345,14 +348,19 @@ public class TestMemoryChannelConcurrency {
tx.close();
// now just check the committed puts match the committed takes
- for(Entry<String, AtomicInteger> takes : committedTakes.entrySet()) {
+ for (Entry<String, AtomicInteger> takes : committedTakes.entrySet()) {
AtomicInteger count = committedPuts.get(takes.getKey());
- if(count == null)
+ if (count == null) {
Assert.fail("Putted data doesn't exist");
- if(count.get() != takes.getValue().get())
- Assert.fail(String.format("Mismatched put and take counts expected %d had %d", count.get(), takes.getValue().get()));
+ }
+ if (count.get() != takes.getValue().get()) {
+ Assert.fail(String.format("Mismatched put and take counts expected %d had %d",
+ count.get(), takes.getValue().get()));
+ }
committedPuts.remove(takes.getKey());
}
- if(!committedPuts.isEmpty()) Assert.fail("Puts still has entries remaining");
+ if (!committedPuts.isEmpty()) {
+ Assert.fail("Puts still has entries remaining");
+ }
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelTransaction.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelTransaction.java b/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelTransaction.java
index b8e00d8..55b81ee 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelTransaction.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/channel/TestMemoryChannelTransaction.java
@@ -43,7 +43,8 @@ public class TestMemoryChannelTransaction {
@Test
public void testCommit() throws InterruptedException, EventDeliveryException {
- Event event, event2;
+ Event event;
+ Event event2;
Context context = new Context();
int putCounter = 0;
@@ -85,7 +86,8 @@ public class TestMemoryChannelTransaction {
public void testRollBack() throws InterruptedException,
EventDeliveryException {
- Event event, event2;
+ Event event;
+ Event event2;
Context context = new Context();
int putCounter = 0;
@@ -158,7 +160,8 @@ public class TestMemoryChannelTransaction {
public void testReEntTxn() throws InterruptedException,
EventDeliveryException {
- Event event, event2;
+ Event event;
+ Event event2;
Context context = new Context();
int putCounter = 0;
@@ -199,7 +202,8 @@ public class TestMemoryChannelTransaction {
@Test
public void testReEntTxnRollBack() throws InterruptedException,
EventDeliveryException {
- Event event, event2;
+ Event event;
+ Event event2;
Context context = new Context();
int putCounter = 0;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestReliableSpoolingFileEventReader.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestReliableSpoolingFileEventReader.java b/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestReliableSpoolingFileEventReader.java
index 4e90054..fdc3ce9 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestReliableSpoolingFileEventReader.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/client/avro/TestReliableSpoolingFileEventReader.java
@@ -37,14 +37,25 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
-import java.util.concurrent.*;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.Semaphore;
public class TestReliableSpoolingFileEventReader {
- private static final Logger logger = LoggerFactory.getLogger
- (TestReliableSpoolingFileEventReader.class);
+ private static final Logger logger =
+ LoggerFactory.getLogger(TestReliableSpoolingFileEventReader.class);
private static final File WORK_DIR = new File("target/test/work/" +
TestReliableSpoolingFileEventReader.class.getSimpleName());
@@ -57,7 +68,7 @@ public class TestReliableSpoolingFileEventReader {
// write out a few files
for (int i = 0; i < 4; i++) {
- File fileName = new File(WORK_DIR, "file"+i);
+ File fileName = new File(WORK_DIR, "file" + i);
StringBuilder sb = new StringBuilder();
// write as many lines as the index of the file
@@ -102,11 +113,12 @@ public class TestReliableSpoolingFileEventReader {
@Test
public void testIgnorePattern() throws IOException {
- ReliableEventReader reader = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR)
- .ignorePattern("^file2$")
- .deletePolicy(DeletePolicy.IMMEDIATE.toString())
- .build();
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder()
+ .spoolDirectory(WORK_DIR)
+ .ignorePattern("^file2$")
+ .deletePolicy(DeletePolicy.IMMEDIATE.toString())
+ .build();
List<File> before = listFiles(WORK_DIR);
Assert.assertEquals("Expected 5, not: " + before, 5, before.size());
@@ -128,8 +140,9 @@ public class TestReliableSpoolingFileEventReader {
@Test
public void testRepeatedCallsWithCommitAlways() throws IOException {
- ReliableEventReader reader = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR).build();
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .build();
final int expectedLines = 0 + 1 + 2 + 3 + 1;
int seenLines = 0;
@@ -148,8 +161,10 @@ public class TestReliableSpoolingFileEventReader {
SpoolDirectorySourceConfigurationConstants.DEFAULT_TRACKER_DIR;
File trackerDir = new File(WORK_DIR, trackerDirPath);
- ReliableEventReader reader = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR).trackerDirPath(trackerDirPath).build();
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .trackerDirPath(trackerDirPath)
+ .build();
final int expectedLines = 0 + 1 + 2 + 3 + 1;
int seenLines = 0;
@@ -173,10 +188,10 @@ public class TestReliableSpoolingFileEventReader {
@Test
public void testFileDeletion() throws IOException {
- ReliableEventReader reader = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR)
- .deletePolicy(DeletePolicy.IMMEDIATE.name())
- .build();
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .deletePolicy(DeletePolicy.IMMEDIATE.name())
+ .build();
List<File> before = listFiles(WORK_DIR);
Assert.assertEquals("Expected 5, not: " + before, 5, before.size());
@@ -197,29 +212,25 @@ public class TestReliableSpoolingFileEventReader {
@Test(expected = NullPointerException.class)
public void testNullConsumeOrder() throws IOException {
- new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR)
- .consumeOrder(null)
- .build();
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .consumeOrder(null)
+ .build();
}
@Test
public void testConsumeFileRandomly() throws IOException {
- ReliableEventReader reader
- = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR)
- .consumeOrder(ConsumeOrder.RANDOM)
- .build();
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .consumeOrder(ConsumeOrder.RANDOM)
+ .build();
File fileName = new File(WORK_DIR, "new-file");
- FileUtils.write(fileName,
- "New file created in the end. Shoud be read randomly.\n");
+ FileUtils.write(fileName, "New file created in the end. Shoud be read randomly.\n");
Set<String> actual = Sets.newHashSet();
readEventsForFilesInDir(WORK_DIR, reader, actual);
Set<String> expected = Sets.newHashSet();
createExpectedFromFilesInSetup(expected);
expected.add("");
- expected.add(
- "New file created in the end. Shoud be read randomly.");
+ expected.add("New file created in the end. Shoud be read randomly.");
Assert.assertEquals(expected, actual);
}
@@ -229,54 +240,46 @@ public class TestReliableSpoolingFileEventReader {
if (SystemUtils.IS_OS_WINDOWS) {
return;
}
- final ReliableEventReader reader
- = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR)
- .consumeOrder(ConsumeOrder.RANDOM)
- .build();
+ final ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .consumeOrder(ConsumeOrder.RANDOM)
+ .build();
File fileName = new File(WORK_DIR, "new-file");
- FileUtils.write(fileName,
- "New file created in the end. Shoud be read randomly.\n");
+ FileUtils.write(fileName, "New file created in the end. Shoud be read randomly.\n");
Set<String> expected = Sets.newHashSet();
int totalFiles = WORK_DIR.listFiles().length;
final Set<String> actual = Sets.newHashSet();
ExecutorService executor = Executors.newSingleThreadExecutor();
final Semaphore semaphore1 = new Semaphore(0);
final Semaphore semaphore2 = new Semaphore(0);
- Future<Void> wait = executor.submit(
- new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- readEventsForFilesInDir(WORK_DIR, reader, actual, semaphore1, semaphore2);
- return null;
- }
+ Future<Void> wait = executor.submit(new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ readEventsForFilesInDir(WORK_DIR, reader, actual, semaphore1, semaphore2);
+ return null;
}
- );
+ });
semaphore1.acquire();
File finalFile = new File(WORK_DIR, "t-file");
FileUtils.write(finalFile, "Last file");
semaphore2.release();
wait.get();
- int listFilesCount = ((ReliableSpoolingFileEventReader)reader)
- .getListFilesCount();
+ int listFilesCount = ((ReliableSpoolingFileEventReader)reader).getListFilesCount();
finalFile.delete();
createExpectedFromFilesInSetup(expected);
expected.add("");
- expected.add(
- "New file created in the end. Shoud be read randomly.");
+ expected.add("New file created in the end. Shoud be read randomly.");
expected.add("Last file");
Assert.assertTrue(listFilesCount < (totalFiles + 2));
Assert.assertEquals(expected, actual);
}
-
@Test
public void testConsumeFileOldest() throws IOException, InterruptedException {
- ReliableEventReader reader
- = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR)
- .consumeOrder(ConsumeOrder.OLDEST)
- .build();
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .consumeOrder(ConsumeOrder.OLDEST)
+ .build();
File file1 = new File(WORK_DIR, "new-file1");
File file2 = new File(WORK_DIR, "new-file2");
File file3 = new File(WORK_DIR, "new-file3");
@@ -299,13 +302,11 @@ public class TestReliableSpoolingFileEventReader {
}
@Test
- public void testConsumeFileYoungest()
- throws IOException, InterruptedException {
- ReliableEventReader reader
- = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR)
- .consumeOrder(ConsumeOrder.YOUNGEST)
- .build();
+ public void testConsumeFileYoungest() throws IOException, InterruptedException {
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .consumeOrder(ConsumeOrder.YOUNGEST)
+ .build();
File file1 = new File(WORK_DIR, "new-file1");
File file2 = new File(WORK_DIR, "new-file2");
File file3 = new File(WORK_DIR, "new-file3");
@@ -332,12 +333,11 @@ public class TestReliableSpoolingFileEventReader {
@Test
public void testConsumeFileOldestWithLexicographicalComparision()
- throws IOException, InterruptedException {
- ReliableEventReader reader
- = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR)
- .consumeOrder(ConsumeOrder.OLDEST)
- .build();
+ throws IOException, InterruptedException {
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .consumeOrder(ConsumeOrder.OLDEST)
+ .build();
File file1 = new File(WORK_DIR, "new-file1");
File file2 = new File(WORK_DIR, "new-file2");
File file3 = new File(WORK_DIR, "new-file3");
@@ -362,12 +362,11 @@ public class TestReliableSpoolingFileEventReader {
@Test
public void testConsumeFileYoungestWithLexicographicalComparision()
- throws IOException, InterruptedException {
- ReliableEventReader reader
- = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR)
- .consumeOrder(ConsumeOrder.YOUNGEST)
- .build();
+ throws IOException, InterruptedException {
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .consumeOrder(ConsumeOrder.YOUNGEST)
+ .build();
File file1 = new File(WORK_DIR, "new-file1");
File file2 = new File(WORK_DIR, "new-file2");
File file3 = new File(WORK_DIR, "new-file3");
@@ -393,6 +392,7 @@ public class TestReliableSpoolingFileEventReader {
@Test public void testLargeNumberOfFilesOLDEST() throws IOException {
templateTestForLargeNumberOfFiles(ConsumeOrder.OLDEST, null, 1000);
}
+
@Test public void testLargeNumberOfFilesYOUNGEST() throws IOException {
templateTestForLargeNumberOfFiles(ConsumeOrder.YOUNGEST, new Comparator<Long>() {
@@ -402,6 +402,7 @@ public class TestReliableSpoolingFileEventReader {
}
}, 1000);
}
+
@Test public void testLargeNumberOfFilesRANDOM() throws IOException {
templateTestForLargeNumberOfFiles(ConsumeOrder.RANDOM, null, 1000);
}
@@ -409,19 +410,21 @@ public class TestReliableSpoolingFileEventReader {
@Test
public void testZeroByteTrackerFile() throws IOException {
String trackerDirPath =
- SpoolDirectorySourceConfigurationConstants.DEFAULT_TRACKER_DIR;
+ SpoolDirectorySourceConfigurationConstants.DEFAULT_TRACKER_DIR;
File trackerDir = new File(WORK_DIR, trackerDirPath);
- if(!trackerDir.exists()) {
+ if (!trackerDir.exists()) {
trackerDir.mkdir();
}
File trackerFile = new File(trackerDir, ReliableSpoolingFileEventReader.metaFileName);
- if(trackerFile.exists()) {
+ if (trackerFile.exists()) {
trackerFile.delete();
}
trackerFile.createNewFile();
- ReliableEventReader reader = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(WORK_DIR).trackerDirPath(trackerDirPath).build();
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(WORK_DIR)
+ .trackerDirPath(trackerDirPath)
+ .build();
final int expectedLines = 1;
int seenLines = 0;
List<Event> events = reader.readEvents(10);
@@ -434,18 +437,16 @@ public class TestReliableSpoolingFileEventReader {
Assert.assertEquals(expectedLines, seenLines);
}
- private void templateTestForLargeNumberOfFiles(ConsumeOrder order,
- Comparator<Long> comparator,
- int N) throws IOException {
+ private void templateTestForLargeNumberOfFiles(ConsumeOrder order, Comparator<Long> comparator,
+ int N) throws IOException {
File dir = null;
try {
- dir = new File(
- "target/test/work/" + this.getClass().getSimpleName() +
- "_large");
+ dir = new File("target/test/work/" + this.getClass().getSimpleName() + "_large");
Files.createParentDirs(new File(dir, "dummy"));
- ReliableEventReader reader
- = new ReliableSpoolingFileEventReader.Builder()
- .spoolDirectory(dir).consumeOrder(order).build();
+ ReliableEventReader reader =
+ new ReliableSpoolingFileEventReader.Builder().spoolDirectory(dir)
+ .consumeOrder(order)
+ .build();
Map<Long, List<String>> expected;
if (comparator == null) {
expected = new TreeMap<Long, List<String>>();
@@ -476,16 +477,14 @@ public class TestReliableSpoolingFileEventReader {
List<Event> events;
events = reader.readEvents(10);
for (Event e : events) {
- if (order == ConsumeOrder.RANDOM) {
+ if (order == ConsumeOrder.RANDOM) {
Assert.assertTrue(expectedList.remove(new String(e.getBody())));
} else {
- Assert.assertEquals(
- ((ArrayList<String>) expectedList).get(0),
- new String(e.getBody()));
+ Assert.assertEquals(((ArrayList<String>) expectedList).get(0), new String(e.getBody()));
((ArrayList<String>) expectedList).remove(0);
}
}
- reader.commit();
+ reader.commit();
}
} finally {
deleteDir(dir);
@@ -493,23 +492,24 @@ public class TestReliableSpoolingFileEventReader {
}
private void readEventsForFilesInDir(File dir, ReliableEventReader reader,
- Collection<String> actual) throws IOException {
+ Collection<String> actual) throws IOException {
readEventsForFilesInDir(dir, reader, actual, null, null);
}
/* Read events, one for each file in the given directory. */
- private void readEventsForFilesInDir(File dir, ReliableEventReader reader,
- Collection<String> actual, Semaphore semaphore1, Semaphore semaphore2) throws IOException {
+ private void readEventsForFilesInDir(File dir, ReliableEventReader reader,
+ Collection<String> actual, Semaphore semaphore1,
+ Semaphore semaphore2) throws IOException {
List<Event> events;
boolean executed = false;
- for (int i=0; i < listFiles(dir).size(); i++) {
+ for (int i = 0; i < listFiles(dir).size(); i++) {
events = reader.readEvents(10);
for (Event e : events) {
actual.add(new String(e.getBody()));
}
reader.commit();
try {
- if(!executed) {
+ if (!executed) {
executed = true;
if (semaphore1 != null) {
semaphore1.release();
@@ -533,8 +533,7 @@ public class TestReliableSpoolingFileEventReader {
}
private static List<File> listFiles(File dir) {
- List<File> files = Lists.newArrayList(dir.listFiles(new FileFilter
- () {
+ List<File> files = Lists.newArrayList(dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return !pathname.isDirectory();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/formatter/output/TestBucketPath.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/formatter/output/TestBucketPath.java b/flume-ng-core/src/test/java/org/apache/flume/formatter/output/TestBucketPath.java
index 21b972b..b1b828a 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/formatter/output/TestBucketPath.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/formatter/output/TestBucketPath.java
@@ -18,6 +18,12 @@
package org.apache.flume.formatter.output;
+import org.apache.flume.Clock;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -26,21 +32,15 @@ import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
-import org.apache.flume.Clock;
-import org.joda.time.format.DateTimeFormatter;
-import org.joda.time.format.ISODateTimeFormat;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TestBucketPath {
Calendar cal;
Map<String, String> headers;
+
@Before
- public void setUp(){
+ public void setUp() {
cal = Calendar.getInstance();
cal.set(2012, 5, 23, 13, 46, 33);
cal.set(Calendar.MILLISECOND, 234);
@@ -49,7 +49,7 @@ public class TestBucketPath {
}
@Test
- public void testDateFormatCache(){
+ public void testDateFormatCache() {
TimeZone utcTimeZone = TimeZone.getTimeZone("UTC");
String test = "%c";
BucketPath.escapeString(
@@ -60,7 +60,7 @@ public class TestBucketPath {
SimpleDateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy");
Date d = new Date(cal.getTimeInMillis());
String expectedString = format.format(d);
- System.out.println("Expected String: "+ expectedString);
+ System.out.println("Expected String: " + expectedString);
Assert.assertEquals(expectedString, escapedString);
}
@@ -76,7 +76,7 @@ public class TestBucketPath {
SimpleDateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy");
Date d = new Date(cal2.getTimeInMillis());
String expectedString = format.format(d);
- System.out.println("Expected String: "+ expectedString);
+ System.out.println("Expected String: " + expectedString);
Assert.assertEquals(expectedString, escapedString);
}
@@ -89,8 +89,8 @@ public class TestBucketPath {
Calendar cal2 = Calendar.getInstance();
cal2.set(2012, 5, 23, 13, 45, 0);
cal2.set(Calendar.MILLISECOND, 0);
- String expectedString = String.valueOf(cal2.getTimeInMillis()/1000);
- System.out.println("Expected String: "+ expectedString);
+ String expectedString = String.valueOf(cal2.getTimeInMillis() / 1000);
+ System.out.println("Expected String: " + expectedString);
Assert.assertEquals(expectedString, escapedString);
}
@@ -103,13 +103,13 @@ public class TestBucketPath {
Calendar cal2 = Calendar.getInstance();
cal2.set(2012, 5, 23, 13, 46, 30);
cal2.set(Calendar.MILLISECOND, 0);
- String expectedString = String.valueOf(cal2.getTimeInMillis()/1000);
- System.out.println("Expected String: "+ expectedString);
+ String expectedString = String.valueOf(cal2.getTimeInMillis() / 1000);
+ System.out.println("Expected String: " + expectedString);
Assert.assertEquals(expectedString, escapedString);
}
@Test
- public void testNoRounding(){
+ public void testNoRounding() {
String test = "%c";
String escapedString = BucketPath.escapeString(
test, headers, false, Calendar.HOUR_OF_DAY, 12);
@@ -117,19 +117,19 @@ public class TestBucketPath {
SimpleDateFormat format = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy");
Date d = new Date(cal.getTimeInMillis());
String expectedString = format.format(d);
- System.out.println("Expected String: "+ expectedString);
+ System.out.println("Expected String: " + expectedString);
Assert.assertEquals(expectedString, escapedString);
}
@Test
- public void testNoPadding(){
+ public void testNoPadding() {
Calendar calender;
Map<String, String> calender_timestamp;
calender = Calendar.getInstance();
-
+
//Check single digit dates
- calender.set(2014, (5-1), 3, 13, 46, 33);
+ calender.set(2014, (5 - 1), 3, 13, 46, 33);
calender_timestamp = new HashMap<String, String>();
calender_timestamp.put("timestamp", String.valueOf(calender.getTimeInMillis()));
SimpleDateFormat format = new SimpleDateFormat("M-d");
@@ -141,19 +141,19 @@ public class TestBucketPath {
String expectedString = format.format(d);
//Check two digit dates
- calender.set(2014, (11-1), 13, 13, 46, 33);
+ calender.set(2014, (11 - 1), 13, 13, 46, 33);
calender_timestamp.put("timestamp", String.valueOf(calender.getTimeInMillis()));
- escapedString += " " + BucketPath.escapeString(
+ escapedString += " " + BucketPath.escapeString(
test, calender_timestamp, false, Calendar.HOUR_OF_DAY, 12);
System.out.println("Escaped String: " + escapedString);
d = new Date(calender.getTimeInMillis());
- expectedString += " " + format.format(d);
- System.out.println("Expected String: "+ expectedString);
+ expectedString += " " + format.format(d);
+ System.out.println("Expected String: " + expectedString);
Assert.assertEquals(expectedString, escapedString);
}
@Test
- public void testDateFormatTimeZone(){
+ public void testDateFormatTimeZone() {
TimeZone utcTimeZone = TimeZone.getTimeZone("UTC");
String test = "%c";
String escapedString = BucketPath.escapeString(
@@ -163,7 +163,7 @@ public class TestBucketPath {
format.setTimeZone(utcTimeZone);
Date d = new Date(cal.getTimeInMillis());
String expectedString = format.format(d);
- System.out.println("Expected String: "+ expectedString);
+ System.out.println("Expected String: " + expectedString);
Assert.assertEquals(expectedString, escapedString);
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/instrumentation/TestMonitoredCounterGroup.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/TestMonitoredCounterGroup.java b/flume-ng-core/src/test/java/org/apache/flume/instrumentation/TestMonitoredCounterGroup.java
index b1f637f..7db535e 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/TestMonitoredCounterGroup.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/instrumentation/TestMonitoredCounterGroup.java
@@ -18,22 +18,15 @@
*/
package org.apache.flume.instrumentation;
-import java.lang.management.ManagementFactory;
-import java.util.Random;
-
-import javax.management.AttributeNotFoundException;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanException;
-import javax.management.MBeanInfo;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.ReflectionException;
-
import junit.framework.Assert;
-
import org.junit.Before;
import org.junit.Test;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+import java.util.Random;
+
public class TestMonitoredCounterGroup {
private static final int MAX_BOUNDS = 1000;
@@ -61,7 +54,6 @@ public class TestMonitoredCounterGroup {
private static final String SRC_ATTR_APPEND_BATCH_ACCEPTED_COUNT =
"AppendBatchAcceptedCount";
-
private static final String CH_ATTR_CHANNEL_SIZE = "ChannelSize";
private static final String CH_ATTR_EVENT_PUT_ATTEMPT =
"EventPutAttemptCount";
@@ -122,28 +114,28 @@ public class TestMonitoredCounterGroup {
int eventDrainAttempt = random.nextInt(MAX_BOUNDS);
int eventDrainSuccess = random.nextInt(MAX_BOUNDS);
- for (int i = 0; i<connCreated; i++) {
+ for (int i = 0; i < connCreated; i++) {
skc.incrementConnectionCreatedCount();
}
- for (int i = 0; i<connClosed; i++) {
+ for (int i = 0; i < connClosed; i++) {
skc.incrementConnectionClosedCount();
}
- for (int i = 0; i<connFailed; i++) {
+ for (int i = 0; i < connFailed; i++) {
skc.incrementConnectionFailedCount();
}
- for (int i = 0; i<batchEmpty; i++) {
+ for (int i = 0; i < batchEmpty; i++) {
skc.incrementBatchEmptyCount();
}
- for (int i = 0; i<batchUnderflow; i++) {
+ for (int i = 0; i < batchUnderflow; i++) {
skc.incrementBatchUnderflowCount();
}
- for (int i = 0; i<batchComplete; i++) {
+ for (int i = 0; i < batchComplete; i++) {
skc.incrementBatchCompleteCount();
}
- for (int i = 0; i<eventDrainAttempt; i++) {
+ for (int i = 0; i < eventDrainAttempt; i++) {
skc.incrementEventDrainAttemptCount();
}
- for (int i = 0; i<eventDrainSuccess; i++) {
+ for (int i = 0; i < eventDrainSuccess; i++) {
skc.incrementEventDrainSuccessCount();
}
@@ -204,10 +196,10 @@ public class TestMonitoredCounterGroup {
int numEventTakeSuccess = random.nextInt(MAX_BOUNDS);
chc.setChannelSize(numChannelSize);
- for (int i = 0; i<numEventPutAttempt; i++) {
+ for (int i = 0; i < numEventPutAttempt; i++) {
chc.incrementEventPutAttemptCount();
}
- for (int i = 0; i<numEventTakeAttempt; i++) {
+ for (int i = 0; i < numEventTakeAttempt; i++) {
chc.incrementEventTakeAttemptCount();
}
chc.addToEventPutSuccessCount(numEventPutSuccess);
@@ -264,16 +256,16 @@ public class TestMonitoredCounterGroup {
srcc.addToEventReceivedCount(numEventReceived);
srcc.addToEventAcceptedCount(numEventAccepted);
- for (int i = 0; i<numAppendReceived; i++) {
+ for (int i = 0; i < numAppendReceived; i++) {
srcc.incrementAppendReceivedCount();
}
- for (int i = 0; i<numAppendAccepted; i++) {
+ for (int i = 0; i < numAppendAccepted; i++) {
srcc.incrementAppendAcceptedCount();
}
- for (int i = 0; i<numAppendBatchReceived; i++) {
+ for (int i = 0; i < numAppendBatchReceived; i++) {
srcc.incrementAppendBatchReceivedCount();
}
- for (int i = 0; i<numAppendBatchAccepted; i++) {
+ for (int i = 0; i < numAppendBatchAccepted; i++) {
srcc.incrementAppendBatchAcceptedCount();
}
@@ -302,11 +294,11 @@ public class TestMonitoredCounterGroup {
int numEventReceived2 = random.nextInt(MAX_BOUNDS);
int numEventAccepted2 = random.nextInt(MAX_BOUNDS);
- for (int i = 0; i<numEventReceived2; i++) {
+ for (int i = 0; i < numEventReceived2; i++) {
srcc.incrementEventReceivedCount();
}
- for (int i = 0; i<numEventAccepted2; i++) {
+ for (int i = 0; i < numEventAccepted2; i++) {
srcc.incrementEventAcceptedCount();
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestHTTPMetricsServer.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestHTTPMetricsServer.java b/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestHTTPMetricsServer.java
index eb2d02d..09d419f 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestHTTPMetricsServer.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/instrumentation/http/TestHTTPMetricsServer.java
@@ -20,12 +20,6 @@ package org.apache.flume.instrumentation.http;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.lang.reflect.Type;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Map;
import org.apache.flume.Channel;
import org.apache.flume.Context;
import org.apache.flume.Transaction;
@@ -39,6 +33,12 @@ import org.junit.Assert;
import org.junit.Test;
import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.lang.reflect.Type;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Map;
/**
*
@@ -47,9 +47,7 @@ public class TestHTTPMetricsServer {
Channel memChannel = new MemoryChannel();
Channel pmemChannel = new PseudoTxnMemoryChannel();
- Type mapType =
- new TypeToken<Map<String, Map<String, String>>>() {
- }.getType();
+ Type mapType = new TypeToken<Map<String, Map<String, String>>>() {}.getType();
Gson gson = new Gson();
@Test
@@ -99,7 +97,7 @@ public class TestHTTPMetricsServer {
private void testWithPort(int port) throws Exception {
MonitorService srv = new HTTPMetricsServer();
Context context = new Context();
- if(port > 1024){
+ if (port > 1024) {
context.put(HTTPMetricsServer.CONFIG_PORT, String.valueOf(port));
} else {
port = HTTPMetricsServer.DEFAULT_PORT;
@@ -139,8 +137,7 @@ public class TestHTTPMetricsServer {
doTestForbiddenMethods(4432,"OPTIONS");
}
- public void doTestForbiddenMethods(int port, String method)
- throws Exception {
+ public void doTestForbiddenMethods(int port, String method) throws Exception {
MonitorService srv = new HTTPMetricsServer();
Context context = new Context();
if (port > 1024) {
@@ -154,8 +151,7 @@ public class TestHTTPMetricsServer {
URL url = new URL("http://0.0.0.0:" + String.valueOf(port) + "/metrics");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(method);
- Assert.assertEquals(HttpServletResponse.SC_FORBIDDEN,
- conn.getResponseCode());
+ Assert.assertEquals(HttpServletResponse.SC_FORBIDDEN, conn.getResponseCode());
srv.stop();
}
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/instrumentation/kafka/KafkaSourceCounterTest.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/kafka/KafkaSourceCounterTest.java b/flume-ng-core/src/test/java/org/apache/flume/instrumentation/kafka/KafkaSourceCounterTest.java
index 4a71265..6d64c53 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/instrumentation/kafka/KafkaSourceCounterTest.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/instrumentation/kafka/KafkaSourceCounterTest.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,41 +23,41 @@ import org.junit.Test;
public class KafkaSourceCounterTest {
- KafkaSourceCounter counter;
-
- @Before
- public void setUp() throws Exception {
- counter = new KafkaSourceCounter("test");
- }
-
- @Test
- public void testAddToKafkaEventGetTimer() throws Exception {
- Assert.assertEquals(1L, counter.addToKafkaEventGetTimer(1L));
- }
-
- @Test
- public void testAddToKafkaCommitTimer() throws Exception {
- Assert.assertEquals(1L, counter.addToKafkaCommitTimer(1L));
- }
-
- @Test
- public void testIncrementKafkaEmptyCount() throws Exception {
- Assert.assertEquals(1L, counter.incrementKafkaEmptyCount());
- }
-
- @Test
- public void testGetKafkaCommitTimer() throws Exception {
- Assert.assertEquals(0, counter.getKafkaCommitTimer());
- }
-
- @Test
- public void testGetKafkaEventGetTimer() throws Exception {
- Assert.assertEquals(0, counter.getKafkaEventGetTimer());
- }
-
- @Test
- public void testGetKafkaEmptyCount() throws Exception {
- Assert.assertEquals(0, counter.getKafkaEmptyCount());
- }
+ KafkaSourceCounter counter;
+
+ @Before
+ public void setUp() throws Exception {
+ counter = new KafkaSourceCounter("test");
+ }
+
+ @Test
+ public void testAddToKafkaEventGetTimer() throws Exception {
+ Assert.assertEquals(1L, counter.addToKafkaEventGetTimer(1L));
+ }
+
+ @Test
+ public void testAddToKafkaCommitTimer() throws Exception {
+ Assert.assertEquals(1L, counter.addToKafkaCommitTimer(1L));
+ }
+
+ @Test
+ public void testIncrementKafkaEmptyCount() throws Exception {
+ Assert.assertEquals(1L, counter.incrementKafkaEmptyCount());
+ }
+
+ @Test
+ public void testGetKafkaCommitTimer() throws Exception {
+ Assert.assertEquals(0, counter.getKafkaCommitTimer());
+ }
+
+ @Test
+ public void testGetKafkaEventGetTimer() throws Exception {
+ Assert.assertEquals(0, counter.getKafkaEventGetTimer());
+ }
+
+ @Test
+ public void testGetKafkaEmptyCount() throws Exception {
+ Assert.assertEquals(0, counter.getKafkaEmptyCount());
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java
index ac46131..dd42079 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorMillisSerializer.java
@@ -18,7 +18,6 @@
package org.apache.flume.interceptor;
import junit.framework.Assert;
-
import org.apache.flume.Context;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@@ -29,7 +28,8 @@ public class TestRegexExtractorInterceptorMillisSerializer {
@Test
public void shouldRequirePatternInConfiguration() {
try {
- RegexExtractorInterceptorMillisSerializer fixture = new RegexExtractorInterceptorMillisSerializer();
+ RegexExtractorInterceptorMillisSerializer fixture =
+ new RegexExtractorInterceptorMillisSerializer();
fixture.configure(new Context());
Assert.fail();
} catch (IllegalArgumentException ex) {
@@ -40,7 +40,8 @@ public class TestRegexExtractorInterceptorMillisSerializer {
@Test
public void shouldRequireValidPatternInConfiguration() {
try {
- RegexExtractorInterceptorMillisSerializer fixture = new RegexExtractorInterceptorMillisSerializer();
+ RegexExtractorInterceptorMillisSerializer fixture =
+ new RegexExtractorInterceptorMillisSerializer();
Context context = new Context();
context.put("pattern", "ABCDEFG");
fixture.configure(context);
@@ -52,7 +53,8 @@ public class TestRegexExtractorInterceptorMillisSerializer {
@Test
public void shouldReturnMillisFromPattern() {
- RegexExtractorInterceptorMillisSerializer fixture = new RegexExtractorInterceptorMillisSerializer();
+ RegexExtractorInterceptorMillisSerializer fixture =
+ new RegexExtractorInterceptorMillisSerializer();
Context context = new Context();
String pattern = "yyyy-MM-dd HH:mm:ss";
context.put("pattern", pattern);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorPassThroughSerializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorPassThroughSerializer.java b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorPassThroughSerializer.java
index 569c274..33003e6 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorPassThroughSerializer.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestRegexExtractorInterceptorPassThroughSerializer.java
@@ -26,7 +26,8 @@ public class TestRegexExtractorInterceptorPassThroughSerializer {
@Test
public void shouldReturnSameValue() {
- RegexExtractorInterceptorPassThroughSerializer fixture = new RegexExtractorInterceptorPassThroughSerializer();
+ RegexExtractorInterceptorPassThroughSerializer fixture =
+ new RegexExtractorInterceptorPassThroughSerializer();
fixture.configure(new Context());
String input = "testing (1,2,3,4)";
Assert.assertEquals(input, fixture.serialize(input));
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java
index 2ab15f5..616b86b 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/interceptor/TestSearchAndReplaceInterceptor.java
@@ -35,7 +35,7 @@ public class TestSearchAndReplaceInterceptor {
private void testSearchReplace(Context context, String input, String output)
throws Exception {
- Interceptor.Builder builder = InterceptorBuilderFactory.newInstance(
+ Interceptor.Builder builder = InterceptorBuilderFactory.newInstance(
InterceptorType.SEARCH_REPLACE.toString());
builder.configure(context);
Interceptor interceptor = builder.build();
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/serialization/SyslogAvroEventSerializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/serialization/SyslogAvroEventSerializer.java b/flume-ng-core/src/test/java/org/apache/flume/serialization/SyslogAvroEventSerializer.java
index 896eced..05af3b1 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/serialization/SyslogAvroEventSerializer.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/serialization/SyslogAvroEventSerializer.java
@@ -231,20 +231,45 @@ public class SyslogAvroEventSerializer
private String hostname = "";
private String message = "";
- public void setFacility(int f) { facility = f; }
- public int getFacility() { return facility; }
+ public void setFacility(int f) {
+ facility = f;
+ }
+
+ public int getFacility() {
+ return facility;
+ }
+
+ public void setSeverity(int s) {
+ severity = s;
+ }
- public void setSeverity(int s) { severity = s; }
- public int getSeverity() { return severity; }
+ public int getSeverity() {
+ return severity;
+ }
- public void setTimestamp(long t) { timestamp = t; }
- public long getTimestamp() { return timestamp; }
+ public void setTimestamp(long t) {
+ timestamp = t;
+ }
- public void setHostname(String h) { hostname = h; }
- public String getHostname() { return hostname; }
+ public long getTimestamp() {
+ return timestamp;
+ }
- public void setMessage(String m) { message = m; }
- public String getMessage() { return message; }
+ public void setHostname(String h) {
+ hostname = h;
+ }
+
+ public String getHostname() {
+ return hostname;
+ }
+
+ public void setMessage(String m) {
+ message = m;
+ }
+
+ public String getMessage() {
+ return message;
+ }
@Override
public String toString() {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/serialization/TestAvroEventDeserializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestAvroEventDeserializer.java b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestAvroEventDeserializer.java
index 6f9ddc2..b95433f 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestAvroEventDeserializer.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestAvroEventDeserializer.java
@@ -49,6 +49,7 @@ public class TestAvroEventDeserializer {
LoggerFactory.getLogger(TestAvroEventDeserializer.class);
private static final Schema schema;
+
static {
schema = Schema.createRecord("MyRecord", "", "org.apache.flume", false);
Schema.Field field = new Schema.Field("foo",
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/serialization/TestDurablePositionTracker.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestDurablePositionTracker.java b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestDurablePositionTracker.java
index e52affb..0c76cc9 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestDurablePositionTracker.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestDurablePositionTracker.java
@@ -31,8 +31,7 @@ import java.net.URL;
public class TestDurablePositionTracker {
- private static final Logger logger = LoggerFactory.getLogger
- (TestDurablePositionTracker.class);
+ private static final Logger logger = LoggerFactory.getLogger(TestDurablePositionTracker.class);
@Test
public void testBasicTracker() throws IOException {
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/serialization/TestFlumeEventAvroEventSerializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestFlumeEventAvroEventSerializer.java b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestFlumeEventAvroEventSerializer.java
index 3860b5e..ded3b13 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestFlumeEventAvroEventSerializer.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestFlumeEventAvroEventSerializer.java
@@ -18,14 +18,7 @@
*/
package org.apache.flume.serialization;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.charset.CharsetDecoder;
-
+import com.google.common.base.Charsets;
import org.apache.avro.file.DataFileReader;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
@@ -38,7 +31,13 @@ import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
-import com.google.common.base.Charsets;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.CharsetDecoder;
public class TestFlumeEventAvroEventSerializer {
@@ -77,17 +76,16 @@ public class TestFlumeEventAvroEventSerializer {
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."));
+ !System.getProperty("java.version").startsWith("1.7."));
createAvroFile(TESTFILE, "snappy");
validateAvroFile(TESTFILE);
FileUtils.forceDelete(TESTFILE);
}
- public void createAvroFile(File file, String codec)
- throws FileNotFoundException, IOException {
+ public void createAvroFile(File file, String codec) throws FileNotFoundException, IOException {
- if(file.exists()){
+ if (file.exists()) {
FileUtils.forceDelete(file);
}
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java
index 631bdfe..9f336eb 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestResettableFileInputStream.java
@@ -27,8 +27,6 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.junit.Assert.*;
-
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -39,15 +37,21 @@ import java.nio.charset.Charset;
import java.nio.charset.MalformedInputException;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
public class TestResettableFileInputStream {
private static final boolean CLEANUP = true;
private static final File WORK_DIR =
new File("target/test/work").getAbsoluteFile();
- private static final Logger logger = LoggerFactory.getLogger
- (TestResettableFileInputStream.class);
+ private static final Logger logger =
+ LoggerFactory.getLogger(TestResettableFileInputStream.class);
- private File file, meta;
+ private File file;
+ private File meta;
@Before
public void setup() throws Exception {
@@ -156,7 +160,8 @@ public class TestResettableFileInputStream {
public void testUtf16BOMAndSurrogatePairRead() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
generateUtf16SurrogatePairSequence(out);
- // buffer now contains 1 BOM and 2 chars (1 surrogate pair) and 6 bytes total (including 2-byte BOM)
+ // buffer now contains 1 BOM and 2 chars (1 surrogate pair) and 6 bytes total
+ // (including 2-byte BOM)
Files.write(out.toByteArray(), file);
ResettableInputStream in = initInputStream(8, Charsets.UTF_16, DecodeErrorPolicy.FAIL);
String result = readLine(in, 2);
@@ -176,7 +181,8 @@ public class TestResettableFileInputStream {
generateShiftJis2ByteSequence(out);
// buffer now contains 8 chars and 10 bytes total
Files.write(out.toByteArray(), file);
- ResettableInputStream in = initInputStream(8, Charset.forName("Shift_JIS"), DecodeErrorPolicy.FAIL);
+ ResettableInputStream in = initInputStream(8, Charset.forName("Shift_JIS"),
+ DecodeErrorPolicy.FAIL);
String result = readLine(in, 8);
assertEquals("1234567\u4E9C\n", result);
}
@@ -215,7 +221,7 @@ public class TestResettableFileInputStream {
String javaVersionStr = System.getProperty("java.version");
double javaVersion = Double.parseDouble(javaVersionStr.substring(0, 3));
- if(javaVersion < 1.8) {
+ if (javaVersion < 1.8) {
assertTrue(preJdk8ExpectedStr.replaceAll("X", "\ufffd").equals(sb.toString()));
} else {
assertTrue(expectedStr.replaceAll("X", "\ufffd").equals(sb.toString()));
@@ -508,8 +514,8 @@ public class TestResettableFileInputStream {
return initInputStream(2048, Charsets.UTF_8, policy);
}
- private ResettableInputStream initInputStream(int bufferSize, Charset charset, DecodeErrorPolicy policy)
- throws IOException {
+ private ResettableInputStream initInputStream(int bufferSize, Charset charset,
+ DecodeErrorPolicy policy) throws IOException {
PositionTracker tracker = new DurablePositionTracker(meta, file.getPath());
ResettableInputStream in = new ResettableFileInputStream(file, tracker,
bufferSize, charset, policy);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/serialization/TestSyslogAvroEventSerializer.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestSyslogAvroEventSerializer.java b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestSyslogAvroEventSerializer.java
index 7bd342a..ba9f4ab 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/serialization/TestSyslogAvroEventSerializer.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/serialization/TestSyslogAvroEventSerializer.java
@@ -75,7 +75,7 @@ public class TestSyslogAvroEventSerializer {
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."));
+ !System.getProperty("java.version").startsWith("1.7."));
//Schema schema = new Schema.Parser().parse(schemaFile);
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/sink/TestAvroSink.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/sink/TestAvroSink.java b/flume-ng-core/src/test/java/org/apache/flume/sink/TestAvroSink.java
index 757a536..0f3f9ec 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/sink/TestAvroSink.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/sink/TestAvroSink.java
@@ -19,28 +19,10 @@
package org.apache.flume.sink;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-
import com.google.common.base.Charsets;
-import java.io.FileInputStream;
-import java.security.KeyStore;
-import java.security.Security;
-import java.util.concurrent.Executors;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
import org.apache.avro.AvroRemoteException;
import org.apache.avro.ipc.NettyServer;
-import org.apache.avro.ipc.NettyTransceiver;
import org.apache.avro.ipc.Server;
-import org.apache.avro.ipc.specific.SpecificRequestor;
import org.apache.avro.ipc.specific.SpecificResponder;
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
@@ -49,8 +31,8 @@ import org.apache.flume.Event;
import org.apache.flume.EventDeliveryException;
import org.apache.flume.Sink;
import org.apache.flume.Transaction;
-import org.apache.flume.channel.ChannelProcessor;
import org.apache.flume.api.RpcClient;
+import org.apache.flume.channel.ChannelProcessor;
import org.apache.flume.channel.MemoryChannel;
import org.apache.flume.channel.ReplicatingChannelSelector;
import org.apache.flume.conf.Configurables;
@@ -61,19 +43,30 @@ import org.apache.flume.source.AvroSource;
import org.apache.flume.source.avro.AvroFlumeEvent;
import org.apache.flume.source.avro.AvroSourceProtocol;
import org.apache.flume.source.avro.Status;
-import org.jboss.netty.channel.ChannelException;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.handler.ssl.SslHandler;
import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.charset.Charset;
+import java.security.KeyStore;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicLong;
+
public class TestAvroSink {
private static final Logger logger = LoggerFactory
@@ -90,7 +83,9 @@ public class TestAvroSink {
}
public void setUp(String compressionType, int compressionLevel) {
- if (sink != null) { throw new RuntimeException("double setup");}
+ if (sink != null) {
+ throw new RuntimeException("double setup");
+ }
sink = new AvroSink();
channel = new MemoryChannel();
@@ -607,8 +602,9 @@ public class TestAvroSink {
}
@Test
- public void testSslSinkWithNonTrustedCert() throws InterruptedException,
- EventDeliveryException, InstantiationException, IllegalAccessException {
+ public void testSslSinkWithNonTrustedCert()
+ throws InterruptedException, EventDeliveryException, InstantiationException,
+ IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
Server server = createSslServer(new MockAvroServer());
@@ -662,37 +658,38 @@ public class TestAvroSink {
}
@Test
- public void testRequestWithNoCompression() throws InterruptedException, IOException, EventDeliveryException {
-
+ public void testRequestWithNoCompression()
+ throws InterruptedException, IOException, EventDeliveryException {
doRequest(false, false, 6);
}
@Test
- public void testRequestWithCompressionOnClientAndServerOnLevel0() throws InterruptedException, IOException, EventDeliveryException {
-
+ public void testRequestWithCompressionOnClientAndServerOnLevel0()
+ throws InterruptedException, IOException, EventDeliveryException {
doRequest(true, true, 0);
}
@Test
- public void testRequestWithCompressionOnClientAndServerOnLevel1() throws InterruptedException, IOException, EventDeliveryException {
-
+ public void testRequestWithCompressionOnClientAndServerOnLevel1()
+ throws InterruptedException, IOException, EventDeliveryException {
doRequest(true, true, 1);
}
@Test
- public void testRequestWithCompressionOnClientAndServerOnLevel6() throws InterruptedException, IOException, EventDeliveryException {
-
+ public void testRequestWithCompressionOnClientAndServerOnLevel6()
+ throws InterruptedException, IOException, EventDeliveryException {
doRequest(true, true, 6);
}
@Test
- public void testRequestWithCompressionOnClientAndServerOnLevel9() throws InterruptedException, IOException, EventDeliveryException {
-
+ public void testRequestWithCompressionOnClientAndServerOnLevel9()
+ throws InterruptedException, IOException, EventDeliveryException {
doRequest(true, true, 9);
}
- private void doRequest(boolean serverEnableCompression, boolean clientEnableCompression, int compressionLevel) throws InterruptedException, IOException, EventDeliveryException {
-
+ private void doRequest(boolean serverEnableCompression, boolean clientEnableCompression,
+ int compressionLevel)
+ throws InterruptedException, IOException, EventDeliveryException {
if (clientEnableCompression) {
setUp("deflate", compressionLevel);
} else {
@@ -732,15 +729,12 @@ public class TestAvroSink {
source.start();
- Assert
- .assertTrue("Reached start or error", LifecycleController.waitForOneOf(
- source, LifecycleState.START_OR_ERROR));
- Assert.assertEquals("Server is started", LifecycleState.START,
- source.getLifecycleState());
-
+ Assert.assertTrue("Reached start or error",
+ LifecycleController.waitForOneOf(source, LifecycleState.START_OR_ERROR));
+ Assert.assertEquals("Server is started",
+ LifecycleState.START, source.getLifecycleState());
- Event event = EventBuilder.withBody("Hello avro",
- Charset.forName("UTF8"));
+ Event event = EventBuilder.withBody("Hello avro", Charset.forName("UTF8"));
sink.start();
@@ -858,7 +852,8 @@ public class TestAvroSink {
public SSLChannelPipelineFactory() {
}
- public SSLChannelPipelineFactory(String keystore, String keystorePassword, String keystoreType) {
+ public SSLChannelPipelineFactory(String keystore, String keystorePassword,
+ String keystoreType) {
this.keystore = keystore;
this.keystorePassword = keystorePassword;
this.keystoreType = keystoreType;
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java b/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java
index 835f541..cf6cbbc 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java
@@ -37,7 +37,6 @@ public class TestDefaultSinkFactory {
@Test
public void testDuplicateCreate() {
-
Sink avroSink1 = sinkFactory.create("avroSink1", "avro");
Sink avroSink2 = sinkFactory.create("avroSink2", "avro");
@@ -55,7 +54,7 @@ public class TestDefaultSinkFactory {
}
private void verifySinkCreation(String name, String type, Class<?> typeClass)
- throws Exception {
+ throws Exception {
Sink sink = sinkFactory.create(name, type);
Assert.assertNotNull(sink);
Assert.assertTrue(typeClass.isInstance(sink));
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/sink/TestFailoverSinkProcessor.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/sink/TestFailoverSinkProcessor.java b/flume-ng-core/src/test/java/org/apache/flume/sink/TestFailoverSinkProcessor.java
index 3358cf4..8882056 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/sink/TestFailoverSinkProcessor.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/sink/TestFailoverSinkProcessor.java
@@ -94,7 +94,7 @@ public class TestFailoverSinkProcessor {
@Override
public Status process() throws EventDeliveryException {
- synchronized(this) {
+ synchronized (this) {
if (remaining <= 0) {
throw new EventDeliveryException("can't consume more");
}
@@ -107,7 +107,7 @@ public class TestFailoverSinkProcessor {
tx.close();
if (e != null) {
- synchronized(this) {
+ synchronized (this) {
remaining--;
}
written++;
@@ -167,7 +167,7 @@ public class TestFailoverSinkProcessor {
Assert.assertEquals(LifecycleState.START, s1.getLifecycleState());
Assert.assertEquals(LifecycleState.START, s2.getLifecycleState());
Assert.assertEquals(LifecycleState.START, s3.getLifecycleState());
- for(int i = 0; i < 15; i++) {
+ for (int i = 0; i < 15; i++) {
Transaction tx = ch.getTransaction();
tx.begin();
ch.put(EventBuilder.withBody("test".getBytes()));
@@ -178,7 +178,7 @@ public class TestFailoverSinkProcessor {
Assert.assertEquals(new Integer(10), s1.getWritten());
Assert.assertEquals(new Integer(5), s2.getWritten());
- for(int i = 0; i < 50; i++) {
+ for (int i = 0; i < 50; i++) {
Transaction tx = ch.getTransaction();
tx.begin();
ch.put(EventBuilder.withBody("test".getBytes()));
@@ -195,7 +195,7 @@ public class TestFailoverSinkProcessor {
// get us past the retry time for the failed sink
Thread.sleep(5000);
- for(int i = 0; i < 100; i++) {
+ for (int i = 0; i < 100; i++) {
Transaction tx = ch.getTransaction();
tx.begin();
ch.put(EventBuilder.withBody("test".getBytes()));
http://git-wip-us.apache.org/repos/asf/flume/blob/cfbf1156/flume-ng-core/src/test/java/org/apache/flume/sink/TestLoadBalancingSinkProcessor.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/sink/TestLoadBalancingSinkProcessor.java b/flume-ng-core/src/test/java/org/apache/flume/sink/TestLoadBalancingSinkProcessor.java
index 7d95655..011d2d1 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/sink/TestLoadBalancingSinkProcessor.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/sink/TestLoadBalancingSinkProcessor.java
@@ -17,16 +17,7 @@
*/
package org.apache.flume.sink;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import junit.framework.Assert;
-
import org.apache.flume.Channel;
import org.apache.flume.ChannelException;
import org.apache.flume.Context;
@@ -38,6 +29,14 @@ import org.apache.flume.Transaction;
import org.apache.flume.channel.AbstractChannel;
import org.junit.Test;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
public class TestLoadBalancingSinkProcessor {
private Context getContext(String selectorType, boolean backoff) {
@@ -62,8 +61,7 @@ public class TestLoadBalancingSinkProcessor {
return getProcessor(sinks, getContext(selectorType, backoff));
}
- private LoadBalancingSinkProcessor getProcessor(List<Sink> sinks, Context ctx)
- {
+ private LoadBalancingSinkProcessor getProcessor(List<Sink> sinks, Context ctx) {
LoadBalancingSinkProcessor lbsp = new LoadBalancingSinkProcessor();
lbsp.setSinks(sinks);
lbsp.configure(ctx);
@@ -77,7 +75,7 @@ public class TestLoadBalancingSinkProcessor {
// If no selector is specified, the round-robin selector should be used
Channel ch = new MockChannel();
int n = 100;
- int numEvents = 3*n;
+ int numEvents = 3 * n;
for (int i = 0; i < numEvents; i++) {
ch.put(new MockEvent("test" + i));
}
@@ -185,7 +183,7 @@ public class TestLoadBalancingSinkProcessor {
// TODO: there is a remote possibility that s0 or s2
// never get hit by the random assignment
// and thus not backoffed, causing the test to fail
- for(int i=0; i < 50; i++) {
+ for (int i = 0; i < 50; i++) {
// a well behaved runner would always check the return.
lbsp.process();
}
@@ -214,7 +212,7 @@ public class TestLoadBalancingSinkProcessor {
public void testRandomPersistentFailure() throws Exception {
Channel ch = new MockChannel();
int n = 100;
- int numEvents = 3*n;
+ int numEvents = 3 * n;
for (int i = 0; i < numEvents; i++) {
ch.put(new MockEvent("test" + i));
}
@@ -244,7 +242,7 @@ public class TestLoadBalancingSinkProcessor {
}
Assert.assertTrue(s2.getEvents().size() == 0);
- Assert.assertTrue(s1.getEvents().size() + s3.getEvents().size() == 3*n);
+ Assert.assertTrue(s1.getEvents().size() + s3.getEvents().size() == 3 * n);
}
@Test
@@ -325,8 +323,6 @@ public class TestLoadBalancingSinkProcessor {
Assert.assertTrue("Miraculous distribution", sizeSet.size() > 1);
}
-
-
@Test
public void testRoundRobinOneActiveSink() throws Exception {
Channel ch = new MockChannel();
@@ -373,7 +369,7 @@ public class TestLoadBalancingSinkProcessor {
public void testRoundRobinPersistentFailure() throws Exception {
Channel ch = new MockChannel();
int n = 100;
- int numEvents = 3*n;
+ int numEvents = 3 * n;
for (int i = 0; i < numEvents; i++) {
ch.put(new MockEvent("test" + i));
}
@@ -404,7 +400,7 @@ public class TestLoadBalancingSinkProcessor {
Assert.assertTrue(s1.getEvents().size() == n);
Assert.assertTrue(s2.getEvents().size() == 0);
- Assert.assertTrue(s3.getEvents().size() == 2*n);
+ Assert.assertTrue(s3.getEvents().size() == 2 * n);
}
// test that even if the sink recovers immediately that it is kept out of commission briefly
@@ -413,7 +409,7 @@ public class TestLoadBalancingSinkProcessor {
public void testRoundRobinBackoffInitialFailure() throws EventDeliveryException {
Channel ch = new MockChannel();
int n = 100;
- int numEvents = 3*n;
+ int numEvents = 3 * n;
for (int i = 0; i < numEvents; i++) {
ch.put(new MockEvent("test" + i));
}
@@ -424,7 +420,7 @@ public class TestLoadBalancingSinkProcessor {
MockSink s2 = new MockSink(2);
s2.setChannel(ch);
- MockSink s3 = new MockSink(3);
+ MockSink s3 = new MockSink(3);
s3.setChannel(ch);
List<Sink> sinks = new ArrayList<Sink>();
@@ -449,14 +445,15 @@ public class TestLoadBalancingSinkProcessor {
Assert.assertEquals((3 * n) / 2, s1.getEvents().size());
Assert.assertEquals(1, s2.getEvents().size());
- Assert.assertEquals((3 * n) /2 - 1, s3.getEvents().size());
+ Assert.assertEquals((3 * n) / 2 - 1, s3.getEvents().size());
}
@Test
- public void testRoundRobinBackoffIncreasingBackoffs() throws EventDeliveryException, InterruptedException {
+ public void testRoundRobinBackoffIncreasingBackoffs()
+ throws EventDeliveryException, InterruptedException {
Channel ch = new MockChannel();
int n = 100;
- int numEvents = 3*n;
+ int numEvents = 3 * n;
for (int i = 0; i < numEvents; i++) {
ch.put(new MockEvent("test" + i));
}
@@ -468,7 +465,7 @@ public class TestLoadBalancingSinkProcessor {
s2.setChannel(ch);
s2.setFail(true);
- MockSink s3 = new MockSink(3);
+ MockSink s3 = new MockSink(3);
s3.setChannel(ch);
List<Sink> sinks = new ArrayList<Sink>();
@@ -508,10 +505,11 @@ public class TestLoadBalancingSinkProcessor {
}
@Test
- public void testRoundRobinBackoffFailureRecovery() throws EventDeliveryException, InterruptedException {
+ public void testRoundRobinBackoffFailureRecovery()
+ throws EventDeliveryException, InterruptedException {
Channel ch = new MockChannel();
int n = 100;
- int numEvents = 3*n;
+ int numEvents = 3 * n;
for (int i = 0; i < numEvents; i++) {
ch.put(new MockEvent("test" + i));
}
@@ -523,7 +521,7 @@ public class TestLoadBalancingSinkProcessor {
s2.setChannel(ch);
s2.setFail(true);
- MockSink s3 = new MockSink(3);
+ MockSink s3 = new MockSink(3);
s3.setChannel(ch);
List<Sink> sinks = new ArrayList<Sink>();
@@ -548,13 +546,12 @@ public class TestLoadBalancingSinkProcessor {
Assert.assertEquals(n, s3.getEvents().size());
}
-
@Test
public void testRoundRobinNoFailure() throws Exception {
Channel ch = new MockChannel();
int n = 100;
- int numEvents = 3*n;
+ int numEvents = 3 * n;
for (int i = 0; i < numEvents; i++) {
ch.put(new MockEvent("test" + i));
}
@@ -656,8 +653,9 @@ public class TestLoadBalancingSinkProcessor {
throw new EventDeliveryException("failed");
}
Event e = this.getChannel().take();
- if (e == null)
+ if (e == null) {
return Status.BACKOFF;
+ }
events.add(e);
return Status.READY;