diff options
author | Yannick Welsch <yannick@welsch.lu> | 2016-03-15 15:04:34 +0100 |
---|---|---|
committer | Yannick Welsch <yannick@welsch.lu> | 2016-03-15 15:40:37 +0100 |
commit | f5e6db4090d6bbb1dd9c237e117570fe5959bf7b (patch) | |
tree | af734388294baa11cd8c74a0454d19f8960183d6 /core/src/test/java/org/elasticsearch | |
parent | e91fd0969285829ad3f9c474e4e15d73c3e36ff0 (diff) |
Remove System.out.println and Throwable.printStackTrace from tests
Diffstat (limited to 'core/src/test/java/org/elasticsearch')
13 files changed, 66 insertions, 80 deletions
diff --git a/core/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java b/core/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java index 9129e3c05b..36b16d6a17 100644 --- a/core/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java @@ -166,7 +166,7 @@ public class XContentBuilderTests extends ESTestCase { byte[] data = bos.bytes().toBytes(); String sData = new String(data, "UTF8"); - System.out.println("DATA: " + sData); + assertThat(sData, equalTo("{\"name\":\"something\", source : { test : \"value\" },\"name2\":\"something2\"}")); } public void testFieldCaseConversion() throws Exception { diff --git a/core/src/test/java/org/elasticsearch/http/netty/NettyHttpServerPipeliningTests.java b/core/src/test/java/org/elasticsearch/http/netty/NettyHttpServerPipeliningTests.java index 6afe8a0aef..5d4330ec5c 100644 --- a/core/src/test/java/org/elasticsearch/http/netty/NettyHttpServerPipeliningTests.java +++ b/core/src/test/java/org/elasticsearch/http/netty/NettyHttpServerPipeliningTests.java @@ -181,7 +181,7 @@ public class NettyHttpServerPipeliningTests extends ESTestCase { @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) { - e.getCause().printStackTrace(); + logger.info("Caught exception", e.getCause()); e.getChannel().close(); } } diff --git a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java index 337d91356b..984908ad9d 100644 --- a/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java +++ b/core/src/test/java/org/elasticsearch/index/translog/TranslogTests.java @@ -1491,7 +1491,7 @@ public class TranslogTests extends ESTestCase { if (writtenOperations.size() != snapshot.totalOperations()) { for (int i = 0; i < threadCount; i++) { if (threadExceptions[i] != null) { - threadExceptions[i].printStackTrace(); + logger.info("Translog exception", threadExceptions[i]); } } } diff --git a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java index 4f08c49744..3316b52be2 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java +++ b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java @@ -281,7 +281,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { controller.assertNotThrottled(shard0); controller.assertThrottled(shard1); - System.out.println("TEST: now index more"); + logger.info("--> Indexing more data"); // More indexing to shard0 controller.simulateIndexing(shard0); diff --git a/core/src/test/java/org/elasticsearch/percolator/ConcurrentPercolatorIT.java b/core/src/test/java/org/elasticsearch/percolator/ConcurrentPercolatorIT.java index f2493d85e8..1cf2ef035b 100644 --- a/core/src/test/java/org/elasticsearch/percolator/ConcurrentPercolatorIT.java +++ b/core/src/test/java/org/elasticsearch/percolator/ConcurrentPercolatorIT.java @@ -54,7 +54,7 @@ import static org.hamcrest.Matchers.nullValue; * */ public class ConcurrentPercolatorIT extends ESIntegTestCase { - public void testSimpleConcurrentPercolator() throws Exception { + public void testSimpleConcurrentPercolator() throws Throwable { // We need to index a document / define mapping, otherwise field1 doesn't get recognized as number field. // If we don't do this, then 'test2' percolate query gets parsed as a TermQuery and not a RangeQuery. // The percolate api doesn't parse the doc if no queries have registered, so it can't lazily create a mapping @@ -143,9 +143,8 @@ public class ConcurrentPercolatorIT extends ESIntegTestCase { Throwable assertionError = exceptionHolder.get(); if (assertionError != null) { - assertionError.printStackTrace(); + throw assertionError; } - assertThat(assertionError + " should be null", assertionError, nullValue()); } public void testConcurrentAddingAndPercolating() throws Exception { diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java index f180ab5716..667cc9008a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java @@ -218,7 +218,7 @@ public abstract class BasePipelineAggregationTestCase<AF extends PipelineAggrega AF testAgg = createTestAggregatorFactory(); AggregatorFactories.Builder factoriesBuilder = AggregatorFactories.builder().skipResolveOrder().addPipelineAggregator(testAgg); String contentString = factoriesBuilder.toString(); - System.out.println(contentString); + logger.info("Content string: {}", contentString); XContentParser parser = XContentFactory.xContent(contentString).createParser(contentString); QueryParseContext parseContext = new QueryParseContext(queriesRegistry); parseContext.reset(parser); diff --git a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java index 3159217f17..071f737538 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java @@ -27,6 +27,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.termvectors.TermVectorsRequest; import org.elasticsearch.action.termvectors.TermVectorsResponse; import org.elasticsearch.common.Priority; +import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.termvectors.TermVectorsService; @@ -173,7 +174,7 @@ public class FetchSubPhasePluginIT extends ESIntegTestCase { } hitField.values().add(tv); } catch (IOException e) { - e.printStackTrace(); + ESLoggerFactory.getLogger(FetchSubPhasePluginIT.class.getName()).info("Swallowed exception", e); } } } diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java index 8f04bd7275..83e89592b8 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoFilterIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.geo; +import org.elasticsearch.common.logging.ESLoggerFactory; import org.locationtech.spatial4j.context.SpatialContext; import org.locationtech.spatial4j.distance.DistanceUtils; import org.locationtech.spatial4j.exception.InvalidShapeException; @@ -560,7 +561,7 @@ public class GeoFilterIT extends ESIntegTestCase { strategy.makeQuery(args); return true; } catch (UnsupportedSpatialOperation e) { - e.printStackTrace(); + ESLoggerFactory.getLogger(GeoFilterIT.class.getName()).info("Unsupported spatial operation {}", e, relation); return false; } } diff --git a/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java b/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java index b8f775639f..84b3b5a36a 100644 --- a/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/highlight/HighlightBuilderTests.java @@ -400,7 +400,6 @@ public class HighlightBuilderTests extends ESTestCase { context.reset(parser); highlightBuilder = HighlightBuilder.PROTOTYPE.fromXContent(context); assertEquals("expected HighlightBuilder with field", new HighlightBuilder().field(new Field("foo")), highlightBuilder); - System.out.println(Math.log(1/(double)(1+1)) + 1.0); } /** diff --git a/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java b/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java index f65ce317d7..454fa836b8 100644 --- a/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java +++ b/core/src/test/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java @@ -137,8 +137,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { try { channel.sendResponse(new StringMessageResponse("hello " + request.message)); } catch (IOException e) { - e.printStackTrace(); - assertThat(e.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", e); + fail(e.getMessage()); } } }); @@ -162,8 +162,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); - assertThat("got exception instead of a response: " + exp.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } }); @@ -193,8 +193,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); - assertThat("got exception instead of a response: " + exp.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } }); @@ -218,7 +218,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { threadPool.getThreadContext().putHeader("test.pong.user", "pong_user"); channel.sendResponse(response); } catch (IOException e) { - assertThat(e.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", e); + fail(e.getMessage()); } }); final Object context = new Object(); @@ -245,7 +246,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - assertThat("got exception instead of a response: " + exp.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } }; StringMessageRequest ping = new StringMessageRequest("ping"); @@ -317,8 +319,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { try { channel.sendResponse(TransportResponse.Empty.INSTANCE, TransportResponseOptions.builder().withCompress(true).build()); } catch (IOException e) { - e.printStackTrace(); - assertThat(e.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", e); + fail(e.getMessage()); } } }); @@ -341,8 +343,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); - assertThat("got exception instead of a response: " + exp.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } }); @@ -364,8 +366,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { try { channel.sendResponse(new StringMessageResponse("hello " + request.message), TransportResponseOptions.builder().withCompress(true).build()); } catch (IOException e) { - e.printStackTrace(); - assertThat(e.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", e); + fail(e.getMessage()); } } }); @@ -389,8 +391,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); - assertThat("got exception instead of a response: " + exp.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } }); @@ -552,8 +554,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { try { channel.sendResponse(new StringMessageResponse("hello " + request.message)); } catch (IOException e) { - e.printStackTrace(); - assertThat(e.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", e); + fail(e.getMessage()); } } }); @@ -613,7 +615,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); + logger.error("Unexpected failure", exp); fail("got exception instead of a response for " + counter + ": " + exp.getDetailedMessage()); } }); @@ -959,8 +961,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); - fail(); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } @Override @@ -1000,8 +1002,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); - fail(); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } @Override @@ -1044,8 +1046,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); - fail(); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } @Override @@ -1084,8 +1086,8 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); - fail(); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } @Override diff --git a/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java b/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java index 3d6ff1cd06..c812a67845 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/NettyScheduledPingTests.java @@ -86,8 +86,8 @@ public class NettyScheduledPingTests extends ESTestCase { try { channel.sendResponse(TransportResponse.Empty.INSTANCE, TransportResponseOptions.EMPTY); } catch (IOException e) { - e.printStackTrace(); - assertThat(e.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", e); + fail(e.getMessage()); } } }); @@ -113,8 +113,8 @@ public class NettyScheduledPingTests extends ESTestCase { @Override public void handleException(TransportException exp) { - exp.printStackTrace(); - assertThat("got exception instead of a response: " + exp.getMessage(), false, equalTo(true)); + logger.error("Unexpected failure", exp); + fail("got exception instead of a response: " + exp.getMessage()); } }).txGet(); } diff --git a/core/src/test/java/org/elasticsearch/versioning/ConcurrentDocumentOperationIT.java b/core/src/test/java/org/elasticsearch/versioning/ConcurrentDocumentOperationIT.java index bb8636d36e..6b69a038a0 100644 --- a/core/src/test/java/org/elasticsearch/versioning/ConcurrentDocumentOperationIT.java +++ b/core/src/test/java/org/elasticsearch/versioning/ConcurrentDocumentOperationIT.java @@ -54,7 +54,7 @@ public class ConcurrentDocumentOperationIT extends ESIntegTestCase { @Override public void onFailure(Throwable e) { - e.printStackTrace(); + logger.error("Unexpected exception while indexing", e); failure.set(e); latch.countDown(); } diff --git a/core/src/test/java/org/elasticsearch/versioning/SimpleVersioningIT.java b/core/src/test/java/org/elasticsearch/versioning/SimpleVersioningIT.java index 3432411b22..4e319c65ba 100644 --- a/core/src/test/java/org/elasticsearch/versioning/SimpleVersioningIT.java +++ b/core/src/test/java/org/elasticsearch/versioning/SimpleVersioningIT.java @@ -354,9 +354,7 @@ public class SimpleVersioningIT extends ESIntegTestCase { switch (random.nextInt(6)) { case 0: // random simple - if (VERBOSE) { - System.out.println("TEST: use random simple ids"); - } + logger.info("--> use random simple ids"); ids = new IDSource() { @Override public String next() { @@ -366,9 +364,7 @@ public class SimpleVersioningIT extends ESIntegTestCase { break; case 1: // random realistic unicode - if (VERBOSE) { - System.out.println("TEST: use random realistic unicode ids"); - } + logger.info("--> use random realistic unicode ids"); ids = new IDSource() { @Override public String next() { @@ -378,9 +374,7 @@ public class SimpleVersioningIT extends ESIntegTestCase { break; case 2: // sequential - if (VERBOSE) { - System.out.println("TEST: use seuquential ids"); - } + logger.info("--> use sequential ids"); ids = new IDSource() { int upto; @@ -392,9 +386,7 @@ public class SimpleVersioningIT extends ESIntegTestCase { break; case 3: // zero-pad sequential - if (VERBOSE) { - System.out.println("TEST: use zero-pad seuquential ids"); - } + logger.info("--> use zero-padded sequential ids"); ids = new IDSource() { final int radix = TestUtil.nextInt(random, Character.MIN_RADIX, Character.MAX_RADIX); final String zeroPad = String.format(Locale.ROOT, "%0" + TestUtil.nextInt(random, 4, 20) + "d", 0); @@ -409,9 +401,7 @@ public class SimpleVersioningIT extends ESIntegTestCase { break; case 4: // random long - if (VERBOSE) { - System.out.println("TEST: use random long ids"); - } + logger.info("--> use random long ids"); ids = new IDSource() { final int radix = TestUtil.nextInt(random, Character.MIN_RADIX, Character.MAX_RADIX); int upto; @@ -424,9 +414,7 @@ public class SimpleVersioningIT extends ESIntegTestCase { break; case 5: // zero-pad random long - if (VERBOSE) { - System.out.println("TEST: use zero-pad random long ids"); - } + logger.info("--> use zero-padded random long ids"); ids = new IDSource() { final int radix = TestUtil.nextInt(random, Character.MIN_RADIX, Character.MAX_RADIX); final String zeroPad = String.format(Locale.ROOT, "%015d", 0); @@ -539,9 +527,7 @@ public class SimpleVersioningIT extends ESIntegTestCase { idPrefix = ""; } else { idPrefix = TestUtil.randomSimpleString(random); - if (VERBOSE) { - System.out.println("TEST: use id prefix: " + idPrefix); - } + logger.debug("--> use id prefix {}", idPrefix); } int numIDs; @@ -564,9 +550,7 @@ public class SimpleVersioningIT extends ESIntegTestCase { final IDAndVersion[] idVersions = new IDAndVersion[TestUtil.nextInt(random, numIDs / 2, numIDs * (TEST_NIGHTLY ? 8 : 2))]; final Map<String, IDAndVersion> truth = new HashMap<>(); - if (VERBOSE) { - System.out.println("TEST: use " + numIDs + " ids; " + idVersions.length + " operations"); - } + logger.debug("--> use {} ids; {} operations", numIDs, idVersions.length); for (int i = 0; i < idVersions.length; i++) { @@ -596,10 +580,9 @@ public class SimpleVersioningIT extends ESIntegTestCase { idVersions[i] = x; } - if (VERBOSE) { - for (IDAndVersion idVersion : idVersions) { - System.out.println("id=" + idVersion.id + " version=" + idVersion.version + " delete?=" + idVersion.delete + " truth?=" + (truth.get(idVersion.id) == idVersion)); - } + for (IDAndVersion idVersion : idVersions) { + logger.debug("--> id={} version={} delete?={} truth?={}", idVersion.id, idVersion.version, idVersion.delete, + truth.get(idVersion.id) == idVersion); } final AtomicInteger upto = new AtomicInteger(); @@ -623,8 +606,8 @@ public class SimpleVersioningIT extends ESIntegTestCase { if (index >= idVersions.length) { break; } - if (VERBOSE && index % 100 == 0) { - System.out.println(Thread.currentThread().getName() + ": index=" + index); + if (index % 100 == 0) { + logger.trace("{}: index={}", Thread.currentThread().getName(), index); } IDAndVersion idVersion = idVersions[index]; @@ -657,18 +640,18 @@ public class SimpleVersioningIT extends ESIntegTestCase { idVersion.indexFinishTime = System.nanoTime() - startTime; if (threadRandom.nextInt(100) == 7) { - System.out.println(threadID + ": TEST: now refresh at " + (System.nanoTime() - startTime)); + logger.trace("--> {}: TEST: now refresh at {}", threadID, System.nanoTime() - startTime); refresh(); - System.out.println(threadID + ": TEST: refresh done at " + (System.nanoTime() - startTime)); + logger.trace("--> {}: TEST: refresh done at {}", threadID, System.nanoTime() - startTime); } if (threadRandom.nextInt(100) == 7) { - System.out.println(threadID + ": TEST: now flush at " + (System.nanoTime() - startTime)); + logger.trace("--> {}: TEST: now flush at {}", threadID, System.nanoTime() - startTime); try { flush(); } catch (FlushNotAllowedEngineException fnaee) { // OK } - System.out.println(threadID + ": TEST: flush done at " + (System.nanoTime() - startTime)); + logger.trace("--> {}: TEST: flush done at {}", threadID, System.nanoTime() - startTime); } } } catch (Exception e) { @@ -696,16 +679,17 @@ public class SimpleVersioningIT extends ESIntegTestCase { } long actualVersion = client().prepareGet("test", "type", id).execute().actionGet().getVersion(); if (actualVersion != expected) { - System.out.println("FAILED: idVersion=" + idVersion + " actualVersion=" + actualVersion); + logger.error("--> FAILED: idVersion={} actualVersion= {}", idVersion, actualVersion); failed = true; } } if (failed) { - System.out.println("All versions:"); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < idVersions.length; i++) { - System.out.println("i=" + i + " " + idVersions[i]); + sb.append("i=").append(i).append(" ").append(idVersions[i]).append(System.lineSeparator()); } + logger.error("All versions: {}", sb); fail("wrong versions for some IDs"); } } |