Example usage for java.lang System clearProperty

List of usage examples for java.lang System clearProperty

Introduction

In this page you can find the example usage for java.lang System clearProperty.

Prototype

public static String clearProperty(String key) 

Source Link

Document

Removes the system property indicated by the specified key.

Usage

From source file:org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl.java

/**
 * @param config/*  ww w . j av  a  2s. c  o m*/
 *          initial configuration
 */
@SuppressWarnings("deprecation")
public MiniAccumuloClusterImpl(MiniAccumuloConfigImpl config) throws IOException {

    this.config = config.initialize();

    mkdirs(config.getConfDir());
    mkdirs(config.getLogDir());
    mkdirs(config.getLibDir());
    mkdirs(config.getLibExtDir());

    if (!config.useExistingInstance()) {
        if (!config.useExistingZooKeepers())
            mkdirs(config.getZooKeeperDir());
        mkdirs(config.getWalogDir());
        mkdirs(config.getAccumuloDir());
    }

    if (config.useMiniDFS()) {
        File nn = new File(config.getAccumuloDir(), "nn");
        mkdirs(nn);
        File dn = new File(config.getAccumuloDir(), "dn");
        mkdirs(dn);
        File dfs = new File(config.getAccumuloDir(), "dfs");
        mkdirs(dfs);
        Configuration conf = new Configuration();
        conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, nn.getAbsolutePath());
        conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, dn.getAbsolutePath());
        conf.set(DFSConfigKeys.DFS_REPLICATION_KEY, "1");
        conf.set(DFSConfigKeys.DFS_NAMENODE_REPLICATION_MIN_KEY, "1");
        conf.set("dfs.support.append", "true");
        conf.set("dfs.datanode.synconclose", "true");
        conf.set("dfs.datanode.data.dir.perm", MiniDFSUtil.computeDatanodeDirectoryPermission());
        String oldTestBuildData = System.setProperty("test.build.data", dfs.getAbsolutePath());
        miniDFS = new MiniDFSCluster.Builder(conf).build();
        if (oldTestBuildData == null)
            System.clearProperty("test.build.data");
        else
            System.setProperty("test.build.data", oldTestBuildData);
        miniDFS.waitClusterUp();
        InetSocketAddress dfsAddress = miniDFS.getNameNode().getNameNodeAddress();
        dfsUri = "hdfs://" + dfsAddress.getHostName() + ":" + dfsAddress.getPort();
        File coreFile = new File(config.getConfDir(), "core-site.xml");
        writeConfig(coreFile, Collections.singletonMap("fs.default.name", dfsUri).entrySet());
        File hdfsFile = new File(config.getConfDir(), "hdfs-site.xml");
        writeConfig(hdfsFile, conf);

        Map<String, String> siteConfig = config.getSiteConfig();
        siteConfig.put(Property.INSTANCE_DFS_URI.getKey(), dfsUri);
        siteConfig.put(Property.INSTANCE_DFS_DIR.getKey(), "/accumulo");
        config.setSiteConfig(siteConfig);
    } else if (config.useExistingInstance()) {
        dfsUri = CachedConfiguration.getInstance().get(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY);
    } else {
        dfsUri = "file:///";
    }

    File clientConfFile = config.getClientConfFile();
    // Write only the properties that correspond to ClientConfiguration properties
    writeConfigProperties(clientConfFile, Maps.filterEntries(config.getSiteConfig(),
            v -> ClientConfiguration.ClientProperty.getPropertyByKey(v.getKey()) != null));

    File siteFile = new File(config.getConfDir(), "accumulo-site.xml");
    writeConfig(siteFile, config.getSiteConfig().entrySet());

    if (!config.useExistingInstance() && !config.useExistingZooKeepers()) {
        zooCfgFile = new File(config.getConfDir(), "zoo.cfg");
        FileWriter fileWriter = new FileWriter(zooCfgFile);

        // zookeeper uses Properties to read its config, so use that to write in order to properly escape things like Windows paths
        Properties zooCfg = new Properties();
        zooCfg.setProperty("tickTime", "2000");
        zooCfg.setProperty("initLimit", "10");
        zooCfg.setProperty("syncLimit", "5");
        zooCfg.setProperty("clientPortAddress", "127.0.0.1");
        zooCfg.setProperty("clientPort", config.getZooKeeperPort() + "");
        zooCfg.setProperty("maxClientCnxns", "1000");
        zooCfg.setProperty("dataDir", config.getZooKeeperDir().getAbsolutePath());
        zooCfg.store(fileWriter, null);

        fileWriter.close();
    }

    // disable audit logging for mini....
    InputStream auditStream = this.getClass().getResourceAsStream("/auditLog.xml");

    if (auditStream != null) {
        FileUtils.copyInputStreamToFile(auditStream, new File(config.getConfDir(), "auditLog.xml"));
    }

    clusterControl = new MiniAccumuloClusterControl(this);
}

From source file:org.apache.kylin.query.test.KylinTestBase.java

protected int runSQL(File sqlFile, boolean debug, boolean explain) throws Exception {
    if (debug) {//  w ww .  j a v a 2 s .  co m
        System.setProperty("calcite.debug", "true");
        InputStream inputStream = new FileInputStream("src/test/resources/logging.properties");
        LogManager.getLogManager().readConfiguration(inputStream);
    }

    String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
    printInfo("Testing Query " + queryName);
    String sql = getTextFromFile(sqlFile);
    if (explain) {
        sql = "explain plan for " + sql;
    }
    int count = executeQuery(sql, true);

    if (debug) {
        System.clearProperty("optiq.debug");
    }
    return count;
}

From source file:com.netflix.genie.common.client.TestBaseGenieClient.java

/**
 * Try to test the init eureka method./*from  w w  w. j  a  va2 s . c  o m*/
 */
@Test
public void testInitEureka() {
    final String env = "dev";
    Assert.assertNull(System.getProperty(BaseGenieClient.EUREKA_ENVIRONMENT_PROPERTY));
    BaseGenieClient.initEureka(env);
    Assert.assertNotNull(System.getProperty(BaseGenieClient.EUREKA_ENVIRONMENT_PROPERTY));
    Assert.assertEquals(env, System.getProperty(BaseGenieClient.EUREKA_ENVIRONMENT_PROPERTY));
    System.clearProperty(BaseGenieClient.EUREKA_ENVIRONMENT_PROPERTY);
}

From source file:org.codice.ddf.configuration.migration.SystemConfigurationMigrationTest.java

@Test(expected = MigrationException.class)
public void testExportKeystorePropertyNotSet() throws Exception {
    // Setup/*from  ww  w  .  ja  v a 2s.  c  o m*/
    System.clearProperty(KEYSTORE_SYSTEM_PROP);
    System.setProperty(TRUSTSTORE_SYSTEM_PROP, TRUSTSTORE_REL_PATH);
    SystemConfigurationMigration securityConfigurationMigrator = new SystemConfigurationMigration(
            createTempDdf()) {
        @Override
        Properties readPropertiesFile(Path propertiesFile) throws MigrationException {
            Properties properties = new Properties();
            properties.setProperty(CRL_PROP_KEY, CRL_REL_PATH);
            return properties;
        }
    };

    // Perform Test
    securityConfigurationMigrator.export(exportDirectory);
}

From source file:com.seleniumtests.it.core.TestSeleniumRobotTestListener.java

@Test(groups = { "it" })
public void testContextDriverNotBlockingInTest(ITestContext testContext) throws Exception {

    try {//  ww  w  .j a  va2  s. co  m
        System.setProperty(SeleniumTestsContext.BROWSER, "htmlunit");
        System.setProperty("startLocation", "test");
        executeSubTest(1,
                new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForListener5.test1Listener5",
                        "com.seleniumtests.it.stubclasses.StubTestClassForListener5.test2Listener5" },
                "", "stub1");
    } finally {
        System.clearProperty(SeleniumTestsContext.BROWSER);
    }

    String detailedReportContent1 = readTestMethodResultFile("test1Listener5");
    Assert.assertFalse(detailedReportContent1.contains(DRIVER_BLOCKED_MSG));

    String logs = readSeleniumRobotLogFile();
    Assert.assertTrue(logs.contains("Finished creating *htmlunit driver"));
    Assert.assertTrue(logs.contains("start suite"));
    Assert.assertTrue(logs.contains("start test"));
    Assert.assertTrue(logs.contains("start class"));
    Assert.assertTrue(logs.contains("start method"));
    Assert.assertTrue(logs.contains("test 1"));
    Assert.assertTrue(logs.contains("test 2"));

    String outDir = new File(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory())
            .getAbsolutePath();
    JSONObject jsonResult = new JSONObject(
            FileUtils.readFileToString(Paths.get(outDir, "results.json").toFile()));

    // All tests should be skipped because configuration method is skipped
    Assert.assertEquals(jsonResult.getInt("pass"), 2);
}

From source file:com.aurel.track.util.emailHandling.MailSender.java

private Email setSecurityMode(Email email) {
    Integer smtpSecurity = smtpMailSettings.getSecurity();
    String oldTrustStore = (String) System.clearProperty("javax.net.ssl.trustStore");
    LOGGER.debug("oldTrustStore=" + oldTrustStore);
    switch (smtpSecurity) {
    case TSiteBean.SECURITY_CONNECTIONS_MODES.NEVER:
        LOGGER.debug("SMTP security connection mode is NEVER");
        break;/*from  w  w w.j  av  a  2  s. com*/
    case TSiteBean.SECURITY_CONNECTIONS_MODES.TLS_IF_AVAILABLE:
        LOGGER.debug("SMTP security connection mode is TLS_IF_AVAILABLE");
        email.setStartTLSEnabled(true);
        MailBL.setTrustKeyStore(smtpMailSettings.getHost());
        break;
    case TSiteBean.SECURITY_CONNECTIONS_MODES.TLS:
        LOGGER.debug("SMTP security connection mode is TLS");
        email.setStartTLSEnabled(true);
        email.setStartTLSRequired(true);
        MailBL.setTrustKeyStore(smtpMailSettings.getHost());
        break;
    case TSiteBean.SECURITY_CONNECTIONS_MODES.SSL: {
        LOGGER.debug("SMTP security connection mode is SSL");
        MailBL.setTrustKeyStore(smtpMailSettings.getHost());
        email.setSSLOnConnect(true);
        break;
    }
    default:
        break;
    }
    return email;
}

From source file:org.jboss.as.test.integration.security.common.CoreUtils.java

/**
 * Sets or removes (in case value==null) a system property. It's only a helper method, which avoids
 * {@link NullPointerException} thrown from {@link System#setProperty(String, String)} method, when the value is
 * <code>null</code>.//from   ww  w  . j  a v a 2 s  . c om
 *
 * @param key   property name
 * @param value property value
 * @return the previous string value of the system property
 */
public static String setSystemProperty(final String key, final String value) {
    return value == null ? System.clearProperty(key) : System.setProperty(key, value);
}

From source file:org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase.java

public final Region createExpiryRootRegion(final String rootName, final RegionAttributes attributes)
        throws RegionExistsException, TimeoutException {
    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
    try {/*from ww  w . j  a va  2 s  .  c om*/
        return createRootRegion(rootName, attributes);
    } finally {
        System.clearProperty(LocalRegion.EXPIRY_MS_PROPERTY);
    }
}

From source file:org.codice.ddf.configuration.migration.SystemConfigurationMigrationTest.java

@Test(expected = MigrationException.class)
public void testExportTruststorePropertyNotSet() throws Exception {
    // Setup/*from  w  w  w .ja va 2  s  .co  m*/
    System.setProperty(KEYSTORE_SYSTEM_PROP, KEYSTORE_REL_PATH);
    System.clearProperty(TRUSTSTORE_SYSTEM_PROP);

    SystemConfigurationMigration securityConfigurationMigrator = new SystemConfigurationMigration(
            createTempDdf()) {
        @Override
        Properties readPropertiesFile(Path propertiesFile) throws MigrationException {
            Properties properties = new Properties();
            properties.setProperty(CRL_PROP_KEY, CRL_REL_PATH);
            return properties;
        }
    };

    // Perform Test
    securityConfigurationMigrator.export(exportDirectory);
}

From source file:org.dspace.servicemanager.config.DSpaceConfigurationServiceTest.java

/**
 * Test method for {@link org.dspace.servicemanager.config.DSpaceConfigurationService#reloadConfig()}.
 */// www.  ja v  a  2  s .c o  m
@Test
public void testReloadConfig() {
    // Initialize new config service
    DSpaceConfigurationService dscs = new DSpaceConfigurationService();
    int size = dscs.getProperties().size();

    // Add two new Sytem properties
    System.setProperty("Hello", "World");
    System.setProperty("Tim", "Donohue");

    // Assert the new properties are not yet loaded
    assertEquals(size, dscs.getProperties().size());

    dscs.reloadConfig();

    // Assert the new properties now exist
    assertEquals(size + 2, dscs.getProperties().size());

    // Set a new value
    System.setProperty("Hello", "There");

    // Assert old value still in Configuration
    assertEquals("World", dscs.getProperty("Hello"));

    dscs.reloadConfig();

    // Now, should be new value
    assertEquals("There", dscs.getProperty("Hello"));

    // Clear set properties
    System.clearProperty("Hello");
    System.clearProperty("Tim");

    // Assert value not yet cleared from Configuration
    assertEquals("There", dscs.getProperty("Hello"));

    dscs.reloadConfig();

    // Now, should be null
    assertNull(dscs.getProperty("Hello"));

    dscs.clear();
    dscs = null;
}