Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SMALLFIX] - Warn users if an unkown authority is passed to the hadoo…
…p client (#7845) * Warn users if an unkown authority is passed and ignore it * Respond to comments - Added unit tests - Refactored log checker to Junit rule - Updated warning message. * final nits - Make mAppender private in TestLoggerRule - Fix typos in test method name - Add space around bracket in TestLoggerRule
- Loading branch information
Showing
5 changed files
with
198 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
core/client/hdfs/src/test/java/alluxio/hadoop/AbstractFileSystemApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
/* | |||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | |||
* (the "License"). You may not use this work except in compliance with the License, which is | |||
* available at www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |||
* either express or implied, as more fully set forth in the License. | |||
* | |||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | |||
*/ | |||
|
|||
package alluxio.hadoop; | |||
|
|||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
|
|||
import alluxio.TestLoggerRule; | |||
|
|||
import org.junit.After; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
|
|||
import java.io.IOException; | |||
import java.net.URI; | |||
|
|||
/** | |||
* Tests for {@link AbstractFileSystem}. Unlike {@link AbstractFileSystemTest}, these tests only | |||
* exercise the public API of {@link AbstractFileSystem}. | |||
*/ | |||
public final class AbstractFileSystemApiTest { | |||
|
|||
@Rule | |||
public TestLoggerRule mTestLogger = new TestLoggerRule(); | |||
|
|||
@After | |||
public void after() { | |||
HadoopClientTestUtils.resetClient(); | |||
} | |||
|
|||
@Test | |||
public void unknownAuthorityTriggersWarning() throws IOException { | |||
URI unknown = URI.create("alluxio://test/"); | |||
FileSystem.get(unknown, new org.apache.hadoop.conf.Configuration()); | |||
assertTrue(mTestLogger.wasLogged("Authority \"test\" is unknown")); | |||
} | |||
|
|||
@Test | |||
public void noAuthorityNoWarning() throws IOException { | |||
URI unknown = URI.create("alluxio:///"); | |||
FileSystem.get(unknown, new org.apache.hadoop.conf.Configuration()); | |||
assertFalse(mTestLogger.wasLogged("Authority \"\" is unknown")); | |||
} | |||
|
|||
@Test | |||
public void validAuthorityNoWarning() throws IOException { | |||
URI unknown = URI.create("alluxio://localhost:12345/"); | |||
FileSystem.get(unknown, new org.apache.hadoop.conf.Configuration()); | |||
assertFalse(mTestLogger.wasLogged("Authority \"localhost:12345\" is unknown")); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,77 @@ | |||
/* | |||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | |||
* (the "License"). You may not use this work except in compliance with the License, which is | |||
* available at www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |||
* either express or implied, as more fully set forth in the License. | |||
* | |||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | |||
*/ | |||
|
|||
package alluxio; | |||
|
|||
import org.apache.log4j.AppenderSkeleton; | |||
import org.apache.log4j.Logger; | |||
import org.apache.log4j.spi.LoggingEvent; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.List; | |||
|
|||
public class TestLoggerRule extends AbstractResourceRule { | |||
|
|||
private TestAppender mAppender; | |||
|
|||
@Before | |||
public void before() { | |||
mAppender = new TestAppender(); | |||
Logger.getRootLogger().addAppender(mAppender); | |||
} | |||
|
|||
@After | |||
public void after() { | |||
Logger.getRootLogger().removeAppender(mAppender); | |||
} | |||
|
|||
/** | |||
* Determine if a specific piece of text appears in log output. | |||
* | |||
* @param eventString The piece of text to search for in log events | |||
* @return True if an event containing the string exists, false otherwise | |||
*/ | |||
public boolean wasLogged(String eventString) { | |||
return mAppender.wasLogged(eventString); | |||
} | |||
|
|||
public class TestAppender extends AppenderSkeleton { | |||
|
|||
public List<LoggingEvent> mEvents = new ArrayList<LoggingEvent>(); | |||
|
|||
public void close() { } | |||
|
|||
/** | |||
* Determines whether string was logged. | |||
*/ | |||
public boolean wasLogged(String eventString) { | |||
for (LoggingEvent e : mEvents) { | |||
if (e.getRenderedMessage().contains(eventString)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
|
|||
public boolean requiresLayout() { | |||
return false; | |||
} | |||
|
|||
@Override | |||
protected void append(LoggingEvent event) { | |||
mEvents.add(event); | |||
} | |||
} | |||
|
|||
} | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,38 @@ | |||
/* | |||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | |||
* (the "License"). You may not use this work except in compliance with the License, which is | |||
* available at www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |||
* either express or implied, as more fully set forth in the License. | |||
* | |||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | |||
*/ | |||
|
|||
package alluxio; | |||
|
|||
import static org.junit.Assert.assertTrue; | |||
|
|||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
|
|||
/** | |||
* Unit tests for {@link TestLoggerRule}. | |||
*/ | |||
public final class TestLoggerRuleTest { | |||
|
|||
private static final Logger LOG = LoggerFactory.getLogger(TestLoggerRuleTest.class); | |||
|
|||
@Rule | |||
public TestLoggerRule mLogger = new TestLoggerRule(); | |||
|
|||
@Test | |||
public void wasLoggedTest() { | |||
String logEvent = "This is a test"; | |||
LOG.info(logEvent); | |||
assertTrue(mLogger.wasLogged(logEvent)); | |||
} | |||
|
|||
} |