-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from alipay/20201030-multiAccountResouce
20201030 multi account resouce
- Loading branch information
Showing
12 changed files
with
309 additions
and
23 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
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
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
131 changes: 131 additions & 0 deletions
131
rdf-file-core/src/test/java/com/alipay/rdf/file/loader/ResourceLoaderTest.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* Alipay.com Inc. | ||
* Copyright (c) 2004-2020 All Rights Reserved. | ||
*/ | ||
package com.alipay.rdf.file.loader; | ||
|
||
import com.alipay.rdf.file.model.FileDefaultConfig; | ||
import com.alipay.rdf.file.model.StorageConfig; | ||
import com.alipay.rdf.file.resource.TestResource; | ||
import com.alipay.rdf.file.spi.RdfFileResourceSpi; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
|
||
import static com.alipay.rdf.file.loader.ResourceLoader.getInputStream; | ||
|
||
/** | ||
* Copyright (C) 2013-2018 Ant Financial Services Group | ||
* | ||
* @author quhongwei | ||
* @version : ResourceLoaderTest.java, v 0.1 2020年11月01日 09:19 quhongwei Exp $ | ||
*/ | ||
public class ResourceLoaderTest { | ||
|
||
@Test | ||
public void testGetInputStreamResourceKey() throws Exception{ | ||
|
||
FileDefaultConfig.DEFAULT_FILE_PARAMS.remove("key1"); | ||
FileDefaultConfig.DEFAULT_FILE_PARAMS.remove("key1"); | ||
FileDefaultConfig.DEFAULT_FILE_PARAMS.remove("testResource"); | ||
|
||
Field field = ResourceLoader.class.getDeclaredField("RESOURCE_CACHE"); | ||
field.setAccessible(true); | ||
|
||
Map<String, RdfFileResourceSpi> resourceMap = ( Map<String, RdfFileResourceSpi>)field.get(null); | ||
|
||
getInputStream("aa/bb/cc/dd.json"); | ||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
|
||
getInputStream("classpath:aa/bb/cc/dd.json"); | ||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
|
||
getInputStream("classpath:aa/bb/cc/dd.json?resourceKey=hzconfig"); | ||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
Assert.assertNotNull(resourceMap.get("classpathhzconfig")); | ||
|
||
getInputStream("classpath:aa/bb/cc/dd.json?resourceKey=shconfig"); | ||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
Assert.assertNotNull(resourceMap.get("classpathshconfig")); | ||
|
||
getInputStream("classpath:aa/bb/cc/dd.json?resourceKey=shconfig&xx=dd"); | ||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
Assert.assertNotNull(resourceMap.get("classpathhzconfig")); | ||
Assert.assertNotNull(resourceMap.get("classpathshconfig")); | ||
|
||
|
||
TestResource.TestInputStream testInputStream = (TestResource.TestInputStream)ResourceLoader.getInputStream("testResource:aa/bb/cc/dd.json"); | ||
|
||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
Assert.assertNotNull(resourceMap.get("classpathhzconfig")); | ||
Assert.assertNotNull(resourceMap.get("classpathshconfig")); | ||
Assert.assertNotNull(resourceMap.get("testResource")); | ||
|
||
Assert.assertEquals("testResource", testInputStream.getResourceType()); | ||
Assert.assertEquals("aa/bb/cc/dd.json", testInputStream.getPath()); | ||
Assert.assertNull( testInputStream.getConfig()); | ||
|
||
FileDefaultConfig.DEFAULT_FILE_PARAMS.put("testResource", new StorageConfig("nas") { | ||
{ | ||
addParam("type", "testResource"); | ||
} | ||
}); | ||
|
||
FileDefaultConfig.DEFAULT_FILE_PARAMS.put("key1", new StorageConfig("nas") { | ||
{ | ||
addParam("type", "key1"); | ||
} | ||
}); | ||
|
||
FileDefaultConfig.DEFAULT_FILE_PARAMS.put("key2", new StorageConfig("nas") { | ||
{ | ||
addParam("type", "key2"); | ||
} | ||
}); | ||
|
||
testInputStream = (TestResource.TestInputStream)ResourceLoader.getInputStream("testResource:aa/bb/cc/dd.json?resourceKey=key1"); | ||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
Assert.assertNotNull(resourceMap.get("classpathhzconfig")); | ||
Assert.assertNotNull(resourceMap.get("classpathshconfig")); | ||
Assert.assertNotNull(resourceMap.get("testResource")); | ||
Assert.assertNotNull(resourceMap.get("testResourcekey1")); | ||
|
||
RdfFileResourceSpi pre = resourceMap.get("testResourcekey1"); | ||
|
||
// 重复看看缓存 | ||
testInputStream = (TestResource.TestInputStream)ResourceLoader.getInputStream("testResource:aa/bb/cc/dd.json?resourceKey=key1"); | ||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
Assert.assertNotNull(resourceMap.get("classpathhzconfig")); | ||
Assert.assertNotNull(resourceMap.get("classpathshconfig")); | ||
Assert.assertNotNull(resourceMap.get("testResource")); | ||
Assert.assertNotNull(resourceMap.get("testResourcekey1")); | ||
Assert.assertEquals("key1", testInputStream.getConfig().getParam("type")); | ||
Assert.assertEquals(pre, resourceMap.get("testResourcekey1")); | ||
|
||
testInputStream = (TestResource.TestInputStream)ResourceLoader.getInputStream("testResource:aa/bb/cc/dd.json?resourceKey=key2"); | ||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
Assert.assertNotNull(resourceMap.get("classpathhzconfig")); | ||
Assert.assertNotNull(resourceMap.get("classpathshconfig")); | ||
Assert.assertNotNull(resourceMap.get("testResource")); | ||
Assert.assertNotNull(resourceMap.get("testResourcekey1")); | ||
Assert.assertNotNull(resourceMap.get("testResourcekey2")); | ||
Assert.assertEquals("key2", testInputStream.getConfig().getParam("type")); | ||
|
||
testInputStream = (TestResource.TestInputStream)ResourceLoader.getInputStream("testResource:aa/bb/cc/dd.json?resourceKey=key3"); | ||
Assert.assertNotNull(resourceMap.get("classpath")); | ||
Assert.assertNotNull(resourceMap.get("classpathhzconfig")); | ||
Assert.assertNotNull(resourceMap.get("classpathshconfig")); | ||
Assert.assertNotNull(resourceMap.get("testResource")); | ||
Assert.assertNotNull(resourceMap.get("testResourcekey1")); | ||
Assert.assertNotNull(resourceMap.get("testResourcekey2")); | ||
Assert.assertNotNull(resourceMap.get("testResourcekey3")); | ||
Assert.assertEquals("testResource", testInputStream.getConfig().getParam("type")); | ||
|
||
FileDefaultConfig.DEFAULT_FILE_PARAMS.remove("key1"); | ||
FileDefaultConfig.DEFAULT_FILE_PARAMS.remove("key2"); | ||
FileDefaultConfig.DEFAULT_FILE_PARAMS.remove("testResource"); | ||
|
||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
rdf-file-core/src/test/java/com/alipay/rdf/file/resource/TestResource.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Alipay.com Inc. | ||
* Copyright (c) 2004-2020 All Rights Reserved. | ||
*/ | ||
package com.alipay.rdf.file.resource; | ||
|
||
import com.alipay.rdf.file.model.StorageConfig; | ||
import com.alipay.rdf.file.spi.RdfFileResourceSpi; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Copyright (C) 2013-2018 Ant Financial Services Group | ||
* | ||
* @author quhongwei | ||
* @version : TestResource.java, v 0.1 2020年11月01日 09:48 quhongwei Exp $ | ||
*/ | ||
public class TestResource extends AbstractRdfResources { | ||
@Override | ||
public RdfInputStream getInputStream(String path) { | ||
return new TestInputStream(storageConfig, resourceType, path); | ||
} | ||
|
||
public static class TestInputStream extends RdfInputStream { | ||
private final StorageConfig config; | ||
private final String resourceType; | ||
private final String path; | ||
|
||
public TestInputStream(StorageConfig config, String resourceType, String path) { | ||
super(new InputStream() { | ||
@Override | ||
public int read() throws IOException { | ||
return 0; | ||
} | ||
}); | ||
this.config = config; | ||
this.resourceType = resourceType; | ||
this.path = path; | ||
} | ||
|
||
public StorageConfig getConfig() { | ||
return config; | ||
} | ||
|
||
public String getResourceType() { | ||
return resourceType; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
} | ||
} |
Oops, something went wrong.