private void testStore(StorageProvider provider, int size) throws IOException { byte[] data = createData(size); Assert.assertEquals(size, data.length); Storage storage = provider.store(new ByteArrayInputStream(data)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ContentUtil.copy(storage.getInputStream(), baos); verifyData(data, baos.toByteArray()); }
@Override public void run() { log.debug("SpaceDeleteWorker started!"); Iterator<String> contents = getSpaceContents(spaceId, null); int count = 0; while (contents.hasNext() && count++ < 5) { try { Thread.sleep((long) Math.pow(2, count) * 100); } catch (InterruptedException e) { } StorageProvider sp = StorageProviderBase.this; if (wrappedStorageProvider != null) { sp = wrappedStorageProvider; } while (contents.hasNext()) { String contentId = contents.next(); log.debug("deleteContent(" + spaceId + ", " + contentId + ") - count=" + count); try { sp.deleteContent(spaceId, contentId); } catch (Exception e) { log.error("Error deleting content " + contentId + " in space " + spaceId, e); } } contents = getSpaceContents(spaceId, null); } if (contents.hasNext()) { log.debug("deleteSpaceContents(" + spaceId + ") exceeded retries"); Map<String, String> allProps = getAllSpaceProperties(spaceId); allProps.put("delete-error", "Unable to delete all contents"); doSetSpaceProperties(spaceId, allProps); } else { log.debug("removeSpace(" + spaceId + ")"); removeSpace(spaceId); } log.debug("SpaceDeleteWorker ended!"); }
private void testDelete(StorageProvider provider) throws IOException { Storage storage = provider.store(new ByteArrayInputStream(createData(512))); storage.delete(); // getInputStream has to throw an IllegalStateException try { storage.getInputStream(); Assert.fail(); } catch (IllegalStateException expected) { } // invoking delete a second time should not have any effect storage.delete(); }