You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pa...@apache.org on 2011/05/10 05:49:28 UTC

svn commit: r1101303 - in /river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test: impl/discoverymanager/ impl/locatordiscovery/ share/

Author: pats
Date: Tue May 10 03:49:28 2011
New Revision: 1101303

URL: http://svn.apache.org/viewvc?rev=1101303&view=rev
Log:
RIVER-395
QA tests for listeners that throw exceptions.

Added:
    river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.java
    river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.td
    river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.java
    river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.td
    river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/share/BadTestListener.java

Added: river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.java?rev=1101303&view=auto
==============================================================================
--- river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.java (added)
+++ river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.java Tue May 10 03:49:28 2011
@@ -0,0 +1,105 @@
+/*
+ * 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.discoverymanager;
+
+import java.util.logging.Level;
+
+import com.sun.jini.qa.harness.TestException;
+import com.sun.jini.test.share.BadTestListener;
+import com.sun.jini.test.spec.discoverymanager.Discovered;
+
+/**
+ * With respect to the <code>addDiscoveryListener</code> method, this class
+ * verifies that the <code>LookupDiscoveryManager</code> utility operates in a
+ * manner consistent with the specification.
+ * <p>
+ * In particular, this class verifies that upon adding a new instance of
+ * <code>DiscoveryListener</code> to a lookup discovery manager configured to
+ * discover a set of lookup services through a MIX of group discovery and
+ * locator discovery, the lookup discovery manager will send a discovered event
+ * - with the appropriate contents - to that listener for each lookup service
+ * that satisfies the discovery criteria.
+ * 
+ * The environment in which this class expects to operate is as follows:
+ * <p>
+ * <ul>
+ * <li>N lookup services having locator L0i, and belonging to groups
+ * {G0i,G1i,G2i}, where i = 0 ... N
+ * <li>one lookup discovery manager configured to discover some of the lookups
+ * by only group discovery, some by only locator discovery, and some by both
+ * group and locator discovery
+ * <li>one instance of DiscoveryListener registered with the lookup discovery
+ * manager
+ * <li>after discovery, a new instance of DiscoveryListener is added to the
+ * lookup discovery manager utility through the invocation of the
+ * addDiscoveryListener method
+ * </ul>
+ * <p>
+ * 
+ * If the lookup discovery manager functions as specified, then each of the
+ * client's listeners will receive the expected number of discovery events, with
+ * the expected contents.
+ */
+public class BadDiscoveryListener extends Discovered {
+
+    protected LookupListener newListener = new LookupListener();;
+
+    /**
+     * Executes the current test by doing the following:
+     * <p>
+     * <ul>
+     * <li>creates N lookup services having locator L0i, and belonging to groups
+     * {G0i,G1i,G2i}, where i = 0 ... N
+     * <li>creates a lookup discovery manager (LDM) initially configured to
+     * discover NO_GROUPS and NO_LOCATORS
+     * <li>reconfigures the LDM to discover some of the lookups by only group
+     * discovery, some by only locator discovery, and some by both group and
+     * locator discovery
+     * <li>verifies that the discovery process is working by waiting for the
+     * expected discovery events
+     * <li>verifies that the lookup discovery manager utility under test sends
+     * the expected events, with the expected contents to the first listener
+     * <li>invokes the addDiscoveryListener method on the lookup discovery
+     * manager to add a new listener for the original set of lookups to discover
+     * <li>verifies that the lookup discovery manager utility under test sends
+     * the expected events, with the expected contents to the first listener
+     * </ul>
+     */
+    public void run() throws Exception {
+        super.run();
+        logger.log(Level.FINE, "Adding bad listener");
+        boolean exceptionHappened = false;
+        try {
+            discoveryMgr.addDiscoveryListener(new BadTestListener(logger));
+        } catch (BadTestListener.BadListenerException e) {
+            logger.log(Level.FINEST, "Expected exception happened");
+            exceptionHappened = true;
+        }
+        if (!exceptionHappened) {
+            throw new TestException(
+                    "Initial discovery exception not thrown back to test program");
+        }
+        logger.log(Level.FINE, "adding a new listener to the "
+                + "lookup discovery manager ... ");
+        newListener.setLookupsToDiscover(initLookupsToStart,
+                locatorsToDiscover, groupsToDiscover);
+        discoveryMgr.addDiscoveryListener(newListener);
+        waitForDiscovery(newListener);
+    }
+}

Added: river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.td
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.td?rev=1101303&view=auto
==============================================================================
--- river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.td (added)
+++ river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/discoverymanager/BadDiscoveryListener.td Tue May 10 03:49:28 2011
@@ -0,0 +1,4 @@
+testClass=com.sun.jini.test.impl.discoverymanager.BadDiscoveryListener
+testCategories=discoverymanager,discoverymanager_impl
+include0=discoverymanager.properties
+include1=com/sun/jini/test/share/reggie3_2.properties

Added: river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.java?rev=1101303&view=auto
==============================================================================
--- river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.java (added)
+++ river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.java Tue May 10 03:49:28 2011
@@ -0,0 +1,85 @@
+/*
+ * 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.locatordiscovery;
+
+import java.util.logging.Level;
+
+import net.jini.core.discovery.LookupLocator;
+
+import com.sun.jini.test.share.BadTestListener;
+import com.sun.jini.test.share.LocatorsUtil;
+import com.sun.jini.test.spec.locatordiscovery.AbstractBaseTest;
+
+/**
+ * With respect to the current implementation of the
+ * <code>LookupLocatorDiscovery</code> utility, this class verifies that if the
+ * <code>addDiscoveryListener</code> method is invoked after the lookup locator
+ * discovery utility has been terminated, an <code>IllegalStateException</code>
+ * results.
+ * 
+ * The environment in which this class expects to operate is as follows:
+ * <p>
+ * <ul>
+ * <li>no lookup services
+ * <li>one instance of LookupLocatorDiscovery
+ * <li>after invoking the terminate method on the lookup locator discovery
+ * utility, the addDiscoveryListener method is invoked
+ * </ul>
+ * <p>
+ * 
+ * If the <code>LookupLocatorDiscovery</code> utility functions as intended,
+ * upon invoking the <code>addDiscoveryListener</code> method after the that
+ * utility has been terminated, an <code>IllegalStateException</code> will
+ * occur.
+ * 
+ */
+public class BadLocatorDiscoveryListener extends AbstractBaseTest {
+
+    /**
+     * Tests listener throwing exception by adding a bad listener. Remaining
+     * code based on AddLocators.java.
+     */
+    public void run() throws Exception {
+        logger.log(Level.FINE, "run()");
+        /* Add the bad listener. */
+        logger.log(Level.FINE, "Adding bad listener");
+        locatorDiscovery.addDiscoveryListener(new BadTestListener(logger));
+        /* Start the additional lookup services */
+        startAddLookups();
+        /* Verify discovery of the initial lookups */
+        doDiscovery(initLookupsToStart, mainListener);
+        /*
+         * Configure the listener's expected event state for the additional
+         * lookup services
+         */
+        mainListener.clearAllEventInfo();
+        mainListener.setLookupsToDiscover(addLookupsToStart);
+        /*
+         * Configure the lookup locator discovery utility to discover the
+         * additional lookups
+         */
+        LookupLocator[] locsToAdd = toLocatorArray(addLookupsToStart);
+        locatorDiscovery.addLocators(locsToAdd);
+        logger.log(Level.FINE, "added additional locators to "
+                + "lookup locator discovery --");
+        LocatorsUtil.displayLocatorSet(locsToAdd, "locator", Level.FINE);
+        /* Verify discovery of the added lookups */
+        waitForDiscovery(mainListener);
+    }
+}

Added: river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.td
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.td?rev=1101303&view=auto
==============================================================================
--- river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.td (added)
+++ river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/impl/locatordiscovery/BadLocatorDiscoveryListener.td Tue May 10 03:49:28 2011
@@ -0,0 +1,4 @@
+testClass=BadLocatorDiscoveryListener
+testCategories=locatordiscovery,locatordiscovery_impl,impllocatordiscovery
+include0=locatordiscovery.properties
+include1=com/sun/jini/test/share/reggie3_2.properties

Added: river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/share/BadTestListener.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/share/BadTestListener.java?rev=1101303&view=auto
==============================================================================
--- river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/share/BadTestListener.java (added)
+++ river/jtsk/skunk/PatsRiver395/qa/src/com/sun/jini/test/share/BadTestListener.java Tue May 10 03:49:28 2011
@@ -0,0 +1,50 @@
+/**
+ * 
+ */
+package com.sun.jini.test.share;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import net.jini.discovery.DiscoveryChangeListener;
+import net.jini.discovery.DiscoveryEvent;
+
+/**
+ * Listener for testing notify code resiliance in
+ * the face of listener exceptions. Each of the event
+ * handling methods throws an exception.
+ */
+public class BadTestListener implements DiscoveryChangeListener {
+    protected Logger logger;
+
+    public BadTestListener(Logger logger) {
+        this.logger = logger;
+    }
+
+    public void discarded(DiscoveryEvent e) {
+        logger.log(Level.FINEST,
+                "BadListener.discarded about to throw exception");
+        throw new BadListenerException("Discarded");
+
+    }
+
+    public void discovered(DiscoveryEvent e) {
+        logger.log(Level.FINEST,
+                "BadListener.discovered about to throw exception");
+        throw new BadListenerException("Discovered");
+    }
+
+    public void changed(DiscoveryEvent e) {
+        logger.log(Level.FINEST,
+                "Bad listener changed about to throw exception");
+        throw new BadListenerException("Changed");
+    }
+
+    public static class BadListenerException extends RuntimeException {
+        private static final long serialVersionUID = 1L;
+
+        public BadListenerException(String message) {
+            super(message);
+        }
+    }
+}
\ No newline at end of file