public void testPersistence()
        {
            fRC = RequestCache.GetInstance(fAgent);
            storeAssertedRequests(fRC);
            fRC.Close();

            // Create a new instance. This one should retrieve its settings from the persistence mechanism
            fRC = RequestCache.GetInstance(fAgent);
            assertStoredRequests(fRC, true);

            fRC.Close();
            fRC = RequestCache.GetInstance(fAgent);
            Assertion.AssertEquals("Should have zero pending requests", 0, fRC.ActiveRequestCount);
        }
        public void testWithCorruptFile()
        {
            // Delete the existing cache file, if it exists
            String fname = fAgent.HomeDir + Path.DirectorySeparatorChar + "work" + Path.DirectorySeparatorChar +
                           "requestcache.adk";
            FileInfo fi = new FileInfo(fname);
            StreamWriter sw = fi.CreateText();
            sw.WriteLine("!@#$!@#$");
            sw.Flush();
            sw.Close();

            //RandomAccessFile raf = new RandomAccessFile(fname, "rw");
            //raf.writeChars("!@#$!@#$");
            // raf.close();

            fRC = RequestCache.GetInstance(fAgent);
            storeAssertedRequests(fRC);
            fRC.Close();

            // Create a new instance. This one should retrieve its settings from the persistence mechanism
            fRC = RequestCache.GetInstance(fAgent);
            assertStoredRequests(fRC, true);
        }
        public void testPersistenceWithRemoval()
        {
            fRC = RequestCache.GetInstance(fAgent);
            SIF_QueryObject obj = new SIF_QueryObject("");
            SIF_Query query = new SIF_Query(obj);
            SIF_Request request = new SIF_Request();

            request.SIF_Query = query;

            Query q = new Query(StudentDTD.STUDENTPERSONAL);
            String testStateItem = Adk.MakeGuid();
            TestState ts = new TestState();
            ts.State = testStateItem;
            q.UserData = ts;

            fMsgIds = new String[10];
            // Add 10 entries to the cache, interspersed with other entries that are removed
            for (int i = 0; i < 10; i++)
            {
                String phantom1 = Adk.MakeGuid();
                String phantom2 = Adk.MakeGuid();
                storeRequest(fRC, request, q, phantom1, "foo");
                fMsgIds[i] = Adk.MakeGuid();
                storeRequest(fRC, request, q, fMsgIds[i], "Object_" + i);
                storeRequest(fRC, request, q, phantom2, "bar");

                fRC.GetRequestInfo(phantom1, null);
                fRC.GetRequestInfo(phantom2, null);
            }

            // remove every other entry, close, re-open and assert that the correct entries are there
            for (int i = 0; i < 10; i += 2)
            {
                fRC.GetRequestInfo(fMsgIds[i], null);
            }

            Assertion.AssertEquals("Before closing Should have five objects", 5, fRC.ActiveRequestCount);
            fRC.Close();

            // Create a new instance. This one should retrieve its settings from the persistence mechanism
            fRC = RequestCache.GetInstance(fAgent);
            Assertion.AssertEquals("After Re-Openeing Should have five objects", 5, fRC.ActiveRequestCount);
            for (int i = 1; i < 10; i += 2)
            {
                IRequestInfo cachedInfo = fRC.GetRequestInfo(fMsgIds[i], null);
                Assertion.AssertNotNull("No cachedID returned for " + i, cachedInfo);
            }
            Assertion.AssertEquals("Should have zero objects", 0, fRC.ActiveRequestCount);
        }