Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/LeaseRenewDurRFE.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/LeaseRenewDurRFE.java?rev=1634322&r1=1634321&r2=1634322&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/LeaseRenewDurRFE.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/LeaseRenewDurRFE.java Sun Oct 26 13:17:28 2014 @@ -548,12 +548,16 @@ public class LeaseRenewDurRFE extends Ab /* First wait the lease duration */ try{ Thread.sleep(leaseDur[v]); - } catch(InterruptedException e) { } + } catch(InterruptedException e) { + Thread.currentThread().interrupt(); + } /* Wait a delta amount to account for communication latency */ boolean leaseExpired = false; int i = 0; while( !leaseExpired && (i < rfeDelta) ) { - try{ Thread.sleep(1000); } catch(InterruptedException e) {} + try{ Thread.sleep(1000); } catch(InterruptedException e) { + Thread.currentThread().interrupt(); + } i = i+1; if(sdm.lookup(tmpl[v],null) == null) leaseExpired = true; }//end loop
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/RaceAttrsVsTerminateISE.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/RaceAttrsVsTerminateISE.java?rev=1634322&r1=1634321&r2=1634322&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/RaceAttrsVsTerminateISE.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/joinmanager/RaceAttrsVsTerminateISE.java Sun Oct 26 13:17:28 2014 @@ -1,126 +1,128 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.sun.jini.test.impl.joinmanager; - -import com.sun.jini.qa.harness.QAConfig; -import com.sun.jini.qa.harness.Test; -import com.sun.jini.test.spec.joinmanager.AbstractBaseTest; -import java.util.List; -import net.jini.lookup.JoinManager; - -import java.util.logging.Level; - -/** Regression test for bug #4953710 (ISE = IllegalStateException). - * - * This test should be run manually against an instrumented JoinManager - * to test for regression. When run in automatic mode against an - * uninstrumented JoinManager, this should always pass. See the run() - * method documentation below for information on how to instrument - * JoinManager for this test. - * - * It is not necessary to run this under all configurations. - * - * See bug ID 4953710: JoinManager - race when terminate is called after - * attribute mutator methods (ex. setAttributes). - */ -public class RaceAttrsVsTerminateISE extends AbstractBaseTest { - - private JoinManager jm; - - /** Performs actions necessary to prepare for execution of the - * current test as follows: - * <p><ul> - * <li> starts N lookup service(s) whose member groups are finite - * and unique relative to the member groups of all other lookup - * services running within the same multicast radius of the new - * lookup services - * <li> creates an instance of JoinManager inputting an instance of - * a test service, a set of attributes (either null or non-null) - * with which to register the service, and a non-null instance - * of a lookup discovery manager configured to discover the - * lookup services started in the previous step - * </ul> - */ - public Test construct(QAConfig sysConfig) throws Exception { - super.construct(sysConfig); - newServiceAttrs = - removeDups( addAttrsDup1DupAll(serviceAttrs,newServiceAttrs) ); - /* Discover & join lookups just started */ - jm = new JoinManager(testService,serviceAttrs,serviceID, - getLookupDiscoveryManager(),leaseMgr, - sysConfig.getConfiguration()); - return this; - }//end construct - - /** Call one of the attribute mutator methods, delay N seconds, and then - * terminate the JoinManager to test for regression. Regression occurs - * if an IllegalStateException (caused by an UnmarshalException, which - * is caused by an IOException from a thread interrupt) is encountered - * and logged; thus, this test should be manually run and the output - * should be visually inspected for a stack trace containing - * IllegalStateException. - * - * Note that in order to create the conditions that can result in - * an IllegalStateException, the JoinManager must be instrumented, - * and the test must be run, in the following way: - * - * 1. Place a 5 second delay in JoinManager.setAttributes, just prior - * to the call to srvcRegistration.setAttributes(attSet) - * 2. Use the instrumented JoinManager to register a service with a - * lookup service and then call setAttributes() (or addAttributes() - * or modifyAttributes()), delay 5 seconds (probably best to delay - * the same amount of time as in the JoinManager), then call - * terminate(). - * - * Without the bug fix in JoinManager, this should cause a stack trace - * originating in the WakeupManager to be displayed. - */ - public void run() throws Exception { - /* Verify all lookups are discovered */ - List lookupsStarted = getLookupServices().getLookupsStarted(); - mainListener.setLookupsToDiscover(lookupsStarted, - toGroupsArray(lookupsStarted)); - waitForDiscovery(mainListener); - logger.log(Level.INFO, "discovery verified: discovered " - +curLookupListSize("RaceAttrsVsTerminateISE.run") - +" lookup service(s)"); - /* Verify service has joined all lookups */ - verifyJoin(); - logger.log(Level.INFO, "join verified: joined " - +curLookupListSize("RaceAttrsVsTerminateISE.run") - +" lookup service(s)"); - /* Verify initial attributes are registered with all lookups */ - verifyPropagation(serviceAttrs); - logger.log(Level.INFO, "initial attributes verified: registered with " - +curLookupListSize("RegisterAttributes.run") - +" lookup service(s)"); - /* Call setAttributes(), delay, then call terminate() */ - long nMS = 5*1000; - - logger.log(Level.INFO, "JoinManager.setAttributes"); - jm.setAttributes(newServiceAttrs); - - logger.log(Level.INFO, "Delay "+(nMS/1000)+" seconds"); - try { Thread.sleep(nMS); } catch (InterruptedException e) { } - - logger.log(Level.INFO, "JoinManager.terminate"); - jm.terminate(); - }//end run - -}//end class RaceAttrsVsTerminateISE +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.sun.jini.test.impl.joinmanager; + +import com.sun.jini.qa.harness.QAConfig; +import com.sun.jini.qa.harness.Test; +import com.sun.jini.test.spec.joinmanager.AbstractBaseTest; +import java.util.List; +import net.jini.lookup.JoinManager; + +import java.util.logging.Level; + +/** Regression test for bug #4953710 (ISE = IllegalStateException). + * + * This test should be run manually against an instrumented JoinManager + * to test for regression. When run in automatic mode against an + * uninstrumented JoinManager, this should always pass. See the run() + * method documentation below for information on how to instrument + * JoinManager for this test. + * + * It is not necessary to run this under all configurations. + * + * See bug ID 4953710: JoinManager - race when terminate is called after + * attribute mutator methods (ex. setAttributes). + */ +public class RaceAttrsVsTerminateISE extends AbstractBaseTest { + + private JoinManager jm; + + /** Performs actions necessary to prepare for execution of the + * current test as follows: + * <p><ul> + * <li> starts N lookup service(s) whose member groups are finite + * and unique relative to the member groups of all other lookup + * services running within the same multicast radius of the new + * lookup services + * <li> creates an instance of JoinManager inputting an instance of + * a test service, a set of attributes (either null or non-null) + * with which to register the service, and a non-null instance + * of a lookup discovery manager configured to discover the + * lookup services started in the previous step + * </ul> + */ + public Test construct(QAConfig sysConfig) throws Exception { + super.construct(sysConfig); + newServiceAttrs = + removeDups( addAttrsDup1DupAll(serviceAttrs,newServiceAttrs) ); + /* Discover & join lookups just started */ + jm = new JoinManager(testService,serviceAttrs,serviceID, + getLookupDiscoveryManager(),leaseMgr, + sysConfig.getConfiguration()); + return this; + }//end construct + + /** Call one of the attribute mutator methods, delay N seconds, and then + * terminate the JoinManager to test for regression. Regression occurs + * if an IllegalStateException (caused by an UnmarshalException, which + * is caused by an IOException from a thread interrupt) is encountered + * and logged; thus, this test should be manually run and the output + * should be visually inspected for a stack trace containing + * IllegalStateException. + * + * Note that in order to create the conditions that can result in + * an IllegalStateException, the JoinManager must be instrumented, + * and the test must be run, in the following way: + * + * 1. Place a 5 second delay in JoinManager.setAttributes, just prior + * to the call to srvcRegistration.setAttributes(attSet) + * 2. Use the instrumented JoinManager to register a service with a + * lookup service and then call setAttributes() (or addAttributes() + * or modifyAttributes()), delay 5 seconds (probably best to delay + * the same amount of time as in the JoinManager), then call + * terminate(). + * + * Without the bug fix in JoinManager, this should cause a stack trace + * originating in the WakeupManager to be displayed. + */ + public void run() throws Exception { + /* Verify all lookups are discovered */ + List lookupsStarted = getLookupServices().getLookupsStarted(); + mainListener.setLookupsToDiscover(lookupsStarted, + toGroupsArray(lookupsStarted)); + waitForDiscovery(mainListener); + logger.log(Level.INFO, "discovery verified: discovered " + +curLookupListSize("RaceAttrsVsTerminateISE.run") + +" lookup service(s)"); + /* Verify service has joined all lookups */ + verifyJoin(); + logger.log(Level.INFO, "join verified: joined " + +curLookupListSize("RaceAttrsVsTerminateISE.run") + +" lookup service(s)"); + /* Verify initial attributes are registered with all lookups */ + verifyPropagation(serviceAttrs); + logger.log(Level.INFO, "initial attributes verified: registered with " + +curLookupListSize("RegisterAttributes.run") + +" lookup service(s)"); + /* Call setAttributes(), delay, then call terminate() */ + long nMS = 5*1000; + + logger.log(Level.INFO, "JoinManager.setAttributes"); + jm.setAttributes(newServiceAttrs); + + logger.log(Level.INFO, "Delay "+(nMS/1000)+" seconds"); + try { Thread.sleep(nMS); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + + logger.log(Level.INFO, "JoinManager.terminate"); + jm.terminate(); + }//end run + +}//end class RaceAttrsVsTerminateISE Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mahalo/RandomStressTest.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mahalo/RandomStressTest.java?rev=1634322&r1=1634321&r2=1634322&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mahalo/RandomStressTest.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mahalo/RandomStressTest.java Sun Oct 26 13:17:28 2014 @@ -241,7 +241,9 @@ public class RandomStressTest extends Tx try { Thread.sleep(sleep_time); - } catch (InterruptedException ie) {} + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + } } if (!allComplete) { Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mahalo/TxnMgrImplNullRecoveredLocators.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mahalo/TxnMgrImplNullRecoveredLocators.java?rev=1634322&r1=1634321&r2=1634322&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mahalo/TxnMgrImplNullRecoveredLocators.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mahalo/TxnMgrImplNullRecoveredLocators.java Sun Oct 26 13:17:28 2014 @@ -1,150 +1,151 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.jini.test.impl.mahalo; - -import java.util.logging.Level; - -import com.sun.jini.qa.harness.QAConfig; -import com.sun.jini.qa.harness.QATestEnvironment; -import net.jini.config.ConfigurationException; -import com.sun.jini.start.ServiceStarter; -import com.sun.jini.start.SharedGroup; -import com.sun.jini.qa.harness.OverrideProvider; -import com.sun.jini.qa.harness.TestException; -import com.sun.jini.qa.harness.QAConfig; -import com.sun.jini.qa.harness.Test; -import com.sun.jini.qa.harness.VMKiller; - -import java.io.*; -import java.rmi.*; -import java.util.*; - -import net.jini.core.transaction.server.TransactionManager; - -/** - * Verifies that proxies for the same shared group service - * are equal and that proxies for different shared groups - * are not equal - */ - -public class TxnMgrImplNullRecoveredLocators extends QATestEnvironment implements Test { - - private static class OverrideGenerator implements OverrideProvider { - - public String[] getOverrides(QAConfig config, - String servicePrefix, - int index) throws TestException - { - String[] ret = new String[0]; - if (servicePrefix == null) { // check for test override - return ret; - } - String override = - config.getServiceStringProperty(servicePrefix, - "override", - index); - logger.log(Level.INFO, - "getOverrides for " + servicePrefix + "." + index); - if (override != null) { - StringTokenizer st = new StringTokenizer(override, "|"); - String token; - ArrayList pairs = new ArrayList(); - while(st.hasMoreTokens()) { - token = st.nextToken(); - int eq = token.indexOf('='); - if (eq == -1) { - throw new IllegalArgumentException("override missing " - + "'=' character: " + - token); - } - pairs.add(token.substring(0, eq)); - pairs.add(token.substring(eq + 1)); - } - logger.log(Level.INFO, "getOverrides returning " + pairs); - ret = (String[])pairs.toArray(new String[pairs.size()]); - } - return ret; - } - } - - public Test construct(QAConfig sysConfig) throws Exception { - super.construct(sysConfig); - sysConfig.addOverrideProvider(new OverrideGenerator()); - return this; - } - - public void run() throws Exception { - logger.log(Level.INFO, "run()"); - - TransactionManager txn_mgr_proxy = null; - final String serviceName = - "net.jini.core.transaction.server.TransactionManager"; - try { - txn_mgr_proxy = - (TransactionManager)getManager().startService(serviceName); - if (!getManager().killVM(txn_mgr_proxy)) { - logger.log(Level.INFO, "Could not kill " + serviceName); - } - - // get delay in seconds - int killDelay = getConfig().getIntConfigVal( - "com.sun.jini.qa.harness.killvm.delay", 15); - - if (killDelay < 0) { - killDelay = 15; - } - - // Allow service time to auto-restart, which should fail - try { - Thread.sleep(killDelay * 1000); - } catch (InterruptedException ie) { - logger.log(Level.INFO, "Sleep was interrupted"); - //ignore - } - } catch (Exception e) { - e.printStackTrace(); - throw new TestException("Caught unexpected exception: " + e); - } - try { - /* - * Should recover locators upon startup and try to - * use null recovered locator preparer. - */ - txn_mgr_proxy.create(1000); - throw new TestException("Restarted service with " - + "invalid configuration"); - } catch (Throwable e) { - e.printStackTrace(); - if (!verifyConfigurationException(e)) { - throw new TestException("Service failed due to " - + "non-configuration related exception."); - } - logger.log(Level.INFO, "Caught expected exception"); - } - return; - } - - private static boolean verifyConfigurationException(Throwable e) { - Throwable cause = e; - while (cause.getCause() != null) { - cause = cause.getCause(); - } - return (cause instanceof ConfigurationException); - } -} - +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.jini.test.impl.mahalo; + +import java.util.logging.Level; + +import com.sun.jini.qa.harness.QAConfig; +import com.sun.jini.qa.harness.QATestEnvironment; +import net.jini.config.ConfigurationException; +import com.sun.jini.start.ServiceStarter; +import com.sun.jini.start.SharedGroup; +import com.sun.jini.qa.harness.OverrideProvider; +import com.sun.jini.qa.harness.TestException; +import com.sun.jini.qa.harness.QAConfig; +import com.sun.jini.qa.harness.Test; +import com.sun.jini.qa.harness.VMKiller; + +import java.io.*; +import java.rmi.*; +import java.util.*; + +import net.jini.core.transaction.server.TransactionManager; + +/** + * Verifies that proxies for the same shared group service + * are equal and that proxies for different shared groups + * are not equal + */ + +public class TxnMgrImplNullRecoveredLocators extends QATestEnvironment implements Test { + + private static class OverrideGenerator implements OverrideProvider { + + public String[] getOverrides(QAConfig config, + String servicePrefix, + int index) throws TestException + { + String[] ret = new String[0]; + if (servicePrefix == null) { // check for test override + return ret; + } + String override = + config.getServiceStringProperty(servicePrefix, + "override", + index); + logger.log(Level.INFO, + "getOverrides for " + servicePrefix + "." + index); + if (override != null) { + StringTokenizer st = new StringTokenizer(override, "|"); + String token; + ArrayList pairs = new ArrayList(); + while(st.hasMoreTokens()) { + token = st.nextToken(); + int eq = token.indexOf('='); + if (eq == -1) { + throw new IllegalArgumentException("override missing " + + "'=' character: " + + token); + } + pairs.add(token.substring(0, eq)); + pairs.add(token.substring(eq + 1)); + } + logger.log(Level.INFO, "getOverrides returning " + pairs); + ret = (String[])pairs.toArray(new String[pairs.size()]); + } + return ret; + } + } + + public Test construct(QAConfig sysConfig) throws Exception { + super.construct(sysConfig); + sysConfig.addOverrideProvider(new OverrideGenerator()); + return this; + } + + public void run() throws Exception { + logger.log(Level.INFO, "run()"); + + TransactionManager txn_mgr_proxy = null; + final String serviceName = + "net.jini.core.transaction.server.TransactionManager"; + try { + txn_mgr_proxy = + (TransactionManager)getManager().startService(serviceName); + if (!getManager().killVM(txn_mgr_proxy)) { + logger.log(Level.INFO, "Could not kill " + serviceName); + } + + // get delay in seconds + int killDelay = getConfig().getIntConfigVal( + "com.sun.jini.qa.harness.killvm.delay", 15); + + if (killDelay < 0) { + killDelay = 15; + } + + // Allow service time to auto-restart, which should fail + try { + Thread.sleep(killDelay * 1000); + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + logger.log(Level.INFO, "Sleep was interrupted"); + //ignore + } + } catch (Exception e) { + e.printStackTrace(); + throw new TestException("Caught unexpected exception: " + e); + } + try { + /* + * Should recover locators upon startup and try to + * use null recovered locator preparer. + */ + txn_mgr_proxy.create(1000); + throw new TestException("Restarted service with " + + "invalid configuration"); + } catch (Throwable e) { + e.printStackTrace(); + if (!verifyConfigurationException(e)) { + throw new TestException("Service failed due to " + + "non-configuration related exception."); + } + logger.log(Level.INFO, "Caught expected exception"); + } + return; + } + + private static boolean verifyConfigurationException(Throwable e) { + Throwable cause = e; + while (cause.getCause() != null) { + cause = cause.getCause(); + } + return (cause instanceof ConfigurationException); + } +} + Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/EMSTestBase.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/EMSTestBase.java?rev=1634322&r1=1634321&r2=1634322&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/EMSTestBase.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/EMSTestBase.java Sun Oct 26 13:17:28 2014 @@ -1,208 +1,212 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.jini.test.impl.mercury; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.logging.Level; - -import java.rmi.RemoteException; - -import com.sun.jini.constants.TimeConstants; - -import net.jini.core.event.RemoteEvent; -import net.jini.event.EventMailbox; -import net.jini.event.MailboxRegistration; -import net.jini.event.MailboxPullRegistration; -import net.jini.core.lease.Lease; -import net.jini.core.event.RemoteEventListener; -import net.jini.space.JavaSpace; - -import com.sun.jini.qa.harness.TestException; - - -public abstract class EMSTestBase extends MailboxTestBase { - - public void assertCount(TestListener tl, long desired) throws TestException { - long evCnt = 0; - try { - evCnt = tl.getEventCount(); - } catch (Exception e) { - throw new TestException ("Unexpected exception while " - + "getting event count", e); - } - if (evCnt != desired) { - throw new TestException ("Unexpected event count of " + evCnt + - " when expecting count of " + desired); - } - } - - public void assertCount(TestPullListener tpl, long desired) - throws TestException - { - long evCnt = 0; - try { - evCnt = tpl.getCollectedRemoteEventsSize(); - } catch (Exception e) { - throw new TestException ("Unexpected exception while " - + "getting event count", e); - } - if (evCnt != desired) { - throw new TestException ("Unexpected event count of " + evCnt + - " when expecting count of " + desired); - } - } - - public void getCollectedRemoteEvents( - TestPullListener tpl, MailboxPullRegistration mr, - int desired, long maxDelay) - throws Exception - { - long start = System.currentTimeMillis(); - boolean done = false; - // Collect new events, if any - Collection events = tpl.getRemoteEvents(mr); - while (!done) { - if (tpl.getCollectedRemoteEventsSize() >= desired) { - done = true; - } else if (getTime() - start >= maxDelay) { - done = true; - } else { - try { - // Sleep one second between checks - Thread.sleep(1000); -// Thread.yield(); //Give someone else a chance - } catch (InterruptedException ie) { /* ignore */ } - } - events = tpl.getRemoteEvents(mr); - } - /** - * Would like to check event source for the proper "type". - * Our test generator can be tested for "instanceof TestGenerator", but - * the JavaSpace source is of type "OutriggerServer" and "JavaSpace". - * So, rather than introduce "private" classes, we'll defer the - * source checking to verifyEvents. - **/ - } - - - public void waitForEvents(TestListener tl, int desired, long maxDelay) - throws RemoteException - { - long start = System.currentTimeMillis(); - boolean done = false; - while (!done) { - try { - // Sleep one second between checks - Thread.sleep(1000); - } catch (InterruptedException ie) { /* ignore */ } - - long received = tl.getEventCount(); - if (received >= desired) - done = true; - else if (getTime() - start >= maxDelay) - done = true; - else if ((received % ((desired / 10) + 1)) == 0) { - // output log msg for every 1/10th of desired events - logger.log(Level.FINE, Thread.currentThread().getName() - + " has received " + received + " events."); - } - -// Thread.yield(); //Give someone else a chance - } - } - - protected void assertEvents(TestListener tl, RemoteEvent[] events) - throws RemoteException, TestException - { - if (tl.verifyEvents(events) == false) { - throw new TestException ("Failed to verify event set"); - } - } - protected void assertEvent(TestListener tl, RemoteEvent event) - throws RemoteException, TestException - { - if (tl.verifyEvent(event) == false) { - throw new TestException ("Failed to verify event"); - } - } - protected void assertEvents(TestPullListener tpl, RemoteEvent[] events) - throws RemoteException, TestException - { - if (tpl.verifyEvents(events) == false) { - throw new TestException ("Failed to verify event set"); - } - } - protected void assertEvent(TestPullListener tpl, RemoteEvent event) - throws RemoteException, TestException - { - if (tpl.verifyEvent(event) == false) { - throw new TestException ("Failed to verify event"); - } - } - - protected void assertEvents(Collection src, Collection tgt) - throws RemoteException, TestException - { - int i = 0; - RemoteEvent[] sent = (RemoteEvent[]) src.toArray(new RemoteEvent[0]); - ArrayList srcList = new ArrayList(sent.length); - for (i=0; i < sent.length; i++) { - srcList.add(new RemoteEventHandle(sent[i])); - } - - RemoteEvent[] rcvd = (RemoteEvent[]) tgt.toArray(new RemoteEvent[0]); - ArrayList tgtList = new ArrayList(rcvd.length); - for (i=0; i < rcvd.length; i++) { - tgtList.add(new RemoteEventHandle(rcvd[i])); - } - if (!srcList.containsAll(tgtList)) { - throw new TestException("Expected events not received."); - } - } - - protected void assertEvent(RemoteEvent src, RemoteEvent tgt) - throws RemoteException, TestException - { - if (!new RemoteEventHandle(src).equals(new RemoteEventHandle(tgt))) { - throw new TestException("Expected event doesn't match"); - } - } - - protected long getTime() { - return System.currentTimeMillis(); - } - - protected static java.util.ArrayList getClassLoaderTree(ClassLoader classloader) { - java.util.ArrayList loaderList = new java.util.ArrayList(); - while(classloader != null) { - loaderList.add(classloader); - final ClassLoader myClassLoader = classloader; - classloader = (ClassLoader) - java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { - public Object run() { - return myClassLoader.getParent(); - } - }); - }//end loop - loaderList.add(null); //Append boot classloader - java.util.Collections.reverse(loaderList); - return loaderList; - }//end getClassLoaderTree - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.jini.test.impl.mercury; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.logging.Level; + +import java.rmi.RemoteException; + +import com.sun.jini.constants.TimeConstants; + +import net.jini.core.event.RemoteEvent; +import net.jini.event.EventMailbox; +import net.jini.event.MailboxRegistration; +import net.jini.event.MailboxPullRegistration; +import net.jini.core.lease.Lease; +import net.jini.core.event.RemoteEventListener; +import net.jini.space.JavaSpace; + +import com.sun.jini.qa.harness.TestException; + + +public abstract class EMSTestBase extends MailboxTestBase { + + public void assertCount(TestListener tl, long desired) throws TestException { + long evCnt = 0; + try { + evCnt = tl.getEventCount(); + } catch (Exception e) { + throw new TestException ("Unexpected exception while " + + "getting event count", e); + } + if (evCnt != desired) { + throw new TestException ("Unexpected event count of " + evCnt + + " when expecting count of " + desired); + } + } + + public void assertCount(TestPullListener tpl, long desired) + throws TestException + { + long evCnt = 0; + try { + evCnt = tpl.getCollectedRemoteEventsSize(); + } catch (Exception e) { + throw new TestException ("Unexpected exception while " + + "getting event count", e); + } + if (evCnt != desired) { + throw new TestException ("Unexpected event count of " + evCnt + + " when expecting count of " + desired); + } + } + + public void getCollectedRemoteEvents( + TestPullListener tpl, MailboxPullRegistration mr, + int desired, long maxDelay) + throws Exception + { + long start = System.currentTimeMillis(); + boolean done = false; + // Collect new events, if any + Collection events = tpl.getRemoteEvents(mr); + while (!done) { + if (tpl.getCollectedRemoteEventsSize() >= desired) { + done = true; + } else if (getTime() - start >= maxDelay) { + done = true; + } else { + try { + // Sleep one second between checks + Thread.sleep(1000); +// Thread.yield(); //Give someone else a chance + } catch (InterruptedException ie) { /* ignore */ + Thread.currentThread().interrupt(); + } + } + events = tpl.getRemoteEvents(mr); + } + /** + * Would like to check event source for the proper "type". + * Our test generator can be tested for "instanceof TestGenerator", but + * the JavaSpace source is of type "OutriggerServer" and "JavaSpace". + * So, rather than introduce "private" classes, we'll defer the + * source checking to verifyEvents. + **/ + } + + + public void waitForEvents(TestListener tl, int desired, long maxDelay) + throws RemoteException + { + long start = System.currentTimeMillis(); + boolean done = false; + while (!done) { + try { + // Sleep one second between checks + Thread.sleep(1000); + } catch (InterruptedException ie) { /* ignore */ + Thread.currentThread().interrupt(); + } + + long received = tl.getEventCount(); + if (received >= desired) + done = true; + else if (getTime() - start >= maxDelay) + done = true; + else if ((received % ((desired / 10) + 1)) == 0) { + // output log msg for every 1/10th of desired events + logger.log(Level.FINE, Thread.currentThread().getName() + + " has received " + received + " events."); + } + +// Thread.yield(); //Give someone else a chance + } + } + + protected void assertEvents(TestListener tl, RemoteEvent[] events) + throws RemoteException, TestException + { + if (tl.verifyEvents(events) == false) { + throw new TestException ("Failed to verify event set"); + } + } + protected void assertEvent(TestListener tl, RemoteEvent event) + throws RemoteException, TestException + { + if (tl.verifyEvent(event) == false) { + throw new TestException ("Failed to verify event"); + } + } + protected void assertEvents(TestPullListener tpl, RemoteEvent[] events) + throws RemoteException, TestException + { + if (tpl.verifyEvents(events) == false) { + throw new TestException ("Failed to verify event set"); + } + } + protected void assertEvent(TestPullListener tpl, RemoteEvent event) + throws RemoteException, TestException + { + if (tpl.verifyEvent(event) == false) { + throw new TestException ("Failed to verify event"); + } + } + + protected void assertEvents(Collection src, Collection tgt) + throws RemoteException, TestException + { + int i = 0; + RemoteEvent[] sent = (RemoteEvent[]) src.toArray(new RemoteEvent[0]); + ArrayList srcList = new ArrayList(sent.length); + for (i=0; i < sent.length; i++) { + srcList.add(new RemoteEventHandle(sent[i])); + } + + RemoteEvent[] rcvd = (RemoteEvent[]) tgt.toArray(new RemoteEvent[0]); + ArrayList tgtList = new ArrayList(rcvd.length); + for (i=0; i < rcvd.length; i++) { + tgtList.add(new RemoteEventHandle(rcvd[i])); + } + if (!srcList.containsAll(tgtList)) { + throw new TestException("Expected events not received."); + } + } + + protected void assertEvent(RemoteEvent src, RemoteEvent tgt) + throws RemoteException, TestException + { + if (!new RemoteEventHandle(src).equals(new RemoteEventHandle(tgt))) { + throw new TestException("Expected event doesn't match"); + } + } + + protected long getTime() { + return System.currentTimeMillis(); + } + + protected static java.util.ArrayList getClassLoaderTree(ClassLoader classloader) { + java.util.ArrayList loaderList = new java.util.ArrayList(); + while(classloader != null) { + loaderList.add(classloader); + final ClassLoader myClassLoader = classloader; + classloader = (ClassLoader) + java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { + public Object run() { + return myClassLoader.getParent(); + } + }); + }//end loop + loaderList.add(null); //Append boot classloader + java.util.Collections.reverse(loaderList); + return loaderList; + }//end getClassLoaderTree + +} Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/PullTimeoutTest.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/PullTimeoutTest.java?rev=1634322&r1=1634321&r2=1634322&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/PullTimeoutTest.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/PullTimeoutTest.java Sun Oct 26 13:17:28 2014 @@ -1,293 +1,294 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.jini.test.impl.mercury; - -import java.util.logging.Level; - -import java.rmi.RemoteException; -import java.rmi.NoSuchObjectException; -import java.rmi.ServerException; -import java.util.Date; -import java.util.ArrayList; -import java.util.logging.Logger; - - -import net.jini.event.InvalidIteratorException; -import net.jini.event.MailboxPullRegistration; -import net.jini.event.PullEventMailbox; -import net.jini.event.RemoteEventIterator; -import net.jini.core.lease.Lease; -import net.jini.core.event.EventRegistration; -import net.jini.core.event.RemoteEvent; -import net.jini.core.event.RemoteEventListener; -import net.jini.core.event.UnknownEventException; - -import com.sun.jini.constants.TimeConstants; - -import com.sun.jini.test.impl.mercury.EMSTestBase; -import com.sun.jini.test.impl.mercury.TestUtils; -import com.sun.jini.test.impl.mercury.TestListener; -import com.sun.jini.test.impl.mercury.TestGenerator; - -import com.sun.jini.qa.harness.QAConfig; -import com.sun.jini.qa.harness.Test; -import com.sun.jini.qa.harness.TestException; - -public class PullTimeoutTest - extends EMSTestBase implements TimeConstants -{ - - // - // This should be long enough to sensibly run the test. - // If the service doesn't grant long enough leases, then - // we might have to resort to using something like the - // LeaseRenewalManager to keep our leases current. - // - private final long DURATION1 = 3*HOURS; - - private final int NUM_EVENTS = 5; - - private final long EVENT_ID = 1234; - private final long EVENT_ID2 = 5678; - - private final long MAX_WAIT_GET_EVENT = 60 * 1000; - private final long MAX_WAIT_SEND_EVENT = MAX_WAIT_GET_EVENT / 4; - - class MyEventGeneratorRunnable implements Runnable { - final TestGenerator myGen; - final long evid; - final int maxTries; - final int numEvents; - final Logger logger; - final long delay; - MyEventGeneratorRunnable(TestGenerator myGen, long evid, int maxTries, - int numEvents, Logger logger, long delay) - { - this.myGen = myGen; - this.evid = evid; - this.maxTries = maxTries; - this.numEvents = numEvents; - this.logger = logger; - this.delay = delay; - } - public void run() { - try { - logger.log(Level.FINEST, - "MyEventGeneratorRunnable sleeping @ {0} for {1} ms", - new Object[] { new Date(), new Long(delay)}); - Thread.sleep(delay); - logger.log(Level.FINEST, - "MyEventGeneratorRunnable awoken @ {0}", new Date()); - } catch (InterruptedException ie) { - // ignore - logger.log(Level.FINEST, - "Sleep interrupted", ie); - } - for (int i = 0; i < numEvents; i++) { - try { - myGen.generateEvent(evid, maxTries); - logger.log(Level.FINEST, "Sent event @ {0}", new Date()); - } catch (RemoteException re) { - logger.log(Level.FINEST, - "Ignoring RemoteException from generating event", - re); - } catch (UnknownEventException uee) { - logger.log(Level.FINEST, - "Ignoring UnknownEventException from generating event", - uee); - } - } - } - } - - public void run() throws Exception { - logger.log(Level.INFO, "Starting up " + this.getClass().toString()); - - PullEventMailbox mb = getPullMailbox(); - int i = 0; - - // Register and check lease - MailboxPullRegistration mr = getPullRegistration(mb, DURATION1); - Lease mrl = getPullMailboxLease(mr); - checkLease(mrl, DURATION1); - - // Get the mailbox service provided listener - RemoteEventListener mbRel = getPullMailboxListener(mr); - - // Create an event generator and pass it the - // mailbox's remote event listener. - TestGenerator myGen = TestUtils.createGenerator(getManager()); - logger.log(Level.FINEST, - "Test generator class tree" - + getClassLoaderTree(myGen.getClass().getClassLoader())); - EventRegistration evtReg = - myGen.register(EVENT_ID, // Event ID to use - null, // handback - mbRel, // Notification target - DURATION1); // Lease duration - Lease tgl = evtReg.getLease(); - checkLease(tgl, DURATION1); - - // Create another event generator and pass it the - // mailbox's remote event listener. - TestGenerator myGen2 = TestUtils.createGenerator(getManager()); - logger.log(Level.FINEST, - "Test generator class tree" - + getClassLoaderTree(myGen2.getClass().getClassLoader())); - EventRegistration evtReg2 = - myGen2.register(EVENT_ID2, // Event ID to use - null, // handback - mbRel, // Notification target - DURATION1); // Lease duration - Lease tgl2 = evtReg2.getLease(); - checkLease(tgl2, DURATION1); - - // Get events and verify - logger.log(Level.INFO, "Getting events from empty mailbox."); - RemoteEventIterator rei = mr.getRemoteEvents(); - RemoteEvent rei_event; - Date before = new Date(); - logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); - rei_event = rei.next(MAX_WAIT_GET_EVENT); - Date after = new Date(); - logger.log(Level.INFO, "Returned from next() @ {0}", after); - //Verify that timeout was honored - long delta = after.getTime() - before.getTime(); - if (delta < MAX_WAIT_GET_EVENT) { - throw new TestException("Returned from next() before expected: " - + delta); - } - if (rei_event != null) { - throw new TestException( - "Received unexpected event from empty mailbox: " + rei_event); - } - - // Start event generator thread with a delay of MAX_WAIT_SEND_EVENT - Thread t = - new Thread( - new MyEventGeneratorRunnable(myGen, evtReg.getID(), 3, 1, - logger, MAX_WAIT_SEND_EVENT )); - t.start(); - before = new Date(); - logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); - rei_event = rei.next(MAX_WAIT_GET_EVENT); - after = new Date(); - //Verify that we returned before the timeout - delta = after.getTime() - before.getTime(); - logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", - new Object[] {after, new Long(delta)}); - if (delta >= MAX_WAIT_GET_EVENT) { - throw new TestException("Returned from next() after expected: " - + delta); - } else if (delta <= MAX_WAIT_SEND_EVENT) { - throw new TestException("Returned from next() before expected: " - + delta); - } - if (rei_event == null) { - throw new TestException( - "Did not receive expected event from mailbox."); - } - - //Generate a soon-to-be unknown event. - myGen.generateEvent(evtReg.getID(), 3); - - /* - * Add genereated event to unknown list and verify that they aren't - * subsequently received. - */ - ArrayList unknowns = new ArrayList(1); - unknowns.add(rei_event); - mr.addUnknownEvents(unknowns); - - before = new Date(); - logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); - rei_event = rei.next(MAX_WAIT_GET_EVENT); - after = new Date(); - //Verify that we returned after the timeout - delta = after.getTime() - before.getTime(); - logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", - new Object[] {after, new Long(delta)}); - if (delta < MAX_WAIT_GET_EVENT) { - throw new TestException("Returned from next() before expected: " - + delta); - } - if (rei_event != null) { - throw new TestException( - "Received unexpected event from mailbox: " + rei_event); - } - - // Start event generator thread with a delay of MAX_WAIT_SEND_EVENT - // from a "good" event source. - t = new Thread( - new MyEventGeneratorRunnable(myGen2, evtReg2.getID(), 3, 1, - logger, MAX_WAIT_SEND_EVENT )); - t.start(); - // Call with "infinite" timeout. - before = new Date(); - logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); - rei_event = rei.next(Long.MAX_VALUE); - after = new Date(); - delta = after.getTime() - before.getTime(); - logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", - new Object[] {after, new Long(delta)}); - if (delta <= MAX_WAIT_SEND_EVENT) { - throw new TestException("Returned from next() before expected: " - + delta); - } - /* - * No need to check delta > Long.MAX_VALUE since the test would - * have been interrupted well before then. - */ - if (rei_event == null) { - throw new TestException( - "Did not receive expected event from mailbox."); - } - - // Call with zero timeout. - before = new Date(); - logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); - rei_event = rei.next(0); - after = new Date(); - delta = after.getTime() - before.getTime(); - logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", - new Object[] {after, new Long(delta)}); - if (rei_event != null) { - throw new TestException( - "Received unexpected event from empty mailbox: " + rei_event); - } - - try { - rei.next(-1); - throw new TestException("Successfully called next() with -1"); - } catch (IllegalArgumentException iae) { - logger.log(Level.FINEST, - "Caught IllegalArgumentException -- expected", iae); - } - - } - /** - * Invoke parent's construct and parser - * @exception TestException will usually indicate an "unresolved" - * condition because at this point the test has not yet begun. - */ - public Test construct(QAConfig sysConfig) throws Exception { - super.construct(sysConfig); - parse(); - return this; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.jini.test.impl.mercury; + +import java.util.logging.Level; + +import java.rmi.RemoteException; +import java.rmi.NoSuchObjectException; +import java.rmi.ServerException; +import java.util.Date; +import java.util.ArrayList; +import java.util.logging.Logger; + + +import net.jini.event.InvalidIteratorException; +import net.jini.event.MailboxPullRegistration; +import net.jini.event.PullEventMailbox; +import net.jini.event.RemoteEventIterator; +import net.jini.core.lease.Lease; +import net.jini.core.event.EventRegistration; +import net.jini.core.event.RemoteEvent; +import net.jini.core.event.RemoteEventListener; +import net.jini.core.event.UnknownEventException; + +import com.sun.jini.constants.TimeConstants; + +import com.sun.jini.test.impl.mercury.EMSTestBase; +import com.sun.jini.test.impl.mercury.TestUtils; +import com.sun.jini.test.impl.mercury.TestListener; +import com.sun.jini.test.impl.mercury.TestGenerator; + +import com.sun.jini.qa.harness.QAConfig; +import com.sun.jini.qa.harness.Test; +import com.sun.jini.qa.harness.TestException; + +public class PullTimeoutTest + extends EMSTestBase implements TimeConstants +{ + + // + // This should be long enough to sensibly run the test. + // If the service doesn't grant long enough leases, then + // we might have to resort to using something like the + // LeaseRenewalManager to keep our leases current. + // + private final long DURATION1 = 3*HOURS; + + private final int NUM_EVENTS = 5; + + private final long EVENT_ID = 1234; + private final long EVENT_ID2 = 5678; + + private final long MAX_WAIT_GET_EVENT = 60 * 1000; + private final long MAX_WAIT_SEND_EVENT = MAX_WAIT_GET_EVENT / 4; + + class MyEventGeneratorRunnable implements Runnable { + final TestGenerator myGen; + final long evid; + final int maxTries; + final int numEvents; + final Logger logger; + final long delay; + MyEventGeneratorRunnable(TestGenerator myGen, long evid, int maxTries, + int numEvents, Logger logger, long delay) + { + this.myGen = myGen; + this.evid = evid; + this.maxTries = maxTries; + this.numEvents = numEvents; + this.logger = logger; + this.delay = delay; + } + public void run() { + try { + logger.log(Level.FINEST, + "MyEventGeneratorRunnable sleeping @ {0} for {1} ms", + new Object[] { new Date(), new Long(delay)}); + Thread.sleep(delay); + logger.log(Level.FINEST, + "MyEventGeneratorRunnable awoken @ {0}", new Date()); + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + // ignore + logger.log(Level.FINEST, + "Sleep interrupted", ie); + } + for (int i = 0; i < numEvents; i++) { + try { + myGen.generateEvent(evid, maxTries); + logger.log(Level.FINEST, "Sent event @ {0}", new Date()); + } catch (RemoteException re) { + logger.log(Level.FINEST, + "Ignoring RemoteException from generating event", + re); + } catch (UnknownEventException uee) { + logger.log(Level.FINEST, + "Ignoring UnknownEventException from generating event", + uee); + } + } + } + } + + public void run() throws Exception { + logger.log(Level.INFO, "Starting up " + this.getClass().toString()); + + PullEventMailbox mb = getPullMailbox(); + int i = 0; + + // Register and check lease + MailboxPullRegistration mr = getPullRegistration(mb, DURATION1); + Lease mrl = getPullMailboxLease(mr); + checkLease(mrl, DURATION1); + + // Get the mailbox service provided listener + RemoteEventListener mbRel = getPullMailboxListener(mr); + + // Create an event generator and pass it the + // mailbox's remote event listener. + TestGenerator myGen = TestUtils.createGenerator(getManager()); + logger.log(Level.FINEST, + "Test generator class tree" + + getClassLoaderTree(myGen.getClass().getClassLoader())); + EventRegistration evtReg = + myGen.register(EVENT_ID, // Event ID to use + null, // handback + mbRel, // Notification target + DURATION1); // Lease duration + Lease tgl = evtReg.getLease(); + checkLease(tgl, DURATION1); + + // Create another event generator and pass it the + // mailbox's remote event listener. + TestGenerator myGen2 = TestUtils.createGenerator(getManager()); + logger.log(Level.FINEST, + "Test generator class tree" + + getClassLoaderTree(myGen2.getClass().getClassLoader())); + EventRegistration evtReg2 = + myGen2.register(EVENT_ID2, // Event ID to use + null, // handback + mbRel, // Notification target + DURATION1); // Lease duration + Lease tgl2 = evtReg2.getLease(); + checkLease(tgl2, DURATION1); + + // Get events and verify + logger.log(Level.INFO, "Getting events from empty mailbox."); + RemoteEventIterator rei = mr.getRemoteEvents(); + RemoteEvent rei_event; + Date before = new Date(); + logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); + rei_event = rei.next(MAX_WAIT_GET_EVENT); + Date after = new Date(); + logger.log(Level.INFO, "Returned from next() @ {0}", after); + //Verify that timeout was honored + long delta = after.getTime() - before.getTime(); + if (delta < MAX_WAIT_GET_EVENT) { + throw new TestException("Returned from next() before expected: " + + delta); + } + if (rei_event != null) { + throw new TestException( + "Received unexpected event from empty mailbox: " + rei_event); + } + + // Start event generator thread with a delay of MAX_WAIT_SEND_EVENT + Thread t = + new Thread( + new MyEventGeneratorRunnable(myGen, evtReg.getID(), 3, 1, + logger, MAX_WAIT_SEND_EVENT )); + t.start(); + before = new Date(); + logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); + rei_event = rei.next(MAX_WAIT_GET_EVENT); + after = new Date(); + //Verify that we returned before the timeout + delta = after.getTime() - before.getTime(); + logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", + new Object[] {after, new Long(delta)}); + if (delta >= MAX_WAIT_GET_EVENT) { + throw new TestException("Returned from next() after expected: " + + delta); + } else if (delta <= MAX_WAIT_SEND_EVENT) { + throw new TestException("Returned from next() before expected: " + + delta); + } + if (rei_event == null) { + throw new TestException( + "Did not receive expected event from mailbox."); + } + + //Generate a soon-to-be unknown event. + myGen.generateEvent(evtReg.getID(), 3); + + /* + * Add genereated event to unknown list and verify that they aren't + * subsequently received. + */ + ArrayList unknowns = new ArrayList(1); + unknowns.add(rei_event); + mr.addUnknownEvents(unknowns); + + before = new Date(); + logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); + rei_event = rei.next(MAX_WAIT_GET_EVENT); + after = new Date(); + //Verify that we returned after the timeout + delta = after.getTime() - before.getTime(); + logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", + new Object[] {after, new Long(delta)}); + if (delta < MAX_WAIT_GET_EVENT) { + throw new TestException("Returned from next() before expected: " + + delta); + } + if (rei_event != null) { + throw new TestException( + "Received unexpected event from mailbox: " + rei_event); + } + + // Start event generator thread with a delay of MAX_WAIT_SEND_EVENT + // from a "good" event source. + t = new Thread( + new MyEventGeneratorRunnable(myGen2, evtReg2.getID(), 3, 1, + logger, MAX_WAIT_SEND_EVENT )); + t.start(); + // Call with "infinite" timeout. + before = new Date(); + logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); + rei_event = rei.next(Long.MAX_VALUE); + after = new Date(); + delta = after.getTime() - before.getTime(); + logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", + new Object[] {after, new Long(delta)}); + if (delta <= MAX_WAIT_SEND_EVENT) { + throw new TestException("Returned from next() before expected: " + + delta); + } + /* + * No need to check delta > Long.MAX_VALUE since the test would + * have been interrupted well before then. + */ + if (rei_event == null) { + throw new TestException( + "Did not receive expected event from mailbox."); + } + + // Call with zero timeout. + before = new Date(); + logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); + rei_event = rei.next(0); + after = new Date(); + delta = after.getTime() - before.getTime(); + logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", + new Object[] {after, new Long(delta)}); + if (rei_event != null) { + throw new TestException( + "Received unexpected event from empty mailbox: " + rei_event); + } + + try { + rei.next(-1); + throw new TestException("Successfully called next() with -1"); + } catch (IllegalArgumentException iae) { + logger.log(Level.FINEST, + "Caught IllegalArgumentException -- expected", iae); + } + + } + /** + * Invoke parent's construct and parser + * @exception TestException will usually indicate an "unresolved" + * condition because at this point the test has not yet begun. + */ + public Test construct(QAConfig sysConfig) throws Exception { + super.construct(sysConfig); + parse(); + return this; + } +} Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/PullTimeoutTest3.java URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/PullTimeoutTest3.java?rev=1634322&r1=1634321&r2=1634322&view=diff ============================================================================== --- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/PullTimeoutTest3.java (original) +++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/mercury/PullTimeoutTest3.java Sun Oct 26 13:17:28 2014 @@ -1,164 +1,165 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.sun.jini.test.impl.mercury; - -import java.util.logging.Level; - -import java.rmi.RemoteException; -import java.rmi.NoSuchObjectException; -import java.rmi.ServerException; -import java.util.Date; -import java.util.ArrayList; -import java.util.logging.Logger; - - -import net.jini.event.InvalidIteratorException; -import net.jini.event.MailboxPullRegistration; -import net.jini.event.PullEventMailbox; -import net.jini.event.RemoteEventIterator; -import net.jini.core.lease.Lease; -import net.jini.core.lease.UnknownLeaseException; -import net.jini.core.event.EventRegistration; -import net.jini.core.event.RemoteEvent; -import net.jini.core.event.RemoteEventListener; -import net.jini.core.event.UnknownEventException; - -import com.sun.jini.constants.TimeConstants; - -import com.sun.jini.test.impl.mercury.EMSTestBase; -import com.sun.jini.test.impl.mercury.TestUtils; -import com.sun.jini.test.impl.mercury.TestListener; -import com.sun.jini.test.impl.mercury.TestGenerator; - -import com.sun.jini.qa.harness.QAConfig; -import com.sun.jini.qa.harness.Test; -import com.sun.jini.qa.harness.TestException; - -public class PullTimeoutTest3 - extends EMSTestBase implements TimeConstants -{ - - // - // This should be long enough to sensibly run the test. - // If the service doesn't grant long enough leases, then - // we might have to resort to using something like the - // LeaseRenewalManager to keep our leases current. - // - private final long REG_LEASE = 60 * 1000; - private final long REG_LEASE_WAIT = REG_LEASE * 2; - private final long REG_LEASE_CANCEL_WAIT = REG_LEASE / 2; - - private final int NUM_EVENTS = 5; - - private final long EVENT_ID = 1234; - private final long EVENT_ID2 = 5678; - - class Canceler implements Runnable { - final Lease l; - final long delay; - final Logger logger; - Canceler(Lease l, long delay, Logger logger) - { - this.l = l; - this.delay = delay; - this.logger = logger; - } - public void run() { - try { - logger.log(Level.FINEST, - "Canceler sleeping @ {0} for {1} ms", - new Object[] { new Date(), new Long(delay)}); - Thread.sleep(delay); - logger.log(Level.FINEST, - "Canceler awoken @ {0}", new Date()); - } catch (InterruptedException ie) { - // ignore - logger.log(Level.FINEST, - "Sleep interrupted", ie); - } - try { - l.cancel(); - logger.log(Level.FINEST, "Cancelled reg @ {0}", new Date()); - } catch (RemoteException re) { - logger.log(Level.FINEST, - "Ignoring RemoteException from generating event", - re); - } catch (UnknownLeaseException ule) { - logger.log(Level.FINEST, - "Ignoring UnknownEventException from generating event", - ule); - } - } - } - - public void run() throws Exception { - logger.log(Level.INFO, "Starting up " + this.getClass().toString()); - - PullEventMailbox mb = getPullMailbox(); - int i = 0; - - // Register and check lease - Date gotLease = new Date(); - MailboxPullRegistration mr = getPullRegistration(mb, REG_LEASE); - Lease mrl = getPullMailboxLease(mr); - checkLease(mrl, REG_LEASE); - - // Start canceler thread with a delay of REG_LEASE_CANCEL_WAIT - Thread t = - new Thread( - new Canceler(mrl, REG_LEASE_CANCEL_WAIT, logger)); - t.start(); - - // Get events and verify - logger.log(Level.INFO, "Getting events from empty mailbox."); - RemoteEventIterator rei = mr.getRemoteEvents(); - RemoteEvent rei_event; - Date before = new Date(); - logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); - try { - rei_event = rei.next(REG_LEASE_WAIT); - throw new TestException("Successfully called next on expired reg."); - } catch (NoSuchObjectException nsoe) { - logger.log(Level.INFO, "Received expected exception", nsoe); - } - Date after = new Date(); - //Verify that we returned in time - long delta = after.getTime() - before.getTime(); - logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", - new Object[] {after, new Long(delta)}); - if (delta >= REG_LEASE_WAIT) { - throw new TestException("Returned from next() after expected: " - + delta); - } else if (after.getTime() <= (gotLease.getTime() + REG_LEASE_CANCEL_WAIT)) { - throw new TestException("Returned from next() before expected: " - + after.getTime() + " ms versus " - + (gotLease.getTime() + REG_LEASE) + " ms."); - } - - } - /** - * Invoke parent's construct and parser - * @exception TestException will usually indicate an "unresolved" - * condition because at this point the test has not yet begun. - */ - public Test construct(QAConfig sysConfig) throws Exception { - super.construct(sysConfig); - parse(); - return this; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.sun.jini.test.impl.mercury; + +import java.util.logging.Level; + +import java.rmi.RemoteException; +import java.rmi.NoSuchObjectException; +import java.rmi.ServerException; +import java.util.Date; +import java.util.ArrayList; +import java.util.logging.Logger; + + +import net.jini.event.InvalidIteratorException; +import net.jini.event.MailboxPullRegistration; +import net.jini.event.PullEventMailbox; +import net.jini.event.RemoteEventIterator; +import net.jini.core.lease.Lease; +import net.jini.core.lease.UnknownLeaseException; +import net.jini.core.event.EventRegistration; +import net.jini.core.event.RemoteEvent; +import net.jini.core.event.RemoteEventListener; +import net.jini.core.event.UnknownEventException; + +import com.sun.jini.constants.TimeConstants; + +import com.sun.jini.test.impl.mercury.EMSTestBase; +import com.sun.jini.test.impl.mercury.TestUtils; +import com.sun.jini.test.impl.mercury.TestListener; +import com.sun.jini.test.impl.mercury.TestGenerator; + +import com.sun.jini.qa.harness.QAConfig; +import com.sun.jini.qa.harness.Test; +import com.sun.jini.qa.harness.TestException; + +public class PullTimeoutTest3 + extends EMSTestBase implements TimeConstants +{ + + // + // This should be long enough to sensibly run the test. + // If the service doesn't grant long enough leases, then + // we might have to resort to using something like the + // LeaseRenewalManager to keep our leases current. + // + private final long REG_LEASE = 60 * 1000; + private final long REG_LEASE_WAIT = REG_LEASE * 2; + private final long REG_LEASE_CANCEL_WAIT = REG_LEASE / 2; + + private final int NUM_EVENTS = 5; + + private final long EVENT_ID = 1234; + private final long EVENT_ID2 = 5678; + + class Canceler implements Runnable { + final Lease l; + final long delay; + final Logger logger; + Canceler(Lease l, long delay, Logger logger) + { + this.l = l; + this.delay = delay; + this.logger = logger; + } + public void run() { + try { + logger.log(Level.FINEST, + "Canceler sleeping @ {0} for {1} ms", + new Object[] { new Date(), new Long(delay)}); + Thread.sleep(delay); + logger.log(Level.FINEST, + "Canceler awoken @ {0}", new Date()); + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + // ignore + logger.log(Level.FINEST, + "Sleep interrupted", ie); + } + try { + l.cancel(); + logger.log(Level.FINEST, "Cancelled reg @ {0}", new Date()); + } catch (RemoteException re) { + logger.log(Level.FINEST, + "Ignoring RemoteException from generating event", + re); + } catch (UnknownLeaseException ule) { + logger.log(Level.FINEST, + "Ignoring UnknownEventException from generating event", + ule); + } + } + } + + public void run() throws Exception { + logger.log(Level.INFO, "Starting up " + this.getClass().toString()); + + PullEventMailbox mb = getPullMailbox(); + int i = 0; + + // Register and check lease + Date gotLease = new Date(); + MailboxPullRegistration mr = getPullRegistration(mb, REG_LEASE); + Lease mrl = getPullMailboxLease(mr); + checkLease(mrl, REG_LEASE); + + // Start canceler thread with a delay of REG_LEASE_CANCEL_WAIT + Thread t = + new Thread( + new Canceler(mrl, REG_LEASE_CANCEL_WAIT, logger)); + t.start(); + + // Get events and verify + logger.log(Level.INFO, "Getting events from empty mailbox."); + RemoteEventIterator rei = mr.getRemoteEvents(); + RemoteEvent rei_event; + Date before = new Date(); + logger.log(Level.INFO, "Calling next() on empty set @ {0}", before); + try { + rei_event = rei.next(REG_LEASE_WAIT); + throw new TestException("Successfully called next on expired reg."); + } catch (NoSuchObjectException nsoe) { + logger.log(Level.INFO, "Received expected exception", nsoe); + } + Date after = new Date(); + //Verify that we returned in time + long delta = after.getTime() - before.getTime(); + logger.log(Level.INFO, "Returned from next() @ {0}, delta = {1}", + new Object[] {after, new Long(delta)}); + if (delta >= REG_LEASE_WAIT) { + throw new TestException("Returned from next() after expected: " + + delta); + } else if (after.getTime() <= (gotLease.getTime() + REG_LEASE_CANCEL_WAIT)) { + throw new TestException("Returned from next() before expected: " + + after.getTime() + " ms versus " + + (gotLease.getTime() + REG_LEASE) + " ms."); + } + + } + /** + * Invoke parent's construct and parser + * @exception TestException will usually indicate an "unresolved" + * condition because at this point the test has not yet begun. + */ + public Test construct(QAConfig sysConfig) throws Exception { + super.construct(sysConfig); + parse(); + return this; + } +}
