Skip to content
Permalink
Browse files
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.
  • Loading branch information
mpercy committed Jul 8, 2016
1 parent c8c0f9b commit cfbf1156858af9ae26975fefc94594d91c8cd3f4
Showing 141 changed files with 3,523 additions and 3,423 deletions.
@@ -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>
@@ -12,32 +12,40 @@
<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"
files="ElasticSearchClientFactory\.java"/>

<!-- 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>
@@ -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 -->
@@ -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 void testFlumeLoginPrincipalWithoutRealm() throws Exception {
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();
@@ -18,51 +18,57 @@
*/
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;
private final int until;
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;
}
@@ -33,52 +33,61 @@ 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);
selector.setChannels(channels);
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;
}
@@ -28,11 +28,11 @@
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 void setup() throws IOException {
Assert.assertTrue(file.isFile());
Assert.assertTrue(file.canWrite());
}

@After
public void cleanup() {
file.delete();
}

@Test
public void testSerialization() throws Exception {
EventQueueBackingStore backingStore =

0 comments on commit cfbf115

Please sign in to comment.