Package org.geowebcache.diskquota.storage

Examples of org.geowebcache.diskquota.storage.Quota


    public void testRenameLayer() throws InterruptedException {
        final String oldLayerName = tilePageCalculator.getLayerNames().iterator().next();
        final String newLayerName = "renamed_layer";

        // make sure the layer is there and has stuff
        Quota usedQuota = store.getUsedQuotaByLayerName(oldLayerName);
        assertNotNull(usedQuota);

        TileSet tileSet = tilePageCalculator.getTileSetsFor(oldLayerName).iterator().next();
        TilePage page = new TilePage(tileSet.getId(), 0, 0, (byte) 0);
        store.addHitsAndSetAccesTime(Collections.singleton(new PageStatsPayload(page)));
        store.addToQuotaAndTileCounts(tileSet, new Quota(BigInteger.valueOf(1024)),
                Collections.EMPTY_LIST);

        Quota expectedQuota = store.getUsedQuotaByLayerName(oldLayerName);
        assertEquals(1024L, expectedQuota.getBytes().longValue());

        assertNotNull(store.getTileSetById(tileSet.getId()));

        store.renameLayer(oldLayerName, newLayerName);

        // cascade deleted old layer?
        assertNull(store.getLeastRecentlyUsedPage(Collections.singleton(oldLayerName)));
        usedQuota = store.getUsedQuotaByLayerName(oldLayerName);
        assertNotNull(usedQuota);
        assertEquals(0L, usedQuota.getBytes().longValue());

        // created new layer?
        Quota newLayerUsedQuota = store.getUsedQuotaByLayerName(newLayerName);
        assertEquals(expectedQuota.getBytes(), newLayerUsedQuota.getBytes());
    }
View Full Code Here


    public void testGetUsedQuotaByLayerName() throws Exception {
        String layerName = "topp:states2";
        List<TileSet> tileSets;
        tileSets = new ArrayList<TileSet>(tilePageCalculator.getTileSetsFor(layerName));

        Quota expected = new Quota();
        for (TileSet tset : tileSets) {
            Quota quotaDiff = new Quota(10, StorageUnit.MiB);
            expected.add(quotaDiff);
            store.addToQuotaAndTileCounts(tset, quotaDiff, Collections.EMPTY_SET);
        }

        Quota usedQuotaByLayerName = store.getUsedQuotaByLayerName(layerName);
        assertEquals(expected.getBytes(), usedQuotaByLayerName.getBytes());
    }
View Full Code Here

        tileSets = new ArrayList<TileSet>(tilePageCalculator.getTileSetsFor(layerName));

        Map<String, Quota> expectedById = new HashMap<String, Quota>();

        for (TileSet tset : tileSets) {
            Quota quotaDiff = new Quota(10D * Math.random(), StorageUnit.MiB);
            store.addToQuotaAndTileCounts(tset, quotaDiff, Collections.EMPTY_SET);
            store.addToQuotaAndTileCounts(tset, quotaDiff, Collections.EMPTY_SET);
            Quota tsetQuota = new Quota(quotaDiff);
            tsetQuota.add(quotaDiff);
            expectedById.put(tset.getId(), tsetQuota);
        }

        for (Map.Entry<String, Quota> expected : expectedById.entrySet()) {
            BigInteger expectedValaue = expected.getValue().getBytes();
View Full Code Here

                    log.debug("First time run: creating global quota object");
                    // need a global TileSet cause the Quota->TileSet relationship is enforced
                    TileSet globalTileSet = new TileSet(GLOBAL_QUOTA_NAME);
                    tileSetById.put(transaction, globalTileSet);

                    Quota globalQuota = new Quota();
                    globalQuota.setTileSetId(GLOBAL_QUOTA_NAME);
                    usedQuotaById.put(transaction, globalQuota);
                    log.debug("created Global Quota");
                }

                final Set<String> layerNames = tilePageCalculator.getLayerNames();
View Full Code Here

        PageStatsPayload payload = new PageStatsPayload(page);
        int numHits = 100;
        payload.setNumHits(numHits);
        payload.setNumTiles(5);

        store.addToQuotaAndTileCounts(testTileSet, new Quota(1, StorageUnit.MiB),
                Collections.singleton(payload));
        List<PageStats> stats = store.addHitsAndSetAccesTime(Collections.singleton(payload)).get();
        assertTrue(stats.get(0).getFillFactor() > 0f);
        PageStats pageStats = store.setTruncated(page);
        assertEquals(0f, pageStats.getFillFactor());
View Full Code Here

        private UsedQuotaByTileSetId(String tileSetId) {
            this.tileSetId = tileSetId;
        }

        public Quota call() throws Exception {
            Quota quota = usedQuotaByTileSetId.get(null, tileSetId, LockMode.READ_COMMITTED);
            if (quota == null) {
                quota = new Quota();
            }
            return quota;
        }
View Full Code Here

            EntityCursor<TileSet> tileSets = tileSetsByLayer.entities(transaction, layerName, true,
                    layerName, true, null);
            try {
                TileSet tileSet;
                Quota freed;
                Quota global;
                while (null != (tileSet = tileSets.next())) {
                    freed = usedQuotaByTileSetId
                            .get(transaction, tileSet.getId(), LockMode.DEFAULT);
                    global = usedQuotaByTileSetId.get(transaction, GLOBAL_QUOTA_NAME,
                            LockMode.DEFAULT);

                    tileSets.delete();
                    global.subtract(freed.getBytes());
                    usedQuotaById.put(transaction, global);
                }
            } finally {
                tileSets.close();
            }
View Full Code Here

            Transaction transaction = entityStore.getEnvironment().beginTransaction(null, null);
            try {
                EntityCursor<TileSet> tileSets = tileSetsByLayer.entities(transaction, layerName,
                        true, layerName, true, null);
                TileSet tileSet;
                Quota freed;
                Quota global;
                try {
                    while (null != (tileSet = tileSets.next())) {
                        if (tileSet.getGridsetId().equals(gridSetId)) {
                            freed = usedQuotaByTileSetId.get(transaction, tileSet.getId(),
                                    LockMode.DEFAULT);
                            global = usedQuotaByTileSetId.get(transaction, GLOBAL_QUOTA_NAME,
                                    LockMode.DEFAULT);

                            tileSets.delete();
                            global.subtract(freed.getBytes());
                            usedQuotaById.put(transaction, global);
                        }
                    }
                } finally {
                    tileSets.close();
View Full Code Here

            EntityCursor<TileSet> tileSets = tileSetsByLayer.entities(transaction, oldLayerName,
                    true, oldLayerName, true, null);
            try {
                TileSet oldTileSet;
                TileSet newTileSet;
                Quota oldQuota;
                Quota newQuota;
                TilePage oldPage;
                TilePage newPage;
                while (null != (oldTileSet = tileSets.next())) {
                    final String gridsetId = oldTileSet.getGridsetId();
                    final String blobFormat = oldTileSet.getBlobFormat();
                    final String parametersId = oldTileSet.getParametersId();
                    newTileSet = new TileSet(newLayerName, gridsetId, blobFormat, parametersId);
                    // this creates the tileset's empty used Quota too
                    newTileSet = getOrCreateTileSet(transaction, newTileSet);

                    final String oldTileSetId = oldTileSet.getId();
                    final String newTileSetId = newTileSet.getId();

                    oldQuota = usedQuotaByTileSetId
                            .get(transaction, oldTileSetId, LockMode.DEFAULT);
                    newQuota = usedQuotaByTileSetId
                            .get(transaction, newTileSetId, LockMode.DEFAULT);
                    newQuota.setBytes(oldQuota.getBytes());
                    usedQuotaById.putNoReturn(transaction, newQuota);

                    EntityCursor<TilePage> oldPages = pagesByTileSetId.entities(transaction,
                            oldTileSetId, true, oldTileSetId, true, CursorConfig.DEFAULT);
                    try {
View Full Code Here

        public UsedQuotaByLayerName(final String layerName) {
            this.layerName = layerName;
        }

        public Quota call() throws Exception {
            Quota aggregated = null;

            EntityCursor<TileSet> layerTileSetsIds;
            layerTileSetsIds = tileSetsByLayer.entities(null, layerName, true, layerName, true,
                    CursorConfig.DEFAULT);
            TileSet tileSet;
            try {
                Quota tileSetUsedQuota;
                while (null != (tileSet = layerTileSetsIds.next())) {
                    if (aggregated == null) {
                        aggregated = new Quota();
                    }
                    tileSetUsedQuota = new UsedQuotaByTileSetId(tileSet.getId()).call();
                    aggregated.add(tileSetUsedQuota);
                }
            } finally {
                layerTileSetsIds.close();
            }
            if (aggregated == null) {
                aggregated = new Quota();
            }

            return aggregated;
        }
View Full Code Here

TOP

Related Classes of org.geowebcache.diskquota.storage.Quota

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.