Package com.volantis.impl.mcs.runtime.policies

Examples of com.volantis.impl.mcs.runtime.policies.CachingActivatedPolicyRetriever


        // =====================================================================
        //   Test Expectations
        // =====================================================================
        ActivatedPolicyRetriever retriever =
                new CachingActivatedPolicyRetriever(policyCache, retrieverMock);
        ActivatedPolicy actualPolicy;

        // Get the policy, this should invoke the underlying retriever.
        actualPolicy = retriever.retrievePolicy(projectMock, projectRelativeName);
        assertSame(policy, actualPolicy);

        // Get the policy, this should get the policy from the cache.
        actualPolicy = retriever.retrievePolicy(projectMock, projectRelativeName);
        assertSame(policy, actualPolicy);

        // Make sure that the object was stored in the cache.
        Object object = policyCache.retrieve(
                new ProjectSpecificKey(projectMock, projectRelativeName),
View Full Code Here


        // =====================================================================
        //   Test Expectations
        // =====================================================================
        ActivatedPolicyRetriever retriever =
                new CachingActivatedPolicyRetriever(policyCache, retrieverMock);
        ActivatedPolicy actualPolicy;

        // Get the policy, this should invoke the underlying retriever.
        actualPolicy = retriever.retrievePolicy(projectMock, projectRelativeName);
        assertSame(policy, actualPolicy);

        // Get the policy, this should get the policy from the cache.
        actualPolicy = retriever.retrievePolicy(projectMock, projectRelativeName);
        assertSame(policy, actualPolicy);

        // Make sure that the object was stored in the cache.
        Object object = policyCache.retrieve(remoteName, providerMock);
        assertSame(policy, object);
View Full Code Here

        // =====================================================================
        //   Test Expectations
        // =====================================================================
        ActivatedPolicyRetriever retriever =
                new CachingActivatedPolicyRetriever(policyCache, retrieverMock);
        ActivatedPolicy policy;

        // Get the policy, this should invoke the underlying retriever.
        policy = retriever.retrievePolicy(projectMock, projectRelativeName);
        assertNull(policy);

        // Get the policy, this should get the policy from the cache.
        policy = retriever.retrievePolicy(projectMock, projectRelativeName);
        assertNull(policy);
    }
View Full Code Here

        // =====================================================================
        //   Test Expectations
        // =====================================================================

        ActivatedPolicyRetriever retriever =
                new CachingActivatedPolicyRetriever(policyCache, retrieverMock);
        Policy actualPolicy;

        // ---------------------------------------------------------------------
        //   First Request
        // ---------------------------------------------------------------------

        // First request fails to find the policy in the cache so retrieves
        // it and stores it in the cache.

        // The policy returned by the retriever underlying the provider.
        retrieverMock.expects
                .retrievePolicy(projectMock, projectRelativeName)
                .returns(originalPolicy);

        // The current time for the calculation of the expiration time.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(1000));

        actualPolicy = retriever.retrievePolicy(projectMock,
                projectRelativeName);
        assertSame(originalPolicy, actualPolicy);

        expectations.verify();

        // ---------------------------------------------------------------------
        //   Second Request
        // ---------------------------------------------------------------------

        // Second request finds the policy in the cache and it has not yet
        // expired so is returned without invoking the provider.

        // The current time used to determine whether the policy has expired.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(1500));

        actualPolicy = retriever.retrievePolicy(projectMock,
                projectRelativeName);
        assertSame(originalPolicy, actualPolicy);

        expectations.verify();

        // ---------------------------------------------------------------------
        //   Third Request
        // ---------------------------------------------------------------------

        // Third request finds the policy in the cache but it has expired so
        // the provider is invoked.

        // The current time used to determine whether the policy has expired.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(2500));

        // The new policy returned by the retriever underlying the provider.
        retrieverMock.expects
                .retrievePolicy(projectMock, projectRelativeName)
                .returns(refreshedPolicy);

        // The current time used to calculate the expiration time of the newly
        // retrieved policy. This is different to the above as it will
        // happen after the provider has returned the policy which will be
        // some time afterwards.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(3000));

        actualPolicy = retriever.retrievePolicy(projectMock,
                projectRelativeName);
        assertSame(refreshedPolicy, actualPolicy);

        expectations.verify();

        // ---------------------------------------------------------------------
        //   Fourth Request
        // ---------------------------------------------------------------------

        // Fourth request occurs after the policy has expired and retry is
        // due but fails.

        // Time is after expiry time.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(6500));

        retrieverMock.expects
                .retrievePolicy(projectMock, projectRelativeName)
                .returns(null);

        projectMock.expects.getCacheControlDefaults()
                .returns(constraints.getDefaultCacheControl());

        // Get the time after the retriever has failed to return a policy so
        // that it can calculate the expiry time for the retry.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(8000));

        actualPolicy = retriever.retrievePolicy(projectMock,
                projectRelativeName);
        assertSame(refreshedPolicy, actualPolicy);

        expectations.verify();

        // ---------------------------------------------------------------------
        //   Fifth Request
        // ---------------------------------------------------------------------

        // Fifth request occurs before the retry period is due so should not
        // invoke the retriever.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(8999));

        actualPolicy = retriever.retrievePolicy(projectMock,
                projectRelativeName);
        assertSame(refreshedPolicy, actualPolicy);

        expectations.verify();

        // ---------------------------------------------------------------------
        //   Sixth Request
        // ---------------------------------------------------------------------

        // Sixth request occurs after the retry period has passed and so should
        // invoke the retriever.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(11000));

        retrieverMock.expects
                .retrievePolicy(projectMock, projectRelativeName)
                .returns(originalPolicy);

        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(12000));

        actualPolicy = retriever.retrievePolicy(projectMock,
                projectRelativeName);
        assertSame(originalPolicy, actualPolicy);
    }
View Full Code Here

        // =====================================================================
        //   Test Expectations
        // =====================================================================

        ActivatedPolicyRetriever retriever =
                new CachingActivatedPolicyRetriever(policyCache, retrieverMock);

        Policy actualPolicy;

        // ---------------------------------------------------------------------
        //   First Request
        // ---------------------------------------------------------------------

        // First request fails to find the policy in the cache and cannot
        // retrieve one either.

        retrieverMock.expects
                .retrievePolicy(projectMock, projectRelativeName)
                .returns(null);

        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(1000));

        actualPolicy = retriever.retrievePolicy(projectMock,
                projectRelativeName);
        assertNull(actualPolicy);

        expectations.verify();

        // ---------------------------------------------------------------------
        //   Second Request
        // ---------------------------------------------------------------------

        // Second request occurs before the policy has expired.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(1500));

        actualPolicy = retriever.retrievePolicy(projectMock,
                projectRelativeName);
        assertNull(actualPolicy);

        expectations.verify();

        // ---------------------------------------------------------------------
        //   Third Request
        // ---------------------------------------------------------------------

        // Third request occurs after the policy has expired and a retry is
        // due and succeeds.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(4000));

        retrieverMock.expects
                .retrievePolicy(projectMock, projectRelativeName)
                .returns(policy);

        // Get the current time for calculating the expiration time.
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(5000));

        actualPolicy = retriever.retrievePolicy(projectMock,
                projectRelativeName);
        assertSame(policy, actualPolicy);
    }
View Full Code Here

TOP

Related Classes of com.volantis.impl.mcs.runtime.policies.CachingActivatedPolicyRetriever

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.