Package com.volantis.cache.provider

Examples of com.volantis.cache.provider.ProviderResult


        // =====================================================================
        //   Set Expectations
        // =====================================================================

        addProviderExpectation(key1, null,
                new ProviderResult(value1, root, true, null));

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

        // =====================================================================
        //   Test Expectations
View Full Code Here


        // =====================================================================
        //   Set Expectations
        // =====================================================================

        addProviderExpectation(key1, null,
                new ProviderResult(value1, root, true, null));

        // =====================================================================
        //   Test Expectations
        // =====================================================================
        Object object;
View Full Code Here

        // =====================================================================

        expectations.add(new OrderedExpectations() {
            public void add() {
                addProviderExpectation(key1, null,
                        new ProviderResult(value1, root, true, null));
                addProviderExpectation(key2, null,
                        new ProviderResult(value2, root, true, null));

                addProviderExpectation(key3, null,
                        new ProviderResult(value3, root, true, null));
                removalListenerMock.fuzzy
                        .entryRemoved(EXPECTED_CACHE_ENTRY)
                        .does(new ExpectCacheEntry(key1, value1));

                addProviderExpectation(key1, null,
                        new ProviderResult(value1, root, true, null));
                removalListenerMock.fuzzy
                        .entryRemoved(EXPECTED_CACHE_ENTRY)
                        .does(new ExpectCacheEntry(key3, value3));
            }
        });
View Full Code Here

        // =====================================================================

        expectations.add(new OrderedExpectations() {
            public void add() {
                addProviderExpectation(key1, null,
                        new ProviderResult(value1, root, true, null));

                // First time expiration checker reports that entry has not
                // expired.
                expirationCheckerMock.fuzzy
                        .hasExpired(clockMock, EXPECTED_CACHE_ENTRY)
                        .returns(false);

                // Second time expiration checker reports that entry has
                // expired.
                expirationCheckerMock.fuzzy
                        .hasExpired(clockMock, EXPECTED_CACHE_ENTRY)
                        .returns(true);

                // Second request retrieves different value but entry still
                // has old value in it. Different value is in different group.
                addProviderExpectation(key1, value1,
                        new ProviderResult(value2, other, true, null));
            }
        });

        // =====================================================================
        //   Test Expectations
View Full Code Here

                new IllegalStateException("expected");

        expectations.add(new OrderedExpectations() {
            public void add() {
                addProviderExpectation(key1, null,
                        new ProviderResult(value1, root, true, null));

                // Expiration check for second request reports that entry has
                // expired.
                expirationCheckerMock.fuzzy
                        .hasExpired(clockMock, EXPECTED_CACHE_ENTRY)
View Full Code Here

        // =====================================================================

        // Expect a request that initially assumes that the entry is cacheable
        // but returns a result that indicates that it is not.
        addProviderExpectation(key1, null,
                new ProviderResult(value1, root, false, null));

        // Retrieve the object, this will work and mark the entry as
        // uncacheable.
        Object value = cache.retrieve(key1);
        assertSame(value1, value);

        // Expect a request for an uncacheable entry that fails with an error.
        Throwable throwable = new Error();
        addUncacheableProviderExpectation(key1, throwable);

        // Retrieve the object, this will fail and should result in an
        // exception being thrown. However, it must not mark the entry as
        // in error because that would be equivalent to caching the result
        // and the entry is uncacheable.
        try {
            cache.retrieve(key1);
            fail("Did not cause exception");
        } catch (Error expected) {
            assertSame(throwable, expected);
        }

        // Expect a request for an uncacheable entry but return a result that
        // indicates that it is now cacheable.
        addUncacheableProviderExpectation(key1,
                new ProviderResult(value2, root, true, null));

        // Retrieve the object again, this will not fail this time and should
        // result in the object being returned.
        value = cache.retrieve(key1);
        assertSame(value2, value);
View Full Code Here

        CacheEntry entry = async.getEntry();
        assertNotNull(entry);

        final SystemClock clock = SystemClock.getDefaultInstance();
        ProviderResult result = new ProviderResult(new Integer(1),
            cache.getRootGroup(), true,
            new PipelineCacheState(
                clock.getCurrentTime().addPeriod(Period.inSeconds(2))));
        async.update(result);
View Full Code Here

        public ExpiredObjectsRemainExpiredCacheableObjectProvider(Group group) {
            this.group = group;
        }

        public ProviderResult retrieve(SystemClock clock, Object key, CacheEntry entry) {
            return new ProviderResult(null, group, false, null);
        }
View Full Code Here

                                       final Object key,
                                       final CacheEntry entry) {
            final PipelineCacheState state = new PipelineCacheState(
                SystemClock.getDefaultInstance().getCurrentTime().addPeriod(
                    value.getDependency().getTimeToLive()));
            return new ProviderResult(value, group, cacheable, state);
        }
View Full Code Here

        HttpContent httpContent;
        CachedHttpContentState state = null;
        HTTPResponseAccessor accessor;
        boolean cacheable = false;
        ProviderResult result = null;
        try {
            // check if validation headers can be added
            if (entry != null) {
                final CachedHttpContentState existingState =
                    (CachedHttpContentState) entry.getExtensionObject();
                if (existingState != null) {
                    // this is a validation
                    // set the If-Modified-Since header using the stored
                    // last modified value (if there is any)
                    final Time lastModified = existingState.getLastModified();
                    if (lastModified != null) {
                        final String lastModifiedAsString;
                        // SimpleDateFormat is not thread safe
                        synchronized (RFC1123) {
                            lastModifiedAsString = RFC1123.format(
                                new Date(lastModified.inMillis()));
                        }
                        final Header header =
                            new HeaderImpl(HeaderNames.IF_MODIFIED_SINCE_HEADER);
                        header.setValue(lastModifiedAsString);
                        executor.addRequestHeader(header);
                    }

                    // set the If-None-Match header with the eTag value, if
                    // there is any
                    final String eTag = existingState.getETag();
                    if (eTag != null && eTag.trim().length() > 0) {
                        final Header header =
                            new HeaderImpl(HeaderNames.IF_NONE_MATCH_HEADER);
                        header.setValue(eTag);
                        executor.addRequestHeader(header);
                    }
                }
            }

            // record the request time
            final CachedHttpContentStateBuilder builder =
                new CachedHttpContentStateBuilder();
            builder.setRequestTime(clock.getCurrentTime());
            accessor = executor.execute();
            // record response time
            builder.setResponseTime(clock.getCurrentTime());

            // process the response
            builder.setMethodAccessor(
                new HttpResponseHeaderAccessorWrapper(accessor));
            httpContent = new HTTPResponseAccessorWrapper(accessor);
            final int statusCode = accessor.getStatusCode();
            if (isStatusCodeCachable(statusCode)) {
                state = builder.build();
                if (state != null && state.isCacheable()) {
                    httpContent = new CachedHttpContent(httpContent, state, clock,
                        new CacheableDependency(key, state, clock,
                            cache, this));
                    cacheable = true;
                }
            } else if (statusCode == 304) {
                // 304 Not Modified
                // it is only possible if it is a revalidation cache entry holds
                // the exisiting cache config as an extension object
                state = builder.merge(
                    ((CachedHttpContentState) entry.getExtensionObject()));
                cacheable = state.isCacheable();
                // entry must have a CachedHttpContent
                final CachedHttpContent originalContent =
                    (CachedHttpContent) entry.getValue();
                originalContent.combineHeaders(httpContent, state);
                httpContent = originalContent;
            }

            result = new ProviderResult(httpContent, group, cacheable, state);
        } catch (Throwable e) {
            // Yep, thats right. We do want to catch all exceptions. Return a
            // 500 error (internal server error).
            try {
                httpContent = new HTTPResponseAccessorWrapper(
                    ERROR_500_RESPONSE_ACCESSOR);
            } catch (HTTPException e1) {
                throw new IllegalStateException(
                    "Wrapping ERROR_500 Accessor failed");
            }
            result = new ProviderResult(e, group, false, null);
        }
       
        return result;
    }
View Full Code Here

TOP

Related Classes of com.volantis.cache.provider.ProviderResult

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.