public Void run() { System.setProperties(properties); return null; } }
private static void removeJavaProperties(final Properties javaProps) { if (javaProps != null) { Properties props = System.getProperties(); for (Iterator iter = javaProps.keySet().iterator(); iter.hasNext();) { props.remove(iter.next()); } System.setProperties(props); } }
Properties p = new Properties(System.getProperties()); p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog"); p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); // Off or any other level System.setProperties(p);
@Override public void close() { // Clear the extra stuff from System properties Properties properties = System.getProperties(); properties.remove(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTH_INIT); properties.remove(SECURITY_SYSTEM_PREFIX + SECURITY_PEER_AUTHENTICATOR); Iterator iter = security.keySet().iterator(); while (iter.hasNext()) { properties.remove(SECURITY_SYSTEM_PREFIX + iter.next()); } System.setProperties(properties); }
@Override public void intercept(IMethodInvocation invocation) throws Throwable { Properties original = new Properties(); original.putAll(System.getProperties()); try { invocation.proceed(); } finally { System.setProperties(original); } } }
public static void teardown() { System.setProperties(null); } }
public static void makeSystemPropertiesWriteOnce() { Properties properties = System.getProperties(); if (properties instanceof WriteOnceProperties) { return; } System.setProperties(new WriteOnceProperties(properties)); }
@Signature public static void setProperties(Properties properties) { System.setProperties(properties); }
public void tearDown() { System.setProperties(savedProperties); }
@Override public void beforeTestExecution(ExtensionContext ec) throws Exception { getStore(ec).put(SYSPROPS_KEY, System.getProperties()); Properties copy = new Properties(); copy.putAll(System.getProperties()); System.setProperties(copy); }
/** * Properties 本质上是一个HashTable,每次读写都会加锁,所以不支持频繁的System.getProperty(name)来检查系统内容变化 因此扩展了一个ListenableProperties, * 在其所关心的属性变化时进行通知. * * @see ListenableProperties */ public static synchronized void registerSystemPropertiesListener(PropertiesListener listener) { Properties currentProperties = System.getProperties(); // 将System的properties实现替换为ListenableProperties if (!(currentProperties instanceof ListenableProperties)) { ListenableProperties newProperties = new ListenableProperties(currentProperties); System.setProperties(newProperties); currentProperties = newProperties; } ((ListenableProperties) currentProperties).register(listener); }
/** * Constructor. * * @param name Name. * @param val Value. */ public SystemProperty(String name, String val) { this.name = name; Properties props = System.getProperties(); originalValue = (String)props.put(name, val); System.setProperties(props); }
/** {@inheritDoc} */ @Override public void close() { Properties props = System.getProperties(); if (originalValue != null) props.put(name, originalValue); else props.remove(name); System.setProperties(props); } }
public void setUp() { savedProperties = System.getProperties(); System.setProperties(new Properties(savedProperties)); }
/** * Tests that a lookup object for system properties can deal with a full * replacement of the system properties object. This test is related to * LANG-1055. */ @Test public void testSystemPropertiesLookupReplacedProperties() { final Properties oldProperties = System.getProperties(); final String osName = "os.name"; final String newOsName = oldProperties.getProperty(osName) + "_changed"; final StrLookup<String> sysLookup = StrLookup.systemPropertiesLookup(); final Properties newProps = new Properties(); newProps.setProperty(osName, newOsName); System.setProperties(newProps); try { assertEquals("Changed properties not detected", newOsName, sysLookup.lookup(osName)); } finally { System.setProperties(oldProperties); } }
@Override protected void after() { cleanUp(); System.setProperties( originalProperties ); Locale.setDefault( originalLocale ); Locale.setDefault( Locale.Category.FORMAT, originalFormatLocale ); LanguageChoice.getInstance().setDefaultLocale( originalLocale ); TimeZone.setDefault( originalTimezone ); FileUtils.deleteQuietly( tmpKettleHome.toFile() ); }
@After public void cleanUp() { System.setProperties(original); files.cleanUp(); }
@Test(enabled = false) public void testIgnoreProxyPropertiesByDefault() throws IOException, TimeoutException, InterruptedException { // FIXME not threadsafe! Properties originalProps = new Properties(); originalProps.putAll(System.getProperties()); System.setProperty(ProxyUtils.PROXY_HOST, "localhost"); System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1)); System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "localhost"); AsyncHttpClientConfigHelper.reloadProperties(); try (AsyncHttpClient client = asyncHttpClient()) { String target = "http://localhost:1234/"; Future<Response> f = client.prepareGet(target).execute(); try { f.get(3, TimeUnit.SECONDS); fail("should not be able to connect"); } catch (ExecutionException e) { // ok, no proxy used } } finally { System.setProperties(originalProps); } }
@Test(enabled = false) public void testWildcardNonProxyHosts() throws IOException, TimeoutException, InterruptedException { // FIXME not threadsafe! Properties originalProps = new Properties(); originalProps.putAll(System.getProperties()); System.setProperty(ProxyUtils.PROXY_HOST, "127.0.0.1"); System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1)); System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "127.*"); AsyncHttpClientConfigHelper.reloadProperties(); try (AsyncHttpClient client = asyncHttpClient(config().setUseProxyProperties(true))) { String nonProxifiedTarget = "http://127.0.0.1:1234/"; Future<Response> f = client.prepareGet(nonProxifiedTarget).execute(); try { f.get(3, TimeUnit.SECONDS); fail("should not be able to connect"); } catch (ExecutionException e) { // ok, no proxy used } } finally { System.setProperties(originalProps); } }
@After public void after() { System.setProperties(original); new SystemEnvironment().reset(SystemEnvironment.ENABLE_CONFIG_MERGE_FEATURE); }