@@ -0,0 +1,2057 @@
+/*%0A * Licensed to Metamarkets Group Inc. (Metamarkets) under one%0A * or more contributor license agreements.  See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership.  Metamarkets licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License.  You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0A%0Apackage io.druid.common.utils;%0A%0Aimport com.metamx.common.ISE;%0Aimport com.metamx.common.logger.Logger;%0Aimport org.junit.Ignore;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException;%0A%0A// The issue here is that parameters to the logging system are evaluated eagerly%0A// So CPU or resource heavy clauses in the log parameters get evaluated even if there is no debug logging%0Apublic class LogTest%0A%7B%0A  private static final Logger LOG = new Logger(LogTest.class);%0A  @Rule%0A  public ExpectedException expectedException = ExpectedException.none();%0A%0A  @Test%0A  public void testGoodLog()%0A  %7B%0A    final ExpensiveClass expensiveClass = new ExpensiveClass();%0A    if (LOG.isDebugEnabled()) %7B%0A      expectedException.expect(ISE.class);%0A    %7D%0A    if (LOG.isDebugEnabled()) %7B%0A      LOG.debug(%22Some error %25s%22, expensiveClass.expensiveMethod());%0A    %7D%0A  %7D%0A%0A  @Test%0A  @Ignore%0A  public void testBadLog()%0A  %7B%0A    final ExpensiveClass expensiveClass = new ExpensiveClass();%0A    if (LOG.isDebugEnabled()) %7B%0A      expectedException.expect(ISE.class);%0A    %7D%0A    LOG.debug(%22Some error %25s%22, expensiveClass.expensiveMethod());%0A  %7D%0A%7D%0A%0Aclass ExpensiveClass%0A%7B%0A  String expensiveMethod()%0A  %7B%0A    throw new ISE(%22Hogged up too much CPU time%22);%0A  %7D%0A%7D%0A

Add LogTest to show bad log behavior