Skip to content

Commit

Permalink
DRILL-6438: Remove excess logging form the tests.
Browse files Browse the repository at this point in the history
 - Removed usages of System.out and System.err from the test and replaced with loggers

closes #1284
  • Loading branch information
ilooner authored and sohami committed Jun 6, 2018
1 parent e0c39e0 commit f53fd1d
Show file tree
Hide file tree
Showing 91 changed files with 378 additions and 671 deletions.
Expand Up @@ -24,6 +24,7 @@
import static org.hamcrest.CoreMatchers.equalTo;

public class Drill2130CommonHamcrestConfigurationTest {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Drill2130CommonHamcrestConfigurationTest.class);

@SuppressWarnings("unused")
private org.hamcrest.MatcherAssert forCompileTimeCheckForNewEnoughHamcrest;
Expand All @@ -38,8 +39,7 @@ public void testJUnitHamcrestMatcherFailureWorks() {
+ " Got NoSuchMethodError; e: " + e );
}
catch ( AssertionError e ) {
System.out.println( "Class path seems fine re new JUnit vs. old Hamcrest."
+ " (Got AssertionError, not NoSuchMethodError.)" );
logger.info("Class path seems fine re new JUnit vs. old Hamcrest. (Got AssertionError, not NoSuchMethodError.)");
}
}

Expand Down
42 changes: 0 additions & 42 deletions common/src/test/java/org/apache/drill/test/DrillTest.java
Expand Up @@ -17,21 +17,17 @@
*/
package org.apache.drill.test;

import java.io.PrintStream;
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.util.List;

import org.apache.commons.io.output.NullOutputStream;
import org.apache.drill.common.util.DrillStringUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.DisableOnDebug;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
Expand Down Expand Up @@ -68,32 +64,6 @@ public class DrillTest {
*/
@Rule public final ExpectedException thrownException = ExpectedException.none();

@Rule public TestName TEST_NAME = new TestName();

/**
* Option to cause tests to produce verbose output. Many tests provide
* detailed information to stdout when enabled. To enable:
* <p>
* <tt>java ... -Dtest.verbose=true ...</tt>
*/
public static final String VERBOSE_OUTPUT = "test.verbose";

protected static final boolean verbose = Boolean.parseBoolean(System.getProperty(VERBOSE_OUTPUT));

/**
* Output destination for verbose test output. Rather than using
* <tt>System.out</tt>, use <tt>DrillTest.out</tt>. Output will
* automagically be routed to the bit bucket unless the
* {@link #VERBOSE_OUTPUT} flag is set.
*/

public static final PrintStream out = verbose ? System.out : new PrintStream(new NullOutputStream());

@Before
public void printID() throws Exception {
System.out.printf("Running %s#%s\n", getClass().getName(), TEST_NAME.getMethodName());
}

@BeforeClass
public static void initDrillTest() throws Exception {
memWatcher = new MemWatcher();
Expand Down Expand Up @@ -195,16 +165,4 @@ public long getMemNonHeap() {
return memoryBean.getNonHeapMemoryUsage().getUsed();
}
}

/**
* Reports whether verbose output has been selected for this test run.
*
* @return <tt>true</tt> if verbose output is wanted (test is likely running
* in a debugger), <tt>false</tt> if verbose output is to be suppressed
* (test is likely running in a batch Maven build).
*/

public static boolean verbose( ) {
return verbose;
}
}
Expand Up @@ -70,7 +70,6 @@ public static void setupTests() throws Exception {
// Sleep to allow table data to be flushed to tables.
// Without this, the row count stats to return 0,
// causing the planner to reject optimized plans.
System.out.println("Sleeping for 5 seconds to allow table flushes");
Thread.sleep(5000);

conf = HBaseTestsSuite.getConf();
Expand Down
Expand Up @@ -50,7 +50,6 @@ public static void tearDownAfterClass() throws Exception {


protected List<QueryDataBatch> runHBaseSQLlWithResults(String sql) throws Exception {
System.out.println("Running query:\n" + sql);
return testSqlWithResults(sql);
}

Expand All @@ -65,5 +64,4 @@ private void printResultAndVerifyRowCount(List<QueryDataBatch> results, int expe
Assert.assertEquals(expectedRowCount, rowCount);
}
}

}
Expand Up @@ -84,7 +84,6 @@ protected void runHBasePhysicalVerifyCount(String planFile, String tableName, in

protected List<QueryDataBatch> runHBaseSQLlWithResults(String sql) throws Exception {
sql = canonizeHBaseSQL(sql);
System.out.println("Running query:\n" + sql);
return testSqlWithResults(sql);
}

Expand Down
Expand Up @@ -21,8 +21,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Map.Entry;

import com.google.common.collect.Lists;
import org.apache.drill.categories.HbaseStorageTest;
import org.apache.drill.common.config.LogicalPlanPersistence;
Expand Down Expand Up @@ -66,12 +64,7 @@ public void testTableProvider() throws StoreException {
assertTrue(hbaseStore.contains(""));
assertFalse(hbaseStore.contains("unknown_key"));

int rowCount = 0;
for (Entry<String, String> entry : Lists.newArrayList(hbaseStore.getAll())) {
rowCount++;
System.out.println(entry.getKey() + "=" + entry.getValue());
}
assertEquals(7, rowCount);
assertEquals(7, Lists.newArrayList(hbaseStore.getAll()).size());

PersistentStore<String> hbaseTestStore = provider.getOrCreateStore(PersistentStoreConfig.newJacksonBuilder(lp.getMapper(), String.class).name("hbase.test").build());
hbaseTestStore.put("", "v0");
Expand All @@ -84,12 +77,7 @@ public void testTableProvider() throws StoreException {
assertEquals("v0", hbaseStore.get(""));
assertEquals("testValue", hbaseStore.get(".test"));

rowCount = 0;
for (Entry<String, String> entry : Lists.newArrayList(hbaseTestStore.getAll())) {
rowCount++;
System.out.println(entry.getKey() + "=" + entry.getValue());
}
assertEquals(6, rowCount);
assertEquals(6, Lists.newArrayList(hbaseTestStore.getAll()).size());
}

@AfterClass
Expand Down
Expand Up @@ -44,8 +44,6 @@ public class TestHiveUDFs extends BaseTestQuery {

@Test
public void testGenericUDF() throws Throwable {

int numRecords = 0;
String planString = Resources.toString(Resources.getResource("functions/hive/GenericUDF.json"), Charsets.UTF_8);
List<QueryDataBatch> results = testPhysicalWithResults(planString);

Expand Down Expand Up @@ -82,10 +80,6 @@ public void testGenericUDF() throws Throwable {
String concat = new String(concatV.getAccessor().get(i), Charsets.UTF_8);
assertTrue(concat.equals(in+"-"+in));

float flt1 = flt1V.getAccessor().get(i);
String format_number = new String(format_numberV.getAccessor().get(i), Charsets.UTF_8);


String nullableStr1 = null;
if (!nullableStr1V.getAccessor().isNull(i)) {
nullableStr1 = new String(nullableStr1V.getAccessor().get(i), Charsets.UTF_8);
Expand All @@ -100,23 +94,15 @@ public void testGenericUDF() throws Throwable {
if (nullableStr1 != null) {
assertEquals(nullableStr1.toUpperCase(), upperNullableStr1);
}

System.out.println(in + ", " + upper + ", " + concat + ", " +
flt1 + ", " + format_number + ", " + nullableStr1 + ", " + upperNullableStr1);

numRecords++;
}

result.release();
batchLoader.clear();
}

System.out.println("Processed " + numRecords + " records");
}

@Test
public void testUDF() throws Throwable {
int numRecords = 0;
String planString = Resources.toString(Resources.getResource("functions/hive/UDF.json"), Charsets.UTF_8);
List<QueryDataBatch> results = testPhysicalWithResults(planString);

Expand Down Expand Up @@ -146,25 +132,17 @@ public void testUDF() throws Throwable {
long str1Length = str1LengthV.getAccessor().get(i);
assertTrue(str1.length() == str1Length);

int str1Ascii = str1AsciiV.getAccessor().get(i);

float flt1 = flt1V.getAccessor().get(i);

double pow = 0;
if (!powV.getAccessor().isNull(i)) {
pow = powV.getAccessor().get(i);
assertTrue(Math.pow(flt1, 2.0) == pow);
}

System.out.println(str1 + ", " + str1Length + ", " + str1Ascii + ", " + flt1 + ", " + pow);
numRecords++;
}

result.release();
batchLoader.clear();
}

System.out.println("Processed " + numRecords + " records");
}

}
Expand Up @@ -24,6 +24,7 @@
import static org.hamcrest.CoreMatchers.equalTo;

public class Drill2130StorageHiveCoreHamcrestConfigurationTest {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Drill2130StorageHiveCoreHamcrestConfigurationTest.class);

@SuppressWarnings("unused")
private org.hamcrest.MatcherAssert forCompileTimeCheckForNewEnoughHamcrest;
Expand All @@ -38,9 +39,7 @@ public void testJUnitHamcrestMatcherFailureWorks() {
+ " Got NoSuchMethodError; e: " + e );
}
catch ( AssertionError e ) {
System.out.println( "Class path seems fine re new JUnit vs. old Hamcrest."
+ " (Got AssertionError, not NoSuchMethodError.)" );
logger.info("Class path seems fine re new JUnit vs. old Hamcrest. (Got AssertionError, not NoSuchMethodError.)");
}
}

}
Expand Up @@ -35,7 +35,6 @@
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.ListTablesResponse;
import org.apache.kudu.client.PartialRow;
import org.apache.kudu.client.RowResult;
import org.apache.kudu.client.RowResultIterator;
import org.apache.kudu.client.SessionConfiguration;
import org.junit.experimental.categories.Category;
Expand Down Expand Up @@ -99,8 +98,7 @@ public static void createKuduTable(String tableName, int tablets, int replicas,
while (scanner.hasMoreRows()) {
RowResultIterator results = scanner.nextRows();
while (results.hasNext()) {
RowResult result = results.next();
System.out.println(result.toStringLongFormat());
logger.debug(results.next().toString());
}
}
}
Expand Down
Expand Up @@ -36,21 +36,21 @@
import com.google.common.collect.Lists;

public class VectorUtil {

private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(VectorUtil.class);
public static final int DEFAULT_COLUMN_WIDTH = 15;

public static void showVectorAccessibleContent(VectorAccessible va, final String delimiter) {

final StringBuilder sb = new StringBuilder();
int rows = va.getRecordCount();
System.out.println(rows + " row(s):");
sb.append(rows).append(" row(s):\n");
List<String> columns = Lists.newArrayList();
for (VectorWrapper<?> vw : va) {
columns.add(formatFieldSchema(vw.getValueVector().getField()));
}

int width = columns.size();
for (String column : columns) {
System.out.printf("%s%s",column, column.equals(columns.get(width - 1)) ? "\n" : delimiter);
sb.append(column).append(column.equals(columns.get(width - 1)) ? "\n" : delimiter);
}
for (int row = 0; row < rows; row++) {
int columnCounter = 0;
Expand All @@ -65,14 +65,14 @@ public static void showVectorAccessibleContent(VectorAccessible va, final String
if (o == null) {
//null value
String value = "null";
System.out.printf("%s%s", value, lastColumn ? "\n" : delimiter);
sb.append(value).append(lastColumn ? "\n" : delimiter);
}
else if (o instanceof byte[]) {
String value = new String((byte[]) o);
System.out.printf("%s%s", value, lastColumn ? "\n" : delimiter);
sb.append(value).append(lastColumn ? "\n" : delimiter);
} else {
String value = o.toString();
System.out.printf("%s%s", value, lastColumn ? "\n" : delimiter);
sb.append(value).append(lastColumn ? "\n" : delimiter);
}
columnCounter++;
}
Expand All @@ -81,6 +81,8 @@ else if (o instanceof byte[]) {
for (VectorWrapper<?> vw : va) {
vw.clear();
}

logger.info(sb.toString());
}

public static String formatFieldSchema(MaterializedField field) {
Expand Down Expand Up @@ -140,6 +142,7 @@ public static void showVectorAccessibleContent(VectorAccessible va, int columnWi
}

public static void showVectorAccessibleContent(VectorAccessible va, int[] columnWidths) {
final StringBuilder sb = new StringBuilder();
int width = 0;
int columnIndex = 0;
List<String> columns = Lists.newArrayList();
Expand All @@ -153,19 +156,20 @@ public static void showVectorAccessibleContent(VectorAccessible va, int[] column
}

int rows = va.getRecordCount();
System.out.println(rows + " row(s):");
sb.append(rows).append(" row(s):\n");
for (int row = 0; row < rows; row++) {
// header, every 50 rows.
if (row%50 == 0) {
System.out.println(StringUtils.repeat("-", width + 1));
sb.append(StringUtils.repeat("-", width + 1)).append('\n');
columnIndex = 0;
for (String column : columns) {
int columnWidth = getColumnWidth(columnWidths, columnIndex);
System.out.printf(formats.get(columnIndex), column.length() <= columnWidth ? column : column.substring(0, columnWidth - 1));
sb.append(String.format(formats.get(columnIndex), column.length() <= columnWidth ? column : column.substring(0, columnWidth - 1)));
columnIndex++;
}
System.out.printf("|\n");
System.out.println(StringUtils.repeat("-", width + 1));

sb.append("|\n");
sb.append(StringUtils.repeat("-", width + 1)).append('\n');
}
// column values
columnIndex = 0;
Expand All @@ -178,13 +182,13 @@ public static void showVectorAccessibleContent(VectorAccessible va, int[] column
} else {
cellString = DrillStringUtils.escapeNewLines(String.valueOf(o));
}
System.out.printf(formats.get(columnIndex), cellString.length() <= columnWidth ? cellString : cellString.substring(0, columnWidth - 1));
sb.append(String.format(formats.get(columnIndex), cellString.length() <= columnWidth ? cellString : cellString.substring(0, columnWidth - 1)));
columnIndex++;
}
System.out.printf("|\n");
sb.append("|\n");
}
if (rows > 0) {
System.out.println(StringUtils.repeat("-", width + 1));
sb.append(StringUtils.repeat("-", width + 1)).append('\n');
}

for (VectorWrapper<?> vw : va) {
Expand Down
Expand Up @@ -24,6 +24,8 @@
import org.apache.parquet.schema.Type.Repetition;

public class ParquetSchemaMerge {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ParquetSchemaMerge.class);

public static void main(String[] args) {
MessageType message1;
MessageType message2;
Expand All @@ -42,6 +44,6 @@ public static void main(String[] args) {

StringBuilder builder = new StringBuilder();
message3.writeToStringBuilder(builder, "");
System.out.println(builder);
logger.info(builder.toString());
}
}

0 comments on commit f53fd1d

Please sign in to comment.