private static InputStream lookupFile(String configFile, ClassLoader classLoader, ClassLoader strictClassLoader) throws FileNotFoundException { FileLookup fileLookup = FileLookupFactory.newInstance(); InputStream input = fileLookup.lookupFile(configFile, classLoader); // when it's not a user-provided configuration file, it might be a default configuration file, // and if that's included in [this] module might not be visible to the ClassLoaderService: if (input == null) { // This time use lookupFile*Strict* so to provide an exception if we can't find it yet: input = fileLookup.lookupFileStrict(configFile, strictClassLoader); } return input; }
private InputStream findPropertiesFile() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); return FileLookupFactory.newInstance() .lookupFile(RemoteCacheManager.HOTROD_CLIENT_PROPERTIES, cl); }
@Test public void testSchema() throws Exception { FileLookup lookup = FileLookupFactory.newInstance(); String schemaFilename = String.format("schema/infinispan-config-%s.xsd", Version.getMajorMinor()); URL schemaFile = lookup.lookupFileLocation(schemaFilename, Thread.currentThread().getContextClassLoader()); if (schemaFile == null) { throw new NullPointerException("Failed to find a schema file " + schemaFilename); } Source xmlFile = new StreamSource(lookup.lookupFile(String.format("configs/unified/%s.xml", Version.getMajorMinor()), Thread.currentThread().getContextClassLoader())); SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaFile).newValidator().validate(xmlFile); }
public Properties getProperties(ClassLoader cl) { InputStream is = FileLookupFactory.newInstance().lookupFile("hotrod-client.properties", cl); Properties testProperties = new Properties(); try { testProperties.load(is); return testProperties; } catch (IOException e) { throw new AssertionError(e); } }
@Test public void testTimestampValidation() { final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache"; Properties p = createProperties(); InputStream configStream = FileLookupFactory.newInstance().lookupFile(DEF_INFINISPAN_CONFIG_RESOURCE, getClass().getClassLoader()); ConfigurationBuilderHolder cbh = new ParserRegistry().parse(configStream); ConfigurationBuilder builder = cbh.getNamedConfigurationBuilders().get( DEF_TIMESTAMPS_RESOURCE ); builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC); DefaultCacheManager manager = new DefaultCacheManager(cbh, true); try { TestRegionFactory factory = createRegionFactory(manager, p, null); factory.start(ServiceRegistryTestingImpl.forUnitTesting(), p); // Should have failed saying that invalidation is not allowed for timestamp caches. Exceptions.expectException(CacheException.class, () -> factory.buildTimestampsRegion(timestamps)); } finally { TestingUtil.killCacheManagers( manager ); } }