Package org.geowebcache.storage.blobstore.file

Examples of org.geowebcache.storage.blobstore.file.FileBlobStore


public class BlobStoreTest extends TestCase {
    public static final String TEST_BLOB_DIR_NAME = "gwcTestBlobs";

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

        Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes());
        long[] xyz = { 1L, 2L, 3L };
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("a", "x");
        parameters.put("b", "ø");
        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);

        Resource resp = fbs.get(to2);

        to2.setBlob(resp);

        assertEquals(to.getBlobFormat(), to2.getBlobFormat());
        InputStream is = to.getBlob().getInputStream();
View Full Code Here


            is2.close();
        }
    }

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

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

        Resource resp = fbs.get(to2);

        // to2.setBlob(resp);

        InputStream is = resp.getInputStream();
        InputStream is2 = bytes.getInputStream();
        try {
            assertTrue(IOUtils.contentEquals(is, is2));
        } finally {
            is.close();
            is2.close();
        }

       
        TileObject to3 = TileObject.createQueryTileObject("test:123123 112", xyz, "EPSG:4326",
                "image/jpeg", parameters);
        fbs.delete(to3);

        TileObject to4 = TileObject.createQueryTileObject("test:123123 112", xyz, "EPSG:4326",
                "image/jpeg", parameters);
        assertNull(fbs.get(to4));
    }
View Full Code Here

                "image/jpeg", parameters);
        assertNull(fbs.get(to4));
    }

    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][4];
        int zoomStart = zoomLevel - 1;
        int zoomStop = zoomLevel + 1;

        long[] range = { x, y, x + tos.length - 3, y };
        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);
        InputStream is = fbs.get(firstTO).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);
        is = fbs.get(lastTO).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);
        Resource res = fbs.get(midTO);

        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();
        final 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]);
        }

        final String newLayerName = "modifiedLayerName";
        BlobStoreListener listener = EasyMock.createNiceMock(BlobStoreListener.class);
        listener.layerRenamed(EasyMock.eq(layerName), EasyMock.eq(newLayerName));
        EasyMock.replay(listener);

        fbs.addListener(listener);

        boolean renamed = fbs.rename(layerName, newLayerName);
        assertTrue(renamed);

        EasyMock.verify(listener);

        try {
            fbs.rename(layerName, newLayerName);
            fail("Expected StorageException, target dir already exists");
        } catch (StorageException e) {
            assertTrue(true);
        }
    }
View Full Code Here

        }
        if (!fh.exists() && !fh.mkdirs()) {
            throw new StorageException("Unable to create " + fh.getAbsolutePath());
        }

        return new FileBlobStore(StorageBrokerTest.findTempDir() + File.separator
                + TEST_BLOB_DIR_NAME);
    }
View Full Code Here

        File blobDirs = new File(blobPath);
        if(! blobDirs.exists() && ! blobDirs.mkdirs()) {
            throw new StorageException("Unable to create " + blobPath);
        }
       
        BlobStore blobStore = new FileBlobStore(blobPath);
       
        StorageBroker sb = new StorageBroker(metaStore, blobStore);
       
        //long[] xyz = {1L,2L,3L};
        Resource blob = new ByteArrayResource(new byte[20*1024]);
 
View Full Code Here

          request.setupAddParameter("height", height +"");
          request.setupAddParameter("bbox", bounds.toString());
          final File imageTile = new File(getClass().getResource("/image.png").toURI());
         
          StorageBroker broker = new DefaultStorageBroker(
            new FileBlobStore(temp.getAbsolutePath()) {

          @Override
          public boolean get(TileObject stObj)
              throws StorageException {
            stObj.setBlob(new FileResource(imageTile));
View Full Code Here

public class BlobStoreTest extends TestCase {
    public static final String TEST_BLOB_DIR_NAME = "gwcTestBlobs";

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

        Resource bytes = new ByteArrayResource("1 2 3 4 5 6 test".getBytes());
        long[] xyz = { 1L, 2L, 3L };
        Map<String, String> parameters = new HashMap<String, String>();
        parameters.put("a", "x");
        parameters.put("b", "ø");
        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);

        assertEquals(to.getBlobFormat(), to2.getBlobFormat());
        InputStream is = to.getBlob().getInputStream();
        InputStream is2 = to2.getBlob().getInputStream();
        try {
View Full Code Here

            is2.close();
        }
    }

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

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

        TileObject to3 = TileObject.createQueryTileObject("test:123123 112", xyz, "EPSG:4326",
                "image/jpeg", parameters);
        fbs.delete(to3);

        TileObject to4 = TileObject.createQueryTileObject("test:123123 112", xyz, "EPSG:4326",
                "image/jpeg", parameters);
        assertFalse(fbs.get(to4));
    }
View Full Code Here

                "image/jpeg", parameters);
        assertFalse(fbs.get(to4));
    }

    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

TOP

Related Classes of org.geowebcache.storage.blobstore.file.FileBlobStore

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.