Package com.volantis.cache.group

Examples of com.volantis.cache.group.Group


        CacheBuilder builder = factory.createCacheBuilder();
        builder.setClock(clockMock);
        builder.setObjectProvider(providerMock);
        builder.setMaxCount(Integer.MAX_VALUE);
        InternalCache cache = (InternalCache) builder.buildCache();
        Group root = cache.getRootGroup();

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

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

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

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

        Object object;

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        object = cache.retrieve(key1);
        assertSame(value1, object);

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        object = cache.retrieve(key1);
        assertSame(value1, object);

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        StatisticsSnapshot snapshot = root.getStatisticsSnapshot();
        assertEquals(1, snapshot.getEntryCount());
        assertEquals(Time.inMilliSeconds(1010), snapshot.getGatherTime());
        assertEquals(Period.inMilliSeconds(1010), snapshot.getPeriod());
        assertEquals(1, snapshot.getHitCount());
        assertEquals(1, snapshot.getMissedAddedCount());
View Full Code Here


        CacheBuilder builder = factory.createCacheBuilder();
        builder.setClock(clockMock);
        builder.setMaxCount(Integer.MAX_VALUE);
        InternalCache cache = (InternalCache) builder.buildCache();
        Group root = cache.getRootGroup();

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

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

        // =====================================================================
        //   Test Expectations
        // =====================================================================
        Object object;

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        object = cache.retrieve(key1, providerMock);
        assertSame(value1, object);

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        object = cache.retrieve(key1, providerMock);
        assertSame(value1, object);

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

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

        StatisticsSnapshot snapshot = root.getStatisticsSnapshot();
        assertEquals(1, snapshot.getEntryCount());
        assertEquals(1, snapshot.getHitCount());
        assertEquals(1, snapshot.getMissedAddedCount());
    }
View Full Code Here

        CacheBuilder builder = factory.createCacheBuilder();
        builder.setClock(clockMock);
        builder.setMaxCount(2);
        builder.setObjectProvider(providerMock);
        InternalCache cache = (InternalCache) builder.buildCache();
        final Group root = cache.getRootGroup();

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

        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));
            }
        });

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

        root.addRemovalListener(removalListenerMock);

        Object object;

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        object = cache.retrieve(key1);
        assertSame(value1, object);

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        object = cache.retrieve(key2);
        assertSame(value2, object);

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        // At this point cache contains (key2, key1).

        // Retrieving this should discard the entry for key1.
        object = cache.retrieve(key3);
        assertSame(value3, object);

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        // At this point cache contains (key3, key2).

        object = cache.retrieve(key2);
        assertSame(value2, object);

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        // At this point cache contains (key2, key3).

        // Retrieving this should discard the entry for key3.
        object = cache.retrieve(key1);
        assertSame(value1, object);

        // Check the cache integrity.
        ensureCacheIntegrity(cache);

        // At this point cache contains (key1, key2).
        clockMock.expects.getCurrentTime().returns(Time.inMilliSeconds(2000));
        StatisticsSnapshot snapshot = root.getStatisticsSnapshot();
        assertEquals(2, snapshot.getEntryCount());
        assertEquals(1, snapshot.getHitCount());
        assertEquals(4, snapshot.getMissedAddedCount());
    }
View Full Code Here

        GroupBuilder groupBuilder = factory.createGroupBuilder();
        groupBuilder.setMaxCount(2);

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

        final Group root = cache.getRootGroup();
        final Group other = root.addGroup("group1", groupBuilder);

        // =====================================================================
        //   Set Expectations
        // =====================================================================
View Full Code Here

        builder.setClock(clockMock);
        builder.setExpirationChecker(expirationCheckerMock);
        builder.setMaxCount(2);
        builder.setObjectProvider(providerMock);
        InternalCache cache = (InternalCache) builder.buildCache();
        final Group root = cache.getRootGroup();

        // =====================================================================
        //   Set Expectations
        // =====================================================================
View Full Code Here

        builder.setClock(clockMock);
        builder.setMaxCount(2);
        builder.setObjectProvider(providerMock);
        InternalCache cache = (InternalCache) builder.buildCache();

        Group root = cache.getRootGroup();

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

     * @throws IllegalStateException if the group already exists.
     */
    public Group addGroup(
            Object groupName, InternalCache cache, InternalGroup parent,
            GroupBuilder builder, SystemClock clock) {
        Group group;

        group = (Group) map.get(groupName);
        if (group != null) {
            throw new IllegalStateException("Group '" +
                    groupName + "' already exists");
View Full Code Here

        final InternalCache cache = (InternalCache) builder.buildCache();

        // Create 7 groups, of size 4,8,12,16,20,24,28 with two subgroups
        // one of which is 50% and one is 75% of the size of the parent group.
        GroupBuilder groupBuilder = factory.createGroupBuilder();
        Group rootGroup = cache.getRootGroup();
        for (int i = 0, g = 0; i < 7; i += 1) {
            int maxCount = i * GROUP_SIZE_MULTIPLE + 4;
            groupBuilder.setMaxCount(maxCount);
            Group group = rootGroup.addGroup("group" + i, groupBuilder);
            groups[g++] = group;

            for (int s = 0; s < 2; s += 1) {
                groupBuilder.setMaxCount((int) ((0.5 + s / 4.0) * maxCount));
                groups[g++] = group.addGroup("group" + i + "/" + s,
                        groupBuilder);
            }
        }

        TestRemovalListener listener = new TestRemovalListener();
View Full Code Here

        }
    }

    // Javadoc inherited.
    public Group addGroup(Object groupName, GroupBuilder builder) {
        Group group;

        synchronized (groupsMutex) {
            if (groups == null) {
                groups = new GroupMap();
            }
View Full Code Here

        return group;
    }

    // Javadoc inherited.
    public Group getGroup(Object groupName) {
        Group group = findGroup(groupName);
        if (group == null) {
            throw new IllegalStateException(
                    "Group '" + groupName + "' does not exist");
        }
        return group;
View Full Code Here

TOP

Related Classes of com.volantis.cache.group.Group

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.