Package com.volantis.mcs.cache

Examples of com.volantis.mcs.cache.CacheIdentity


        //
        // Store our WritableCSSEntityMock in the cache and get the identity
        // that can be used to retrieve the entry.
        //
        CacheIdentity identity = cache.store(
                new CSSCacheEntry(writableCSSEntityMock));


        //
        // EXPECTATIONS
        //

        //
        // Setup a usable servlet environment using mocks.
        //
        ServletHelper.setExpectedResults(expectations,
                servletConfigMock,
                servletContextMock,
                CSSServlet.class);


        //
        // Create a writer for the HttpServletResponse to use
        //

        StringWriter stringWriter = new StringWriter();

        PrintWriter printWriter = new PrintWriter(stringWriter);

        //
        // We don't need a fully initialised Volantis bean so we can
        // return a MarinerServletApplicationMock.
        //
        servletContextMock
                .expects
                .getAttribute("marinerApplication")
                .returns(marinerApplicationMock);

        //
        // We need to register our Version of the Volantis bean against our
        // MarinerServketApplicationMock as we cannot overide the
        // getVolantisBean() method which is package protected.
        //

        ApplicationInternals.setVolantisBean(marinerApplicationMock, volantis);
//        marinerApplicationMock
//                .expects
//                .getVolantisBean()
//                .returns(volantis).any();

        //
        // For piece of mind we will get our WritableCSSEntityMock to actually
        // write something to its supplied writer. That way we know for sure
        // that the servlet works end to end.
        //
        writableCSSEntityMock.expects.write(printWriter).does(new MethodAction() {
            public Object perform(MethodActionEvent event) throws Throwable {
                Writer pw = (Writer) event.getArgument(Writer.class);
                pw.write("foo");
                return null;
            }
        });

        httpServletRequestMock
                .expects
                .getParameter("key")
                .returns(identity.getBase64KeyAsString());

        httpServletResponseMock
                .expects
                .getWriter()
                .returns(printWriter);
View Full Code Here


        //
        // Store our WritableCSSEntityMock in the cache and get the identity
        // that can be used to retrieve the entry.
        //
        CacheIdentity identity = cache.store(
                new CSSCacheEntry(writableCSSEntityMock));
        //
        // Now remove all entries so we get a cache miss.
        //
        cache.clear();

        //
        // EXPECTATIONS
        //

        //
        // Setup a usable servlet environment using mocks.
        //
        ServletHelper.setExpectedResults(expectations,
                servletConfigMock,
                servletContextMock,
                CSSServlet.class);

        //
        // We don't need a fully initialised Volantis bean so we can
        // return a MarinerServletApplicationMock.
        //
        servletContextMock
                .expects
                .getAttribute("marinerApplication")
                .returns(marinerApplicationMock);

        //
        // We need to register our Version of the Volantis bean against our
        // MarinerServketApplicationMock as we cannot overide the
        // getVolantisBean() method which is package protected.
        //

        ApplicationInternals.setVolantisBean(marinerApplicationMock, volantis);
//        marinerApplicationMock
//                .expects
//                .getVolantisBean()
//                .returns(volantis).any();


        httpServletRequestMock
                .expects
                .getParameter("key")
                .returns(identity.getBase64KeyAsString());


        httpServletResponseMock.expects.sendError(404);

View Full Code Here

                timeToLive = ttl.inMillis();
            }
        }

        // Create and store CSS Cache Entry.
        final CacheIdentity identity =
            cssCache.store(new CSSCacheEntry(entity, timeToLive));

        MarinerURL baseURL = getBaseURL();
        baseURL.setParameterValue("key", identity.getBase64KeyAsString());

        final String sessionType = configuration.getCssSessionType();
        if (sessionType != null && StyleSheetConfiguration.INCLUDE_SESSION_ID.equals(sessionType)) {
            baseURL = context.getSessionURLRewriter().mapToExternalURL(
                    context.getRequestContext(), baseURL);
View Full Code Here

        // take the greater of entry/store values.
        long identityTimeToLive = (entryTimeToLive == -1) ? timeToLive :
            Math.max(timeToLive, entryTimeToLive);
       
        // Create cache identity with actual time-to-live value.
        CacheIdentity identity =
                entry.generateIdentity(cacheTime,
                        identityTimeToLive,
                        getNextSequenceNumber());
       
        // Put an entry in the cache.
View Full Code Here

    //Javadoc inherited.
    public CacheIdentity retrieveOldestExpiredIdentity() {

        // This variable will hold expired identity to return
        CacheIdentity expiredIdentity = null;
       
        // This varialbe will hold the oldest identity.
        CacheIdentity identity = null;
       
        // Retrieve first key from the TreeMap, which would be the one with
        // least expiresTime value. Note, that the firstKey() method throws
        // NoSuchElementException in case TreeMap is empty, so we need
        // to handle it there.
View Full Code Here

        List identities = new ArrayList();

        synchronized(this) {
            while (keySetIterator.hasNext()) {
                CacheIdentity identity = (CacheIdentity) keySetIterator.next();
                if (isExpired(identity)) {
                    identities.add(identity);
                } else {
                    break;
                }
View Full Code Here

        CacheEntry entry2 = new CSSCacheEntry(writableCSSEntityMock2, 50);
        CacheEntry entry3 = new CSSCacheEntry(writableCSSEntityMock2, 150);

        // We add the first identity which should get a cacheTime of 0,
        // expiresTime of 100 and a sequence number of 0
        CacheIdentity identity1 = defaultCacheStore.store(entry1);
        assertEquals("T1", identity1.getCreateTime(),0);
        assertEquals("T2", identity1.getExpiresTime(),100);
        assertEquals("T3", identity1.getSequenceNo(),0);

        // We add the second identity which should get a cacheTime of 10,
        // expiresTime of max(10+50,10+100)=110 and a sequence number of 1
        CacheIdentity identity2 = defaultCacheStore.store(entry2);
        assertEquals("T4", identity2.getCreateTime(),10);
        assertEquals("T5", identity2.getExpiresTime(),110);
        assertEquals("T6", identity2.getSequenceNo(),1);

        // We add the third identity which should get a cacheTime of 20,
        // expiresTime of max(20+150,20+100)=170 and a sequence number of 2
        CacheIdentity identity3 = defaultCacheStore.store(entry3);
        assertEquals("T7", identity3.getCreateTime(),20);
        assertEquals("T8", identity3.getExpiresTime(),170);
        assertEquals("T9", identity3.getSequenceNo(),2);

        // Retrieve expired identities that are as old or older
        // than 25 - TTL (should be none).
        assertNull("T10", defaultCacheStore.retrieveOldestExpiredIdentity());
View Full Code Here


        CacheEntry entry1 = new CSSCacheEntry(writableCSSEntityMock1);
        CacheEntry entry2 = new CSSCacheEntry(writableCSSEntityMock2, 40);

        CacheIdentity identity1 = defaultCacheStore.store(entry1);
        CacheIdentity identity2 = defaultCacheStore.store(entry2);



        assertEquals(entry1,defaultCacheStore.retrieve(identity1));
        assertEquals(entry2,defaultCacheStore.retrieve(identity2));
View Full Code Here

        CacheStore defaultCacheStore = new DefaultCacheStore(cacheTime,100);


        CacheEntry entry1 = new CSSCacheEntry(writableCSSEntityMock1);

        CacheIdentity identity1 = defaultCacheStore.store(entry1);

        assertEquals(entry1,defaultCacheStore.retrieve(identity1));

        defaultCacheStore.remove(identity1);
        assertNull(defaultCacheStore.retrieve(identity1));
View Full Code Here

        return sequenceNo;
    }

    //Javadoc inherited
    public int compareTo(Object o) {
        CacheIdentity identity = (CacheIdentity) o;
        if (createTime < identity.getCreateTime()) {
            return -1;
        } else if (createTime == identity.getCreateTime()) {
            if (sequenceNo < identity.getSequenceNo()) {
                return -1;
            } else if (sequenceNo == identity.getSequenceNo()) {
                return 0;
            } else {
                return 1;
            }
        } else {
View Full Code Here

TOP

Related Classes of com.volantis.mcs.cache.CacheIdentity

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.