Skip to content

Commit 5ad4591

Browse files
author
Costin Leau
committed
fix to address cycle bug with URL handlers
SHDP-92
1 parent e321e55 commit 5ad4591

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/main/java/org/springframework/data/hadoop/configuration/ConfigurationFactoryBean.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.commons.logging.LogFactory;
2424
import org.apache.hadoop.conf.Configuration;
2525
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
26+
import org.apache.hadoop.security.UserGroupInformation;
2627
import org.springframework.beans.factory.BeanClassLoaderAware;
2728
import org.springframework.beans.factory.FactoryBean;
2829
import org.springframework.beans.factory.InitializingBean;
@@ -67,6 +68,8 @@ public void afterPropertiesSet() throws Exception {
6768

6869
if (registerJvmUrl) {
6970
try {
71+
// force UGI init to prevent infinite loop - see SHDP-92
72+
UserGroupInformation.setConfiguration(internalConfig);
7073
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory(getObject()));
7174
log.info("Registered HDFS URL stream handler");
7275
} catch (Error err) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2011-2012 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.hadoop.configuration;
17+
18+
import org.apache.hadoop.fs.FileSystem;
19+
import org.junit.Test;
20+
21+
import static org.junit.Assert.*;
22+
23+
/**
24+
* See SHDP-92: https://jira.springsource.org/browse/SHDP-92
25+
* @author Costin Leau
26+
*/
27+
public class UrlInfiniteLoopTest {
28+
29+
@Test
30+
public void testInfiniteLoop() throws Exception {
31+
ConfigurationFactoryBean factory = new ConfigurationFactoryBean();
32+
factory.setRegisterUrlHandler(true);
33+
factory.afterPropertiesSet();
34+
assertNotNull(factory.getObject());
35+
FileSystem fs = FileSystem.get(factory.getObject());
36+
assertNotNull(fs);
37+
}
38+
}

0 commit comments

Comments
 (0)