You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2012/01/21 08:28:36 UTC
svn commit: r1234278 [26/29] - in /river/tck: ./ configs/ doc/ doc/api/
doc/api/com/ doc/api/com/sun/ doc/api/com/sun/jini/
doc/api/com/sun/jini/compat/ doc/api/com/sun/jini/compat/admin1/
doc/api/com/sun/jini/compat/admin2/ doc/api/com/sun/jini/compat...
Added: river/tck/src/com/sun/jini/compat/test/lookup/TestRegistrar.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/test/lookup/TestRegistrar.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/test/lookup/TestRegistrar.java (added)
+++ river/tck/src/com/sun/jini/compat/test/lookup/TestRegistrar.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,848 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed 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.compat.test.lookup;
+
+import com.sun.jini.compat.harness.BasicAdmin;
+import com.sun.jini.compat.harness.BasicLookupAdmin;
+import com.sun.jini.compat.harness.Config;
+
+import com.sun.jini.compat.test.lookup.TestException;
+
+import net.jini.core.entry.Entry;
+import net.jini.core.lease.*;
+import net.jini.core.lookup.*;
+import net.jini.admin.Administrable;
+
+import java.util.Properties;
+import java.io.Serializable;
+import java.io.IOException;
+import java.rmi.activation.ActivationGroup;
+import java.rmi.activation.ActivationGroupID;
+import java.rmi.activation.ActivationException;
+import java.rmi.activation.UnknownGroupException;
+import java.rmi.RMISecurityManager;
+import java.rmi.MarshalledObject;
+import java.rmi.RemoteException;
+import java.util.List;
+
+/** Besides providing implementations for the abstract methods of the
+ * super class (QATestImpl), this class is the common super class of
+ * all LDJ Kit lookup tests.
+ * This class encapsulates shared data and methods on behalf of each
+ * of those test classes.
+ *
+ * @see com.sun.jini.test.lookup.QATest
+ * @see com.sun.jini.test.lookup.QATestImpl
+ */
+public abstract class TestRegistrar extends TestImpl {
+
+ /** Identifier of the Activation Group to which the Registrar belongs */
+ ActivationGroupID actGroupID;
+
+ /** The number of milliseconds to wait after the service lease has
+ * expired to guarantee that the next lookup is performed after
+ * service lease expiration has occurred
+ */
+ public long deltaTSrvcLeaseExp =
+ TestUtils.N_MS_PER_SEC*10;
+
+ /** The number of milliseconds to wait after the event lease has
+ * expired to guarantee that the next event-generating operation is
+ * performed after event lease expiration has occurred
+ */
+ public long deltaTEvntLeaseExp =
+ TestUtils.N_MS_PER_SEC*10;
+ /** The number of milliseconds to wait after a notification-generating
+ * event has occurred; in order to guarantee that the
+ * notification-generating event has completed its operations before
+ * attempting any further testing
+ */
+ public long deltaTEvntNotify =
+ TestUtils.N_MS_PER_SEC*10;
+ /** The number of milliseconds to wait to allow an event listener to
+ * perform its duties after events have been sent by the Registrar
+ */
+ public long deltaTListener =
+ TestUtils.N_MS_PER_SEC*5;
+ /** The set of possible interfaces implemented by the service classes that
+ * will be registered for testing
+ */
+ protected static final String INTERFACES[]
+ = {"com.sun.jini.compat.test.lookup.service.Interface00",
+ "com.sun.jini.compat.test.lookup.service.Interface01",
+ "com.sun.jini.compat.test.lookup.service.Interface02"};
+ /** The set of service classes to register for testing */
+ protected static final String TEST_SRVC_CLASSES[]
+ = {"com.sun.jini.compat.test.lookup.service.Service00"};
+ /** The maximum number of classes in a "super class chain" of services */
+ protected int MAX_SRVC_CHAIN_LEN = 2;
+ /** The number of different service classes to test per run */
+ private int nTestClasses = TEST_SRVC_CLASSES.length;
+ /** The maximum number of different instances of each test class */
+ private final static int MAX_N_INSTANCES_PER_CLASS = 1;
+ /** The number of different instances of each test class */
+ private int nInstancesPerClass = MAX_N_INSTANCES_PER_CLASS;
+ /** The total number of different instances created */
+ private int nInstances = nTestClasses*nInstancesPerClass;
+ /** The set of expected matches when testing lookup by exact class
+ * Note: the values in this set are dependent on the relationships
+ * among the test classes in TEST_SRVC_CLASSES[].
+ */
+ protected int[] expectedNMatchesExact;
+ /** The maximum number of super classes in any "chain" of test classes
+ * (the class Object will never be counted).
+ */
+ public final static int MAX_N_SUPER_CHAIN_LEN = TEST_SRVC_CLASSES.length;
+ /** The set of expected matches when testing lookup by a test class'
+ * super class.
+ * Note: the values in this set are dependent on the relationships
+ * among the test classes in TEST_SRVC_CLASSES[]
+ */
+ protected int[][] expectedNMatchesSuper;
+ /** The maximum number of interfaces any test class will implement (add 1
+ * because the classes must implement java.io.Serializable -- but
+ * Serializable will be excluded from the analysis).
+ */
+ public final static int MAX_N_INTFC_PER_CLASS = 1+INTERFACES.length;
+ /** The set of expected matches when testing lookup by interfaces
+ * implemented by the registered services instances.
+ * Note: the values in this set are dependent on the relationships
+ * among the test classes in QATestRegistrar.TEST_SRVC_CLASSES[]
+ */
+ protected int[][] expectedNMatchesIntfc;
+ /** For each interface defined in the test set, there are a N classes
+ * from the set of test classes which will implement that interface.
+ * This array reflects not only the number of classes that implement
+ * an interface, but also any classes which extend a class that
+ * implements the interface. That is, if interface i02 is implemented
+ * by classes t1,t3 and t4, and if classes t7 and t9 do not implement
+ * i02 but each is a sub-class of a class that implements i02, then
+ * n = 5 for interface i02 in this array.
+ */
+ protected static final int N_CLASSES_THAT_IMPL_INTFC[] = {1,1,1};
+ /** This matrix indicates which classes implement which interfaces.
+ * This matrix, together with the array N_CLASSES_THAT_IMPL_INTFC will
+ * be used to determine how many matches one can expect when performing
+ * a lookup-by-interface. That is, these two data structures will be
+ * used to populate the matrix expectedNMatchesIntfc[][].
+ */
+ protected static final int INTFC_IMPL_MATRIX[][] = { {1, 1, 1} };
+
+ /** This matrix is used to map the interfaces to the set of services
+ * that will be returned by lookup() when performing a lookup-by-
+ * interface. This matrix is then used to compute a start index into
+ * into the array of registered srvcItems[]. It is from this index that
+ * stored services are retrieved and compared to the services returned
+ * by lookup() when testing lookup-by-interfaces. The values in this
+ * matrix correspond to the indices of the array TEST_SRVC_CLASSES[]
+ */
+ protected static final int INTFC_TO_SI[][] = { {0},
+ {0},
+ {0}
+ };
+ /** The set of service classes to register for testing */
+ protected static final String ATTR_CLASSES[]
+ = {"com.sun.jini.compat.test.lookup.attribute.Attr00"};
+ /** The number of different attribute classes to test per run */
+ private int nAttrClasses = ATTR_CLASSES.length;
+ /** The max number of different instances of each attribute class */
+ private final static int MAX_N_INSTANCES_PER_ATTR_CLASS = 1;
+ /** The number of different instances of each test class */
+ private int nAttrInstancesPerClass = MAX_N_INSTANCES_PER_ATTR_CLASS;
+ /** The total number of different instances created */
+ private int nAttrInstances = nAttrClasses*nAttrInstancesPerClass;
+ /** Column 0 contains the number of "sets" of attribute fields in the
+ * attribute class. Column 1 contains the number of arguments expected
+ * by the attributes' constructor. For example, if attribute class 3
+ * contains the following fields: int i0;
+ * boolean b0;
+ * String s0;
+ * then N_SETS_FIELDS_ATTR[3] = {1,3} -- (1 "set" of fields, 3 fields
+ * in that set)
+ * If attribute class 4 contains the fields: int i0;
+ * boolean b0;
+ * String s0;
+ * long l0;
+ * int i1;
+ * boolean b1;
+ * String s1;
+ * long l1;
+ * then N_SETS_FIELDS_ATTR[4] = {2,4} -- (2 "sets" of fields, 4 fields
+ * in that set)
+ * The methods defined in this class that are related to instantiating
+ * the test attribute classes reflected in the array ATTR_CLASSES[]
+ * assume that all of the attribute classes will be structured in the
+ * way just described; that is, order and field type are important. This
+ * fact must be taken into account when and if more test attribute
+ * classes are added and/or more fields are added to existing or new
+ * test attribute classes,
+ */
+ protected static final int N_SETS_FIELDS_ATTR[][] = { {1,3} };
+ /** Constant indicating an Integer argument type in N_SETS_FIELDS_ATTR */
+ private static final int ARG_IS_INT = 0;
+ /** Constant indicating a Boolean argument type in N_SETS_FIELDS_ATTR */
+ private static final int ARG_IS_BOOLEAN = 1;
+ /** Constant indicating a String argument type in N_SETS_FIELDS_ATTR */
+ private static final int ARG_IS_STRING = 2;
+ /** Constant indicating a Long argument type in N_SETS_FIELDS_ATTR */
+ private static final int ARG_IS_LONG = 3;
+ /** Flag indicating attributes will be created for the first time */
+ private static final int INITIAL_ATTRS = 0;
+ /** Flag indicating existing attributes will be modified */
+ private static final int MODIFIED_ATTRS = 1;
+ /** RMI codebase: the download URL for QA classes */
+ private String rmiCodebase = null;
+ /** Lookup codebase: the download URL for lookup classes */
+ private String actCodebase = null;
+ /** Lookup classpath: the classpath for the lookup service */
+ private String actClasspath = null;
+ /** The path and filename of the policy file */
+ private String policy = null;
+ /** Flag for the transient (non-Activated) version of the Registrar */
+ private boolean useTransient = false;
+ /** Array to store all created service items */
+ private ServiceItem[] srvcItems;
+ /** Array to store the ServiceRegistration returned by register() */
+ private ServiceRegistration[] srvcRegs;
+ /** The proxy for the lookup service Registrar */
+ private ServiceRegistrar proxy;
+ /** Constant indicating non-random service selection during lookup */
+ public final static int SELECT_METHOD_SAME_ONE = 0;
+ /** Constant indicating random service selection during lookup */
+ public final static int SELECT_METHOD_RANDOM = 1;
+ /** A number retrieved from the input arg list representing the
+ * method used by the Registrar to select a service being looked up
+ */
+ private int selectMethod;
+
+ /** Executes the current QA test.
+ * @exception QATestException will usually indicate a failure
+ * since the exception occurs during the actual test run.
+ */
+ public abstract void doQATest() throws TestException;
+
+ /** After performing high-level setup by invoking the setup() method
+ * in the super class (QATestImpl), this method will perform mid-level,
+ * general-purpose setup actions necessary to prepare for execution of
+ * the current QA test.
+ *
+ * This method parses the argument list to retrieve and process the
+ * following arguments:
+ * -- the number of instances per class that should be created
+ * -- the selection method to employ when performing a lookup
+ * -- the RMI codebase to use
+ * -- the codebase to register with the Activation daemon
+ * -- the name and path of the policy file
+ * -- whether or not to use the transient form of the Registrar
+ *
+ * After processing the appropriate data in the argument list, the values
+ * of a number of this class' fields are set, the codebase system property
+ * is set, and the RMI security manager is set.
+ * @param args command line arguments for the current QA test
+ * @exception QATestException will usually indicate an "unresolved"
+ * condition because at this point the test has not yet begun.
+ */
+ public void setup(List args) throws TestException {
+ super.setup(args);
+
+ expectedNMatchesExact = new int[nTestClasses];
+ expectedNMatchesExact[0] = 1;
+
+ expectedNMatchesSuper = new int[nTestClasses][MAX_N_SUPER_CHAIN_LEN];
+ expectedNMatchesSuper[0][0] = 1;
+
+ expectedNMatchesIntfc = new int[nTestClasses][INTERFACES.length];
+ for(int i = 0; i < INTERFACES.length; i++) {
+ expectedNMatchesIntfc[0][i] = 1;
+ }
+
+ selectMethod = SELECT_METHOD_RANDOM;
+ }
+
+ /**
+ * Sets up the current LDJ Kit lookup test. It starts up the program
+ * being tested and gets it ServiceRegistrar.
+ */
+ public void setupQATest() throws TestException {
+ Config tc = getConfig();
+ BasicLookupAdmin bla = (BasicLookupAdmin)tc.getAdmin();
+ try {
+ bla.start();
+ proxy = bla.getServiceRegistrar();
+ } catch (RemoteException re) {
+ throw new TestUnresolvedException(re.getMessage(),
+ re.detail);
+ }
+ }
+ /**
+ * Stops the program at the end of a test
+ */
+ public void cleanupQATest() throws TestException {
+ try {
+ Config tc = getConfig();
+ BasicLookupAdmin bla = (BasicLookupAdmin)tc.getAdmin();
+ bla.stop();
+ } catch (RemoteException re) {
+ throw new TestUnresolvedException(re.getMessage(),
+ re.detail);
+ }
+ }
+
+ /**
+ * This method overloads the Test method of the same name.
+ * All lookup tests are in the BasicLookupAdmin category.
+ */
+ public String[] getCategories() {
+ String[] tempArray = { BasicLookupAdmin.CATEGORY };
+ return tempArray;
+ }
+
+ /**
+ * This method overloads the Test method of the same name.
+ * All lookup tests require an admin that is both a BasicAdmin
+ * and a BasicLookupAdmin.
+ */
+ public Class[] getRequiredAdmins() {
+ Class[] tempC = { BasicAdmin.class,
+ BasicLookupAdmin.class };
+ return tempC;
+ }
+
+ /** Returns the number of different service classes to test per run
+ * @return int
+ */
+ protected int getNTestClasses() {
+ return nTestClasses;
+ }
+
+ /** Returns the number of different instances of each test class
+ * @return int
+ */
+ protected int getNInstancesPerClass() {
+ return nInstancesPerClass;
+ }
+
+ /** Returns the total number of different test class instances created
+ * @return int
+ */
+ protected int getNInstances() {
+ return nInstances;
+ }
+
+ /** Returns the number of different attribute classes to test per run
+ * @return int
+ */
+ protected int getNAttrClasses() {
+ return nAttrClasses;
+ }
+
+ /** Returns the number of different instances of each attribute class
+ * @return int
+ */
+ protected int getNAttrInstancesPerClass() {
+ return nAttrInstancesPerClass;
+ }
+
+ /** Returns total number of different attribute class instances created
+ * @return int
+ */
+ protected int getNAttrInstances() {
+ return nAttrInstances;
+ }
+
+ /** Returns the proxy of the lookup service Registrar
+ * @return ServiceRegistrar object as defined in
+ * net.jini.core.lookup.ServiceRegistrar
+ * @see net.jini.core.lookup.ServiceRegistrar
+ */
+ protected ServiceRegistrar getProxy() {
+ return proxy;
+ }
+
+ /** Returns the value indicating the method employed by the Registrar to
+ * select a service being looked up
+ * @return int
+ */
+ protected int getSelectMethod() {
+ return selectMethod;
+ }
+
+ /** Creates service items for each class in the given list of class names
+ * @param classNames array of class name Strings
+ * @exception QATestException usually indicates a failure
+ * @return ServiceItem an array of objects as defined in
+ * net.jini.core.lookup.ServiceItem
+ * @see net.jini.core.lookup.ServiceItem
+ */
+ protected ServiceItem[] createServiceItems(String[] classNames)
+ throws TestException
+ {
+ try {
+ int k = 0;
+ srvcItems = new ServiceItem[nTestClasses*nInstancesPerClass];
+ for (int i = 0; i < nTestClasses; i++) {
+ Class c = Class.forName(classNames[i]);
+ for (int j = 0; j < nInstancesPerClass; j++) {
+ srvcItems[k] = createServiceItem(c,k);
+ k++;
+ }
+ }
+ return srvcItems;
+ } catch (ClassNotFoundException e) {
+ throw new TestUnresolvedException
+ ("TestRegistrar.createServiceItems: "+e.toString(), e);
+ }
+ }
+
+ /** Creates service items, containing the given set of attributes, for
+ * each class in the given list of class names
+ * @param classNames array of class name Strings
+ * @param attrs array of Entry type elements containing attributes
+ * @exception QATestException usually indicates a failure
+ * @return ServiceItem an array of objects as defined in
+ * net.jini.core.lookup.ServiceItem
+ * @see net.jini.core.lookup.ServiceItem
+ */
+ protected ServiceItem[] createServiceItems(String[] classNames,
+ Entry[] attrs)
+ throws TestException
+ {
+ try {
+ int k = 0;
+ srvcItems = new ServiceItem[nTestClasses*nInstancesPerClass];
+ for (int i = 0; i < nTestClasses; i++) {
+ Class c = Class.forName(classNames[i]);
+ for (int j = 0; j < nInstancesPerClass; j++) {
+ srvcItems[k] = createServiceItem(c,k,attrs);
+ k++;
+ }
+ }
+ return srvcItems;
+ } catch (ClassNotFoundException e) {
+ throw new TestUnresolvedException
+ ("TestRegistrar.createServiceItems: "+e.toString(), e);
+ }
+ }
+
+ /** Creates service items for each class and each possible field value
+ * @param nServiceTypes number of service class types to create
+ * @param nServices number of services to create
+ * @exception QATestException usually indicates a failure
+ * @return ServiceItem an array of objects as defined in
+ * net.jini.core.lookup.ServiceItem
+ * @see net.jini.core.lookup.ServiceItem
+ */
+ protected ServiceItem[] createSrvcsForEquals(int nServiceTypes,
+ int nServices)
+ throws TestException
+ {
+ ServiceItem[] srvcsForEquals =
+ new ServiceItem[nServiceTypes*nServices];
+ for (int i=0, k=0;i<nServiceTypes;i++) {
+ for (int j=0;j<nServices;j++) {
+ try {
+ Class srvcClass = Class.forName(TEST_SRVC_CLASSES[i]);
+ srvcsForEquals[k] = createServiceItem(srvcClass,j);
+ k++;
+ } catch (ClassNotFoundException e) {
+ throw new TestFailedException
+ ("createSrvcsForEquals: ClassNotFoundException while creating "+
+ "array srvcItemsForEquals[] (i=" +i+",j="+j+")",e);
+ }
+ }
+ }
+ return srvcsForEquals;
+ }
+
+ /** Creates one service item of the given class type, having the given
+ * field value
+ * @param classObj the class type of the service to create
+ * @param instanceIndx the value to initialize the class field to
+ * @exception QATestException usually indicates a failure
+ * @return ServiceItem object as defined in net.jini.core.lookup.ServiceItem
+ * @see net.jini.core.lookup.ServiceItem
+ */
+ protected ServiceItem createServiceItem(Class classObj,
+ int instanceIndx)
+ throws TestException
+ {
+ return new ServiceItem(null,
+ TestUtils.createInstance
+ (classObj,instanceIndx),
+ null);
+ }
+
+ /** Creates one service item of the given class type; and which contains
+ * the given set of attributes and has the given field value
+ * @param classObj the class type of the service to create
+ * @param instanceIndx the value to initialize the class field to
+ * @param attrs array of Entry type elements containing attributes
+ * @exception QATestException usually indicates a failure
+ * @return ServiceItem object as defined in net.jini.core.lookup.ServiceItem
+ * @see net.jini.core.lookup.ServiceItem
+ */
+ protected ServiceItem createServiceItem(Class classObj,
+ int instanceIndx,
+ Entry[] attrs)
+ throws TestException
+ {
+ return new ServiceItem(null,
+ TestUtils.createInstance
+ (classObj,instanceIndx),
+ attrs);
+ }
+
+ /** Creates one service item having the given class name, having the given
+ * field value
+ * @param className the name of the class type to create
+ * @param instanceIndx the value to initialize the class field to
+ * @exception QATestException usually indicates a failure
+ * @return ServiceItem object as defined in net.jini.core.lookup.ServiceItem
+ * @see net.jini.core.lookup.ServiceItem
+ */
+ protected ServiceItem createServiceItem(String className,
+ int instanceIndx)
+ throws TestException
+ {
+ try {
+ return createServiceItem(Class.forName(className),instanceIndx);
+ } catch (ClassNotFoundException e) {
+ throw new TestUnresolvedException
+ ("createServiceItem: ClassNotFoundException (instanceIndx="
+ +instanceIndx+")",e);
+ }
+ }
+
+ /** Creates one service item having the given class name; and which
+ * contains the given set of attributes and has the given field value
+ * @param className the name of the class type to create
+ * @param instanceIndx the value to initialize the class field to
+ * @param attrs array of Entry type elements containing attributes
+ * @exception QATestException usually indicates a failure
+ * @return ServiceItem object as defined in net.jini.core.lookup.ServiceItem
+ * @see net.jini.core.lookup.ServiceItem
+ */
+ protected ServiceItem createServiceItem(String className,
+ int instanceIndx,
+ Entry[] attrs)
+ throws TestException
+ {
+ try {
+ return createServiceItem(Class.forName(className),instanceIndx,
+ attrs);
+ } catch (ClassNotFoundException e) {
+ throw new TestUnresolvedException
+ ("createServiceItem: ClassNotFoundException (instanceIndx="
+ +instanceIndx+")",e);
+ }
+ }
+
+ /** Creates initialized attributes for each attribute in the list defined
+ * in this class
+ * @exception QATestException usually indicates a failure
+ * @return Entry an array of objects as defined in net.jini.core.entry.Entry
+ * @see net.jini.core.entry.Entry
+ */
+ protected Entry[] createNonNullFieldAttributes() throws TestException {
+ return createAttributes(ATTR_CLASSES);
+ }
+
+ /** Creates non-initialized attributes for each attribute in the list
+ * defined in this class
+ * @exception QATestException usually indicates a failure
+ * @return Entry an array of objects as defined in net.jini.core.entry.Entry
+ * @see net.jini.core.entry.Entry
+ */
+ protected Entry[] createNullFieldAttributes() throws TestException {
+ int i=0;
+ Entry[] attrs = new Entry[ATTR_CLASSES.length];
+ for (i=0;i<nAttrClasses;i++) {
+ try {
+ Class loadedAttrObj = Class.forName(ATTR_CLASSES[i]);
+ attrs[i] = (Entry)loadedAttrObj.newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new TestUnresolvedException
+ ("createNullFieldAttributes: ClassNotFoundException "+
+ "from Class.forName (i="+i+")",e);
+ } catch (IllegalAccessException e) {
+ throw new TestUnresolvedException
+ ("createNullFieldAttributes: IllegalAccessException "+
+ "from Class.forName (i="+i+")",e);
+ } catch (InstantiationException e) {
+ throw new TestUnresolvedException
+ ("createNullFieldAttributes: InstantiationException "+
+ "from Class.forName (i="+i+")",e);
+ }
+ }
+ return attrs;
+ }
+
+ /** Creates initialized attributes for each attribute class having a
+ * class name contained in the given set of class names
+ * @param classNames array of attribute class names to create
+ * @exception QATestException usually indicates a failure
+ * @return Entry an array of objects as defined in net.jini.core.entry.Entry
+ * @see net.jini.core.entry.Entry
+ */
+ protected Entry[] createAttributes(String[] classNames)
+ throws TestException
+ {
+ try {
+ int k = 0;
+ Entry attrEntries[]
+ = new Entry[nAttrClasses*nAttrInstancesPerClass];
+ for (int i = 0; i < nAttrClasses; i++) {
+ Class c = Class.forName(classNames[i]);
+ for (int j = 0; j < nAttrInstancesPerClass; j++) {
+ attrEntries[k] = createAttribute(c,i,INITIAL_ATTRS);
+ k++;
+ }
+ }
+ return attrEntries;
+ } catch (ClassNotFoundException e) {
+ throw new TestUnresolvedException
+ ("TestRegistrar.createAttributes: "+e.toString(), e);
+ }
+ }
+
+ /** Creates a set of initialized attributes for each attribute class
+ * having a class name contained in the given set of class names;
+ * and in which each attribute class is guaranteed to not equal
+ * corresponding classes created initially.
+ *
+ * This method should be used to create a set of attributes that can
+ * then be used to modify an existing set of attributes belonging
+ * to registered services
+ * @param classNames array of attribute class names to create
+ * @exception QATestException usually indicates a failure
+ * @return Entry an array of objects as defined in net.jini.core.entry.Entry
+ * @see net.jini.core.entry.Entry
+ */
+ protected Entry[] createModifiedAttributes(String[] classNames)
+ throws TestException
+ {
+ try {
+ int k = 0;
+ Entry attrEntries[]
+ = new Entry[nAttrClasses*nAttrInstancesPerClass];
+ for (int i = 0; i < nAttrClasses; i++) {
+ Class c = Class.forName(classNames[i]);
+ for (int j = 0; j < nAttrInstancesPerClass; j++) {
+ attrEntries[k] = createAttribute(c,i,MODIFIED_ATTRS);
+ k++;
+ }
+ }
+ return attrEntries;
+ } catch (ClassNotFoundException e) {
+ throw new TestUnresolvedException
+ ("TestRegistrar.createModifiedAttributes: "+e.toString(), e);
+ }
+ }
+
+ /** Creates one attribute of the given attribute class type corresponding
+ * to the given class index; if the createFlag argument equals
+ * MODIFIED_ATTRS, the field values of the attribute class will be
+ * set to values that differ from the field values created for
+ * the initially created attribute set
+ * @param classObj class type of the attribute to create
+ * @param classIndx index of the attribute class (for initialization)
+ * @param createFlag MODIFIED_ATTRS or INITIAL_ATTRS
+ * @exception QATestException usually indicates a failure
+ * @return Entry object as defined in net.jini.core.entry.Entry
+ * @see net.jini.core.entry.Entry
+ */
+ protected Entry createAttribute(Class classObj,
+ int classIndx,
+ int createFlag) throws TestException
+ {
+ /* create an array containing the VALUES of the arguments that the
+ * class' constructor expects to be input when the class is
+ * instantiated
+ */
+ Object[] constructorArgs = null;
+ int delta = (createFlag == MODIFIED_ATTRS ? 1:0);
+
+ int nSets = N_SETS_FIELDS_ATTR[classIndx][0];
+ int nArgsPerSet = N_SETS_FIELDS_ATTR[classIndx][1];
+ int nArgs = nSets*nArgsPerSet;
+ if (nArgs > 0) {
+ constructorArgs = new Object[nArgs];
+ int k = 0;
+ for (int i=0;i<nSets;i++) {
+ for (int j=0;j<nArgsPerSet;j++) {
+ int val = delta + 100*classIndx + 10*i + j;
+ Integer iVal = new Integer(val);
+ int argIs = j%nArgsPerSet;
+ switch ( argIs ) {
+ case ARG_IS_INT:
+ constructorArgs[k] = iVal;
+ break;
+ case ARG_IS_BOOLEAN:
+ constructorArgs[k] = new Boolean(true);
+ break;
+ case ARG_IS_STRING:
+ constructorArgs[k]
+ = "attribute string "+iVal.toString();
+ break;
+ case ARG_IS_LONG:
+ constructorArgs[k] = new Long(val);
+ break;
+ default:
+ return null;
+ }
+ k++;
+ }
+ }
+ }
+ return (Entry)TestUtils.createInstance(classObj,constructorArgs);
+ }
+
+ /** Requesting the maximum duration for the service lease, registers all
+ * service items from the list defined in this class and returns the
+ * resulting ServiceRegistration objects
+ * @exception QATestException usually indicates a failure
+ * @return ServiceRegistration an array of objects as defined in
+ * net.jini.core.lookup.ServiceRegistration
+ * @see net.jini.core.lookup.ServiceRegistration
+ */
+ protected ServiceRegistration[] registerAll() throws TestException {
+ return registerNSrvcsPerClass(nInstancesPerClass);
+ }
+
+ /** Requesting the given duration for the service lease, registers all
+ * service items from the list defined in this class and returns the
+ * resulting ServiceRegistration objects
+ * @param srvcLeaseDurMS number of milliseconds for lease duration
+ * @exception QATestException usually indicates a failure
+ * @return ServiceRegistration an array of objects as defined in
+ * net.jini.core.lookup.ServiceRegistration
+ * @see net.jini.core.lookup.ServiceRegistration
+ */
+ protected ServiceRegistration[] registerAll(long srvcLeaseDurMS)
+ throws TestException
+ {
+ return registerNSrvcsPerClass(nInstancesPerClass,srvcLeaseDurMS);
+ }
+
+ /** Requesting the maximum duration for the service lease, registers
+ * n instances of each of the service items from the list defined
+ * in this class and returns the resulting ServiceRegistration objects
+ * @param n number of instances of each class to register
+ * @exception QATestException usually indicates a failure
+ * @return ServiceRegistration an array of objects as defined in
+ * net.jini.core.lookup.ServiceRegistration
+ * @see net.jini.core.lookup.ServiceRegistration
+ */
+ protected ServiceRegistration[] registerNSrvcsPerClass(int n)
+ throws TestException
+ {
+ int i=0;
+ int j=0;
+ int k=0;
+ int delta = nInstancesPerClass;
+ srvcRegs =
+ new ServiceRegistration[(n*srvcItems.length)/nInstancesPerClass];
+ for(i=0;i<srvcItems.length;i=i+delta) {
+ for(j=i;j<(i+n);j++) {
+ srvcRegs[k++] = registerItem(srvcItems[j],Long.MAX_VALUE,
+ proxy);
+ }
+ }
+ return srvcRegs;
+ }
+
+ /** Requesting the given duration for the service lease, registers
+ * n instances of each of the service items from the list defined
+ * in this class and returns the resulting ServiceRegistration objects
+ * @param n number of instances of each class to register
+ * @param srvcLeaseDurMS number of milliseconds for lease duration
+ * @exception QATestException usually indicates a failure
+ * @return ServiceRegistration an array of objects as defined in
+ * net.jini.core.lookup.ServiceRegistration
+ * @see net.jini.core.lookup.ServiceRegistration
+ */
+ protected ServiceRegistration[] registerNSrvcsPerClass(int n,
+ long srvcLeaseDurMS)
+ throws TestException
+ {
+ int i=0;
+ int j=0;
+ int k=0;
+ int delta = nInstancesPerClass;
+ srvcRegs =
+ new ServiceRegistration[(n*srvcItems.length)/nInstancesPerClass];
+ for(i=0;i<srvcItems.length;i=i+delta) {
+ for(j=i;j<(i+n);j++) {
+ srvcRegs[k++] = registerItem(srvcItems[j],srvcLeaseDurMS,
+ proxy);
+ }
+ }
+ return srvcRegs;
+ }
+
+ /** Requesting the maximum duration for the service lease, uses the
+ * given Registrar proxy to register the given service item and
+ * returns the resulting ServiceRegistration object
+ * @param srvcItem the service item to register
+ * @param regProxy Registrar proxy through which registration occurs
+ * @exception QATestException usually indicates a failure
+ * @return ServiceRegistration object as defined in
+ * net.jini.core.lookup.ServiceRegistration
+ * @see net.jini.core.lookup.ServiceRegistration
+ */
+ protected ServiceRegistration registerItem(ServiceItem srvcItem,
+ ServiceRegistrar regProxy)
+ throws TestException
+ {
+ try {
+ return regProxy.register(srvcItem,Long.MAX_VALUE);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ e.detail.printStackTrace();
+ throw new TestUnresolvedException
+ ("registerItem: RemoteException (srvcItem="+srvcItem+")");
+ }
+ }
+
+
+ /** Requesting the given duration for the service lease, uses the
+ * given Registrar proxy to register the given service item and
+ * returns the resulting ServiceRegistration object
+ * @param srvcItem the service item to register
+ * @param srvcLeaseDurMS number of milliseconds for lease duration
+ * @param regProxy Registrar proxy through which registration occurs
+ * @exception QATestException usually indicates a failure
+ * @return ServiceRegistration object as defined in
+ * net.jini.core.lookup.ServiceRegistration
+ * @see net.jini.core.lookup.ServiceRegistration
+ */
+ protected ServiceRegistration registerItem(ServiceItem srvcItem,
+ long srvcLeaseDurMS,
+ ServiceRegistrar regProxy)
+ throws TestException
+ {
+ try {
+ return regProxy.register(srvcItem,srvcLeaseDurMS);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ throw new TestUnresolvedException
+ ("registerItem: RemoteException (srvcItem="+srvcItem+")");
+ }
+ }
+
+}
Propchange: river/tck/src/com/sun/jini/compat/test/lookup/TestRegistrar.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/tck/src/com/sun/jini/compat/test/lookup/TestUnresolvedException.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/test/lookup/TestUnresolvedException.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/test/lookup/TestUnresolvedException.java (added)
+++ river/tck/src/com/sun/jini/compat/test/lookup/TestUnresolvedException.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,58 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed 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.compat.test.lookup;
+
+import com.sun.jini.compat.test.lookup.TestException;
+
+/** Class that represents conditions indicating neither true failure
+ * nor true success that occur during processing of any LDJ Kit lookup tests.
+ * Such a condition will
+ * result in the test run being labelled as "unresolved". A typical
+ * example of an unresolved condition during a run of LDJ Kit lookup tests
+ * would be when an exception occurs during test setup; this might be
+ * due to network failure, problems in the Activation daemon, etc. In
+ * this case, the test has certainly not succeeded; but neither did it
+ * fail since it was never allowed to start. Whenever an unresolved
+ * condition occurs during a test run, this exception will be thrown.
+ *
+ * @see com.sun.jini.compat.test.lookup.TestException
+ */
+public class TestUnresolvedException extends TestException {
+
+ /** Creates a TestUnresolvedException */
+ public TestUnresolvedException(){
+ super();
+ }
+
+ /** Creates a TestUnresolvedException with the given String
+ * @param s String to display
+ */
+ public TestUnresolvedException(String s){
+ super(s);
+ }
+
+ /** Creates a TestUnresolvedException with the given String and the
+ * given nested exception
+ * @param s String to display
+ * @param e nested exception detail
+ */
+ public TestUnresolvedException(String s,
+ Throwable e){
+ super(s,e);
+ }
+}
Propchange: river/tck/src/com/sun/jini/compat/test/lookup/TestUnresolvedException.java
------------------------------------------------------------------------------
svn:eol-style = native