*
*/
public void testStore()
{
// Keep an authority around
Service oAuth = null;
///
// List namespaces, none present
///
try
{
assertEquals(0, moAdmin.listRootAuthorities().length);
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Create a root authority
///
try
{
oAuth = moAdmin.createRootAuthority("SomeNS");
assertNotNull(oAuth);
assertNotNull(oAuth.getProviderID());
assertTrue(oAuth.getNumURIs() > 0);
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Create a duplicate root authority
///
try
{
oAuth = moAdmin.createRootAuthority("SomeNS");
fail("Expected exception, but received none.");
}
catch (StoreException oEx)
{
assertEquals(Util.KEY_DUPNAME, oEx.getExKey());
}
///
// NEW Create a null-namespace root authority.
// Passing null via IIOP is a no-no.
///
boolean bIIOPFailure = false;
try
{
moAdmin.createRootAuthority(null);
fail("Expected exception, but received none.");
}
catch (StoreException oEx)
{
assertEquals(Util.KEY_NOTFOUND, oEx.getExKey());
}
catch (BAD_PARAM oEx)
{
// Expected that
bIIOPFailure = true;
}
///
// Find an existing namespace
///
try
{
Service oAuth2 = moAdmin.findRootAuthority("SomeNS");
assertNotNull(oAuth2);
assertNotNull(oAuth2.getProviderID());
assertTrue(oAuth.getNumURIs() > 0);
assertEquals(oAuth.getProviderID(), oAuth2.getProviderID());
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Find a non-existent namespace
///
try
{
moAdmin.findRootAuthority("nonexistent");
fail("Expected exception, but received none.");
}
catch (StoreException oEx)
{
assertEquals(Util.KEY_NOTFOUND, oEx.getExKey());
}
///
// NEW Find a null namespace
// What should the outcome of this test be?
///
bIIOPFailure = false;
try
{
moAdmin.findRootAuthority(null);
fail("Expected exception, but received none.");
}
catch (StoreException oEx)
{
assertEquals(Util.KEY_NOTFOUND, oEx.getExKey());
}
catch (BAD_PARAM oEx)
{
// Expected that
bIIOPFailure = true;
}
///
// Register a subsegment
///
bIIOPFailure = false;
try
{
Service[] oLocals = new Service[0];
String[] oInternals = new String[0];
String[] oExternals = new String[0];
Service oSubAuth = new Service();
moAdmin.registerSubsegment(
oAuth.getProviderID(), ".foo", oLocals, oInternals, oExternals,
oSubAuth);
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
catch (BAD_PARAM oEx)
{
// Expected that
bIIOPFailure = true;
}
///
// Perform an IIOP-safe registration of a subsegment
///
if (bIIOPFailure)
{
try
{
Service[] oLocals = new Service[0];
String[] oInternals = new String[0];
String[] oExternals = new String[0];
// IIOP-safe authority
Service oSubAuth = new Service();
moAdmin.registerSubsegment(
oAuth.getProviderID(), ".foo", oLocals, oInternals,
oExternals, oSubAuth);
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
} // if(bIIOPFailure)
bIIOPFailure = false;
///
// Register a duplicate subsegment
///
try
{
Service[] oLocals = new Service[0];
String[] oInternals = new String[0];
String[] oExternals = new String[0];
// IIOP-safe authority
Service oSubAuth = new Service();
moAdmin.registerSubsegment(
oAuth.getProviderID(), ".foo", oLocals, oInternals, oExternals,
oSubAuth);
fail("Expected exception, but received none.");
}
catch (StoreException oEx)
{
assertEquals(Util.KEY_DUPNAME, oEx.getExKey());
}
///
// NEW Retrieve a descriptor
///
try
{
String sDescriptor =
moAdmin.lookup(oAuth.getProviderID(), ".foo", false)
.getDescriptor();
assertNotNull(sDescriptor);
assertTrue(sDescriptor.length() > 0);
// XXX is the value correct?
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Release a subsegment
///
try
{
moAdmin.releaseSubsegment(oAuth.getProviderID(), ".foo");
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Re-Release a subsegment
///
try
{
moAdmin.releaseSubsegment(oAuth.getProviderID(), ".foo");
fail("Expected exception, but received none.");
}
catch (StoreException oEx)
{
assertEquals(Util.KEY_NOTFOUND, oEx.getExKey());
}
///
// NEW Retrieve a deleted descriptor
///
try
{
String sDescriptor =
moAdmin.lookup(oAuth.getProviderID(), ".foo", false)
.getDescriptor();
assertNull(sDescriptor);
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Re-Register a subsegment
///
try
{
Service[] oLocals = new Service[0];
String[] oInternals = new String[0];
String[] oExternals = new String[0];
// IIOP-safe authority
Service oSubAuth = new Service();
moAdmin.registerSubsegment(
oAuth.getProviderID(), ".foo", oLocals, oInternals, oExternals,
oSubAuth);
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// NEW Retrieve a re-registered descriptor
///
try
{
String sDescriptor =
moAdmin.lookup(oAuth.getProviderID(), ".foo", false)
.getDescriptor();
assertNotNull(sDescriptor);
assertTrue(sDescriptor.length() > 0);
// XXX is the value correct?
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Register a local authority
///
try
{
Service[] oLocals = new Service[0];
String[] oInternals = new String[0];
String[] oExternals = new String[0];
Service oSubAuth =
moAdmin.registerLocalAuthority(
oAuth.getProviderID(), ".boo", oLocals, oInternals,
oExternals);
assertNotNull(oSubAuth);
assertNotNull(oSubAuth.getProviderID());
assertTrue(oSubAuth.getProviderID() != "");
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Delete a namespace (root authority)
///
try
{
moAdmin.deleteRootAuthority("SomeNS");
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Delete an authority
///
try
{
moAdmin.deleteAuthority(oAuth.getProviderID());
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Re-Delete an authority
///
try
{
moAdmin.deleteAuthority(oAuth.getProviderID());
}
catch (StoreException oEx)
{
fail("Received unexpected exception " + oEx.getExMessage());
}
///
// Retrieve the list of namespaces (no leftovers)
///
try
{
assertEquals(0, moAdmin.listRootAuthorities().length);
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// One last, comprehensive test
///
Service oDefaultAuth = null;
Service oHostIDAuth = null;
try
{
Service[] oServices = new Service[1];
// IIOP-safe Service structure
oServices[0] = new Service();
oServices[0].setType("xri:@epok/tdx/xrixns");
oServices[0].setMediaType("text/xml");
oServices[0].addURI("xri://@!42!3");
oHostIDAuth = moAdmin.createRootAuthority("hostid");
oDefaultAuth = moAdmin.createRootAuthority("default");
Service oNewAuth =
moAdmin.registerLocalAuthority(
oDefaultAuth.getProviderID(), ".email", oServices,
new String[0], new String[0]);
// IIOP-safe Authority
Service oEmptyAuth = new Service();
moAdmin.registerSubsegment(
oNewAuth.getProviderID(), ".chetan", new Service[0],
new String[0], new String[0], oEmptyAuth);
moAdmin.releaseSubsegment(oNewAuth.getProviderID(), ".chetan");
System.out.println("");
// List namespaces
String[] oNamespaces = moAdmin.listRootAuthorities();
for (int x = 0; x < oNamespaces.length; x++)
{
System.out.println("Namespace " + x + ": " + oNamespaces[x]);
// Account for stale namespaces
try
{
Service oRootAuth =
moAdmin.findRootAuthority(oNamespaces[x]);
System.out.println(" ID " + oRootAuth.getProviderID());
}
catch (StoreException oEx)
{
System.out.println(" No Authority");
}
}
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// A little performace test. One thread.
///
try
{
String sDescriptor =
moAdmin.lookup(oDefaultAuth.getProviderID(), ".email", false)
.getDescriptor();
assertNotNull(sDescriptor);
assertTrue(sDescriptor.length() > 0);
int iCount = 1000;
long lStamp = System.currentTimeMillis();
for (int x = 0; x < iCount; x++)
{
moAdmin.lookup(oDefaultAuth.getProviderID(), ".email", false);
}
lStamp = System.currentTimeMillis() - lStamp;
System.err.println(
iCount + " descriptor retrievals took " + lStamp + "ms.");
}
catch (StoreException oEx)
{
oEx.printStackTrace();
fail(
"Caught unexpected exception '" + oEx.getExKey() + "' '" +
oEx.getExMessage() + "'.");
}
///
// Multiple threads.
///
Thread[] oThreads = new Thread[10];
for (int x = 0; x < 10; x++)
{
oThreads[x] =
new Thread(
new DescriptorRetriever(
moAdmin, oDefaultAuth.getProviderID(), ".email", 1000));
}
long lStamp = System.currentTimeMillis();
for (int x = 0; x < 10; x++)
{
oThreads[x].start();
}
for (int x = 0; x < 10; x++)
{
try
{
oThreads[x].join();
}
catch (InterruptedException oEx) {}
}
lStamp = System.currentTimeMillis() - lStamp;
System.err.println(
(10 * 1000) + " descriptor retrievals took " + lStamp + "ms.");
// clean up namespaces;
try
{
String[] oNamespaces = moAdmin.listRootAuthorities();
for (int x = 0; x < oNamespaces.length; x++)
{
System.out.println(
"Deleting Namespace " + x + ": " + oNamespaces[x]);
Service oCurrentAuth =
moAdmin.findRootAuthority(oNamespaces[x]);
moAdmin.deleteRootAuthority(oNamespaces[x]);
moAdmin.deleteAuthority(oCurrentAuth.getProviderID());
}
}
catch (StoreException e)
{
assertTrue(