@Test public void testMoveNamespace() throws Exception { HashMap<String, String> headers = new HashMap<>(); headers.put("filename", "brain_slug.png"); headers.put("retention", "1000"); File bsImage = new File(TestTempFileSystemBlobStore.class.getClassLoader().getResource("brain_slug.png").getFile()); BlobStore bs = new TempFileSystemBlobStore(); String key = UUID.randomUUID().toString(); String originalNameSpace = "ashish"; bs.update(originalNameSpace, key, headers, new FileInputStream(bsImage)); Map<String, String> storedHeaders = bs.readHeaders(originalNameSpace, key); assertEquals( "'filename' property doesn't exists or not equals to stored metadata ", "brain_slug.png", storedHeaders.get("filename")); Assert.assertTrue(bs.isExists(originalNameSpace, key)); ByteArrayOutputStream originalByteArrayOutputStream = new ByteArrayOutputStream(); bs.readBlob(originalNameSpace, key, originalByteArrayOutputStream); assertEquals( "Stored file in blob store is not the same as received from blob store", originalByteArrayOutputStream.toByteArray().length, bsImage.length()); String newNamespace = "chen"; bs.moveNameSpace(originalNameSpace, key, newNamespace); Assert.assertTrue(bs.isExists(newNamespace, key)); Assert.assertTrue(bs.isExists(newNamespace, key)); ByteArrayOutputStream newByteArrayOutputStream = new ByteArrayOutputStream(); bs.readBlob(newNamespace, key, newByteArrayOutputStream); assertEquals( "Stored file in blob store is not the same as received from blob store", newByteArrayOutputStream.toByteArray().length, bsImage.length()); Assert.assertFalse(bs.isExists(originalNameSpace, key)); bs.delete(newNamespace, key); }
@Override public void moveNameSpace(final String oldNamespace, final String key, final String newNamespace) throws ObjectKeyFormatException, DuplicateObjectKeyException, IllegalStoreStateException { isKeyAcceptable(key); isKeyAcceptable(oldNamespace); isKeyAcceptable(newNamespace); try { File[] files = folder.listFiles(getHeadersFilenameFilter(oldNamespace, key)); ren(files, HEADERS_PREFIX + oldNamespace + "." + key, HEADERS_PREFIX + newNamespace + "." + key + "."); files = folder.listFiles(getFilenameFilter(oldNamespace, key)); ren(files, BLOB_PREFIX + oldNamespace + "." + key, BLOB_PREFIX + newNamespace + "." + key + "."); } catch (IOException e) { throw new IllegalStoreStateException("IOException happened", e); } }
TempFileSystemBlobStore implements BlobStore { @Override public void moveNameSpace(final String oldNamespace, final String key, final String newNamespace) throws ObjectKeyFormatException, DuplicateObjectKeyException, IllegalStoreStateException { isKeyAcceptable(key); isKeyAcceptable(oldNamespace); isKeyAcceptable(newNamespace); try { File[] files = folder.listFiles(getHeadersFilenameFilter(oldNamespace, key)); ren(files, HEADERS_PREFIX + oldNamespace + "." + key, HEADERS_PREFIX + newNamespace + "." + key + "."); files = folder.listFiles(getFilenameFilter(oldNamespace, key)); ren(files, BLOB_PREFIX + oldNamespace + "." + key, BLOB_PREFIX + newNamespace + "." + key + "."); } catch (IOException e) { throw new IllegalStoreStateException("IOException happened", e); } } }
TempFileSystemBlobStore implements BlobStore { @Override public void moveNameSpace(final String oldNamespace, final String key, final String newNamespace) throws ObjectKeyFormatException, DuplicateObjectKeyException, IllegalStoreStateException { isKeyAcceptable(key); isKeyAcceptable(oldNamespace); isKeyAcceptable(newNamespace); try { File[] files = folder.listFiles(getHeadersFilenameFilter(oldNamespace, key)); ren(files, HEADERS_PREFIX + oldNamespace + "." + key, HEADERS_PREFIX + newNamespace + "." + key + "."); files = folder.listFiles(getFilenameFilter(oldNamespace, key)); ren(files, BLOB_PREFIX + oldNamespace + "." + key, BLOB_PREFIX + newNamespace + "." + key + "."); } catch (IOException e) { throw new IllegalStoreStateException("IOException happened", e); } } TempFileSystemBlobStore(); }
TempFileSystemBlobStore implements BlobStore { @Override public void moveNameSpace(final String oldNamespace, final String key, final String newNamespace) throws ObjectKeyFormatException, DuplicateObjectKeyException, IllegalStoreStateException { isKeyAcceptable(key); isKeyAcceptable(oldNamespace); isKeyAcceptable(newNamespace); try { File[] files = folder.listFiles(getHeadersFilenameFilter(oldNamespace, key)); ren(files, HEADERS_PREFIX + oldNamespace + "." + key, HEADERS_PREFIX + newNamespace + "." + key + "."); files = folder.listFiles(getFilenameFilter(oldNamespace, key)); ren(files, BLOB_PREFIX + oldNamespace + "." + key, BLOB_PREFIX + newNamespace + "." + key + "."); } catch (IOException e) { throw new IllegalStoreStateException("IOException happened", e); } } TempFileSystemBlobStore(); void create(String namespace, String key, Map<String, String> headers, final InputStream blob); @Override void create(String namespace, String key, Map<String, String> headers, BlobWriter blobWriter); @Override void update(String namespace, String key, Map<String, String> headers, InputStream blob); @Override void update(String namespace, String key, Map<String, String> headers, BlobWriter blobWriter); @Override void moveNameSpace(final String oldNamespace, final String key, final String newNamespace); void ren(File[] files, String target, String replacement); @Override void readBlob(final String namespace, final String key, BlobReader reader); @Override void readBlob(final String namespace, final String key, final OutputStream out); @Override Map<String, String> readHeaders(final String namespace, final String key); @Override void delete(int expirySeconds); @Override void delete(final String namespace, final String key); FilenameFilter getHeadersFilenameFilter(String namespace, String key); FilenameFilter getFilenameFilter(String namespace, String key); @Override boolean isExists(final String namespace, final String key); @Override Collection<BlobStoreLink> list(); }
TempFileSystemBlobStore implements BlobStore { @Override public void moveNameSpace(final String oldNamespace, final String key, final String newNamespace) throws ObjectKeyFormatException, DuplicateObjectKeyException, IllegalStoreStateException { isKeyAcceptable(key); isKeyAcceptable(oldNamespace); isKeyAcceptable(newNamespace); try { File[] files = folder.listFiles(getHeadersFilenameFilter(oldNamespace, key)); ren(files, HEADERS_PREFIX + oldNamespace + "." + key, HEADERS_PREFIX + newNamespace + "." + key + "."); files = folder.listFiles(getFilenameFilter(oldNamespace, key)); ren(files, BLOB_PREFIX + oldNamespace + "." + key, BLOB_PREFIX + newNamespace + "." + key + "."); } catch (IOException e) { throw new IllegalStoreStateException("IOException happened", e); } } TempFileSystemBlobStore(); void create(String namespace, String key, Map<String, String> headers, final InputStream blob); @Override void create(String namespace, String key, Map<String, String> headers, BlobWriter blobWriter); @Override void update(String namespace, String key, Map<String, String> headers, InputStream blob); @Override void update(String namespace, String key, Map<String, String> headers, BlobWriter blobWriter); @Override void moveNameSpace(final String oldNamespace, final String key, final String newNamespace); void ren(File[] files, String target, String replacement); @Override void readBlob(final String namespace, final String key, BlobReader reader); @Override void readBlob(final String namespace, final String key, final OutputStream out); @Override Map<String, String> readHeaders(final String namespace, final String key); @Override void delete(int expirySeconds); @Override void delete(final String namespace, final String key); FilenameFilter getHeadersFilenameFilter(String namespace, String key); FilenameFilter getFilenameFilter(String namespace, String key); @Override boolean isExists(final String namespace, final String key); @Override Collection<BlobStoreLink> list();  }