public void testPersistenceWithBadState()
        {
            //create new cache for agent
            RequestCache cache = RequestCache.GetInstance(fAgent);

            //create new queryobject
            SIF_QueryObject obj = new SIF_QueryObject("");
            //create query, telling it what type of query it is(passing it queryobj)
            SIF_Query query = new SIF_Query(obj);
            //create new sif request
            SIF_Request request = new SIF_Request();
            //set query property
            request.SIF_Query = query;

            Query q = new Query(StudentDTD.STUDENTPERSONAL);

            String testStateItem = Adk.MakeGuid();
            String requestMsgId = Adk.MakeGuid();
            String testObjectType = Adk.MakeGuid();

            TestState ts = new TestState();
            ts.State = testStateItem;
            ts.setCreateErrorOnRead(true);

            q.UserData = ts;
            storeRequest(cache, request, q, requestMsgId, testObjectType);

            cache.Close();

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

            IRequestInfo ri = cache.GetRequestInfo(requestMsgId, null);

            //if state is null, should still return ri object
            Assertion.AssertNotNull("RequestInfo was null", ri);
            Assertion.AssertEquals("MessageId", requestMsgId, ri.MessageId);
            Assertion.AssertEquals("ObjectType", testObjectType, ri.ObjectType);
            ts = (TestState) ri.UserData;
            // In order for this to be a valid test, the TestState class should have thrown
            // an exception during deserialization and should be null here.
            Assertion.AssertNull("UserData should be null", ts);
        }
        /**
           * Stores the items in the cache that will later be asserted
           * @param cache
           */
        private void storeAssertedRequests(RequestCache cache)
        {
            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;
            TestState ts;

            fMsgIds = new String[10];
            fStateObjects = new String[10];
            // Add 10 entries to the cache, interspersed with other entries that are removed
            for (int i = 0; i < 10; i++)
            {
                ts = new TestState();
                ts.State = Adk.MakeGuid();
                fStateObjects[i] = ts.State;
                q = new Query(StudentDTD.STUDENTPERSONAL);
                q.UserData = ts;

                String phantom1 = Adk.MakeGuid();
                String phantom2 = Adk.MakeGuid();
                storeRequest(cache, request, q, phantom1, "foo");
                fMsgIds[i] = Adk.MakeGuid();

                storeRequest(cache, request, q, fMsgIds[i], "Object_" + i.ToString());
                storeRequest(cache, request, q, phantom2, "bar");

                cache.GetRequestInfo(phantom1, null);
                cache.GetRequestInfo(phantom2, null);
            }
        }
        public void testWithLegacyFile()
        {
            //assertStoredRequests(fRC, true);
            // Copy the legacy requests.adk file to the agent work directory
            //FileInfo legacyFile = new FileInfo("requests.adk");

            //Assertion.Assert("Saved legacy file does [not?] exist", legacyFile.Exists);
            //FileInfo copiedFile = new FileInfo(fAgent.HomeDir + Path.DirectorySeparatorChar + "work" + Path.DirectorySeparatorChar + "requests.adk");
            //if (copiedFile.Exists)
            //{
            //   copiedFile.Delete();
            //}

            //// Copy the file
            //legacyFile.CopyTo(copiedFile.FullName, true);

            // Now open up an instance of the request cache and verify that the contents are there

            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;
            TestState ts;

            fMsgIds = new String[10];
            fStateObjects = new String[10];
            // Add 10 entries to the cache
            for (int i = 0; i < 10; i++)
            {
                ts = new TestState();
                ts.State = Adk.MakeGuid();
                fStateObjects[i] = (String) ts.State;
                q = new Query(StudentDTD.STUDENTPERSONAL);
                q.UserData = ts;
                fMsgIds[i] = Adk.MakeGuid();
                storeRequest(fRC, request, q, fMsgIds[i], "Object_" + i.ToString());
            }

            Assertion.AssertEquals("Active request count", 10, fRC.ActiveRequestCount);

            // Lookup each setting,
            for (int i = 0; i < 10; i++)
            {
                IRequestInfo reqInfo = fRC.LookupRequestInfo(fMsgIds[i], null);
                Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType);
            }

            // Lookup each setting,
            for (int i = 0; i < 10; i++)
            {
                IRequestInfo reqInfo = fRC.GetRequestInfo(fMsgIds[i], null);
                Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType);
            }

            // all messages should now be removed from the queue
            Assertion.AssertEquals("Cache should be empty", 0, fRC.ActiveRequestCount);

            // Now run one of our other tests
            testPersistence();
        }
        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);
        }
        public void testSIFRetryQueryResults()
        {
            TestState requestState = new TestState(Adk.MakeGuid());
             IElementDef objType = StudentDTD.STUDENTCONTACT;
             ErrorMessageHandler handler =
             new ErrorMessageHandler(ErrorMessageHandler.HandlerBehavior.ThrowSIFRetryException);
             handler.RequestStateObject = requestState;
             fZone.SetQueryResults(handler, objType, null);
             fZone.Connect(ProvisioningFlags.Register);
             SIF_Response r = createSIF_Response(objType, true, requestState);
             AssertRetryHandling(handler, r, fZone);

             // Now, dispatch a second time. This time the dispatching should work correctly, including
             // custom state
             handler.Behavior = ErrorMessageHandler.HandlerBehavior.Normal;
             assertNormalHandling(handler, r, fZone);
             assertRequestCacheCleared(r);
        }
예제 #6
0
        public void testWithLegacyFile()
        {
            //assertStoredRequests(fRC, true);
            // Copy the legacy requests.adk file to the agent work directory
            //FileInfo legacyFile = new FileInfo("requests.adk");

            //Assertion.Assert("Saved legacy file does [not?] exist", legacyFile.Exists);
            //FileInfo copiedFile = new FileInfo(fAgent.HomeDir + Path.DirectorySeparatorChar + "work" + Path.DirectorySeparatorChar + "requests.adk");
            //if (copiedFile.Exists)
            //{
            //   copiedFile.Delete();
            //}

            //// Copy the file
            //legacyFile.CopyTo(copiedFile.FullName, true);

            // Now open up an instance of the request cache and verify that the contents are there


            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;
            TestState ts;

            fMsgIds = new String[10];
            fStateObjects = new String[10];
            // Add 10 entries to the cache 
            for (int i = 0; i < 10; i++)
            {
                ts = new TestState();
                ts.State = Adk.MakeGuid();
                fStateObjects[i] = (String) ts.State;
                q = new Query(StudentDTD.STUDENTPERSONAL);
                q.UserData = ts;
                fMsgIds[i] = Adk.MakeGuid();
                storeRequest(fRC, request, q, fMsgIds[i], "Object_" + i.ToString());
            }


            Assertion.AssertEquals("Active request count", 10, fRC.ActiveRequestCount);


            // Lookup each setting, 
            for (int i = 0; i < 10; i++)
            {
                IRequestInfo reqInfo = fRC.LookupRequestInfo(fMsgIds[i], null);
                Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType);
            }

            // Lookup each setting, 
            for (int i = 0; i < 10; i++)
            {
                IRequestInfo reqInfo = fRC.GetRequestInfo(fMsgIds[i], null);
                Assertion.AssertEquals("Initial lookup", "Object_" + i.ToString(), reqInfo.ObjectType);
            }

            // all messages should now be removed from the queue
            Assertion.AssertEquals("Cache should be empty", 0, fRC.ActiveRequestCount);

            // Now run one of our other tests
            testPersistence();
        }