List of usage examples for java.lang System clearProperty
public static String clearProperty(String key)
From source file:org.geotools.gce.imagemosaic.ImageMosaicReaderTest.java
@AfterClass public static void close() { System.clearProperty("org.geotools.referencing.forceXY"); }
From source file:org.apache.zookeeper.server.quorum.QuorumPeerMainTest.java
/** * Currently, in SNAP sync, the leader will start queuing the * proposal/commits and the NEWLEADER packet before sending * over the snapshot over wire. So it's possible that the zxid * associated with the snapshot might be higher than all the * packets queued before NEWLEADER.// ww w . jav a 2s .co m * * When the follower received the snapshot, it will apply all * the txns queued before NEWLEADER, which may not cover all * the txns up to the zxid in the snapshot. After that, it * will write the snapshot out to disk with the zxid associated * with the snapshot. In case the server crashed after writing * this out, when loading the data from disk, it will use zxid * of the snapshot file to sync with leader, and it could cause * data inconsistent, because we only replayed partial of the * historical data during previous syncing. * * This test case is going to cover and simulate this scenario * and make sure there is no data inconsistency issue after fix. */ @Test public void testInconsistentDueToNewLeaderOrder() throws Exception { // 1. set up an ensemble with 3 servers final int ENSEMBLE_SERVERS = 3; final int clientPorts[] = new int[ENSEMBLE_SERVERS]; StringBuilder sb = new StringBuilder(); String server; for (int i = 0; i < ENSEMBLE_SERVERS; i++) { clientPorts[i] = PortAssignment.unique(); server = "server." + i + "=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ":participant;127.0.0.1:" + clientPorts[i]; sb.append(server + "\n"); } String currentQuorumCfgSection = sb.toString(); // start servers MainThread[] mt = new MainThread[ENSEMBLE_SERVERS]; ZooKeeper zk[] = new ZooKeeper[ENSEMBLE_SERVERS]; Context contexts[] = new Context[ENSEMBLE_SERVERS]; for (int i = 0; i < ENSEMBLE_SERVERS; i++) { final Context context = new Context(); contexts[i] = context; mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, false) { @Override public TestQPMain getTestQPMain() { return new CustomizedQPMain(context); } }; mt[i].start(); zk[i] = new ZooKeeper("127.0.0.1:" + clientPorts[i], ClientBase.CONNECTION_TIMEOUT, this); } waitForAll(zk, States.CONNECTED); LOG.info("all servers started"); String nodePath = "/testInconsistentDueToNewLeader"; int leaderId = -1; int followerA = -1; for (int i = 0; i < ENSEMBLE_SERVERS; i++) { if (mt[i].main.quorumPeer.leader != null) { leaderId = i; } else if (followerA == -1) { followerA = i; } } LOG.info("shutdown follower {}", followerA); mt[followerA].shutdown(); waitForOne(zk[followerA], States.CONNECTING); try { // 2. set force snapshot to be true LOG.info("force snapshot sync"); System.setProperty(LearnerHandler.FORCE_SNAP_SYNC, "true"); // 3. create a node String initialValue = "1"; final ZooKeeper leaderZk = zk[leaderId]; leaderZk.create(nodePath, initialValue.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); LOG.info("created node {} with value {}", nodePath, initialValue); CustomQuorumPeer leaderQuorumPeer = (CustomQuorumPeer) mt[leaderId].main.quorumPeer; // 4. on the customized leader catch the startForwarding call // (without synchronized), set the node to value v1, then // call the super.startForwarding to generate the ongoing // txn proposal and commit for v1 value update leaderQuorumPeer.setStartForwardingListener(new StartForwardingListener() { @Override public void start() { if (!Boolean.getBoolean(LearnerHandler.FORCE_SNAP_SYNC)) { return; } final String value = "2"; LOG.info("start forwarding, set {} to {}", nodePath, value); // use async, otherwise it will block the logLock in // ZKDatabase and the setData request will timeout try { leaderZk.setData(nodePath, value.getBytes(), -1, new AsyncCallback.StatCallback() { public void processResult(int rc, String path, Object ctx, Stat stat) { } }, null); // wait for the setData txn being populated Thread.sleep(1000); } catch (Exception e) { LOG.error("error when set {} to {}", nodePath, value, e); } } }); // 5. on the customized leader catch the beginSnapshot call in // LearnerSnapshotThrottler to set the node to value v2, // wait it hit data tree leaderQuorumPeer.setBeginSnapshotListener(new BeginSnapshotListener() { @Override public void start() { String value = "3"; LOG.info("before sending snapshot, set {} to {}", nodePath, value); try { leaderZk.setData(nodePath, value.getBytes(), -1); LOG.info("successfully set {} to {}", nodePath, value); } catch (Exception e) { LOG.error("error when set {} to {}, {}", nodePath, value, e); } } }); // 6. exit follower A after taking snapshot CustomQuorumPeer followerAQuorumPeer = ((CustomQuorumPeer) mt[followerA].main.quorumPeer); LOG.info("set exit when ack new leader packet on {}", followerA); contexts[followerA].exitWhenAckNewLeader = true; CountDownLatch latch = new CountDownLatch(1); final MainThread followerAMT = mt[followerA]; contexts[followerA].newLeaderAckCallback = new NewLeaderAckCallback() { @Override public void start() { try { latch.countDown(); followerAMT.shutdown(); } catch (Exception e) { } } }; // 7. start follower A to do snapshot sync LOG.info("starting follower {}", followerA); mt[followerA].start(); Assert.assertTrue(latch.await(30, TimeUnit.SECONDS)); // 8. now we have invalid data on disk, let's load it and verify LOG.info("disable exit when ack new leader packet on {}", followerA); System.setProperty(LearnerHandler.FORCE_SNAP_SYNC, "false"); contexts[followerA].exitWhenAckNewLeader = true; contexts[followerA].newLeaderAckCallback = null; LOG.info("restarting follower {}", followerA); mt[followerA].start(); zk[followerA].close(); zk[followerA] = new ZooKeeper("127.0.0.1:" + clientPorts[followerA], ClientBase.CONNECTION_TIMEOUT, this); // 9. start follower A, after it's in broadcast state, make sure // the node value is same as what we have on leader waitForOne(zk[followerA], States.CONNECTED); Assert.assertEquals(new String(zk[followerA].getData(nodePath, null, null)), new String(zk[leaderId].getData(nodePath, null, null))); } finally { System.clearProperty(LearnerHandler.FORCE_SNAP_SYNC); for (int i = 0; i < ENSEMBLE_SERVERS; i++) { mt[i].shutdown(); zk[i].close(); } } }
From source file:org.apache.solr.cloud.AbstractFullDistribZkTestBase.java
@Override @After//w ww .j a va 2 s. c o m public void tearDown() throws Exception { if (VERBOSE || printLayoutOnTearDown) { super.printLayout(); } if (commondCloudSolrServer != null) { commondCloudSolrServer.shutdown(); } if (controlClient != null) { ((HttpSolrServer) controlClient).shutdown(); } if (cloudClient != null) { cloudClient.shutdown(); } if (controlClientCloud != null) { controlClientCloud.shutdown(); } super.tearDown(); System.clearProperty("zkHost"); System.clearProperty("numShards"); }
From source file:de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordParserTest.java
@Test public void testModelSharing() throws Exception { // Save share override value (if any was set) and enable sharing for the StanfordParser String prop = "dkpro.core.resourceprovider.sharable." + StanfordParser.class.getName(); String oldValue = System.getProperty(prop); System.setProperty(prop, "true"); final List<LoggingEvent> records = new ArrayList<LoggingEvent>(); // Tell the logger to log everything Logger rootLogger = org.apache.log4j.LogManager.getRootLogger(); final org.apache.log4j.Level oldLevel = rootLogger.getLevel(); rootLogger.setLevel(org.apache.log4j.Level.ALL); Appender appender = (Appender) rootLogger.getAllAppenders().nextElement(); // Capture output, log only what would have passed the original logging level appender.addFilter(new org.apache.log4j.spi.Filter() { @Override/*w ww . j a v a 2 s . co m*/ public int decide(LoggingEvent event) { records.add(event); return event.getLevel().toInt() >= oldLevel.toInt() ? org.apache.log4j.spi.Filter.NEUTRAL : org.apache.log4j.spi.Filter.DENY; } }); try { AnalysisEngineDescription pipeline = createEngineDescription( createEngineDescription(StanfordParser.class, StanfordParser.PARAM_WRITE_CONSTITUENT, true, StanfordParser.PARAM_WRITE_DEPENDENCY, false), createEngineDescription(StanfordParser.class, StanfordParser.PARAM_WRITE_CONSTITUENT, false, StanfordParser.PARAM_WRITE_DEPENDENCY, true)); JCas jcas = TestRunner.runTest(pipeline, "en", "This is a test ."); boolean found = false; for (LoggingEvent e : records) { if (String.valueOf(e.getMessage()).contains("Used resource from cache")) { found = true; } } assertTrue("No log message about using the cached resource was found!", found); String[] dependencies = { "[ 0, 4]NSUBJ(nsubj,basic) D[0,4](This) G[10,14](test)", "[ 5, 7]COP(cop,basic) D[5,7](is) G[10,14](test)", "[ 8, 9]DET(det,basic) D[8,9](a) G[10,14](test)", "[ 10, 14]ROOT(root,basic) D[10,14](test) G[10,14](test)" }; AssertAnnotations.assertDependencies(dependencies, select(jcas, Dependency.class)); } finally { if (oldLevel != null) { rootLogger.setLevel(oldLevel); appender.clearFilters(); } if (oldValue != null) { System.setProperty(prop, oldValue); } else { System.clearProperty(prop); } } }
From source file:org.apache.solr.SolrTestCaseJ4.java
@AfterClass public static void unchooseMPForMP() { System.clearProperty(SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICYFACTORY); System.clearProperty(SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICY); }
From source file:org.apache.solr.SolrTestCaseJ4.java
@Deprecated // remove with SOLR-8668 protected static void systemClearPropertySolrTestsMergePolicy() { System.clearProperty(SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICY); }
From source file:org.apache.solr.SolrTestCaseJ4.java
protected static void systemClearPropertySolrTestsMergePolicyFactory() { System.clearProperty(SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICYFACTORY); }
From source file:org.jbpm.bpmn2.IntermediateEventTest.java
@Test(timeout = 10000) public void testEventBasedSplitWithCronTimerAndSignal() throws Exception { System.setProperty("jbpm.enable.multi.con", "true"); try {/*from ww w.ja va2s . c o m*/ NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener( "Request photos of order in use", 1); NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener( "Request an online review", 1); NodeLeftCountDownProcessEventListener countDownListener3 = new NodeLeftCountDownProcessEventListener( "Send a thank you card", 1); NodeLeftCountDownProcessEventListener countDownListener4 = new NodeLeftCountDownProcessEventListener( "Request an online review", 1); KieBase kbase = createKnowledgeBase("timer/BPMN2-CronTimerWithEventBasedGateway.bpmn2"); ksession = createKnowledgeSession(kbase); TestWorkItemHandler handler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); ksession.addEventListener(countDownListener); ksession.addEventListener(countDownListener2); ksession.addEventListener(countDownListener3); ksession.addEventListener(countDownListener4); ProcessInstance processInstance = ksession.startProcess("timerWithEventBasedGateway"); assertProcessInstanceActive(processInstance.getId(), ksession); countDownListener.waitTillCompleted(); logger.debug("First timer triggered"); countDownListener2.waitTillCompleted(); logger.debug("Second timer triggered"); countDownListener3.waitTillCompleted(); logger.debug("Third timer triggered"); countDownListener4.waitTillCompleted(); logger.debug("Fourth timer triggered"); List<WorkItem> wi = handler.getWorkItems(); assertThat(wi).isNotNull(); assertThat(wi.size()).isEqualTo(3); ksession.abortProcessInstance(processInstance.getId()); } finally { // clear property only as the only relevant value is when it's set to true System.clearProperty("jbpm.enable.multi.con"); } }
From source file:com.cisco.dvbu.ps.deploytool.services.VCSManagerImpl.java
private static void clearVCSConnectionProperties() { // Only clear the Java Environment when the non-V2 methods are being invoked if (!vcsV2Method) { String oldProp = null;/*from w w w . j a va2 s . co m*/ // VCS_TYPE oldProp = System.clearProperty("VCS_TYPE"); // VCS_BASE_TYPE oldProp = System.clearProperty("VCS_BASE_TYPE"); // VCS_HOME oldProp = System.clearProperty("VCS_HOME"); // VCS_COMMAND oldProp = System.clearProperty("VCS_COMMAND"); // VCS_EXEC_FULL_PATH oldProp = System.clearProperty("VCS_EXEC_FULL_PATH"); // VCS_REPOSITORY_URL oldProp = System.clearProperty("VCS_REPOSITORY_URL"); // VCS_PROJECT_ROOT oldProp = System.clearProperty("VCS_PROJECT_ROOT"); // VCS_WORKSPACE_HOME oldProp = System.clearProperty("VCS_WORKSPACE_HOME"); // VCS_WORKSPACE_DIR oldProp = System.clearProperty("VCS_WORKSPACE_NAME"); // VCS_WORKSPACE_DIR oldProp = System.clearProperty("VCS_WORKSPACE_DIR"); // VCS_TEMP_DIR oldProp = System.clearProperty("VCS_TEMP_DIR"); // VCS_OPTIONS oldProp = System.clearProperty("VCS_OPTIONS"); // VCS_WORKSPACE_INIT_NEW_OPTIONS oldProp = System.clearProperty("VCS_WORKSPACE_INIT_NEW_OPTIONS"); // VCS_WORKSPACE_INIT_LINK_OPTIONS oldProp = System.clearProperty("VCS_WORKSPACE_INIT_LINK_OPTIONS"); // VCS_WORKSPACE_INIT_GET_OPTIONS oldProp = System.clearProperty("VCS_WORKSPACE_INIT_GET_OPTIONS"); // VCS_BASE_FOLDER_INIT_ADD oldProp = System.clearProperty("VCS_BASE_FOLDER_INIT_ADD"); // VCS_CHECKIN_OPTIONS oldProp = System.clearProperty("VCS_CHECKIN_OPTIONS"); // VCS_CHECKIN_OPTIONS_REQUIRED oldProp = System.clearProperty("VCS_CHECKIN_OPTIONS_REQUIRED"); // VCS_CHECKOUT_OPTIONS oldProp = System.clearProperty("VCS_CHECKOUT_OPTIONS"); // VCS_CHECKOUT_OPTIONS_REQUIRED oldProp = System.clearProperty("VCS_CHECKOUT_OPTIONS_REQUIRED"); // VCS_CIS_IMPORT_OPTIONS oldProp = System.clearProperty("VCS_CIS_IMPORT_OPTIONS"); // VCS_CIS_EXPORT_OPTIONS oldProp = System.clearProperty("VCS_CIS_EXPORT_OPTIONS"); // VCS_USERNAME oldProp = System.clearProperty("VCS_USERNAME"); // VCS_PASSWORD oldProp = System.clearProperty("VCS_PASSWORD"); // VCS_IGNORE_MESSAGES oldProp = System.clearProperty("VCS_IGNORE_MESSAGES"); // VCS_MESSAGE_PREPEND oldProp = System.clearProperty("VCS_MESSAGE_PREPEND"); // TFS_SERVER_URL oldProp = System.clearProperty("TFS_SERVER_URL"); // VCS_MESSAGE_MANDATORY /* 3-7-2012: may not need oldProp = System.clearProperty("VCS_MESSAGE_MANDATORY"); */ } }