Package org.geoserver.geofence.cache

Examples of org.geoserver.geofence.cache.CachedRuleReader$NoAuthException


       
        form.add(new TextField<Long>("cacheExpire", new PropertyModel<Long>(
                cacheModel, "expireMilliSec")).setRequired(true));


        CachedRuleReader cacheRuleReader = GeoServerExtensions.bean(CachedRuleReader.class);

        final Model<String> ruleStatsModel = new Model(getStats(cacheRuleReader));
        final Label ruleStats = new Label("rulestats", ruleStatsModel);
        ruleStats.setOutputMarkupId(true);
        ruleStats.setEscapeModelStrings(false);
        form.add(ruleStats);
        final Model<String> userStatsModel = new Model(getUserStats(cacheRuleReader));
        final Label userStats = new Label("userstats", userStatsModel);
        userStats.setEscapeModelStrings(false);
        userStats.setOutputMarkupId(true);
        form.add(userStats);
       
        form.add(new AjaxSubmitLink("invalidate") {

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                CachedRuleReader cacheRuleReader = GeoServerExtensions
                    .bean(CachedRuleReader.class);
                cacheRuleReader.invalidateAll();
                info(new StringResourceModel(GeofencePage.class.getSimpleName() +
                        ".cacheInvalidated", null).getObject());
                ruleStatsModel.setObject(getStats(cacheRuleReader));
                userStatsModel.setObject(getUserStats(cacheRuleReader));
                target.addComponent(ruleStats);
View Full Code Here


        config.setExpireMilliSec(1000);
        config.setCustomTicker(ticker);

        configManager.setCacheConfiguration(config);

        CachedRuleReader cachedRuleReader = new CachedRuleReader(configManager);
        cachedRuleReader.setRealRuleReaderService(realReader);

        System.out.println(cachedRuleReader.getStats());
        assertEquals(0, cachedRuleReader.getStats().hitCount());
        assertEquals(0, cachedRuleReader.getStats().missCount());
        assertEquals(0, cachedRuleReader.getStats().evictionCount());

        RuleFilter filter1 = new RuleFilter();
        filter1.setUser("test_1");
        RuleFilter filter2 = new RuleFilter();
        filter2.setUser("test_2");
        RuleFilter filter3 = new RuleFilter();
        filter3.setUser("test_3");

        assertNotSame(filter1, filter2);

        // expected stats
        int hitExp = 0;
        int missExp = 0;
        int evictExp = 0;

        // first loading, obviously a miss
        AccessInfo ai1_1= cachedRuleReader.getAccessInfo(filter1);

        System.out.println(cachedRuleReader.getStats());
        assertEquals(hitExp, cachedRuleReader.getStats().hitCount());
        assertEquals(++missExp, cachedRuleReader.getStats().missCount());
        assertEquals(evictExp, cachedRuleReader.getStats().evictionCount());

        // second loading with the same rule, should be a hit
        ticker.setMillisec(1);
        AccessInfo ai1_2= cachedRuleReader.getAccessInfo(filter1);

        System.out.println(cachedRuleReader.getStats());
        assertEquals(++hitExp, cachedRuleReader.getStats().hitCount());
        assertEquals(missExp, cachedRuleReader.getStats().missCount());
        assertEquals(evictExp, cachedRuleReader.getStats().evictionCount());

        assertEquals(ai1_1, ai1_2);

        // loading a different filter, a miss again
        ticker.setMillisec(2);
        AccessInfo ai2= cachedRuleReader.getAccessInfo(filter2);

        System.out.println(cachedRuleReader.getStats());
        assertEquals(hitExp, cachedRuleReader.getStats().hitCount());
        assertEquals(++missExp, cachedRuleReader.getStats().missCount());
        assertEquals(evictExp, cachedRuleReader.getStats().evictionCount());

        // yet another different filter. we expect a miss, and an eviction
        ticker.setMillisec(3);
        AccessInfo ai3= cachedRuleReader.getAccessInfo(filter3);

        System.out.println(cachedRuleReader.getStats());
        assertEquals(hitExp, cachedRuleReader.getStats().hitCount());
        assertEquals(++missExp, cachedRuleReader.getStats().missCount());
        assertEquals(++evictExp, cachedRuleReader.getStats().evictionCount());

        // filter1 is the oldest one:
        ticker.setMillisec(4);
        cachedRuleReader.getAccessInfo(filter2);
        System.out.println(cachedRuleReader.getStats());
        assertEquals(++hitExp, cachedRuleReader.getStats().hitCount());

        ticker.setMillisec(5);
        cachedRuleReader.getAccessInfo(filter3);
        System.out.println(cachedRuleReader.getStats());
        assertEquals(++hitExp, cachedRuleReader.getStats().hitCount());

        // reload filter1, ==> filter 2 should be evicted
        ticker.setMillisec(6);
        cachedRuleReader.getAccessInfo(filter1);
        System.out.println(cachedRuleReader.getStats());
        assertEquals(hitExp, cachedRuleReader.getStats().hitCount());
        assertEquals(++missExp, cachedRuleReader.getStats().missCount());
        assertEquals(++evictExp, cachedRuleReader.getStats().evictionCount());
    }
View Full Code Here

        config.setExpireMilliSec(1000);
        config.setCustomTicker(ticker);

        configManager.setCacheConfiguration(config);

        CachedRuleReader cachedRuleReader = new CachedRuleReader(configManager);
        cachedRuleReader.setRealRuleReaderService(realReader);

        cachedRuleReader.getCacheInitParams().setSize(100);
        cachedRuleReader.getCacheInitParams().setRefreshMilliSec(500);
        cachedRuleReader.getCacheInitParams().setExpireMilliSec(1000);
        cachedRuleReader.getCacheInitParams().setCustomTicker(ticker);

        cachedRuleReader.init();

        System.out.println(cachedRuleReader.getStats());
        assertEquals(0, cachedRuleReader.getStats().hitCount());
        assertEquals(0, cachedRuleReader.getStats().missCount());
        assertEquals(0, cachedRuleReader.getStats().evictionCount());

        RuleFilter filter1 = new RuleFilter();
        filter1.setUser("test_1");
        RuleFilter filter2 = new RuleFilter();
        filter2.setUser("test_2");
        RuleFilter filter3 = new RuleFilter();
        filter3.setUser("test_3");

        int hitExp = 0;
        int missExp = 0;
        int evictExp = 0;

        // first loading
        AccessInfo ai1_1= cachedRuleReader.getAccessInfo(filter1);

        System.out.println(cachedRuleReader.getStats());
        assertEquals(hitExp, cachedRuleReader.getStats().hitCount());
        assertEquals(++missExp, cachedRuleReader.getStats().missCount());
        assertEquals(evictExp, cachedRuleReader.getStats().evictionCount());

        // second loading with the same rule, should be a hit
        ticker.setMillisec(1);
        AccessInfo ai1_2= cachedRuleReader.getAccessInfo(filter1);

        System.out.println(cachedRuleReader.getStats());
        assertEquals(++hitExp, cachedRuleReader.getStats().hitCount());
        assertEquals(missExp, cachedRuleReader.getStats().missCount());
        assertEquals(evictExp, cachedRuleReader.getStats().evictionCount());
        assertEquals(1, cachedRuleReader.getStats().loadSuccessCount());

        assertEquals(ai1_1, ai1_2);

        // loading the same filter, after the refresh time
        ticker.setMillisec(600);
//        LOGGER.log(Level.INFO, "We expect a reload() now....");
        System.out.println("---> We expect a reload() now....");
        AccessInfo ai1_3= cachedRuleReader.getAccessInfo(filter1);

        System.out.println(cachedRuleReader.getStats());
        assertEquals(++hitExp, cachedRuleReader.getStats().hitCount());
        assertEquals(missExp, cachedRuleReader.getStats().missCount());
        assertEquals(evictExp, cachedRuleReader.getStats().evictionCount());
//        assertEquals(2, cachedRuleReader.getStats().loadSuccessCount()); // dunno if load is made asynch or not

        // reloading should have been triggered
        ticker.setMillisec(700);
        System.out.println("sleeping...");
        Thread.sleep(500);
        System.out.println(cachedRuleReader.getStats());
        assertEquals(hitExp, cachedRuleReader.getStats().hitCount());
        assertEquals(missExp, cachedRuleReader.getStats().missCount());
        assertEquals(evictExp, cachedRuleReader.getStats().evictionCount());
//        assertEquals(2, cachedRuleReader.getStats().loadSuccessCount());  // uhm, this does not work
        if(2!=cachedRuleReader.getStats().loadSuccessCount())
            LOGGER.log(Level.SEVERE, "*** Bad successCount check, expected 2, found {0}", cachedRuleReader.getStats().loadSuccessCount());

        ticker.setMillisec(800);
        cachedRuleReader.getAccessInfo(filter1);
        System.out.println(cachedRuleReader.getStats());

        ticker.setMillisec(2000);
        cachedRuleReader.getAccessInfo(filter1);
        System.out.println(cachedRuleReader.getStats());
    }
View Full Code Here

TOP

Related Classes of org.geoserver.geofence.cache.CachedRuleReader$NoAuthException

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.