Example #1
0
        /*
        ****************************************************************************
        * testCache()
        ****************************************************************************
        */
        /**
        *
        */
        public void testCache()
        {
            Cache oCache = new Cache(1000);
            assertTrue("Initial cache not empty", oCache.getNumNodes() == 0);

            XRD oDesc = new XRD();
            Service atAuthService = new Service();
            atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
            atAuthService.addType(Tags.SERVICE_AUTH_RES);
            atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at");
            oDesc.addService(atAuthService);

            XRD oDummy = new XRD();
            Service dummyService = new Service();
            dummyService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
            dummyService.addType(Tags.SERVICE_AUTH_RES);
            dummyService.addURI("http://www.example.com/xri/resolve?id=1");
            oDummy.addService(dummyService);

            GCSAuthority oAuth = new GCSAuthority("@");
            oCache.stuff(oAuth, oDesc);
            assertTrue("Initial cache incorrect", oCache.getNumNodes() == 1);

            oCache.stuff(
            (XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!b!foo"), oDummy);
            assertTrue("Cache size incorrect", oCache.getNumNodes() == 4);

            oCache.stuff(
            (XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!c!moo"), oDummy);
            assertTrue("Cache size incorrect", oCache.getNumNodes() == 6);

            oCache.stuff(
            (XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!c!woo"), oDummy);
            assertTrue("Cache size incorrect", oCache.getNumNodes() == 7);

            Cache.CachedValue oVal =
            oCache.find(
                (XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!c!woo"),
                false);
            assertTrue("Cached value not found", oVal != null);

            oVal =
            oCache.find(
                (XRIAuthority) AuthorityPath.buildAuthorityPath("@!a!b!woo"),
                false);
            assertTrue("Cached value should not have been found", oVal == null);
            oCache.dump();
        }
Example #2
0
        /*
        ****************************************************************************
        * Constructor()
        ****************************************************************************
        */
        /**
         *  This is used to add a new CacheNode to the cache
         */
        CacheNode(CacheNode oParent, string sSubsegment)
        {
            // we need to keep track of these for the removeSelf method
            moParent = oParent;
            msSubsegment = sSubsegment;
            moCache = oParent.moCache;
            moCache.increment();

            addToFront();
        }
Example #3
0
        Hashtable moCacheHash = new Hashtable(); // this was a synchronized object in java

        #endregion Fields

        #region Constructors

        /*
        ****************************************************************************
        * Constructor()
        ****************************************************************************
        */
        /**
         * This constructor is used only for the root node, makes a circular
         * doubly linked list
         */
        internal CacheNode(Cache oCache)
        {
            moCache = oCache;
            moNext = this;
            moPrev = this;
        }
Example #4
0
            /*
            ************************************************************************
            * run()
            ************************************************************************
            */
            /**
            *
            */
            public void run()
            {
                XRD oDummy = new XRD();
                Service dummyService = new Service();
                dummyService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
                dummyService.addType(Tags.SERVICE_AUTH_RES);
                dummyService.addURI("http://www.example.com/xri/resolve?id=1");
                oDummy.addService(dummyService);

                String[] oCases =
                { "@!a1!b2!c3!d4", "@!x1!y2!z3", "@!a1!b2!c3", "@!a1!b2", "@!a1!b2!m3", "@!a1!o2!p3", "@!a1!o2!q3", "@!a1!b2!c3!d4!e5", "@!x1!y2" };

                Cache oCache = new Cache(1000);

                for (int i = 0; i < 1000; i++)
                {
                int x = moRand.nextInt(oCases.length);
                bool bStuff = moRand.nextBoolean();
                XRIAuthority oAuth =
                    (XRIAuthority) AuthorityPath.buildAuthorityPath(oCases[x]);

                if (bStuff)
                {
                    oCache.stuff(oAuth, oDummy);
                }
                else
                {
                    oCache.prune(oAuth);
                }

                oCache.find(oAuth, true);
                }
            }
Example #5
0
        /*
        ****************************************************************************
        * testConcurrent()
        ****************************************************************************
        */
        /**
        *
        */
        public void testConcurrent()
        {
            Cache oCache = new Cache(1000);
            oCache.prune((XRIAuthority) AuthorityPath.buildAuthorityPath("@"));
            assertTrue("Initial cache not empty", oCache.getNumNodes() == 0);

            XRD oDesc = new XRD();
            Service atAuthService = new Service();
            atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
            atAuthService.addType(Tags.SERVICE_AUTH_RES);
            atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at");
            oDesc.addService(atAuthService);

            GCSAuthority oAuth = new GCSAuthority("@");
            oCache.stuff(oAuth, oDesc);
            assertTrue("Initial cache incorrect", oCache.getNumNodes() == 1);

            oCache.setMaxSize(5);

            Random oRand = new Random();

            try
            {
            Thread[] oThreads = new StuffPruneThread[100];
            for (int i = 0; i < oThreads.length; i++)
            {
                oThreads[i] = new StuffPruneThread(oRand);
            }

            for (int i = 0; i < oThreads.length; i++)
            {
                oThreads[i].start();
            }

            for (int i = 0; i < oThreads.length; i++)
            {
                oThreads[i].join();
            }
            }
            catch (Exception e)
            {
            assertTrue("Unexpected exception" + e, false);
            }

            oCache.dump();

            assertTrue(
            "Max cache size not honored",
            oCache.getNumNodes() <= oCache.getMaxSize());

            Cache.CachedValue oVal =
            oCache.find(
                (XRIAuthority) AuthorityPath.buildAuthorityPath("@"), false);
            assertTrue("Cached value for @ not found", oVal != null);
        }
Example #6
0
    /*
    ****************************************************************************
    * Constructor()
    ****************************************************************************
    */ /**
    * This constructor is used only for the root node, makes a circular
    * doubly linked list
    */
    CacheNode(Cache oCache)
    {
        moCache = oCache;
        moNext = this;
        moPrev = this;

    } // Constructor()