Package org.geowebcache.io

Examples of org.geowebcache.io.Resource


        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("a", "x");
        parameters.put("b", "ø");

        Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes());
        long[] xyz = { 5L, 6L, 7L };
        TileObject to = TileObject.createCompleteTileObject("test:123123 112", xyz, "EPSG:4326",
                "image/jpeg", parameters, bytes);
        to.setId(11231231);

        fbs.put(to);

        TileObject to2 = TileObject.createQueryTileObject("test:123123 112", xyz, "EPSG:4326",
                "image/jpeg", parameters);
        to2.setId(11231231);
        fbs.get(to2);

        InputStream is = to2.getBlob().getInputStream();
        InputStream is2 = bytes.getInputStream();
        try {
            assertTrue(IOUtils.contentEquals(is, is2));
        } finally {
            is.close();
            is2.close();
View Full Code Here


    }

    public void testTilRangeDelete() throws Exception {
        FileBlobStore fbs = setup();

        Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes());
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("a", "x");
        parameters.put("b", "ø");
        MimeType mime = ImageMime.png;
        SRS srs = SRS.getEPSG4326();
        String layerName = "test:123123 112";

        int zoomLevel = 7;
        int x = 25;
        int y = 6;

        // long[] origXYZ = {x,y,zoomLevel};

        TileObject[] tos = new TileObject[6];

        for (int i = 0; i < tos.length; i++) {
            long[] xyz = { x + i - 1, y, zoomLevel };
            tos[i] = TileObject.createCompleteTileObject(layerName, xyz, srs.toString(),
                    mime.getFormat(), parameters, bytes);
            fbs.put(tos[i]);
        }

        long[][] rangeBounds = new long[zoomLevel + 2][5];
        int zoomStart = zoomLevel - 1;
        int zoomStop = zoomLevel + 1;

        long[] range = { x, y, x + tos.length - 3, y, zoomLevel};
        rangeBounds[zoomLevel] = range;

        TileRange trObj = new TileRange(layerName, srs.toString(), zoomStart, zoomStop,
                rangeBounds, mime, parameters);

        fbs.delete(trObj);

        // starting x and x + tos.length should have data, the remaining should not
        TileObject firstTO = TileObject.createQueryTileObject(layerName, tos[0].xyz,
                srs.toString(), mime.getFormat(), parameters);
        fbs.get(firstTO);
        InputStream is = firstTO.getBlob().getInputStream();
        InputStream is2 = bytes.getInputStream();
        try {
            assertTrue(IOUtils.contentEquals(is, is2));
        } finally {
            is.close();
            is2.close();
        }

        TileObject lastTO = TileObject.createQueryTileObject(layerName, tos[tos.length - 1].xyz,
                srs.toString(), mime.getFormat(), parameters);
        fbs.get(lastTO);
        is = lastTO.getBlob().getInputStream();
        is2 = bytes.getInputStream();
        try {
            assertTrue(IOUtils.contentEquals(is, is2));
        } finally {
            is.close();
            is2.close();
        }

        TileObject midTO = TileObject.createQueryTileObject(layerName,
                tos[(tos.length - 1) / 2].xyz, srs.toString(), mime.getFormat(), parameters);
        fbs.get(midTO);
        Resource res = midTO.getBlob();

        assertNull(res);
    }
View Full Code Here

        assertNull(res);
    }

    public void testRenameLayer() throws Exception {
        FileBlobStore fbs = setup();
        Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes());
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("a", "x");
        parameters.put("b", "ø");
        MimeType mime = ImageMime.png;
        SRS srs = SRS.getEPSG4326();
View Full Code Here

        transCache.setTicker(ticker);
    }
   
    @Test
    public void testHit() throws Exception {
        Resource r = new ByteArrayResource(new byte[]{1,2,3});
       
        transCache.put("foo", r);
       
        ticker.advanceMilli(EXPIRE_TIME-1);
        Resource result = transCache.get("foo");
        assertThat(result, notNullValue());
        assertThat(r.getLastModified(), equalTo(r.getLastModified()));
        try (InputStream is = result.getInputStream();){
            assertThat(is.read(), equalTo(1));
            assertThat(is.read(), equalTo(2));
            assertThat(is.read(), equalTo(3));
            assertThat(is.read(), equalTo(-1));
        }
View Full Code Here

        }
    }
   
    @Test
    public void testRemoveOnHit() throws Exception {
        Resource r = new ByteArrayResource(new byte[]{1,2,3});
       
        transCache.put("foo", r);
       
        ticker.advanceMilli(EXPIRE_TIME-1);
       
        transCache.get("foo"); // Hit
       
        Resource result = transCache.get("foo");
        assertThat(result, nullValue()); // Should have been cleared
    }
View Full Code Here

        assertThat(result, nullValue()); // Should have been cleared
    }
   
    @Test
    public void testRemoveOnExpire() throws Exception {
        Resource r = new ByteArrayResource(new byte[]{1,2,3});
       
        transCache.put("foo", r);
       
        ticker.advanceMilli(EXPIRE_TIME+1);
       
        Resource result = transCache.get("foo");
        assertThat(result, nullValue()); // Should have expired
    }
View Full Code Here

   
    @Test
    public void testRemoveWhenMaxTiles() throws Exception {
       
        for (byte i = 0; i<MAX_TILES; i++) {
           Resource r = new ByteArrayResource(new byte[]{(byte)(i+1),(byte)(i+2),(byte)(i+3)});
           transCache.put("foo"+i, r);
           assertThat(transCache.size(), is(i+1));
        }
        assertThat(transCache.storageSize(), is((long)MAX_TILES*3));
        Resource r = new ByteArrayResource(new byte[]{(byte)(MAX_TILES+1),(byte)(MAX_TILES+2)});
        transCache.put("foo"+MAX_TILES, r);
        assertThat(transCache.size(), is(MAX_TILES));
        assertThat(transCache.storageSize(), is((long)MAX_TILES*3-1)); // remove a 3 byte  and add a 2 byte
       
        ticker.advanceMilli(1);
       
        Resource result1 = transCache.get("foo0");
        assertThat(result1, nullValue()); // Should have expired
        Resource result2 = transCache.get("foo1");
        assertThat(result2, notNullValue()); // Should still be cached
    }
View Full Code Here

   
    @Test
    public void testRemoveWhenMaxSpace() throws Exception {
       
        for (long i = 0; i<MAX_SPACE_KiB; i++) {
           Resource r = new ByteArrayResource(new byte[i==0?1023:1024]); // make the first one 1 byte less than a KiB
           transCache.put("foo"+i, r);
           assertThat(transCache.storageSize(), is((i+1)*1024-1)); // 1 KiB per resource, less a byte for the first
           ticker.advanceMilli(1);
        }
        assertThat(transCache.storageSize(), is((long)MAX_SPACE_KiB*1024-1)); // 1 KiB per resource, less a byte for the first
        assertThat(transCache.size(), is(MAX_SPACE_KiB));
        Resource r = new ByteArrayResource(new byte[2]); // 2 bytes will go over the maximum
        transCache.put("foo"+MAX_SPACE_KiB, r);
        assertThat(transCache.storageSize(), is((long)(MAX_SPACE_KiB-1)*1024+2)); // 1 KiB for each of the resources except the first should be removed, and the last is only 2 bytes.
        assertThat(transCache.size(), is(MAX_SPACE_KiB));
       
        ticker.advanceMilli(1);
       
        Resource result1 = transCache.get("foo0");
        assertThat(result1, nullValue()); // Should have expired
        Resource result2 = transCache.get("foo1");
        assertThat(result2, notNullValue()); // Should still be cached
    }
View Full Code Here

        TransientCache transCache = new TransientCache(100, 1024, 2000);
       
        StorageBroker sb = new DefaultStorageBroker(blobStore);
       
        //long[] xyz = {1L,2L,3L};
        Resource blob = new ByteArrayResource(new byte[20*1024]);

        System.out.println("Inserting into database, " + TILE_PUT_COUNT + " tiles");
       
        long startInsert = System.currentTimeMillis();
        for(int i=1; i < TILE_PUT_COUNT; i++) {
View Full Code Here

       return null;
    }

   
    public Resource getResponse() {
        Resource ret = BlankTileException.blankTile;
        if (ret == null) {
            synchronized (BlankTileException.class) {
                ret = BlankTileException.blankTile;
                if (ret == null) {
                    BlankTileException.blankTile = ret = getBlankTile();
View Full Code Here

TOP

Related Classes of org.geowebcache.io.Resource

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.